2017-01-02 22:53:31 -06:00
|
|
|
// 2 january 2017
|
2016-01-12 00:12:35 -06:00
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
struct uiDrawTextLayout {
|
|
|
|
CFAttributedStringRef attrstr;
|
|
|
|
double width;
|
2017-01-03 22:59:23 -06:00
|
|
|
CTFramesetterRef framesetter;
|
|
|
|
CGSize size;
|
|
|
|
CGPathRef path;
|
2016-01-12 00:12:35 -06:00
|
|
|
};
|
|
|
|
|
2017-01-03 11:18:17 -06:00
|
|
|
static CTFontRef fontdescToCTFont(uiDrawFontDescriptor *fd)
|
|
|
|
{
|
|
|
|
CTFontDescriptorRef desc;
|
|
|
|
CTFontRef font;
|
|
|
|
|
2017-01-03 22:59:23 -06:00
|
|
|
desc = fontdescToCTFontDescriptor(fd);
|
|
|
|
font = CTFontCreateWithFontDescriptor(desc, fd->Size, NULL);
|
2017-01-03 11:18:17 -06:00
|
|
|
CFRelease(desc); // TODO correct?
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CFAttributedStringRef attrstrToCoreFoundation(uiAttributedString *s, uiDrawFontDescriptor *defaultFont)
|
2016-01-12 00:12:35 -06:00
|
|
|
{
|
|
|
|
CFStringRef cfstr;
|
2017-01-03 11:18:17 -06:00
|
|
|
CFMutableDictionaryRef defaultAttrs;
|
|
|
|
CTFontRef defaultCTFont;
|
2017-01-02 22:53:31 -06:00
|
|
|
CFAttributedStringRef base;
|
|
|
|
CFMutableAttributedStringRef mas;
|
2016-01-12 00:12:35 -06:00
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
cfstr = CFStringCreateWithCharacters(NULL, attrstrUTF16(s), attrstrUTF16Len(s));
|
|
|
|
if (cfstr == NULL) {
|
|
|
|
// TODO
|
2016-01-12 00:12:35 -06:00
|
|
|
}
|
2017-01-03 11:18:17 -06:00
|
|
|
defaultAttrs = CFDictionaryCreateMutable(NULL, 1,
|
2017-01-02 22:53:31 -06:00
|
|
|
&kCFCopyStringDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
if (defaultAttrs == NULL) {
|
|
|
|
// TODO
|
2016-01-12 00:12:35 -06:00
|
|
|
}
|
2017-01-03 11:18:17 -06:00
|
|
|
defaultCTFont = fontdescToCTFont(defaultFont);
|
|
|
|
CFDictionaryAddValue(defaultAttrs, kCTFontAttributeName, defaultCTFont);
|
|
|
|
CFRelease(defaultCTFont);
|
2016-01-12 00:12:35 -06:00
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
base = CFAttributedStringCreate(NULL, cfstr, defaultAttrs);
|
|
|
|
if (base == NULL) {
|
|
|
|
// TODO
|
2016-01-12 00:12:35 -06:00
|
|
|
}
|
2017-01-02 22:53:31 -06:00
|
|
|
CFRelease(cfstr);
|
|
|
|
CFRelease(defaultAttrs);
|
|
|
|
mas = CFAttributedStringCreateMutableCopy(NULL, 0, base);
|
|
|
|
CFRelease(base);
|
2016-01-12 00:46:28 -06:00
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
CFAttributedStringBeginEditing(mas);
|
|
|
|
// TODO copy in the attributes
|
|
|
|
CFAttributedStringEndEditing(mas);
|
2016-01-12 00:12:35 -06:00
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
return mas;
|
2016-01-12 00:46:28 -06:00
|
|
|
}
|
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
uiDrawTextLayout *uiDrawNewTextLayout(uiAttributedString *s, uiDrawFontDescriptor *defaultFont, double width)
|
2016-01-12 00:46:28 -06:00
|
|
|
{
|
2017-01-03 22:59:23 -06:00
|
|
|
uiDrawTextLayout *tl;
|
|
|
|
CGFloat cgwidth;
|
|
|
|
CFRange range, unused;
|
|
|
|
CGRect rect;
|
|
|
|
|
|
|
|
tl = uiNew(uiDrawTextLayout);
|
|
|
|
tl->attrstr = attrstrToCoreFoundation(s, defaultFont);
|
|
|
|
range.location = 0;
|
|
|
|
range.length = CFAttributedStringGetLength(tl->attrstr);
|
|
|
|
tl->width = width;
|
|
|
|
|
|
|
|
// TODO CTFrameProgression for RTL/LTR
|
|
|
|
// TODO kCTParagraphStyleSpecifierMaximumLineSpacing, kCTParagraphStyleSpecifierMinimumLineSpacing, kCTParagraphStyleSpecifierLineSpacingAdjustment for line spacing
|
|
|
|
tl->framesetter = CTFramesetterCreateWithAttributedString(tl->attrstr);
|
|
|
|
if (tl->framesetter == NULL) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
cgwidth = (CGFloat) width;
|
|
|
|
if (cgwidth < 0)
|
|
|
|
cgwidth = CGFLOAT_MAX;
|
|
|
|
// TODO these seem to be floor()'d or truncated?
|
|
|
|
// TODO double check to make sure this TODO was right
|
|
|
|
tl->size = CTFramesetterSuggestFrameSizeWithConstraints(tl->framesetter,
|
|
|
|
range,
|
|
|
|
// TODO kCTFramePathWidthAttributeName?
|
|
|
|
NULL,
|
|
|
|
CGSizeMake(cgwidth, CGFLOAT_MAX),
|
|
|
|
&unused); // not documented as accepting NULL
|
|
|
|
|
|
|
|
rect.origin = CGZeroPoint;
|
|
|
|
rect.size = tl->size;
|
|
|
|
tl->path = CGPathCreateWithRect(rect, NULL);
|
|
|
|
return tl;
|
2016-01-12 00:12:35 -06:00
|
|
|
}
|
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
void uiDrawFreeTextLayout(uiDrawTextLayout *tl)
|
2016-01-12 00:12:35 -06:00
|
|
|
{
|
2017-01-03 22:59:23 -06:00
|
|
|
CFRelease(tl->path);
|
|
|
|
CFRelease(tl->framesetter);
|
2017-01-03 11:18:17 -06:00
|
|
|
CFRelease(tl->attrstr);
|
|
|
|
uiFree(tl);
|
2016-01-12 00:12:35 -06:00
|
|
|
}
|
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
void uiDrawText(uiDrawContext *c, uiDrawTextLayout *tl, double x, double y)
|
2016-01-15 19:18:53 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
void uiDrawTextLayoutExtents(uiDrawTextLayout *tl, double *width, double *height)
|
2016-01-16 12:34:22 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
int uiDrawTextLayoutNumLines(uiDrawTextLayout *tl)
|
2016-01-16 12:34:22 -06:00
|
|
|
{
|
|
|
|
}
|
2016-01-15 21:48:38 -06:00
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
void uiDrawTextLayoutLineByteRange(uiDrawTextLayout *tl, int line, size_t *start, size_t *end)
|
2016-01-15 19:18:53 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
void uiDrawTextLayoutLineGetMetrics(uiDrawTextLayout *tl, int line, uiDrawTextLayoutLineMetrics *m)
|
2016-01-12 00:12:35 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
void uiDrawTextLayoutByteIndexToGraphemeRect(uiDrawTextLayout *tl, size_t pos, int *line, double *x, double *y, double *width, double *height)
|
2016-01-12 00:12:35 -06:00
|
|
|
{
|
|
|
|
}
|
2016-01-13 14:17:49 -06:00
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
uiDrawTextLayoutHitTestResult uiDrawTextLayoutHitTest(uiDrawTextLayout *tl, double x, double y, size_t *byteIndex, int *line)
|
2016-05-23 00:11:43 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-02 22:53:31 -06:00
|
|
|
void uiDrawTextLayoutByteRangeToRectangle(uiDrawTextLayout *tl, size_t start, size_t end, uiDrawTextLayoutByteRangeRectangle *r)
|
2016-04-19 15:06:50 -05:00
|
|
|
{
|
|
|
|
}
|