9 #include "flutter/fml/logging.h"
11 #include "include/core/SkRect.h"
12 #include "third_party/skia/include/core/SkFont.h"
13 #include "third_party/skia/include/core/SkFontMetrics.h"
14 #include "third_party/skia/src/core/SkStrikeSpec.h"
15 #include "third_party/skia/src/core/SkTextBlobPriv.h"
20 auto& font = run.font();
21 auto typeface = std::make_shared<TypefaceSkia>(font.refTypeface());
23 SkFontMetrics sk_metrics;
24 font.getMetrics(&sk_metrics);
28 metrics.
embolden = font.isEmbolden();
29 metrics.
skewX = font.getSkewX();
30 metrics.
scaleX = font.getScaleX();
32 return Font{std::move(typeface), metrics};
36 return Rect::MakeLTRB(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
42 const sk_sp<SkTextBlob>& blob) {
43 bool has_color =
false;
44 std::vector<TextRun> runs;
45 for (SkTextBlobRunIterator run(blob.get()); !run.done(); run.next()) {
48 SkStrikeSpec strikeSpec = SkStrikeSpec::MakeWithNoDevice(run.font());
49 SkBulkGlyphMetricsAndPaths paths{strikeSpec};
51 const auto glyph_count = run.glyphCount();
52 const auto* glyphs = run.glyphs();
53 switch (run.positioning()) {
54 case SkTextBlobRunIterator::kFull_Positioning: {
55 std::vector<SkRect> glyph_bounds;
56 glyph_bounds.resize(glyph_count);
57 SkFont font = run.font();
58 auto font_size = font.getSize();
64 font.getBounds(glyphs, glyph_count, glyph_bounds.data(),
nullptr);
66 std::vector<TextRun::GlyphPosition> positions;
67 positions.reserve(glyph_count);
68 for (
auto i = 0u; i < glyph_count; i++) {
70 const SkPoint* glyph_points = run.points();
71 const auto* point = glyph_points + i;
72 Glyph::Type type = paths.glyph(glyphs[i])->isColor()
78 Glyph{glyphs[i], type,
80 Point{point->
x(), point->y()}});
83 runs.emplace_back(text_run);
87 FML_DLOG(ERROR) <<
"Unimplemented.";
91 return std::make_shared<TextFrame>(runs,
ToRect(blob->bounds()), has_color);