Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
flutter::Paragraph Class Reference

#include <paragraph.h>

Inheritance diagram for flutter::Paragraph:
flutter::RefCountedDartWrappable< Paragraph > fml::RefCountedThreadSafe< Paragraph > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase txt::ParagraphSkia

Public Member Functions

 ~Paragraph () override
 
double width ()
 
double height ()
 
double longestLine ()
 
double minIntrinsicWidth ()
 
double maxIntrinsicWidth ()
 
double alphabeticBaseline ()
 
double ideographicBaseline ()
 
bool didExceedMaxLines ()
 
void layout (double width)
 
void paint (Canvas *canvas, double x, double y)
 
tonic::Float32List getRectsForRange (unsigned start, unsigned end, unsigned boxHeightStyle, unsigned boxWidthStyle)
 
tonic::Float32List getRectsForPlaceholders ()
 
Dart_Handle getPositionForOffset (double dx, double dy)
 
Dart_Handle getGlyphInfoAt (unsigned utf16Offset, Dart_Handle constructor) const
 
Dart_Handle getClosestGlyphInfo (double dx, double dy, Dart_Handle constructor) const
 
Dart_Handle getWordBoundary (unsigned offset)
 
Dart_Handle getLineBoundary (unsigned offset)
 
tonic::Float64List computeLineMetrics () const
 
Dart_Handle getLineMetricsAt (int lineNumber, Dart_Handle constructor) const
 
size_t getNumberOfLines () const
 
int getLineNumberAt (size_t utf16Offset) const
 
void dispose ()
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< Paragraph >
virtual void RetainDartWrappableReference () const override
 
virtual void ReleaseDartWrappableReference () const override
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< Paragraph >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
virtual void RetainDartWrappableReference () const =0
 
virtual void ReleaseDartWrappableReference () const =0
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Static Public Member Functions

static void Create (Dart_Handle paragraph_handle, std::unique_ptr< txt::Paragraph > txt_paragraph)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields { kPeerIndex , kNumberOfNativeFields }
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< Paragraph >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

Definition at line 15 of file paragraph.h.

Constructor & Destructor Documentation

◆ ~Paragraph()

flutter::Paragraph::~Paragraph ( )
overridedefault

Member Function Documentation

◆ alphabeticBaseline()

double flutter::Paragraph::alphabeticBaseline ( )

Definition at line 49 of file paragraph.cc.

49 {
50 return m_paragraph_->GetAlphabeticBaseline();
51}

◆ computeLineMetrics()

tonic::Float64List flutter::Paragraph::computeLineMetrics ( ) const

Definition at line 187 of file paragraph.cc.

187 {
188 std::vector<txt::LineMetrics> metrics = m_paragraph_->GetLineMetrics();
189
190 // Layout:
191 // boxes.size() groups of 9 which are the line metrics
192 // properties
193 tonic::Float64List result(
194 Dart_NewTypedData(Dart_TypedData_kFloat64, metrics.size() * 9));
195 uint64_t position = 0;
196 for (uint64_t i = 0; i < metrics.size(); i++) {
197 const txt::LineMetrics& line = metrics[i];
198 result[position++] = static_cast<double>(line.hard_break);
199 result[position++] = line.ascent;
200 result[position++] = line.descent;
201 result[position++] = line.unscaled_ascent;
202 // We add then round to get the height. The
203 // definition of height here is different
204 // than the one in LibTxt.
205 result[position++] = round(line.ascent + line.descent);
206 result[position++] = line.width;
207 result[position++] = line.left;
208 result[position++] = line.baseline;
209 result[position++] = static_cast<double>(line.line_number);
210 }
211
212 return result;
213}
static void round(SkPoint *p)
@ Dart_TypedData_kFloat64
Definition: dart_api.h:2624
DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, intptr_t length)
GAsyncResult * result

◆ Create()

static void flutter::Paragraph::Create ( Dart_Handle  paragraph_handle,
std::unique_ptr< txt::Paragraph txt_paragraph 
)
inlinestatic

Definition at line 20 of file paragraph.h.

21 {
22 auto paragraph = fml::MakeRefCounted<Paragraph>(std::move(txt_paragraph));
23 paragraph->AssociateWithDartWrapper(paragraph_handle);
24 }

