Commit a310c37b authored by rjw's avatar rjw

A different fix to 3078065 that doesn't depend on the appkit's idea of

        fixed pitch font.

        The fix is to adjust the width of all characters that have the same width
        as the space character to match the adjustment of the space character.
        This has the slight downside that non-monospace fonts that contain glyphs
        with the same width as the space character will have an extra adjustment.
        In practice this is not noticeable as the adjustment is always sub-pixel.
        Nor of course does this cause any mislayout, as it's done at the lowest
        level for both measurement and drawing.

        Until we move kthml internals to floats this will be just fine.

        * WebCoreSupport.subproj/WebTextRenderer.h:
        * WebCoreSupport.subproj/WebTextRenderer.m:
        (widthForGlyph):
        (-[WebTextRenderer initWithFont:]):
        (-[WebTextRenderer _floatWidthForCharacters:stringLength:fromCharacterPosition:numberOfCharacters:withPadding:applyRounding:attemptFontSubstitution:widths:fonts:glyphs:numGlyphs:letterSpacing:wordSpacing:]):
tAfterNavigationPolicy:request:]):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2819 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3708706f
2002-11-21 Richard Williamson <rjw@apple.com>
A different fix to 3078065 that doesn't depend on the appkit's idea of
fixed pitch font.
The fix is to adjust the width of all characters that have the same width
as the space character to match the adjustment of the space character.
This has the slight downside that non-monospace fonts that contain glyphs
with the same width as the space character will have an extra adjustment.
In practice this is not noticeable as the adjustment is always sub-pixel.
Nor of course does this cause any mislayout, as it's done at the lowest
level for both measurement and drawing.
Until we move kthml internals to floats this will be just fine.
* WebCoreSupport.subproj/WebTextRenderer.h:
* WebCoreSupport.subproj/WebTextRenderer.m:
(widthForGlyph):
(-[WebTextRenderer initWithFont:]):
(-[WebTextRenderer _floatWidthForCharacters:stringLength:fromCharacterPosition:numberOfCharacters:withPadding:applyRounding:attemptFontSubstitution:widths:fonts:glyphs:numGlyphs:letterSpacing:wordSpacing:]):
tAfterNavigationPolicy:request:]):
2002-11-21 Maciej Stachowiak <mjs@apple.com>
* Makefile.am: Pass symroots for this tree to pbxbuild.
......
2002-11-21 Richard Williamson <rjw@apple.com>
A different fix to 3078065 that doesn't depend on the appkit's idea of
fixed pitch font.
The fix is to adjust the width of all characters that have the same width
as the space character to match the adjustment of the space character.
This has the slight downside that non-monospace fonts that contain glyphs
with the same width as the space character will have an extra adjustment.
In practice this is not noticeable as the adjustment is always sub-pixel.
Nor of course does this cause any mislayout, as it's done at the lowest
level for both measurement and drawing.
Until we move kthml internals to floats this will be just fine.
* WebCoreSupport.subproj/WebTextRenderer.h:
* WebCoreSupport.subproj/WebTextRenderer.m:
(widthForGlyph):
(-[WebTextRenderer initWithFont:]):
(-[WebTextRenderer _floatWidthForCharacters:stringLength:fromCharacterPosition:numberOfCharacters:withPadding:applyRounding:attemptFontSubstitution:widths:fonts:glyphs:numGlyphs:letterSpacing:wordSpacing:]):
tAfterNavigationPolicy:request:]):
2002-11-21 Maciej Stachowiak <mjs@apple.com>
* Makefile.am: Pass symroots for this tree to pbxbuild.
......
......@@ -21,8 +21,8 @@ typedef struct GlyphMap GlyphMap;
NSFont *font;
GlyphMap *characterToGlyphMap;
WidthMap *glyphToWidthMap;
float fixedWidth;
BOOL isFixedPitch;
float spaceWidth;
float adjustedSpaceWidth;
}
+ (BOOL)shouldBufferTextDrawing;
......
......@@ -176,8 +176,16 @@ static inline WebGlyphWidth widthForGlyph (WebTextRenderer *renderer, WidthMap *
if (width == UNINITIALIZED_GLYPH_WIDTH)
width = widthForGlyph (renderer, map->next, glyph);
if (renderer->isFixedPitch && width != 0)
return renderer->fixedWidth;
// Hack to ensure that characters that match the width of the space character
// have the same integer width as the space character. This is necessary so
// glyphs in fixed pitch fonts all have the same integer width. We can't depend
// on the fixed pitch property of NSFont because that isn't set for all
// monospaced fonts, in particular Courier! This has the downside of inappropriately
// adjusting the widths of characters in non-monospaced fonts that are coincidentally
// the same width as a space in that font. In practice this is not an issue as the
// adjustment is always as the sub-pixel level.
if (width == renderer->spaceWidth)
return renderer->adjustedSpaceWidth;
return width;
}
......@@ -356,12 +364,11 @@ - (void)convertCharacters: (const UniChar *)characters length: (unsigned)numChar
ATSUDisposeStyle(style);
spaceGlyph = nonGlyphID;
isFixedPitch = [font isFixedPitch];
if (isFixedPitch)
fixedWidth = CEIL_TO_INT([font widthOfString: @"X"]);
UniChar c = ' ';
spaceGlyph = [self extendCharacterToGlyphMapToInclude: c];
spaceWidth = widthForGlyph(self, glyphToWidthMap, spaceGlyph);
adjustedSpaceWidth = (float)ceil(spaceWidth);
return self;
}
......@@ -738,6 +745,7 @@ - (float)_floatWidthForCharacters:(const UniChar *)characters stringLength:(unsi
}
for (i = 0; i < stringLength; i++) {
UniChar c = characters[i];
// Skip control characters.
......@@ -819,7 +827,7 @@ - (float)_floatWidthForCharacters:(const UniChar *)characters stringLength:(unsi
if (widthBuffer)
widthBuffer[numGlyphs - 1] += delta;
}
lastWidth = CEIL_TO_INT(widthForGlyph(self, glyphToWidthMap, glyphID));
lastWidth = adjustedSpaceWidth;
if (padding > 0){
// Only use left over padding if note evenly divisible by
// number of spaces.
......
Markdown is supported
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