Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Metrics.h
Go to the documentation of this file.
1// Copyright 2019 Google LLC.
2#ifndef Metrics_DEFINED
3#define Metrics_DEFINED
4
5#include <map>
7
8namespace skia {
9namespace textlayout {
11public:
12 StyleMetrics(const TextStyle* style) : text_style(style) {}
13
14 StyleMetrics(const TextStyle* style, SkFontMetrics& metrics)
15 : text_style(style), font_metrics(metrics) {}
16
18
19 // SkFontMetrics contains the following metrics:
20 //
21 // * Top distance to reserve above baseline
22 // * Ascent distance to reserve below baseline
23 // * Descent extent below baseline
24 // * Bottom extent below baseline
25 // * Leading distance to add between lines
26 // * AvgCharWidth average character width
27 // * MaxCharWidth maximum character width
28 // * XMin minimum x
29 // * XMax maximum x
30 // * XHeight height of lower-case 'x'
31 // * CapHeight height of an upper-case letter
32 // * UnderlineThickness underline thickness
33 // * UnderlinePosition underline position relative to baseline
34 // * StrikeoutThickness strikeout thickness
35 // * StrikeoutPosition strikeout position relative to baseline
37};
38
40public:
42
44 size_t end,
45 size_t end_excluding_whitespace,
46 size_t end_including_newline,
47 bool hard_break)
49 , fEndIndex(end)
50 , fEndExcludingWhitespaces(end_excluding_whitespace)
51 , fEndIncludingNewline(end_including_newline)
52 , fHardBreak(hard_break) {}
53 // The following fields are used in the layout process itself.
54
55 // The indexes in the text buffer the line begins and ends.
56 size_t fStartIndex = 0;
57 size_t fEndIndex = 0;
60 bool fHardBreak = false;
61
62 // The following fields are tracked after or during layout to provide to
63 // the user as well as for computing bounding boxes.
64
65 // The final computed ascent and descent for the line. This can be impacted by
66 // the strut, height, scaling, as well as outlying runs that are very tall.
67 //
68 // The top edge is `baseline - ascent` and the bottom edge is `baseline +
69 // descent`. Ascent and descent are provided as positive numbers. Raw numbers
70 // for specific runs of text can be obtained in run_metrics_map. These values
71 // are the cumulative metrics for the entire line.
75 // Total height of the paragraph including the current line.
76 //
77 // The height of the current line is `round(ascent + descent)`.
78 double fHeight = 0.0;
79 // Width of the line.
80 double fWidth = 0.0;
81 // The left edge of the line. The right edge can be obtained with `left +
82 // width`
83 double fLeft = 0.0;
84 // The y position of the baseline for this line from the top of the paragraph.
85 double fBaseline = 0.0;
86 // Zero indexed line number
87 size_t fLineNumber = 0;
88
89 // Mapping between text index ranges and the FontMetrics associated with
90 // them. The first run will be keyed under start_index. The metrics here
91 // are before layout and are the base values we calculate from.
92 std::map<size_t, StyleMetrics> fLineMetrics;
93};
94
95} // namespace textlayout
96} // namespace skia
97
98#endif // Metrics_DEFINED
#define SK_ScalarMin
Definition SkScalar.h:25
#define SK_ScalarMax
Definition SkScalar.h:24
LineMetrics(size_t start, size_t end, size_t end_excluding_whitespace, size_t end_including_newline, bool hard_break)
Definition Metrics.h:43
std::map< size_t, StyleMetrics > fLineMetrics
Definition Metrics.h:92
const TextStyle * text_style
Definition Metrics.h:17
StyleMetrics(const TextStyle *style, SkFontMetrics &metrics)
Definition Metrics.h:14
StyleMetrics(const TextStyle *style)
Definition Metrics.h:12
glong glong end