[webkit-changes] cvs commit: WebKit/WebCoreSupport.subproj WebTextRenderer.m

Beth bdakin at opensource.apple.com
Tue Jan 3 18:01:42 PST 2006


bdakin      06/01/03 18:01:42

  Modified:    .        ChangeLog
               WebCoreSupport.subproj WebTextRenderer.m
  Log:
  Bug #:
  Bug #:
  
  Revision  Changes    Path
  1.3441    +19 -0     WebKit/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebKit/ChangeLog,v
  retrieving revision 1.3440
  retrieving revision 1.3441
  diff -u -r1.3440 -r1.3441
  --- ChangeLog	4 Jan 2006 01:02:45 -0000	1.3440
  +++ ChangeLog	4 Jan 2006 02:01:35 -0000	1.3441
  @@ -1,3 +1,22 @@
  +2006-01-03  Darin Adler  <darin at apple.com>
  +
  +        Reviewed by Beth.
  +
  +	This is a fix for <rdar://problem/3710994> HiDPI: Link underlines are 
  +	still one pixel high even if the UI resolution is > 100%
  +
  +	This fix refactors -drawLineForCharacters to make its organization
  +	more logical. It changes behavior when printing to the screen by
  +	rounding the parameters of the line (x- and y-values, width, and 
  +	thickness) to integer boundaries in device space. Previously,
  +	this part of the routine just hardcoded a 1 pixel line.
  +
  +        * WebCoreSupport.subproj/WebTextRenderer.m:
  +        (drawHorizontalLine): This just takes care of drawing the line once everything
  +	has been calculated in -drawLineForCharacters
  +        (-[WebTextRenderer drawLineForCharacters:yOffset:width:color:thickness:]):
  +	Now takes device space into account. Calls drawHorizontalLine
  +
   2006-01-03  Maciej Stachowiak  <mjs at apple.com>
   
           Reviewed by Vicki.
  
  
  
  1.214     +56 -31    WebKit/WebCoreSupport.subproj/WebTextRenderer.m
  
  Index: WebTextRenderer.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebCoreSupport.subproj/WebTextRenderer.m,v
  retrieving revision 1.213
  retrieving revision 1.214
  diff -u -r1.213 -r1.214
  --- WebTextRenderer.m	30 Dec 2005 22:17:09 -0000	1.213
  +++ WebTextRenderer.m	4 Jan 2006 02:01:42 -0000	1.214
  @@ -515,49 +515,74 @@
       return CG_floatWidthForRun(self, run, style, 0, 0, 0, 0, 0);
   }
   
  -- (void)drawLineForCharacters:(NSPoint)point yOffset:(float)yOffset width:(int)width color:(NSColor *)color thickness:(float)thickness
  +static void drawHorizontalLine(float x, float y, float width, NSColor *color, float thickness, bool shouldAntialias)
   {
       NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext];
  +    CGContextRef cgContext = (CGContextRef)[graphicsContext graphicsPort];
   
  -    bool flag = [graphicsContext shouldAntialias];
  +    CGContextSaveGState(cgContext);
   
  -    // We don't want antialiased lines on screen, but we do when printing (else they are too thick).
  -    if ([graphicsContext isDrawingToScreen]) {
  -        [graphicsContext setShouldAntialias:NO];
  -    }
  -    
       [color set];
  +    CGContextSetLineWidth(cgContext, thickness);
  +    CGContextSetShouldAntialias(cgContext, shouldAntialias);
  +
  +    float halfThickness = thickness / 2;
  +
  +    CGPoint linePoints[2];
  +    linePoints[0].x = x + halfThickness;
  +    linePoints[0].y = y + halfThickness;
  +    linePoints[1].x = x + width - halfThickness;
  +    linePoints[1].y = y + halfThickness;
  +    CGContextStrokeLineSegments(cgContext, linePoints, 2);
  +
  +    CGContextRestoreGState(cgContext);
  +}
  +
  +- (void)drawLineForCharacters:(NSPoint)point yOffset:(float)yOffset width:(int)width color:(NSColor *)color thickness:(float)thickness
  +{
  +    // Note: This function assumes that point.x and point.y are integers (and that's currently always the case).
   
  +    NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext];
       CGContextRef cgContext = (CGContextRef)[graphicsContext graphicsPort];
   
  -    // Hack to make thickness 2 underlines for international text input look right
  -    if (thickness > 1.5F && thickness < 2.5F) {
  -        yOffset += .5F;
  -    }
  +    bool printing = ![graphicsContext isDrawingToScreen];
   
  -    if (thickness == 0.0F) {
  -        if ([graphicsContext isDrawingToScreen]) {
  -            CGSize size = CGSizeApplyAffineTransform(CGSizeMake(1.0F, 1.0F), CGAffineTransformInvert(CGContextGetCTM(cgContext)));
  -            CGContextSetLineWidth(cgContext, size.width);
  -        } else {
  -            // See bugzilla bug 4255 for details of why we do this when printing
  -            CGContextSetLineWidth(cgContext, 0.5F);
  -        }
  +    float x = point.x;
  +    float y = point.y + yOffset;
  +
  +    // Leave 1.0 in user space between the baseline of the text and the top of the underline.
  +    // FIXME: Is this the right distance for space above the underline? Even for thick underlines on large sized text?
  +    y += 1;
  +
  +    if (printing) {
  +        // When printing, use a minimum thickness of 0.5 in user space.
  +        // See bugzilla bug 4255 for details of why 0.5 is the right minimum thickness to use while printing.
  +        if (thickness < 0.5)
  +            thickness = 0.5;
  +
  +        // When printing, use antialiasing instead of putting things on integral pixel boundaries.
       } else {
  -        CGContextSetLineWidth(cgContext, thickness);
  +        // On screen, use a minimum thickness of 1.0 in user space (later rounded to an integral number in device space).
  +        if (thickness < 1)
  +            thickness = 1;
  +
  +        // On screen, round all parameters to integer boundaries in device space.
  +        CGRect lineRect = CGContextConvertRectToDeviceSpace(cgContext, CGRectMake(x, y, width, thickness));
  +        lineRect.origin.x = roundf(lineRect.origin.x);
  +        lineRect.origin.y = roundf(lineRect.origin.y);
  +        lineRect.size.width = roundf(lineRect.size.width);
  +        lineRect.size.height = roundf(lineRect.size.height);
  +        if (lineRect.size.height == 0) // don't let thickness round down to 0 pixels
  +            lineRect.size.height = 1;
  +        lineRect = CGContextConvertRectToUserSpace(cgContext, lineRect);
  +        x = lineRect.origin.x;
  +        y = lineRect.origin.y;
  +        width = lineRect.size.width;
  +        thickness = lineRect.size.height;
       }
  -    
  -    // Use CGContextStrokeLineSegments.
  -    // With Q2DX turned on CGContextStrokeLineSegments sometimes fails to draw lines.  See 3952084.
  -    // Tiger shipped with Q2DX disabled, tho, so we can use CGContextStrokeLineSegments.
  -    CGPoint linePoints[2];
  -    linePoints[0].x = point.x;
  -    linePoints[0].y = point.y + 1.5F + yOffset;
  -    linePoints[1].x = point.x - 1.0F + width;
  -    linePoints[1].y = linePoints[0].y;
  -    CGContextStrokeLineSegments(cgContext, linePoints, 2);
   
  -    [graphicsContext setShouldAntialias: flag];
  +    // FIXME: How about using a rectangle fill instead of drawing a line?
  +    drawHorizontalLine(x, y, width, color, thickness, printing);
   }
   
   - (NSRect)selectionRectForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry
  
  
  



More information about the webkit-changes mailing list