[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fix: RTFConsumer, -currentFont
From: |
Georg Fleischmann |
Subject: |
Fix: RTFConsumer, -currentFont |
Date: |
Thu, 10 Oct 2002 00:33:39 GMT |
Hi Nicola,
here is my suggestion for a fix, which corrects the RTFConsumer to return the
correct font for composite fontNames such as Helvetica-Light or Futura-Book.
I didn't succeed to implement your approach (using -fontWithName: and then
patching up the font by adding the traits), because -fontWithName: would return
nil for a composite fontName, if it doesn't exist (or at least not the desired
font-family).
Example: If the desired fontName would be Futura-Condensed which is not
installed, then fontWithName would return nil. By using -fontWithFamily: we
have at least a font with the desired family. So this approach seems a lot more
tolerant to me.
Maybe there is yet another and better way, but I have no idea at the moment.
Georg
2002-10-09 Georg Fleischmann
* gui/TextConverters/RTF/RTFConsumer.m [-currentFont]:
allow composite font names like 'FontFamily-Face'
*** gui/TextConverters/RTF/RTFConsumer.m.old Tue Jun 11 21:36:51 2002
--- gui/TextConverters/RTF/RTFConsumer.m Thu Oct 10 00:53:05 2002
***************
*** 115,120 ****
--- 115,130 ----
NSFont *font;
NSFontTraitMask traits = 0;
int weight;
+ NSRange range;
+ NSString *fontFamily;
+
+ /* Check, whether fontName is composite, and extract fontFamily
+ */
+ range = [fontName rangeOfString:@"-"];
+ if (range.length)
+ fontFamily = [fontName substringToIndex:range.location];
+ else
+ fontFamily = fontName;
if (bold)
{
***************
*** 136,145 ****
traits |= NSUnitalicFontMask;
}
! font = [[NSFontManager sharedFontManager] fontWithFamily: fontName
traits: traits
weight: weight
size: fontSize];
if (font == nil)
{
NSDebugMLLog(@"RTFParser",
--- 146,166 ----
traits |= NSUnitalicFontMask;
}
! font = [[NSFontManager sharedFontManager] fontWithFamily: fontFamily
traits: traits
weight: weight
size: fontSize];
+
+ /* set the typeface for composite names, if it is not correct.
+ */
+ if ( font && range.length
+ && ![[font fontName] rangeOfString:fontName].length )
+ {
+ font = [[NSFontManager sharedFontManager] convertFont:font
+ toFace:fontName];
+ font = [[NSFontManager sharedFontManager] convertFont:font
+ toHaveTrait:traits];
+ }
if (font == nil)
{
NSDebugMLLog(@"RTFParser",
- Fix: RTFConsumer, -currentFont,
Georg Fleischmann <=