Flutter Engine
flutter::Paragraph Class Reference

#include <paragraph.h>

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

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 getWordBoundary (unsigned offset)
 
Dart_Handle getLineBoundary (unsigned offset)
 
tonic::Float64List computeLineMetrics ()
 
size_t GetAllocationSize () const override
 
- 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
 
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)
 
static void RegisterNatives (tonic::DartLibraryNatives *natives)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields {
  kPeerIndex,
  kWrapperInfoIndex,
  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 21 of file paragraph.h.

Constructor & Destructor Documentation

◆ ~Paragraph()

flutter::Paragraph::~Paragraph ( )
overridedefault

Member Function Documentation

◆ alphabeticBaseline()

double flutter::Paragraph::alphabeticBaseline ( )

Definition at line 74 of file paragraph.cc.

74  {
75  return m_paragraph->GetAlphabeticBaseline();
76 }

◆ computeLineMetrics()

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

Definition at line 165 of file paragraph.cc.

References txt::LineMetrics::ascent, txt::LineMetrics::baseline, txt::LineMetrics::descent, txt::LineMetrics::hard_break, txt::LineMetrics::left, txt::LineMetrics::line_number, txt::LineMetrics::unscaled_ascent, and txt::LineMetrics::width.

165  {
166  std::vector<txt::LineMetrics> metrics = m_paragraph->GetLineMetrics();
167 
168  // Layout:
169  // boxes.size() groups of 9 which are the line metrics
170  // properties
171  tonic::Float64List result(
172  Dart_NewTypedData(Dart_TypedData_kFloat64, metrics.size() * 9));
173  uint64_t position = 0;
174  for (uint64_t i = 0; i < metrics.size(); i++) {
175  const txt::LineMetrics& line = metrics[i];
176  result[position++] = static_cast<double>(line.hard_break);
177  result[position++] = line.ascent;
178  result[position++] = line.descent;
179  result[position++] = line.unscaled_ascent;
180  // We add then round to get the height. The
181  // definition of height here is different
182  // than the one in LibTxt.
183  result[position++] = round(line.ascent + line.descent);
184  result[position++] = line.width;
185  result[position++] = line.left;
186  result[position++] = line.baseline;
187  result[position++] = static_cast<double>(line.line_number);
188  }
189 
190  return result;
191 }
double unscaled_ascent
Definition: line_metrics.h:50

◆ Create()

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

Definition at line 26 of file paragraph.h.

References height, and width.

Referenced by flutter::ParagraphBuilder::build().

27  {
28  auto paragraph = fml::MakeRefCounted<Paragraph>(std::move(txt_paragraph));
29  paragraph->AssociateWithDartWrapper(paragraph_handle);
30  }

◆ didExceedMaxLines()

bool flutter::Paragraph::didExceedMaxLines ( )

Definition at line 82 of file paragraph.cc.

82  {
83  return m_paragraph->DidExceedMaxLines();
84 }

◆ GetAllocationSize()

size_t flutter::Paragraph::GetAllocationSize ( ) const
overridevirtual

Reimplemented from tonic::DartWrappable.

Definition at line 47 of file paragraph.cc.

47  {
48  // We don't have an accurate accounting of the paragraph's memory consumption,
49  // so return a fixed size to indicate that its impact is more than the size
50  // of the Paragraph class.
51  return 2000;
52 }

◆ getLineBoundary()

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

Definition at line 150 of file paragraph.cc.

150  {
151  std::vector<txt::LineMetrics> metrics = m_paragraph->GetLineMetrics();
152  int line_start = -1;
153  int line_end = -1;
154  for (txt::LineMetrics& line : metrics) {
155  if (offset >= line.start_index && offset <= line.end_index) {
156  line_start = line.start_index;
157  line_end = line.end_index;
158  break;
159  }
160  }
161  std::vector<int> result = {line_start, line_end};
163 }

◆ getPositionForOffset()

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

Definition at line 134 of file paragraph.cc.

References txt::Paragraph::PositionWithAffinity::affinity, and txt::Paragraph::PositionWithAffinity::position.

134  {
136  m_paragraph->GetGlyphPositionAtCoordinate(dx, dy);
137  std::vector<size_t> result = {
138  pos.position, // size_t already
139  static_cast<size_t>(pos.affinity) // affinity (enum)
140  };
142 }

◆ getRectsForPlaceholders()

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

Definition at line 128 of file paragraph.cc.

References flutter::EncodeTextBoxes().

128  {
129  std::vector<txt::Paragraph::TextBox> boxes =
130  m_paragraph->GetRectsForPlaceholders();
131  return EncodeTextBoxes(boxes);
132 }
static tonic::Float32List EncodeTextBoxes(const std::vector< txt::Paragraph::TextBox > &boxes)
Definition: paragraph.cc:98

◆ getRectsForRange()

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

Definition at line 118 of file paragraph.cc.

References flutter::EncodeTextBoxes().

121  {
122  std::vector<txt::Paragraph::TextBox> boxes = m_paragraph->GetRectsForRange(
123  start, end, static_cast<txt::Paragraph::RectHeightStyle>(boxHeightStyle),
124  static_cast<txt::Paragraph::RectWidthStyle>(boxWidthStyle));
125  return EncodeTextBoxes(boxes);
126 }
static tonic::Float32List EncodeTextBoxes(const std::vector< txt::Paragraph::TextBox > &boxes)
Definition: paragraph.cc:98

◆ getWordBoundary()

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

Definition at line 144 of file paragraph.cc.

References txt::Paragraph::Range< T >::end, and txt::Paragraph::Range< T >::start.

144  {
145  txt::Paragraph::Range<size_t> point = m_paragraph->GetWordBoundary(offset);
146  std::vector<size_t> result = {point.start, point.end};
148 }

◆ height()

double flutter::Paragraph::height ( )

Definition at line 58 of file paragraph.cc.

58  {
59  return m_paragraph->GetHeight();
60 }

◆ ideographicBaseline()

double flutter::Paragraph::ideographicBaseline ( )

Definition at line 78 of file paragraph.cc.

78  {
79  return m_paragraph->GetIdeographicBaseline();
80 }

◆ layout()

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

Definition at line 86 of file paragraph.cc.

86  {
87  m_paragraph->Layout(width);
88 }

◆ longestLine()

double flutter::Paragraph::longestLine ( )

Definition at line 62 of file paragraph.cc.

62  {
63  return m_paragraph->GetLongestLine();
64 }

◆ maxIntrinsicWidth()

double flutter::Paragraph::maxIntrinsicWidth ( )

Definition at line 70 of file paragraph.cc.

70  {
71  return m_paragraph->GetMaxIntrinsicWidth();
72 }

◆ minIntrinsicWidth()

double flutter::Paragraph::minIntrinsicWidth ( )

Definition at line 66 of file paragraph.cc.

66  {
67  return m_paragraph->GetMinIntrinsicWidth();
68 }

◆ paint()

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

Definition at line 90 of file paragraph.cc.

References flutter::Canvas::canvas().

90  {
91  SkCanvas* sk_canvas = canvas->canvas();
92  if (!sk_canvas) {
93  return;
94  }
95  m_paragraph->Paint(sk_canvas, x, y);
96 }

◆ RegisterNatives()

static void flutter::Paragraph::RegisterNatives ( tonic::DartLibraryNatives natives)
static

◆ width()

double flutter::Paragraph::width ( )

Definition at line 54 of file paragraph.cc.

54  {
55  return m_paragraph->GetMaxWidth();
56 }

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