From 2c4ada8807f7f5739172f9558c8f0aad1532ff7b Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Tue, 22 Aug 2023 13:25:18 -0700 Subject: [PATCH] Make `FontWeight` an enum, Remove unused text classes (#44960) [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- ci/licenses_golden/licenses_flutter | 4 -- lib/ui/BUILD.gn | 2 - lib/ui/text.dart | 53 +++++++----------------- lib/ui/text/line_metrics.h | 62 ----------------------------- lib/ui/text/paragraph.h | 2 - lib/ui/text/text_box.h | 28 ------------- 6 files changed, 15 insertions(+), 136 deletions(-) delete mode 100644 lib/ui/text/line_metrics.h delete mode 100644 lib/ui/text/text_box.h diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 77dc862ce894d..6af3864bfeb6e 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1869,12 +1869,10 @@ 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 @@ -4598,12 +4596,10 @@ 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 diff --git a/lib/ui/BUILD.gn b/lib/ui/BUILD.gn index 8ad0197bb1d8d..1c985fc3763c3 100644 --- a/lib/ui/BUILD.gn +++ b/lib/ui/BUILD.gn @@ -123,12 +123,10 @@ 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", diff --git a/lib/ui/text.dart b/lib/ui/text.dart index 45f86ce3c76ba..20cd759382f2d 100644 --- a/lib/ui/text.dart +++ b/lib/ui/text.dart @@ -13,41 +13,38 @@ enum FontStyle { } /// The thickness of the glyphs used to draw the text -class FontWeight { - const FontWeight._(this.index, this.value); - - /// The encoded integer value of this font weight. - final int index; - - /// The thickness value of this font weight. - final int value; - +enum FontWeight { /// Thin, the least thick - static const FontWeight w100 = FontWeight._(0, 100); + w100._(100), /// Extra-light - static const FontWeight w200 = FontWeight._(1, 200); + w200._(200), /// Light - static const FontWeight w300 = FontWeight._(2, 300); + w300._(300), /// Normal / regular / plain - static const FontWeight w400 = FontWeight._(3, 400); + w400._(400), /// Medium - static const FontWeight w500 = FontWeight._(4, 500); + w500._(500), /// Semi-bold - static const FontWeight w600 = FontWeight._(5, 600); + w600._(600), /// Bold - static const FontWeight w700 = FontWeight._(6, 700); + w700._(700), /// Extra-bold - static const FontWeight w800 = FontWeight._(7, 800); + w800._(800), /// Black, the most thick - static const FontWeight w900 = FontWeight._(8, 900); + w900._(900); + + const FontWeight._(this.value); + + /// The thickness value of this font weight. + final int value; /// The default font weight. static const FontWeight normal = w400; @@ -55,11 +52,6 @@ class FontWeight { /// 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 values = [ - 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 @@ -87,21 +79,6 @@ class FontWeight { } return values[_lerpInt((a ?? normal).index, (b ?? normal).index, t).round().clamp(0, 8)]; } - - @override - String toString() { - return const { - 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. diff --git a/lib/ui/text/line_metrics.h b/lib/ui/text/line_metrics.h deleted file mode 100644 index f5f656cd816f9..0000000000000 --- a/lib/ui/text/line_metrics.h +++ /dev/null @@ -1,62 +0,0 @@ -// 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_ diff --git a/lib/ui/text/paragraph.h b/lib/ui/text/paragraph.h index 1a5d8217aafc4..3a0523a580827 100644 --- a/lib/ui/text/paragraph.h +++ b/lib/ui/text/paragraph.h @@ -8,8 +8,6 @@ #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 { diff --git a/lib/ui/text/text_box.h b/lib/ui/text/text_box.h deleted file mode 100644 index 27f60670f232f..0000000000000 --- a/lib/ui/text/text_box.h +++ /dev/null @@ -1,28 +0,0 @@ -// 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_