| Flutter Impeller |

paragraph.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 "impeller/toolkit/interop/paragraph.h"
6
7 namespace impeller::interop {
8
9 Paragraph::Paragraph(std::unique_ptr<txt::Paragraph> paragraph)
10 : paragraph_(std::move(paragraph)) {}
11
12 Paragraph::~Paragraph() = default;
13
14 Scalar Paragraph::GetMaxWidth() const {
15 return paragraph_->GetMaxWidth();
16 }
17
18 Scalar Paragraph::GetHeight() const {
19 return paragraph_->GetHeight();
20 }
21
22 Scalar Paragraph::GetLongestLineWidth() const {
23 return paragraph_->GetLongestLine();
24 }
25
26 Scalar Paragraph::GetMinIntrinsicWidth() const {
27 return paragraph_->GetMinIntrinsicWidth();
28 }
29
30 Scalar Paragraph::GetMaxIntrinsicWidth() const {
31 return paragraph_->GetMaxIntrinsicWidth();
32 }
33
34 Scalar Paragraph::GetIdeographicBaseline() const {
35 return paragraph_->GetIdeographicBaseline();
36 }
37
38 Scalar Paragraph::GetAlphabeticBaseline() const {
39 return paragraph_->GetAlphabeticBaseline();
40 }
41
42 uint32_t Paragraph::GetLineCount() const {
43 return paragraph_->GetNumberOfLines();
44 }
45
46 const std::unique_ptr<txt::Paragraph>& Paragraph::GetHandle() const {
47 return paragraph_;
48 }
49
50 ScopedObject<LineMetrics> Paragraph::GetLineMetrics() const {
51 // Line metrics are expensive to calculate and the recommendation is that
52 // the metric after each layout must be cached. But interop::Paragraphs are
53 // immutable. So do the caching on behalf of the caller.
54 if (lazy_line_metrics_) {
55 return lazy_line_metrics_;
56 }
57 lazy_line_metrics_ = Create<LineMetrics>(paragraph_->GetLineMetrics());
58 return lazy_line_metrics_;
59 }
60
61 ScopedObject<GlyphInfo> Paragraph::GetGlyphInfoAtCodeUnitIndex(
62 size_t code_unit_index) const {
63 skia::textlayout::Paragraph::GlyphInfo info = {};
64 if (paragraph_->GetGlyphInfoAt(code_unit_index, &info)) {
65 return Create<GlyphInfo>(info);
66 }
67 return nullptr;
68 }
69
70 ScopedObject<GlyphInfo> Paragraph::GetClosestGlyphInfoAtParagraphCoordinates(
71 double x,
72 double y) const {
73 skia::textlayout::Paragraph::GlyphInfo info = {};
74 if (paragraph_->GetClosestGlyphInfoAtCoordinate(x, y, &info)) {
75 return Create<GlyphInfo>(info);
76 }
77 return nullptr;
78 }
79
80 ImpellerRange Paragraph::GetWordBoundary(size_t code_unit_index) const {
81 const auto range = paragraph_->GetWordBoundary(code_unit_index);
82 return ImpellerRange{range.start, range.end};
83 }
84
85 } // namespace impeller::interop
impeller::interop::Paragraph::GetMaxWidth
Scalar GetMaxWidth() const
Definition: paragraph.cc:14
impeller::interop::Paragraph::GetLongestLineWidth
Scalar GetLongestLineWidth() const
Definition: paragraph.cc:22
impeller::interop::Paragraph::GetGlyphInfoAtCodeUnitIndex
ScopedObject< GlyphInfo > GetGlyphInfoAtCodeUnitIndex(size_t code_unit_index) const
Definition: paragraph.cc:61
impeller::interop::Paragraph::GetMinIntrinsicWidth
Scalar GetMinIntrinsicWidth() const
Definition: paragraph.cc:26
impeller::interop::Paragraph::GetHeight
Scalar GetHeight() const
Definition: paragraph.cc:18
impeller::interop::Paragraph::GetWordBoundary
ImpellerRange GetWordBoundary(size_t code_unit_index) const
Definition: paragraph.cc:80
impeller::interop::Paragraph::GetLineCount
uint32_t GetLineCount() const
Definition: paragraph.cc:42
impeller::interop::Paragraph::GetIdeographicBaseline
Scalar GetIdeographicBaseline() const
Definition: paragraph.cc:34
impeller::interop::Paragraph::Paragraph
Paragraph(std::unique_ptr< txt::Paragraph > paragraph)
Definition: paragraph.cc:9
impeller::interop::Paragraph::GetAlphabeticBaseline
Scalar GetAlphabeticBaseline() const
Definition: paragraph.cc:38
impeller::interop::Paragraph::~Paragraph
~Paragraph() override
impeller::interop::Paragraph::GetClosestGlyphInfoAtParagraphCoordinates
ScopedObject< GlyphInfo > GetClosestGlyphInfoAtParagraphCoordinates(double x, double y) const
Definition: paragraph.cc:70
impeller::interop::Paragraph::GetLineMetrics
ScopedObject< LineMetrics > GetLineMetrics() const
Definition: paragraph.cc:50
impeller::interop::Paragraph::GetMaxIntrinsicWidth
Scalar GetMaxIntrinsicWidth() const
Definition: paragraph.cc:30
impeller::interop::Paragraph::GetHandle
const std::unique_ptr< txt::Paragraph > & GetHandle() const
Definition: paragraph.cc:46
impeller::interop::ScopedObject
Definition: object.h:67
x
int32_t x
Definition: dl_golden_unittests.cc:458
impeller::interop
Definition: context_gles.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:18
std
Definition: comparable.h:95
paragraph.h
ImpellerRange
Definition: impeller.h:500
ImpellerRange::start
uint64_t start
Definition: impeller.h:501