• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Changing font size
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing font size


  • Subject: Re: Changing font size
  • From: Martin Winter <email@hidden>
  • Date: Tue, 23 Dec 2003 15:32:14 +0100

There's really no need to worry about inefficiency. The NSFont documentation states:

"You dont create NSFont objects using the alloc and init methods. Instead, you use either fontWithName:matrix: or fontWithName:size: to look up an available font and alter its size or matrix to your needs. These methods check for an existing font object with the specified characteristics, returning it if there is one. Otherwise, they look up the font data requested and create the appropriate object."

However, I use a different method that is likely to be even more efficient:

1. Let's assume the current font is stored in a variable like NSFont *myFont.

2. Obtain the shared font manager:
NSFontManager *fontManager = [NSFontManager sharedFontManager];

3. Now you can use NSFontManager's method convertFont:toSize: to get a resized version of myFont:
myFont = [fontManager convertFont:myFont toSize:newSize];
(In this case, myFont would simply be replaced by the resized version.)

With Cocoa, you can usually trust that there's a lot of optimization going on "behind the scenes."
Hope that helps,
Martin


I'd like to have a single base font that's used to draw strings at
different
sizes, depending on context. As such, it seems simplest to save a
single
font in user defaults, and resize that according to where I need it.

The problem is that there seems to be no straightforward way to go
about
doing this. The only way I can figure is to get an NSFontDescriptor,
pull
the size out of that, change it, and then recreate a new font using the
different size. It all seems seriously inefficient and complicated,
and I
know that most things done with Cocoa aren't like that, so I assume I'm
missing something.

You could say [myFont fontName] to get the font's name, and hold on to
that NSString instead of holding on to the NSFont itself. Then, when
you need to render, you can just use [NSFont fontWithName:myFontName
size:whateverSizeYouNeedAtTheMoment]; . I've been doing things this way
and AFAICS it works fine.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Database Application with Obj-C --> Valentina database
  • Next by Date: I can't delete a window from Interface Builder
  • Previous by thread: Re: Changing font size
  • Next by thread: Copy an image into hard disk from NSImageView
  • Index(es):
    • Date
    • Thread