Flutter Engine
The Flutter Engine
line_metrics.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef LIB_TXT_SRC_LINE_METRICS_H_
18#define LIB_TXT_SRC_LINE_METRICS_H_
19
20#include <map>
21#include <vector>
22
23#include "run_metrics.h"
24
25namespace txt {
26
28 public:
29 // The following fields are used in the layout process itself.
30
31 // The indexes in the text buffer the line begins and ends.
32 size_t start_index = 0;
33 size_t end_index = 0;
36 bool hard_break = false;
37
38 // The following fields are tracked after or during layout to provide to
39 // the user as well as for computing bounding boxes.
40
41 // The final computed ascent and descent for the line. This can be impacted by
42 // the strut, height, scaling, as well as outlying runs that are very tall.
43 //
44 // The top edge is `baseline - ascent` and the bottom edge is `baseline +
45 // descent`. Ascent and descent are provided as positive numbers. Raw numbers
46 // for specific runs of text can be obtained in run_metrics_map. These values
47 // are the cumulative metrics for the entire line.
48 double ascent = 0.0;
49 double descent = 0.0;
50 double unscaled_ascent = 0.0;
51 // Total height of the paragraph including the current line.
52 //
53 // The height of the current line is `round(ascent + descent)`.
54 double height = 0.0;
55 // Width of the line.
56 double width = 0.0;
57 // The left edge of the line. The right edge can be obtained with `left +
58 // width`
59 double left = 0.0;
60 // The y position of the baseline for this line from the top of the paragraph.
61 double baseline = 0.0;
62 // Zero indexed line number.
63 size_t line_number = 0;
64
65 // Mapping between text index ranges and the FontMetrics associated with
66 // them. The first run will be keyed under start_index. The metrics here
67 // are before layout and are the base values we calculate from.
68 std::map<size_t, RunMetrics> run_metrics;
69
71
72 LineMetrics(size_t start,
73 size_t end,
76 bool hard_break)
82};
83
84} // namespace txt
85
86#endif // LIB_TXT_SRC_LINE_METRICS_H_
size_t end_including_newline
Definition: line_metrics.h:35
LineMetrics(size_t start, size_t end, size_t end_excluding_whitespace, size_t end_including_newline, bool hard_break)
Definition: line_metrics.h:72
size_t end_excluding_whitespace
Definition: line_metrics.h:34
std::map< size_t, RunMetrics > run_metrics
Definition: line_metrics.h:68
double unscaled_ascent
Definition: line_metrics.h:50
glong glong end