Merge lp:~macslow/notify-osd/fix-fractional-point-size into lp:notify-osd/karmic

Proposed by Mirco Müller
Status: Merged
Merge reported by: Mirco Müller
Merged at revision: not available
Proposed branch: lp:~macslow/notify-osd/fix-fractional-point-size
Merge into: lp:notify-osd/karmic
Diff against target: 165 lines
4 files modified
src/defaults.c (+19/-12)
src/util.c (+0/-39)
src/util.h (+0/-3)
tests/test-text-filtering.c (+0/-23)
To merge this branch: bzr merge lp:~macslow/notify-osd/fix-fractional-point-size
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+13913@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Mirco Müller (macslow) wrote :

This branch fixes extracting a fonts point-size with a fractional part and thus addresses LP: #396736, LP: #457655, LP: #458413, LP: #459290, LP: #459689. The lack of this fix causes notification bubbles to be really tiny (see http://launchpadlibrarian.net/34315070/screenshot_001.png), should the user have set a font point-size of e.g. 8,5. I regard this fix to be critical within the scope of immediate user-experience of Karmic and taking into account a users system setup, which might not be the default "Sans 10"-case.

Revision history for this message
Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/defaults.c'
--- src/defaults.c 2009-10-19 17:59:53 +0000
+++ src/defaults.c 2009-10-25 10:15:22 +0000
@@ -172,13 +172,14 @@
172static void172static void
173_get_font_size_dpi (Defaults* self)173_get_font_size_dpi (Defaults* self)
174{174{
175 GString* string = NULL;175 GString* string = NULL;
176 GError* error = NULL;176 GError* error = NULL;
177 guint points = 0;177 gdouble points = 0.0f;
178 GString* font_face = NULL;178 GString* font_face = NULL;
179 gdouble dpi = 0.0f;179 gdouble dpi = 0.0f;
180 gdouble pixels_per_em = 0;180 gdouble pixels_per_em = 0;
181 gchar* font_name = NULL;181 gchar* font_name = NULL;
182 PangoFontDescription* desc = NULL;
182183
183 if (!IS_DEFAULTS (self))184 if (!IS_DEFAULTS (self))
184 return;185 return;
@@ -198,11 +199,17 @@
198 error->message);199 error->message);
199 g_error_free (error);200 g_error_free (error);
200 }201 }
202
203 // extract text point-size
204 desc = pango_font_description_from_string (font_name);
205 if (pango_font_description_get_size_is_absolute (desc))
206 points = (gdouble) pango_font_description_get_size (desc);
207 else
208 points = (gdouble) pango_font_description_get_size (desc) /
209 (gdouble) PANGO_SCALE;
210 pango_font_description_free (desc);
201 g_free ((gpointer) font_name);211 g_free ((gpointer) font_name);
202212
203 // extract text point-size
204 points = extract_point_size (string->str);
205
206 // extract font-face-name/style213 // extract font-face-name/style
207 font_face = extract_font_face (string->str);214 font_face = extract_font_face (string->str);
208215
@@ -233,12 +240,12 @@
233 }240 }
234241
235 /* update stored DPI-value */242 /* update stored DPI-value */
236 pixels_per_em = (gdouble) points * dpi / 72.0f;243 pixels_per_em = points * dpi / 72.0f;
237 g_object_set (self, "pixels-per-em", pixels_per_em, NULL);244 g_object_set (self, "pixels-per-em", pixels_per_em, NULL);
238 g_object_set (self, "screen-dpi", dpi, NULL);245 g_object_set (self, "screen-dpi", dpi, NULL);
239246
240 if (g_getenv ("DEBUG"))247 if (g_getenv ("DEBUG"))
241 g_print ("font-size: %dpt\ndpi: %3.1f\npixels/EM: %2.2f\nwidth: %d px\ntitle-height: %2.2f pt\nbody-height: %2.2f pt\n\n",248 g_print ("font-size: %fpt\ndpi: %3.1f\npixels/EM: %2.2f\nwidth: %d px\ntitle-height: %2.2f pt\nbody-height: %2.2f pt\n\n",
242 points,249 points,
243 defaults_get_screen_dpi (self),250 defaults_get_screen_dpi (self),
244 pixels_per_em,251 pixels_per_em,
245252
=== modified file 'src/util.c'
--- src/util.c 2009-10-19 04:57:25 +0000
+++ src/util.c 2009-10-25 10:15:22 +0000
@@ -258,45 +258,6 @@
258 return (gchar*) buffer;258 return (gchar*) buffer;
259}259}
260260
261guint
262extract_point_size (const gchar* string)
263{
264 guint point_size = 0;
265 GRegex* regex = NULL;
266 GMatchInfo* match_info = NULL;
267
268 // sanity check
269 if (!string)
270 return 0;
271
272 // setup regular expression to extract an integer from the end of string
273 regex = g_regex_new ("\\d+$", 0, 0, NULL);
274 if (!regex)
275 return 0;
276
277 // walk the string
278 g_regex_match (regex, string, 0, &match_info);
279 while (g_match_info_matches (match_info))
280 {
281 gchar* word = NULL;
282
283 word = g_match_info_fetch (match_info, 0);
284 if (word)
285 {
286 sscanf (word, "%d", &point_size);
287 g_free (word);
288 }
289
290 g_match_info_next (match_info, NULL);
291 }
292
293 // clean up
294 g_match_info_free (match_info);
295 g_regex_unref (regex);
296
297 return point_size;
298}
299
300GString*261GString*
301extract_font_face (const gchar* string)262extract_font_face (const gchar* string)
302{263{
303264
=== modified file 'src/util.h'
--- src/util.h 2009-10-19 04:57:25 +0000
+++ src/util.h 2009-10-25 10:15:22 +0000
@@ -52,8 +52,5 @@
52gchar*52gchar*
53get_wm_name (Display* dpy);53get_wm_name (Display* dpy);
5454
55guint
56extract_point_size (const gchar* string);
57
58GString*55GString*
59extract_font_face (const gchar* string);56extract_font_face (const gchar* string);
6057
=== modified file 'tests/test-text-filtering.c'
--- tests/test-text-filtering.c 2009-10-19 04:57:25 +0000
+++ tests/test-text-filtering.c 2009-10-25 10:15:22 +0000
@@ -103,28 +103,6 @@
103}103}
104104
105static void105static void
106test_extract_point_size ()
107{
108 static const IntegerExtraction tests[] = {
109 { "", 0 },
110 { "foobar", 0 },
111 { "Bla Fasel -12.0", 0 },
112 { "Sans 10", 10 },
113 { "Candara 9", 9 },
114 { "Bitstream Vera Serif Italic 1", 1 },
115 { "Calibri Italic 100", 100 },
116 { "Century Schoolbook L Italic 42", 42 },
117 { NULL, 0 }
118 };
119
120 for (int i = 0; tests[i].before != NULL; i++)
121 {
122 guint extracted = extract_point_size (tests[i].before);
123 g_assert_cmpuint (extracted, ==, tests[i].expected);
124 }
125}
126
127static void
128test_extract_font_face ()106test_extract_font_face ()
129{107{
130 static const TextComparisons tests[] = {108 static const TextComparisons tests[] = {
@@ -156,7 +134,6 @@
156134
157 g_test_suite_add(ts, TC(test_text_filter));135 g_test_suite_add(ts, TC(test_text_filter));
158 g_test_suite_add(ts, TC(test_newline_to_space));136 g_test_suite_add(ts, TC(test_newline_to_space));
159 g_test_suite_add(ts, TC(test_extract_point_size));
160 g_test_suite_add(ts, TC(test_extract_font_face));137 g_test_suite_add(ts, TC(test_extract_font_face));
161138
162 return ts;139 return ts;

Subscribers

People subscribed via source and target branches

to all changes: