1 | /* Pango |
2 | * test-font.c: Test PangoFontDescription |
3 | * |
4 | * Copyright (C) 2014 Red Hat, Inc |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public |
17 | * License along with this library; if not, write to the |
18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | * Boston, MA 02111-1307, USA. |
20 | */ |
21 | |
22 | #include <glib.h> |
23 | #include <string.h> |
24 | #include <locale.h> |
25 | |
26 | #include <gio/gio.h> |
27 | #include <pango/pangocairo.h> |
28 | |
29 | static PangoContext *context; |
30 | |
31 | static void |
32 | test_parse (void) |
33 | { |
34 | PangoFontDescription **descs; |
35 | PangoFontDescription *desc; |
36 | |
37 | descs = g_new (PangoFontDescription *, 2); |
38 | |
39 | descs[0] = desc = pango_font_description_from_string (str: "Cantarell 14" ); |
40 | |
41 | g_assert_cmpstr (pango_font_description_get_family (desc), ==, "Cantarell" ); |
42 | g_assert (!pango_font_description_get_size_is_absolute (desc)); |
43 | g_assert_cmpint (pango_font_description_get_size (desc), ==, 14 * PANGO_SCALE); |
44 | g_assert_cmpint (pango_font_description_get_style (desc), ==, PANGO_STYLE_NORMAL); |
45 | g_assert_cmpint (pango_font_description_get_variant (desc), ==, PANGO_VARIANT_NORMAL); |
46 | g_assert_cmpint (pango_font_description_get_weight (desc), ==, PANGO_WEIGHT_NORMAL); |
47 | g_assert_cmpint (pango_font_description_get_stretch (desc), ==, PANGO_STRETCH_NORMAL); |
48 | g_assert_cmpint (pango_font_description_get_gravity (desc), ==, PANGO_GRAVITY_SOUTH); |
49 | g_assert_cmpint (pango_font_description_get_set_fields (desc), ==, PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_STYLE | PANGO_FONT_MASK_VARIANT | PANGO_FONT_MASK_WEIGHT | PANGO_FONT_MASK_STRETCH | PANGO_FONT_MASK_SIZE); |
50 | |
51 | descs[1] = desc = pango_font_description_from_string (str: "Sans Bold Italic Condensed 22.5px" ); |
52 | |
53 | g_assert_cmpstr (pango_font_description_get_family (desc), ==, "Sans" ); |
54 | g_assert (pango_font_description_get_size_is_absolute (desc)); |
55 | g_assert_cmpint (pango_font_description_get_size (desc), ==, 225 * PANGO_SCALE / 10); |
56 | g_assert_cmpint (pango_font_description_get_style (desc), ==, PANGO_STYLE_ITALIC); |
57 | g_assert_cmpint (pango_font_description_get_variant (desc), ==, PANGO_VARIANT_NORMAL); |
58 | g_assert_cmpint (pango_font_description_get_weight (desc), ==, PANGO_WEIGHT_BOLD); |
59 | g_assert_cmpint (pango_font_description_get_stretch (desc), ==, PANGO_STRETCH_CONDENSED); |
60 | g_assert_cmpint (pango_font_description_get_gravity (desc), ==, PANGO_GRAVITY_SOUTH); g_assert_cmpint (pango_font_description_get_set_fields (desc), ==, PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_STYLE | PANGO_FONT_MASK_VARIANT | PANGO_FONT_MASK_WEIGHT | PANGO_FONT_MASK_STRETCH | PANGO_FONT_MASK_SIZE); |
61 | |
62 | pango_font_descriptions_free (descs, n_descs: 2); |
63 | } |
64 | |
65 | static void |
66 | test_roundtrip (void) |
67 | { |
68 | PangoFontDescription *desc; |
69 | char *str; |
70 | |
71 | desc = pango_font_description_from_string (str: "Cantarell 14" ); |
72 | str = pango_font_description_to_string (desc); |
73 | g_assert_cmpstr (str, ==, "Cantarell 14" ); |
74 | pango_font_description_free (desc); |
75 | g_free (mem: str); |
76 | |
77 | desc = pango_font_description_from_string (str: "Sans Bold Italic Condensed 22.5px" ); |
78 | str = pango_font_description_to_string (desc); |
79 | g_assert_cmpstr (str, ==, "Sans Bold Italic Condensed 22.5px" ); |
80 | pango_font_description_free (desc); |
81 | g_free (mem: str); |
82 | } |
83 | |
84 | static void |
85 | test_variations (void) |
86 | { |
87 | PangoFontDescription *desc1; |
88 | PangoFontDescription *desc2; |
89 | gchar *str; |
90 | |
91 | desc1 = pango_font_description_from_string (str: "Cantarell 14" ); |
92 | g_assert (desc1 != NULL); |
93 | g_assert ((pango_font_description_get_set_fields (desc1) & PANGO_FONT_MASK_VARIATIONS) == 0); |
94 | g_assert (pango_font_description_get_variations (desc1) == NULL); |
95 | |
96 | str = pango_font_description_to_string (desc: desc1); |
97 | g_assert_cmpstr (str, ==, "Cantarell 14" ); |
98 | g_free (mem: str); |
99 | |
100 | desc2 = pango_font_description_from_string (str: "Cantarell 14 @wght=100,wdth=235" ); |
101 | g_assert (desc2 != NULL); |
102 | g_assert ((pango_font_description_get_set_fields (desc2) & PANGO_FONT_MASK_VARIATIONS) != 0); |
103 | g_assert_cmpstr (pango_font_description_get_variations (desc2), ==, "wght=100,wdth=235" ); |
104 | |
105 | str = pango_font_description_to_string (desc: desc2); |
106 | g_assert_cmpstr (str, ==, "Cantarell 14 @wght=100,wdth=235" ); |
107 | g_free (mem: str); |
108 | |
109 | g_assert (!pango_font_description_equal (desc1, desc2)); |
110 | |
111 | pango_font_description_set_variations (desc: desc1, variations: "wght=100,wdth=235" ); |
112 | g_assert ((pango_font_description_get_set_fields (desc1) & PANGO_FONT_MASK_VARIATIONS) != 0); |
113 | g_assert_cmpstr (pango_font_description_get_variations (desc1), ==, "wght=100,wdth=235" ); |
114 | |
115 | g_assert (pango_font_description_equal (desc1, desc2)); |
116 | |
117 | pango_font_description_free (desc: desc1); |
118 | pango_font_description_free (desc: desc2); |
119 | } |
120 | |
121 | static void |
122 | test_empty_variations (void) |
123 | { |
124 | PangoFontDescription *desc; |
125 | gchar *str; |
126 | |
127 | desc = pango_font_description_from_string (str: "Cantarell 14" ); |
128 | g_assert_nonnull (desc); |
129 | g_assert_cmpint ((pango_font_description_get_set_fields (desc) & PANGO_FONT_MASK_VARIATIONS), ==, 0); |
130 | g_assert_null (pango_font_description_get_variations (desc)); |
131 | |
132 | str = pango_font_description_to_string (desc); |
133 | g_assert_cmpstr (str, ==, "Cantarell 14" ); |
134 | g_free (mem: str); |
135 | |
136 | pango_font_description_set_variations (desc, variations: "" ); |
137 | g_assert_cmpint ((pango_font_description_get_set_fields (desc) & PANGO_FONT_MASK_VARIATIONS), ==, PANGO_FONT_MASK_VARIATIONS); |
138 | g_assert_cmpstr (pango_font_description_get_variations (desc), ==, "" ); |
139 | |
140 | str = pango_font_description_to_string (desc); |
141 | g_assert_cmpstr (str, ==, "Cantarell 14" ); |
142 | g_free (mem: str); |
143 | |
144 | pango_font_description_free (desc); |
145 | } |
146 | |
147 | static void |
148 | test_metrics (void) |
149 | { |
150 | PangoFontDescription *desc; |
151 | PangoFontMetrics *metrics; |
152 | char *str; |
153 | |
154 | |
155 | if (strcmp (G_OBJECT_TYPE_NAME (pango_context_get_font_map (context)), s2: "PangoCairoWin32FontMap" ) == 0) |
156 | desc = pango_font_description_from_string (str: "Verdana 11" ); |
157 | else |
158 | desc = pango_font_description_from_string (str: "Cantarell 11" ); |
159 | |
160 | str = pango_font_description_to_string (desc); |
161 | |
162 | metrics = pango_context_get_metrics (context, desc, language: pango_language_get_default ()); |
163 | |
164 | g_test_message (format: "%s metrics" , str); |
165 | g_test_message (format: "\tascent: %d" , pango_font_metrics_get_ascent (metrics)); |
166 | g_test_message (format: "\tdescent: %d" , pango_font_metrics_get_descent (metrics)); |
167 | g_test_message (format: "\theight: %d" , pango_font_metrics_get_height (metrics)); |
168 | g_test_message (format: "\tchar width: %d" , |
169 | pango_font_metrics_get_approximate_char_width (metrics)); |
170 | g_test_message (format: "\tdigit width: %d" , |
171 | pango_font_metrics_get_approximate_digit_width (metrics)); |
172 | g_test_message (format: "\tunderline position: %d" , |
173 | pango_font_metrics_get_underline_position (metrics)); |
174 | g_test_message (format: "\tunderline thickness: %d" , |
175 | pango_font_metrics_get_underline_thickness (metrics)); |
176 | g_test_message (format: "\tstrikethrough position: %d" , |
177 | pango_font_metrics_get_strikethrough_position (metrics)); |
178 | g_test_message (format: "\tstrikethrough thickness: %d" , |
179 | pango_font_metrics_get_strikethrough_thickness (metrics)); |
180 | |
181 | pango_font_metrics_unref (metrics); |
182 | g_free (mem: str); |
183 | pango_font_description_free (desc); |
184 | } |
185 | |
186 | static void |
187 | test_extents (void) |
188 | { |
189 | const char *str = "Composer" ; |
190 | GList *items; |
191 | PangoItem *item; |
192 | PangoGlyphString *glyphs; |
193 | PangoRectangle ink, log; |
194 | PangoContext *context; |
195 | PangoFontDescription *desc; |
196 | |
197 | context = pango_font_map_create_context (fontmap: pango_cairo_font_map_get_default ()); |
198 | desc = pango_font_description_from_string(str: "Cantarell 11" ); |
199 | pango_context_set_font_description (context, desc); |
200 | pango_font_description_free (desc); |
201 | |
202 | items = pango_itemize (context, text: str, start_index: 0, length: strlen (s: str), NULL, NULL); |
203 | glyphs = pango_glyph_string_new (); |
204 | item = items->data; |
205 | pango_shape (text: str, length: strlen (s: str), analysis: &item->analysis, glyphs); |
206 | pango_glyph_string_extents (glyphs, font: item->analysis.font, ink_rect: &ink, logical_rect: &log); |
207 | |
208 | g_assert_cmpint (ink.width, >=, 0); |
209 | g_assert_cmpint (ink.height, >=, 0); |
210 | g_assert_cmpint (log.width, >=, 0); |
211 | g_assert_cmpint (log.height, >=, 0); |
212 | |
213 | pango_glyph_string_free (string: glyphs); |
214 | g_list_free_full (list: items, free_func: (GDestroyNotify)pango_item_free); |
215 | g_object_unref (object: context); |
216 | } |
217 | |
218 | static void |
219 | test_enumerate (void) |
220 | { |
221 | PangoFontMap *fontmap; |
222 | PangoContext *context; |
223 | PangoFontFamily **families; |
224 | PangoFontFamily *family; |
225 | int n_families; |
226 | int i; |
227 | PangoFontFace **faces; |
228 | PangoFontFace *face; |
229 | int n_faces; |
230 | PangoFontDescription *desc; |
231 | PangoFont *font; |
232 | gboolean found_face; |
233 | |
234 | fontmap = pango_cairo_font_map_get_default (); |
235 | context = pango_font_map_create_context (fontmap); |
236 | |
237 | pango_font_map_list_families (fontmap, families: &families, n_families: &n_families); |
238 | g_assert_cmpint (n_families, >, 0); |
239 | |
240 | for (i = 0; i < n_families; i++) |
241 | { |
242 | family = pango_font_map_get_family (fontmap, name: pango_font_family_get_name (family: families[i])); |
243 | g_assert_true (family == families[i]); |
244 | } |
245 | |
246 | pango_font_family_list_faces (family: families[0], faces: &faces, n_faces: &n_faces); |
247 | g_assert_cmpint (n_faces, >, 0); |
248 | for (i = 0; i < n_faces; i++) |
249 | { |
250 | face = pango_font_family_get_face (family: families[0], name: pango_font_face_get_face_name (face: faces[i])); |
251 | g_assert_cmpstr (pango_font_face_get_face_name (face), ==, pango_font_face_get_face_name (faces[i])); |
252 | } |
253 | |
254 | desc = pango_font_description_new (); |
255 | pango_font_description_set_family (desc, family: pango_font_family_get_name (family: families[0])); |
256 | pango_font_description_set_size (desc, size: 10*PANGO_SCALE); |
257 | |
258 | font = pango_font_map_load_font (fontmap, context, desc); |
259 | face = pango_font_get_face (font); |
260 | found_face = FALSE; |
261 | for (i = 0; i < n_faces; i++) |
262 | { |
263 | if (face == faces[i]) |
264 | { |
265 | found_face = TRUE; |
266 | break; |
267 | } |
268 | } |
269 | g_assert_true (found_face); |
270 | |
271 | g_object_unref (object: font); |
272 | pango_font_description_free (desc); |
273 | g_free (mem: faces); |
274 | g_free (mem: families); |
275 | g_object_unref (object: context); |
276 | } |
277 | |
278 | static void |
279 | test_roundtrip_plain (void) |
280 | { |
281 | PangoFontMap *fontmap; |
282 | PangoContext *context; |
283 | PangoFontDescription *desc, *desc2; |
284 | PangoFont *font; |
285 | |
286 | #ifdef HAVE_CARBON |
287 | desc = pango_font_description_from_string ("Helvetica 11" ); |
288 | #else |
289 | desc = pango_font_description_from_string (str: "Cantarell 11" ); |
290 | #endif |
291 | |
292 | fontmap = pango_cairo_font_map_get_default (); |
293 | context = pango_font_map_create_context (fontmap); |
294 | |
295 | |
296 | font = pango_context_load_font (context, desc); |
297 | desc2 = pango_font_describe (font); |
298 | |
299 | g_assert_true (pango_font_description_equal (desc2, desc)); |
300 | |
301 | pango_font_description_free (desc: desc2); |
302 | g_object_unref (object: font); |
303 | pango_font_description_free (desc); |
304 | g_object_unref (object: context); |
305 | } |
306 | |
307 | static void |
308 | test_roundtrip_small_caps (void) |
309 | { |
310 | PangoFontMap *fontmap; |
311 | PangoContext *context; |
312 | PangoFontDescription *desc, *desc2; |
313 | PangoFont *font; |
314 | hb_feature_t features[32]; |
315 | guint num = 0; |
316 | |
317 | if (strcmp (G_OBJECT_TYPE_NAME (pango_cairo_font_map_get_default ()), s2: "PangoCairoCoreTextFontMap" ) == 0) |
318 | { |
319 | g_test_skip (msg: "Small Caps support needs to be added to PangoCoreTextFontMap" ); |
320 | return; |
321 | } |
322 | |
323 | fontmap = pango_cairo_font_map_get_default (); |
324 | context = pango_font_map_create_context (fontmap); |
325 | |
326 | desc = pango_font_description_from_string (str: "Cantarell Small-Caps 11" ); |
327 | g_assert_true (pango_font_description_get_variant (desc) == PANGO_VARIANT_SMALL_CAPS); |
328 | |
329 | font = pango_context_load_font (context, desc); |
330 | desc2 = pango_font_describe (font); |
331 | |
332 | num = 0; |
333 | pango_font_get_features (font, features, G_N_ELEMENTS (features), num_features: &num); |
334 | g_assert_true (num == 1); |
335 | g_assert_true (features[0].tag == HB_TAG ('s', 'm', 'c', 'p')); |
336 | g_assert_true (features[0].value == 1); |
337 | g_assert_true (pango_font_description_get_variant (desc2) == PANGO_VARIANT_SMALL_CAPS); |
338 | g_assert_true (pango_font_description_equal (desc2, desc)); |
339 | |
340 | pango_font_description_free (desc: desc2); |
341 | g_object_unref (object: font); |
342 | pango_font_description_free (desc); |
343 | |
344 | desc = pango_font_description_from_string (str: "Cantarell All-Small-Caps 11" ); |
345 | g_assert_true (pango_font_description_get_variant (desc) == PANGO_VARIANT_ALL_SMALL_CAPS); |
346 | |
347 | font = pango_context_load_font (context, desc); |
348 | desc2 = pango_font_describe (font); |
349 | |
350 | num = 0; |
351 | pango_font_get_features (font, features, G_N_ELEMENTS (features), num_features: &num); |
352 | g_assert_true (num == 2); |
353 | g_assert_true (features[0].tag == HB_TAG ('s', 'm', 'c', 'p')); |
354 | g_assert_true (features[0].value == 1); |
355 | g_assert_true (features[1].tag == HB_TAG ('c', '2', 's', 'c')); |
356 | g_assert_true (features[1].value == 1); |
357 | g_assert_true (pango_font_description_get_variant (desc2) == PANGO_VARIANT_ALL_SMALL_CAPS); |
358 | g_assert_true (pango_font_description_equal (desc2, desc)); |
359 | |
360 | pango_font_description_free (desc: desc2); |
361 | g_object_unref (object: font); |
362 | pango_font_description_free (desc); |
363 | |
364 | desc = pango_font_description_from_string (str: "Cantarell Unicase 11" ); |
365 | g_assert_true (pango_font_description_get_variant (desc) == PANGO_VARIANT_UNICASE); |
366 | |
367 | font = pango_context_load_font (context, desc); |
368 | desc2 = pango_font_describe (font); |
369 | |
370 | num = 0; |
371 | pango_font_get_features (font, features, G_N_ELEMENTS (features), num_features: &num); |
372 | g_assert_true (num == 1); |
373 | g_assert_true (features[0].tag == HB_TAG ('u', 'n', 'i', 'c')); |
374 | g_assert_true (features[0].value == 1); |
375 | g_assert_true (pango_font_description_get_variant (desc2) == PANGO_VARIANT_UNICASE); |
376 | g_assert_true (pango_font_description_equal (desc2, desc)); |
377 | |
378 | pango_font_description_free (desc: desc2); |
379 | g_object_unref (object: font); |
380 | pango_font_description_free (desc); |
381 | |
382 | g_object_unref (object: context); |
383 | } |
384 | |
385 | static void |
386 | test_roundtrip_emoji (void) |
387 | { |
388 | PangoFontMap *fontmap; |
389 | PangoContext *context; |
390 | PangoFontDescription *desc, *desc2; |
391 | PangoFont *font; |
392 | |
393 | fontmap = pango_cairo_font_map_get_default (); |
394 | context = pango_font_map_create_context (fontmap); |
395 | |
396 | /* This is how pango_itemize creates the emoji font desc */ |
397 | desc = pango_font_description_from_string (str: "Cantarell 11" ); |
398 | pango_font_description_set_family_static (desc, family: "emoji" ); |
399 | |
400 | font = pango_context_load_font (context, desc); |
401 | desc2 = pango_font_describe (font); |
402 | |
403 | /* We can't expect the family name to match, since we go in with |
404 | * a generic family |
405 | */ |
406 | pango_font_description_unset_fields (desc, to_unset: PANGO_FONT_MASK_FAMILY); |
407 | pango_font_description_unset_fields (desc: desc2, to_unset: PANGO_FONT_MASK_FAMILY); |
408 | g_assert_true (pango_font_description_equal (desc2, desc)); |
409 | |
410 | pango_font_description_free (desc: desc2); |
411 | g_object_unref (object: font); |
412 | pango_font_description_free (desc); |
413 | g_object_unref (object: context); |
414 | } |
415 | |
416 | static void |
417 | test_font_models (void) |
418 | { |
419 | PangoFontMap *map = pango_cairo_font_map_get_default (); |
420 | gboolean monospace_found = FALSE; |
421 | int n_families = 0; |
422 | int n_variable_families = 0; |
423 | int n_monospace_families = 0; |
424 | |
425 | g_assert_true (g_list_model_get_item_type (G_LIST_MODEL (map)) == PANGO_TYPE_FONT_FAMILY); |
426 | |
427 | for (guint i = 0; i < g_list_model_get_n_items (list: G_LIST_MODEL (ptr: map)); i++) |
428 | { |
429 | GObject *obj = g_list_model_get_item (list: G_LIST_MODEL (ptr: map), position: i); |
430 | |
431 | g_assert_true (PANGO_IS_FONT_FAMILY (obj)); |
432 | |
433 | g_assert_true (g_list_model_get_item_type (G_LIST_MODEL (obj)) == PANGO_TYPE_FONT_FACE); |
434 | |
435 | if (g_ascii_strcasecmp (s1: pango_font_family_get_name (PANGO_FONT_FAMILY (obj)), s2: "monospace" ) == 0) |
436 | { |
437 | g_assert_true (pango_font_family_is_monospace (PANGO_FONT_FAMILY (obj))); |
438 | } |
439 | |
440 | n_families++; |
441 | |
442 | if (pango_font_family_is_variable (PANGO_FONT_FAMILY (obj))) |
443 | n_variable_families++; |
444 | |
445 | if (pango_font_family_is_monospace (PANGO_FONT_FAMILY (obj))) |
446 | n_monospace_families++; |
447 | |
448 | for (guint j = 0; j < g_list_model_get_n_items (list: G_LIST_MODEL (ptr: obj)); j++) |
449 | { |
450 | GObject *obj2 = g_list_model_get_item (list: G_LIST_MODEL (ptr: obj), position: j); |
451 | int *sizes; |
452 | int n_sizes; |
453 | |
454 | g_assert_true (PANGO_IS_FONT_FACE (obj2)); |
455 | |
456 | g_assert_true (pango_font_face_get_family (PANGO_FONT_FACE (obj2)) == (PangoFontFamily *)obj); |
457 | |
458 | pango_font_face_list_sizes (PANGO_FONT_FACE (obj2), sizes: &sizes, n_sizes: &n_sizes); |
459 | g_assert_true ((sizes == NULL) == (n_sizes == 0)); |
460 | g_free (mem: sizes); |
461 | |
462 | if (pango_font_family_is_monospace (PANGO_FONT_FAMILY (obj))) |
463 | { |
464 | if (pango_font_face_is_synthesized (PANGO_FONT_FACE (obj2))) |
465 | { |
466 | monospace_found = TRUE; |
467 | } |
468 | } |
469 | |
470 | g_object_unref (object: obj2); |
471 | } |
472 | |
473 | g_object_unref (object: obj); |
474 | } |
475 | |
476 | g_assert_true (monospace_found); |
477 | |
478 | g_print (format: "# %d font families, %d monospace, %d variable\n" , |
479 | n_families, n_monospace_families, n_variable_families); |
480 | } |
481 | |
482 | static void |
483 | test_glyph_extents (void) |
484 | { |
485 | PangoRectangle ink, logical; |
486 | |
487 | pango_font_get_glyph_extents (NULL, glyph: 0, ink_rect: &ink, logical_rect: &logical); |
488 | g_assert_cmpint (ink.height, ==, (PANGO_UNKNOWN_GLYPH_HEIGHT - 2) * PANGO_SCALE); |
489 | g_assert_cmpint (ink.width, ==, (PANGO_UNKNOWN_GLYPH_WIDTH - 2) * PANGO_SCALE); |
490 | g_assert_cmpint (logical.height, ==, PANGO_UNKNOWN_GLYPH_HEIGHT * PANGO_SCALE); |
491 | g_assert_cmpint (logical.width, ==, PANGO_UNKNOWN_GLYPH_WIDTH * PANGO_SCALE); |
492 | } |
493 | |
494 | static void |
495 | test_font_metrics (void) |
496 | { |
497 | PangoFontMetrics *metrics; |
498 | |
499 | metrics = pango_font_get_metrics (NULL, NULL); |
500 | |
501 | g_assert_cmpint (metrics->approximate_char_width, ==, PANGO_SCALE * PANGO_UNKNOWN_GLYPH_WIDTH); |
502 | g_assert_cmpint (metrics->approximate_digit_width, ==, PANGO_SCALE * PANGO_UNKNOWN_GLYPH_WIDTH); |
503 | |
504 | pango_font_metrics_unref (metrics); |
505 | } |
506 | |
507 | static void |
508 | test_to_filename (void) |
509 | { |
510 | PangoFontDescription *desc; |
511 | char *str; |
512 | |
513 | desc = pango_font_description_from_string (str: "Futura Medium Italic 14" ); |
514 | str = pango_font_description_to_filename (desc); |
515 | |
516 | g_assert_nonnull (strstr (str, "futura" )); |
517 | g_assert_nonnull (strstr (str, "medium" )); |
518 | g_assert_nonnull (strstr (str, "italic" )); |
519 | |
520 | g_free (mem: str); |
521 | |
522 | pango_font_description_free (desc); |
523 | } |
524 | |
525 | static void |
526 | test_set_gravity (void) |
527 | { |
528 | PangoFontDescription *desc; |
529 | |
530 | desc = pango_font_description_from_string (str: "Futura Medium Italic 14" ); |
531 | pango_font_description_set_gravity (desc, gravity: PANGO_GRAVITY_SOUTH); |
532 | g_assert_true (pango_font_description_get_set_fields (desc) & PANGO_FONT_MASK_GRAVITY); |
533 | |
534 | pango_font_description_set_gravity (desc, gravity: PANGO_GRAVITY_AUTO); |
535 | g_assert_false (pango_font_description_get_set_fields (desc) & PANGO_FONT_MASK_GRAVITY); |
536 | |
537 | pango_font_description_free (desc); |
538 | } |
539 | |
540 | static void |
541 | test_match (void) |
542 | { |
543 | PangoFontDescription *desc; |
544 | PangoFontDescription *desc1; |
545 | PangoFontDescription *desc2; |
546 | |
547 | desc = pango_font_description_from_string (str: "Futura Medium Italic 14" ); |
548 | desc1 = pango_font_description_from_string (str: "Futura Bold 16" ); |
549 | pango_font_description_set_style (desc: desc1, style: PANGO_STYLE_OBLIQUE); |
550 | desc2 = pango_font_description_from_string (str: "Futura Medium 16" ); |
551 | pango_font_description_set_style (desc: desc2, style: PANGO_STYLE_ITALIC); |
552 | |
553 | g_assert_true (pango_font_description_better_match (desc, desc1, desc2)); |
554 | |
555 | pango_font_description_free (desc); |
556 | pango_font_description_free (desc: desc1); |
557 | pango_font_description_free (desc: desc2); |
558 | } |
559 | |
560 | int |
561 | main (int argc, char *argv[]) |
562 | { |
563 | setlocale (LC_ALL, locale: "" ); |
564 | |
565 | g_test_init (argc: &argc, argv: &argv, NULL); |
566 | |
567 | context = pango_font_map_create_context (fontmap: pango_cairo_font_map_get_default ()); |
568 | |
569 | g_test_add_func (testpath: "/pango/font/metrics" , test_func: test_metrics); |
570 | g_test_add_func (testpath: "/pango/fontdescription/parse" , test_func: test_parse); |
571 | g_test_add_func (testpath: "/pango/fontdescription/roundtrip" , test_func: test_roundtrip); |
572 | g_test_add_func (testpath: "/pango/fontdescription/variations" , test_func: test_variations); |
573 | g_test_add_func (testpath: "/pango/fontdescription/empty-variations" , test_func: test_empty_variations); |
574 | g_test_add_func (testpath: "/pango/fontdescription/to-filename" , test_func: test_to_filename); |
575 | g_test_add_func (testpath: "/pango/fontdescription/set-gravity" , test_func: test_set_gravity); |
576 | g_test_add_func (testpath: "/pango/fontdescription/match" , test_func: test_match); |
577 | g_test_add_func (testpath: "/pango/font/extents" , test_func: test_extents); |
578 | g_test_add_func (testpath: "/pango/font/enumerate" , test_func: test_enumerate); |
579 | g_test_add_func (testpath: "/pango/font/roundtrip/plain" , test_func: test_roundtrip_plain); |
580 | g_test_add_func (testpath: "/pango/font/roundtrip/small-caps" , test_func: test_roundtrip_small_caps); |
581 | g_test_add_func (testpath: "/pango/font/roundtrip/emoji" , test_func: test_roundtrip_emoji); |
582 | g_test_add_func (testpath: "/pango/font/models" , test_func: test_font_models); |
583 | g_test_add_func (testpath: "/pango/font/glyph-extents" , test_func: test_glyph_extents); |
584 | g_test_add_func (testpath: "/pango/font/font-metrics" , test_func: test_font_metrics); |
585 | |
586 | return g_test_run (); |
587 | } |
588 | |