Skip to content

Commit

Permalink
Revert "Make FontWeight an enum, Remove unused text classes" (flutt…
Browse files Browse the repository at this point in the history
  • Loading branch information
zanderso authored Aug 23, 2023
1 parent 41912e7 commit 139df5c
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 15 deletions.
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
53 changes: 38 additions & 15 deletions lib/ui/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,53 @@ 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;

/// 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
Expand Down Expand Up @@ -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.
Expand Down
62 changes: 62 additions & 0 deletions lib/ui/text/line_metrics.h
Original file line number Diff line number Diff line change
@@ -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_
2 changes: 2 additions & 0 deletions lib/ui/text/paragraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions lib/ui/text/text_box.h
Original file line number Diff line number Diff line change
@@ -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_

0 comments on commit 139df5c

Please sign in to comment.