From 37f9bfd1b9e4b27e2e20d24d6ae2526012eec588 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 15 Jan 2016 22:48:38 -0500 Subject: [PATCH] More OS X layout work. --- darwin/drawtext.m | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/darwin/drawtext.m b/darwin/drawtext.m index df5cea89..773215d7 100644 --- a/darwin/drawtext.m +++ b/darwin/drawtext.m @@ -526,13 +526,21 @@ void uiDrawTextLayoutSetWidth(uiDrawTextLayout *layout, double width) layout->width = width; } +// TODO CTFrameProgression for RTL/LTR + +// TODO document that the extent width can be greater than the requested width if the requested width is small enough that only one character can fit +// TODO figure out how line separation and leading plays into this void uiDrawTextLayoutExtents(uiDrawTextLayout *layout, double *width, double *height) { CTLineRef line; + CTFramesetterRef fs; + CGSize size; + CFRange fitRange; double ascent, descent; double w; // one line + // TODO actually could not constraining the width of the framesetter do the same thing? if (layout->width < 0) { line = CTLineCreateWithAttributedString(layout->mas); if (line == NULL) @@ -544,7 +552,19 @@ void uiDrawTextLayoutExtents(uiDrawTextLayout *layout, double *width, double *he *height = ascent + descent; return; } - // TODO + + // multiple lines + fs = CTFramesetterCreateWithAttributedString(layout->mas); + if (fs == NULL) + complain("error creating CTFramesetter object in uiDrawTextLayoutExtents()"); + size = CTFramesetterSuggestFrameSizeWithConstraints(fs, + CFRangeMake(0, 0), + NULL, // TODO kCTFramePathWidthAttributeName? + CGSizeMake(layout->width, CGFLOAT_MAX), + &fitRange); // not documented as accepting NULL + CFRelease(fs); + *width = size.width; + *height = size.height; } // Core Text doesn't draw onto a flipped view correctly; we have to do this