void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
{
    LowLevelGraphicsContext& context = g.getInternalContext();
    Font lastFont (context.getFont());
    bool needToRestore = false;

    for (int i = 0; i < glyphs.size(); ++i)
    {
        const PositionedGlyph& pg = glyphs.getReference(i);

        if (pg.font.isUnderlined())
            drawGlyphUnderline (g, pg, i, transform);

        if (! pg.isWhitespace())
        {
            if (lastFont != pg.font)
            {
                lastFont = pg.font;

                if (! needToRestore)
                {
                    needToRestore = true;
                    context.saveState();
                }

                context.setFont (lastFont);
            }

            context.drawGlyph (pg.glyph, AffineTransform::translation (pg.x, pg.y).followedBy (transform));
        }
    }

    if (needToRestore)
        context.restoreState();
}
void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
{
    for (int i = 0; i < glyphs.size(); ++i)
    {
        const PositionedGlyph& pg = glyphs.getReference(i);

        if (pg.font.isUnderlined())
            drawGlyphUnderline (g, pg, i, transform);

        pg.draw (g, transform);
    }
}