mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
SkPaint::FontMetrics -> SkFontMetrics (#6824)
* SkPaint::FontMetrics -> SkFontMetrics * fix file formatting * another attempt to correct file formatting
This commit is contained in:
parent
453fc8f512
commit
14db8b397a
@ -39,7 +39,7 @@ static void BM_PaintRecordInit(benchmark::State& state) {
|
||||
auto text_blob = builder.make();
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
PaintRecord PaintRecord(style, text_blob, SkPaint::FontMetrics(), 0, 0);
|
||||
PaintRecord PaintRecord(style, text_blob, SkFontMetrics(), 0, 0);
|
||||
}
|
||||
}
|
||||
BENCHMARK(BM_PaintRecordInit);
|
||||
|
||||
4
third_party/txt/src/txt/paint_record.cc
vendored
4
third_party/txt/src/txt/paint_record.cc
vendored
@ -24,7 +24,7 @@ PaintRecord::~PaintRecord() = default;
|
||||
PaintRecord::PaintRecord(TextStyle style,
|
||||
SkPoint offset,
|
||||
sk_sp<SkTextBlob> text,
|
||||
SkPaint::FontMetrics metrics,
|
||||
SkFontMetrics metrics,
|
||||
size_t line,
|
||||
double run_width)
|
||||
: style_(style),
|
||||
@ -36,7 +36,7 @@ PaintRecord::PaintRecord(TextStyle style,
|
||||
|
||||
PaintRecord::PaintRecord(TextStyle style,
|
||||
sk_sp<SkTextBlob> text,
|
||||
SkPaint::FontMetrics metrics,
|
||||
SkFontMetrics metrics,
|
||||
size_t line,
|
||||
double run_width)
|
||||
: style_(style),
|
||||
|
||||
8
third_party/txt/src/txt/paint_record.h
vendored
8
third_party/txt/src/txt/paint_record.h
vendored
@ -37,13 +37,13 @@ class PaintRecord {
|
||||
PaintRecord(TextStyle style,
|
||||
SkPoint offset,
|
||||
sk_sp<SkTextBlob> text,
|
||||
SkPaint::FontMetrics metrics,
|
||||
SkFontMetrics metrics,
|
||||
size_t line,
|
||||
double run_width);
|
||||
|
||||
PaintRecord(TextStyle style,
|
||||
sk_sp<SkTextBlob> text,
|
||||
SkPaint::FontMetrics metrics,
|
||||
SkFontMetrics metrics,
|
||||
size_t line,
|
||||
double run_width);
|
||||
|
||||
@ -57,7 +57,7 @@ class PaintRecord {
|
||||
|
||||
SkTextBlob* text() const { return text_.get(); }
|
||||
|
||||
const SkPaint::FontMetrics& metrics() const { return metrics_; }
|
||||
const SkFontMetrics& metrics() const { return metrics_; }
|
||||
|
||||
const TextStyle& style() const { return style_; }
|
||||
|
||||
@ -72,7 +72,7 @@ class PaintRecord {
|
||||
// SkTextBlob stores the glyphs and coordinates to draw them.
|
||||
sk_sp<SkTextBlob> text_;
|
||||
// FontMetrics stores the measurements of the font used.
|
||||
SkPaint::FontMetrics metrics_;
|
||||
SkFontMetrics metrics_;
|
||||
size_t line_;
|
||||
double run_width_ = 0.0f;
|
||||
|
||||
|
||||
42
third_party/txt/src/txt/paragraph.cc
vendored
42
third_party/txt/src/txt/paragraph.cc
vendored
@ -205,7 +205,7 @@ Paragraph::CodeUnitRun::CodeUnitRun(std::vector<GlyphPosition>&& p,
|
||||
Range<size_t> cu,
|
||||
Range<double> x,
|
||||
size_t line,
|
||||
const SkPaint::FontMetrics& metrics,
|
||||
const SkFontMetrics& metrics,
|
||||
TextDirection dir)
|
||||
: positions(std::move(p)),
|
||||
code_units(cu),
|
||||
@ -686,7 +686,7 @@ void Paragraph::Layout(double width, bool force) {
|
||||
|
||||
if (glyph_positions.empty())
|
||||
continue;
|
||||
SkPaint::FontMetrics metrics;
|
||||
SkFontMetrics metrics;
|
||||
paint.getFontMetrics(&metrics);
|
||||
paint_records.emplace_back(run.style(), SkPoint::Make(run_x_offset, 0),
|
||||
builder.make(), metrics, line_number,
|
||||
@ -738,7 +738,7 @@ void Paragraph::Layout(double width, bool force) {
|
||||
double max_line_spacing = 0;
|
||||
double max_descent = 0;
|
||||
SkScalar max_unscaled_ascent = 0;
|
||||
auto update_line_metrics = [&](const SkPaint::FontMetrics& metrics,
|
||||
auto update_line_metrics = [&](const SkFontMetrics& metrics,
|
||||
const TextStyle& style) {
|
||||
// TODO(garyq): Multipling in the style.height on the first line is
|
||||
// probably wrong. Figure out how paragraph and line heights are supposed
|
||||
@ -768,7 +768,7 @@ void Paragraph::Layout(double width, bool force) {
|
||||
// If no fonts were actually rendered, then compute a baseline based on the
|
||||
// font of the paragraph style.
|
||||
if (paint_records.empty()) {
|
||||
SkPaint::FontMetrics metrics;
|
||||
SkFontMetrics metrics;
|
||||
TextStyle style(paragraph_style_.GetTextStyle());
|
||||
paint.setTypeface(GetDefaultSkiaTypeface(style));
|
||||
paint.setTextSize(style.font_size);
|
||||
@ -923,7 +923,7 @@ void Paragraph::PaintDecorations(SkCanvas* canvas,
|
||||
if (record.style().decoration == TextDecoration::kNone)
|
||||
return;
|
||||
|
||||
const SkPaint::FontMetrics& metrics = record.metrics();
|
||||
const SkFontMetrics& metrics = record.metrics();
|
||||
SkPaint paint;
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
if (record.style().decoration_color == SK_ColorTRANSPARENT) {
|
||||
@ -948,8 +948,8 @@ void Paragraph::PaintDecorations(SkCanvas* canvas,
|
||||
}
|
||||
|
||||
SkScalar underline_thickness;
|
||||
if ((metrics.fFlags & SkPaint::FontMetrics::FontMetricsFlags::
|
||||
kUnderlineThicknessIsValid_Flag) &&
|
||||
if ((metrics.fFlags &
|
||||
SkFontMetrics::FontMetricsFlags::kUnderlineThicknessIsValid_Flag) &&
|
||||
metrics.fUnderlineThickness > 0) {
|
||||
underline_thickness = metrics.fUnderlineThickness;
|
||||
} else {
|
||||
@ -1024,10 +1024,11 @@ void Paragraph::PaintDecorations(SkCanvas* canvas,
|
||||
double y_offset_original = y_offset;
|
||||
// Underline
|
||||
if (record.style().decoration & TextDecoration::kUnderline) {
|
||||
y_offset += (metrics.fFlags & SkPaint::FontMetrics::FontMetricsFlags::
|
||||
kUnderlinePositionIsValid_Flag)
|
||||
? metrics.fUnderlinePosition
|
||||
: underline_thickness;
|
||||
y_offset +=
|
||||
(metrics.fFlags &
|
||||
SkFontMetrics::FontMetricsFlags::kUnderlinePositionIsValid_Flag)
|
||||
? metrics.fUnderlinePosition
|
||||
: underline_thickness;
|
||||
if (record.style().decoration_style != TextDecorationStyle::kWavy) {
|
||||
canvas->drawLine(x, y + y_offset, x + width, y + y_offset, paint);
|
||||
} else {
|
||||
@ -1053,19 +1054,20 @@ void Paragraph::PaintDecorations(SkCanvas* canvas,
|
||||
}
|
||||
// Strikethrough
|
||||
if (record.style().decoration & TextDecoration::kLineThrough) {
|
||||
if (metrics.fFlags & SkPaint::FontMetrics::FontMetricsFlags::
|
||||
kStrikeoutThicknessIsValid_Flag)
|
||||
if (metrics.fFlags &
|
||||
SkFontMetrics::FontMetricsFlags::kStrikeoutThicknessIsValid_Flag)
|
||||
paint.setStrokeWidth(metrics.fStrikeoutThickness *
|
||||
record.style().decoration_thickness_multiplier);
|
||||
// Make sure the double line is "centered" vertically.
|
||||
y_offset += (decoration_count - 1.0) * underline_thickness *
|
||||
kDoubleDecorationSpacing / -2.0;
|
||||
y_offset += (metrics.fFlags & SkPaint::FontMetrics::FontMetricsFlags::
|
||||
kStrikeoutThicknessIsValid_Flag)
|
||||
? metrics.fStrikeoutPosition
|
||||
// Backup value if the strikeoutposition metric is not
|
||||
// available:
|
||||
: metrics.fXHeight / -2.0;
|
||||
y_offset +=
|
||||
(metrics.fFlags &
|
||||
SkFontMetrics::FontMetricsFlags::kStrikeoutThicknessIsValid_Flag)
|
||||
? metrics.fStrikeoutPosition
|
||||
// Backup value if the strikeoutposition metric is not
|
||||
// available:
|
||||
: metrics.fXHeight / -2.0;
|
||||
if (record.style().decoration_style != TextDecorationStyle::kWavy) {
|
||||
canvas->drawLine(x, y + y_offset, x + width, y + y_offset, paint);
|
||||
} else {
|
||||
@ -1084,7 +1086,7 @@ void Paragraph::PaintBackground(SkCanvas* canvas,
|
||||
if (!record.style().has_background)
|
||||
return;
|
||||
|
||||
const SkPaint::FontMetrics& metrics = record.metrics();
|
||||
const SkFontMetrics& metrics = record.metrics();
|
||||
SkRect rect(SkRect::MakeLTRB(0, metrics.fAscent, record.GetRunWidth(),
|
||||
metrics.fDescent));
|
||||
rect.offset(base_offset + record.offset());
|
||||
|
||||
4
third_party/txt/src/txt/paragraph.h
vendored
4
third_party/txt/src/txt/paragraph.h
vendored
@ -310,14 +310,14 @@ class Paragraph {
|
||||
Range<size_t> code_units;
|
||||
Range<double> x_pos;
|
||||
size_t line_number;
|
||||
SkPaint::FontMetrics font_metrics;
|
||||
SkFontMetrics font_metrics;
|
||||
TextDirection direction;
|
||||
|
||||
CodeUnitRun(std::vector<GlyphPosition>&& p,
|
||||
Range<size_t> cu,
|
||||
Range<double> x,
|
||||
size_t line,
|
||||
const SkPaint::FontMetrics& metrics,
|
||||
const SkFontMetrics& metrics,
|
||||
TextDirection dir);
|
||||
|
||||
void Shift(double delta);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user