开发者

CGContext set text to justify right when generating a pdf

I'm using开发者_StackOverflow a series of CGContext commands to create text to be used for generating a pdf file:

CGContextSelectFont (pdfContext, "Helvetica", 14, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
CGContextSetTextMatrix(pdfContext, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));

I would like to right justify the text though. Any idea on how to do this? For example, is there a method that allows you to specify the origin as the top right corner of the text, not the top left?

    CGContextShowTextAtPoint (pdfContext, x, y, text, strlen(text));

Thanks!


Right and center justifications are not supported. In order to draw right aligned text, you need to compute the text width, subtract the text width from the right aligned x and then draw the text at the computed position.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