Changeset 114679 in webkit


Ignore:
Timestamp:
Apr 19, 2012 3:05:38 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Canvas more precisely makes the bounding rect for stroke rendering.
https://bugs.webkit.org/show_bug.cgi?id=75792

Patch by Huang Dongsung <luxtella@company100.net> on 2012-04-19
Reviewed by Simon Fraser.

  • html/canvas/CanvasRenderingContext2D.cpp:

(WebCore::CanvasRenderingContext2D::stroke):
(WebCore::CanvasRenderingContext2D::drawTextInternal):
(WebCore::CanvasRenderingContext2D::inflateStrokeRect):
(WebCore):

  • html/canvas/CanvasRenderingContext2D.h:

(CanvasRenderingContext2D):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r114678 r114679  
     12012-04-19  Huang Dongsung  <luxtella@company100.net>
     2
     3        Canvas more precisely makes the bounding rect for stroke rendering.
     4        https://bugs.webkit.org/show_bug.cgi?id=75792
     5
     6        Reviewed by Simon Fraser.
     7
     8        * html/canvas/CanvasRenderingContext2D.cpp:
     9        (WebCore::CanvasRenderingContext2D::stroke):
     10        (WebCore::CanvasRenderingContext2D::drawTextInternal):
     11        (WebCore::CanvasRenderingContext2D::inflateStrokeRect):
     12        (WebCore):
     13        * html/canvas/CanvasRenderingContext2D.h:
     14        (CanvasRenderingContext2D):
     15
    1162012-04-19  Luke Macpherson  <macpherson@chromium.org>
    217
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r114437 r114679  
    950950    if (!m_path.isEmpty()) {
    951951        FloatRect dirtyRect = m_path.fastBoundingRect();
    952         // Fast approximation of the stroke's bounding rect.
    953         // This yields a slightly oversized rect but is very fast
    954         // compared to Path::strokeBoundingRect().
    955         dirtyRect.inflate(state().m_miterLimit + state().m_lineWidth);
     952        inflateStrokeRect(dirtyRect);
    956953
    957954        c->strokePath(m_path);
     
    21032100                                   width + fontMetrics.height(), fontMetrics.lineSpacing());
    21042101    if (!fill)
    2105         textRect.inflate(c->strokeThickness() / 2);
     2102        inflateStrokeRect(textRect);
    21062103
    21072104#if USE(CG)
    21082105    CanvasStyle* drawStyle = fill ? state().m_fillStyle.get() : state().m_strokeStyle.get();
    21092106    if (drawStyle->canvasGradient() || drawStyle->canvasPattern()) {
    2110         // FIXME: The rect is not big enough for miters on stroked text.
    21112107        IntRect maskRect = enclosingIntRect(textRect);
    21122108
     
    21632159        c->drawBidiText(font, textRun, location);
    21642160
    2165     if (fill)
    2166         didDraw(textRect);
    2167     else {
    2168         // When stroking text, pointy miters can extend outside of textRect, so we
    2169         // punt and dirty the whole canvas.
    2170         didDraw(FloatRect(0, 0, canvas()->width(), canvas()->height()));
    2171     }
     2161    didDraw(textRect);
    21722162
    21732163#if PLATFORM(QT)
     
    21762166}
    21772167
     2168void CanvasRenderingContext2D::inflateStrokeRect(FloatRect& rect) const
     2169{
     2170    // Fast approximation of the stroke's bounding rect.
     2171    // This yields a slightly oversized rect but is very fast
     2172    // compared to Path::strokeBoundingRect().
     2173    static const float root2 = sqrt(2);
     2174    float delta = state().m_lineWidth / 2;
     2175    if (state().m_lineJoin == MiterJoin)
     2176        delta *= state().m_miterLimit;
     2177    else if (state().m_lineCap == SquareCap)
     2178        delta *= root2;
     2179
     2180    rect.inflate(delta);
     2181}
     2182
    21782183const Font& CanvasRenderingContext2D::accessFont()
    21792184{
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h

    r114150 r114679  
    313313    void compositeBuffer(ImageBuffer*, const IntRect&, CompositeOperator);
    314314
     315    void inflateStrokeRect(FloatRect&) const;
     316
    315317    template<class T> void fullCanvasCompositedFill(const T&);
    316318    template<class T> void fullCanvasCompositedDrawImage(T*, ColorSpace, const FloatRect&, const FloatRect&, CompositeOperator);
Note: See TracChangeset for help on using the changeset viewer.