Title: [114679] trunk/Source/WebCore
- Revision
- 114679
- Author
- [email protected]
- Date
- 2012-04-19 15:05:38 -0700 (Thu, 19 Apr 2012)
Log Message
Canvas more precisely makes the bounding rect for stroke rendering.
https://bugs.webkit.org/show_bug.cgi?id=75792
Patch by Huang Dongsung <[email protected]> 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):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (114678 => 114679)
--- trunk/Source/WebCore/ChangeLog 2012-04-19 22:03:01 UTC (rev 114678)
+++ trunk/Source/WebCore/ChangeLog 2012-04-19 22:05:38 UTC (rev 114679)
@@ -1,3 +1,18 @@
+2012-04-19 Huang Dongsung <[email protected]>
+
+ Canvas more precisely makes the bounding rect for stroke rendering.
+ https://bugs.webkit.org/show_bug.cgi?id=75792
+
+ Reviewed by Simon Fraser.
+
+ * html/canvas/CanvasRenderingContext2D.cpp:
+ (WebCore::CanvasRenderingContext2D::stroke):
+ (WebCore::CanvasRenderingContext2D::drawTextInternal):
+ (WebCore::CanvasRenderingContext2D::inflateStrokeRect):
+ (WebCore):
+ * html/canvas/CanvasRenderingContext2D.h:
+ (CanvasRenderingContext2D):
+
2012-04-19 Luke Macpherson <[email protected]>
Eliminate potential null pointer dereference in CSSStyleSelector::containsUncommonAttributeSelector().
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (114678 => 114679)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2012-04-19 22:03:01 UTC (rev 114678)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2012-04-19 22:05:38 UTC (rev 114679)
@@ -949,10 +949,7 @@
if (!m_path.isEmpty()) {
FloatRect dirtyRect = m_path.fastBoundingRect();
- // Fast approximation of the stroke's bounding rect.
- // This yields a slightly oversized rect but is very fast
- // compared to Path::strokeBoundingRect().
- dirtyRect.inflate(state().m_miterLimit + state().m_lineWidth);
+ inflateStrokeRect(dirtyRect);
c->strokePath(m_path);
didDraw(dirtyRect);
@@ -2102,12 +2099,11 @@
FloatRect textRect = FloatRect(location.x() - fontMetrics.height() / 2, location.y() - fontMetrics.ascent() - fontMetrics.lineGap(),
width + fontMetrics.height(), fontMetrics.lineSpacing());
if (!fill)
- textRect.inflate(c->strokeThickness() / 2);
+ inflateStrokeRect(textRect);
#if USE(CG)
CanvasStyle* drawStyle = fill ? state().m_fillStyle.get() : state().m_strokeStyle.get();
if (drawStyle->canvasGradient() || drawStyle->canvasPattern()) {
- // FIXME: The rect is not big enough for miters on stroked text.
IntRect maskRect = enclosingIntRect(textRect);
#if USE(IOSURFACE_CANVAS_BACKING_STORE)
@@ -2162,19 +2158,28 @@
} else
c->drawBidiText(font, textRun, location);
- if (fill)
- didDraw(textRect);
- else {
- // When stroking text, pointy miters can extend outside of textRect, so we
- // punt and dirty the whole canvas.
- didDraw(FloatRect(0, 0, canvas()->width(), canvas()->height()));
- }
+ didDraw(textRect);
#if PLATFORM(QT)
Font::setCodePath(oldCodePath);
#endif
}
+void CanvasRenderingContext2D::inflateStrokeRect(FloatRect& rect) const
+{
+ // Fast approximation of the stroke's bounding rect.
+ // This yields a slightly oversized rect but is very fast
+ // compared to Path::strokeBoundingRect().
+ static const float root2 = sqrt(2);
+ float delta = state().m_lineWidth / 2;
+ if (state().m_lineJoin == MiterJoin)
+ delta *= state().m_miterLimit;
+ else if (state().m_lineCap == SquareCap)
+ delta *= root2;
+
+ rect.inflate(delta);
+}
+
const Font& CanvasRenderingContext2D::accessFont()
{
canvas()->document()->updateStyleIfNeeded();
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h (114678 => 114679)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h 2012-04-19 22:03:01 UTC (rev 114678)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h 2012-04-19 22:05:38 UTC (rev 114679)
@@ -312,6 +312,8 @@
PassOwnPtr<ImageBuffer> createCompositingBuffer(const IntRect&);
void compositeBuffer(ImageBuffer*, const IntRect&, CompositeOperator);
+ void inflateStrokeRect(FloatRect&) const;
+
template<class T> void fullCanvasCompositedFill(const T&);
template<class T> void fullCanvasCompositedDrawImage(T*, ColorSpace, const FloatRect&, const FloatRect&, CompositeOperator);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes