Question

I have configured a CGContextPDF so the (0,0) coordinates are at the top left and not the bottom left using the following:

context.TranslateCTM(0, height);
context.ScaleCTM(1, -1);

However, now whenever I call ShowText the text is rendered upside down. I remember coming across this issue using MonoTouch for iOS and the fix was to do the above, however, the difference was with UIKit the coordinate system already started at the top left.

I have tried flipping the TextMatrix scale in a similar way both before & after selecting the font (incase that mattered) but it doesn't seem to have any effect.

Any idea's?

Was it helpful?

Solution

Finally figured this one out - turns out all you need to do is flip the TextMatrix and it doesn't matter if you do it before or after you flip the coordinate system for the entire context. The reason why it didn't work previously was because I was applying it to the existing transform instead of assigning a new one i.e. this works

context.TextMatrix = CGAffineTransform.MakeScale(1.0f, -1.0f);
context.TranslateCTM(0, height);
context.ScaleCTM(1.0f, -1.0f);

But this doesn't

context.TextMatrix.Scale(1.0f, -1.0f);
context.TranslateCTM(0, height);
context.ScaleCTM(1.0f, -1.0f);

Also one other downside is the text is always rendered upwards now instead of downwards so you always need to translate the height of the text if looking to draw on (x,y) and not under.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top