Ok, this one has got me seriously confused. I'm drawing out some text to a bitmap context using a bundled font. I had the following code in main() to list fonts my application can see :
My function to draw out the text then gets called this way :
To make sense of a few types/defines, here's some relevant code from my header :
This works fine. It shows the text I want it to show at the proper spot. However, if I comment out the font listing code from main, leaving only the 4 lines of auto-generated stuff, the application hangs on the CGContextSelectFont(). Commenting out the call lets the application run (without drawing out any text of course since no font is selected/font size set).
It doesn't matter if I use my bundled font (which is a .ttf format font) or let's say, plain Helvetica. Commenting out the code from main to list font families/names makes CGContextSelectFont() hang.
What the heck is the UIFont stuff in main doing that's so special ?
Code:
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
/* List fonts... or not */
NSArray * familyNames = [UIFont familyNames];
NSArray * fontNames;
for(int i = 0; i < [familyNames count]; i++)
{
NSLog(@"Font family name : %@", [familyNames objectAtIndex: i]);
fontNames = [UIFont fontNamesForFamilyName: [familyNames objectAtIndex: i]];
for(int j = 0; j < [fontNames count]; j++)
{
NSLog(@" Font name : %@", [fontNames objectAtIndex: j]);
}
}
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
My function to draw out the text then gets called this way :
Code:
-(void) addImageTextFromString: (NSString *) string withColor: (BRUnifiedPixelRGBA) color widthOffset: (NSInteger) widthoffset heightOffset: (NSInteger) heightoffset
{
CGColorSpaceRef colorSpace;
CGContextRef context;
colorSpace = CGColorSpaceCreateDeviceRGB();
context = CGBitmapContextCreate(imagePixels,
width,
height,
8,
width * bytesPerChannel,
colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGContextTranslateCTM(context, widthoffset, height - (heightoffset + BR_DEFAULT_FONT_HEIGHT));
CGContextSelectFont(context, BR_DEFAULT_FONT_NAME, BR_DEFAULT_FONT_SIZE, kCGEncodingMacRoman);
CGContextSetRGBFillColor(context,
(CGFloat) color.components[COMPONENT_RED] / 255,
(CGFloat) color.components[COMPONENT_GREEN] / 255,
(CGFloat) color.components[COMPONENT_BLUE] / 255,
(CGFloat) color.components[COMPONENT_ALPHA] / 255);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextShowText(context, [string UTF8String], [string length]);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
}
To make sense of a few types/defines, here's some relevant code from my header :
Code:
#define BR_DEFAULT_FONT_NAME "FontNameCopyPastedFromLog"
#define BR_DEFAULT_FONT_SIZE 18.0f
#define COMPONENT_RED 0x00
#define COMPONENT_GREEN 0x01
#define COMPONENT_BLUE 0x02
#define COMPONENT_ALPHA 0x03
typedef union
{
unsigned char components[4];
uint32_t pixel;
} BRUnifiedPixelRGBA;
This works fine. It shows the text I want it to show at the proper spot. However, if I comment out the font listing code from main, leaving only the 4 lines of auto-generated stuff, the application hangs on the CGContextSelectFont(). Commenting out the call lets the application run (without drawing out any text of course since no font is selected/font size set).
It doesn't matter if I use my bundled font (which is a .ttf format font) or let's say, plain Helvetica. Commenting out the code from main to list font families/names makes CGContextSelectFont() hang.
What the heck is the UIFont stuff in main doing that's so special ?
Last edited: