Changeset 55923 in webkit


Ignore:
Timestamp:
Mar 12, 2010 11:45:13 AM (14 years ago)
Author:
jpetsovits@rim.com
Message:

2010-03-12 Jakob Petsovits <jpetsovits@rim.com>

Reviewed by Dirk Schulze.

[OpenVG] Add support for drawing text to PainterOpenVG
https://bugs.webkit.org/show_bug.cgi?id=35581

Doesn't come with any actual font classes, as OpenVG
by itself doesn't provide any access to platform fonts
but just the means to draw glyphs that have been loaded
manually before.

  • platform/graphics/openvg/PainterOpenVG.cpp: (WebCore::PlatformPainterState::PlatformPainterState): (WebCore::PlatformPainterState::copyPaintState): (WebCore::PainterOpenVG::textDrawingMode): (WebCore::PainterOpenVG::setTextDrawingMode): (WebCore::PainterOpenVG::drawText):
  • platform/graphics/openvg/PainterOpenVG.h:
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r55922 r55923  
     12010-03-12  Jakob Petsovits  <jpetsovits@rim.com>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        [OpenVG] Add support for drawing text to PainterOpenVG
     6        https://bugs.webkit.org/show_bug.cgi?id=35581
     7
     8        Doesn't come with any actual font classes, as OpenVG
     9        by itself doesn't provide any access to platform fonts
     10        but just the means to draw glyphs that have been loaded
     11        manually before.
     12
     13        * platform/graphics/openvg/PainterOpenVG.cpp:
     14        (WebCore::PlatformPainterState::PlatformPainterState):
     15        (WebCore::PlatformPainterState::copyPaintState):
     16        (WebCore::PainterOpenVG::textDrawingMode):
     17        (WebCore::PainterOpenVG::setTextDrawingMode):
     18        (WebCore::PainterOpenVG::drawText):
     19        * platform/graphics/openvg/PainterOpenVG.h:
     20
    1212010-03-12  Jakob Petsovits  <jpetsovits@rim.com>
    222
  • trunk/WebCore/platform/graphics/openvg/PainterOpenVG.cpp

    r55922 r55923  
    123123    float strokeDashOffset;
    124124
     125    int textDrawingMode;
    125126    bool antialiasingEnabled;
    126127
     
    140141        , strokeMiterLimit(4.0)
    141142        , strokeDashOffset(0.0)
     143        , textDrawingMode(cTextFill)
    142144        , antialiasingEnabled(true)
    143145    {
     
    188190        strokeDashOffset = other->strokeDashOffset;
    189191
     192        textDrawingMode = other->textDrawingMode;
    190193        antialiasingEnabled = other->antialiasingEnabled;
    191194    }
     
    651654    m_state->fillColor = color;
    652655    setVGSolidColor(VG_FILL_PATH, color);
     656}
     657
     658int PainterOpenVG::textDrawingMode() const
     659{
     660    ASSERT(m_state);
     661    return m_state->textDrawingMode;
     662}
     663
     664void PainterOpenVG::setTextDrawingMode(int mode)
     665{
     666    ASSERT(m_state);
     667    m_state->textDrawingMode = mode;
    653668}
    654669
     
    10711086}
    10721087
     1088#ifdef OPENVG_VERSION_1_1
     1089void PainterOpenVG::drawText(VGFont vgFont, Vector<VGuint>& characters, VGfloat* adjustmentsX, VGfloat* adjustmentsY, const FloatPoint& point)
     1090{
     1091    ASSERT(m_state);
     1092
     1093    VGbitfield paintModes = 0;
     1094
     1095    if (m_state->textDrawingMode & cTextClip)
     1096        return; // unsupported for every port except CG at the time of writing
     1097    if (m_state->textDrawingMode & cTextFill && !m_state->fillDisabled())
     1098        paintModes |= VG_FILL_PATH;
     1099    if (m_state->textDrawingMode & cTextStroke && !m_state->strokeDisabled())
     1100        paintModes |= VG_STROKE_PATH;
     1101
     1102    m_surface->makeCurrent();
     1103
     1104    FloatPoint effectivePoint = m_state->surfaceTransformation.mapPoint(point);
     1105    FloatPoint p = point;
     1106    AffineTransform* originalTransformation = 0;
     1107
     1108    // In case the font isn't drawn at a pixel-exact baseline and we can easily
     1109    // fix that (which is the case for non-rotated affine transforms), let's
     1110    // align the starting point to the pixel boundary in order to prevent
     1111    // font rendering issues such as glyphs that appear off by a pixel.
     1112    // This causes us to have inconsistent spacing between baselines in a
     1113    // larger paragraph, but that seems to be the least of all evils.
     1114    if ((fmod(effectivePoint.x() + 0.01, 1.0) > 0.02 || fmod(effectivePoint.y() + 0.01, 1.0) > 0.02)
     1115        && isNonRotatedAffineTransformation(m_state->surfaceTransformation))
     1116    {
     1117        originalTransformation = new AffineTransform(m_state->surfaceTransformation);
     1118        setTransformation(AffineTransform(
     1119            m_state->surfaceTransformation.a(), 0,
     1120            0, m_state->surfaceTransformation.d(),
     1121            roundf(effectivePoint.x()), roundf(effectivePoint.y())));
     1122        p = FloatPoint();
     1123    }
     1124
     1125    const VGfloat vgPoint[2] = { p.x(), p.y() };
     1126    vgSetfv(VG_GLYPH_ORIGIN, 2, vgPoint);
     1127    ASSERT_VG_NO_ERROR();
     1128
     1129    vgDrawGlyphs(vgFont, characters.size(), characters.data(),
     1130        adjustmentsX, adjustmentsY, paintModes, VG_TRUE /* allow autohinting */);
     1131    ASSERT_VG_NO_ERROR();
     1132
     1133    if (originalTransformation) {
     1134        setTransformation(*originalTransformation);
     1135        delete originalTransformation;
     1136    }
     1137}
     1138#endif
     1139
    10731140void PainterOpenVG::save(PainterOpenVG::SaveMode saveMode)
    10741141{
  • trunk/WebCore/platform/graphics/openvg/PainterOpenVG.h

    r55922 r55923  
    9090    void setFillColor(const Color&);
    9191
     92    int textDrawingMode() const;
     93    void setTextDrawingMode(int mode);
     94
    9295    bool antialiasingEnabled() const;
    9396    void setAntialiasingEnabled(bool);
     
    99102    void drawEllipse(const IntRect& bounds, VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH));
    100103    void drawPolygon(size_t numPoints, const FloatPoint* points, VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH));
     104#ifdef OPENVG_VERSION_1_1
     105    void drawText(VGFont, Vector<VGuint>& characters, VGfloat* adjustmentsX, VGfloat* adjustmentsY, const FloatPoint&);
     106#endif
    101107
    102108    void scale(const FloatSize& scaleFactors);
Note: See TracChangeset for help on using the changeset viewer.