Started working on text metrics support.
This commit is contained in:
parent
09458c794a
commit
a082469cf8
18
test/page9.c
18
test/page9.c
|
@ -31,6 +31,7 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
|
|||
char *s;
|
||||
char *family; // make compiler happy
|
||||
uiDrawTextLayout *layout;
|
||||
uiDrawTextFontMetrics metrics;
|
||||
|
||||
memset(&desc, 0, sizeof (uiDrawTextFontDescriptor));
|
||||
family = uiEntryText(textFont);
|
||||
|
@ -41,18 +42,21 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
|
|||
desc.SmallCaps = uiCheckboxChecked(textSmallCaps);
|
||||
desc.Stretch = uiComboboxSelected(textStretch);
|
||||
desc.Gravity = uiComboboxSelected(textGravity);
|
||||
|
||||
font = uiDrawLoadClosestFont(&desc);
|
||||
uiFreeText(family);
|
||||
uiDrawTextFontGetMetrics(font, &metrics);
|
||||
|
||||
s = uiEntryText(textString);
|
||||
layout = uiDrawNewTextLayout(s, font);
|
||||
|
||||
uiDrawText(dp->Context, 10, 10, layout);
|
||||
|
||||
uiDrawFreeTextLayout(layout);
|
||||
uiDrawFreeTextFont(font);
|
||||
uiFreeText(s);
|
||||
uiFreeText(family);
|
||||
uiDrawText(dp->Context, 10, 10, layout);
|
||||
uiDrawFreeTextLayout(layout);
|
||||
|
||||
layout = uiDrawNewTextLayout("This is a second line", font);
|
||||
uiDrawText(dp->Context, 10, 10 + metrics.Ascent + metrics.Descent + metrics.Leading, layout);
|
||||
uiDrawFreeTextLayout(layout);
|
||||
|
||||
uiDrawFreeTextFont(font);
|
||||
}
|
||||
|
||||
static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e)
|
||||
|
|
13
ui.h
13
ui.h
|
@ -456,6 +456,7 @@ _UI_EXTERN void uiDrawFreeFontFamilies(uiDrawFontFamilies *ff);
|
|||
typedef struct uiDrawTextLayout uiDrawTextLayout;
|
||||
typedef struct uiDrawTextFont uiDrawTextFont;
|
||||
typedef struct uiDrawTextFontDescriptor uiDrawTextFontDescriptor;
|
||||
typedef struct uiDrawTextFontMetrics uiDrawTextFontMetrics;
|
||||
|
||||
typedef enum uiDrawTextWeight {
|
||||
uiDrawTextWeightThin,
|
||||
|
@ -508,15 +509,21 @@ struct uiDrawTextFontDescriptor {
|
|||
uiDrawTextGravity Gravity;
|
||||
};
|
||||
|
||||
// TODO wait why do I have these functions? I don't think they provide a correct line height...
|
||||
_UI_EXTERN double uiDrawTextSizeToPoints(double textSize);
|
||||
_UI_EXTERN double uiDrawPointsToTextSize(double points);
|
||||
struct uiDrawTextFontMetrics {
|
||||
double Ascent;
|
||||
double Descent;
|
||||
double Leading;
|
||||
double UnderlinePos;
|
||||
double UnderlineThickness;
|
||||
};
|
||||
|
||||
_UI_EXTERN uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc);
|
||||
_UI_EXTERN void uiDrawFreeTextFont(uiDrawTextFont *font);
|
||||
_UI_EXTERN uintptr_t uiDrawTextFontHandle(uiDrawTextFont *font);
|
||||
_UI_EXTERN void uiDrawTextFontDescribe(uiDrawTextFont *font, uiDrawTextFontDescriptor *desc);
|
||||
// TODO make copy with given attributes methods?
|
||||
// TODO yuck this name
|
||||
_UI_EXTERN void uiDrawTextFontGetMetrics(uiDrawTextFont *font, uiDrawTextFontMetrics *metrics);
|
||||
|
||||
_UI_EXTERN uiDrawTextLayout *uiDrawNewTextLayout(const char *text, uiDrawTextFont *defaultFont);
|
||||
_UI_EXTERN void uiDrawFreeTextLayout(uiDrawTextLayout *layout);
|
||||
|
|
Loading…
Reference in New Issue