views:

995

answers:

1

I want to have a greater control on how and when fonts are loaded and released, therefore I'm interested in getting CGFontCreateWithFontName() to work.

GContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSelectFont(ctx, "Georgia", 20.0, kCGEncodingMacRoman);
// DRAWING WITH CGContextShowTextAtPoint() IS WORKING...


GContextRef ctx = UIGraphicsGetCurrentContext();
CGFontRef fontRef = CGFontCreateWithFontName((CFStringRef)@"Georgia");
CGContextSetFont(ctx, fontRef);
CGContextSetFontSize(ctx, 20.0);
// DRAWING WITH CGContextShowTextAtPoint() IS NOT WORKING...

Any clue on what's wrong with the 2nd block?

+1  A: 

Take a look at documentation:

Quartz use font data provided by Apple Type Services (ATS) to map each byte of the array through the encoding vector of the current font to obtain the glyph to display. Note that the font must have been set using CGContextSelectFont. Don’t use CGContextShowTextAtPoint in conjunction with CGContextSetFont.

You want to use CGContextSelectFont instead.

EightyEight