[metacity] libmetacity: own created title font descriptions
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [metacity] libmetacity: own created title font descriptions
- Date: Tue, 7 Jun 2016 18:28:59 +0000 (UTC)
commit 4c6a8b38970581e7979bfc344122bbfdb9627fee
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Mon Jun 6 18:12:48 2016 +0300
libmetacity: own created title font descriptions
libmetacity/meta-theme.c | 41 +++++++++++++++++++++++++++++++----
libmetacity/meta-theme.h | 2 +-
src/ui/frames.c | 5 +--
src/ui/ui.c | 3 +-
theme-viewer/theme-viewer-window.c | 6 +---
5 files changed, 42 insertions(+), 15 deletions(-)
---
diff --git a/libmetacity/meta-theme.c b/libmetacity/meta-theme.c
index 056dc3f..3f66add 100644
--- a/libmetacity/meta-theme.c
+++ b/libmetacity/meta-theme.c
@@ -43,6 +43,8 @@ struct _MetaTheme
GHashTable *variants;
PangoContext *context;
+
+ GHashTable *font_descs;
};
enum
@@ -163,6 +165,8 @@ meta_theme_dispose (GObject *object)
g_clear_object (&theme->context);
+ g_clear_pointer (&theme->font_descs, g_hash_table_destroy);
+
G_OBJECT_CLASS (meta_theme_parent_class)->dispose (object);
}
@@ -240,6 +244,9 @@ meta_theme_init (MetaTheme *theme)
theme->variants = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_object_unref);
+
+ theme->font_descs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
+ (GDestroyNotify) pango_font_description_free);
}
/**
@@ -294,6 +301,7 @@ meta_theme_invalidate (MetaTheme *theme)
{
g_hash_table_remove_all (theme->variants);
g_clear_object (&theme->context);
+ g_hash_table_remove_all (theme->font_descs);
}
void
@@ -315,6 +323,8 @@ meta_theme_set_titlebar_font (MetaTheme *theme,
{
pango_font_description_free (theme->titlebar_font);
theme->titlebar_font = pango_font_description_copy (titlebar_font);
+
+ g_hash_table_remove_all (theme->font_descs);
}
MetaFrameStyle *
@@ -435,15 +445,34 @@ meta_theme_create_title_layout (MetaTheme *theme,
return layout;
}
+/**
+ * meta_theme_get_title_font_desc:
+ * @theme: a #MetaTheme
+ * @variant: (nullable): theme variant
+ * @type: frame type
+ * @flags: frame flags
+ *
+ * Returns: (transfer none): the #PangoFontDescription
+ */
PangoFontDescription*
-meta_theme_create_font_desc (MetaTheme *theme,
- const gchar *variant,
- MetaFrameType type,
- MetaFrameFlags flags)
+meta_theme_get_title_font_desc (MetaTheme *theme,
+ const gchar *variant,
+ MetaFrameType type,
+ MetaFrameFlags flags)
{
+ gchar *key;
+ PangoFontDescription *font_desc;
MetaStyleInfo *style_info;
GtkStyleContext *context;
- PangoFontDescription *font_desc;
+
+ key = g_strdup_printf ("%s_%d_%x", variant ? variant : "default", type, flags);
+ font_desc = g_hash_table_lookup (theme->font_descs, key);
+
+ if (font_desc != NULL)
+ {
+ g_free (key);
+ return font_desc;
+ }
style_info = meta_theme_get_style_info (theme, variant);
context = meta_style_info_get_style (style_info, META_STYLE_ELEMENT_TITLE);
@@ -461,6 +490,8 @@ meta_theme_create_font_desc (MetaTheme *theme,
font_desc_apply_scale (font_desc, theme, type, flags);
+ g_hash_table_insert (theme->font_descs, key, font_desc);
+
return font_desc;
}
diff --git a/libmetacity/meta-theme.h b/libmetacity/meta-theme.h
index d3217db..69f778b 100644
--- a/libmetacity/meta-theme.h
+++ b/libmetacity/meta-theme.h
@@ -168,7 +168,7 @@ MetaFrameStyle *meta_theme_get_frame_style (MetaTheme
PangoLayout *meta_theme_create_title_layout (MetaTheme *theme,
const gchar *title);
-PangoFontDescription *meta_theme_create_font_desc (MetaTheme *theme,
+PangoFontDescription *meta_theme_get_title_font_desc (MetaTheme *theme,
const gchar *variant,
MetaFrameType type,
MetaFrameFlags flags);
diff --git a/src/ui/frames.c b/src/ui/frames.c
index 1d99456..aaf03a5 100644
--- a/src/ui/frames.c
+++ b/src/ui/frames.c
@@ -443,8 +443,8 @@ meta_frames_ensure_layout (MetaFrames *frames,
int size;
frame->text_layout = meta_theme_create_title_layout (theme, frame->title);
- font_desc = meta_theme_create_font_desc (theme, frame->theme_variant,
- type, flags);
+ font_desc = meta_theme_get_title_font_desc (theme, frame->theme_variant,
+ type, flags);
size = pango_font_description_get_size (font_desc);
@@ -464,7 +464,6 @@ meta_frames_ensure_layout (MetaFrames *frames,
}
pango_layout_set_font_description (frame->text_layout, font_desc);
- pango_font_description_free (font_desc);
}
}
diff --git a/src/ui/ui.c b/src/ui/ui.c
index 2fa3012..3175269 100644
--- a/src/ui/ui.c
+++ b/src/ui/ui.c
@@ -688,9 +688,8 @@ meta_ui_theme_get_frame_borders (MetaUI *ui,
theme = meta_ui_get_theme ();
theme_variant = NULL;
- font_desc = meta_theme_create_font_desc (theme, theme_variant, type, flags);
+ font_desc = meta_theme_get_title_font_desc (theme, theme_variant, type, flags);
text_height = meta_theme_get_title_height (theme, font_desc);
- pango_font_description_free (font_desc);
meta_theme_get_frame_borders (theme, theme_variant, type,
text_height, flags, borders);
diff --git a/theme-viewer/theme-viewer-window.c b/theme-viewer/theme-viewer-window.c
index 11af971..ee39e5b 100644
--- a/theme-viewer/theme-viewer-window.c
+++ b/theme-viewer/theme-viewer-window.c
@@ -241,8 +241,8 @@ update_title_layout (ThemeViewerWindow *window)
gint height;
layout = meta_theme_create_title_layout (window->theme, "Metacity Theme Viewer");
- font_desc = meta_theme_create_font_desc (window->theme, window->theme_variant,
- window->frame_type, window->frame_flags);
+ font_desc = meta_theme_get_title_font_desc (window->theme, window->theme_variant,
+ window->frame_type, window->frame_flags);
height = meta_theme_get_title_height (window->theme, font_desc);
@@ -253,8 +253,6 @@ update_title_layout (ThemeViewerWindow *window)
window->title_layout = layout;
window->title_height = height;
-
- pango_font_description_free (font_desc);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]