Search in sources :

Example 1 with CFRange

use of org.robovm.apple.corefoundation.CFRange in project playn by threerings.

the class RoboTextLayout method wrapLines.

private static CFArray wrapLines(NSAttributedString astring, float wrapWidth) {
    CTFramesetter fs = CTFramesetter.create(astring);
    try {
        // iOS lays things out from max-y up to zero (inverted coordinate system); so we need to
        // provide a large height for our rectangle to ensure that all lines "fit"
        CGPath path = CGPath.createWithRect(new CGRect(0, 0, wrapWidth, Float.MAX_VALUE / 2), CGAffineTransform.Identity());
        CTFrame frame = fs.createFrame(new CFRange(0, 0), path, null);
        return frame.getLines();
    } finally {
        fs.dispose();
    }
}
Also used : CGPath(org.robovm.apple.coregraphics.CGPath) CGRect(org.robovm.apple.coregraphics.CGRect) CFRange(org.robovm.apple.corefoundation.CFRange)

Example 2 with CFRange

use of org.robovm.apple.corefoundation.CFRange in project playn by threerings.

the class RoboTextLayout method layoutText.

public static RoboTextLayout[] layoutText(RoboGraphics gfx, String text, TextFormat format, TextWrap wrap) {
    text = normalizeEOL(text);
    final RoboFont font = (format.font == null) ? RoboGraphics.defaultFont : (RoboFont) format.font;
    NSAttributedStringAttributes attribs = createAttribs(font);
    CFArray lines = wrapLines(new NSAttributedString(text, attribs), wrap.width);
    RoboTextLayout[] layouts = new RoboTextLayout[(int) lines.size()];
    for (int ii = 0; ii < layouts.length; ii++) {
        CTLine line = lines.get(ii, CTLine.class);
        CFRange range = line.getStringRange();
        String ltext = text.substring((int) range.getLocation(), (int) (range.getLocation() + range.getLength()));
        layouts[ii] = new RoboTextLayout(gfx, ltext, format, font, line);
    }
    return layouts;
}
Also used : NSAttributedStringAttributes(org.robovm.apple.uikit.NSAttributedStringAttributes) CFArray(org.robovm.apple.corefoundation.CFArray) NSAttributedString(org.robovm.apple.foundation.NSAttributedString) CFRange(org.robovm.apple.corefoundation.CFRange) CTLine(org.robovm.apple.coretext.CTLine) NSAttributedString(org.robovm.apple.foundation.NSAttributedString)

Aggregations

CFRange (org.robovm.apple.corefoundation.CFRange)2 CFArray (org.robovm.apple.corefoundation.CFArray)1 CGPath (org.robovm.apple.coregraphics.CGPath)1 CGRect (org.robovm.apple.coregraphics.CGRect)1 CTLine (org.robovm.apple.coretext.CTLine)1 NSAttributedString (org.robovm.apple.foundation.NSAttributedString)1 NSAttributedStringAttributes (org.robovm.apple.uikit.NSAttributedStringAttributes)1