简体   繁体   中英

core text - getting nsstring from ctrunref

I have the following code to get a run:

        CFArrayRef runs = CTLineGetGlyphRuns(line);

        for(int j = 0; j < CFArrayGetCount(runs); j++)
        //for(id runObj in (__bridge NSArray*)CTLineGetGlyphRuns(line))
        {
            CTRunRef run = CFArrayGetValueAtIndex(runs, j);
}

What I need to do is to get the actual string of characters that contains this run. If I get the glyphs then these are not actual characters, is there any way to for example get an nsstring containing the actual text given a ctrun? Thanks

CTRunRef run = (CTRunRef)runObj;          
CFRange runRange = CTRunGetStringRange(run);
[[_attributedString attributedSubstringFromRange:NSMakeRange(runRange.location, runRange.length)] string]

No there is no way to get back the attributed string that was used in creation of a CTRun . Your program already ought to know this information, since it created the CTFrame , CTLine or CTRun from an attributed string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM