Bug 382206. Ensure that the clip rectangle used to draw partial ligatures is pixel-aligned. Also fix an off-by-one error that busted the detection of the end of a ligature. r=pavlov
authorroc+@cs.cmu.edu
Tue, 29 May 2007 02:47:54 -0700
changeset 1939 a759101289ae05116164d750bae84b591e92d742
parent 1938 2cf6bf8e3792adc54877ada0dd9bfb0fed805cc8
child 1940 ca450b60b1fdcc693155556ec8891ae06c6eaf8e
push idunknown
push userunknown
push dateunknown
reviewerspavlov
bugs382206
milestone1.9a5pre
Bug 382206. Ensure that the clip rectangle used to draw partial ligatures is pixel-aligned. Also fix an off-by-one error that busted the detection of the end of a ligature. r=pavlov
gfx/thebes/src/gfxFont.cpp
--- a/gfx/thebes/src/gfxFont.cpp
+++ b/gfx/thebes/src/gfxFont.cpp
@@ -980,36 +980,39 @@ gfxTextRun::DrawPartialLigature(gfxFont 
         }
         widthBeforeCluster = clusterWidth*data.mPartClusterIndex +
             data.mBeforeSpacing;
     } else {
         // We're drawing the start of the ligature, so our cluster includes any
         // before-spacing.
         widthBeforeCluster = 0;
     }
-    if (aOffset < data.mEndOffset) {
+    if (aOffset < data.mEndOffset - 1) {
         // Not the end of the ligature; need to clip the ligature after the current cluster
         gfxFloat endEdge = aPt->x + clusterWidth;
         if (IsRightToLeft()) {
             left = PR_MAX(left, endEdge);
         } else {
             right = PR_MIN(right, endEdge);
         }
         afterSpace = 0;
     } else {
         afterSpace = data.mAfterSpacing;
     }
 
     aCtx->Save();
+    aCtx->NewPath();
     // use division here to ensure that when the rect is aligned on multiples
-    // of mAppUnitsPerDevUnit, we clip to true device unit boundaries
-    aCtx->Clip(gfxRect(left/mAppUnitsPerDevUnit,
-                       aDirtyRect->Y()/mAppUnitsPerDevUnit,
-                       (right - left)/mAppUnitsPerDevUnit,
-                       aDirtyRect->Height()/mAppUnitsPerDevUnit));
+    // of mAppUnitsPerDevUnit, we clip to true device unit boundaries.
+    // Also, make sure we snap the rectangle to device pixels.
+    aCtx->Rectangle(gfxRect(left/mAppUnitsPerDevUnit,
+                            aDirtyRect->Y()/mAppUnitsPerDevUnit,
+                            (right - left)/mAppUnitsPerDevUnit,
+                            aDirtyRect->Height()/mAppUnitsPerDevUnit), PR_TRUE);
+    aCtx->Clip();
     gfxPoint pt(aPt->x - direction*widthBeforeCluster, aPt->y);
     DrawGlyphs(aFont, aCtx, PR_FALSE, &pt, data.mStartOffset,
                data.mEndOffset, aProvider);
     aCtx->Restore();
 
     aPt->x += direction*(clusterWidth + afterSpace);
 }