Question

How do i draw truncated text with ATSUI?? I have a legacy app which uses QuickDraw API. it uses StringWidth , TruncString and DrawString functions. 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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top