From ea1e017086a4c9442bcae6641e340745cbf657e7 Mon Sep 17 00:00:00 2001 From: Samuel Scheit Date: Sun, 13 Oct 2024 23:03:17 +0000 Subject: [PATCH] fix: canvas debug information not showing --- packages/skia/cpp/rnskia/RNSkDomView.cpp | 12 ++++++++---- packages/skia/cpp/rnskia/RNSkDomView.h | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/skia/cpp/rnskia/RNSkDomView.cpp b/packages/skia/cpp/rnskia/RNSkDomView.cpp index 7e53e71ab7..c632c08d58 100644 --- a/packages/skia/cpp/rnskia/RNSkDomView.cpp +++ b/packages/skia/cpp/rnskia/RNSkDomView.cpp @@ -17,7 +17,13 @@ RNSkDomRenderer::RNSkDomRenderer(std::function requestRedraw, std::shared_ptr context) : RNSkRenderer(requestRedraw), _platformContext(std::move(context)), _renderLock(std::make_shared()), - _renderTimingInfo("SKIA/RENDER") {} + _renderTimingInfo("SKIA/RENDER") { + + auto style = SkFontStyle::Normal(); + auto fontMgr = _platformContext->createFontMgr(); + auto _typeface = fontMgr->matchFamilyStyle("Arial", style); + _font = SkFont(_typeface, 14); +} RNSkDomRenderer::~RNSkDomRenderer() { if (_root != nullptr) { @@ -130,12 +136,10 @@ void RNSkDomRenderer::renderDebugOverlays(SkCanvas *canvas) { std::string debugString = stream.str(); // Set up debug font/paints - auto font = SkFont(); - font.setSize(14); auto paint = SkPaint(); paint.setColor(SkColors::kRed); canvas->drawSimpleText(debugString.c_str(), debugString.size(), - SkTextEncoding::kUTF8, 8, 18, font, paint); + SkTextEncoding::kUTF8, 8, 18, _font, paint); } } // namespace RNSkia diff --git a/packages/skia/cpp/rnskia/RNSkDomView.h b/packages/skia/cpp/rnskia/RNSkDomView.h index 8f6bfec12b..9dd194b9eb 100644 --- a/packages/skia/cpp/rnskia/RNSkDomView.h +++ b/packages/skia/cpp/rnskia/RNSkDomView.h @@ -23,6 +23,7 @@ #include "include/core/SkBBHFactory.h" #include "include/core/SkCanvas.h" #include "include/core/SkPictureRecorder.h" +#include "include/core/SkFont.h" #pragma clang diagnostic pop @@ -63,6 +64,7 @@ class RNSkDomRenderer : public RNSkRenderer, RNSkTimingInfo _renderTimingInfo; std::mutex _rootLock; + SkFont _font; }; class RNSkDomView : public RNSkView {