I using CoreText to draw to a CGBitmapContext. I found a great example on StackOverflow that centers text using GetBounds and TranslateCTM, and this works great for me.
However, if I try to add a 2nd text element, I can't predictably reset the coordinates and can't find any useful documentation. I can draw either text element, but not both, as the 2nd always appears in the wrong place.
I have tried calling SaveState at the start and RestoreState after drawing the first text. I don't think this does anything as far as coordinates. I’ve also tried MoveTo(0,0) which also doesn’t seem to do anything either.
I can call TranslateCTM again, which at least seems to do something. I don’t know if this transform is relative to the previous time it was called, or sets the translation matrix to absolute coordinates, but am guessing it is relative based on what I’ve seen. TranslateCTM(0,0) doesn’t seem to do anything. TranslateCTM using 0 - the values I used to center the text seems to put my cursor to the right of the last text I drew, but a larger negative offset doesn’t seem to take it left of where my previous text ended.
How do I reset my transform and coordinates back to the way they started?