Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1fa6d0d authored by Ben Wagner's avatar Ben Wagner
Browse files

Use UTF32 directly in HarfBuzz<->Skia interface.

This fixes a TODO to use kUTF32_TextEncoding directly. This avoids
encoding UTF32 codepoints from HarfBuzz into UTF16 to pass to Skia,
which will then re-decode to UTF32. This also removes a use of
SkUtils.h which Skia desires to move to private use.

Change-Id: I087f4216c25f7874e496920cd33e2f109530c397
parent 0d198d3a
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@
#include <SkPoint.h>
#include <SkRect.h>
#include <SkTypeface.h>
#include <SkUtils.h>

#include <hb.h>

@@ -82,17 +81,16 @@ static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint
static hb_bool_t harfbuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoint_t unicode, hb_codepoint_t variationSelector, hb_codepoint_t* glyph, void* userData)
{
    HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData);
    SkPaint* paint = hbFontData->m_paint;
    paint->setTextEncoding(SkPaint::kUTF32_TextEncoding);

    if (unicode > 0x10ffff) {
        unicode = 0xfffd;
    }
    SkPaint* paint = hbFontData->m_paint;
    // It would be better to use kUTF32_TextEncoding directly
    paint->setTextEncoding(SkPaint::kUTF16_TextEncoding);
    SkUnichar unichar = unicode;

    uint16_t glyph16;
    uint16_t unichar[2];
    size_t size = SkUTF16_FromUnichar(unicode, unichar);
    paint->textToGlyphs(unichar, size * sizeof(*unichar), &glyph16);
    paint->textToGlyphs(&unichar, sizeof(unichar), &glyph16);
    *glyph = glyph16;
    return !!*glyph;
}