summaryrefslogtreecommitdiffstats
path: root/abs/core/pango/bgo563356.patch
blob: 226fd0c49543df758dd36a917406b737de00fea0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
diff -aur old/ChangeLog new/ChangeLog
--- old/ChangeLog	2008-12-06 14:35:33.037390818 +0800
+++ new/ChangeLog	2008-12-06 14:35:11.475339336 +0800
@@ -1,3 +1,39 @@
+2008-12-05  Behdad Esfahbod  <behdad@gnome.org>
+
+	Bug 563356 – The input area of firefox and the blank width after text
+	in gnome-menu was stretched too wide, under pango-1.22.3
+
+	* docs/tmpl/fonts.sgml:
+	* pango/pango-impl-utils.h:
+	* pango/pangocairo-atsuifont.c
+	(pango_cairo_atsui_font_create_metrics_for_context):
+	* pango/pangocairo-win32font.c
+	(pango_cairo_win32_font_create_metrics_for_context):
+	* pango/pangofc-font.c (pango_fc_font_create_metrics_for_context):
+	For approximate_char_width calculation take each char's width into
+	account.  That is, do a weighted average instead of uniform average.
+	g_unichar_iszerowidth() chars count as 0, g_unichar_iswide() chars
+	count 2, and the rest count as 1.  Pretty much wcwidth() behavior.
+	See bug report for rationale.
+
+2008-11-28  Behdad Esfahbod  <behdad@gnome.org>
+
+	Bug 562574 – Pangocariowin32 is leaking every cairo font it ever
+	creates
+
+	* pango/pangocairo-atsuifont.c (pango_cairo_atsui_font_finalize):
+	* pango/pangocairo-win32font.c (pango_cairo_win32_font_finalize):
+	Finalize shared pangocairo font resources.  Oops!
+
+	* pango/pangocairo-font.c (_pango_cairo_font_private_finalize):
+	Protect against multiple calls to finalize.  This is practiced by the
+	pangocairo-fcfont when a font is shutdown and then finalized.
+
+2008-11-26  Behdad Esfahbod  <behdad@gnome.org>
+
+	* examples/cairotwisted.c (parametrize_path), (point_on_path):
+	Handle close_path correctly.
+
 2008-11-23  Behdad Esfahbod  <behdad@gnome.org>
 
 	* === Released 1.22.3 ===
diff -aur old/docs/tmpl/fonts.sgml new/docs/tmpl/fonts.sgml
--- old/docs/tmpl/fonts.sgml	2008-12-06 14:35:11.450807479 +0800
+++ new/docs/tmpl/fonts.sgml	2008-12-06 14:34:53.771786070 +0800
@@ -441,7 +441,10 @@
 @descent: the distance from the baseline to the lowest point of the glyphs of
 	 the font. This is positive in practically all fonts.
 @approximate_char_width: approximate average width of the regular glyphs of
-         the font.
+         the font.  Note that for this calculation, East Asian characters
+	 (those passing g_unichar_iswide()) are counted as double-width.
+	 This produces a more uniform value for this measure across languages
+	 and results in more uniform and more expected UI sizes.
 @approximate_digit_width: approximate average width of the glyphs for digits
          of the font.
 @underline_position: position of the underline. This is normally negative.
