diff --git a/darwin/drawtext.m b/darwin/drawtext.m index b90e7075..f175bee4 100644 --- a/darwin/drawtext.m +++ b/darwin/drawtext.m @@ -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; diff --git a/test/page9.c b/test/page9.c index 127f7cf0..c24cde16 100644 --- a/test/page9.c +++ b/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; diff --git a/ui.h b/ui.h index 3e40c121..bd27bdf4 100644 --- a/ui.h +++ b/ui.h @@ -513,6 +513,7 @@ struct uiDrawTextFontMetrics { double Ascent; double Descent; double Leading; + // TODO do these two mean the same across all platforms? double UnderlinePos; double UnderlineThickness; };