Commit f7f3eb17 authored by rjw's avatar rjw
Browse files

Fixed recursion problems. +[NSFont findFontLike:forString:withRange:inLanguage:]

        will alternate between suggested fonts with bogus answers.  The work
        around involves adding an explicit flag indicating whether or not
        font substitution should be attempted.

        * Misc.subproj/IFStringTruncator.m:
        (+[IFStringTruncator centerTruncateString:toWidth:withFont:]):
        * WebCoreSupport.subproj/IFTextRenderer.h:
        * WebCoreSupport.subproj/IFTextRenderer.m:
        (-[IFTextRenderer slowDrawCharacters:length:atPoint:withColor:attemptFontSubstitution:]):
        (-[IFTextRenderer drawCharacters:length:atPoint:withColor:]):
        (-[IFTextRenderer floatWidthForCharacters:length:applyRounding:attemptFontSubstitution:]):
        (-[IFTextRenderer widthForCharacters:length:]):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@1439 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 807450b5
2002-06-26 Richard Williamson <rjw@apple.com>
Fixed recursion problems. +[NSFont findFontLike:forString:withRange:inLanguage:]
will alternate between suggested fonts with bogus answers. The work
around involves adding an explicit flag indicating whether or not
font substitution should be attempted.
* Misc.subproj/IFStringTruncator.m:
(+[IFStringTruncator centerTruncateString:toWidth:withFont:]):
* WebCoreSupport.subproj/IFTextRenderer.h:
* WebCoreSupport.subproj/IFTextRenderer.m:
(-[IFTextRenderer slowDrawCharacters:length:atPoint:withColor:attemptFontSubstitution:]):
(-[IFTextRenderer drawCharacters:length:atPoint:withColor:]):
(-[IFTextRenderer floatWidthForCharacters:length:applyRounding:attemptFontSubstitution:]):
(-[IFTextRenderer widthForCharacters:length:]):
2002-06-26 Darin Adler <darin@apple.com>
* WebView.subproj/IFHTMLView.mm:
......
2002-06-26 Richard Williamson <rjw@apple.com>
Fixed recursion problems. +[NSFont findFontLike:forString:withRange:inLanguage:]
will alternate between suggested fonts with bogus answers. The work
around involves adding an explicit flag indicating whether or not
font substitution should be attempted.
* Misc.subproj/IFStringTruncator.m:
(+[IFStringTruncator centerTruncateString:toWidth:withFont:]):
* WebCoreSupport.subproj/IFTextRenderer.h:
* WebCoreSupport.subproj/IFTextRenderer.m:
(-[IFTextRenderer slowDrawCharacters:length:atPoint:withColor:attemptFontSubstitution:]):
(-[IFTextRenderer drawCharacters:length:atPoint:withColor:]):
(-[IFTextRenderer floatWidthForCharacters:length:applyRounding:attemptFontSubstitution:]):
(-[IFTextRenderer widthForCharacters:length:]):
2002-06-26 Darin Adler <darin@apple.com>
* WebView.subproj/IFHTMLView.mm:
......
......@@ -77,7 +77,7 @@ + (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth wi
[IFTextRendererFactory createSharedFactory];
currentRenderer = [[[IFTextRendererFactory sharedFactory] rendererWithFont:font] retain];
ellipsis = ELLIPSIS_CHARACTER;
currentEllipsisWidth = [currentRenderer floatWidthForCharacters:&ellipsis length:1 applyRounding: NO];
currentEllipsisWidth = [currentRenderer floatWidthForCharacters:&ellipsis length:1 applyRounding: NO attemptFontSubstitution: YES];
}
WEBKIT_ASSERT(currentRenderer);
......@@ -96,7 +96,7 @@ + (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth wi
}
width = [currentRenderer floatWidthForCharacters:stringBuffer
length:truncatedLength applyRounding: NO];
length:truncatedLength applyRounding: NO attemptFontSubstitution: YES];
if (width <= maxWidth) {
return string;
}
......@@ -136,7 +136,7 @@ + (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth wi
keepCount:keepCount
toBuffer:stringBuffer];
width = [currentRenderer floatWidthForCharacters:stringBuffer length:truncatedLength applyRounding: NO];
width = [currentRenderer floatWidthForCharacters:stringBuffer length:truncatedLength applyRounding: NO attemptFontSubstitution: YES];
if (width <= maxWidth) {
keepCountForLargestKnownToFit = keepCount;
widthForLargestKnownToFit = width;
......
......@@ -77,7 +77,7 @@ + (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth wi
[IFTextRendererFactory createSharedFactory];
currentRenderer = [[[IFTextRendererFactory sharedFactory] rendererWithFont:font] retain];
ellipsis = ELLIPSIS_CHARACTER;
currentEllipsisWidth = [currentRenderer floatWidthForCharacters:&ellipsis length:1 applyRounding: NO];
currentEllipsisWidth = [currentRenderer floatWidthForCharacters:&ellipsis length:1 applyRounding: NO attemptFontSubstitution: YES];
}
WEBKIT_ASSERT(currentRenderer);
......@@ -96,7 +96,7 @@ + (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth wi
}
width = [currentRenderer floatWidthForCharacters:stringBuffer
length:truncatedLength applyRounding: NO];
length:truncatedLength applyRounding: NO attemptFontSubstitution: YES];
if (width <= maxWidth) {
return string;
}
......@@ -136,7 +136,7 @@ + (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth wi
keepCount:keepCount
toBuffer:stringBuffer];
width = [currentRenderer floatWidthForCharacters:stringBuffer length:truncatedLength applyRounding: NO];
width = [currentRenderer floatWidthForCharacters:stringBuffer length:truncatedLength applyRounding: NO attemptFontSubstitution: YES];
if (width <= maxWidth) {
keepCountForLargestKnownToFit = keepCount;
widthForLargestKnownToFit = width;
......
......@@ -29,6 +29,6 @@ typedef struct GlyphMap GlyphMap;
- initWithFont:(NSFont *)font;
// Set applyRounding = NO to get an Cocoa equivalent width.
- (float)floatWidthForCharacters:(const unichar *)characters length:(unsigned)length applyRounding: (BOOL)applyRounding;
- (float)floatWidthForCharacters:(const unichar *)characters length:(unsigned)length applyRounding: (BOOL)applyRounding attemptFontSubstitution: (BOOL)attemptFontSubstitution;
@end
......@@ -470,7 +470,7 @@ - (NSPoint)drawGlyphs: (CGGlyph *)glyphs numGlyphs: (unsigned int)numGlyphs atPo
// Useful page for testing http://home.att.net/~jameskass
- (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withColor:(NSColor *)color
- (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withColor:(NSColor *)color attemptFontSubstitution: (BOOL)attemptFontSubstitution
{
unsigned int charPos = 0, lastDrawnGlyph = 0;
unsigned int clusterLength, i, numGlyphs, fragmentLength;
......@@ -486,7 +486,7 @@ - (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)
clusterLength = findLengthOfCharacterCluster (&characters[charPos], length - charPos);
if (glyphID == 0){
if (glyphID == 0 && attemptFontSubstitution){
// Draw everthing up to this point.
fragmentLength = i - lastDrawnGlyph;
if (fragmentLength > 0)
......@@ -495,7 +495,7 @@ - (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)
// Draw the character in the alternate font.
substituteFont = [self substituteFontForCharacters: &characters[charPos] length: clusterLength];
if (substituteFont)
point = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] slowDrawCharacters: &characters[charPos] length: clusterLength atPoint: point withColor: color];
point = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] slowDrawCharacters: &characters[charPos] length: clusterLength atPoint: point withColor: color attemptFontSubstitution: NO];
else
point = [self drawGlyphs: &glyphs[i] numGlyphs: 1 atPoint: point withColor: color];
......@@ -602,10 +602,10 @@ - (void)drawCharacters:(const UniChar *)characters length: (unsigned int)length
reason = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] _drawCharacters: characters length: length atPoint: point withColor: color];
if (!substituteFont || reason != _IFDrawSucceeded)
[self slowDrawCharacters: characters length: length atPoint: point withColor: color];
[self slowDrawCharacters: characters length: length atPoint: point withColor: color attemptFontSubstitution: YES];
}
else if (reason == _IFNonBaseCharacter) {
[self slowDrawCharacters: characters length: length atPoint: point withColor: color];
[self slowDrawCharacters: characters length: length atPoint: point withColor: color attemptFontSubstitution: YES];
}
}
......@@ -677,7 +677,7 @@ - (float)slowFloatWidthForCharacters: (const UniChar *)characters length: (unsig
}
- (float)floatWidthForCharacters:(const UniChar *)characters length:(unsigned)length applyRounding: (BOOL)applyRounding
- (float)floatWidthForCharacters:(const UniChar *)characters length:(unsigned)length applyRounding: (BOOL)applyRounding attemptFontSubstitution: (BOOL)attemptSubstitution
{
float totalWidth = 0;
unsigned int i, clusterLength;
......@@ -703,13 +703,13 @@ - (float)floatWidthForCharacters:(const UniChar *)characters length:(unsigned)le
}
// Try to find a substitute font if this font didn't have a glyph for a character in the
// string. If one isn't found we end up drawing and measuring a box.
if (glyphID == 0) {
// string. If one isn't found we end up drawing and measuring the 0 glyph, usually a box.
if (glyphID == 0 && attemptSubstitution) {
clusterLength = findLengthOfCharacterCluster (&characters[i], length - i);
substituteFont = [self substituteFontForCharacters: &characters[i] length: clusterLength];
if (substituteFont) {
//WEBKITDEBUGLEVEL (WEBKIT_LOG_FONTCACHE, "substituting %s for %s, missing 0x%04x\n", DEBUG_OBJECT(substituteFont), DEBUG_OBJECT([font displayName]), c);
lastWidth = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] floatWidthForCharacters: &characters[i] length: clusterLength applyRounding: YES];
lastWidth = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] floatWidthForCharacters: &characters[i] length: clusterLength applyRounding: YES attemptFontSubstitution: NO];
}
}
......@@ -733,7 +733,7 @@ - (float)floatWidthForCharacters:(const UniChar *)characters length:(unsigned)le
- (int)widthForCharacters:(const UniChar *)characters length:(unsigned)length
{
return ROUND_TO_INT([self floatWidthForCharacters:characters length:length applyRounding:YES]);
return ROUND_TO_INT([self floatWidthForCharacters:characters length:length applyRounding:YES attemptFontSubstitution: YES]);
}
......
......@@ -29,6 +29,6 @@ typedef struct GlyphMap GlyphMap;
- initWithFont:(NSFont *)font;
// Set applyRounding = NO to get an Cocoa equivalent width.
- (float)floatWidthForCharacters:(const unichar *)characters length:(unsigned)length applyRounding: (BOOL)applyRounding;
- (float)floatWidthForCharacters:(const unichar *)characters length:(unsigned)length applyRounding: (BOOL)applyRounding attemptFontSubstitution: (BOOL)attemptFontSubstitution;
@end
......@@ -470,7 +470,7 @@ - (NSPoint)drawGlyphs: (CGGlyph *)glyphs numGlyphs: (unsigned int)numGlyphs atPo
// Useful page for testing http://home.att.net/~jameskass
- (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withColor:(NSColor *)color
- (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)length atPoint:(NSPoint)point withColor:(NSColor *)color attemptFontSubstitution: (BOOL)attemptFontSubstitution
{
unsigned int charPos = 0, lastDrawnGlyph = 0;
unsigned int clusterLength, i, numGlyphs, fragmentLength;
......@@ -486,7 +486,7 @@ - (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)
clusterLength = findLengthOfCharacterCluster (&characters[charPos], length - charPos);
if (glyphID == 0){
if (glyphID == 0 && attemptFontSubstitution){
// Draw everthing up to this point.
fragmentLength = i - lastDrawnGlyph;
if (fragmentLength > 0)
......@@ -495,7 +495,7 @@ - (NSPoint)slowDrawCharacters:(const UniChar *)characters length: (unsigned int)
// Draw the character in the alternate font.
substituteFont = [self substituteFontForCharacters: &characters[charPos] length: clusterLength];
if (substituteFont)
point = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] slowDrawCharacters: &characters[charPos] length: clusterLength atPoint: point withColor: color];
point = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] slowDrawCharacters: &characters[charPos] length: clusterLength atPoint: point withColor: color attemptFontSubstitution: NO];
else
point = [self drawGlyphs: &glyphs[i] numGlyphs: 1 atPoint: point withColor: color];
......@@ -602,10 +602,10 @@ - (void)drawCharacters:(const UniChar *)characters length: (unsigned int)length
reason = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] _drawCharacters: characters length: length atPoint: point withColor: color];
if (!substituteFont || reason != _IFDrawSucceeded)
[self slowDrawCharacters: characters length: length atPoint: point withColor: color];
[self slowDrawCharacters: characters length: length atPoint: point withColor: color attemptFontSubstitution: YES];
}
else if (reason == _IFNonBaseCharacter) {
[self slowDrawCharacters: characters length: length atPoint: point withColor: color];
[self slowDrawCharacters: characters length: length atPoint: point withColor: color attemptFontSubstitution: YES];
}
}
......@@ -677,7 +677,7 @@ - (float)slowFloatWidthForCharacters: (const UniChar *)characters length: (unsig
}
- (float)floatWidthForCharacters:(const UniChar *)characters length:(unsigned)length applyRounding: (BOOL)applyRounding
- (float)floatWidthForCharacters:(const UniChar *)characters length:(unsigned)length applyRounding: (BOOL)applyRounding attemptFontSubstitution: (BOOL)attemptSubstitution
{
float totalWidth = 0;
unsigned int i, clusterLength;
......@@ -703,13 +703,13 @@ - (float)floatWidthForCharacters:(const UniChar *)characters length:(unsigned)le
}
// Try to find a substitute font if this font didn't have a glyph for a character in the
// string. If one isn't found we end up drawing and measuring a box.
if (glyphID == 0) {
// string. If one isn't found we end up drawing and measuring the 0 glyph, usually a box.
if (glyphID == 0 && attemptSubstitution) {
clusterLength = findLengthOfCharacterCluster (&characters[i], length - i);
substituteFont = [self substituteFontForCharacters: &characters[i] length: clusterLength];
if (substituteFont) {
//WEBKITDEBUGLEVEL (WEBKIT_LOG_FONTCACHE, "substituting %s for %s, missing 0x%04x\n", DEBUG_OBJECT(substituteFont), DEBUG_OBJECT([font displayName]), c);
lastWidth = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] floatWidthForCharacters: &characters[i] length: clusterLength applyRounding: YES];
lastWidth = [[[IFTextRendererFactory sharedFactory] rendererWithFont: substituteFont] floatWidthForCharacters: &characters[i] length: clusterLength applyRounding: YES attemptFontSubstitution: NO];
}
}
......@@ -733,7 +733,7 @@ - (float)floatWidthForCharacters:(const UniChar *)characters length:(unsigned)le
- (int)widthForCharacters:(const UniChar *)characters length:(unsigned)length
{
return ROUND_TO_INT([self floatWidthForCharacters:characters length:length applyRounding:YES]);
return ROUND_TO_INT([self floatWidthForCharacters:characters length:length applyRounding:YES attemptFontSubstitution: YES]);
}
......
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