diff -aur old/examples/cairotwisted.c new/examples/cairotwisted.c
--- old/examples/cairotwisted.c	2008-12-06 14:35:32.900725834 +0800
+++ new/examples/cairotwisted.c	2008-12-06 14:35:11.264059243 +0800
@@ -216,7 +216,7 @@
 parametrize_path (cairo_path_t *path)
 {
   int i;
-  cairo_path_data_t *data, current_point;
+  cairo_path_data_t *data, last_move_to, current_point;
   parametrization_t *parametrization;
 
   parametrization = malloc (path->num_data * sizeof (parametrization[0]));
@@ -226,8 +226,13 @@
     parametrization[i] = 0.0;
     switch (data->header.type) {
     case CAIRO_PATH_MOVE_TO:
+	last_move_to = data[1];
 	current_point = data[1];
 	break;
+    case CAIRO_PATH_CLOSE_PATH:
+	/* Make it look like it's a line_to to last_move_to */
+	data = (&last_move_to) - 1;
+	/* fall through */
     case CAIRO_PATH_LINE_TO:
 	parametrization[i] = two_points_distance (&current_point, &data[1]);
 	current_point = data[1];
@@ -245,8 +250,6 @@
 
 	current_point = data[3];
 	break;
-    case CAIRO_PATH_CLOSE_PATH:
-	break;
     default:
 	g_assert_not_reached ();
     }
@@ -320,7 +323,7 @@
 {
   int i;
   double ratio, the_y = *y, the_x = *x, dx, dy;
-  cairo_path_data_t *data, current_point;
+  cairo_path_data_t *data, last_move_to, current_point;
   cairo_path_t *path = param->path;
   parametrization_t *parametrization = param->parametrization;
 
@@ -333,6 +336,7 @@
     switch (data->header.type) {
     case CAIRO_PATH_MOVE_TO:
 	current_point = data[1];
+        last_move_to = data[1];
 	break;
     case CAIRO_PATH_LINE_TO:
 	current_point = data[1];
@@ -352,6 +356,10 @@
 
   case CAIRO_PATH_MOVE_TO:
       break;
+  case CAIRO_PATH_CLOSE_PATH:
+      /* Make it look like it's a line_to to last_move_to */
+      data = (&last_move_to) - 1;
+      /* fall through */
   case CAIRO_PATH_LINE_TO:
       {
 	ratio = the_x / parametrization[i];
@@ -424,8 +432,6 @@
 	*y +=  dx * ratio;
       }
       break;
-  case CAIRO_PATH_CLOSE_PATH:
-      break;
   default:
       g_assert_not_reached ();
   }
diff -aur old/pango/pango-impl-utils.h new/pango/pango-impl-utils.h
--- old/pango/pango-impl-utils.h	2008-12-06 14:35:22.291559359 +0800
+++ new/pango/pango-impl-utils.h	2008-12-06 14:35:03.550729660 +0800
@@ -23,6 +23,7 @@
 #ifndef __PANGO_IMPL_UTILS_H__
 #define __PANGO_IMPL_UTILS_H__
 
+#include <glib.h>
 #include <glib-object.h>
 #include <pango/pango.h>
 
@@ -92,6 +93,36 @@
 			       PangoRectangle   *ink_rect,
 			       PangoRectangle   *logical_rect);
 
+
+/* We define these functions static here because we don't want to add public API
+ * for them (if anything, it belongs to glib, but glib found it trivial enough
+ * not to add API for).  At some point metrics calculations will be
+ * centralized and this mess can be minimized.  Or so I hope.
+ */
+
+static inline G_GNUC_UNUSED int
+pango_unichar_width (gunichar c)
+{
+  return G_UNLIKELY (g_unichar_iszerowidth (c)) ? 0 :
+	   G_UNLIKELY (g_unichar_iswide (c)) ? 2 : 1;
+}
+
+static G_GNUC_UNUSED glong
+pango_utf8_strwidth (const gchar *p)
+{
+  glong len = 0;
+  g_return_val_if_fail (p != NULL, 0);
+
+  while (*p)
+    {
+      len += pango_unichar_width (g_utf8_get_char (p));
+      p = g_utf8_next_char (p);
+    }
+
+  return len;
+}
+
+
 G_END_DECLS
 
 #endif /* __PANGO_IMPL_UTILS_H__ */
diff -aur old/pango/pangocairo-atsuifont.c new/pango/pangocairo-atsuifont.c
--- old/pango/pangocairo-atsuifont.c	2008-12-06 14:35:23.464057615 +0800
+++ new/pango/pangocairo-atsuifont.c	2008-12-06 14:35:04.914061436 +0800
@@ -24,6 +24,7 @@
 
 #import <Cocoa/Cocoa.h>
 
+#include "pango-impl-utils.h"
 #include "pangoatsui-private.h"
 #include "pangocairo.h"
 #include "pangocairo-private.h"
@@ -148,7 +149,7 @@
   pango_layout_set_text (layout, sample_str, -1);
   pango_layout_get_extents (layout, NULL, &extents);
 
-  metrics->approximate_char_width = extents.width / g_utf8_strlen (sample_str, -1);
+  metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str);
 
   pango_layout_set_text (layout, "0123456789", -1);
   metrics->approximate_digit_width = max_glyph_width (layout);
@@ -174,6 +175,10 @@
 static void
 pango_cairo_atsui_font_finalize (GObject *object)
 {
+  PangoCairoATSUIFont *cafont = (PangoCairoATSUIFont *) object;
+
+  _pango_cairo_font_private_finalize (&cafont->cf_priv);
+
   G_OBJECT_CLASS (pango_cairo_atsui_font_parent_class)->finalize (object);
 }
 
