Skip to content

Instantly share code, notes, and snippets.

@jonahwilliams
Created January 17, 2025 18:45
Show Gist options
  • Save jonahwilliams/29ccffa43446da438c544ef12371225a to your computer and use it in GitHub Desktop.
Save jonahwilliams/29ccffa43446da438c544ef12371225a to your computer and use it in GitHub Desktop.
diff --git a/engine/src/flutter/impeller/typographer/backends/skia/typographer_context_skia.cc b/engine/src/flutter/impeller/typographer/backends/skia/typographer_context_skia.cc
index d4082760bf..606c6142ab 100644
--- a/engine/src/flutter/impeller/typographer/backends/skia/typographer_context_skia.cc
+++ b/engine/src/flutter/impeller/typographer/backends/skia/typographer_context_skia.cc
@@ -38,11 +38,16 @@
#include "include/core/SkPaint.h"
#include "include/core/SkSize.h"
+#include "include/core/SkTypes.h"
+#include "src/base/SkArenaAlloc.h"
+#include "src/core/SkGlyph.h"
+#include "src/core/SkStrikeSpec.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkBlendMode.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkFont.h"
#include "third_party/skia/include/core/SkSurface.h"
+#include "third_party/skia/src/core/SkStrike.h"
namespace impeller {
@@ -224,6 +229,27 @@ static void DrawGlyph(SkCanvas* canvas,
sk_font.setSubpixel(true);
sk_font.setSize(sk_font.getSize() * scaled_font.scale);
+ SkStrikeSpec spec = SkStrikeSpec::MakeWithNoDevice(sk_font);
+ SkArenaAlloc alloc(1024);
+ auto scaler_context = spec.createScalerContext();
+ // Subpixel adjustment would go in the glyph ID here.
+ // constexpr SkPackedGlyphID(SkGlyphID glyphID, SkFixed x, SkFixed y)
+ //
+ SkGlyph sk_glyph =
+ scaler_context->makeGlyph(SkPackedGlyphID(glyph_id), &alloc);
+
+ sk_sp<SkStrike> strike = spec.findOrCreateStrike();
+ strike->lock();
+ if (!strike->prepareForImage(&sk_glyph)) {
+ VALIDATION_LOG << "Failed to prepare glyph";
+ }
+ strike->unlock();
+
+ // PTR to image data;
+ sk_glyph.image();
+ // image data dim?
+ sk_glyph.glyphRect();
+
auto glyph_color = prop.has_value() ? prop->color.ToARGB() : SK_ColorBLACK;
SkPaint glyph_paint;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment