Example #1
0
float Font::getGlyphsAndAdvancesForSimpleText(const TextRun& run, int from, int to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot forTextEmphasis) const
{
    WidthIterator it(this, run, 0, false, forTextEmphasis);
    GlyphBuffer localGlyphBuffer;
    it.advance(run.length(), &localGlyphBuffer);

    if (localGlyphBuffer.isEmpty())
        return 0;

    float totalWidth = it.m_runWidthSoFar;
    float beforeWidth = 0;
    int glyphPos = 0;
    for (; glyphPos < localGlyphBuffer.size() && it.m_characterIndexOfGlyph[glyphPos] < from; ++glyphPos)
        beforeWidth += localGlyphBuffer.advanceAt(glyphPos).width();
    int glyphFrom = glyphPos;

    float afterWidth = totalWidth;
    glyphPos = localGlyphBuffer.size() - 1;
    for (; glyphPos >= glyphFrom && it.m_characterIndexOfGlyph[glyphPos] >= to; --glyphPos)
        afterWidth -= localGlyphBuffer.advanceAt(glyphPos).width();
    int glyphTo = glyphPos + 1;

    glyphBuffer.add(&localGlyphBuffer, glyphFrom, glyphTo - glyphFrom);

    if (run.rtl()) {
        glyphBuffer.reverse(0, glyphBuffer.size());
        return totalWidth - afterWidth;
    }

    return beforeWidth;
}
Example #2
0
float Font::getGlyphsAndAdvancesForSimpleText(const TextRun& run, int from, int to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot forTextEmphasis) const
{
    float initialAdvance;

    WidthIterator it(this, run, 0, false, forTextEmphasis);
    // FIXME: Using separate glyph buffers for the prefix and the suffix is incorrect when kerning or
    // ligatures are enabled.
    GlyphBuffer localGlyphBuffer;
    it.advance(from, &localGlyphBuffer);
    float beforeWidth = it.m_runWidthSoFar;
    it.advance(to, &glyphBuffer);

    if (glyphBuffer.isEmpty())
        return 0;

    float afterWidth = it.m_runWidthSoFar;

    if (run.rtl()) {
        float finalRoundingWidth = it.m_finalRoundingWidth;
        it.advance(run.length(), &localGlyphBuffer);
        initialAdvance = finalRoundingWidth + it.m_runWidthSoFar - afterWidth;
    } else {
        initialAdvance = beforeWidth;
    }

    if (run.rtl())
        glyphBuffer.reverse(0, glyphBuffer.size());

    return initialAdvance;
}
float Font::getGlyphsAndAdvancesForComplexText(const TextRun& run, int from, int to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot forTextEmphasis) const
{
    float initialAdvance;

    ComplexTextController controller(this, run, false, 0, forTextEmphasis);
    controller.advance(from);
    float beforeWidth = controller.runWidthSoFar();
    controller.advance(to, &glyphBuffer);

    if (glyphBuffer.isEmpty())
        return 0;

    float afterWidth = controller.runWidthSoFar();

    if (run.rtl()) {
        initialAdvance = controller.totalWidth() + controller.finalRoundingWidth() - afterWidth;
        glyphBuffer.reverse(0, glyphBuffer.size());
    } else
        initialAdvance = beforeWidth;

    return initialAdvance;
}