Reviewed by Darin Adler.
[WebKit-https.git] / WebCore / platform / graphics / cg / GraphicsContextCG.cpp
index 16aa10ea11385d7871f215dc38e00bd26511e943..fc9d58687fae0834bca8b7ab4a4665245ca0d44f 100644 (file)
@@ -30,6 +30,7 @@
 #if PLATFORM(CG)
 
 #include "AffineTransform.h"
+#include "FloatConversion.h"
 #include "GraphicsContextPlatformPrivate.h"
 #include "KURL.h"
 #include "Path.h"
@@ -509,15 +510,35 @@ void GraphicsContext::setShadow(const IntSize& size, int blur, const Color& colo
 
     if (paintingDisabled())
         return;
+    CGContextRef context = platformContext();
+
+    CGFloat width = size.width();
+    CGFloat height = size.height();
+
+#if PLATFORM(MAC)
+    // Work around <rdar://problem/5539388> by ensuring that the offsets will get truncated
+    // to the desired integer.
+    // FIXME: This is not needed post-Leopard.
+    static const CGFloat extraShadowOffset = narrowPrecisionToCGFloat(1.0 / 128);
+    if (width > 0)
+        width += extraShadowOffset;
+    else if (width < 0)
+        width -= extraShadowOffset;
+
+    if (height > 0)
+        height += extraShadowOffset;
+    else if (height < 0)
+        height -= extraShadowOffset;
+#endif
+
     // Check for an invalid color, as this means that the color was not set for the shadow
     // and we should therefore just use the default shadow color.
-    CGContextRef context = platformContext();
     if (!color.isValid())
-        CGContextSetShadow(context, CGSizeMake(size.width(), -size.height()), blur); // y is flipped.
+        CGContextSetShadow(context, CGSizeMake(width, -height), blur); // y is flipped.
     else {
         CGColorRef colorCG = cgColor(color);
         CGContextSetShadowWithColor(context,
-                                    CGSizeMake(size.width(), -size.height()), // y is flipped.
+                                    CGSizeMake(width, -height), // y is flipped.
                                     blur, 
                                     colorCG);
         CGColorRelease(colorCG);