开发者

How to draw Truncated text with ATSUI

How do i draw truncated text with ATSUI?? I have a legacy app which uses QuickDraw API. it uses StringWidth , TruncString and DrawString functions. 开发者_C百科I could replace the StringWidth and DrawString with ATSUI's ATSUMeasureTextImage and ATSUDrawText. However i could not find a way to truncate a string so that it fits into a rect.

I used Quartz with QuickDraw before choosing ATSUI. Quartz does not provide any functions to estimate the size (in pixels) of the drawn text.

CGContextSelectFont(cgContext,
    "Geneva", 12.0, kCGEncodingMacRoman);
CGContextSetTextMatrix(cgContext,
    CGAffineTransformMake(1.0,0.0, 0.0,
    -1.0, 0.0, 0.0));
CGContextShowTextAtPoint(cgContext,
    inPoint.h, inPoint.v + 12.00, (const
    char*)&(inString[1]), inString[0]);

Is there any function in ATSUI that does string truncation like TruncString...?? if not how do i draw a string truncated to a rect.

Thanks, Abhinay.


You want to use HIThemeGetTextDimensions to measure the string with a truncation policy. It will give you the rectangle width and height and the baseline; you can make a CGRect with that width and height and set its origin to wherever you want the text.

Amazingly, this function appears to still be supported in 64-bit, although it has never been documented (there has never been any reference documentation at all for HITheme). Look it up in the headers for details.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