Flutter Engine
 
Loading...
Searching...
No Matches
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
6
7namespace impeller::interop {
8
9Paragraph::Paragraph(std::unique_ptr<txt::Paragraph> paragraph)
10 : paragraph_(std::move(paragraph)) {}
11
12Paragraph::~Paragraph() = default;
13
15 return paragraph_->GetMaxWidth();
16}
17
19 return paragraph_->GetHeight();
20}
21
23 return paragraph_->GetLongestLine();
24}
25
27 return paragraph_->GetMinIntrinsicWidth();
28}
29
31 return paragraph_->GetMaxIntrinsicWidth();
32}
33
35 return paragraph_->GetIdeographicBaseline();
36}
37
39 return paragraph_->GetAlphabeticBaseline();
40}
41
42uint32_t Paragraph::GetLineCount() const {
43 return paragraph_->GetNumberOfLines();
44}
45
46const std::unique_ptr<txt::Paragraph>& Paragraph::GetHandle() const {
47 return paragraph_;
48}
49
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
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
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
80ImpellerRange 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
Scalar GetLongestLineWidth() const
Definition paragraph.cc:22
ScopedObject< GlyphInfo > GetGlyphInfoAtCodeUnitIndex(size_t code_unit_index) const
Definition paragraph.cc:61
Scalar GetMinIntrinsicWidth() const
Definition paragraph.cc:26
ImpellerRange GetWordBoundary(size_t code_unit_index) const
Definition paragraph.cc:80
uint32_t GetLineCount() const
Definition paragraph.cc:42
Scalar GetIdeographicBaseline() const
Definition paragraph.cc:34
Paragraph(std::unique_ptr< txt::Paragraph > paragraph)
Definition paragraph.cc:9
Scalar GetAlphabeticBaseline() const
Definition paragraph.cc:38
ScopedObject< GlyphInfo > GetClosestGlyphInfoAtParagraphCoordinates(double x, double y) const
Definition paragraph.cc:70
ScopedObject< LineMetrics > GetLineMetrics() const
Definition paragraph.cc:50
Scalar GetMaxIntrinsicWidth() const
Definition paragraph.cc:30
const std::unique_ptr< txt::Paragraph > & GetHandle() const
Definition paragraph.cc:46
int32_t x
double y
float Scalar
Definition scalar.h:19
Definition ref_ptr.h:261
uint64_t start
Definition impeller.h:525