Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
paragraph.cc File Reference
#include "third_party/skia/modules/skparagraph/include/Paragraph.h"
#include "flutter/skwasm/export.h"
#include "flutter/skwasm/live_objects.h"
#include "flutter/skwasm/text/text_types.h"
#include "third_party/skia/include/core/SkScalar.h"
#include "third_party/skia/modules/skparagraph/include/DartTypes.h"
#include "third_party/skia/modules/skparagraph/include/TextStyle.h"

Go to the source code of this file.

Classes

struct  TextBoxList
 

Functions

SKWASM_EXPORT void paragraph_dispose (Skwasm::Paragraph *paragraph)
 
SKWASM_EXPORT SkScalar paragraph_getWidth (Skwasm::Paragraph *paragraph)
 
SKWASM_EXPORT SkScalar paragraph_getHeight (Skwasm::Paragraph *paragraph)
 
SKWASM_EXPORT SkScalar paragraph_getLongestLine (Skwasm::Paragraph *paragraph)
 
SKWASM_EXPORT SkScalar paragraph_getMinIntrinsicWidth (Skwasm::Paragraph *paragraph)
 
SKWASM_EXPORT SkScalar paragraph_getMaxIntrinsicWidth (Skwasm::Paragraph *paragraph)
 
SKWASM_EXPORT SkScalar paragraph_getAlphabeticBaseline (Skwasm::Paragraph *paragraph)
 
SKWASM_EXPORT SkScalar paragraph_getIdeographicBaseline (Skwasm::Paragraph *paragraph)
 
SKWASM_EXPORT bool paragraph_getDidExceedMaxLines (Skwasm::Paragraph *paragraph)
 
SKWASM_EXPORT void paragraph_layout (Skwasm::Paragraph *paragraph, SkScalar width)
 
SKWASM_EXPORT int32_t paragraph_getPositionForOffset (Skwasm::Paragraph *paragraph, SkScalar offset_x, SkScalar offset_y, skia::textlayout::Affinity *out_affinity)
 
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)
 
SKWASM_EXPORT bool paragraph_getGlyphInfoAt (Skwasm::Paragraph *paragraph, size_t index, SkRect *grapheme_layout_bounds, size_t *grapheme_code_unit_range, bool *boolean_flags)
 
SKWASM_EXPORT void paragraph_getWordBoundary (Skwasm::Paragraph *paragraph, unsigned int position, int32_t *out_range)
 
SKWASM_EXPORT size_t paragraph_getLineCount (Skwasm::Paragraph *paragraph)
 
SKWASM_EXPORT int paragraph_getLineNumberAt (Skwasm::Paragraph *paragraph, size_t character_index)
 
SKWASM_EXPORT skia::textlayout::LineMetrics * paragraph_getLineMetricsAtIndex (Skwasm::Paragraph *paragraph, size_t line_number)
 
SKWASM_EXPORT void textBoxList_dispose (TextBoxList *list)
 
SKWASM_EXPORT size_t textBoxList_getLength (TextBoxList *list)
 
SKWASM_EXPORT skia::textlayout::TextDirection textBoxList_getBoxAtIndex (TextBoxList *list, size_t index, SkRect *out_rect)
 
SKWASM_EXPORT TextBoxListparagraph_getBoxesForRange (Skwasm::Paragraph *paragraph, int start, int end, skia::textlayout::RectHeightStyle height_style, skia::textlayout::RectWidthStyle width_style)
 
SKWASM_EXPORT TextBoxListparagraph_getBoxesForPlaceholders (Skwasm::Paragraph *paragraph)
 
SKWASM_EXPORT int paragraph_getUnresolvedCodePoints (Skwasm::Paragraph *paragraph, SkUnichar *out_code_points, int out_length)
 

Function Documentation

◆ paragraph_dispose()

SKWASM_EXPORT void paragraph_dispose ( Skwasm::Paragraph paragraph)

Definition at line 13 of file paragraph.cc.

13 {
15 delete paragraph;
16}
uint32_t live_paragraph_count

References Skwasm::live_paragraph_count.

◆ paragraph_getAlphabeticBaseline()

SKWASM_EXPORT SkScalar paragraph_getAlphabeticBaseline ( Skwasm::Paragraph paragraph)

Definition at line 41 of file paragraph.cc.

41 {
42 return paragraph->skia_paragraph->getAlphabeticBaseline();
43}
std::unique_ptr< skia::textlayout::Paragraph > skia_paragraph
Definition text_types.h:49

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getBoxesForPlaceholders()

SKWASM_EXPORT TextBoxList * paragraph_getBoxesForPlaceholders ( Skwasm::Paragraph paragraph)

Definition at line 181 of file paragraph.cc.

182 {
184 return new TextBoxList{paragraph->skia_paragraph->getRectsForPlaceholders()};
185}
uint32_t live_text_box_list_count

References Skwasm::live_text_box_list_count, and Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getBoxesForRange()

SKWASM_EXPORT TextBoxList * paragraph_getBoxesForRange ( Skwasm::Paragraph paragraph,
int  start,
int  end,
skia::textlayout::RectHeightStyle  height_style,
skia::textlayout::RectWidthStyle  width_style 
)

Definition at line 170 of file paragraph.cc.

175 {
177 return new TextBoxList{paragraph->skia_paragraph->getRectsForRange(
178 start, end, height_style, width_style)};
179}
const size_t end

References end, Skwasm::live_text_box_list_count, Skwasm::Paragraph::skia_paragraph, and start.

