Implemented the new fontbutton routines on GTK+.
This commit is contained in:
parent
cfa1b6bf0a
commit
e6effa042d
31
unix/draw.c
31
unix/draw.c
|
@ -538,12 +538,27 @@ static const PangoStretch pangoStretches[] = {
|
|||
// TODO really see if there's a better way instead; what do GDK and GTK+ do internally? gdk_pango_context_get()?
|
||||
#define mkGenericPangoCairoContext() (pango_font_map_create_context(pango_cairo_font_map_get_default()))
|
||||
|
||||
PangoFont *pangoDescToPangoFont(PangoFontDescription *pdesc)
|
||||
{
|
||||
PangoFont *f;
|
||||
PangoContext *context;
|
||||
|
||||
// in this case, the context is necessary for the metrics to be correct
|
||||
context = mkGenericPangoCairoContext();
|
||||
f = pango_font_map_load_font(pango_cairo_font_map_get_default(), context, pdesc);
|
||||
if (f == NULL) {
|
||||
// TODO
|
||||
g_error("[libui] no match in pangoDescToPangoFont(); report to andlabs");
|
||||
}
|
||||
g_object_unref(context);
|
||||
return f;
|
||||
}
|
||||
|
||||
uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc)
|
||||
{
|
||||
PangoFont *f;
|
||||
PangoFontDescription *pdesc;
|
||||
//TODO PangoVariant variant;
|
||||
PangoContext *context;
|
||||
|
||||
pdesc = pango_font_description_new();
|
||||
pango_font_description_set_family(pdesc,
|
||||
|
@ -563,17 +578,9 @@ TODO
|
|||
#endif
|
||||
pango_font_description_set_stretch(pdesc,
|
||||
pangoStretches[desc->Stretch]);
|
||||
|
||||
// in this case, the context is necessary for the metrics to be correct
|
||||
context = mkGenericPangoCairoContext();
|
||||
f = pango_font_map_load_font(pango_cairo_font_map_get_default(), context, pdesc);
|
||||
if (f == NULL) {
|
||||
// TODO
|
||||
g_error("[libui] no match in uiDrawLoadClosestFont(); report to andlabs");
|
||||
}
|
||||
g_object_unref(context);
|
||||
|
||||
return mkTextFont(f, FALSE); // we hold the initial reference; no need to retain
|
||||
f = pangoDescToPangoFont(pdesc);
|
||||
pango_font_description_free(pdesc);
|
||||
return mkTextFont(f, FALSE); // we hold the initial reference; no need to ref
|
||||
}
|
||||
|
||||
void uiDrawFreeTextFont(uiDrawTextFont *font)
|
||||
|
|
|
@ -7,6 +7,8 @@ struct uiFontButton {
|
|||
GtkButton *button;
|
||||
GtkFontButton *fb;
|
||||
GtkFontChooser *fc;
|
||||
void (*onChanged)(uiFontButton *, void *);
|
||||
void *onChangedData;
|
||||
};
|
||||
|
||||
uiUnixDefineControl(
|
||||
|
@ -19,25 +21,31 @@ static void onFontSet(GtkFontButton *button, gpointer data)
|
|||
{
|
||||
uiFontButton *b = uiFontButton(data);
|
||||
|
||||
//TODO (*(b->onClicked))(b, b->onClickedData);
|
||||
(*(b->onChanged))(b, b->onChangedData);
|
||||
}
|
||||
|
||||
#if 0
|
||||
TODO
|
||||
static void defaultOnClicked(uiButton *b, void *data)
|
||||
static void defaultOnChanged(uiFontButton *b, void *data)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
TODO
|
||||
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
|
||||
uiDrawTextFont *uiFontButtonFont(uiFontButton *b)
|
||||
{
|
||||
b->onClicked = f;
|
||||
b->onClickedData = data;
|
||||
PangoFont *f;
|
||||
PangoFontDescription *desc;
|
||||
|
||||
desc = gtk_font_chooser_get_font_desc(b->fc);
|
||||
f = pangoDescToPangoFont(desc);
|
||||
// desc is transfer-full and thus is a copy
|
||||
pango_font_description_free(desc);
|
||||
return mkTextFont(f, FALSE); // we hold the initial reference; no need to ref
|
||||
}
|
||||
|
||||
void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data)
|
||||
{
|
||||
b->onChanged = f;
|
||||
b->onChangedData = data;
|
||||
}
|
||||
#endif
|
||||
|
||||
uiFontButton *uiNewFontButton(void)
|
||||
{
|
||||
|
@ -59,7 +67,7 @@ uiFontButton *uiNewFontButton(void)
|
|||
gtk_font_chooser_set_show_preview_entry(b->fc, TRUE);
|
||||
|
||||
g_signal_connect(b->widget, "font-set", G_CALLBACK(onFontSet), b);
|
||||
//TODO uiButtonOnClicked(b, defaultOnClicked, NULL);
|
||||
uiFontButtonOnChanged(b, defaultOnChanged, NULL);
|
||||
|
||||
uiUnixFinishNewControl(b, uiFontButton);
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ extern void childSetMargined(struct child *c, int margined);
|
|||
extern uiDrawContext *newContext(cairo_t *);
|
||||
extern void freeContext(uiDrawContext *);
|
||||
extern uiDrawTextFont *mkTextFont(PangoFont *f, gboolean add);
|
||||
extern PangoFont *pangoDescToPangoFont(PangoFontDescription *pdesc);
|
||||
|
||||
// TODO
|
||||
#define uiControlQueueResize(...)
|
||||
|
|
Loading…
Reference in New Issue