+2005-03-09 Richard Williamson <rjw@apple.com>
+
+ Fixed <rdar://problem/4032938> Safari: text layout for MS P Gothic font is corrupted
+
+ The AppKit and ATS reports that MS P Gothic is fixed pitch. It is
+ not! This is another case of "fixed pitch" being wrong. I've
+ coalesced all the special cases into our isFontFixedPitch:, and
+ used a dictionary to improve speed. No performance regression.
+
+ Reviewed by Maciej.
+
+ * WebCoreSupport.subproj/WebTextRenderer.m:
+ (-[WebTextRenderer _computeWidthForSpace]):
+ * WebCoreSupport.subproj/WebTextRendererFactory.m:
+ (-[WebTextRendererFactory clearCaches]):
+ (-[WebTextRendererFactory isFontFixedPitch:]):
+
2005-03-09 Darin Adler <darin@apple.com>
Reviewed by Maciej.
+ (NSFont *) findFontLike:(NSFont *)aFont forCharacter:(UInt32)c inLanguage:(NSLanguage *) language;
+ (NSFont *) findFontLike:(NSFont *)aFont forString:(NSString *)string withRange:(NSRange)range inLanguage:(NSLanguage *) language;
- (NSGlyph)_defaultGlyphForChar:(unichar)uu;
-- (BOOL)_isFakeFixedPitch;
@end
// Macros
float width = widthForGlyph(self, spaceGlyph, 0);
spaceWidth = width;
- treatAsFixedPitch = [font isFixedPitch] || [font _isFakeFixedPitch] || [font _web_isFakeFixedPitch];
+ treatAsFixedPitch = [[WebTextRendererFactory sharedFactory] isFontFixedPitch:font];
adjustedSpaceWidth = treatAsFixedPitch ? CEIL_TO_INT(width) : ROUND_TO_INT(width);
return YES;
- (BOOL)_isFakeFixedPitch;
@end
-@implementation NSFont (WebPrivateExtensions)
-- (BOOL)_web_isFakeFixedPitch
-{
- // Special case Osaka-Mono. According to <rdar://problem/3999467>, we should treat Osaka-Mono
- // as fixed pitch.
- if ([[self fontName] caseInsensitiveCompare:@"Osaka-Mono"] == NSOrderedSame)
- return YES;
- return NO;
-}
-@end
-
-
@implementation WebTextRendererFactory
- (BOOL)coalesceTextDrawing
}
-static CFMutableDictionaryRef fontCache = NULL;
+static CFMutableDictionaryRef fontCache;
+static CFMutableDictionaryRef fixedPitchFonts;
- (void)clearCaches
{
CFRelease(fontCache);
fontCache = NULL;
+ if (fixedPitchFonts) {
+ CFRelease (fixedPitchFonts);
+ fixedPitchFonts = 0;
+ }
+
[super clearCaches];
}
- (BOOL)isFontFixedPitch: (NSFont *)font
{
- // We don't add additional check for [font _web_isFakeFixedPitch] here because of
- // performance problems. Instead the check is done down in WebCore (QFont) and
- // also in WebTextRenderer.
- return [font isFixedPitch] || [font _isFakeFixedPitch];
+ BOOL ret = NO;
+
+ if (!fixedPitchFonts) {
+ fixedPitchFonts = CFDictionaryCreateMutable (0, 0, &kCFTypeDictionaryKeyCallBacks, 0);
+ }
+
+ CFBooleanRef val = CFDictionaryGetValue (fixedPitchFonts, font);
+ if (val) {
+ ret = (val == kCFBooleanTrue);
+ }
+ else {
+ // Special case Osaka-Mono. According to <rdar://problem/3999467>, we should treat Osaka-Mono
+ // as fixed pitch. Note that the AppKit does not report MS-PGothic as fixed pitch.
+
+ // Special case MS PGothic. According to <rdar://problem/4032938, we should not treat MS-PGothic
+ // as fixed pitch. Note that AppKit does report MS-PGothic as fixed pitch.
+ if (([font isFixedPitch] || [font _isFakeFixedPitch] || [[font fontName] caseInsensitiveCompare:@"Osaka-Mono"] == NSOrderedSame) &&
+ ![[font fontName] caseInsensitiveCompare:@"MS-PGothic"] == NSOrderedSame) {
+ CFDictionarySetValue (fixedPitchFonts, font, kCFBooleanTrue);
+ ret = YES;
+ }
+ else {
+ CFDictionarySetValue (fixedPitchFonts, font, kCFBooleanFalse);
+ ret = NO;
+ }
+ }
+ return ret;
}
- init