Flutter Engine
txt::ParagraphSkia Class Reference

#include <paragraph_skia.h>

Inheritance diagram for txt::ParagraphSkia:
txt::Paragraph

Public Member Functions

 ParagraphSkia (std::unique_ptr< skia::textlayout::Paragraph > paragraph)
 
virtual ~ParagraphSkia ()=default
 
double GetMaxWidth () override
 
double GetHeight () override
 
double GetLongestLine () override
 
double GetMinIntrinsicWidth () override
 
double GetMaxIntrinsicWidth () override
 
double GetAlphabeticBaseline () override
 
double GetIdeographicBaseline () override
 
std::vector< LineMetrics > & GetLineMetrics () override
 
bool DidExceedMaxLines () override
 
void Layout (double width) override
 
void Paint (SkCanvas *canvas, double x, double y) override
 
std::vector< TextBoxGetRectsForRange (size_t start, size_t end, RectHeightStyle rect_height_style, RectWidthStyle rect_width_style) override
 
std::vector< TextBoxGetRectsForPlaceholders () override
 
PositionWithAffinity GetGlyphPositionAtCoordinate (double dx, double dy) override
 
Range< size_t > GetWordBoundary (size_t offset) override
 
- Public Member Functions inherited from txt::Paragraph
virtual ~Paragraph ()=default
 

Additional Inherited Members

- Public Types inherited from txt::Paragraph
enum  Affinity {
  UPSTREAM,
  DOWNSTREAM
}
 
enum  RectHeightStyle {
  RectHeightStyle::kTight,
  RectHeightStyle::kMax,
  RectHeightStyle::kIncludeLineSpacingMiddle,
  RectHeightStyle::kIncludeLineSpacingTop,
  RectHeightStyle::kIncludeLineSpacingBottom,
  RectHeightStyle::kStrut
}
 
enum  RectWidthStyle {
  RectWidthStyle::kTight,
  RectWidthStyle::kMax
}
 

Detailed Description

Definition at line 29 of file paragraph_skia.h.

Constructor & Destructor Documentation

◆ ParagraphSkia()

txt::ParagraphSkia::ParagraphSkia ( std::unique_ptr< skia::textlayout::Paragraph >  paragraph)

Definition at line 88 of file paragraph_skia.cc.

89  : paragraph_(std::move(paragraph)) {}

◆ ~ParagraphSkia()

virtual txt::ParagraphSkia::~ParagraphSkia ( )
virtualdefault

Member Function Documentation

◆ DidExceedMaxLines()

bool txt::ParagraphSkia::DidExceedMaxLines ( )
overridevirtual

Implements txt::Paragraph.

Definition at line 152 of file paragraph_skia.cc.

152  {
153  return paragraph_->didExceedMaxLines();
154 }

◆ GetAlphabeticBaseline()

double txt::ParagraphSkia::GetAlphabeticBaseline ( )
overridevirtual

Implements txt::Paragraph.

Definition at line 144 of file paragraph_skia.cc.

144  {
145  return SkScalarToDouble(paragraph_->getAlphabeticBaseline());
146 }

◆ GetGlyphPositionAtCoordinate()

Paragraph::PositionWithAffinity txt::ParagraphSkia::GetGlyphPositionAtCoordinate ( double  dx,
double  dy 
)
overridevirtual

Implements txt::Paragraph.

Definition at line 194 of file paragraph_skia.cc.

196  {
197  skt::PositionWithAffinity skia_pos =
198  paragraph_->getGlyphPositionAtCoordinate(dx, dy);
199 
200  return ParagraphSkia::PositionWithAffinity(
201  skia_pos.position, static_cast<Affinity>(skia_pos.affinity));
202 }

◆ GetHeight()

double txt::ParagraphSkia::GetHeight ( )
overridevirtual

Implements txt::Paragraph.

Definition at line 95 of file paragraph_skia.cc.

95  {
96  return SkScalarToDouble(paragraph_->getHeight());
97 }

◆ GetIdeographicBaseline()

double txt::ParagraphSkia::GetIdeographicBaseline ( )
overridevirtual

Implements txt::Paragraph.

Definition at line 148 of file paragraph_skia.cc.

148  {
149  return SkScalarToDouble(paragraph_->getIdeographicBaseline());
150 }

◆ GetLineMetrics()

std::vector< LineMetrics > & txt::ParagraphSkia::GetLineMetrics ( )
overridevirtual

Implements txt::Paragraph.

Definition at line 103 of file paragraph_skia.cc.

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

