Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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
5#include "third_party/skia/modules/skparagraph/include/Paragraph.h"
9#include "third_party/skia/include/core/SkScalar.h"
10#include "third_party/skia/modules/skparagraph/include/DartTypes.h"
11#include "third_party/skia/modules/skparagraph/include/TextStyle.h"
12
15 delete paragraph;
16}
17
19 return paragraph->skia_paragraph->getMaxWidth();
20}
21
23 return paragraph->skia_paragraph->getHeight();
24}
25
27 return paragraph->skia_paragraph->getLongestLine();
28}
29
30SKWASM_EXPORT SkScalar
32 return paragraph->skia_paragraph->getMinIntrinsicWidth();
33}
34
35SKWASM_EXPORT SkScalar
37 return paragraph->skia_paragraph->getMaxIntrinsicWidth();
38}
39
40SKWASM_EXPORT SkScalar
42 return paragraph->skia_paragraph->getAlphabeticBaseline();
43}
44
45SKWASM_EXPORT SkScalar
47 return paragraph->skia_paragraph->getIdeographicBaseline();
48}
49
51 Skwasm::Paragraph* paragraph) {
52 return paragraph->skia_paragraph->didExceedMaxLines();
53}
54
56 SkScalar width) {
57 paragraph->skia_paragraph->layout(width);
58}
59
60SKWASM_EXPORT int32_t
62 SkScalar offset_x,
63 SkScalar offset_y,
64 skia::textlayout::Affinity* out_affinity) {
65 auto position = paragraph->skia_paragraph->getGlyphPositionAtCoordinate(
66 offset_x, offset_y);
67 if (out_affinity) {
68 *out_affinity = position.affinity;
69 }
70 return position.position;
71}
72
74 Skwasm::Paragraph* paragraph,
75 SkScalar offset_x,
76 SkScalar offset_y,
77 // Out parameters:
78 SkRect* grapheme_layout_bounds, // 1 SkRect
79 size_t* grapheme_code_unit_range, // 2 size_ts: [start, end]
80 bool* boolean_flags) { // 1 boolean: isLTR
81 skia::textlayout::Paragraph::GlyphInfo glyph_info;
82 if (!paragraph->skia_paragraph->getClosestUTF16GlyphInfoAt(offset_x, offset_y,
83 &glyph_info)) {
84 return false;
85 }
86 // This is more verbose than memcpying the whole struct but ideally we don't
87 // want to depend on the exact memory layout of the struct.
88 std::memcpy(grapheme_layout_bounds, &glyph_info.fGraphemeLayoutBounds,
89 sizeof(SkRect));
90 std::memcpy(grapheme_code_unit_range, &glyph_info.fGraphemeClusterTextRange,
91 2 * sizeof(size_t));
92 boolean_flags[0] =
93 glyph_info.fDirection == skia::textlayout::TextDirection::kLtr;
94 return true;
95}
96
98 Skwasm::Paragraph* paragraph,
99 size_t index,
100 // Out parameters:
101 SkRect* grapheme_layout_bounds, // 1 SkRect
102 size_t* grapheme_code_unit_range, // 2 size_ts: [start, end]
103 bool* boolean_flags) { // 1 boolean: isLTR
104 skia::textlayout::Paragraph::GlyphInfo glyph_info;
105 if (!paragraph->skia_paragraph->getGlyphInfoAtUTF16Offset(index,
106 &glyph_info)) {
107 return false;
108 }
109 std::memcpy(grapheme_layout_bounds, &glyph_info.fGraphemeLayoutBounds,
110 sizeof(SkRect));
111 std::memcpy(grapheme_code_unit_range, &glyph_info.fGraphemeClusterTextRange,
112 2 * sizeof(size_t));
113 boolean_flags[0] =
114 glyph_info.fDirection == skia::textlayout::TextDirection::kLtr;
115 return true;
116}
117
119 Skwasm::Paragraph* paragraph,
120 unsigned int position,
121 int32_t* out_range // Two `int32_t`s, start and end
122) {
123 auto range = paragraph->skia_paragraph->getWordBoundary(position);
124 out_range[0] = range.start;
125 out_range[1] = range.end;
126}
127
129 return paragraph->skia_paragraph->lineNumber();
130}
131
133 size_t character_index) {
134 return paragraph->skia_paragraph->getLineNumberAtUTF16Offset(character_index);
135}
136
137SKWASM_EXPORT skia::textlayout::LineMetrics* paragraph_getLineMetricsAtIndex(
138 Skwasm::Paragraph* paragraph,
139 size_t line_number) {
141 auto metrics = new skia::textlayout::LineMetrics();
142 if (paragraph->skia_paragraph->getLineMetricsAt(line_number, metrics)) {
143 return metrics;
144 } else {
145 delete metrics;
146 return nullptr;
147 }
148}
149
151 std::vector<skia::textlayout::TextBox> boxes;
152};
153
158
160 return list->boxes.size();
161}
162
163SKWASM_EXPORT skia::textlayout::TextDirection
164textBoxList_getBoxAtIndex(TextBoxList* list, size_t index, SkRect* out_rect) {
165 const auto& box = list->boxes[index];
166 *out_rect = box.rect;
167 return box.direction;
168}
169
171 Skwasm::Paragraph* paragraph,
172 int start,
173 int end,
174 skia::textlayout::RectHeightStyle height_style,
175 skia::textlayout::RectWidthStyle width_style) {
177 return new TextBoxList{paragraph->skia_paragraph->getRectsForRange(
178 start, end, height_style, width_style)};
179}
180
182 Skwasm::Paragraph* paragraph) {
184 return new TextBoxList{paragraph->skia_paragraph->getRectsForPlaceholders()};
185}
186
187// Returns a list of the code points that were unable to be rendered with the
188// selected fonts. The list is deduplicated, so each code point in the output
189// is unique.
190// If `nullptr` is passed in for `outCodePoints`, we simply return the count
191// of the code points.
192// Note: This must be called after the paragraph has been laid out at least
193// once in order to get valid data.
195 Skwasm::Paragraph* paragraph,
196 SkUnichar* out_code_points,
197 int out_length) {
198 if (!out_code_points) {
199 return paragraph->skia_paragraph->unresolvedCodepoints().size();
200 }
201 int out_index = 0;
202 for (SkUnichar character :
203 paragraph->skia_paragraph->unresolvedCodepoints()) {
204 if (out_index < out_length) {
205 out_code_points[out_index] = character;
206 out_index++;
207 } else {
208 break;
209 }
210 }
211 return out_index;
212}
uint32_t live_line_metrics_count
uint32_t live_text_box_list_count
uint32_t live_paragraph_count
int32_t width
#define SKWASM_EXPORT
Definition export.h:10
SKWASM_EXPORT int paragraph_getLineNumberAt(Skwasm::Paragraph *paragraph, size_t character_index)
Definition paragraph.cc:132
SKWASM_EXPORT bool paragraph_getGlyphInfoAt(Skwasm::Paragraph *paragraph, size_t index, SkRect *grapheme_layout_bounds, size_t *grapheme_code_unit_range, bool *boolean_flags)
Definition paragraph.cc:97
SKWASM_EXPORT SkScalar paragraph_getLongestLine(Skwasm::Paragraph *paragraph)
Definition paragraph.cc:26
SKWASM_EXPORT bool paragraph_getClosestGlyphInfoAtCoordinate(Skwasm::Paragraph *paragraph, SkScalar offset_x, SkScalar offset_y, SkRect *grapheme_layout_bounds, size_t *grapheme_code_unit_range, bool *boolean_flags)
Definition paragraph.cc:73
SKWASM_EXPORT SkScalar paragraph_getWidth(Skwasm::Paragraph *paragraph)
Definition paragraph.cc:18
SKWASM_EXPORT size_t paragraph_getLineCount(Skwasm::Paragraph *paragraph)
Definition paragraph.cc:128
SKWASM_EXPORT SkScalar paragraph_getAlphabeticBaseline(Skwasm::Paragraph *paragraph)
Definition paragraph.cc:41
SKWASM_EXPORT int paragraph_getUnresolvedCodePoints(Skwasm::Paragraph *paragraph, SkUnichar *out_code_points, int out_length)
Definition paragraph.cc:194
SKWASM_EXPORT void paragraph_getWordBoundary(Skwasm::Paragraph *paragraph, unsigned int position, int32_t *out_range)
Definition paragraph.cc:118
SKWASM_EXPORT TextBoxList * paragraph_getBoxesForRange(Skwasm::Paragraph *paragraph, int start, int end, skia::textlayout::RectHeightStyle height_style, skia::textlayout::RectWidthStyle width_style)
Definition paragraph.cc:170
SKWASM_EXPORT TextBoxList * paragraph_getBoxesForPlaceholders(Skwasm::Paragraph *paragraph)
Definition paragraph.cc:181
SKWASM_EXPORT size_t textBoxList_getLength(TextBoxList *list)
Definition paragraph.cc:159
SKWASM_EXPORT skia::textlayout::LineMetrics * paragraph_getLineMetricsAtIndex(Skwasm::Paragraph *paragraph, size_t line_number)
Definition paragraph.cc:137
SKWASM_EXPORT skia::textlayout::TextDirection textBoxList_getBoxAtIndex(TextBoxList *list, size_t index, SkRect *out_rect)
Definition paragraph.cc:164
SKWASM_EXPORT SkScalar paragraph_getMinIntrinsicWidth(Skwasm::Paragraph *paragraph)
Definition paragraph.cc:31
SKWASM_EXPORT SkScalar paragraph_getMaxIntrinsicWidth(Skwasm::Paragraph *paragraph)
Definition paragraph.cc:36
SKWASM_EXPORT SkScalar paragraph_getIdeographicBaseline(Skwasm::Paragraph *paragraph)
Definition paragraph.cc:46
SKWASM_EXPORT void textBoxList_dispose(TextBoxList *list)
Definition paragraph.cc:154
SKWASM_EXPORT bool paragraph_getDidExceedMaxLines(Skwasm::Paragraph *paragraph)
Definition paragraph.cc:50
SKWASM_EXPORT int32_t paragraph_getPositionForOffset(Skwasm::Paragraph *paragraph, SkScalar offset_x, SkScalar offset_y, skia::textlayout::Affinity *out_affinity)
Definition paragraph.cc:61
SKWASM_EXPORT void paragraph_layout(Skwasm::Paragraph *paragraph, SkScalar width)
Definition paragraph.cc:55
SKWASM_EXPORT void paragraph_dispose(Skwasm::Paragraph *paragraph)
Definition paragraph.cc:13
SKWASM_EXPORT SkScalar paragraph_getHeight(Skwasm::Paragraph *paragraph)
Definition paragraph.cc:22
std::unique_ptr< skia::textlayout::Paragraph > skia_paragraph
Definition text_types.h:49
std::vector< skia::textlayout::TextBox > boxes
Definition paragraph.cc:151
const size_t start
const size_t end