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

Commit f62034d8 authored by Raph Levien's avatar Raph Levien
Browse files

Initialize shaper offset array. Needed for bug 5443796.

Harfbuzz apparently requires the offset array to be initialized to zero,
otherwise it can report corrupt glyph positions. This change also
contains a small amount of refactoring to avoid code duplication.

Change-Id: I2553974f40bc8e0549876c7d31243960ca92a8a2
parent 6212a4f2
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -915,22 +915,23 @@ size_t TextLayoutShaper::shapeFontRun(const SkPaint* paint, bool isRTL) {

    // Shape
    assert(mShaperItem.item.length > 0); // Harfbuzz will overwrite other memory if length is 0.
    ensureShaperItemGlyphArrays(mShaperItem.item.length * 3 / 2);
    mShaperItem.num_glyphs = mShaperItemGlyphArraySize;
    while (!HB_ShapeItem(&mShaperItem)) {
    size_t size = mShaperItem.item.length * 3 / 2;
    while (!doShaping(size)) {
        // We overflowed our glyph arrays. Resize and retry.
        // HB_ShapeItem fills in shaperItem.num_glyphs with the needed size.
        ensureShaperItemGlyphArrays(mShaperItem.num_glyphs * 2);
        mShaperItem.num_glyphs = mShaperItemGlyphArraySize;
        size = mShaperItem.num_glyphs * 2;
    }
    return baseGlyphCount;
}

void TextLayoutShaper::ensureShaperItemGlyphArrays(size_t size) {
bool TextLayoutShaper::doShaping(size_t size) {
    if (size > mShaperItemGlyphArraySize) {
        deleteShaperItemGlyphArrays();
        createShaperItemGlyphArrays(size);
    }
    mShaperItem.num_glyphs = mShaperItemGlyphArraySize;
    memset(mShaperItem.offsets, 0, mShaperItem.num_glyphs * sizeof(HB_FixedPoint));
    return HB_ShapeItem(&mShaperItem);
}

void TextLayoutShaper::createShaperItemGlyphArrays(size_t size) {
+1 −1
Original line number Diff line number Diff line
@@ -242,7 +242,7 @@ private:
    SkTypeface* getCachedTypeface(SkTypeface** typeface, HB_Script script, SkTypeface::Style style);
    HB_Face getCachedHBFace(SkTypeface* typeface);

    void ensureShaperItemGlyphArrays(size_t size);
    bool doShaping(size_t size);
    void createShaperItemGlyphArrays(size_t size);
    void deleteShaperItemGlyphArrays();