Add uiDrawLoadDefaultFont() API
This commit is contained in:
parent
cda991b7e2
commit
2ff751a836
|
@ -212,3 +212,8 @@ 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];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uiDrawTextFont *uiDrawLoadDefaultFont()
|
||||||
|
{
|
||||||
|
return mkTextFontFromNSFont([NSFont systemFontOfSize:0]);
|
||||||
|
}
|
||||||
|
|
2
ui.h
2
ui.h
|
@ -919,6 +919,8 @@ struct uiFontDescriptor {
|
||||||
uiTextStretch Stretch;
|
uiTextStretch Stretch;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_UI_EXTERN uiDrawTextFont *uiDrawLoadDefaultFont();
|
||||||
|
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uiDrawTextFont *uiDrawLoadDefaultFont()
|
||||||
|
{
|
||||||
|
GtkWidget *widget;
|
||||||
|
GtkStyleContext *style;
|
||||||
|
PangoFontDescription *fontdesc;
|
||||||
|
PangoFont *font;
|
||||||
|
|
||||||
|
widget = g_object_ref_sink(gtk_drawing_area_new());
|
||||||
|
style = gtk_widget_get_style_context(widget);
|
||||||
|
gtk_style_context_get(style, GTK_STATE_FLAG_NORMAL,
|
||||||
|
"font", &fontdesc, NULL);
|
||||||
|
font = pangoDescToPangoFont(fontdesc);
|
||||||
|
g_object_unref(widget);
|
||||||
|
return mkTextFont(font, FALSE);
|
||||||
|
}
|
||||||
|
|
|
@ -534,3 +534,47 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uiDrawTextFont *uiDrawLoadDefaultFont()
|
||||||
|
{
|
||||||
|
uiDrawTextFont *font;
|
||||||
|
fontCollection *collection;
|
||||||
|
IDWriteGdiInterop *gdi;
|
||||||
|
IDWriteFont *dwfont;
|
||||||
|
IDWriteFontFamily *dwfamily;
|
||||||
|
NONCLIENTMETRICS metrics;
|
||||||
|
WCHAR *family;
|
||||||
|
double size;
|
||||||
|
int pixels;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
metrics.cbSize = sizeof(metrics);
|
||||||
|
if (!SystemParametersInfo(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 = loadFontCollection();
|
||||||
|
family = fontCollectionFamilyName(collection, dwfamily);
|
||||||
|
|
||||||
|
pixels = GetDeviceCaps(GetDC(NULL), LOGPIXELSY);
|
||||||
|
if (pixels == 0)
|
||||||
|
logLastError(L"error getting device caps");
|
||||||
|
size = abs(metrics.lfMessageFont.lfHeight) * 72 / pixels;
|
||||||
|
|
||||||
|
font = mkTextFont(dwfont, FALSE, family, FALSE, size);
|
||||||
|
|
||||||
|
fontCollectionFree(collection);
|
||||||
|
dwfamily->Release();
|
||||||
|
gdi->Release();
|
||||||
|
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue