Made the OS X code and the example program use the new layout stuff.
This commit is contained in:
parent
491ec3ae49
commit
8a64a1dfb0
|
@ -155,7 +155,7 @@ static uiDrawTextLayoutLineMetrics *computeLineMetrics(CTFrameRef frame, CGSize
|
||||||
return metrics;
|
return metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
uiDrawTextLayout *uiDrawNewTextLayout(uiAttributedString *s, uiDrawFontDescriptor *defaultFont, double width)
|
uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
|
||||||
{
|
{
|
||||||
uiDrawTextLayout *tl;
|
uiDrawTextLayout *tl;
|
||||||
CGFloat cgwidth;
|
CGFloat cgwidth;
|
||||||
|
@ -163,10 +163,10 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiAttributedString *s, uiDrawFontDescripto
|
||||||
CGRect rect;
|
CGRect rect;
|
||||||
|
|
||||||
tl = uiNew(uiDrawTextLayout);
|
tl = uiNew(uiDrawTextLayout);
|
||||||
tl->attrstr = attrstrToCoreFoundation(s, defaultFont);
|
tl->attrstr = attrstrToCoreFoundation(p->String, p->DefaultFont);
|
||||||
range.location = 0;
|
range.location = 0;
|
||||||
range.length = CFAttributedStringGetLength(tl->attrstr);
|
range.length = CFAttributedStringGetLength(tl->attrstr);
|
||||||
tl->width = width;
|
tl->width = p->Width;
|
||||||
|
|
||||||
// TODO CTFrameProgression for RTL/LTR
|
// TODO CTFrameProgression for RTL/LTR
|
||||||
// TODO kCTParagraphStyleSpecifierMaximumLineSpacing, kCTParagraphStyleSpecifierMinimumLineSpacing, kCTParagraphStyleSpecifierLineSpacingAdjustment for line spacing
|
// TODO kCTParagraphStyleSpecifierMaximumLineSpacing, kCTParagraphStyleSpecifierMinimumLineSpacing, kCTParagraphStyleSpecifierLineSpacingAdjustment for line spacing
|
||||||
|
@ -175,7 +175,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiAttributedString *s, uiDrawFontDescripto
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
cgwidth = (CGFloat) width;
|
cgwidth = (CGFloat) (tl->width);
|
||||||
if (cgwidth < 0)
|
if (cgwidth < 0)
|
||||||
cgwidth = CGFLOAT_MAX;
|
cgwidth = CGFLOAT_MAX;
|
||||||
// TODO these seem to be floor()'d or truncated?
|
// TODO these seem to be floor()'d or truncated?
|
||||||
|
@ -204,8 +204,8 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiAttributedString *s, uiDrawFontDescripto
|
||||||
tl->lineMetrics = computeLineMetrics(tl->frame, tl->size);
|
tl->lineMetrics = computeLineMetrics(tl->frame, tl->size);
|
||||||
|
|
||||||
// and finally copy the UTF-8/UTF-16 conversion tables
|
// and finally copy the UTF-8/UTF-16 conversion tables
|
||||||
tl->u8tou16 = attrstrCopyUTF8ToUTF16(s, &(tl->nUTF8));
|
tl->u8tou16 = attrstrCopyUTF8ToUTF16(p->String, &(tl->nUTF8));
|
||||||
tl->u16tou8 = attrstrCopyUTF16ToUTF8(s, &(tl->nUTF16));
|
tl->u16tou8 = attrstrCopyUTF16ToUTF8(p->String, &(tl->nUTF16));
|
||||||
|
|
||||||
return tl;
|
return tl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ static const char *text =
|
||||||
"and important."
|
"and important."
|
||||||
"";
|
"";
|
||||||
static char fontFamily[] = "Palatino";
|
static char fontFamily[] = "Palatino";
|
||||||
// TODO should be const; look at constructor function
|
// TODO should be const; look at constructor function?
|
||||||
static uiDrawFontDescriptor defaultFont = {
|
static uiDrawFontDescriptor defaultFont = {
|
||||||
.Family = fontFamily,
|
.Family = fontFamily,
|
||||||
.Size = 18,
|
.Size = 18,
|
||||||
|
@ -27,6 +27,7 @@ static uiDrawFontDescriptor defaultFont = {
|
||||||
.Stretch = uiDrawTextStretchNormal,
|
.Stretch = uiDrawTextStretchNormal,
|
||||||
};
|
};
|
||||||
static uiAttributedString *attrstr;
|
static uiAttributedString *attrstr;
|
||||||
|
static uiDrawTextLayoutParams params;
|
||||||
|
|
||||||
#define margins 10
|
#define margins 10
|
||||||
|
|
||||||
|
@ -141,9 +142,8 @@ static void draw(uiAreaDrawParams *p)
|
||||||
uiDrawFreePath(path);
|
uiDrawFreePath(path);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
layout = uiDrawNewTextLayout(attrstr,
|
params.Width = p->AreaWidth - 2 * margins;
|
||||||
&defaultFont,
|
layout = uiDrawNewTextLayout(¶ms);
|
||||||
p->AreaWidth - 2 * margins);
|
|
||||||
uiDrawText(p->Context, layout, margins, margins);
|
uiDrawText(p->Context, layout, margins, margins);
|
||||||
|
|
||||||
uiDrawRestore(p->Context);
|
uiDrawRestore(p->Context);
|
||||||
|
@ -257,6 +257,9 @@ struct example *mkBasicExample(void)
|
||||||
basicExample.key = NULL;
|
basicExample.key = NULL;
|
||||||
|
|
||||||
attrstr = uiNewAttributedString(text);
|
attrstr = uiNewAttributedString(text);
|
||||||
|
params.String = attrstr;
|
||||||
|
params.DefaultFont = &defaultFont;
|
||||||
|
params.Align = uiDrawTextLayoutAlignLeft;
|
||||||
|
|
||||||
return &basicExample;
|
return &basicExample;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ static uiDrawFontDescriptor defaultFont = {
|
||||||
.Stretch = uiDrawTextStretchNormal,
|
.Stretch = uiDrawTextStretchNormal,
|
||||||
};
|
};
|
||||||
static uiAttributedString *attrstr;
|
static uiAttributedString *attrstr;
|
||||||
|
static uiDrawTextLayoutParams params;
|
||||||
|
|
||||||
#define margins 10
|
#define margins 10
|
||||||
|
|
||||||
|
@ -88,9 +89,8 @@ static void draw(uiAreaDrawParams *p)
|
||||||
uiDrawClip(p->Context, path);
|
uiDrawClip(p->Context, path);
|
||||||
uiDrawFreePath(path);
|
uiDrawFreePath(path);
|
||||||
|
|
||||||
layout = uiDrawNewTextLayout(attrstr,
|
params.Width = p->AreaWidth - 2 * margins;
|
||||||
&defaultFont,
|
layout = uiDrawNewTextLayout(¶ms);
|
||||||
p->AreaWidth - 2 * margins);
|
|
||||||
uiDrawText(p->Context, layout, margins, margins);
|
uiDrawText(p->Context, layout, margins, margins);
|
||||||
|
|
||||||
uiDrawRestore(p->Context);
|
uiDrawRestore(p->Context);
|
||||||
|
@ -130,9 +130,8 @@ static void mouse(uiAreaMouseEvent *e)
|
||||||
if (e->Down != 1)
|
if (e->Down != 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
layout = uiDrawNewTextLayout(attrstr,
|
params.Width = e->AreaWidth - 2 * margins;
|
||||||
&defaultFont,
|
layout = uiDrawNewTextLayout(¶ms);
|
||||||
e->AreaWidth - 2 * margins);
|
|
||||||
uiDrawTextLayoutHitTest(layout,
|
uiDrawTextLayoutHitTest(layout,
|
||||||
e->X - margins, e->Y - margins,
|
e->X - margins, e->Y - margins,
|
||||||
&caretPos, &caretLine);
|
&caretPos, &caretLine);
|
||||||
|
@ -237,6 +236,9 @@ struct example *mkHitTestExample(void)
|
||||||
hitTestExample.key = key;
|
hitTestExample.key = key;
|
||||||
|
|
||||||
attrstr = uiNewAttributedString(text);
|
attrstr = uiNewAttributedString(text);
|
||||||
|
params.String = attrstr;
|
||||||
|
params.DefaultFont = &defaultFont;
|
||||||
|
params.Align = uiDrawTextLayoutAlignLeft;
|
||||||
|
|
||||||
return &hitTestExample;
|
return &hitTestExample;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,7 @@ typedef struct uiDrawTextLayout uiDrawTextLayout;
|
||||||
typedef struct uiDrawTextLayoutParams uiDrawTextLayoutParams;
|
typedef struct uiDrawTextLayoutParams uiDrawTextLayoutParams;
|
||||||
typedef struct uiDrawTextLayoutLineMetrics uiDrawTextLayoutLineMetrics;
|
typedef struct uiDrawTextLayoutLineMetrics uiDrawTextLayoutLineMetrics;
|
||||||
|
|
||||||
|
// TODO drop the Layout from this?
|
||||||
_UI_ENUM(uiDrawTextLayoutAlign) {
|
_UI_ENUM(uiDrawTextLayoutAlign) {
|
||||||
uiDrawTextLayoutAlignLeft,
|
uiDrawTextLayoutAlignLeft,
|
||||||
uiDrawTextLayoutAlignCenter,
|
uiDrawTextLayoutAlignCenter,
|
||||||
|
|
Loading…
Reference in New Issue