103  {
104  if (!line_metrics_) {
105  std::vector<skt::LineMetrics> metrics;
106  paragraph_->getLineMetrics(metrics);
107 
108  line_metrics_.emplace();
109  for (const skt::LineMetrics& skm : metrics) {
110  LineMetrics& txtm = line_metrics_->emplace_back(
111  skm.fStartIndex, skm.fEndIndex, skm.fEndExcludingWhitespaces,
112  skm.fEndIncludingNewline, skm.fHardBreak);
113  txtm.ascent = skm.fAscent;
114  txtm.descent = skm.fDescent;
115  txtm.unscaled_ascent = skm.fUnscaledAscent;
116  txtm.height = skm.fHeight;
117  txtm.width = skm.fWidth;
118  txtm.left = skm.fLeft;
119  txtm.baseline = skm.fBaseline;
120  txtm.line_number = skm.fLineNumber;
121 
122  for (const auto& sk_iter : skm.fLineMetrics) {
123  const skt::StyleMetrics& sk_style_metrics = sk_iter.second;
124  line_metrics_styles_.push_back(SkiaToTxt(*sk_style_metrics.text_style));
125  txtm.run_metrics.emplace(
126  std::piecewise_construct, std::forward_as_tuple(sk_iter.first),
127  std::forward_as_tuple(&line_metrics_styles_.back(),
128  sk_style_metrics.font_metrics));
129  }
130  }
131  }
132 
133  return line_metrics_.value();
134 }

◆ GetLongestLine()

double txt::ParagraphSkia::GetLongestLine ( )
overridevirtual

Implements txt::Paragraph.

Definition at line 99 of file paragraph_skia.cc.

99  {
100  return SkScalarToDouble(paragraph_->getLongestLine());
101 }

◆ GetMaxIntrinsicWidth()

double txt::ParagraphSkia::GetMaxIntrinsicWidth ( )
overridevirtual

Implements txt::Paragraph.

Definition at line 140 of file paragraph_skia.cc.

140  {
141  return SkScalarToDouble(paragraph_->getMaxIntrinsicWidth());
142 }

◆ GetMaxWidth()

double txt::ParagraphSkia::GetMaxWidth ( )
overridevirtual

Implements txt::Paragraph.

Definition at line 91 of file paragraph_skia.cc.

91  {
92  return SkScalarToDouble(paragraph_->getMaxWidth());
93 }

◆ GetMinIntrinsicWidth()

double txt::ParagraphSkia::GetMinIntrinsicWidth ( )
overridevirtual

Implements txt::Paragraph.

Definition at line 136 of file paragraph_skia.cc.

136  {
137  return SkScalarToDouble(paragraph_->getMinIntrinsicWidth());
138 }

◆ GetRectsForPlaceholders()

std::vector< Paragraph::TextBox > txt::ParagraphSkia::GetRectsForPlaceholders ( )
overridevirtual

Implements txt::Paragraph.

Definition at line 182 of file paragraph_skia.cc.

182  {
183  std::vector<skt::TextBox> skia_boxes = paragraph_->getRectsForPlaceholders();
184 
185  std::vector<Paragraph::TextBox> boxes;
186  for (const skt::TextBox skia_box : skia_boxes) {
187  boxes.emplace_back(skia_box.rect,
188  static_cast<TextDirection>(skia_box.direction));
189  }
190 
191  return boxes;
192 }

◆ GetRectsForRange()

std::vector< Paragraph::TextBox > txt::ParagraphSkia::GetRectsForRange ( size_t  start,
size_t  end,
RectHeightStyle  rect_height_style,
RectWidthStyle  rect_width_style 
)
overridevirtual

Implements txt::Paragraph.

Definition at line 164 of file paragraph_skia.cc.

168  {
169  std::vector<skt::TextBox> skia_boxes = paragraph_->getRectsForRange(
170  start, end, static_cast<skt::RectHeightStyle>(rect_height_style),
171  static_cast<skt::RectWidthStyle>(rect_width_style));
172 
173  std::vector<Paragraph::TextBox> boxes;
174  for (const skt::TextBox skia_box : skia_boxes) {
175  boxes.emplace_back(skia_box.rect,
176  static_cast<TextDirection>(skia_box.direction));
177  }
178 
179  return boxes;
180 }

◆ GetWordBoundary()

Paragraph::Range< size_t > txt::ParagraphSkia::GetWordBoundary ( size_t  offset)
overridevirtual

Implements txt::Paragraph.

Definition at line 204 of file paragraph_skia.cc.

204  {
205  skt::SkRange<size_t> range = paragraph_->getWordBoundary(offset);
206  return Paragraph::Range<size_t>(range.start, range.end);
207 }

◆ Layout()

void txt::ParagraphSkia::Layout ( double  width)
overridevirtual

Implements txt::Paragraph.

Definition at line 156 of file paragraph_skia.cc.

156  {
157  paragraph_->layout(width);
158 }
int32_t width

◆ Paint()

void txt::ParagraphSkia::Paint ( SkCanvas *  canvas,
double  x,
double  y 
)
overridevirtual

Implements txt::Paragraph.

Definition at line 160 of file paragraph_skia.cc.

160  {
161  paragraph_->paint(canvas, x, y);
162 }

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