Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - Draw some text with CGContext : ok but... mirrored

When I draw some text using CGContext, it is drawn mirrored.

I tried to apply some transformations, then it is draw well, but then the rest of the drawing and all coordinates seems to be draw bad.

I tried to save and restore the context, before and ater drawing the text (and aplying transformation), but that does not help.

How some text must be drawn onto a View using CGContext without affecting the rest of the drawing, nor the onscreen CGPoint coords for that text ?

like image 440
Oliver Avatar asked Aug 31 '11 00:08

Oliver


2 Answers

Can you clarify what you mean as 'mirrored'? Here is some code for drawing some black text. It should not be 'mirrored'.

CGRect viewBounds = self.bounds;
CGContextTranslateCTM(ctx, 0, viewBounds.size.height);
CGContextScaleCTM(ctx, 1, -1);
CGContextSetRGBFillColor(ctx, 0.0, 1.0, 0.0, 1.0);
CGContextSetLineWidth(ctx, 2.0);
CGContextSelectFont(ctx, "Helvetica", 10.0, kCGEncodingMacRoman);
CGContextSetCharacterSpacing(ctx, 1.7);
CGContextSetTextDrawingMode(ctx, kCGTextFill);
CGContextShowTextAtPoint(ctx, 100.0, 100.0, "SOME TEXT", 9);
like image 73
samfu_1 Avatar answered Oct 24 '22 07:10

samfu_1


I think you have to reverse the text matrix :

CGAffineTransform transform = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 0.0);
CGContextSetTextMatrix(context, transform);
like image 23
Guillaume Macaigne Avatar answered Oct 24 '22 06:10

Guillaume Macaigne