| Flutter Impeller |

line_metrics.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/impeller/toolkit/interop/line_metrics.h"
6
7 namespace impeller::interop {
8
9 LineMetrics::LineMetrics(const std::vector<txt::LineMetrics>& metrics) {
10 // There aren't any guarantees (documented or otherwise) that metrics will
11 // have line numbers that are sorted or contiguous.
12 for (const auto& metric : metrics) {
13 metrics_[metric.line_number] = metric;
14 }
15 }
16
17 LineMetrics::~LineMetrics() = default;
18
19 double LineMetrics::GetAscent(size_t line) const {
20 return GetLine(line).ascent;
21 }
22
23 double LineMetrics::GetUnscaledAscent(size_t line) const {
24 return GetLine(line).unscaled_ascent;
25 }
26
27 double LineMetrics::GetDescent(size_t line) const {
28 return GetLine(line).descent;
29 }
30
31 double LineMetrics::GetBaseline(size_t line) const {
32 return GetLine(line).baseline;
33 }
34
35 bool LineMetrics::IsHardbreak(size_t line) const {
36 return GetLine(line).hard_break;
37 }
38
39 double LineMetrics::GetWidth(size_t line) const {
40 return GetLine(line).width;
41 }
42
43 double LineMetrics::GetHeight(size_t line) const {
44 return GetLine(line).height;
45 }
46
47 double LineMetrics::GetLeft(size_t line) const {
48 return GetLine(line).left;
49 }
50
51 size_t LineMetrics::GetCodeUnitStartIndex(size_t line) const {
52 return GetLine(line).start_index;
53 }
54
55 size_t LineMetrics::GetCodeUnitEndIndex(size_t line) const {
56 return GetLine(line).end_index;
57 }
58
59 size_t LineMetrics::GetCodeUnitEndIndexExcludingWhitespace(size_t line) const {
60 return GetLine(line).end_excluding_whitespace;
61 }
62
63 size_t LineMetrics::GetCodeUnitEndIndexIncludingNewline(size_t line) const {
64 return GetLine(line).end_including_newline;
65 }
66
67 const txt::LineMetrics& LineMetrics::GetLine(size_t line) const {
68 auto found = metrics_.find(line);
69 if (found != metrics_.end()) {
70 return found->second;
71 }
72 static txt::LineMetrics kDefaultMetrics = {};
73 return kDefaultMetrics;
74 }
75
76 } // namespace impeller::interop
impeller::interop::LineMetrics::GetLeft
double GetLeft(size_t line) const
Definition: line_metrics.cc:47
impeller::interop::LineMetrics::GetCodeUnitStartIndex
size_t GetCodeUnitStartIndex(size_t line) const
Definition: line_metrics.cc:51
impeller::interop::LineMetrics::GetBaseline
double GetBaseline(size_t line) const
Definition: line_metrics.cc:31
impeller::interop::LineMetrics::LineMetrics
LineMetrics(const std::vector< txt::LineMetrics > &metrics)
Definition: line_metrics.cc:9
impeller::interop::LineMetrics::GetUnscaledAscent
double GetUnscaledAscent(size_t line) const
Definition: line_metrics.cc:23
impeller::interop::LineMetrics::GetCodeUnitEndIndexIncludingNewline
size_t GetCodeUnitEndIndexIncludingNewline(size_t line) const
Definition: line_metrics.cc:63
impeller::interop::LineMetrics::GetWidth
double GetWidth(size_t line) const
Definition: line_metrics.cc:39
impeller::interop::LineMetrics::GetAscent
double GetAscent(size_t line) const
Definition: line_metrics.cc:19
impeller::interop::LineMetrics::~LineMetrics
~LineMetrics()
impeller::interop::LineMetrics::IsHardbreak
bool IsHardbreak(size_t line) const
Definition: line_metrics.cc:35
impeller::interop::LineMetrics::GetHeight
double GetHeight(size_t line) const
Definition: line_metrics.cc:43
impeller::interop::LineMetrics::GetCodeUnitEndIndex
size_t GetCodeUnitEndIndex(size_t line) const
Definition: line_metrics.cc:55
impeller::interop::LineMetrics::GetCodeUnitEndIndexExcludingWhitespace
size_t GetCodeUnitEndIndexExcludingWhitespace(size_t line) const
Definition: line_metrics.cc:59
impeller::interop::LineMetrics::GetDescent
double GetDescent(size_t line) const
Definition: line_metrics.cc:27
line_metrics.h
impeller::interop
Definition: context_gles.cc:12