diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-03-20 06:05:21 +0100 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-03-20 06:05:21 +0100 |
| commit | 28b0c58f3bbeb41a5e0114d76186d0f3bc18ee1e (patch) | |
| tree | a7f2dee45f26e1d3085f7bfba35bf32ba390336e /unity-shared | |
| parent | 6a7760959081af577ad2b654339fadbf69c119be (diff) | |
Unity: Don't use "gtk-xft-dpi" setting for text-scaling, but our own value
(bzr r3725.7.6)
Diffstat (limited to 'unity-shared')
| -rwxr-xr-x | unity-shared/DashStyle.cpp | 46 | ||||
| -rw-r--r-- | unity-shared/DecorationStyle.cpp | 8 | ||||
| -rw-r--r-- | unity-shared/DecorationStyle.h | 1 | ||||
| -rw-r--r-- | unity-shared/IconLoader.cpp | 9 | ||||
| -rw-r--r-- | unity-shared/StaticCairoText.cpp | 43 |
5 files changed, 25 insertions, 82 deletions
diff --git a/unity-shared/DashStyle.cpp b/unity-shared/DashStyle.cpp index 3d36e46d5..680092dbf 100755 --- a/unity-shared/DashStyle.cpp +++ b/unity-shared/DashStyle.cpp @@ -108,9 +108,8 @@ private: } // anon namespace -class Style::Impl +struct Style::Impl : sigc::trackable { -public: Impl(Style* owner); ~Impl(); @@ -293,10 +292,8 @@ Style::Impl::Impl(Style* owner) (gtk_settings_get_default(), "notify::gtk-font-name", sigc::mem_fun(this, &Impl::OnFontChanged))); - signal_manager_.Add(new glib::Signal<void, GtkSettings*, GParamSpec*> - (gtk_settings_get_default(), - "notify::gtk-xft-dpi", - sigc::mem_fun(this, &Impl::OnFontChanged))); + + Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &Impl::Refresh))); Refresh(); // create fallback font-options @@ -388,11 +385,7 @@ void Style::Impl::Refresh() cairo_t* cr = util_cg.GetInternalContext(); glib::String font_description; - int dpi = 0; - ::g_object_get(settings, - "gtk-font-name", &font_description, - "gtk-xft-dpi", &dpi, - NULL); + ::g_object_get(settings, "gtk-font-name", &font_description, nullptr); PangoFontDescription* desc = ::pango_font_description_from_string(font_description); ::pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL); ::pango_font_description_set_size(desc, 9 * PANGO_SCALE); @@ -405,8 +398,7 @@ void Style::Impl::Refresh() GdkScreen* screen = ::gdk_screen_get_default(); ::pango_cairo_context_set_font_options(cxt, ::gdk_screen_get_font_options(screen)); - float pango_scale = PANGO_SCALE; - ::pango_cairo_context_set_resolution(cxt, dpi / pango_scale); + ::pango_cairo_context_set_resolution(cxt, 96.0 * Settings::Instance().font_scaling()); ::pango_layout_context_changed(layout); PangoRectangle log_rect; @@ -1384,7 +1376,6 @@ void Style::Impl::GetTextExtents(int& width, PangoFontDescription* desc = NULL; PangoContext* pangoCtx = NULL; PangoRectangle inkRect = {0, 0, 0, 0}; - int dpi = 0; char* fontName = NULL; GdkScreen* screen = gdk_screen_get_default(); // is not ref'ed GtkSettings* settings = gtk_settings_get_default();// is not ref'ed @@ -1423,17 +1414,7 @@ void Style::Impl::GetTextExtents(int& width, pango_cairo_context_set_font_options(pangoCtx, gdk_screen_get_font_options(screen)); - g_object_get(settings, "gtk-xft-dpi", &dpi, NULL); - if (dpi == -1) - { - // use some default DPI-value - pango_cairo_context_set_resolution(pangoCtx, 96.0f); - } - else - { - pango_cairo_context_set_resolution(pangoCtx, - (float) dpi / (float) PANGO_SCALE); - } + pango_cairo_context_set_resolution(pangoCtx, 96.0 * Settings::Instance().font_scaling()); pango_layout_context_changed(layout); pango_layout_get_extents(layout, &inkRect, NULL); @@ -1461,7 +1442,6 @@ void Style::Impl::Text(cairo_t* cr, PangoLayout* layout = NULL; PangoFontDescription* desc = NULL; PangoContext* pangoCtx = NULL; - int dpi = 0; GdkScreen* screen = gdk_screen_get_default(); // not ref'ed GtkSettings* settings = gtk_settings_get_default(); // not ref'ed gchar* fontName = NULL; @@ -1480,7 +1460,7 @@ void Style::Impl::Text(cairo_t* cr, g_object_get(settings, "gtk-font-name", &fontName, NULL); if (!fontName) - desc = pango_font_description_from_string("Sans 10"); + desc = pango_font_description_from_string("Ubuntu 10"); else desc = pango_font_description_from_string(fontName); @@ -1543,17 +1523,7 @@ void Style::Impl::Text(cairo_t* cr, pango_cairo_context_set_font_options(pangoCtx, gdk_screen_get_font_options(screen)); - g_object_get(settings, "gtk-xft-dpi", &dpi, NULL); - if (dpi == -1) - { - // use some default DPI-value - pango_cairo_context_set_resolution(pangoCtx, 96.0f); - } - else - { - pango_cairo_context_set_resolution(pangoCtx, - (float) dpi / (float) PANGO_SCALE); - } + pango_cairo_context_set_resolution(pangoCtx, 96.0 * Settings::Instance().font_scaling()); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgba(cr, color); diff --git a/unity-shared/DecorationStyle.cpp b/unity-shared/DecorationStyle.cpp index a0f1cc84c..6904796eb 100644 --- a/unity-shared/DecorationStyle.cpp +++ b/unity-shared/DecorationStyle.cpp @@ -157,6 +157,7 @@ struct Style::Impl parent_->integrated_menus = false; parent_->theme = glib::String(GetSettingValue<gchar*>("gtk-theme-name")).Str(); parent_->font = glib::String(GetSettingValue<gchar*>("gtk-font-name")).Str(); + parent_->font_scale = 1.0; SetTitleFont(); UpdateTitlePangoContext(parent_->title_font); @@ -185,14 +186,12 @@ struct Style::Impl LOG_INFO(logger) << "gtk-font-name changed to " << parent_->font(); }); - signals_.Add<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-xft-dpi", [this] (GtkSettings*, GParamSpec*) { - title_pango_ctx_ = gdk_pango_context_get_for_screen(gdk_screen_get_default()); - menu_item_pango_ctx_ = gdk_pango_context_get_for_screen(gdk_screen_get_default()); + parent_->font_scale.changed.connect([this] (bool scale) { UpdateTitlePangoContext(parent_->title_font); UpdateMenuItemPangoContext(parent_->font); gtk_style_context_invalidate(ctx_); parent_->theme.changed.emit(parent_->theme()); - LOG_INFO(logger) << "gtk-xft-dpi changed to " << GetSettingValue<int>("gtk-xft-dpi"); + LOG_INFO(logger) << "font scale changed to " << scale; }); signals_.Add<void, GSettings*, gchar*>(settings_, "changed::" + FONT_KEY, [this] (GSettings*, gchar*) { @@ -255,6 +254,7 @@ struct Style::Impl std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font.c_str()), pango_font_description_free); pango_context_set_font_description(ctx, desc.get()); pango_context_set_language(ctx, gtk_get_default_language()); + pango_cairo_context_set_resolution(ctx, 96.0 * parent_->font_scale()); } void UpdateTitlePangoContext(std::string const& font) diff --git a/unity-shared/DecorationStyle.h b/unity-shared/DecorationStyle.h index ef950ffdb..00c8b13f1 100644 --- a/unity-shared/DecorationStyle.h +++ b/unity-shared/DecorationStyle.h @@ -99,6 +99,7 @@ public: nux::Property<std::string> title_font; nux::Property<bool> integrated_menus; nux::Property<unsigned> grab_wait; + nux::Property<double> font_scale; decoration::Border const& Border() const; decoration::Border const& InputBorder() const; diff --git a/unity-shared/IconLoader.cpp b/unity-shared/IconLoader.cpp index bfa03fae7..8f840dc76 100644 --- a/unity-shared/IconLoader.cpp +++ b/unity-shared/IconLoader.cpp @@ -35,6 +35,7 @@ #include <UnityCore/GTKWrapper.h> #include "unity-shared/Timer.h" +#include "unity-shared/UnitySettings.h" namespace unity { @@ -313,10 +314,8 @@ private: PangoContext* pango_context = NULL; GdkScreen* screen = gdk_screen_get_default(); // not ref'ed glib::String font; - int dpi = -1; g_object_get(gtk_settings_get_default(), "gtk-font-name", &font, NULL); - g_object_get(gtk_settings_get_default(), "gtk-xft-dpi", &dpi, NULL); cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); layout = pango_cairo_create_layout(cr); std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font), pango_font_description_free); @@ -345,10 +344,8 @@ private: pango_layout_set_markup(layout, escaped_text, -1); pango_context = pango_layout_get_context(layout); // is not ref'ed - pango_cairo_context_set_font_options(pango_context, - gdk_screen_get_font_options(screen)); - pango_cairo_context_set_resolution(pango_context, - dpi == -1 ? 96.0f : dpi/(float) PANGO_SCALE); + pango_cairo_context_set_font_options(pango_context, gdk_screen_get_font_options(screen)); + pango_cairo_context_set_resolution(pango_context, 96.0 * Settings::Instance().font_scaling()); pango_layout_context_changed(layout); // find proper font size diff --git a/unity-shared/StaticCairoText.cpp b/unity-shared/StaticCairoText.cpp index b3f2010a2..804ad1006 100644 --- a/unity-shared/StaticCairoText.cpp +++ b/unity-shared/StaticCairoText.cpp @@ -36,12 +36,13 @@ #include <UnityCore/GLibWrapper.h> #include "CairoTexture.h" +#include "UnitySettings.h" using namespace nux; namespace unity { -struct StaticCairoText::Impl +struct StaticCairoText::Impl : sigc::trackable { Impl(StaticCairoText* parent, std::string const& text); ~Impl(); @@ -128,8 +129,8 @@ StaticCairoText::Impl::Impl(StaticCairoText* parent, std::string const& text) GtkSettings* settings = gtk_settings_get_default(); // not ref'ed g_signal_connect(settings, "notify::gtk-font-name", (GCallback)FontChanged, this); - g_signal_connect(settings, "notify::gtk-xft-dpi", - (GCallback)FontChanged, this); + + Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &Impl::OnFontChanged))); } StaticCairoText::Impl::~Impl() @@ -552,9 +553,7 @@ Size StaticCairoText::Impl::GetTextExtents() const PangoLayout* layout = NULL; PangoFontDescription* desc = NULL; PangoContext* pangoCtx = NULL; - int dpi = 0; GdkScreen* screen = gdk_screen_get_default(); // is not ref'ed - GtkSettings* settings = gtk_settings_get_default(); // is not ref'ed if (!need_new_extent_cache_) { @@ -581,19 +580,8 @@ Size StaticCairoText::Impl::GetTextExtents() const pango_layout_set_spacing(layout, line_spacing_ * PANGO_SCALE); pangoCtx = pango_layout_get_context(layout); // is not ref'ed - pango_cairo_context_set_font_options(pangoCtx, - gdk_screen_get_font_options(screen)); - g_object_get(settings, "gtk-xft-dpi", &dpi, NULL); - if (dpi == -1) - { - // use some default DPI-value - pango_cairo_context_set_resolution(pangoCtx, 96.0f); - } - else - { - pango_cairo_context_set_resolution(pangoCtx, - (float) dpi / (float) PANGO_SCALE); - } + pango_cairo_context_set_font_options(pangoCtx, gdk_screen_get_font_options(screen)); + pango_cairo_context_set_resolution(pangoCtx, 96.0 * Settings::Instance().font_scaling()); pango_layout_context_changed(layout); PangoRectangle ink_rect, logic_rect; @@ -721,9 +709,7 @@ void StaticCairoText::Impl::DrawText(CacheTexture::Ptr const& texture) PangoLayout* layout = NULL; PangoFontDescription* desc = NULL; PangoContext* pangoCtx = NULL; - int dpi = 0; GdkScreen* screen = gdk_screen_get_default(); // not ref'ed - GtkSettings* settings = gtk_settings_get_default(); // not ref'ed std::string text = text_.substr(texture->start_index, texture->length); @@ -746,22 +732,11 @@ void StaticCairoText::Impl::DrawText(CacheTexture::Ptr const& texture) SetAttributes(layout); pangoCtx = pango_layout_get_context(layout); // is not ref'ed - pango_cairo_context_set_font_options(pangoCtx, - gdk_screen_get_font_options(screen)); - g_object_get(settings, "gtk-xft-dpi", &dpi, NULL); - if (dpi == -1) - { - // use some default DPI-value - pango_cairo_context_set_resolution(pangoCtx, 96.0f); - } - else - { - pango_cairo_context_set_resolution(pangoCtx, - (float) dpi / (float) PANGO_SCALE); - } + pango_cairo_context_set_font_options(pangoCtx, gdk_screen_get_font_options(screen)); + pango_cairo_context_set_resolution(pangoCtx, 96.0 * Settings::Instance().font_scaling()); + pango_layout_context_changed(layout); Size result; - pango_layout_context_changed(layout); pango_layout_get_pixel_size(layout, &result.width, &result.height); if (std::ceil(result.width * scale_) > parent_->GetMaximumWidth()) |
