Merge lp:~3v1n0/unity/fuzzy-deco-text-fix into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Brandon Schaefer
Approved revision: no longer in the source branch.
Merged at revision: 3750
Proposed branch: lp:~3v1n0/unity/fuzzy-deco-text-fix
Merge into: lp:unity
Diff against target: 232 lines (+73/-19)
7 files modified
decorations/DecorationsMenuEntry.cpp (+13/-1)
decorations/DecorationsTitle.cpp (+10/-1)
panel/PanelIndicatorEntryView.cpp (+16/-5)
panel/PanelMenuView.cpp (+3/-1)
unity-shared/DecorationStyle.cpp (+27/-6)
unity-shared/DecorationStyle.h (+3/-4)
unity-shared/UnitySettings.cpp (+1/-1)
To merge this branch: bzr merge lp:~3v1n0/unity/fuzzy-deco-text-fix
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Brandon Schaefer (community) Approve
Review via email: mp+213531@code.launchpad.net

Commit message

Panel, Decorations: draw the background under the text glyphs before the text itself

Description of the change

Draw the background under the styled panel and decorations text glyphs to make
sure that cairo will paint the text using in the correct way.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'decorations/DecorationsMenuEntry.cpp'
2--- decorations/DecorationsMenuEntry.cpp 2014-02-24 16:00:02 +0000
3+++ decorations/DecorationsMenuEntry.cpp 2014-03-31 18:58:05 +0000
4@@ -77,9 +77,21 @@
5 if (state == WidgetState::PRELIGHT)
6 Style::Get()->DrawMenuItem(state, text_ctx, text_ctx.width() / scale(), text_ctx.height() / scale());
7
8+ nux::Rect bg_geo(-(horizontal_padding()*scale()), -(vertical_padding()*scale()), GetNaturalWidth(), GetNaturalHeight());
9+
10+ if (state != WidgetState::PRELIGHT)
11+ {
12+ if (BasicContainer::Ptr const& top = GetTopParent())
13+ {
14+ auto const& top_geo = top->Geometry();
15+ auto const& geo = Geometry();
16+ bg_geo.Set(top_geo.x() - geo.x(), top_geo.y() - geo.y(), top_geo.width(), top_geo.height());
17+ }
18+ }
19+
20 cairo_save(text_ctx);
21 cairo_translate(text_ctx, horizontal_padding(), vertical_padding());
22- Style::Get()->DrawMenuItemEntry(entry_->label(), state, text_ctx, natural_.width, natural_.height);
23+ Style::Get()->DrawMenuItemEntry(entry_->label(), state, text_ctx, natural_.width, natural_.height, bg_geo * (1.0/scale));
24 cairo_restore(text_ctx);
25 SetTexture(text_ctx);
26 }
27
28=== modified file 'decorations/DecorationsTitle.cpp'
29--- decorations/DecorationsTitle.cpp 2014-03-03 19:04:46 +0000
30+++ decorations/DecorationsTitle.cpp 2014-03-31 18:58:05 +0000
31@@ -69,7 +69,16 @@
32
33 auto state = focused() ? WidgetState::NORMAL : WidgetState::BACKDROP;
34 cu::CairoContext text_ctx(texture_size_.width, texture_size_.height, scale());
35- Style::Get()->DrawTitle(text(), state, text_ctx, texture_size_.width / scale(), texture_size_.height / scale());
36+ nux::Rect bg_geo(0, 0, texture_size_.width, texture_size_.height);
37+
38+ if (BasicContainer::Ptr const& top = GetTopParent())
39+ {
40+ auto const& top_geo = top->Geometry();
41+ auto const& geo = Geometry();
42+ bg_geo.Set(top_geo.x() - geo.x(), top_geo.y() - geo.y(), top_geo.width(), top_geo.height());
43+ }
44+
45+ Style::Get()->DrawTitle(text(), state, text_ctx, texture_size_.width / scale(), texture_size_.height / scale(), bg_geo * (1.0/scale));
46 SetTexture(text_ctx);
47 }
48
49
50=== modified file 'panel/PanelIndicatorEntryView.cpp'
51--- panel/PanelIndicatorEntryView.cpp 2014-03-20 05:05:21 +0000
52+++ panel/PanelIndicatorEntryView.cpp 2014-03-31 18:58:05 +0000
53@@ -330,14 +330,11 @@
54 cairo_push_group(cr);
55 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y);
56 cairo_paint_with_alpha(cr, (IsIconSensitive() && IsFocused()) ? 1.0 : 0.5);
57-
58- cairo_pattern_t* pat = cairo_pop_group(cr);
59+ std::shared_ptr<cairo_pattern_t> pat(cairo_pop_group(cr), cairo_pattern_destroy);
60
61 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
62 cairo_rectangle(cr, x, y, width, height);
63- cairo_mask(cr, pat);
64-
65- cairo_pattern_destroy(pat);
66+ cairo_mask(cr, pat.get());
67 }
68 else
69 {
70@@ -395,6 +392,20 @@
71 }
72 else
73 {
74+ if (!IsActive())
75+ {
76+ // We need to render the background under the text glyphs, or the edge
77+ // of the text won't be correctly anti-aliased. See bug #723167
78+ cairo_push_group(cr);
79+ gtk_render_layout(style_context, cr, x, y, layout);
80+ std::shared_ptr<cairo_pattern_t> pat(cairo_pop_group(cr), cairo_pattern_destroy);
81+
82+ cairo_push_group(cr);
83+ gtk_render_background(style_context, cr, 0, 0, width, height);
84+ cairo_pop_group_to_source(cr);
85+ cairo_mask(cr, pat.get());
86+ }
87+
88 gtk_render_layout(style_context, cr, x, y, layout);
89 }
90
91
92=== modified file 'panel/PanelMenuView.cpp'
93--- panel/PanelMenuView.cpp 2014-03-12 23:06:44 +0000
94+++ panel/PanelMenuView.cpp 2014-03-31 18:58:05 +0000
95@@ -814,7 +814,9 @@
96 nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, title_geo_.width, title_geo_.height);
97 cairo_surface_set_device_scale(cairo_graphics.GetSurface(), dpi_scale, dpi_scale);
98 cairo_t* cr = cairo_graphics.GetInternalContext();
99- style->DrawTitle(label, state, cr, title_geo_.width / dpi_scale, title_geo_.height / dpi_scale);
100+
101+ nux::Geometry text_bg(-title_geo_.x, -title_geo_.y, geo.width, geo.height);
102+ style->DrawTitle(label, state, cr, title_geo_.width / dpi_scale, title_geo_.height / dpi_scale, text_bg * (1.0/dpi_scale));
103 title_texture_ = texture_ptr_from_cairo_graphics(cairo_graphics);
104 }
105
106
107=== modified file 'unity-shared/DecorationStyle.cpp'
108--- unity-shared/DecorationStyle.cpp 2014-03-20 05:05:21 +0000
109+++ unity-shared/DecorationStyle.cpp 2014-03-31 18:58:05 +0000
110@@ -499,7 +499,25 @@
111 return extents;
112 }
113
114- void DrawTitle(std::string const& text, WidgetState ws, cairo_t* cr, double w, double h)
115+ void DrawTextBackground(GtkStyleContext* ctx, cairo_t* cr, glib::Object<PangoLayout> const& layout, nux::Rect const& bg_geo)
116+ {
117+ if (bg_geo.IsNull())
118+ return;
119+
120+ // We need to render the background under the text glyphs, or the edge
121+ // of the text won't be correctly anti-aliased. See bug #723167
122+
123+ cairo_push_group(cr);
124+ gtk_render_layout(ctx, cr, 0, 0, layout);
125+ std::shared_ptr<cairo_pattern_t> pat(cairo_pop_group(cr), cairo_pattern_destroy);
126+
127+ cairo_push_group(cr);
128+ gtk_render_background(ctx, cr, bg_geo.x, bg_geo.y, bg_geo.width, bg_geo.height);
129+ cairo_pop_group_to_source(cr);
130+ cairo_mask(cr, pat.get());
131+ }
132+
133+ void DrawTitle(std::string const& text, WidgetState ws, cairo_t* cr, double w, double h, nux::Rect const& bg_geo)
134 {
135 gtk_style_context_save(ctx_);
136 AddContextClasses(Side::TOP, ws);
137@@ -516,6 +534,7 @@
138 double fading_width = std::min<double>(title_fade_, out_pixels);
139
140 cairo_push_group(cr);
141+ DrawTextBackground(ctx_, cr, layout, bg_geo);
142 gtk_render_layout(ctx_, cr, 0, 0, layout);
143 cairo_pop_group_to_source(cr);
144
145@@ -529,6 +548,7 @@
146 else
147 {
148 pango_layout_set_width(layout, (w >= 0) ? w * PANGO_SCALE : -1);
149+ DrawTextBackground(ctx_, cr, layout, bg_geo);
150 gtk_render_layout(ctx_, cr, 0, 0, layout);
151 }
152
153@@ -554,7 +574,7 @@
154 gtk_style_context_restore(ctx_);
155 }
156
157- void DrawMenuItemEntry(std::string const& text, WidgetState ws, cairo_t* cr, double w, double h)
158+ void DrawMenuItemEntry(std::string const& text, WidgetState ws, cairo_t* cr, double w, double h, nux::Rect const& bg_geo)
159 {
160 gtk_style_context_save(ctx_);
161 AddContextClassesForMenuItem(ws);
162@@ -573,6 +593,7 @@
163
164 pango_layout_set_width(layout, (w >= 0) ? w * PANGO_SCALE : -1);
165 pango_layout_set_height(layout, (h >= 0) ? h * PANGO_SCALE : -1);
166+ DrawTextBackground(ctx_, cr, layout, bg_geo);
167 gtk_render_layout(ctx_, cr, 0, 0, layout);
168
169 gtk_style_context_restore(ctx_);
170@@ -659,9 +680,9 @@
171 impl_->DrawSide(s, ws, cr, w, h);
172 }
173
174-void Style::DrawTitle(std::string const& t, WidgetState ws, cairo_t* cr, double w, double h)
175+void Style::DrawTitle(std::string const& t, WidgetState ws, cairo_t* cr, double w, double h, nux::Rect const& bg_geo)
176 {
177- impl_->DrawTitle(t, ws, cr, w, h);
178+ impl_->DrawTitle(t, ws, cr, w, h, bg_geo);
179 }
180
181 void Style::DrawMenuItem(WidgetState ws, cairo_t* cr, double w, double h)
182@@ -669,9 +690,9 @@
183 impl_->DrawMenuItem(ws, cr, w, h);
184 }
185
186-void Style::DrawMenuItemEntry(std::string const& t, WidgetState ws, cairo_t* cr, double w, double h)
187+void Style::DrawMenuItemEntry(std::string const& t, WidgetState ws, cairo_t* cr, double w, double h, nux::Rect const& bg_geo)
188 {
189- impl_->DrawMenuItemEntry(t, ws, cr, w, h);
190+ impl_->DrawMenuItemEntry(t, ws, cr, w, h, bg_geo);
191 }
192
193 void Style::DrawMenuItemIcon(std::string const& i, WidgetState ws, cairo_t* cr, int s)
194
195=== modified file 'unity-shared/DecorationStyle.h'
196--- unity-shared/DecorationStyle.h 2014-03-20 05:05:21 +0000
197+++ unity-shared/DecorationStyle.h 2014-03-31 18:58:05 +0000
198@@ -21,8 +21,7 @@
199 #define UNITY_DECORATION_STYLE
200
201 #include <NuxCore/Property.h>
202-#include <NuxCore/Point.h>
203-#include <NuxCore/Size.h>
204+#include <NuxCore/Rect.h>
205 #include <cairo/cairo.h>
206
207 namespace unity
208@@ -130,9 +129,9 @@
209 int DoubleClickMaxTimeDelta() const;
210
211 void DrawSide(Side, WidgetState, cairo_t*, double width, double height);
212- void DrawTitle(std::string const&, WidgetState, cairo_t*, double width, double height);
213+ void DrawTitle(std::string const&, WidgetState, cairo_t*, double width, double height, nux::Rect const& bg_geo = nux::Rect());
214 void DrawMenuItem(WidgetState, cairo_t*, double width, double height);
215- void DrawMenuItemEntry(std::string const&, WidgetState, cairo_t*, double width, double height);
216+ void DrawMenuItemEntry(std::string const&, WidgetState, cairo_t*, double width, double height, nux::Rect const& bg_geo = nux::Rect());
217 void DrawMenuItemIcon(std::string const&, WidgetState, cairo_t*, int size);
218
219 private:
220
221=== modified file 'unity-shared/UnitySettings.cpp'
222--- unity-shared/UnitySettings.cpp 2014-03-21 19:45:29 +0000
223+++ unity-shared/UnitySettings.cpp 2014-03-31 18:58:05 +0000
224@@ -262,7 +262,7 @@
225 double ui_scale = 1.0f;
226 int value;
227
228- if (g_variant_lookup(dict, monitor_name.c_str(), "i", &value))
229+ if (g_variant_lookup(dict, monitor_name.c_str(), "i", &value) && value > 0)
230 ui_scale = static_cast<double>(value)/8.0f;
231
232 if (app_target_monitor.Str() == monitor_name)