Commit 4df709ae authored by rjw's avatar rjw
Browse files

Fixed 3128794. Use CG directy to get font metrics rather than the appkit. The appkit

        has a bug that sometimes causes line height to be 20% too large.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3105 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2113543f
2002-12-17 Richard Williamson <rjw@apple.com>
Fixed 3128794. Use CG directy to get font metrics rather than the appkit. The appkit
has a bug (3129490) that sometimes causes line height to be 20% too large.
Reviewed by hyatt.
* WebCoreSupport.subproj/WebTextRenderer.m:
(-[WebTextRenderer initWithFont:]):
(-[WebTextRenderer ascent]):
(-[WebTextRenderer descent]):
(-[WebTextRenderer lineSpacing]):
2002-12-17 Trey Matteson <trey@apple.com> 2002-12-17 Trey Matteson <trey@apple.com>
Reworking the code to update the page icon led me to roll the WebIconDB API Reworking the code to update the page icon led me to roll the WebIconDB API
......
...@@ -446,7 +446,6 @@ - (void)_computeWidthForSpace ...@@ -446,7 +446,6 @@ - (void)_computeWidthForSpace
spaceWidth = _spaceWidth; spaceWidth = _spaceWidth;
} }
- initWithFont:(NSFont *)f - initWithFont:(NSFont *)f
{ {
if ([f glyphPacking] != NSNativeShortGlyphPacking && if ([f glyphPacking] != NSNativeShortGlyphPacking &&
...@@ -456,9 +455,6 @@ - (void)_computeWidthForSpace ...@@ -456,9 +455,6 @@ - (void)_computeWidthForSpace
[super init]; [super init];
font = [f retain]; font = [f retain];
ascent = -1;
descent = -1;
lineSpacing = -1;
OSStatus errCode; OSStatus errCode;
ATSUStyle style; ATSUStyle style;
...@@ -475,6 +471,44 @@ - (void)_computeWidthForSpace ...@@ -475,6 +471,44 @@ - (void)_computeWidthForSpace
ATSUDisposeStyle(style); ATSUDisposeStyle(style);
[self _computeWidthForSpace]; [self _computeWidthForSpace];
// We emulate the appkit metrics by applying rounding as is done
// in the appkit.
CGFontRef cgFont = [f _backingCGSFont];
const CGFontHMetrics *metrics = CGFontGetHMetrics(cgFont);
unsigned int unitsPerEm = CGFontGetUnitsPerEm(cgFont);
float pointSize = [f pointSize];
float asc = (ScaleEmToUnits(metrics->ascent, unitsPerEm)*pointSize);
float dsc = (-ScaleEmToUnits(metrics->descent, unitsPerEm)*pointSize);
float lineGap = ScaleEmToUnits(metrics->lineGap, unitsPerEm)*pointSize;
ascent = ROUND_TO_INT(asc);
descent = ROUND_TO_INT(dsc);
lineSpacing = ascent + descent + (int)(lineGap > 0.0 ? floor(lineGap + 0.5) : 0.0);
#ifdef COMPARE_APPKIT_CG_METRICS
if ((int)ROUND_TO_INT([f ascender]) != ascent ||
(int)ROUND_TO_INT(-[f descender]) != descent ||
(int)ROUND_TO_INT([font defaultLineHeightForFont]) != lineSpacing){
printf ("\nCG/Appkit mismatched metrics for font %s, %f (%s)\n", [[f displayName] cString], [f pointSize],
([f screenFont] ? [[[f screenFont] displayName] cString] : "none"));
printf ("ascent(%s), descent(%s), lineSpacing(%s)\n",
((int)ROUND_TO_INT([f ascender]) != ascent) ? "different" : "same",
((int)ROUND_TO_INT(-[f descender]) != descent) ? "different" : "same",
((int)ROUND_TO_INT([font defaultLineHeightForFont]) != lineSpacing) ? "different" : "same");
printf ("CG: ascent %f, ", asc);
printf ("descent %f, ", dsc);
printf ("lineGap %f, ", lineGap);
printf ("lineSpacing %d\n", lineSpacing);
printf ("NSFont: ascent %f, ", [f ascender]);
printf ("descent %f, ", [f descender]);
printf ("lineSpacing %f\n", [font defaultLineHeightForFont]);
}
else {
printf ("\nCG/Appkit matched metrics for font %s, %f\n", [[f displayName] cString], [f pointSize]);
}
#endif
return self; return self;
} }
...@@ -527,27 +561,18 @@ - (int)widthForString:(NSString *)string ...@@ -527,27 +561,18 @@ - (int)widthForString:(NSString *)string
- (int)ascent - (int)ascent
{ {
if (ascent < 0) {
ascent = ROUND_TO_INT([font ascender]);
}
return ascent; return ascent;
} }
- (int)descent - (int)descent
{ {
if (descent < 0) {
descent = ROUND_TO_INT(-[font descender]);
}
return descent; return descent;
} }
- (int)lineSpacing - (int)lineSpacing
{ {
if (lineSpacing < 0) {
lineSpacing = ROUND_TO_INT([font defaultLineHeightForFont]);
}
return lineSpacing; return lineSpacing;
} }
...@@ -748,8 +773,8 @@ - (void)drawLineForCharacters:(const UniChar *)characters stringLength:(unsigned ...@@ -748,8 +773,8 @@ - (void)drawLineForCharacters:(const UniChar *)characters stringLength:(unsigned
lineWidth = size.width; lineWidth = size.width;
} }
CGContextSetLineWidth(cgContext, lineWidth); CGContextSetLineWidth(cgContext, lineWidth);
CGContextMoveToPoint(cgContext, point.x, point.y + [font defaultLineHeightForFont] + 1.5 - [self descent] + yOffset); CGContextMoveToPoint(cgContext, point.x, point.y + [self lineSpacing] + 1.5 - [self descent] + yOffset);
CGContextAddLineToPoint(cgContext, point.x + width, point.y + [font defaultLineHeightForFont] + 1.5 - [self descent] + yOffset); CGContextAddLineToPoint(cgContext, point.x + width, point.y + [self lineSpacing] + 1.5 - [self descent] + yOffset);
CGContextStrokePath(cgContext); CGContextStrokePath(cgContext);
[graphicsContext setShouldAntialias: flag]; [graphicsContext setShouldAntialias: flag];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment