Revert "Make FontWeight an enum, Remove unused text classes" (flutter/engine#44987)

Reverts flutter/engine#44960

Failing on customer_testing:
https://ci.chromium.org/ui/p/flutter/builders/try/Mac%20customer_testing/59576/overview
This commit is contained in:
Zachary Anderson
2023-08-22 19:51:45 -07:00
committed by GitHub
parent 8cf3760eed
commit 714d884da5
6 changed files with 149 additions and 28 deletions

View File

@@ -1869,10 +1869,12 @@ ORIGIN: ../../../flutter/lib/ui/text/asset_manager_font_provider.cc + ../../../f
ORIGIN: ../../../flutter/lib/ui/text/asset_manager_font_provider.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/font_collection.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/font_collection.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/line_metrics.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/paragraph.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/paragraph.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/paragraph_builder.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/paragraph_builder.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/text/text_box.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/ui.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/ui_benchmarks.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/ui_dart_state.cc + ../../../flutter/LICENSE
@@ -4596,10 +4598,12 @@ FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.cc
FILE: ../../../flutter/lib/ui/text/asset_manager_font_provider.h
FILE: ../../../flutter/lib/ui/text/font_collection.cc
FILE: ../../../flutter/lib/ui/text/font_collection.h
FILE: ../../../flutter/lib/ui/text/line_metrics.h
FILE: ../../../flutter/lib/ui/text/paragraph.cc
FILE: ../../../flutter/lib/ui/text/paragraph.h
FILE: ../../../flutter/lib/ui/text/paragraph_builder.cc
FILE: ../../../flutter/lib/ui/text/paragraph_builder.h
FILE: ../../../flutter/lib/ui/text/text_box.h
FILE: ../../../flutter/lib/ui/ui.dart
FILE: ../../../flutter/lib/ui/ui_benchmarks.cc
FILE: ../../../flutter/lib/ui/ui_dart_state.cc

View File

@@ -123,10 +123,12 @@ source_set("ui") {
"text/asset_manager_font_provider.h",
"text/font_collection.cc",
"text/font_collection.h",
"text/line_metrics.h",
"text/paragraph.cc",
"text/paragraph.h",
"text/paragraph_builder.cc",
"text/paragraph_builder.h",
"text/text_box.h",
"ui_dart_state.cc",
"ui_dart_state.h",
"volatile_path_tracker.cc",

View File

@@ -13,45 +13,53 @@ enum FontStyle {
}
/// The thickness of the glyphs used to draw the text
enum FontWeight {
/// Thin, the least thick
w100._(100),
class FontWeight {
const FontWeight._(this.index, this.value);
/// Extra-light
w200._(200),
/// Light
w300._(300),
/// Normal / regular / plain
w400._(400),
/// Medium
w500._(500),
/// Semi-bold
w600._(600),
/// Bold
w700._(700),
/// Extra-bold
w800._(800),
/// Black, the most thick
w900._(900);
const FontWeight._(this.value);
/// The encoded integer value of this font weight.
final int index;
/// The thickness value of this font weight.
final int value;
/// Thin, the least thick
static const FontWeight w100 = FontWeight._(0, 100);
/// Extra-light
static const FontWeight w200 = FontWeight._(1, 200);
/// Light
static const FontWeight w300 = FontWeight._(2, 300);
/// Normal / regular / plain
static const FontWeight w400 = FontWeight._(3, 400);
/// Medium
static const FontWeight w500 = FontWeight._(4, 500);
/// Semi-bold
static const FontWeight w600 = FontWeight._(5, 600);
/// Bold
static const FontWeight w700 = FontWeight._(6, 700);
/// Extra-bold
static const FontWeight w800 = FontWeight._(7, 800);
/// Black, the most thick
static const FontWeight w900 = FontWeight._(8, 900);
/// The default font weight.
static const FontWeight normal = w400;
/// A commonly used font weight that is heavier than normal.
static const FontWeight bold = w700;
/// A list of all the font weights.
static const List<FontWeight> values = <FontWeight>[
w100, w200, w300, w400, w500, w600, w700, w800, w900
];
/// Linearly interpolates between two font weights.
///
/// Rather than using fractional weights, the interpolation rounds to the
@@ -79,6 +87,21 @@ enum FontWeight {
}
return values[_lerpInt((a ?? normal).index, (b ?? normal).index, t).round().clamp(0, 8)];
}
@override
String toString() {
return const <int, String>{
0: 'FontWeight.w100',
1: 'FontWeight.w200',
2: 'FontWeight.w300',
3: 'FontWeight.w400',
4: 'FontWeight.w500',
5: 'FontWeight.w600',
6: 'FontWeight.w700',
7: 'FontWeight.w800',
8: 'FontWeight.w900',
}[index]!;
}
}
/// A feature tag and value that affect the selection of glyphs in a font.

View File

@@ -0,0 +1,62 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_LIB_UI_TEXT_LINE_METRICS_H_
#define FLUTTER_LIB_UI_TEXT_LINE_METRICS_H_
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/tonic/converter/dart_converter.h"
namespace flutter {
struct LineMetrics {
const bool* hard_break;
// The final computed ascent and descent for the line. This can be impacted by
// the strut, height, scaling, as well as outlying runs that are very tall.
//
// The top edge is `baseline - ascent` and the bottom edge is `baseline +
// descent`. Ascent and descent are provided as positive numbers. Raw numbers
// for specific runs of text can be obtained in run_metrics_map. These values
// are the cumulative metrics for the entire line.
const double* ascent;
const double* descent;
const double* unscaled_ascent;
// Height of the line.
const double* height;
// Width of the line.
const double* width;
// The left edge of the line. The right edge can be obtained with `left +
// width`
const double* left;
// The y position of the baseline for this line from the top of the paragraph.
const double* baseline;
// Zero indexed line number.
const size_t* line_number;
LineMetrics();
LineMetrics(const bool* hard_break,
const double* ascent,
const double* descent,
const double* unscaled_ascent,
const double* height,
const double* width,
const double* left,
const double* baseline,
const size_t* line_number)
: hard_break(hard_break),
ascent(ascent),
descent(descent),
unscaled_ascent(unscaled_ascent),
height(height),
width(width),
left(left),
baseline(baseline),
line_number(line_number) {}
};
} // namespace flutter
#endif // FLUTTER_LIB_UI_TEXT_LINE_METRICS_H_

View File

@@ -8,6 +8,8 @@
#include "flutter/fml/message_loop.h"
#include "flutter/lib/ui/dart_wrapper.h"
#include "flutter/lib/ui/painting/canvas.h"
#include "flutter/lib/ui/text/line_metrics.h"
#include "flutter/lib/ui/text/text_box.h"
#include "flutter/third_party/txt/src/txt/paragraph.h"
namespace flutter {

View File

@@ -0,0 +1,28 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_LIB_UI_TEXT_TEXT_BOX_H_
#define FLUTTER_LIB_UI_TEXT_TEXT_BOX_H_
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/tonic/converter/dart_converter.h"
namespace flutter {
enum class TextDirection {
rtl,
ltr,
};
struct TextBox {
SkRect rect;
TextDirection direction;
TextBox(SkRect r, TextDirection d) : rect(r), direction(d) {}
};
} // namespace flutter
#endif // FLUTTER_LIB_UI_TEXT_TEXT_BOX_H_