Without my doing anything to request up开发者_JS百科side down text, CGContextShowText is drawing it in that fashion. It is a mirror image vertically of what it should be.
float font_size = 19.;
CGContextSelectFont (context, "Helvetica", font_size, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (context, kCGTextFill);
CGContextSetRGBStrokeColor (context, 255, 0, 0, 0);
CGContextSetRGBFillColor (context, 255, 0, 0, 0);
CGContextSetTextPosition (context, x, y);
CGContextShowText (context, cstring, strlen(cstring));
How can I fix this? Also why is this the default drawing mode?
Thanks.
This "upsidedownness" commonly comes into play when the API renders to your cgContext from top to bottom, but somehow you're drawing from bottom to top. Anyway, the 2 line solution I use is:
CGAffineTransform trans = CGAffineTransformMakeScale(1, -1);
CGContextSetTextMatrix(tex->cgContext, trans);
Swift 3
let context = UIGraphicsGetCurrentContext()!
let textTransform = CGAffineTransform(scaleX: 1.0, y: -1.0)
context.textMatrix = textTransform
The best solution to this problem is to simply call this at the beginning of your draw routine. (Make sure to only call it once.)
CGAffineTransform transform;
transform = CGAffineTransformConcat(CGContextGetTextMatrix(ctx),
CGAffineTransformMake(1.0, 0.0, 0.0,
-1.0, 0.0, 0.0));
CGContextSetTextMatrix(ctx, transform);
精彩评论