开发者

CGContext set text to justify right when generating a pdf

开发者 https://www.devze.com 2023-03-28 15:11 出处:网络
I\'m using开发者_StackOverflow a series of CGContext commands to create text to be used for generating a pdf file:

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

精彩评论

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

关注公众号