9 #include "flutter/display_list/geometry/dl_path.h"
10 #include "flutter/fml/logging.h"
11 #include "fml/status.h"
15 #include "third_party/skia/include/core/SkFont.h"
16 #include "third_party/skia/include/core/SkFontMetrics.h"
17 #include "third_party/skia/include/core/SkPaint.h"
18 #include "third_party/skia/include/core/SkRect.h"
19 #include "third_party/skia/modules/skparagraph/include/Paragraph.h"
20 #include "third_party/skia/src/core/SkStrikeSpec.h"
21 #include "third_party/skia/src/core/SkTextBlobPriv.h"
26 auto& font = run.font();
27 auto typeface = std::make_shared<TypefaceSkia>(font.refTypeface());
29 SkFontMetrics sk_metrics;
30 font.getMetrics(&sk_metrics);
34 metrics.
embolden = font.isEmbolden();
35 metrics.
skewX = font.getSkewX();
36 metrics.
scaleX = font.getScaleX();
38 return Font{std::move(typeface), metrics, alignment};
42 return Rect::MakeLTRB(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
46 const sk_sp<SkTextBlob>& blob) {
47 bool has_color =
false;
48 std::vector<TextRun> runs;
49 for (SkTextBlobRunIterator run(blob.get()); !run.done(); run.next()) {
50 SkStrikeSpec strikeSpec = SkStrikeSpec::MakeWithNoDevice(run.font());
51 SkBulkGlyphMetricsAndPaths paths{strikeSpec};
52 SkSpan<const SkGlyph*> glyphs =
53 paths.glyphs(SkSpan(run.glyphs(), run.glyphCount()));
55 for (
const auto& glyph : glyphs) {
56 has_color |= glyph->isColor();
60 if (run.font().isSubpixel() && run.font().isBaselineSnap() && !has_color) {
64 switch (run.positioning()) {
65 case SkTextBlobRunIterator::kFull_Positioning: {
66 std::vector<TextRun::GlyphPosition> positions;
67 positions.reserve(run.glyphCount());
68 for (
auto i = 0u; i < run.glyphCount(); i++) {
70 const SkPoint* glyph_points = run.points();
71 const SkPoint* point = glyph_points + i;
81 runs.emplace_back(text_run);
85 FML_DLOG(ERROR) <<
"Unimplemented.";
89 return std::make_shared<TextFrame>(
90 runs,
ToRect(blob->bounds()), has_color,
91 [blob]() -> fml::StatusOr<flutter::DlPath> {
92 SkPath path = skia::textlayout::Paragraph::GetPath(blob.get());
94 return fml::Status(fml::StatusCode::kCancelled,
"No path available");
96 SkPath transformed = path.makeTransform(
97 SkMatrix::Translate(blob->bounds().left(), blob->bounds().top()));
Describes a typeface along with any modifications to its intrinsic properties.
Represents a collection of positioned glyphs from a specific font.
static Font ToFont(const SkTextBlobRunIterator &run, AxisAlignment alignment)
static Rect ToRect(const SkRect &rect)
AxisAlignment
Determines the axis along which there is subpixel positioning.
std::shared_ptr< TextFrame > MakeTextFrameFromTextBlobSkia(const sk_sp< SkTextBlob > &blob)
Describes the modifications made to the intrinsic properties of a typeface.
The glyph index in the typeface.
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)