diff --git a/darwin/fontbutton.m b/darwin/fontbutton.m index 22bc6465..433f261f 100644 --- a/darwin/fontbutton.m +++ b/darwin/fontbutton.m @@ -11,7 +11,7 @@ - (void)activateFontButton; - (void)deactivateFontButton:(BOOL)activatingAnother; - (void)deactivateOnClose:(NSNotification *)note; -- (uiDrawTextFont *)libuiFont; +- (void)getfontdesc:(uiDrawFontDescriptor *)uidesc; @end // only one may be active at one time @@ -138,9 +138,16 @@ struct uiFontButton { NSFontPanelCollectionModeMask; } -- (uiDrawTextFont *)libuiFont +- (void)getfontdesc:(uiDrawFontDescriptor *)uidesc { - return mkTextFontFromNSFont(self->libui_font); + CTFontRef ctfont; + CTFontDescriptorRef ctdesc; + + ctfont = (CTFontRef) (self->libui_font); + ctdesc = CTFontCopyFontDescriptor(ctfont); + fontdescFromCTFontDescriptor(ctdesc, uidesc); + CFRelease(ctdesc); + uidesc->Size = CTFontGetSize(ctfont); } @end @@ -192,9 +199,9 @@ static void defaultOnChanged(uiFontButton *b, void *data) // do nothing } -uiDrawTextFont *uiFontButtonFont(uiFontButton *b) +void uiFontButtonFont(uiFontButton *b, uiDrawFontDescriptor *desc) { - return [b->button libuiFont]; + [b->button getfontdesc:desc]; } void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data) diff --git a/darwin/fontmatch.m b/darwin/fontmatch.m index 821855a7..e1660c8b 100644 --- a/darwin/fontmatch.m +++ b/darwin/fontmatch.m @@ -304,7 +304,7 @@ void fontdescFromCTFontDescriptor(CTFontDescriptorRef ctdesc, uiDrawFontDescript int wc; uiDrawTextStretch stretch; - cffamily = (CFStringRef) CTFontDescriptorCopyAttribute(cfdesc, kCTFontFamilyNameAttribute); + cffamily = (CFStringRef) CTFontDescriptorCopyAttribute(ctdesc, kCTFontFamilyNameAttribute); if (cffamily == NULL) { // TODO } @@ -312,7 +312,7 @@ void fontdescFromCTFontDescriptor(CTFontDescriptorRef ctdesc, uiDrawFontDescript uidesc->Family = uiDarwinNSStringToText((NSString *) cffamily); CFRelease(cffamily); - traits = (CFDictionaryRef) CTFontDescriptorCopyAttribute(cfdesc, kCTFontTraitsAttribute); + traits = (CFDictionaryRef) CTFontDescriptorCopyAttribute(ctdesc, kCTFontTraitsAttribute); if (traits == NULL) { // TODO } @@ -331,7 +331,7 @@ void fontdescFromCTFontDescriptor(CTFontDescriptorRef ctdesc, uiDrawFontDescript // TODO is this correct? for (stretch = uiDrawTextStretchUltraCondensed; stretch < uiDrawTextStretchUltraExpanded; stretch++) - if (ctstretch <= stretchesToCTWidth[stretch]) + if (ctstretch <= stretchesToCTWidths[stretch]) break; uidesc->Stretch = stretch; } diff --git a/examples/drawtext/hittest.c b/examples/drawtext/hittest.c index 2393e65b..2b80be5e 100644 --- a/examples/drawtext/hittest.c +++ b/examples/drawtext/hittest.c @@ -31,8 +31,10 @@ static uiAttributedString *attrstr; #define margins 10 static uiBox *panel; +static uiBox *vbox; static uiLabel *caretLabel; static uiCheckbox *showLineBounds; +static uiFontButton *fontButton; static int caretLine = -1; static size_t caretPos; @@ -189,22 +191,38 @@ static void checkboxChecked(uiCheckbox *c, void *data) redraw(); } -static uiCheckbox *newCheckbox(const char *text) +static void changeFont(uiFontButton *b, void *data) +{ + // TODO free old font name + // TODO rename defaultFont + uiFontButtonFont(fontButton, &defaultFont); + // TODO dump the new font + redraw(); +} + +// TODO share? +static uiCheckbox *newCheckbox(uiBox *box, const char *text) { uiCheckbox *c; c = uiNewCheckbox(text); uiCheckboxOnToggled(c, checkboxChecked, NULL); - uiBoxAppend(panel, uiControl(c), 0); + uiBoxAppend(box, uiControl(c), 0); return c; } struct example *mkHitTestExample(void) { - panel = uiNewVerticalBox(); + panel = uiNewHorizontalBox(); + vbox = uiNewVerticalBox(); + uiBoxAppend(panel, uiControl(vbox), 1); caretLabel = uiNewLabel("Caret information is shown here"); - uiBoxAppend(panel, uiControl(caretLabel), 0); - showLineBounds = newCheckbox("Show Line Bounds (for debugging metrics)"); + uiBoxAppend(vbox, uiControl(caretLabel), 0); + showLineBounds = newCheckbox(vbox, "Show Line Bounds (for debugging metrics)"); + fontButton = uiNewFontButton(); + uiFontButtonOnChanged(fontButton, changeFont, NULL); + // TODO set the font button to the current defaultFont + uiBoxAppend(panel, uiControl(fontButton), 0); hitTestExample.name = "Hit-Testing and Grapheme Boundaries"; hitTestExample.panel = uiControl(panel);