2007-06-04 Alp Toker <alp.toker@collabora.co.uk>
authorbdash <bdash@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Jun 2007 23:43:38 +0000 (23:43 +0000)
committerbdash <bdash@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Jun 2007 23:43:38 +0000 (23:43 +0000)
        Reviewed by Anders.

        http://bugs.webkit.org/show_bug.cgi?id=13986
        Cairo graphics fixes and cleanups

        * platform/graphics/ImageBuffer.h:
        * platform/graphics/cairo/ImageBufferCairo.cpp:
        (WebCore::ImageBuffer::surface): Provide surface() accessor.
        * platform/graphics/cairo/AffineTransformCairo.cpp:
        (WebCore::AffineTransform::rotate): Convert from degrees to radians to
        fix rotation.
        * platform/graphics/cairo/GraphicsContextCairo.cpp:
        (WebCore::GraphicsContext::drawRect): Add save/restore.
        (WebCore::GraphicsContext::rotate): Rename parameter to "radians" to
        avoid further confusion.
        * platform/graphics/cairo/PathCairo.cpp:
        (WebCore::Path::boundingRect): The cairo_fill_extents() parameters do
        not describe a point/size but rather the two control points of the
        rectangular region.
        (WebCore::Path::contains): Remove needless casts.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@21974 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/graphics/ImageBuffer.h
WebCore/platform/graphics/cairo/AffineTransformCairo.cpp
WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
WebCore/platform/graphics/cairo/PathCairo.cpp

index 1c88466..01ba4b7 100644 (file)
@@ -1,3 +1,26 @@
+2007-06-04  Alp Toker  <alp.toker@collabora.co.uk>
+
+        Reviewed by Anders.
+
+        http://bugs.webkit.org/show_bug.cgi?id=13986
+        Cairo graphics fixes and cleanups
+
+        * platform/graphics/ImageBuffer.h:
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        (WebCore::ImageBuffer::surface): Provide surface() accessor.
+        * platform/graphics/cairo/AffineTransformCairo.cpp:
+        (WebCore::AffineTransform::rotate): Convert from degrees to radians to
+        fix rotation.
+        * platform/graphics/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::drawRect): Add save/restore.
+        (WebCore::GraphicsContext::rotate): Rename parameter to "radians" to
+        avoid further confusion.
+        * platform/graphics/cairo/PathCairo.cpp:
+        (WebCore::Path::boundingRect): The cairo_fill_extents() parameters do
+        not describe a point/size but rather the two control points of the
+        rectangular region.
+        (WebCore::Path::contains): Remove needless casts.
+
 2007-06-04  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Adam Roben.
index 6ce07eb..61c6236 100644 (file)
@@ -67,6 +67,8 @@ namespace WebCore {
         CGImageRef cgImage() const;
 #elif PLATFORM(QT)
         QPixmap* pixmap() const;
+#elif PLATFORM(CAIRO)
+        _cairo_surface* surface() const;
 #endif
 
     private:
index 30ec73f..f27b5ec 100644 (file)
@@ -32,6 +32,8 @@
 
 namespace WebCore {
 
+static const double deg2rad = 0.017453292519943295769; // pi/180
+
 AffineTransform::AffineTransform()
 {
     cairo_matrix_init_identity(&m_transform);
@@ -206,7 +208,7 @@ AffineTransform &AffineTransform::scale(double sx, double sy)
 
 AffineTransform &AffineTransform::rotate(double d)
 {
-    cairo_matrix_rotate(&m_transform, d);
+    cairo_matrix_rotate(&m_transform, d * deg2rad);
     return *this;
 }
 
index b440827..5f4af36 100644 (file)
@@ -132,6 +132,8 @@ void GraphicsContext::drawRect(const IntRect& rect)
         return;
     
     cairo_t* context = m_data->context;
+    cairo_save(context);
+
     if (fillColor().alpha())
         fillRectSourceOver(context, rect, fillColor());
 
@@ -143,6 +145,8 @@ void GraphicsContext::drawRect(const IntRect& rect)
         cairo_set_line_width(context, 1.0);
         cairo_stroke(context);
     }
+
+    cairo_restore(context);
 }
 
 // FIXME: Now that this is refactored, it should be shared by all contexts.
@@ -729,11 +733,11 @@ void GraphicsContext::clipOut(const Path&)
     notImplemented();
 }
 
-void GraphicsContext::rotate(float angle)
+void GraphicsContext::rotate(float radians)
 {
     if (paintingDisabled())
         return;
-    cairo_rotate(m_data->context, angle);
+    cairo_rotate(m_data->context, radians);
 }
 
 void GraphicsContext::scale(const FloatSize& size)
index 4c0b6ec..597c6ca 100644 (file)
@@ -67,4 +67,10 @@ GraphicsContext* ImageBuffer::context() const
     return m_context.get();
 }
 
+cairo_surface_t* ImageBuffer::surface() const
+{
+    return m_surface;
+}
+
+
 }
index 1d1bc1e..8fa9ab6 100644 (file)
@@ -173,9 +173,9 @@ void Path::closeSubpath()
 FloatRect Path::boundingRect() const
 {
     cairo_t* cr = platformPath()->m_cr;
-    double x, y, w, h;
-    cairo_fill_extents(cr, &x, &y, &w, &h);
-    return FloatRect(x, y, w, h);
+    double x0, x1, y0, y1;
+    cairo_fill_extents(cr, &x0, &y0, &x1, &y1);
+    return FloatRect(x0, y0, x1 - x0, y1 - y0);
 }
 
 bool Path::contains(const FloatPoint& point, WindRule rule) const
@@ -183,7 +183,7 @@ bool Path::contains(const FloatPoint& point, WindRule rule) const
     cairo_t* cr = platformPath()->m_cr;
     cairo_fill_rule_t cur = cairo_get_fill_rule(cr);
     cairo_set_fill_rule(cr, rule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
-    bool contains = cairo_in_fill(cr, static_cast<double>(point.x()), static_cast<double>(point.y()));
+    bool contains = cairo_in_fill(cr, point.x(), point.y());
     cairo_set_fill_rule(cr, cur);
     return contains;
 }