ios4 - NSString drawInRect causes CGContextShowTextAtPoint to incorrectly display text -
i using cgcontextref in ios application create pdf, along utility methods created draw items such lines, text, images, etc.
i have following method used draw multiple line text string cgcontextref:
- (void)drawtextblock:(nsstring *)thetext x:(cgfloat)x y:(cgfloat)y width:(cgfloat)w height:(cgfloat)h { if (thetext == nil) { return; } uigraphicspushcontext(pdfcontext); cgcontextsavegstate(pdfcontext); cgcontexttranslatectm(pdfcontext, 0.0f, pdf_height); cgcontextscalectm(pdfcontext, 1.0f, -1.0f); [thetext drawinrect:pdfcgrectmake(x, 11.0 - y - h, w, h) withfont:[uifont systemfontofsize:fontsize]]; cgcontextrestoregstate(pdfcontext); uigraphicspopcontext(); }
this code works fine drawing text blocks, if try draw other text using cgcontextshowtextatpoint after code executes, text comes out way large , upside down.
if add line @ end of method, size goes normal, text still upside down:
cgcontextsettextmatrix(pdfcontext, cgaffinetransformmake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));
i must missing here, seems original code should save , restore context state enough drawing continue fine. hints or suggestions?
there small typo? in code, try:
cgcontextsettextmatrix(pdfcontext, cgaffinetransformmake(1.0, 0.0, 0.0, 1.0, 0.0, 0.0));
note -1.0 1.0
Comments
Post a Comment