9 #include "flutter/fml/logging.h"
13 #include "third_party/skia/include/core/SkFont.h"
14 #include "third_party/skia/include/core/SkFontMetrics.h"
15 #include "third_party/skia/include/core/SkPaint.h"
16 #include "third_party/skia/include/core/SkRect.h"
17 #include "third_party/skia/src/core/SkStrikeSpec.h"
18 #include "third_party/skia/src/core/SkTextBlobPriv.h"
23 auto& font = run.font();
24 auto typeface = std::make_shared<TypefaceSkia>(font.refTypeface());
26 SkFontMetrics sk_metrics;
27 font.getMetrics(&sk_metrics);
31 metrics.
embolden = font.isEmbolden();
32 metrics.
skewX = font.getSkewX();
33 metrics.
scaleX = font.getScaleX();
35 return Font{std::move(typeface), metrics, alignment};
39 return Rect::MakeLTRB(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
43 const sk_sp<SkTextBlob>& blob) {
44 bool has_color =
false;
45 std::vector<TextRun> runs;
46 for (SkTextBlobRunIterator run(blob.get()); !run.done(); run.next()) {
47 SkStrikeSpec strikeSpec = SkStrikeSpec::MakeWithNoDevice(run.font());
48 SkBulkGlyphMetricsAndPaths paths{strikeSpec};
49 SkSpan<const SkGlyph*> glyphs =
50 paths.glyphs(SkSpan(run.glyphs(), run.glyphCount()));
52 for (
const auto& glyph : glyphs) {
53 has_color |= glyph->isColor();
57 if (run.font().isSubpixel() && run.font().isBaselineSnap() && !has_color) {
61 switch (run.positioning()) {
62 case SkTextBlobRunIterator::kFull_Positioning: {
63 std::vector<TextRun::GlyphPosition> positions;
64 positions.reserve(run.glyphCount());
65 for (
auto i = 0u; i < run.glyphCount(); i++) {
67 const SkPoint* glyph_points = run.points();
68 const SkPoint* point = glyph_points + i;
78 runs.emplace_back(text_run);
82 FML_DLOG(ERROR) <<
"Unimplemented.";
86 return std::make_shared<TextFrame>(runs,
ToRect(blob->bounds()), has_color);