diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 6af3864bfeb6e..77dc862ce894d 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -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 diff --git a/lib/ui/BUILD.gn b/lib/ui/BUILD.gn index 1c985fc3763c3..8ad0197bb1d8d 100644 --- a/lib/ui/BUILD.gn +++ b/lib/ui/BUILD.gn @@ -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", diff --git a/lib/ui/text.dart b/lib/ui/text.dart index 20cd759382f2d..45f86ce3c76ba 100644 --- a/lib/ui/text.dart +++ b/lib/ui/text.dart @@ -13,38 +13,41 @@ enum FontStyle { } /// The thickness of the glyphs used to draw the text -enum FontWeight { +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; + /// Thin, the least thick - w100._(100), + static const FontWeight w100 = FontWeight._(0, 100); /// Extra-light - w200._(200), + static const FontWeight w200 = FontWeight._(1, 200); /// Light - w300._(300), + static const FontWeight w300 = FontWeight._(2, 300); /// Normal / regular / plain - w400._(400), + static const FontWeight w400 = FontWeight._(3, 400); /// Medium - w500._(500), + static const FontWeight w500 = FontWeight._(4, 500); /// Semi-bold - w600._(600), + static const FontWeight w600 = FontWeight._(5, 600); /// Bold - w700._(700), + static const FontWeight w700 = FontWeight._(6, 700); /// Extra-bold - w800._(800), + static const FontWeight w800 = FontWeight._(7, 800); /// Black, the most thick - w900._(900); - - const FontWeight._(this.value); - - /// The thickness value of this font weight. - final int value; + static const FontWeight w900 = FontWeight._(8, 900); /// The default font weight. static const FontWeight normal = w400; @@ -52,6 +55,11 @@ enum 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 @@ -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 { + 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 new file mode 100644 index 0000000000000..f5f656cd816f9 --- /dev/null +++ b/lib/ui/text/line_metrics.h @@ -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_ diff --git a/lib/ui/text/paragraph.h b/lib/ui/text/paragraph.h index 3a0523a580827..1a5d8217aafc4 100644 --- a/lib/ui/text/paragraph.h +++ b/lib/ui/text/paragraph.h @@ -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 { diff --git a/lib/ui/text/text_box.h b/lib/ui/text/text_box.h new file mode 100644 index 0000000000000..27f60670f232f --- /dev/null +++ b/lib/ui/text/text_box.h @@ -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_