Merge lp:~3v1n0/unity/font-scaling-fixes into lp:unity

Proposed by Marco Trevisan (Treviño) on 2014-08-28
Status: Merged
Approved by: Andrea Azzarone on 2014-08-29
Approved revision: 3868
Merged at revision: 3866
Proposed branch: lp:~3v1n0/unity/font-scaling-fixes
Merge into: lp:unity
Diff against target: 429 lines (+77/-63)
9 files modified
dash/FilterBasicButton.cpp (+6/-3)
dash/previews/ActionButton.cpp (+5/-2)
launcher/Launcher.cpp (+0/-2)
launcher/Tooltip.cpp (+5/-4)
unity-shared/DashStyle.cpp (+8/-11)
unity-shared/IconRenderer.cpp (+38/-34)
unity-shared/IconRenderer.h (+0/-2)
unity-shared/SearchBar.cpp (+6/-4)
unity-shared/UnitySettings.cpp (+9/-1)
To merge this branch: bzr merge lp:~3v1n0/unity/font-scaling-fixes
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) 2014-08-28 Approve on 2014-08-29
PS Jenkins bot (community) continuous-integration Approve on 2014-08-28
Review via email: mp+232541@code.launchpad.net

Commit message

SearchBar, ActionButtons, IconRenderer: include the font scaling when scaling textual items

User font scaling settings should be applied to all the items containing text.
Fixed some elements missing support.

To post a comment you must log in.
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Andrea Azzarone (azzar1) wrote :

LGTM.

review: Approve
lp:~3v1n0/unity/font-scaling-fixes updated on 2014-09-04
3869. By Marco Trevisan (Treviño) on 2014-09-04

UnitySettings: add some delay to wait gsettings changes

