[metacity] libmetacity: apply scale in meta_theme_create_font_desc



commit 977eea5508c3d976b0c3d591585978b092a54b53
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Jun 6 01:24:56 2016 +0300

    libmetacity: apply scale in meta_theme_create_font_desc

 libmetacity/meta-frame-style.c     |   10 ----------
 libmetacity/meta-frame-style.h     |    3 ---
 libmetacity/meta-theme.c           |   28 ++++++++++++++++++++++++++--
 libmetacity/meta-theme.h           |    4 +++-
 src/ui/frames.c                    |    4 ++--
 src/ui/ui.c                        |    2 +-
 theme-viewer/theme-viewer-window.c |   12 ++----------
 7 files changed, 34 insertions(+), 29 deletions(-)
---
diff --git a/libmetacity/meta-frame-style.c b/libmetacity/meta-frame-style.c
index 32ee34a..6be5780 100644
--- a/libmetacity/meta-frame-style.c
+++ b/libmetacity/meta-frame-style.c
@@ -298,16 +298,6 @@ meta_frame_style_unref (MetaFrameStyle *style)
     }
 }
 
-void
-meta_frame_style_apply_scale (const MetaFrameStyle *style,
-                              PangoFontDescription *font_desc)
-{
-  int size = pango_font_description_get_size (font_desc);
-  double scale = style->layout->title_scale / get_window_scaling_factor ();
-
-  pango_font_description_set_size (font_desc, MAX (size * scale, 1));
-}
-
 gboolean
 meta_frame_style_validate (MetaFrameStyle  *style,
                            guint            current_theme_version,
diff --git a/libmetacity/meta-frame-style.h b/libmetacity/meta-frame-style.h
index 511c25a..dc6426f 100644
--- a/libmetacity/meta-frame-style.h
+++ b/libmetacity/meta-frame-style.h
@@ -96,9 +96,6 @@ void               meta_frame_style_ref           (MetaFrameStyle        *style)
 
 void               meta_frame_style_unref         (MetaFrameStyle        *style);
 
-void               meta_frame_style_apply_scale   (const MetaFrameStyle  *style,
-                                                   PangoFontDescription  *font_desc);
-
 gboolean           meta_frame_style_validate      (MetaFrameStyle        *style,
                                                    guint                  current_theme_version,
                                                    GError               **error);
diff --git a/libmetacity/meta-theme.c b/libmetacity/meta-theme.c
index f19ac4c..4dc7891 100644
--- a/libmetacity/meta-theme.c
+++ b/libmetacity/meta-theme.c
@@ -56,6 +56,26 @@ static GParamSpec *properties[LAST_PROP] = { NULL };
 
 G_DEFINE_TYPE (MetaTheme, meta_theme, G_TYPE_OBJECT)
 
+static void
+font_desc_apply_scale (PangoFontDescription *font_desc,
+                       MetaTheme            *theme,
+                       MetaFrameType         type,
+                       MetaFrameFlags        flags)
+{
+  gint old_size;
+  MetaFrameStyle *style;
+  gdouble scale;
+  gint new_size;
+
+  old_size = pango_font_description_get_size (font_desc);
+  style = meta_theme_get_frame_style (theme, type, flags);
+  scale = get_window_scaling_factor ();
+
+  new_size = MAX (old_size * (style->layout->title_scale / scale), 1);
+
+  pango_font_description_set_size (font_desc, new_size);
+}
+
 static MetaStyleInfo *
 meta_theme_get_style_info (MetaTheme   *theme,
                            const gchar *variant)
@@ -358,8 +378,10 @@ meta_theme_get_frame_style (MetaTheme      *theme,
 }
 
 PangoFontDescription*
-meta_theme_create_font_desc (MetaTheme   *theme,
-                             const gchar *variant)
+meta_theme_create_font_desc (MetaTheme      *theme,
+                             const gchar    *variant,
+                             MetaFrameType   type,
+                             MetaFrameFlags  flags)
 {
   MetaStyleInfo *style_info;
   GtkStyleContext *context;
@@ -379,6 +401,8 @@ meta_theme_create_font_desc (MetaTheme   *theme,
   if (theme->titlebar_font)
     pango_font_description_merge (font_desc, theme->titlebar_font, TRUE);
 
+  font_desc_apply_scale (font_desc, theme, type, flags);
+
   return font_desc;
 }
 
diff --git a/libmetacity/meta-theme.h b/libmetacity/meta-theme.h
index 11e1011..64b6fc7 100644
--- a/libmetacity/meta-theme.h
+++ b/libmetacity/meta-theme.h
@@ -166,7 +166,9 @@ MetaFrameStyle       *meta_theme_get_frame_style           (MetaTheme
                                                             MetaFrameFlags               flags);
 
 PangoFontDescription *meta_theme_create_font_desc          (MetaTheme                   *theme,
-                                                            const gchar                 *variant);
+                                                            const gchar                 *variant,
+                                                            MetaFrameType                type,
+                                                            MetaFrameFlags               flags);
 
 gint                  meta_pango_font_desc_get_text_height (const PangoFontDescription  *font_desc,
                                                             PangoContext                *context);
diff --git a/src/ui/frames.c b/src/ui/frames.c
index b78a615..a5bbbcf 100644
--- a/src/ui/frames.c
+++ b/src/ui/frames.c
@@ -454,8 +454,8 @@ meta_frames_ensure_layout (MetaFrames  *frames,
 
       current = meta_ui_get_theme ();
 
-      font_desc = meta_theme_create_font_desc (current, frame->theme_variant);
-      meta_frame_style_apply_scale (style, font_desc);
+      font_desc = meta_theme_create_font_desc (current, frame->theme_variant,
+                                               type, flags);
 
       size = pango_font_description_get_size (font_desc);
 
diff --git a/src/ui/ui.c b/src/ui/ui.c
index 4670507..f917c1d 100644
--- a/src/ui/ui.c
+++ b/src/ui/ui.c
@@ -689,7 +689,7 @@ 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);
+  font_desc = meta_theme_create_font_desc (theme, theme_variant, type, flags);
   context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames));
 
   text_height = meta_pango_font_desc_get_text_height (font_desc, context);
diff --git a/theme-viewer/theme-viewer-window.c b/theme-viewer/theme-viewer-window.c
index 6d72f91..7dcd041 100644
--- a/theme-viewer/theme-viewer-window.c
+++ b/theme-viewer/theme-viewer-window.c
@@ -239,22 +239,14 @@ update_title_layout (ThemeViewerWindow *window)
   GtkWidget *widget;
   PangoLayout *layout;
   PangoFontDescription *font_desc;
-  MetaFrameType type;
-  MetaFrameFlags flags;
-  MetaFrameStyle *style;
   PangoContext *context;
   gint height;
 
   widget = GTK_WIDGET (window);
 
   layout = gtk_widget_create_pango_layout (widget, "Metacity Theme Viewer");
-  font_desc = meta_theme_create_font_desc (window->theme, window->theme_variant);
-
-  type = window->frame_type;
-  flags = window->frame_flags;
-
-  style = meta_theme_get_frame_style (window->theme, type, flags);
-  meta_frame_style_apply_scale (style, font_desc);
+  font_desc = meta_theme_create_font_desc (window->theme, window->theme_variant,
+                                           window->frame_type, window->frame_flags);
 
   context = gtk_widget_get_pango_context (widget);
   height = meta_pango_font_desc_get_text_height (font_desc, context);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]