Merge 836fda6aaf
into fea45b2d5b
This commit is contained in:
commit
8912fb6e5f
|
@ -212,3 +212,15 @@ void uiDrawTextLayoutExtents(uiDrawTextLayout *tl, double *width, double *height
|
||||||
[tl->frame returnWidth:width height:NULL];
|
[tl->frame returnWidth:width height:NULL];
|
||||||
[tl->forLines returnWidth:NULL height:height];
|
[tl->forLines returnWidth:NULL height:height];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiLoadControlFont(uiFontDescriptor *f)
|
||||||
|
{
|
||||||
|
CTFontRef ctfont;
|
||||||
|
CTFontDescriptorRef ctdesc;
|
||||||
|
|
||||||
|
ctfont = (CTFontRef) [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSControlSizeRegular]];
|
||||||
|
ctdesc = CTFontCopyFontDescriptor(ctfont);
|
||||||
|
uiprivFontDescriptorFromCTFontDescriptor(ctdesc, f);
|
||||||
|
CFRelease(ctdesc);
|
||||||
|
f->Size = CTFontGetSize(ctfont);
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ uiArea *area;
|
||||||
uiAreaHandler handler;
|
uiAreaHandler handler;
|
||||||
uiFontButton *fontButton;
|
uiFontButton *fontButton;
|
||||||
uiCombobox *alignment;
|
uiCombobox *alignment;
|
||||||
|
uiCheckbox *systemFont;
|
||||||
|
|
||||||
uiAttributedString *attrstr;
|
uiAttributedString *attrstr;
|
||||||
|
|
||||||
|
@ -97,15 +98,21 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
|
||||||
uiDrawTextLayout *textLayout;
|
uiDrawTextLayout *textLayout;
|
||||||
uiFontDescriptor defaultFont;
|
uiFontDescriptor defaultFont;
|
||||||
uiDrawTextLayoutParams params;
|
uiDrawTextLayoutParams params;
|
||||||
|
int useSystemFont = uiCheckboxChecked(systemFont);
|
||||||
|
|
||||||
params.String = attrstr;
|
params.String = attrstr;
|
||||||
uiFontButtonFont(fontButton, &defaultFont);
|
if (useSystemFont)
|
||||||
|
uiLoadControlFont(&defaultFont);
|
||||||
|
else
|
||||||
|
uiFontButtonFont(fontButton, &defaultFont);
|
||||||
params.DefaultFont = &defaultFont;
|
params.DefaultFont = &defaultFont;
|
||||||
params.Width = p->AreaWidth;
|
params.Width = p->AreaWidth;
|
||||||
params.Align = (uiDrawTextAlign) uiComboboxSelected(alignment);
|
params.Align = (uiDrawTextAlign) uiComboboxSelected(alignment);
|
||||||
textLayout = uiDrawNewTextLayout(¶ms);
|
textLayout = uiDrawNewTextLayout(¶ms);
|
||||||
uiDrawText(p->Context, textLayout, 0, 0);
|
uiDrawText(p->Context, textLayout, 0, 0);
|
||||||
uiDrawFreeTextLayout(textLayout);
|
uiDrawFreeTextLayout(textLayout);
|
||||||
|
|
||||||
|
//TODO RENAME?
|
||||||
uiFreeFontButtonFont(&defaultFont);
|
uiFreeFontButtonFont(&defaultFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +147,11 @@ static void onComboboxSelected(uiCombobox *b, void *data)
|
||||||
uiAreaQueueRedrawAll(area);
|
uiAreaQueueRedrawAll(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void onCheckboxToggled(uiCheckbox *b, void *data)
|
||||||
|
{
|
||||||
|
uiAreaQueueRedrawAll(area);
|
||||||
|
}
|
||||||
|
|
||||||
static int onClosing(uiWindow *w, void *data)
|
static int onClosing(uiWindow *w, void *data)
|
||||||
{
|
{
|
||||||
uiControlDestroy(uiControl(mainwin));
|
uiControlDestroy(uiControl(mainwin));
|
||||||
|
@ -208,6 +220,10 @@ int main(void)
|
||||||
uiComboboxOnSelected(alignment, onComboboxSelected, NULL);
|
uiComboboxOnSelected(alignment, onComboboxSelected, NULL);
|
||||||
uiFormAppend(form, "Alignment", uiControl(alignment), 0);
|
uiFormAppend(form, "Alignment", uiControl(alignment), 0);
|
||||||
|
|
||||||
|
systemFont = uiNewCheckbox("");
|
||||||
|
uiCheckboxOnToggled(systemFont, onCheckboxToggled, NULL);
|
||||||
|
uiFormAppend(form, "System Font", uiControl(systemFont), 0);
|
||||||
|
|
||||||
area = uiNewArea(&handler);
|
area = uiNewArea(&handler);
|
||||||
uiBoxAppend(hbox, uiControl(area), 1);
|
uiBoxAppend(hbox, uiControl(area), 1);
|
||||||
|
|
||||||
|
|
2
ui.h
2
ui.h
|
@ -923,6 +923,8 @@ struct uiFontDescriptor {
|
||||||
uiTextStretch Stretch;
|
uiTextStretch Stretch;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_UI_EXTERN void uiLoadControlFont(uiFontDescriptor *f);
|
||||||
|
|
||||||
// uiDrawTextLayout is a concrete representation of a
|
// uiDrawTextLayout is a concrete representation of a
|
||||||
// uiAttributedString that can be displayed in a uiDrawContext.
|
// uiAttributedString that can be displayed in a uiDrawContext.
|
||||||
// It includes information important for the drawing of a block of
|
// It includes information important for the drawing of a block of
|
||||||
|
|
|
@ -79,3 +79,19 @@ void uiDrawTextLayoutExtents(uiDrawTextLayout *tl, double *width, double *height
|
||||||
*width = pangoToCairo(logical.width);
|
*width = pangoToCairo(logical.width);
|
||||||
*height = pangoToCairo(logical.height);
|
*height = pangoToCairo(logical.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiLoadControlFont(uiFontDescriptor *f)
|
||||||
|
{
|
||||||
|
GtkWidget *widget;
|
||||||
|
GtkStyleContext *style;
|
||||||
|
PangoFontDescription *fontdesc;
|
||||||
|
|
||||||
|
widget = g_object_ref_sink(gtk_label_new(""));
|
||||||
|
style = gtk_widget_get_style_context(widget);
|
||||||
|
gtk_style_context_get(style, GTK_STATE_FLAG_NORMAL,
|
||||||
|
"font", &fontdesc, NULL);
|
||||||
|
uiprivFontDescriptorFromPangoFontDescription(fontdesc, f);
|
||||||
|
// pdesc is transfer-full and thus is a copy
|
||||||
|
pango_font_description_free(fontdesc);
|
||||||
|
g_object_unref(widget);
|
||||||
|
}
|
||||||
|
|
|
@ -534,3 +534,53 @@ void uiDrawTextLayoutExtents(uiDrawTextLayout *tl, double *width, double *height
|
||||||
// TODO make sure the behavior of this on empty strings is the same on all platforms (ideally should be 0-width, line height-height; TODO note this in the docs too)
|
// TODO make sure the behavior of this on empty strings is the same on all platforms (ideally should be 0-width, line height-height; TODO note this in the docs too)
|
||||||
*height = metrics.height;
|
*height = metrics.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiLoadControlFont(uiFontDescriptor *f)
|
||||||
|
{
|
||||||
|
fontCollection *collection;
|
||||||
|
IDWriteGdiInterop *gdi;
|
||||||
|
IDWriteFont *dwfont;
|
||||||
|
IDWriteFontFamily *dwfamily;
|
||||||
|
NONCLIENTMETRICSW metrics;
|
||||||
|
HDC dc;
|
||||||
|
WCHAR *family;
|
||||||
|
double size;
|
||||||
|
int pixels;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
metrics.cbSize = sizeof(metrics);
|
||||||
|
if (!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, metrics.cbSize, &metrics, 0))
|
||||||
|
logLastError(L"error getting non-client metrics");
|
||||||
|
hr = dwfactory->GetGdiInterop(&gdi);
|
||||||
|
if (hr != S_OK)
|
||||||
|
logHRESULT(L"error getting GDI interop", hr);
|
||||||
|
|
||||||
|
hr = gdi->CreateFontFromLOGFONT(&metrics.lfMessageFont, &dwfont);
|
||||||
|
if (hr != S_OK)
|
||||||
|
logHRESULT(L"error loading font", hr);
|
||||||
|
|
||||||
|
hr = dwfont->GetFontFamily(&dwfamily);
|
||||||
|
if (hr != S_OK)
|
||||||
|
logHRESULT(L"error loading font family", hr);
|
||||||
|
collection = uiprivLoadFontCollection();
|
||||||
|
family = uiprivFontCollectionFamilyName(collection, dwfamily);
|
||||||
|
|
||||||
|
dc = GetDC(NULL);
|
||||||
|
if (dc == NULL)
|
||||||
|
logLastError(L"error getting DC");
|
||||||
|
pixels = GetDeviceCaps(dc, LOGPIXELSY);
|
||||||
|
if (pixels == 0)
|
||||||
|
logLastError(L"error getting device caps");
|
||||||
|
size = abs(metrics.lfMessageFont.lfHeight) * 72 / pixels;
|
||||||
|
|
||||||
|
uiprivFontDescriptorFromIDWriteFont(dwfont, f);
|
||||||
|
f->Family = toUTF8(family);
|
||||||
|
f->Size = size;
|
||||||
|
|
||||||
|
uiprivFree(family);
|
||||||
|
uiprivFontCollectionFree(collection);
|
||||||
|
dwfamily->Release();
|
||||||
|
gdi->Release();
|
||||||
|
if (ReleaseDC(NULL, dc) == 0)
|
||||||
|
logLastError(L"error releasing DC");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue