Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Does CGContextSetFont() Work?



I'm drawing text with CoreGraphics. There is sample code that uses CGContextSelectFont() and this works fine. However you have to specify a font by name and there is no guarantee that this font exists. If the font doesn't exist CGContextSelectFont() fails silently (yet another new API that doesn't bother with errors) and your text doesn't get displayed. Therefore I'm trying to use CGContextSetFont() to set the application font.

The following code creates a valid CGFont (as least as far as CFShow knows) but no text comes out. The archives show this same question being asked two or three times and the only answer seems to be "use ATSUI". ATSUI is massive overkill for this particular case. Does anybody know how to use CGContextSetFont()?

Thanks for any help,
Nick Nallick

----------------------------------

// this works
CGContextSelectFont(context, "Helvetica", 12.0, kCGEncodingMacRoman);

// this doesn't work - there are no errors recorded but no text either
ATSUFontID fontID;
ATSUFONDtoFontID(kFontIDHelvetica, normal, &fontID);
CGFontRef font = CGFontCreateWithPlatformFont(&fontID);
CFShow(font); // console displays <CGFont 0x1a6dc60>
CGContextSetFont(context, font);
CGContextSetFontSize(context, 12.0);
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.