@@ -191,7 +196,7 @@
 }
 
 static void
-pango_cairo_atsui_font_init (PangoCairoATSUIFont *cafont)
+pango_cairo_atsui_font_init (PangoCairoATSUIFont *cafont G_GNUC_UNUSED)
 {
 }
 
diff -aur old/pango/pangocairo-fcfont.c new/pango/pangocairo-fcfont.c
--- old/pango/pangocairo-fcfont.c	2008-12-06 14:35:22.840724772 +0800
+++ new/pango/pangocairo-fcfont.c	2008-12-06 14:35:04.294060844 +0800
@@ -88,7 +88,7 @@
 static void
 pango_cairo_fc_font_finalize (GObject *object)
 {
-  PangoCairoFcFont *cffont = (PangoCairoFcFont *) (object);
+  PangoCairoFcFont *cffont = (PangoCairoFcFont *) object;
 
   _pango_cairo_font_private_finalize (&cffont->cf_priv);
 
@@ -162,7 +162,7 @@
 }
 
 static void
-pango_cairo_fc_font_init (PangoCairoFcFont *cffont)
+pango_cairo_fc_font_init (PangoCairoFcFont *cffont G_GNUC_UNUSED)
 {
 }
 
diff -aur old/pango/pangocairo-font.c new/pango/pangocairo-font.c
--- old/pango/pangocairo-font.c	2008-12-06 14:35:23.387391067 +0800
+++ new/pango/pangocairo-font.c	2008-12-06 14:35:04.840728398 +0800
@@ -560,14 +560,18 @@
 
   if (cf_priv->scaled_font)
     cairo_scaled_font_destroy (cf_priv->scaled_font);
+  cf_priv->scaled_font = NULL;
 
   _pango_cairo_font_hex_box_info_destroy (cf_priv->hbi);
+  cf_priv->hbi = NULL;
 
   if (cf_priv->glyph_extents_cache)
     g_free (cf_priv->glyph_extents_cache);
+  cf_priv->glyph_extents_cache = NULL;
 
   g_slist_foreach (cf_priv->metrics_by_lang, (GFunc)free_metrics_info, NULL);
   g_slist_free (cf_priv->metrics_by_lang);
+  cf_priv->metrics_by_lang = NULL;
 }
 
 gboolean
diff -aur old/pango/pangocairo-win32font.c new/pango/pangocairo-win32font.c
--- old/pango/pangocairo-win32font.c	2008-12-06 14:35:22.500726273 +0800
+++ new/pango/pangocairo-win32font.c	2008-12-06 14:35:03.990726207 +0800
@@ -150,7 +150,7 @@
   pango_layout_set_text (layout, sample_str, -1);
   pango_layout_get_extents (layout, NULL, &extents);
 
-  metrics->approximate_char_width = extents.width / g_utf8_strlen (sample_str, -1);
+  metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str);
 
   pango_layout_set_text (layout, "0123456789", -1);
   metrics->approximate_digit_width = max_glyph_width (layout);
@@ -164,6 +164,10 @@
 static void
 pango_cairo_win32_font_finalize (GObject *object)
 {
+  PangoCairoWin32Font *cwfont = (PangoCairoWin32Font *) object;
+
+  _pango_cairo_font_private_finalize (&cwfont->cf_priv);
+
   G_OBJECT_CLASS (pango_cairo_win32_font_parent_class)->finalize (object);
 }
 
@@ -225,7 +229,7 @@
 }
 
 static void
-pango_cairo_win32_font_init (PangoCairoWin32Font *cwfont)
+pango_cairo_win32_font_init (PangoCairoWin32Font *cwfont G_GNUC_UNUSED)
 {
 }
 
diff -aur old/pango/pangofc-font.c new/pango/pangofc-font.c
--- old/pango/pangofc-font.c	2008-12-06 14:35:23.117390557 +0800
+++ new/pango/pangofc-font.c	2008-12-06 14:35:04.564059609 +0800
@@ -496,7 +496,7 @@
   pango_layout_get_extents (layout, NULL, &extents);
 
   metrics->approximate_char_width =
-    extents.width / g_utf8_strlen (sample_str, -1);
+    extents.width / pango_utf8_strwidth (sample_str);
 
   pango_layout_set_text (layout, "0123456789", -1);
   metrics->approximate_digit_width = max_glyph_width (layout);