CGContextShowText is inverted text (mirror image)

Without my execution of anything to request inverted text, CGContextShowText draws it this way. This is a vertical mirror image of what 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.

+4
source share
3 answers

This "upsidedownness" usually comes into play when the API displays your cgContext from top to bottom, but somehow you draw from bottom to top. Anyway, the 2-line solution that I use:

 CGAffineTransform trans = CGAffineTransformMakeScale(1, -1); CGContextSetTextMatrix(tex->cgContext, trans); 
+7
source

Swift 3

  let context = UIGraphicsGetCurrentContext()! let textTransform = CGAffineTransform(scaleX: 1.0, y: -1.0) context.textMatrix = textTransform 
+1
source

The best solution to this problem is to simply call it at the beginning of your drawing program. (Make sure you call it only once.)

  CGAffineTransform transform; transform = CGAffineTransformConcat(CGContextGetTextMatrix(ctx), CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 0.0)); CGContextSetTextMatrix(ctx, transform); 
0
source

Source: https://habr.com/ru/post/1369270/


All Articles