From ff7b6654d737983a76d12dce9a63f535983bf2f7 Mon Sep 17 00:00:00 2001 From: PengKejie Date: Thu, 15 Aug 2024 17:46:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3skia=E8=B7=A8=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E7=BC=96=E8=AF=91=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PengKejie --- modules/skshaper/include/SkShaper.h | 8 ++++ modules/skshaper/src/SkShaper_primitive.cpp | 45 ++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/modules/skshaper/include/SkShaper.h b/modules/skshaper/include/SkShaper.h index f63d4a62c3..44b2d9d601 100644 --- a/modules/skshaper/include/SkShaper.h +++ b/modules/skshaper/include/SkShaper.h @@ -45,6 +45,10 @@ class SkFont; class SkFontMgr; class SkUnicode; +#ifdef USE_SKIA_TXT +namespace SkiaRsText { +#endif + class SKSHAPER_API SkShaper { public: static std::unique_ptr MakePrimitive(); @@ -334,4 +338,8 @@ private: }; #endif +#ifdef USE_SKIA_TXT +} +using SkShaper = SkiaRsText::SkShaper; +#endif #endif // SkShaper_DEFINED diff --git a/modules/skshaper/src/SkShaper_primitive.cpp b/modules/skshaper/src/SkShaper_primitive.cpp index 33d829006e..290bb66950 100644 --- a/modules/skshaper/src/SkShaper_primitive.cpp +++ b/modules/skshaper/src/SkShaper_primitive.cpp @@ -12,14 +12,20 @@ #include "modules/skshaper/include/SkShaper.h" #include "src/utils/SkUTF.h" -#ifndef USE_SKIA_TXT +#ifdef USE_SKIA_TXT +namespace SkiaRsText{ +#endif class SkShaperPrimitive : public SkShaper { public: SkShaperPrimitive() {} private: void shape(const char* utf8, size_t utf8Bytes, +#ifdef USE_SKIA_TXT + const RSFont& srcFont, +#else const SkFont& srcFont, +#endif bool leftToRight, SkScalar width, RunHandler*) const override; @@ -75,7 +81,11 @@ static inline bool is_breaking_whitespace(SkUnichar c) { } static size_t linebreak(const char text[], const char stop[], +#ifdef USE_SKIA_TXT + const RSFont& font, SkScalar width, +#else const SkFont& font, SkScalar width, +#endif SkScalar* advance, size_t* trailing) { @@ -141,12 +151,20 @@ void SkShaperPrimitive::shape(const char* utf8, size_t utf8Bytes, SkScalar width, RunHandler* handler) const { +#ifdef USE_SKIA_TXT + RSFont skfont; +#else SkFont skfont; +#endif if (!font.atEnd()) { font.consume(); skfont = font.currentFont(); } else { +#ifdef USE_SKIA_TXT + skfont.SetTypeface(RSTypeface::MakeDefault()); +#else skfont.setTypeface(sk_ref_sp(skfont.getTypefaceOrDefault())); +#endif } SkASSERT(skfont.getTypeface()); bool skbidi = 0; @@ -173,22 +191,40 @@ void SkShaperPrimitive::shape(const char* utf8, size_t utf8Bytes, } void SkShaperPrimitive::shape(const char* utf8, size_t utf8Bytes, +#ifdef USE_SKIA_TXT + const RSFont& font, +#else const SkFont& font, +#endif bool leftToRight, SkScalar width, RunHandler* handler) const { sk_ignore_unused_variable(leftToRight); +#ifdef USE_SKIA_TXT + int glyphCount = font.CountText(utf8, utf8Bytes, RSDrawing::TextEncoding::UTF8); +#else int glyphCount = font.countText(utf8, utf8Bytes, SkTextEncoding::kUTF8); +#endif + if (glyphCount < 0) { return; } std::unique_ptr glyphs(new SkGlyphID[glyphCount]); +#ifdef USE_SKIA_TXT + font.TextToGlyphs(utf8, utf8Bytes, RSDrawing::TextEncoding::UTF8, glyphs.get(), glyphCount); +#else font.textToGlyphs(utf8, utf8Bytes, SkTextEncoding::kUTF8, glyphs.get(), glyphCount); +#endif std::unique_ptr advances(new SkScalar[glyphCount]); +#ifdef USE_SKIA_TXT + font.GetWidths(glyphs.get(), glyphCount, advances.get(), nullptr); +#else font.getWidthsBounds(glyphs.get(), glyphCount, advances.get(), nullptr, nullptr); +#endif + size_t glyphOffset = 0; size_t utf8Offset = 0; @@ -202,7 +238,11 @@ void SkShaperPrimitive::shape(const char* utf8, size_t utf8Bytes, const RunHandler::RunInfo info = { font, 0, +#ifdef USE_SKIA_TXT + { font.MeasureText(utf8, bytesVisible, RSDrawing::TextEncoding::UTF8), 0 }, +#else { font.measureText(utf8, bytesVisible, SkTextEncoding::kUTF8), 0 }, +#endif numGlyphs, RunHandler::Range(utf8Offset, bytesVisible) }; @@ -240,5 +280,6 @@ void SkShaperPrimitive::shape(const char* utf8, size_t utf8Bytes, return; } - +#ifdef USE_SKIA_TXT +} #endif -- Gitee