06-08-2010, 05:10 AM
#1 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 155
Quartz2D: Text on context appears upside down and mirrored
Hi,
i got a custom UIView-subclass and in the drawRect-Method, i am drwing on the context.
The drawing stuff works fine, but when i show some text, it is upside down ond mirrored.
Code:
CGContextRef ctx = UIGraphicsGetCurrentContext();
...
...
CGContextSelectFont(ctx, PDF_FONT_NAME, 20, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (ctx, kCGTextFill);
CGContextSetRGBFillColor (ctx, 1, 1, 1, 1);
const char *goodVals = "Some Text";
CGContextShowTextAtPoint (ctx, 35, 250, goodVals, strlen(goodVals));
I use this code in my app several times and it works fine there.
Any ideas why the text is upside down and mirrored?
Regards,
Daniel
06-08-2010, 10:15 AM
#2 (permalink )
Registered Member
Join Date: May 2010
Posts: 107
Quote:
I use this code in my app several times and it works fine there.
Any ideas why the text is upside down and mirrored?
It has been my experience that text is always drawn upside down the way you are describing... other graphics objects are treated with 0,0 in the top left of the image, and thus are not rendered upsidedown.
insert:
Code:
CGAffineTransform textTransform = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 0.0);
CGContextSetTextMatrix(ctx, textTransform);
before:
Code:
CGContextShowTextAtPoint (ctx, 35, 250, goodVals, strlen(goodVals));
to set it back to what you 'want'.
06-08-2010, 02:31 PM
#3 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 155
Thanks, i didnt thought about this possibilty. Works fine.
06-09-2010, 03:49 PM
#4 (permalink )
Registered Member
Join Date: May 2010
Posts: 107
Another way to draw text...
Apple's Graphics & Animation Coding How-To's mention another way:
Code:
[myText drawAtPoint:CGPointMake(0.0,0.0) withFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]];
where
myText is an NSString.
Last edited by JDave; 06-09-2010 at 03:53 PM .
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 702
24 members and 678 guests
ADY , dacapo , flamingliquid , Frost , GameViewPoint , gc2010 , GHuebner , ilmman , jakerocheleau , JJGEight , joder2006 , kampftrinker , Meoz , mer10 , Morrisone , Oral B , Paradox927 , PixelEnvision , Rudy , ryantcb , sneaky , srouviere , Thompson22 , troop231
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,557
Threads: 89,123
Posts: 380,243
Top Poster: BrianSlick (7,102)
Welcome to our newest member, wTaylorDaviesp