@@ -39,16 +39,17 @@ static Rect ToRect(const SkRect& rect) {
3939
4040static constexpr Scalar kScaleSize = 100000 .0f ;
4141
42- TextFrame MakeTextFrameFromTextBlobSkia (const sk_sp<SkTextBlob>& blob) {
42+ std::optional<TextFrame> MakeTextFrameFromTextBlobSkia (
43+ const sk_sp<SkTextBlob>& blob) {
44+ // Handling nullptr text blobs feels overly defensive here, as I don't
45+ // actually know if this happens.
4346 if (!blob) {
4447 return {};
4548 }
4649
47- TextFrame frame ;
48-
50+ std::vector<TextRun> runs ;
51+ bool has_color = false ;
4952 for (SkTextBlobRunIterator run (blob.get ()); !run.done (); run.next ()) {
50- TextRun text_run (ToFont (run));
51-
5253 // TODO(jonahwilliams): ask Skia for a public API to look this up.
5354 // https://github.com/flutter/flutter/issues/112005
5455 SkStrikeSpec strikeSpec = SkStrikeSpec::MakeWithNoDevice (run.font ());
@@ -57,12 +58,6 @@ TextFrame MakeTextFrameFromTextBlobSkia(const sk_sp<SkTextBlob>& blob) {
5758 const auto glyph_count = run.glyphCount ();
5859 const auto * glyphs = run.glyphs ();
5960 switch (run.positioning ()) {
60- case SkTextBlobRunIterator::kDefault_Positioning :
61- FML_DLOG (ERROR) << " Unimplemented." ;
62- break ;
63- case SkTextBlobRunIterator::kHorizontal_Positioning :
64- FML_DLOG (ERROR) << " Unimplemented." ;
65- break ;
6661 case SkTextBlobRunIterator::kFull_Positioning : {
6762 std::vector<SkRect> glyph_bounds;
6863 glyph_bounds.resize (glyph_count);
@@ -75,32 +70,32 @@ TextFrame MakeTextFrameFromTextBlobSkia(const sk_sp<SkTextBlob>& blob) {
7570 font.setSize (kScaleSize );
7671 font.getBounds (glyphs, glyph_count, glyph_bounds.data (), nullptr );
7772
73+ std::vector<TextRun::GlyphPosition> positions;
74+ positions.reserve (glyph_count);
7875 for (auto i = 0u ; i < glyph_count; i++) {
7976 // kFull_Positioning has two scalars per glyph.
8077 const SkPoint* glyph_points = run.points ();
8178 const auto * point = glyph_points + i;
8279 Glyph::Type type = paths.glyph (glyphs[i])->isColor ()
8380 ? Glyph::Type::kBitmap
8481 : Glyph::Type::kPath ;
82+ has_color |= type == Glyph::Type::kBitmap ;
8583
86- text_run. AddGlyph (
84+ positions. emplace_back (TextRun::GlyphPosition{
8785 Glyph{glyphs[i], type,
8886 ToRect (glyph_bounds[i]).Scale (font_size / kScaleSize )},
89- Point{point->x (), point->y ()});
87+ Point{point->x (), point->y ()}} );
9088 }
89+ TextRun text_run (ToFont (run), positions);
90+ runs.emplace_back (text_run);
9191 break ;
9292 }
93- case SkTextBlobRunIterator::kRSXform_Positioning :
94- FML_DLOG (ERROR) << " Unimplemented." ;
95- break ;
9693 default :
9794 FML_DLOG (ERROR) << " Unimplemented." ;
9895 continue ;
9996 }
100- frame.AddTextRun (std::move (text_run));
10197 }
102-
103- return frame;
98+ return TextFrame (runs, ToRect (blob->bounds ()), has_color);
10499}
105100
106101} // namespace impeller
0 commit comments