◆ paragraph_getClosestGlyphInfoAtCoordinate()

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 at line 73 of file paragraph.cc.

80 { // 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}

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getDidExceedMaxLines()

SKWASM_EXPORT bool paragraph_getDidExceedMaxLines ( Skwasm::Paragraph paragraph)

Definition at line 50 of file paragraph.cc.

51 {
52 return paragraph->skia_paragraph->didExceedMaxLines();
53}

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getGlyphInfoAt()

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 at line 97 of file paragraph.cc.

103 { // 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}

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getHeight()

SKWASM_EXPORT SkScalar paragraph_getHeight ( Skwasm::Paragraph paragraph)

Definition at line 22 of file paragraph.cc.

22 {
23 return paragraph->skia_paragraph->getHeight();
24}

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getIdeographicBaseline()

SKWASM_EXPORT SkScalar paragraph_getIdeographicBaseline ( Skwasm::Paragraph paragraph)

Definition at line 46 of file paragraph.cc.

46 {
47 return paragraph->skia_paragraph->getIdeographicBaseline();
48}

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getLineCount()

SKWASM_EXPORT size_t paragraph_getLineCount ( Skwasm::Paragraph paragraph)

Definition at line 128 of file paragraph.cc.

128 {
129 return paragraph->skia_paragraph->lineNumber();
130}

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getLineMetricsAtIndex()

SKWASM_EXPORT skia::textlayout::LineMetrics * paragraph_getLineMetricsAtIndex ( Skwasm::Paragraph paragraph,
size_t  line_number 
)

Definition at line 137 of file paragraph.cc.

139 {
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}
uint32_t live_line_metrics_count

References Skwasm::live_line_metrics_count, and Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getLineNumberAt()

SKWASM_EXPORT int paragraph_getLineNumberAt ( Skwasm::Paragraph paragraph,
size_t  character_index 
)

Definition at line 132 of file paragraph.cc.

133 {
134 return paragraph->skia_paragraph->getLineNumberAtUTF16Offset(character_index);
135}

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getLongestLine()

SKWASM_EXPORT SkScalar paragraph_getLongestLine ( Skwasm::Paragraph paragraph)

Definition at line 26 of file paragraph.cc.

26 {
27 return paragraph->skia_paragraph->getLongestLine();
28}

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getMaxIntrinsicWidth()

SKWASM_EXPORT SkScalar paragraph_getMaxIntrinsicWidth ( Skwasm::Paragraph paragraph)

Definition at line 36 of file paragraph.cc.

36 {
37 return paragraph->skia_paragraph->getMaxIntrinsicWidth();
38}

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getMinIntrinsicWidth()

SKWASM_EXPORT SkScalar paragraph_getMinIntrinsicWidth ( Skwasm::Paragraph paragraph)

Definition at line 31 of file paragraph.cc.

31 {
32 return paragraph->skia_paragraph->getMinIntrinsicWidth();
33}

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getPositionForOffset()

SKWASM_EXPORT int32_t paragraph_getPositionForOffset ( Skwasm::Paragraph paragraph,
SkScalar  offset_x,
SkScalar  offset_y,
skia::textlayout::Affinity *  out_affinity 
)

Definition at line 61 of file paragraph.cc.

64 {
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}

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getUnresolvedCodePoints()

SKWASM_EXPORT int paragraph_getUnresolvedCodePoints ( Skwasm::Paragraph paragraph,
SkUnichar *  out_code_points,
int  out_length 
)

Definition at line 194 of file paragraph.cc.

197 {
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}

References character, and Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getWidth()

SKWASM_EXPORT SkScalar paragraph_getWidth ( Skwasm::Paragraph paragraph)

Definition at line 18 of file paragraph.cc.

18 {
19 return paragraph->skia_paragraph->getMaxWidth();
20}

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_getWordBoundary()

SKWASM_EXPORT void paragraph_getWordBoundary ( Skwasm::Paragraph paragraph,
unsigned int  position,
int32_t *  out_range 
)

Definition at line 118 of file paragraph.cc.

122 {
123 auto range = paragraph->skia_paragraph->getWordBoundary(position);
124 out_range[0] = range.start;
125 out_range[1] = range.end;
126}

References Skwasm::Paragraph::skia_paragraph.

◆ paragraph_layout()

SKWASM_EXPORT void paragraph_layout ( Skwasm::Paragraph paragraph,
SkScalar  width 
)

Definition at line 55 of file paragraph.cc.

56 {
57 paragraph->skia_paragraph->layout(width);
58}
int32_t width

References Skwasm::Paragraph::skia_paragraph, and width.

◆ textBoxList_dispose()

SKWASM_EXPORT void textBoxList_dispose ( TextBoxList list)

Definition at line 154 of file paragraph.cc.

154 {
156 delete list;
157}

References Skwasm::live_text_box_list_count.

◆ textBoxList_getBoxAtIndex()

SKWASM_EXPORT skia::textlayout::TextDirection textBoxList_getBoxAtIndex ( TextBoxList list,
size_t  index,
SkRect *  out_rect 
)

Definition at line 164 of file paragraph.cc.

164 {
165 const auto& box = list->boxes[index];
166 *out_rect = box.rect;
167 return box.direction;
168}
std::vector< skia::textlayout::TextBox > boxes
Definition paragraph.cc:151

References TextBoxList::boxes.

◆ textBoxList_getLength()

SKWASM_EXPORT size_t textBoxList_getLength ( TextBoxList list)

Definition at line 159 of file paragraph.cc.

159 {
160 return list->boxes.size();
161}

References TextBoxList::boxes.