Implemented the metrics stuff on OS X and improved the test a bit.
This commit is contained in:
parent
a082469cf8
commit
d6063394ee
|
@ -42,19 +42,6 @@ void uiDrawFreeFontFamilies(uiDrawFontFamilies *ff)
|
||||||
uiFree(ff);
|
uiFree(ff);
|
||||||
}
|
}
|
||||||
|
|
||||||
// these two are identical:
|
|
||||||
// - https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/CocoaTextArchitecture/TypoFeatures/TextSystemFeatures.html#//apple_ref/doc/uid/TP40009459-CH6-51627-BBCCHIFF text points are 72 per inch
|
|
||||||
// - https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Transforms/Transforms.html#//apple_ref/doc/uid/TP40003290-CH204-SW5 user space points are 72 per inch
|
|
||||||
double uiDrawTextSizeToPoints(double textSize)
|
|
||||||
{
|
|
||||||
return textSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
double uiDrawPointsToTextSize(double points)
|
|
||||||
{
|
|
||||||
return points;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct uiDrawTextFont {
|
struct uiDrawTextFont {
|
||||||
CTFontRef f;
|
CTFontRef f;
|
||||||
};
|
};
|
||||||
|
@ -429,6 +416,18 @@ void uiDrawTextFontDescribe(uiDrawTextFont *font, uiDrawTextFontDescriptor *desc
|
||||||
// TODO TODO TODO TODO
|
// TODO TODO TODO TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// text sizes and user space points are identical:
|
||||||
|
// - https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/CocoaTextArchitecture/TypoFeatures/TextSystemFeatures.html#//apple_ref/doc/uid/TP40009459-CH6-51627-BBCCHIFF text points are 72 per inch
|
||||||
|
// - https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Transforms/Transforms.html#//apple_ref/doc/uid/TP40003290-CH204-SW5 user space points are 72 per inch
|
||||||
|
void uiDrawTextFontGetMetrics(uiDrawTextFont *font, uiDrawTextFontMetrics *metrics)
|
||||||
|
{
|
||||||
|
metrics->Ascent = CTFontGetAscent(font->f);
|
||||||
|
metrics->Descent = CTFontGetDescent(font->f);
|
||||||
|
metrics->Leading = CTFontGetLeading(font->f);
|
||||||
|
metrics->UnderlinePos = CTFontGetUnderlinePosition(font->f);
|
||||||
|
metrics->UnderlineThickness = CTFontGetUnderlineThickness(font->f);
|
||||||
|
}
|
||||||
|
|
||||||
struct uiDrawTextLayout {
|
struct uiDrawTextLayout {
|
||||||
CFMutableAttributedStringRef mas;
|
CFMutableAttributedStringRef mas;
|
||||||
intmax_t *bytesToCharacters;
|
intmax_t *bytesToCharacters;
|
||||||
|
|
19
test/page9.c
19
test/page9.c
|
@ -10,6 +10,7 @@ static uiCheckbox *textSmallCaps;
|
||||||
static uiCombobox *textStretch;
|
static uiCombobox *textStretch;
|
||||||
static uiCombobox *textGravity;
|
static uiCombobox *textGravity;
|
||||||
static uiButton *textApply;
|
static uiButton *textApply;
|
||||||
|
static uiCheckbox *addLeading;
|
||||||
static uiArea *textArea;
|
static uiArea *textArea;
|
||||||
static uiAreaHandler textAreaHandler;
|
static uiAreaHandler textAreaHandler;
|
||||||
|
|
||||||
|
@ -32,6 +33,7 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
|
||||||
char *family; // make compiler happy
|
char *family; // make compiler happy
|
||||||
uiDrawTextLayout *layout;
|
uiDrawTextLayout *layout;
|
||||||
uiDrawTextFontMetrics metrics;
|
uiDrawTextFontMetrics metrics;
|
||||||
|
double ypos;
|
||||||
|
|
||||||
memset(&desc, 0, sizeof (uiDrawTextFontDescriptor));
|
memset(&desc, 0, sizeof (uiDrawTextFontDescriptor));
|
||||||
family = uiEntryText(textFont);
|
family = uiEntryText(textFont);
|
||||||
|
@ -49,11 +51,15 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
|
||||||
s = uiEntryText(textString);
|
s = uiEntryText(textString);
|
||||||
layout = uiDrawNewTextLayout(s, font);
|
layout = uiDrawNewTextLayout(s, font);
|
||||||
uiFreeText(s);
|
uiFreeText(s);
|
||||||
uiDrawText(dp->Context, 10, 10, layout);
|
ypos = 10;
|
||||||
|
uiDrawText(dp->Context, 10, ypos, layout);
|
||||||
uiDrawFreeTextLayout(layout);
|
uiDrawFreeTextLayout(layout);
|
||||||
|
|
||||||
layout = uiDrawNewTextLayout("This is a second line", font);
|
layout = uiDrawNewTextLayout("This is a second line", font);
|
||||||
uiDrawText(dp->Context, 10, 10 + metrics.Ascent + metrics.Descent + metrics.Leading, layout);
|
ypos += metrics.Ascent + metrics.Descent;
|
||||||
|
if (uiCheckboxChecked(addLeading))
|
||||||
|
ypos += metrics.Leading;
|
||||||
|
uiDrawText(dp->Context, 10, ypos, layout);
|
||||||
uiDrawFreeTextLayout(layout);
|
uiDrawFreeTextLayout(layout);
|
||||||
|
|
||||||
uiDrawFreeTextFont(font);
|
uiDrawFreeTextFont(font);
|
||||||
|
@ -163,9 +169,16 @@ uiBox *makePage9(void)
|
||||||
uiComboboxSetSelected(textGravity, uiDrawTextGravitySouth);
|
uiComboboxSetSelected(textGravity, uiDrawTextGravitySouth);
|
||||||
uiBoxAppend(hbox, uiControl(textGravity), 1);
|
uiBoxAppend(hbox, uiControl(textGravity), 1);
|
||||||
|
|
||||||
|
hbox = newHorizontalBox();
|
||||||
|
uiBoxAppend(vbox, uiControl(hbox), 0);
|
||||||
|
|
||||||
textApply = uiNewButton("Apply");
|
textApply = uiNewButton("Apply");
|
||||||
uiButtonOnClicked(textApply, onTextApply, NULL);
|
uiButtonOnClicked(textApply, onTextApply, NULL);
|
||||||
uiBoxAppend(vbox, uiControl(textApply), 0);
|
uiBoxAppend(hbox, uiControl(textApply), 1);
|
||||||
|
|
||||||
|
addLeading = uiNewCheckbox("Add Leading");
|
||||||
|
uiCheckboxSetChecked(addLeading, 1);
|
||||||
|
uiBoxAppend(hbox, uiControl(addLeading), 0);
|
||||||
|
|
||||||
textAreaHandler.Draw = handlerDraw;
|
textAreaHandler.Draw = handlerDraw;
|
||||||
textAreaHandler.MouseEvent = handlerMouseEvent;
|
textAreaHandler.MouseEvent = handlerMouseEvent;
|
||||||
|
|
1
ui.h
1
ui.h
|
@ -513,6 +513,7 @@ struct uiDrawTextFontMetrics {
|
||||||
double Ascent;
|
double Ascent;
|
||||||
double Descent;
|
double Descent;
|
||||||
double Leading;
|
double Leading;
|
||||||
|
// TODO do these two mean the same across all platforms?
|
||||||
double UnderlinePos;
|
double UnderlinePos;
|
||||||
double UnderlineThickness;
|
double UnderlineThickness;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue