bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fix: RTFConsumer, -currentFont


From: Nicola Pero
Subject: Re: Fix: RTFConsumer, -currentFont
Date: Mon, 2 Sep 2002 14:55:23 +0100 (BST)

> Hi,
> 
> here is a fix which corrects the RTFConsumer to return the correct font for  
> composite fontNames such as Futura-Light or Futura-Book.

Hmmm.

What about taking a completely different approach in the method, and
instead doing a

[NSFont fontWithName: fontName  size: fontSize];

(which automatically parses fontName properly etc) and then patching up
the font by adding the traits NSBoldFontMask or NSItalicFontMask if
required ?

Something like 


- (NSFont*) currentFont
{
  NSFontManager *fm = [NSFontManager sharedFontManager];
  NSFont *font;
  //  int weight;
  
  font = [NSFont fontWithName: fontName  size: fontSize];
  
  if (font == nil)
    {
      NSDebugMLLog(@"RTFParser", 
                   @"Could not find font %@ size %f ", fontName, fontSize);
      font = [NSFont userFontOfSize: fontSize];
    }
  
  if (bold)
    {
      //      weight = 9;
      font = [fm convertFont: font  toHaveTrait: NSBoldFontMask];
    }
  else
    {
      //      weight = 5;
      font = [fm convertFont: font  toNotHaveTrait: NSBoldFontMask];
    }

  if (italic)
    {
      font = [fm convertFont: font  toHaveTrait: NSItalicFontMask];
    }
  else
    {
      font = [fm convertFont: font  toNotHaveTrait: NSItalicFontMask];
    }

  return font;
}


Do you think that would be fine ?  It works for me, does it work for you ?  
I'd much prefer this solution if it's Ok for you.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]