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);
|
||||
}
|
||||
|
||||
// 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 {
|
||||
CTFontRef f;
|
||||
};
|
||||
|
@ -429,6 +416,18 @@ void uiDrawTextFontDescribe(uiDrawTextFont *font, uiDrawTextFontDescriptor *desc
|
|||
// 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 {
|
||||
CFMutableAttributedStringRef mas;
|
||||
intmax_t *bytesToCharacters;
|
||||
|
|
19
test/page9.c
19
test/page9.c
|
@ -10,6 +10,7 @@ static uiCheckbox *textSmallCaps;
|
|||
static uiCombobox *textStretch;
|
||||
static uiCombobox *textGravity;
|
||||
static uiButton *textApply;
|
||||
static uiCheckbox *addLeading;
|
||||
static uiArea *textArea;
|
||||
static uiAreaHandler textAreaHandler;
|
||||
|
||||
|
@ -32,6 +33,7 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
|
|||
char *family; // make compiler happy
|
||||
uiDrawTextLayout *layout;
|
||||
uiDrawTextFontMetrics metrics;
|
||||
double ypos;
|
||||
|
||||
memset(&desc, 0, sizeof (uiDrawTextFontDescriptor));
|
||||
family = uiEntryText(textFont);
|
||||
|
@ -49,11 +51,15 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
|
|||
s = uiEntryText(textString);
|
||||
layout = uiDrawNewTextLayout(s, font);
|
||||
uiFreeText(s);
|
||||
uiDrawText(dp->Context, 10, 10, layout);
|
||||
ypos = 10;
|
||||
uiDrawText(dp->Context, 10, ypos, layout);
|
||||
uiDrawFreeTextLayout(layout);
|
||||
|
||||
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);
|
||||
|
||||
uiDrawFreeTextFont(font);
|
||||
|
@ -163,9 +169,16 @@ uiBox *makePage9(void)
|
|||
uiComboboxSetSelected(textGravity, uiDrawTextGravitySouth);
|
||||
uiBoxAppend(hbox, uiControl(textGravity), 1);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
uiBoxAppend(vbox, uiControl(hbox), 0);
|
||||
|
||||
textApply = uiNewButton("Apply");
|
||||
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.MouseEvent = handlerMouseEvent;
|
||||
|
|
Loading…
Reference in New Issue