◆ didExceedMaxLines()

bool flutter::Paragraph::didExceedMaxLines ( )

Definition at line 57 of file paragraph.cc.

57 {
58 return m_paragraph_->DidExceedMaxLines();
59}

◆ dispose()

void flutter::Paragraph::dispose ( )

Definition at line 251 of file paragraph.cc.

251 {
252 m_paragraph_.reset();
254}

◆ getClosestGlyphInfo()

Dart_Handle flutter::Paragraph::getClosestGlyphInfo ( double  dx,
double  dy,
Dart_Handle  constructor 
) const

Definition at line 151 of file paragraph.cc.

153 {
155 const bool found =
156 m_paragraph_->GetClosestGlyphInfoAtCoordinate(dx, dy, &glyphInfo);
157 if (!found) {
158 return Dart_Null();
159 }
160 Dart_Handle handle = glyphInfoFrom(constructor, glyphInfo);
162 return handle;
163}
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
DART_EXPORT Dart_Handle Dart_Null(void)
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
Dart_Handle glyphInfoFrom(Dart_Handle constructor, const skia::textlayout::Paragraph::GlyphInfo &glyphInfo)
Definition: paragraph.cc:123
bool CheckAndHandleError(Dart_Handle handle)
Definition: dart_error.cc:33

◆ getGlyphInfoAt()

Dart_Handle flutter::Paragraph::getGlyphInfoAt ( unsigned  utf16Offset,
Dart_Handle  constructor 
) const

Definition at line 139 of file paragraph.cc.

140 {
142 const bool found = m_paragraph_->GetGlyphInfoAt(utf16Offset, &glyphInfo);
143 if (!found) {
144 return Dart_Null();
145 }
146 Dart_Handle handle = glyphInfoFrom(constructor, glyphInfo);
148 return handle;
149}

◆ getLineBoundary()

Dart_Handle flutter::Paragraph::getLineBoundary ( unsigned  offset)

Definition at line 172 of file paragraph.cc.

172 {
173 std::vector<txt::LineMetrics> metrics = m_paragraph_->GetLineMetrics();
174 int line_start = -1;
175 int line_end = -1;
176 for (txt::LineMetrics& line : metrics) {
177 if (utf16Offset >= line.start_index && utf16Offset <= line.end_index) {
178 line_start = line.start_index;
179 line_end = line.end_index;
180 break;
181 }
182 }
183 std::vector<int> result = {line_start, line_end};
184 return tonic::DartConverter<decltype(result)>::ToDart(result);
185}
Dart_Handle ToDart(const T &object)

◆ getLineMetricsAt()

Dart_Handle flutter::Paragraph::getLineMetricsAt ( int  lineNumber,
Dart_Handle  constructor 
) const

Definition at line 215 of file paragraph.cc.

216 {
218 const bool found = m_paragraph_->GetLineMetricsAt(lineNumber, &line);
219 if (!found) {
220 return Dart_Null();
221 }
222 std::array<Dart_Handle, 9> arguments = {
223 Dart_NewBoolean(line.fHardBreak),
224 Dart_NewDouble(line.fAscent),
225 Dart_NewDouble(line.fDescent),
226 Dart_NewDouble(line.fUnscaledAscent),
227 // We add then round to get the height. The
228 // definition of height here is different
229 // than the one in LibTxt.
230 Dart_NewDouble(round(line.fAscent + line.fDescent)),
231 Dart_NewDouble(line.fWidth),
232 Dart_NewDouble(line.fLeft),
233 Dart_NewDouble(line.fBaseline),
234 Dart_NewInteger(line.fLineNumber),
235 };
236
237 Dart_Handle handle =
238 Dart_InvokeClosure(constructor, arguments.size(), arguments.data());
240 return handle;
241}
DART_EXPORT Dart_Handle Dart_NewDouble(double value)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)
DART_EXPORT Dart_Handle Dart_NewBoolean(bool value)

◆ getLineNumberAt()

int flutter::Paragraph::getLineNumberAt ( size_t  utf16Offset) const

Definition at line 247 of file paragraph.cc.

247 {
248 return m_paragraph_->GetLineNumberAt(utf16Offset);
249}