Without this delay, in some cases, unity might be notified of changes that have not been really done, but
triggered by some internal component. This race was causing problems to the users using a floating
scaling setting.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dash/FilterBasicButton.cpp'
2--- dash/FilterBasicButton.cpp 2014-07-09 13:46:37 +0000
3+++ dash/FilterBasicButton.cpp 2014-09-04 16:48:18 +0000
4@@ -20,6 +20,7 @@
5 */
6
7 #include "unity-shared/DashStyle.h"
8+#include "unity-shared/UnitySettings.h"
9 #include "FilterBasicButton.h"
10
11 namespace unity
12@@ -70,6 +71,7 @@
13 });
14
15 scale.changed.connect(sigc::mem_fun(this, &FilterBasicButton::UpdateScale));
16+ Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &FilterBasicButton::InitTheme)));
17 }
18
19 void FilterBasicButton::InitTheme()
20@@ -81,11 +83,12 @@
21 normal_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &FilterBasicButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL)));
22 focus_.reset(new nux::CairoWrapper(geo, sigc::mem_fun(this, &FilterBasicButton::RedrawFocusOverlay)));
23
24- SetMinimumWidth(MIN_BUTTON_WIDTH.CP(scale));
25+ double font_scaling = Settings::Instance().font_scaling() * scale;
26+ SetMinimumWidth(MIN_BUTTON_WIDTH.CP(font_scaling));
27 ApplyMinWidth();
28
29- SetMinimumHeight(BUTTON_HEIGHT.CP(scale));
30- SetMaximumHeight(BUTTON_HEIGHT.CP(scale));
31+ SetMinimumHeight(BUTTON_HEIGHT.CP(font_scaling));
32+ SetMaximumHeight(BUTTON_HEIGHT.CP(font_scaling));
33 }
34
35 void FilterBasicButton::RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state)
36
37=== modified file 'dash/previews/ActionButton.cpp'
38--- dash/previews/ActionButton.cpp 2014-07-30 00:49:35 +0000
39+++ dash/previews/ActionButton.cpp 2014-09-04 16:48:18 +0000
40@@ -24,6 +24,7 @@
41 #include <Nux/HLayout.h>
42 #include "unity-shared/IconTexture.h"
43 #include "unity-shared/StaticCairoText.h"
44+#include "unity-shared/UnitySettings.h"
45
46 namespace unity
47 {
48@@ -49,6 +50,7 @@
49 Init();
50 BuildLayout(label, icon_hint, "");
51 scale.changed.connect(sigc::mem_fun(this, &ActionButton::UpdateScale));
52+ Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &ActionButton::InitTheme)));
53 }
54
55 ActionButton::~ActionButton()
56@@ -91,8 +93,9 @@
57 cr_normal_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &ActionButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL)));
58 cr_focus_.reset(new nux::CairoWrapper(geo, sigc::mem_fun(this, &ActionButton::RedrawFocusOverlay)));
59
60- SetMinimumHeight(MIN_BUTTON_HEIGHT.CP(scale));
61- SetMinimumWidth(MIN_BUTTON_WIDTH.CP(scale));
62+ double font_scaling = Settings::Instance().font_scaling() * scale;
63+ SetMinimumHeight(MIN_BUTTON_HEIGHT.CP(font_scaling));
64+ SetMinimumWidth(MIN_BUTTON_WIDTH.CP(font_scaling));
65 }
66
67 void ActionButton::SetExtraHint(std::string const& extra_hint, std::string const& font_hint)
68
69=== modified file 'launcher/Launcher.cpp'
70--- launcher/Launcher.cpp 2014-07-17 18:33:37 +0000
71+++ launcher/Launcher.cpp 2014-09-04 16:48:18 +0000
72@@ -1516,8 +1516,6 @@
73
74 void Launcher::SetIconSize(int tile_size, int icon_size)
75 {
76- ui::IconRenderer::DestroyShortcutTextures();
77-
78 icon_size_ = tile_size;
79 icon_renderer_->scale = cv_->DPIScale();
80 icon_renderer_->SetTargetSize(icon_size_.CP(cv_), RawPixel(icon_size).CP(cv_), SPACE_BETWEEN_ICONS.CP(cv_));
81
82=== modified file 'launcher/Tooltip.cpp'
83--- launcher/Tooltip.cpp 2014-03-24 23:44:58 +0000
84+++ launcher/Tooltip.cpp 2014-09-04 16:48:18 +0000
85@@ -144,11 +144,12 @@
86 _tooltip_text->SetMinimumWidth(text_min_width);
87 _tooltip_text->SetMinimumHeight(text_height);
88
89+ int space_height = _padding.CP(cv_) + CORNER_RADIUS.CP(cv_);
90 if (text_height < ANCHOR_HEIGHT.CP(cv_))
91- {
92- _top_space->SetMinMaxSize(1, (ANCHOR_HEIGHT.CP(cv_) - text_height) / 2 + _padding.CP(cv_) + CORNER_RADIUS.CP(cv_));
93- _bottom_space->SetMinMaxSize(1, (ANCHOR_HEIGHT.CP(cv_) - text_height) / 2 + 1 + _padding.CP(cv_) + CORNER_RADIUS.CP(cv_));
94- }
95+ space_height += (ANCHOR_HEIGHT.CP(cv_) - text_height) / 2;
96+
97+ _top_space->SetMinMaxSize(1, space_height);
98+ _bottom_space->SetMinMaxSize(1, space_height + 1);
99
100 CairoBaseWindow::PreLayoutManagement();
101 }
102
103=== modified file 'unity-shared/DashStyle.cpp'
104--- unity-shared/DashStyle.cpp 2014-07-10 19:30:17 +0000
105+++ unity-shared/DashStyle.cpp 2014-09-04 16:48:18 +0000
106@@ -383,9 +383,9 @@
107 ::pango_layout_context_changed(layout);
108
109 PangoRectangle log_rect;
110- ::pango_layout_get_extents(layout, NULL, &log_rect);
111- text_width_ = log_rect.width / PANGO_SCALE;
112- text_height_ = log_rect.height / PANGO_SCALE;
113+ ::pango_layout_get_pixel_extents(layout, NULL, &log_rect);
114+ text_width_ = log_rect.width;
115+ text_height_ = log_rect.height;
116
117 owner_->changed.emit();
118
119@@ -1396,10 +1396,10 @@
120
121 pango_cairo_context_set_resolution(pangoCtx, 96.0 * Settings::Instance().font_scaling());
122 pango_layout_context_changed(layout);
123- pango_layout_get_extents(layout, &inkRect, NULL);
124+ pango_layout_get_pixel_extents(layout, &inkRect, NULL);
125
126- width = inkRect.width / PANGO_SCALE;
127- height = inkRect.height / PANGO_SCALE;
128+ width = inkRect.width;
129+ height = inkRect.height;
130
131 // clean up
132 pango_font_description_free(desc);
133@@ -1444,11 +1444,8 @@
134
135 if (text_size > 0)
136 {
137- pango_font_description_set_absolute_size(desc, text_size * PANGO_SCALE);
138- }
139- else if (desc)
140- {
141- text_size = pango_font_description_get_size(desc) / PANGO_SCALE;
142+ text_size = pango_units_from_double(Settings::Instance().font_scaling() * text_size);
143+ pango_font_description_set_absolute_size(desc, text_size);
144 }
145
146 PangoWeight weight;
147
148=== modified file 'unity-shared/IconRenderer.cpp'
149--- unity-shared/IconRenderer.cpp 2014-05-08 18:52:16 +0000
150+++ unity-shared/IconRenderer.cpp 2014-09-04 16:48:18 +0000
151@@ -31,6 +31,8 @@
152 #include "unity-shared/CairoTexture.h"
153 #include "unity-shared/DecorationStyle.h"
154 #include "unity-shared/TextureCache.h"
155+#include "unity-shared/UnitySettings.h"
156+#include "unity-shared/WindowManager.h"
157 #include "GraphicsUtils.h"
158
159 #include <gtk/gtk.h>
160@@ -210,7 +212,6 @@
161 return instance;
162 }
163
164- nux::ObjectPtr<nux::BaseTexture> RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color);
165 nux::ObjectPtr<nux::IOpenGLBaseTexture> offscreen_progress_texture;
166 nux::ObjectPtr<nux::IOpenGLShaderProgram> shader_program_uv_persp_correction;
167 #ifndef USE_GLES
168@@ -224,8 +225,6 @@
169 int ColorifyColor;
170 int DesatFactor;
171
172- std::map<char, BaseTexturePtr> labels;
173-
174 private:
175 TexturesPool();
176
177@@ -249,14 +248,18 @@
178 LocalTextures(IconRenderer* parent)
179 : parent_(parent)
180 {
181- theme_conn_ = decoration::Style::Get()->theme.changed.connect([this] (std::string const&) {
182+ connections_.Add(decoration::Style::Get()->theme.changed.connect([this] (std::string const&) {
183 auto& cache = TextureCache::GetDefault();
184
185 for (auto const& tex_data : texture_files_)
186 cache.Invalidate(tex_data.name, tex_data.size, tex_data.size);
187
188 ReloadIconSizedTextures(parent_->icon_size, parent_->image_size);
189- });
190+ }));
191+
192+ auto clear_labels = sigc::hide(sigc::mem_fun(this, &LocalTextures::ClearLabels));
193+ connections_.Add(Settings::Instance().font_scaling.changed.connect(clear_labels));
194+ connections_.Add(WindowManager::Default().average_color.changed.connect(clear_labels));
195 }
196
197 void ReloadIconSizedTextures(int icon_size, int image_size)
198@@ -298,6 +301,22 @@
199 *tex_data.tex_ptr = cache.FindTexture(tex_data.name, tex_data.size, tex_data.size, texture_loader);
200 }
201
202+ nux::BaseTexture* RenderLabelTexture(char label, int icon_size, nux::Color const&);
203+
204+ BaseTexturePtr const& GetLabelTexture(char label, int icon_size, nux::Color const& color)
205+ {
206+ labels_.push_back(TextureCache::GetDefault().FindTexture(std::string(1, label), icon_size, icon_size, [this, &color] (std::string const& label, int size, int) {
207+ return RenderLabelTexture(label[0], size, color);
208+ }));
209+
210+ return labels_.back();
211+ }
212+
213+ void ClearLabels()
214+ {
215+ labels_.clear();
216+ }
217+
218 BaseTexturePtr icon_background;
219 BaseTexturePtr icon_selected_background;
220 BaseTexturePtr icon_edge;
221@@ -315,7 +334,8 @@
222 IconRenderer* parent_;
223 struct TextureData { BaseTexturePtr* tex_ptr; std::string name; int size; };
224 std::vector<TextureData> texture_files_;
225- connection::Wrapper theme_conn_;
226+ std::vector<BaseTexturePtr> labels_;
227+ connection::Manager connections_;
228 };
229
230 IconRenderer::IconRenderer()
231@@ -335,6 +355,7 @@
232 icon_size = tile_size;
233 image_size = image_size_;
234 local_textures_->ReloadIconSizedTextures(icon_size, image_size);
235+ local_textures_->ClearLabels();
236 }
237
238 spacing = spacing_;
239@@ -741,20 +762,8 @@
240 // draw superkey-shortcut label
241 if (arg.draw_shortcut && arg.shortcut_label)
242 {
243- char shortcut = (char) arg.shortcut_label;
244-
245- BaseTexturePtr label;
246- auto label_it = textures_->labels.find(shortcut);
247-
248- if (label_it != textures_->labels.end())
249- {
250- label = label_it->second;
251- }
252- else
253- {
254- label = textures_->RenderLabelTexture(shortcut, icon_size, shortcut_color);
255- textures_->labels[shortcut] = label;
256- }
257+ char shortcut = static_cast<char>(arg.shortcut_label);
258+ auto const& label = local_textures_->GetLabelTexture(shortcut, icon_size, shortcut_color);
259
260 RenderElement(GfxContext,
261 arg,
262@@ -767,7 +776,7 @@
263 }
264 }
265
266-nux::ObjectPtr<nux::BaseTexture> IconRenderer::TexturesPool::RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color)
267+nux::BaseTexture* IconRenderer::LocalTextures::RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color)
268 {
269 nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, icon_size, icon_size);
270 cairo_t* cr = cg.GetInternalContext();
271@@ -791,27 +800,27 @@
272 cairo_set_source_rgba(cr, bg_color.red, bg_color.green, bg_color.blue, 0.20f);
273 cairo_fill(cr);
274
275- const double text_ratio = 0.75;
276- double text_size = label_size * text_ratio;
277 glib::Object<PangoLayout> layout(pango_cairo_create_layout(cr));
278 g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, NULL);
279 std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name),
280 pango_font_description_free);
281- pango_font_description_set_absolute_size(desc.get(), text_size * PANGO_SCALE);
282+ const double text_ratio = 0.75;
283+ int text_size = pango_units_from_double(label_size * text_ratio * Settings::Instance().font_scaling());
284+ pango_font_description_set_absolute_size(desc.get(), text_size);
285 pango_layout_set_font_description(layout, desc.get());
286 pango_layout_set_text(layout, &label, 1);
287
288- nux::Size extents;
289- pango_layout_get_pixel_size(layout, &extents.width, &extents.height);
290+ PangoRectangle ink_rect;
291+ pango_layout_get_pixel_extents(layout, &ink_rect, nullptr);
292
293 // position and paint text
294 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
295- double x = label_x - std::round((extents.width - label_w) / 2.0f);
296- double y = label_y - std::round((extents.height - label_h) / 2.0f);
297+ double x = label_x - std::round((ink_rect.width - label_w) / 2.0f) - ink_rect.x;
298+ double y = label_y - std::round((ink_rect.height - label_h) / 2.0f) - ink_rect.y;
299 cairo_move_to(cr, x, y);
300 pango_cairo_show_layout(cr, layout);
301
302- return texture_ptr_from_cairo_graphics(cg);
303+ return texture_from_cairo_graphics(cg);
304 }
305
306 void IconRenderer::RenderElement(nux::GraphicsEngine& GfxContext,
307@@ -1153,11 +1162,6 @@
308 unity::graphics::PopOffscreenRenderTarget();
309 }
310
311-void IconRenderer::DestroyShortcutTextures()
312-{
313- TexturesPool::Get()->labels.clear();
314-}
315-
316 void IconRenderer::GetInverseScreenPerspectiveMatrix(nux::Matrix4& ViewMatrix, nux::Matrix4& PerspectiveMatrix,
317 int ViewportWidth,
318 int ViewportHeight,
319
320=== modified file 'unity-shared/IconRenderer.h'
321--- unity-shared/IconRenderer.h 2014-02-27 02:37:18 +0000
322+++ unity-shared/IconRenderer.h 2014-09-04 16:48:18 +0000
323@@ -44,8 +44,6 @@
324
325 void SetTargetSize(int tile_size, int image_size, int spacing);
326
327- static void DestroyShortcutTextures();
328-
329 protected:
330 void RenderElement(nux::GraphicsEngine& GfxContext,
331 RenderArg const& arg,
332
333=== modified file 'unity-shared/SearchBar.cpp'
334--- unity-shared/SearchBar.cpp 2014-07-09 10:52:06 +0000
335+++ unity-shared/SearchBar.cpp 2014-09-04 16:48:18 +0000
336@@ -65,7 +65,7 @@
337 const RawPixel FILTER_HORIZONTAL_MARGIN = 8_em;
338
339 // Fonts
340-const std::string HINT_LABEL_FONT_SIZE = "20px";
341+const std::string HINT_LABEL_FONT_SIZE = "15"; // == 20px
342 const std::string HINT_LABEL_FONT_STYLE = "Italic";
343 const std::string HINT_LABEL_DEFAULT_FONT = "Ubuntu " + HINT_LABEL_FONT_STYLE + " " + HINT_LABEL_FONT_SIZE;
344
345@@ -263,6 +263,7 @@
346 im_preedit.SetGetterFunction(sigc::mem_fun(this, &SearchBar::get_im_preedit));
347 showing_filters.changed.connect(sigc::mem_fun(this, &SearchBar::OnShowingFiltersChanged));
348 scale.changed.connect(sigc::mem_fun(this, &SearchBar::UpdateScale));
349+ Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &SearchBar::UpdateSearchBarSize)));
350 can_refine_search.changed.connect([this] (bool can_refine)
351 {
352 if (show_filter_hint_)
353@@ -289,7 +290,8 @@
354
355 entry_layout_->SetSpaceBetweenChildren(SPACE_BETWEEN_SPINNER_AND_TEXT.CP(scale()));
356
357- pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE.CP(scale()));
358+ double font_scaling = scale() * Settings::Instance().font_scaling();
359+ pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE.CP(font_scaling));
360
361 if (show_filter_hint_)
362 {
363@@ -329,7 +331,7 @@
364 layered_layout_->SetMinimumHeight(entry_min);
365 layered_layout_->SetMaximumHeight(entry_min);
366
367- int search_bar_height = style.GetSearchBarHeight().CP(scale);
368+ int search_bar_height = style.GetSearchBarHeight().CP(font_scaling);
369 SetMinimumHeight(search_bar_height);
370 SetMaximumHeight(search_bar_height);
371 }
372@@ -359,7 +361,7 @@
373 if (desc)
374 {
375 pango_entry_->SetFontFamily(pango_font_description_get_family(desc));
376- pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE);
377+ pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE.CP(scale * Settings::Instance().font_scaling()));
378 pango_entry_->SetFontOptions(gdk_screen_get_font_options(gdk_screen_get_default()));
379
380 font_desc << pango_font_description_get_family(desc) << " " << HINT_LABEL_FONT_STYLE << " " << HINT_LABEL_FONT_SIZE;
381
382=== modified file 'unity-shared/UnitySettings.cpp'
383--- unity-shared/UnitySettings.cpp 2014-07-09 09:27:10 +0000
384+++ unity-shared/UnitySettings.cpp 2014-09-04 16:48:18 +0000
385@@ -20,6 +20,7 @@
386
387 #include <glib.h>
388 #include <NuxCore/Logger.h>
389+#include <UnityCore/GLibSource.h>
390 #include <UnityCore/Variant.h>
391
392 #include "DecorationStyle.h"
393@@ -60,6 +61,7 @@
394
395 const int DEFAULT_LAUNCHER_WIDTH = 64;
396 const int MINIMUM_DESKTOP_HEIGHT = 800;
397+const int GNOME_SETTINGS_CHANGED_WAIT_SECONDS = 1;
398 const double DEFAULT_DPI = 96.0f;
399 }
400
401@@ -302,6 +304,7 @@
402 void UpdateAppsScaling(double scale)
403 {
404 changing_gnome_settings_ = true;
405+ changing_gnome_settings_timeout_.reset();
406 unsigned integer_scaling = std::max<unsigned>(1, scale);
407 double point_scaling = scale / static_cast<double>(integer_scaling);
408 double text_scale_factor = parent_->font_scaling() * point_scaling;
409@@ -310,7 +313,11 @@
410 g_settings_set_int(gnome_ui_settings_, GNOME_CURSOR_SIZE.c_str(), cursor_size);
411 g_settings_set_uint(gnome_ui_settings_, GNOME_SCALE_FACTOR.c_str(), integer_scaling);
412 g_settings_set_double(gnome_ui_settings_, GNOME_TEXT_SCALE_FACTOR.c_str(), text_scale_factor);
413- changing_gnome_settings_ = false;
414+
415+ changing_gnome_settings_timeout_.reset(new glib::TimeoutSeconds(GNOME_SETTINGS_CHANGED_WAIT_SECONDS, [this] {
416+ changing_gnome_settings_ = false;
417+ return false;
418+ }, glib::Source::Priority::LOW));
419 }
420
421 Settings* parent_;
422@@ -319,6 +326,7 @@
423 glib::Object<GSettings> ui_settings_;
424 glib::Object<GSettings> ubuntu_ui_settings_;
425 glib::Object<GSettings> gnome_ui_settings_;
426+ glib::Source::UniquePtr changing_gnome_settings_timeout_;
427 glib::SignalManager signals_;
428 std::vector<EMConverter::Ptr> em_converters_;
429 std::vector<int> launcher_widths_;