29using PaintID = skt::ParagraphPainter::PaintID;
38 int txt_weight = (font_weight - 100) / 100;
70 const std::vector<DlPaint>& dl_paints,
71 bool impeller_enabled)
73 dl_paints_(dl_paints),
74 impeller_enabled_(impeller_enabled) {}
79 const SkPaintOrID&
paint)
override {
83 size_t paint_id = std::get<PaintID>(
paint);
86#ifdef IMPELLER_SUPPORTS_RENDERING
87 if (impeller_enabled_) {
88 if (ShouldRenderAsPath(dl_paints_[paint_id])) {
91 x + blob->bounds().left(),
y + blob->bounds().top()));
92 builder_->DrawPath(transformed, dl_paints_[paint_id]);
97 y, dl_paints_[paint_id]);
101 builder_->DrawTextBlob(blob,
x,
y, dl_paints_[paint_id]);
114 if (blur_sigma > 0.0) {
116 paint.setMaskFilter(&filter);
118 if (impeller_enabled_) {
123 builder_->DrawTextBlob(blob,
x,
y,
paint);
126 void drawRect(
const SkRect& rect,
const SkPaintOrID&
paint)
override {
127 size_t paint_id = std::get<PaintID>(
paint);
129 builder_->DrawRect(rect, dl_paints_[paint_id]);
132 void drawFilledRect(
const SkRect& rect,
133 const DecorationStyle& decor_style)
override {
134 DlPaint paint = toDlPaint(decor_style, DlDrawStyle::kFill);
135 builder_->DrawRect(rect,
paint);
139 const DecorationStyle& decor_style)
override {
140 builder_->DrawPath(
path, toDlPaint(decor_style));
147 const DecorationStyle& decor_style)
override {
155 auto dash_path_effect = decor_style.getDashPathEffect();
156#ifdef IMPELLER_SUPPORTS_RENDERING
157 if (impeller_enabled_ && dash_path_effect) {
158 auto path = dashedLine(x0, x1, y0, *dash_path_effect);
159 builder_->DrawPath(
path, toDlPaint(decor_style));
164 auto paint = toDlPaint(decor_style);
165 if (dash_path_effect) {
166 setPathEffect(
paint, *dash_path_effect);
171 void clipRect(
const SkRect& rect)
override {
172 builder_->ClipRect(rect, DlCanvas::ClipOp::kIntersect,
false);
176 builder_->Translate(dx, dy);
179 void save()
override { builder_->Save(); }
181 void restore()
override { builder_->Restore(); }
187 const DashPathEffect& dash_path_effect) {
195 path.moveTo(x0 + dx, y0);
196 dx += dash_path_effect.fOnLength;
197 path.lineTo(x0 + dx, y0);
200 dx += dash_path_effect.fOffLength;
215 return ((
paint.getColorSource() && !
paint.getColorSource()->asColor()) ||
216 paint.getDrawStyle() != DlDrawStyle::kFill);
219 DlPaint toDlPaint(
const DecorationStyle& decor_style,
222 paint.setDrawStyle(draw_style);
223 paint.setAntiAlias(
true);
225 paint.setStrokeWidth(decor_style.getStrokeWidth());
229 void setPathEffect(
DlPaint&
paint,
const DashPathEffect& dash_path_effect) {
233 std::array<SkScalar, 2> intervals{dash_path_effect.fOnLength,
234 dash_path_effect.fOffLength};
235 auto effect = DlDashPathEffect::Make(intervals.data(), intervals.size(), 0);
236 paint.setPathEffect(effect);
240 const std::vector<DlPaint>& dl_paints_;
241 const bool impeller_enabled_;
247 std::vector<flutter::DlPaint>&& dl_paints,
248 bool impeller_enabled)
249 : paragraph_(
std::move(paragraph)),
250 dl_paints_(dl_paints),
251 impeller_enabled_(impeller_enabled) {}
266 if (!line_metrics_) {
267 std::vector<skt::LineMetrics> metrics;
268 paragraph_->getLineMetrics(metrics);
270 line_metrics_.emplace();
271 line_metrics_styles_.reserve(
272 std::accumulate(metrics.begin(), metrics.end(), 0,
274 return a + b.fLineMetrics.size();
279 skm.fStartIndex, skm.fEndIndex, skm.fEndExcludingWhitespaces,
280 skm.fEndIncludingNewline, skm.fHardBreak);
281 txtm.
ascent = skm.fAscent;
284 txtm.
height = skm.fHeight;
285 txtm.
width = skm.fWidth;
286 txtm.
left = skm.fLeft;
290 for (
const auto& sk_iter : skm.fLineMetrics) {
292 line_metrics_styles_.push_back(SkiaToTxt(*sk_style_metrics.
text_style));
294 std::piecewise_construct, std::forward_as_tuple(sk_iter.first),
295 std::forward_as_tuple(&line_metrics_styles_.back(),
301 return line_metrics_.value();
306 return paragraph_->getLineMetricsAt(lineNumber, lineMetrics);
326 return paragraph_->didExceedMaxLines();
330 line_metrics_.reset();
331 line_metrics_styles_.clear();
332 paragraph_->layout(
width);
336 DisplayListParagraphPainter painter(builder, dl_paints_, impeller_enabled_);
337 paragraph_->paint(&painter,
x,
y);
344 RectHeightStyle rect_height_style,
345 RectWidthStyle rect_width_style) {
346 std::vector<skt::TextBox> skia_boxes = paragraph_->getRectsForRange(
350 std::vector<Paragraph::TextBox> boxes;
352 boxes.emplace_back(skia_box.rect,
360 std::vector<skt::TextBox> skia_boxes = paragraph_->getRectsForPlaceholders();
362 std::vector<Paragraph::TextBox> boxes;
364 boxes.emplace_back(skia_box.rect,
375 paragraph_->getGlyphPositionAtCoordinate(dx, dy);
377 return ParagraphSkia::PositionWithAffinity(
384 return paragraph_->getGlyphInfoAtUTF16Offset(
offset, glyphInfo);
391 return paragraph_->getClosestUTF16GlyphInfoAt(dx, dy, glyphInfo);
400 return paragraph_->lineNumber();
404 return paragraph_->getLineNumberAtUTF16Offset(codeUnitIndex);
412 txt.decoration_color =
skia.getDecorationColor();
413 txt.decoration_style =
415 txt.decoration_thickness_multiplier =
417 txt.font_weight = GetTxtFontWeight(
skia.getFontStyle().weight());
418 txt.font_style = GetTxtFontStyle(
skia.getFontStyle().slant());
422 for (
const SkString& font_family :
skia.getFontFamilies()) {
423 txt.font_families.emplace_back(font_family.c_str());
431 txt.locale =
skia.getLocale().c_str();
432 if (
skia.hasBackground()) {
433 PaintID background_id = std::get<PaintID>(
skia.getBackgroundPaintOrID());
434 txt.background = dl_paints_[background_id];
436 if (
skia.hasForeground()) {
437 PaintID foreground_id = std::get<PaintID>(
skia.getForegroundPaintOrID());
438 txt.foreground = dl_paints_[foreground_id];
441 txt.text_shadows.clear();
444 shadow.
offset = skia_shadow.fOffset;
446 shadow.
color = skia_shadow.fColor;
447 txt.text_shadows.emplace_back(shadow);
#define SkScalarToDouble(x)
static SkMatrix Translate(SkScalar dx, SkScalar dy)
static SkPath GetPath(SkTextBlob *textBlob)
const TextStyle * text_style
SkFontMetrics font_metrics
std::map< size_t, RunMetrics > run_metrics
double GetMaxIntrinsicWidth() override
bool DidExceedMaxLines() override
double GetHeight() override
ParagraphSkia(std::unique_ptr< skia::textlayout::Paragraph > paragraph, std::vector< flutter::DlPaint > &&dl_paints, bool impeller_enabled)
size_t GetNumberOfLines() const override
PositionWithAffinity GetGlyphPositionAtCoordinate(double dx, double dy) override
double GetAlphabeticBaseline() override
bool GetClosestGlyphInfoAtCoordinate(double dx, double dy, skia::textlayout::Paragraph::GlyphInfo *glyphInfo) const override
int GetLineNumberAt(size_t utf16Offset) const override
bool GetLineMetricsAt(int lineNumber, skia::textlayout::LineMetrics *lineMetrics) const override
double GetLongestLine() override
std::vector< LineMetrics > & GetLineMetrics() override
void Layout(double width) override
std::vector< TextBox > GetRectsForRange(size_t start, size_t end, RectHeightStyle rect_height_style, RectWidthStyle rect_width_style) override
std::vector< TextBox > GetRectsForPlaceholders() override
double GetMaxWidth() override
bool Paint(flutter::DisplayListBuilder *builder, double x, double y) override
bool GetGlyphInfoAt(unsigned offset, skia::textlayout::Paragraph::GlyphInfo *glyphInfo) const override
double GetMinIntrinsicWidth() override
Range< size_t > GetWordBoundary(size_t offset) override
double GetIdeographicBaseline() override
#define FML_DCHECK(condition)
static void drawPath(SkPath &path, SkCanvas *canvas, SkColor color, const SkRect &clip, SkPaint::Cap cap, SkPaint::Join join, SkPaint::Style style, SkPathFillType fill, SkScalar strokeWidth)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
std::shared_ptr< TextFrame > MakeTextFrameFromTextBlobSkia(const sk_sp< SkTextBlob > &blob)
skt::ParagraphPainter::PaintID PaintID
static constexpr SkPoint Make(float x, float y)