◆ getNumberOfLines()

size_t flutter::Paragraph::getNumberOfLines ( ) const

Definition at line 243 of file paragraph.cc.

243 {
244 return m_paragraph_->GetNumberOfLines();
245}

◆ getPositionForOffset()

Dart_Handle flutter::Paragraph::getPositionForOffset ( double  dx,
double  dy 
)

Definition at line 113 of file paragraph.cc.

113 {
115 m_paragraph_->GetGlyphPositionAtCoordinate(dx, dy);
116 std::vector<size_t> result = {
117 pos.position, // size_t already
118 static_cast<size_t>(pos.affinity) // affinity (enum)
119 };
120 return tonic::DartConverter<decltype(result)>::ToDart(result);
121}
SkPoint pos

◆ getRectsForPlaceholders()

tonic::Float32List flutter::Paragraph::getRectsForPlaceholders ( )

Definition at line 107 of file paragraph.cc.

107 {
108 std::vector<txt::Paragraph::TextBox> boxes =
109 m_paragraph_->GetRectsForPlaceholders();
110 return EncodeTextBoxes(boxes);
111}
static tonic::Float32List EncodeTextBoxes(const std::vector< txt::Paragraph::TextBox > &boxes)
Definition: paragraph.cc:77

◆ getRectsForRange()

tonic::Float32List flutter::Paragraph::getRectsForRange ( unsigned  start,
unsigned  end,
unsigned  boxHeightStyle,
unsigned  boxWidthStyle 
)

Definition at line 97 of file paragraph.cc.

100 {
101 std::vector<txt::Paragraph::TextBox> boxes = m_paragraph_->GetRectsForRange(
102 start, end, static_cast<txt::Paragraph::RectHeightStyle>(boxHeightStyle),
103 static_cast<txt::Paragraph::RectWidthStyle>(boxWidthStyle));
104 return EncodeTextBoxes(boxes);
105}

◆ getWordBoundary()

Dart_Handle flutter::Paragraph::getWordBoundary ( unsigned  offset)

Definition at line 165 of file paragraph.cc.

165 {
167 m_paragraph_->GetWordBoundary(utf16Offset);
168 std::vector<size_t> result = {point.start, point.end};
169 return tonic::DartConverter<decltype(result)>::ToDart(result);
170}

◆ height()

double flutter::Paragraph::height ( )

Definition at line 33 of file paragraph.cc.

33 {
34 return m_paragraph_->GetHeight();
35}

◆ ideographicBaseline()

double flutter::Paragraph::ideographicBaseline ( )

Definition at line 53 of file paragraph.cc.

53 {
54 return m_paragraph_->GetIdeographicBaseline();
55}

◆ layout()

void flutter::Paragraph::layout ( double  width)

Definition at line 61 of file paragraph.cc.

61 {
62 m_paragraph_->Layout(width);
63}

◆ longestLine()

double flutter::Paragraph::longestLine ( )

Definition at line 37 of file paragraph.cc.

37 {
38 return m_paragraph_->GetLongestLine();
39}

◆ maxIntrinsicWidth()

double flutter::Paragraph::maxIntrinsicWidth ( )

Definition at line 45 of file paragraph.cc.

45 {
46 return m_paragraph_->GetMaxIntrinsicWidth();
47}

◆ minIntrinsicWidth()

double flutter::Paragraph::minIntrinsicWidth ( )

Definition at line 41 of file paragraph.cc.

41 {
42 return m_paragraph_->GetMinIntrinsicWidth();
43}

◆ paint()

void flutter::Paragraph::paint ( Canvas canvas,
double  x,
double  y 
)

Definition at line 65 of file paragraph.cc.

65 {
66 if (!m_paragraph_ || !canvas) {
67 // disposed.
68 return;
69 }
70
71 DisplayListBuilder* builder = canvas->builder();
72 if (builder) {
73 m_paragraph_->Paint(builder, x, y);
74 }
75}
double y
double x

◆ width()

double flutter::Paragraph::width ( )

Definition at line 29 of file paragraph.cc.

29 {
30 return m_paragraph_->GetMaxWidth();
31}

The documentation for this class was generated from the following files: