fonts are no longer loaded from the theme file. instead, they are created by the application and passed in while creating/loading a theme
This commit is contained in:
parent
aeda86f460
commit
43d0f79057
5 changed files with 134 additions and 45 deletions
|
@ -75,10 +75,8 @@ static void measure_font(const RrInstance *inst, RrFont *f)
|
||||||
g_free(locale);
|
g_free(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RrFont *openfont(const RrInstance *inst, gchar *fontstring)
|
static RrFont *openfontstring(const RrInstance *inst, gchar *fontstring)
|
||||||
{
|
{
|
||||||
/* This function is called for each font in the theme file. */
|
|
||||||
/* It returns a pointer to a RrFont struct after filling it. */
|
|
||||||
RrFont *out;
|
RrFont *out;
|
||||||
FcPattern *pat;
|
FcPattern *pat;
|
||||||
gint tint;
|
gint tint;
|
||||||
|
@ -90,6 +88,7 @@ static RrFont *openfont(const RrInstance *inst, gchar *fontstring)
|
||||||
|
|
||||||
out = g_new(RrFont, 1);
|
out = g_new(RrFont, 1);
|
||||||
out->inst = inst;
|
out->inst = inst;
|
||||||
|
out->ref = 1;
|
||||||
out->font_desc = pango_font_description_new();
|
out->font_desc = pango_font_description_new();
|
||||||
out->layout = pango_layout_new(inst->pango);
|
out->layout = pango_layout_new(inst->pango);
|
||||||
|
|
||||||
|
@ -156,10 +155,12 @@ static RrFont *openfont(const RrInstance *inst, gchar *fontstring)
|
||||||
/* get the ascent and descent */
|
/* get the ascent and descent */
|
||||||
measure_font(inst, out);
|
measure_font(inst, out);
|
||||||
|
|
||||||
|
FcPatternDestroy(pat);
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
RrFont *RrFontOpen(const RrInstance *inst, gchar *fontstring)
|
RrFont *RrFontOpenByString(const RrInstance *inst, gchar *fontstring)
|
||||||
{
|
{
|
||||||
RrFont *out;
|
RrFont *out;
|
||||||
|
|
||||||
|
@ -168,24 +169,98 @@ RrFont *RrFontOpen(const RrInstance *inst, gchar *fontstring)
|
||||||
started = TRUE;
|
started = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((out = openfont(inst, fontstring)))
|
if ((out = openfontstring(inst, fontstring)))
|
||||||
return out;
|
return out;
|
||||||
g_warning(_("Unable to load font: %s\n"), fontstring);
|
g_warning(_("Unable to load font: %s\n"), fontstring);
|
||||||
g_warning(_("Trying fallback font: %s\n"), "sans");
|
g_warning(_("Trying fallback font: %s\n"), "sans");
|
||||||
|
|
||||||
if ((out = openfont(inst, "sans")))
|
if ((out = openfontstring(inst, "sans")))
|
||||||
return out;
|
return out;
|
||||||
g_warning(_("Unable to load font: %s\n"), "sans");
|
g_warning(_("Unable to load font: %s\n"), "sans");
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RrFont *RrFontOpen(const RrInstance *inst, gchar *name, gint size,
|
||||||
|
RrFontWeight weight, RrFontSlant slant, gboolean shadow,
|
||||||
|
gint shadowoffset, gchar shadowtint)
|
||||||
|
{
|
||||||
|
RrFont *out;
|
||||||
|
PangoWeight pweight;
|
||||||
|
PangoStyle pstyle;
|
||||||
|
|
||||||
|
if (!started) {
|
||||||
|
font_startup();
|
||||||
|
started = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_assert(shadowtint <= 100 && shadowtint >= -100);
|
||||||
|
|
||||||
|
out = g_new(RrFont, 1);
|
||||||
|
out->inst = inst;
|
||||||
|
out->ref = 1;
|
||||||
|
out->font_desc = pango_font_description_new();
|
||||||
|
out->layout = pango_layout_new(inst->pango);
|
||||||
|
|
||||||
|
switch (weight) {
|
||||||
|
case RR_FONTWEIGHT_LIGHT: pweight = PANGO_WEIGHT_LIGHT; break;
|
||||||
|
case RR_FONTWEIGHT_NORMAL: pweight = PANGO_WEIGHT_NORMAL; break;
|
||||||
|
case RR_FONTWEIGHT_SEMIBOLD: pweight = PANGO_WEIGHT_SEMIBOLD; break;
|
||||||
|
case RR_FONTWEIGHT_BOLD: pweight = PANGO_WEIGHT_BOLD; break;
|
||||||
|
case RR_FONTWEIGHT_ULTRABOLD: pweight = PANGO_WEIGHT_ULTRABOLD; break;
|
||||||
|
default: g_assert_not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (slant) {
|
||||||
|
case RR_FONTSLANT_NORMAL: pstyle = PANGO_STYLE_NORMAL; break;
|
||||||
|
case RR_FONTSLANT_ITALIC: pstyle = PANGO_STYLE_ITALIC; break;
|
||||||
|
case RR_FONTSLANT_OBLIQUE: pstyle = PANGO_STYLE_OBLIQUE; break;
|
||||||
|
default: g_assert_not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* setup the font */
|
||||||
|
pango_font_description_set_family(out->font_desc, name);
|
||||||
|
pango_font_description_set_weight(out->font_desc, pweight);
|
||||||
|
pango_font_description_set_style(out->font_desc, pstyle);
|
||||||
|
pango_font_description_set_size(out->font_desc, size * PANGO_SCALE);
|
||||||
|
|
||||||
|
/* setup the shadow */
|
||||||
|
out->shadow = shadow;
|
||||||
|
out->offset = shadowoffset;
|
||||||
|
out->tint = shadowtint;
|
||||||
|
|
||||||
|
/* setup the layout */
|
||||||
|
pango_layout_set_font_description(out->layout, out->font_desc);
|
||||||
|
pango_layout_set_single_paragraph_mode(out->layout, TRUE);
|
||||||
|
pango_layout_set_ellipsize(out->layout, PANGO_ELLIPSIZE_MIDDLE);
|
||||||
|
|
||||||
|
/* get the ascent and descent */
|
||||||
|
measure_font(inst, out);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
RrFont *RrFontOpenDefault(const RrInstance *inst)
|
||||||
|
{
|
||||||
|
return RrFontOpen(inst, RrDefaultFontFamily, RrDefaultFontSize,
|
||||||
|
RrDefaultFontWeight, RrDefaultFontSlant,
|
||||||
|
RrDefaultFontShadow, RrDefaultFontShadowOffset,
|
||||||
|
RrDefaultFontShadowTint);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RrFontRef(RrFont *f)
|
||||||
|
{
|
||||||
|
++f->ref;
|
||||||
|
}
|
||||||
|
|
||||||
void RrFontClose(RrFont *f)
|
void RrFontClose(RrFont *f)
|
||||||
{
|
{
|
||||||
if (f) {
|
if (f) {
|
||||||
g_object_unref(f->layout);
|
if (--f->ref < 1) {
|
||||||
pango_font_description_free(f->font_desc);
|
g_object_unref(f->layout);
|
||||||
g_free(f);
|
pango_font_description_free(f->font_desc);
|
||||||
|
g_free(f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,18 +25,20 @@
|
||||||
|
|
||||||
struct _RrFont {
|
struct _RrFont {
|
||||||
const RrInstance *inst;
|
const RrInstance *inst;
|
||||||
|
gint ref;
|
||||||
PangoFontDescription *font_desc;
|
PangoFontDescription *font_desc;
|
||||||
PangoLayout *layout; /*!< Used for measuring and rendering strings */
|
PangoLayout *layout; /*!< Used for measuring and rendering strings */
|
||||||
gint ascent; /*!< The font's ascent in pango-units */
|
gint ascent; /*!< The font's ascent in pango-units */
|
||||||
gint descent; /*!< The font's descent in pango-units */
|
gint descent; /*!< The font's descent in pango-units */
|
||||||
gint elipses_length; /*!< This one is in pixels, yay */
|
|
||||||
gint shadow;
|
gint shadow;
|
||||||
gchar tint;
|
gchar tint;
|
||||||
gint offset;
|
gint offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
RrFont *RrFontOpen(const RrInstance *inst, gchar *fontstring);
|
|
||||||
void RrFontClose(RrFont *f);
|
|
||||||
void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *position);
|
void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *position);
|
||||||
|
|
||||||
|
/*! Increment the references for this font, RrFontClose will decrement until 0
|
||||||
|
and then really close it */
|
||||||
|
void RrFontRef(RrFont *f);
|
||||||
|
|
||||||
#endif /* __font_h */
|
#endif /* __font_h */
|
||||||
|
|
|
@ -186,6 +186,14 @@ struct _RrAppearance {
|
||||||
#define RrDefaultGreenOffset 8
|
#define RrDefaultGreenOffset 8
|
||||||
#define RrDefaultBlueOffset 0
|
#define RrDefaultBlueOffset 0
|
||||||
|
|
||||||
|
#define RrDefaultFontFamily "arial,sans"
|
||||||
|
#define RrDefaultFontSize 8
|
||||||
|
#define RrDefaultFontWeight RR_FONTWEIGHT_NORMAL
|
||||||
|
#define RrDefaultFontSlant RR_FONTSLANT_NORMAL
|
||||||
|
#define RrDefaultFontShadow FALSE
|
||||||
|
#define RrDefaultFontShadowOffset 1
|
||||||
|
#define RrDefaultFontShadowTint 50
|
||||||
|
|
||||||
RrInstance* RrInstanceNew (Display *display, gint screen);
|
RrInstance* RrInstanceNew (Display *display, gint screen);
|
||||||
void RrInstanceFree (RrInstance *inst);
|
void RrInstanceFree (RrInstance *inst);
|
||||||
|
|
||||||
|
@ -219,9 +227,16 @@ RrAppearance *RrAppearanceNew (const RrInstance *inst, gint numtex);
|
||||||
RrAppearance *RrAppearanceCopy (RrAppearance *a);
|
RrAppearance *RrAppearanceCopy (RrAppearance *a);
|
||||||
void RrAppearanceFree (RrAppearance *a);
|
void RrAppearanceFree (RrAppearance *a);
|
||||||
|
|
||||||
|
RrFont *RrFontOpenByString (const RrInstance *inst, gchar *fontstring);
|
||||||
|
RrFont *RrFontOpen (const RrInstance *inst, gchar *name, gint size,
|
||||||
|
RrFontWeight weight, RrFontSlant slant,
|
||||||
|
gboolean shadow, gint shadowoffset,
|
||||||
|
gchar shadowtint);
|
||||||
|
RrFont *RrFontOpenDefault (const RrInstance *inst);
|
||||||
|
void RrFontClose (RrFont *f);
|
||||||
RrSize *RrFontMeasureString (const RrFont *f, const gchar *str);
|
RrSize *RrFontMeasureString (const RrFont *f, const gchar *str);
|
||||||
gint RrFontHeight (const RrFont *f);
|
gint RrFontHeight (const RrFont *f);
|
||||||
gint RrFontMaxCharWidth (const RrFont *f);
|
gint RrFontMaxCharWidth (const RrFont *f);
|
||||||
|
|
||||||
void RrPaint (RrAppearance *a, Window win, gint w, gint h);
|
void RrPaint (RrAppearance *a, Window win, gint w, gint h);
|
||||||
void RrMinsize (RrAppearance *a, gint *w, gint *h);
|
void RrMinsize (RrAppearance *a, gint *w, gint *h);
|
||||||
|
|
|
@ -45,12 +45,13 @@ static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
|
||||||
static RrPixel32* read_c_image(gint width, gint height, const guint8 *data);
|
static RrPixel32* read_c_image(gint width, gint height, const guint8 *data);
|
||||||
static void set_default_appearance(RrAppearance *a);
|
static void set_default_appearance(RrAppearance *a);
|
||||||
|
|
||||||
RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
|
RrTheme* RrThemeNew(const RrInstance *inst, gchar *name,
|
||||||
|
RrFont *active_window_font, RrFont *inactive_window_font,
|
||||||
|
RrFont *menu_title_font, RrFont *menu_item_font)
|
||||||
{
|
{
|
||||||
XrmDatabase db = NULL;
|
XrmDatabase db = NULL;
|
||||||
RrJustify winjust, mtitlejust;
|
RrJustify winjust, mtitlejust;
|
||||||
gchar *str;
|
gchar *str;
|
||||||
gchar *font_str;
|
|
||||||
RrTheme *theme;
|
RrTheme *theme;
|
||||||
|
|
||||||
theme = g_new0(RrTheme, 1);
|
theme = g_new0(RrTheme, 1);
|
||||||
|
@ -110,22 +111,18 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* load the font stuff */
|
/* load the font stuff */
|
||||||
if (!read_string(db, "window.active.label.text.font", &font_str))
|
if (active_window_font) {
|
||||||
font_str = "arial,sans:bold:pixelsize=10:shadow=y:shadowtint=50";
|
theme->win_font_focused = active_window_font;
|
||||||
|
RrFontRef(active_window_font);
|
||||||
if (!(theme->win_font_focused = RrFontOpen(inst, font_str))) {
|
} else
|
||||||
RrThemeFree(theme);
|
theme->win_font_focused = RrFontOpenDefault(inst);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
theme->win_font_height = RrFontHeight(theme->win_font_focused);
|
theme->win_font_height = RrFontHeight(theme->win_font_focused);
|
||||||
|
|
||||||
if (!read_string(db, "window.inactive.label.text.font", &font_str))
|
if (inactive_window_font) {
|
||||||
/* font_str will already be set to the last one */;
|
theme->win_font_unfocused = inactive_window_font;
|
||||||
|
RrFontRef(inactive_window_font);
|
||||||
if (!(theme->win_font_unfocused = RrFontOpen(inst, font_str))) {
|
} else
|
||||||
RrThemeFree(theme);
|
theme->win_font_unfocused = RrFontOpenDefault(inst);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
theme->win_font_height = MAX(theme->win_font_height,
|
theme->win_font_height = MAX(theme->win_font_height,
|
||||||
RrFontHeight(theme->win_font_unfocused));
|
RrFontHeight(theme->win_font_unfocused));
|
||||||
|
|
||||||
|
@ -137,13 +134,11 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
|
||||||
winjust = RR_JUSTIFY_CENTER;
|
winjust = RR_JUSTIFY_CENTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!read_string(db, "menu.title.text.font", &font_str))
|
if (menu_title_font) {
|
||||||
font_str = "arial,sans:bold:pixelsize=12:shadow=y";
|
theme->menu_title_font = menu_title_font;
|
||||||
|
RrFontRef(menu_title_font);
|
||||||
if (!(theme->menu_title_font = RrFontOpen(inst, font_str))) {
|
} else
|
||||||
RrThemeFree(theme);
|
theme->menu_title_font = RrFontOpenDefault(inst);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
theme->menu_title_font_height = RrFontHeight(theme->menu_title_font);
|
theme->menu_title_font_height = RrFontHeight(theme->menu_title_font);
|
||||||
|
|
||||||
mtitlejust = RR_JUSTIFY_LEFT;
|
mtitlejust = RR_JUSTIFY_LEFT;
|
||||||
|
@ -154,13 +149,11 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
|
||||||
mtitlejust = RR_JUSTIFY_CENTER;
|
mtitlejust = RR_JUSTIFY_CENTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!read_string(db, "menu.items.font", &font_str))
|
if (menu_item_font) {
|
||||||
font_str = "arial,sans:bold:pixelsize=11:shadow=y";
|
theme->menu_font = menu_item_font;
|
||||||
|
RrFontRef(menu_item_font);
|
||||||
if (!(theme->menu_font = RrFontOpen(inst, font_str))) {
|
} else
|
||||||
RrThemeFree(theme);
|
theme->menu_font = RrFontOpenDefault(inst);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
theme->menu_font_height = RrFontHeight(theme->menu_font);
|
theme->menu_font_height = RrFontHeight(theme->menu_font);
|
||||||
|
|
||||||
/* load direct dimensions */
|
/* load direct dimensions */
|
||||||
|
|
|
@ -187,7 +187,11 @@ struct _RrTheme {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
RrTheme* RrThemeNew(const RrInstance *inst, gchar *theme);
|
/*! The font values are all optional. If a NULL is used for any of them, then
|
||||||
|
the default font will be used. */
|
||||||
|
RrTheme* RrThemeNew(const RrInstance *inst, gchar *theme,
|
||||||
|
RrFont *active_window_font, RrFont *inactive_window_font,
|
||||||
|
RrFont *menu_title_font, RrFont *menu_item_font);
|
||||||
void RrThemeFree(RrTheme *theme);
|
void RrThemeFree(RrTheme *theme);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
Loading…
Reference in a new issue