Note that there are some explanatory texts on larger screens.

plurals
  1. POQuartz 2D Text Drawing Errors in Encoding and Transformation?
    text
    copied!<p>I'm working on a Text Addition feature for my App. This text is going to be added with CGContext and Quartz 2D. The variable <code>text</code> is pulled from a UITextField's text property.</p> <p>Here is the code I have so far:</p> <pre><code>CGRect textBox = CGRectMake(0, 0, 300, 200); UIView *textView = [[UIView alloc] initWithFrame:textBox]; const char *textChar = [text UTF8String]; NSInteger xLocation = (contentOffset.x + 100); CGContextSelectFont (UIGraphicsGetCurrentContext(), "Helvetica", 14.0f, kCGEncodingMacRoman); CGContextSetShouldSmoothFonts(UIGraphicsGetCurrentContext(), YES); CGContextSetCharacterSpacing (UIGraphicsGetCurrentContext(), 10); CGContextSetTextDrawingMode (UIGraphicsGetCurrentContext(), kCGTextFill); CGContextSetRGBFillColor (UIGraphicsGetCurrentContext(), 255, 255, 255, 1.0); CGContextShowTextAtPoint (UIGraphicsGetCurrentContext(), xLocation, 110, textChar, 9); [drawGallery addSubview:textView]; </code></pre> <p>I have a few problems with this:</p> <ol> <li><p>The text is rendering flipped - (this is easily rectified with a transform, but the tutorial I followed didn't have this issue so I'm confused a little <a href="http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_text/dq_text.html#//apple_ref/doc/uid/TP30001066-CH213-TPXREF103" rel="nofollow noreferrer">LINK</a>).</p></li> <li><p>The text is rendering with strange characters - I think this is an encoding issue, but how do i adjust this?</p></li> <li><p>The text doesn't get added to the view at the <code>addSubview</code> line, it only gets added when the CGContext is updated, i.e. I have a draw lines function too and if I draw on the view then the text magically pops up.</p></li> <li><p>The text is horribly jagged and badly rendered, is there something I can do for this? I've added a <code>CGContextSetShouldSmoothFonts</code> but it doesn't seem to be doing anything.</p></li> </ol> <p>See below for an example:</p> <p><img src="https://i.stack.imgur.com/CaozJ.png" alt="strange characters"></p> <p>Thanks for any help you can give.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload