Libcroco
cr-fonts.c
Go to the documentation of this file.
1 /* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
2 
3 /*
4  * This file is part of The Croco Library
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of version 2.1 of
9  * the GNU Lesser General Public
10  * License as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the
18  * GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  * USA
22  *
23  *See COPYRIGHTS file for copyright information
24  */
25 
26 #include "cr-fonts.h"
27 #include <string.h>
28 
29 static enum CRStatus
30 cr_font_family_to_string_real (CRFontFamily const * a_this,
31  gboolean a_walk_list, GString ** a_string)
32 {
33  guchar const *name = NULL;
34  enum CRStatus result = CR_OK;
35 
36  if (!*a_string) {
37  *a_string = g_string_new (NULL);
38  g_return_val_if_fail (*a_string,
40  }
41 
42  if (!a_this) {
43  g_string_append (*a_string, "NULL");
44  return CR_OK;
45  }
46 
47  switch (a_this->type) {
49  name = (guchar const *) "sans-serif";
50  break;
51 
52  case FONT_FAMILY_SERIF:
53  name = (guchar const *) "sans-serif";
54  break;
55 
57  name = (guchar const *) "cursive";
58  break;
59 
61  name = (guchar const *) "fantasy";
62  break;
63 
65  name = (guchar const *) "monospace";
66  break;
67 
69  name = (guchar const *) a_this->name;
70  break;
71 
72  default:
73  name = NULL;
74  break;
75  }
76 
77  if (name) {
78  if (a_this->prev) {
79  g_string_append_printf (*a_string, ", %s", name);
80  } else {
81  g_string_append (*a_string, (const gchar *) name);
82  }
83  }
84  if (a_walk_list == TRUE && a_this->next) {
85  result = cr_font_family_to_string_real (a_this->next,
86  TRUE, a_string);
87  }
88  return result;
89 }
90 
91 static const gchar *
92 cr_predefined_absolute_font_size_to_string (enum CRPredefinedAbsoluteFontSize
93  a_code)
94 {
95  gchar const *str = NULL;
96 
97  switch (a_code) {
98  case FONT_SIZE_XX_SMALL:
99  str = "xx-small";
100  break;
101  case FONT_SIZE_X_SMALL:
102  str = "x-small";
103  break;
104  case FONT_SIZE_SMALL:
105  str = "small";
106  break;
107  case FONT_SIZE_MEDIUM:
108  str = "medium";
109  break;
110  case FONT_SIZE_LARGE:
111  str = "large";
112  break;
113  case FONT_SIZE_X_LARGE:
114  str = "x-large";
115  break;
116  case FONT_SIZE_XX_LARGE:
117  str = "xx-large";
118  break;
119  default:
120  str = "unknown absolute font size value";
121  }
122  return str;
123 }
124 
125 static const gchar *
126 cr_relative_font_size_to_string (enum CRRelativeFontSize a_code)
127 {
128  gchar const *str = NULL;
129 
130  switch (a_code) {
131  case FONT_SIZE_LARGER:
132  str = "larger";
133  break;
134  case FONT_SIZE_SMALLER:
135  str = "smaller";
136  break;
137  default:
138  str = "unknown relative font size value";
139  break;
140  }
141  return str;
142 }
143 
144 /**
145  * cr_font_family_new:
146  * @a_type: the type of font family to create.
147  * @a_name: the name of the font family.
148  *
149  * create a font family.
150  *
151  * Returns the newly built font family.
152  */
153 CRFontFamily *
154 cr_font_family_new (enum CRFontFamilyType a_type, guchar * a_name)
155 {
156  CRFontFamily *result = NULL;
157 
158  result = g_try_malloc (sizeof (CRFontFamily));
159 
160  if (!result) {
161  cr_utils_trace_info ("Out of memory");
162  return NULL;
163  }
164 
165  memset (result, 0, sizeof (CRFontFamily));
166  result->type = a_type;
167 
168  cr_font_family_set_name (result, a_name);
169 
170  return result;
171 }
172 
173 /**
174  * cr_font_family_to_string:
175  * @a_this: the current instance of #CRFontFamily.
176  * @a_walk_font_family_list: wether the serialize the entire list.
177  *
178  * Returns the seriliazed font family. The caller has to free it using
179  * g_free().
180  */
181 guchar *
183  gboolean a_walk_font_family_list)
184 {
185  enum CRStatus status = CR_OK;
186  guchar *result = NULL;
187  GString *stringue = NULL;
188 
189  if (!a_this) {
190  result = (guchar *) g_strdup ("NULL");
191  g_return_val_if_fail (result, NULL);
192  return result;
193  }
194  status = cr_font_family_to_string_real (a_this,
195  a_walk_font_family_list,
196  &stringue);
197 
198  if (status == CR_OK && stringue) {
199  result = (guchar *) stringue->str;
200  g_string_free (stringue, FALSE);
201  stringue = NULL;
202 
203  } else {
204  if (stringue) {
205  g_string_free (stringue, TRUE);
206  stringue = NULL;
207  }
208  }
209 
210  return result;
211 }
212 
213 /**
214  * cr_font_family_set_name:
215  * @a_this: the current instance of #CRFontFamily.
216  * @a_name: the new name
217  *
218  * Returns CR_OK upon sucessful completion, an error code otherwise.
219  */
220 enum CRStatus
221 cr_font_family_set_name (CRFontFamily * a_this, guchar * a_name)
222 {
223  g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
224 
225  /*
226  *only non generic font families can have a name
227  */
228 
229  if (a_this->type != FONT_FAMILY_NON_GENERIC) {
230  return CR_BAD_PARAM_ERROR;
231  }
232 
233  if (a_this->name) {
234  g_free (a_this->name);
235  a_this->name = NULL;
236  }
237 
238  a_this->name = a_name;
239  return CR_OK;
240 }
241 
242 /**
243  * cr_font_family_append:
244  * @a_this: the current instance of #CRFontFamily.
245  * @a_family_to_append: the font family to append to the list
246  *
247  * Returns the new font family list.
248  */
249 CRFontFamily *
251  CRFontFamily * a_family_to_append)
252 {
253  CRFontFamily *cur_ff = NULL;
254 
255  g_return_val_if_fail (a_family_to_append, NULL);
256 
257  if (!a_this)
258  return a_family_to_append;
259 
260  for (cur_ff = a_this; cur_ff && cur_ff->next; cur_ff = cur_ff->next) ;
261 
262  cur_ff->next = a_family_to_append;
263  a_family_to_append->prev = cur_ff;
264 
265  return a_this;
266 
267 }
268 
269 /**
270  * cr_font_family_prepend:
271  * @a_this: the current instance #CRFontFamily.
272  * @a_family_to_prepend: the font family to prepend to the list.
273  *
274  * Returns the font family list.
275  */
276 CRFontFamily *
278  CRFontFamily * a_family_to_prepend)
279 {
280  g_return_val_if_fail (a_this && a_family_to_prepend, NULL);
281 
282  if (!a_this)
283  return a_family_to_prepend;
284 
285  a_family_to_prepend->next = a_this;
286  a_this->prev = a_family_to_prepend;
287 
288  return a_family_to_prepend;
289 }
290 
291 /**
292  * cr_font_family_destroy:
293  * @a_this: the current instance of #CRFontFamily.
294  *
295  * Returns CR_OK upon sucessful completion, an error code otherwise.
296  */
297 enum CRStatus
299 {
300  CRFontFamily *cur_ff = NULL;
301 
302  g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
303 
304  for (cur_ff = a_this; cur_ff && cur_ff->next; cur_ff = cur_ff->next) ;
305 
306  for (; cur_ff; cur_ff = cur_ff->prev) {
307  if (a_this->name) {
308  g_free (a_this->name);
309  a_this->name = NULL;
310  }
311 
312  if (cur_ff->next) {
313  g_free (cur_ff->next);
314 
315  }
316 
317  if (cur_ff->prev == NULL) {
318  g_free (a_this);
319  }
320  }
321 
322  return CR_OK;
323 }
324 
325 /***************************************************
326  *'font-size' manipulation functions definitions
327  ***************************************************/
328 
329 /**
330  * cr_font_size_new:
331  *
332  * Returns the newly created font size.
333  */
334 CRFontSize *
336 {
337  CRFontSize *result = NULL;
338 
339  result = g_try_malloc (sizeof (CRFontSize));
340  if (!result) {
341  cr_utils_trace_info ("Out of memory");
342  return NULL;
343  }
344  memset (result, 0, sizeof (CRFontSize));
345 
346  return result;
347 }
348 
349 /**
350  * cr_font_size_clear:
351  * @a_this: the current instance of #CRFontSize
352  *
353  * Returns CR_OK upon successful completion, an error code otherwise.
354  */
355 enum CRStatus
357 {
358  g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
359 
360  switch (a_this->type) {
362  case RELATIVE_FONT_SIZE:
363  case INHERITED_FONT_SIZE:
364  memset (a_this, 0, sizeof (CRFontSize));
365  break;
366 
367  case ABSOLUTE_FONT_SIZE:
368  memset (a_this, 0, sizeof (CRFontSize));
369  break;
370 
371  default:
372  return CR_UNKNOWN_TYPE_ERROR;
373  }
374 
375  return CR_OK;
376 }
377 
378 /**
379  * cr_font_size_copy:
380  * @a_dst: the destination #CRFontSize (where to copy to).
381  * @a_src: the source #CRFontSize (where to copy from).
382  *
383  * Returns CR_OK upon successful completion, an error code otherwise.
384  */
385 enum CRStatus
386 cr_font_size_copy (CRFontSize * a_dst, CRFontSize const * a_src)
387 {
388  g_return_val_if_fail (a_dst && a_src, CR_BAD_PARAM_ERROR);
389 
390  switch (a_src->type) {
392  case RELATIVE_FONT_SIZE:
393  case INHERITED_FONT_SIZE:
394  cr_font_size_clear (a_dst);
395  memcpy (a_dst, a_src, sizeof (CRFontSize));
396  break;
397 
398  case ABSOLUTE_FONT_SIZE:
399  cr_font_size_clear (a_dst);
400  cr_num_copy (&a_dst->value.absolute,
401  &a_src->value.absolute);
402  a_dst->type = a_src->type;
403  break;
404 
405  default:
406  return CR_UNKNOWN_TYPE_ERROR;
407  }
408  return CR_OK;
409 }
410 
411 /**
412  * cr_font_size_set_predefined_absolute_font_size:
413  * @a_this: the current instance of #CRFontSize.
414  * @a_predefined: what to set.
415  *
416  * Returns CR_OK upon sucessful completion, an error code otherwise.
417  */
418 enum CRStatus
420  enum CRPredefinedAbsoluteFontSize a_predefined)
421 {
422  g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
423  g_return_val_if_fail (a_predefined >= FONT_SIZE_XX_SMALL
424  && a_predefined < NB_PREDEFINED_ABSOLUTE_FONT_SIZES,
426 
428  a_this->value.predefined = a_predefined ;
429 
430  return CR_OK ;
431 }
432 
433 /**
434  * cr_font_size_set_relative_font_size:
435  * @a_this: the current instance of #CRFontSize
436  * @a_relative: the new relative font size
437  *
438  * Returns CR_OK upon successful completion, an error code otherwise.
439  */
440 enum CRStatus
442  enum CRRelativeFontSize a_relative)
443 {
444  g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
445  g_return_val_if_fail (a_relative >= FONT_SIZE_LARGER
446  && a_relative < NB_RELATIVE_FONT_SIZE,
448 
449  a_this->type = RELATIVE_FONT_SIZE ;
450  a_this->value.relative = a_relative ;
451  return CR_OK ;
452 }
453 
454 /**
455  * cr_font_size_set_absolute_font_size:
456  * @a_this: the current instance of #CRFontSize
457  * @a_num_type: the type of number to set.
458  * @a_value: the actual value to set.
459  *
460  * Returns CR_OK upon succesful completion, an error code otherwise.
461  */
462 enum CRStatus
464  enum CRNumType a_num_type,
465  gdouble a_value)
466 {
467  g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
468  g_return_val_if_fail (a_num_type >= NUM_AUTO
469  && a_num_type < NB_NUM_TYPE,
471 
472  a_this->type = ABSOLUTE_FONT_SIZE ;
473  cr_num_set (&a_this->value.absolute,
474  a_value, a_num_type) ;
475  return CR_OK ;
476 }
477 
478 /**
479  * cr_font_size_set_to_inherit:
480  * @a_this: the current instance of #CRFontSize
481  *
482  * Returns CR_OK upon succesful completion, an error code otherwise.
483  */
484 enum CRStatus
486 {
487  g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
488 
489  cr_font_size_clear (a_this) ;
490  a_this->type = INHERITED_FONT_SIZE ;
491 
492  return CR_OK ;
493 }
494 
495 /**
496  * cr_font_size_is_set_to_inherit:
497  * @a_this: the current instance of #CRFontSize.
498  *
499  * Returns TRUE if the current instance is set to 'inherit'.
500  */
501 gboolean
503 {
504  g_return_val_if_fail (a_this, FALSE) ;
505 
506  return a_this->type == INHERITED_FONT_SIZE ;
507 }
508 
509 /**
510  * cr_font_size_to_string:
511  * @a_this: the current instance of #CRFontSize
512  *
513  * Returns the serialized form of #CRFontSize. The returned string
514  * has to bee freed using g_free().
515  */
516 gchar *
518 {
519  gchar *str = NULL;
520 
521  if (!a_this) {
522  str = g_strdup ("NULL");
523  g_return_val_if_fail (str, NULL);
524  return str;
525  }
526  switch (a_this->type) {
528  str = g_strdup (cr_predefined_absolute_font_size_to_string
529  (a_this->value.predefined));
530  break;
531  case ABSOLUTE_FONT_SIZE:
532  str = (gchar *) cr_num_to_string (&a_this->value.absolute);
533  break;
534  case RELATIVE_FONT_SIZE:
535  str = g_strdup (cr_relative_font_size_to_string
536  (a_this->value.relative));
537  break;
538  case INHERITED_FONT_SIZE:
539  str = g_strdup ("inherit");
540  break;
541  default:
542  break;
543  }
544  return str;
545 }
546 
547 /**
548  * cr_font_size_get_smaller_predefined:
549  * @a_font_size: the font size to consider.
550  * @a_smaller_size: out parameter. The a smaller value than @a_font_size.
551  */
552 void
554  (enum CRPredefinedAbsoluteFontSize a_font_size,
555  enum CRPredefinedAbsoluteFontSize *a_smaller_size)
556 {
558 
559  g_return_if_fail (a_smaller_size) ;
560  g_return_if_fail (a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES
561  && a_font_size >= FONT_SIZE_XX_SMALL) ;
562 
563  switch (a_font_size) {
564  case FONT_SIZE_XX_SMALL:
565  result = FONT_SIZE_XX_SMALL ;
566  break ;
567  case FONT_SIZE_X_SMALL:
568  result = FONT_SIZE_XX_SMALL ;
569  break ;
570  case FONT_SIZE_SMALL:
571  result = FONT_SIZE_X_SMALL;
572  break ;
573  case FONT_SIZE_MEDIUM:
574  result = FONT_SIZE_SMALL;
575  break ;
576  case FONT_SIZE_LARGE:
577  result = FONT_SIZE_MEDIUM;
578  break ;
579  case FONT_SIZE_X_LARGE:
580  result = FONT_SIZE_LARGE;
581  break ;
582  case FONT_SIZE_XX_LARGE:
583  result = FONT_SIZE_XX_LARGE;
584  break ;
585  case FONT_SIZE_INHERIT:
586  cr_utils_trace_info ("can't return a smaller size for FONT_SIZE_INHERIT") ;
587  result = FONT_SIZE_MEDIUM ;
588  break ;
589  default:
590  cr_utils_trace_info ("Unknown FONT_SIZE") ;
591  result = FONT_SIZE_MEDIUM ;
592  break ;
593  }
594  *a_smaller_size = result ;
595 }
596 
597 
598 /**
599  * cr_font_size_get_larger_predefined_font_size:
600  * @a_font_size: the font size to consider.
601  * @a_larger_size: out parameter. the font size considered larger than
602  * @a_font_size.
603  *
604  */
605 void
607  (enum CRPredefinedAbsoluteFontSize a_font_size,
608  enum CRPredefinedAbsoluteFontSize *a_larger_size)
609 {
611 
612  g_return_if_fail (a_larger_size) ;
613  g_return_if_fail (a_font_size >= FONT_SIZE_XX_SMALL
614  && a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES) ;
615 
616  switch (a_font_size) {
617  case FONT_SIZE_XX_SMALL:
618  result = FONT_SIZE_X_SMALL ;
619  break ;
620  case FONT_SIZE_X_SMALL:
621  result = FONT_SIZE_SMALL ;
622  break ;
623  case FONT_SIZE_SMALL:
624  result = FONT_SIZE_MEDIUM;
625  break ;
626  case FONT_SIZE_MEDIUM:
627  result = FONT_SIZE_LARGE;
628  break ;
629  case FONT_SIZE_LARGE:
630  result = FONT_SIZE_X_LARGE;
631  break ;
632  case FONT_SIZE_X_LARGE:
633  result = FONT_SIZE_XX_LARGE ;
634  break ;
635  case FONT_SIZE_XX_LARGE:
636  result = FONT_SIZE_XX_LARGE;
637  break ;
638  case FONT_SIZE_INHERIT:
639  cr_utils_trace_info ("can't return a bigger size for FONT_SIZE_INHERIT") ;
640  result = FONT_SIZE_MEDIUM ;
641  break ;
642  default:
643  cr_utils_trace_info ("Unknown FONT_SIZE") ;
644  result = FONT_SIZE_MEDIUM ;
645  break ;
646  }
647  *a_larger_size = result ;
648 }
649 
650 /**
651  * cr_font_size_is_predefined_absolute_font_size:
652  * @a_font_size: the font size to consider.
653  *
654  * Returns TRUE if the instance is an predefined absolute font size, FALSE
655  * otherwise.
656  */
657 gboolean
659  (enum CRPredefinedAbsoluteFontSize a_font_size)
660 {
661  if (a_font_size >= FONT_SIZE_XX_SMALL
662  && a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES) {
663  return TRUE ;
664  } else {
665  return FALSE ;
666  }
667 }
668 
669 /**
670  * cr_font_size_adjust_to_string:
671  * @a_this: the instance of #CRFontSizeAdjust.
672  *
673  * Returns the serialized form of #CRFontSizeAdjust
674  */
675 gchar *
677 {
678  gchar *str = NULL;
679 
680  if (!a_this) {
681  str = g_strdup ("NULL");
682  g_return_val_if_fail (str, NULL);
683  return str;
684  }
685 
686  switch (a_this->type) {
688  str = g_strdup ("none");
689  break;
691  if (a_this->num)
692  str = (gchar *) cr_num_to_string (a_this->num);
693  else
694  str = g_strdup ("unknown font-size-adjust property value"); /* Should raise an error no?*/
695  break;
697  str = g_strdup ("inherit");
698  }
699  return str;
700 }
701 
702 /**
703  * cr_font_style_to_string:
704  * @a_code: the current instance of #CRFontStyle .
705  *
706  * Returns the serialized #CRFontStyle. The caller must free the returned
707  * string using g_free().
708  */
709 const gchar *
711 {
712  gchar *str = NULL;
713 
714  switch (a_code) {
715  case FONT_STYLE_NORMAL:
716  str = (gchar *) "normal";
717  break;
718  case FONT_STYLE_ITALIC:
719  str = (gchar *) "italic";
720  break;
721  case FONT_STYLE_OBLIQUE:
722  str = (gchar *) "oblique";
723  break;
724  case FONT_STYLE_INHERIT:
725  str = (gchar *) "inherit";
726  break;
727  default:
728  str = (gchar *) "unknown font style value";
729  break;
730  }
731  return str;
732 }
733 
734 /**
735  * cr_font_variant_to_string:
736  * @a_code: the current instance of #CRFontVariant.
737  *
738  * Returns the serialized form of #CRFontVariant. The caller has
739  * to free the returned string using g_free().
740  */
741 const gchar *
743 {
744  gchar *str = NULL;
745 
746  switch (a_code) {
747  case FONT_VARIANT_NORMAL:
748  str = (gchar *) "normal";
749  break;
751  str = (gchar *) "small-caps";
752  break;
754  str = (gchar *) "inherit";
755  break;
756  }
757  return str;
758 }
759 
760 /**
761  * cr_font_weight_get_bolder:
762  * @a_weight: the #CRFontWeight to consider.
763  *
764  * Returns a font weight bolder than @a_weight
765  */
766 enum CRFontWeight
768 {
769  if (a_weight == FONT_WEIGHT_INHERIT) {
770  cr_utils_trace_info ("can't return a bolder weight for FONT_WEIGHT_INHERIT") ;
771  return a_weight;
772  } else if (a_weight >= FONT_WEIGHT_900) {
773  return FONT_WEIGHT_900 ;
774  } else if (a_weight < FONT_WEIGHT_NORMAL) {
775  return FONT_WEIGHT_NORMAL ;
776  } else if (a_weight == FONT_WEIGHT_BOLDER
777  || a_weight == FONT_WEIGHT_LIGHTER) {
778  cr_utils_trace_info ("FONT_WEIGHT_BOLDER or FONT_WEIGHT_LIGHTER should not appear here") ;
779  return FONT_WEIGHT_NORMAL ;
780  } else {
781  return a_weight << 1 ;
782  }
783 }
784 
785 /**
786  * cr_font_weight_to_string:
787  * @a_code: the font weight to consider.
788  *
789  * Returns the serialized form of #CRFontWeight.
790  */
791 const gchar *
793 {
794  gchar *str = NULL;
795 
796  switch (a_code) {
797  case FONT_WEIGHT_NORMAL:
798  str = (gchar *) "normal";
799  break;
800  case FONT_WEIGHT_BOLD:
801  str = (gchar *) "bold";
802  break;
803  case FONT_WEIGHT_BOLDER:
804  str = (gchar *) "bolder";
805  break;
806  case FONT_WEIGHT_LIGHTER:
807  str = (gchar *) "lighter";
808  break;
809  case FONT_WEIGHT_100:
810  str = (gchar *) "100";
811  break;
812  case FONT_WEIGHT_200:
813  str = (gchar *) "200";
814  break;
815  case FONT_WEIGHT_300:
816  str = (gchar *) "300";
817  break;
818  case FONT_WEIGHT_400:
819  str = (gchar *) "400";
820  break;
821  case FONT_WEIGHT_500:
822  str = (gchar *) "500";
823  break;
824  case FONT_WEIGHT_600:
825  str = (gchar *) "600";
826  break;
827  case FONT_WEIGHT_700:
828  str = (gchar *) "700";
829  break;
830  case FONT_WEIGHT_800:
831  str = (gchar *) "800";
832  break;
833  case FONT_WEIGHT_900:
834  str = (gchar *) "900";
835  break;
836  case FONT_WEIGHT_INHERIT:
837  str = (gchar *) "inherit";
838  break;
839  default:
840  str = (gchar *) "unknown font-weight property value";
841  break;
842  }
843  return str;
844 }
845 
846 /**
847  * cr_font_stretch_to_string:
848  * @a_code: the instance of #CRFontStretch to consider.
849  *
850  * Returns the serialized form of #CRFontStretch.
851  */
852 const gchar *
854 {
855  gchar *str = NULL;
856 
857  switch (a_code) {
858  case FONT_STRETCH_NORMAL:
859  str = (gchar *) "normal";
860  break;
861  case FONT_STRETCH_WIDER:
862  str = (gchar *) "wider";
863  break;
865  str = (gchar *) "narrower";
866  break;
868  str = (gchar *) "ultra-condensed";
869  break;
871  str = (gchar *) "extra-condensed";
872  break;
874  str = (gchar *) "condensed";
875  break;
877  str = (gchar *) "semi-condensed";
878  break;
880  str = (gchar *) "semi-expanded";
881  break;
883  str = (gchar *) "expanded";
884  break;
886  str = (gchar *) "extra-expaned";
887  break;
889  str = (gchar *) "ultra-expanded";
890  break;
892  str = (gchar *) "inherit";
893  break;
894  }
895  return str;
896 }
897 
898 /**
899  * cr_font_size_destroy:
900  * @a_font_size: the font size to destroy
901  *
902  */
903 void
905 {
906  g_return_if_fail (a_font_size);
907 
908  g_free (a_font_size) ;
909 }
910 
911 /*******************************************************
912  *'font-size-adjust' manipulation function definition
913  *******************************************************/
914 
915 /**
916  * cr_font_size_adjust_new:
917  *
918  * Returns a newly built instance of #CRFontSizeAdjust
919  */
922 {
923  CRFontSizeAdjust *result = NULL;
924 
925  result = g_try_malloc (sizeof (CRFontSizeAdjust));
926  if (!result) {
927  cr_utils_trace_info ("Out of memory");
928  return NULL;
929  }
930  memset (result, 0, sizeof (CRFontSizeAdjust));
931 
932  return result;
933 }
934 
935 /**
936  * cr_font_size_adjust_destroy:
937  * @a_this: the current instance of #CRFontSizeAdjust.
938  *
939  */
940 void
942 {
943  g_return_if_fail (a_this);
944 
945  if (a_this->type == FONT_SIZE_ADJUST_NUMBER && a_this->num) {
946  cr_num_destroy (a_this->num);
947  a_this->num = NULL;
948  }
949 }
FONT_FAMILY_SANS_SERIF
@ FONT_FAMILY_SANS_SERIF
Definition: cr-fonts.h:42
FONT_SIZE_X_LARGE
@ FONT_SIZE_X_LARGE
Definition: cr-fonts.h:89
_CRFontSize::type
enum CRFontSizeType type
Definition: cr-fonts.h:156
FONT_FAMILY_CURSIVE
@ FONT_FAMILY_CURSIVE
Definition: cr-fonts.h:44
FONT_SIZE_SMALLER
@ FONT_SIZE_SMALLER
Definition: cr-fonts.h:109
CRPredefinedAbsoluteFontSize
CRPredefinedAbsoluteFontSize
The different types of absolute font size.
Definition: cr-fonts.h:82
FONT_WEIGHT_BOLD
@ FONT_WEIGHT_BOLD
Definition: cr-fonts.h:195
FONT_STRETCH_NORMAL
@ FONT_STRETCH_NORMAL
Definition: cr-fonts.h:213
PREDEFINED_ABSOLUTE_FONT_SIZE
@ PREDEFINED_ABSOLUTE_FONT_SIZE
If the type of CRFontSize is PREDEFINED_ABSOLUTE_FONT_SIZE, the CRFontSize::value....
Definition: cr-fonts.h:125
cr_num_set
enum CRStatus cr_num_set(CRNum *a_this, gdouble a_val, enum CRNumType a_type)
cr_num_set: Sets an instance of CRNum.
Definition: cr-num.c:264
FONT_WEIGHT_400
@ FONT_WEIGHT_400
Definition: cr-fonts.h:201
CRFontFamilyType
CRFontFamilyType
Definition: cr-fonts.h:40
INHERITED_FONT_SIZE
@ INHERITED_FONT_SIZE
If the type of CRFontSize is INHERITED_FONT_SIZE, the None of the field of the CRFontSize::value enum...
Definition: cr-fonts.h:149
FONT_WEIGHT_200
@ FONT_WEIGHT_200
Definition: cr-fonts.h:199
_CRFontFamily::prev
CRFontFamily * prev
Definition: cr-fonts.h:67
cr_font_size_new
CRFontSize * cr_font_size_new(void)
cr_font_size_new:
Definition: cr-fonts.c:335
FONT_VARIANT_INHERIT
@ FONT_VARIANT_INHERIT
Definition: cr-fonts.h:189
_CRFontSize::absolute
CRNum absolute
Definition: cr-fonts.h:160
cr_num_to_string
guchar * cr_num_to_string(CRNum const *a_this)
cr_num_to_string: @a_this: the current instance of CRNum.
Definition: cr-num.c:95
cr-fonts.h
FONT_WEIGHT_700
@ FONT_WEIGHT_700
Definition: cr-fonts.h:204
CR_INSTANCIATION_FAILED_ERROR
@ CR_INSTANCIATION_FAILED_ERROR
Definition: cr-utils.h:46
_CRFontSizeAdjust::num
CRNum * num
Definition: cr-fonts.h:174
cr_font_variant_to_string
const gchar * cr_font_variant_to_string(enum CRFontVariant a_code)
cr_font_variant_to_string: @a_code: the current instance of CRFontVariant.
Definition: cr-fonts.c:742
FONT_SIZE_ADJUST_NONE
@ FONT_SIZE_ADJUST_NONE
Definition: cr-fonts.h:166
cr_font_size_get_smaller_predefined_font_size
void cr_font_size_get_smaller_predefined_font_size(enum CRPredefinedAbsoluteFontSize a_font_size, enum CRPredefinedAbsoluteFontSize *a_smaller_size)
cr_font_size_get_smaller_predefined: @a_font_size: the font size to consider.
Definition: cr-fonts.c:554
FONT_STRETCH_ULTRA_CONDENSED
@ FONT_STRETCH_ULTRA_CONDENSED
Definition: cr-fonts.h:216
FONT_SIZE_INHERIT
@ FONT_SIZE_INHERIT
Definition: cr-fonts.h:91
CR_BAD_PARAM_ERROR
@ CR_BAD_PARAM_ERROR
Definition: cr-utils.h:45
FONT_WEIGHT_NORMAL
@ FONT_WEIGHT_NORMAL
Definition: cr-fonts.h:194
cr_font_weight_to_string
const gchar * cr_font_weight_to_string(enum CRFontWeight a_code)
cr_font_weight_to_string: @a_code: the font weight to consider.
Definition: cr-fonts.c:792
FONT_FAMILY_MONOSPACE
@ FONT_FAMILY_MONOSPACE
Definition: cr-fonts.h:46
FONT_VARIANT_NORMAL
@ FONT_VARIANT_NORMAL
Definition: cr-fonts.h:187
FONT_FAMILY_FANTASY
@ FONT_FAMILY_FANTASY
Definition: cr-fonts.h:45
FONT_WEIGHT_100
@ FONT_WEIGHT_100
Definition: cr-fonts.h:198
FONT_STYLE_OBLIQUE
@ FONT_STYLE_OBLIQUE
Definition: cr-fonts.h:181
cr_font_family_new
CRFontFamily * cr_font_family_new(enum CRFontFamilyType a_type, guchar *a_name)
cr_font_family_new: @a_type: the type of font family to create.
Definition: cr-fonts.c:154
NB_PREDEFINED_ABSOLUTE_FONT_SIZES
@ NB_PREDEFINED_ABSOLUTE_FONT_SIZES
Definition: cr-fonts.h:92
CR_UNKNOWN_TYPE_ERROR
@ CR_UNKNOWN_TYPE_ERROR
Definition: cr-utils.h:47
FONT_WEIGHT_300
@ FONT_WEIGHT_300
Definition: cr-fonts.h:200
FONT_STRETCH_EXTRA_CONDENSED
@ FONT_STRETCH_EXTRA_CONDENSED
Definition: cr-fonts.h:217
cr_font_size_is_set_to_inherit
gboolean cr_font_size_is_set_to_inherit(CRFontSize const *a_this)
cr_font_size_is_set_to_inherit: @a_this: the current instance of CRFontSize.
Definition: cr-fonts.c:502
FONT_SIZE_XX_LARGE
@ FONT_SIZE_XX_LARGE
Definition: cr-fonts.h:90
CRFontWeight
CRFontWeight
Definition: cr-fonts.h:192
FONT_WEIGHT_INHERIT
@ FONT_WEIGHT_INHERIT
Definition: cr-fonts.h:207
FONT_SIZE_ADJUST_NUMBER
@ FONT_SIZE_ADJUST_NUMBER
Definition: cr-fonts.h:167
NUM_AUTO
@ NUM_AUTO
Definition: cr-num.h:56
cr_font_family_append
CRFontFamily * cr_font_family_append(CRFontFamily *a_this, CRFontFamily *a_family_to_append)
cr_font_family_append: @a_this: the current instance of CRFontFamily.
Definition: cr-fonts.c:250
FONT_STRETCH_WIDER
@ FONT_STRETCH_WIDER
Definition: cr-fonts.h:214
FONT_STYLE_NORMAL
@ FONT_STYLE_NORMAL
Definition: cr-fonts.h:179
CR_OK
@ CR_OK
Definition: cr-utils.h:44
cr_font_size_clear
enum CRStatus cr_font_size_clear(CRFontSize *a_this)
cr_font_size_clear: @a_this: the current instance of CRFontSize
Definition: cr-fonts.c:356
_CRFontFamily::type
enum CRFontFamilyType type
Definition: cr-fonts.h:57
cr_num_copy
enum CRStatus cr_num_copy(CRNum *a_dest, CRNum const *a_src)
cr_num_copy: @a_src: the instance of CRNum to copy.
Definition: cr-num.c:218
cr_font_size_destroy
void cr_font_size_destroy(CRFontSize *a_font_size)
cr_font_size_destroy: @a_font_size: the font size to destroy
Definition: cr-fonts.c:904
FONT_STRETCH_EXTRA_EXPANDED
@ FONT_STRETCH_EXTRA_EXPANDED
Definition: cr-fonts.h:222
cr_font_style_to_string
const gchar * cr_font_style_to_string(enum CRFontStyle a_code)
cr_font_style_to_string: @a_code: the current instance of CRFontStyle .
Definition: cr-fonts.c:710
cr_num_destroy
void cr_num_destroy(CRNum *a_this)
cr_num_destroy: @a_this: the this pointer of the current instance of CRNum.
Definition: cr-num.c:308
_CRFontFamily::next
CRFontFamily * next
Definition: cr-fonts.h:66
CRFontStretch
CRFontStretch
Definition: cr-fonts.h:211
FONT_WEIGHT_900
@ FONT_WEIGHT_900
Definition: cr-fonts.h:206
FONT_STYLE_INHERIT
@ FONT_STYLE_INHERIT
Definition: cr-fonts.h:182
FONT_STRETCH_NARROWER
@ FONT_STRETCH_NARROWER
Definition: cr-fonts.h:215
CRFontVariant
CRFontVariant
Definition: cr-fonts.h:185
NB_NUM_TYPE
@ NB_NUM_TYPE
Definition: cr-num.h:76
cr_font_size_copy
enum CRStatus cr_font_size_copy(CRFontSize *a_dst, CRFontSize const *a_src)
cr_font_size_copy: @a_dst: the destination CRFontSize (where to copy to).
Definition: cr-fonts.c:386
FONT_STRETCH_EXPANDED
@ FONT_STRETCH_EXPANDED
Definition: cr-fonts.h:221
FONT_WEIGHT_BOLDER
@ FONT_WEIGHT_BOLDER
Definition: cr-fonts.h:196
FONT_SIZE_LARGER
@ FONT_SIZE_LARGER
Definition: cr-fonts.h:108
_CRFontSize::value
union _CRFontSize::@0 value
cr_font_family_to_string
guchar * cr_font_family_to_string(CRFontFamily const *a_this, gboolean a_walk_font_family_list)
cr_font_family_to_string: @a_this: the current instance of CRFontFamily.
Definition: cr-fonts.c:182
cr_font_size_set_predefined_absolute_font_size
enum CRStatus cr_font_size_set_predefined_absolute_font_size(CRFontSize *a_this, enum CRPredefinedAbsoluteFontSize a_predefined)
cr_font_size_set_predefined_absolute_font_size: @a_this: the current instance of CRFontSize.
Definition: cr-fonts.c:419
FONT_STRETCH_SEMI_CONDENSED
@ FONT_STRETCH_SEMI_CONDENSED
Definition: cr-fonts.h:219
NB_RELATIVE_FONT_SIZE
@ NB_RELATIVE_FONT_SIZE
Definition: cr-fonts.h:110
FONT_STRETCH_SEMI_EXPANDED
@ FONT_STRETCH_SEMI_EXPANDED
Definition: cr-fonts.h:220
cr_font_family_destroy
enum CRStatus cr_font_family_destroy(CRFontFamily *a_this)
cr_font_family_destroy: @a_this: the current instance of CRFontFamily.
Definition: cr-fonts.c:298
cr_font_size_get_larger_predefined_font_size
void cr_font_size_get_larger_predefined_font_size(enum CRPredefinedAbsoluteFontSize a_font_size, enum CRPredefinedAbsoluteFontSize *a_larger_size)
cr_font_size_get_larger_predefined_font_size: @a_font_size: the font size to consider.
Definition: cr-fonts.c:607
cr_font_size_set_relative_font_size
enum CRStatus cr_font_size_set_relative_font_size(CRFontSize *a_this, enum CRRelativeFontSize a_relative)
cr_font_size_set_relative_font_size: @a_this: the current instance of CRFontSize @a_relative: the new...
Definition: cr-fonts.c:441
cr_font_weight_get_bolder
enum CRFontWeight cr_font_weight_get_bolder(enum CRFontWeight a_weight)
cr_font_weight_get_bolder: @a_weight: the CRFontWeight to consider.
Definition: cr-fonts.c:767
FONT_SIZE_MEDIUM
@ FONT_SIZE_MEDIUM
Definition: cr-fonts.h:87
FONT_SIZE_ADJUST_INHERIT
@ FONT_SIZE_ADJUST_INHERIT
Definition: cr-fonts.h:168
FONT_SIZE_XX_SMALL
@ FONT_SIZE_XX_SMALL
Definition: cr-fonts.h:84
FONT_WEIGHT_600
@ FONT_WEIGHT_600
Definition: cr-fonts.h:203
FONT_WEIGHT_LIGHTER
@ FONT_WEIGHT_LIGHTER
Definition: cr-fonts.h:197
FONT_WEIGHT_800
@ FONT_WEIGHT_800
Definition: cr-fonts.h:205
CRNumType
CRNumType
The different types of numbers.
Definition: cr-num.h:54
_CRFontSizeAdjust
Definition: cr-fonts.h:171
cr_font_family_prepend
CRFontFamily * cr_font_family_prepend(CRFontFamily *a_this, CRFontFamily *a_family_to_prepend)
cr_font_family_prepend: @a_this: the current instance CRFontFamily.
Definition: cr-fonts.c:277
_CRFontFamily::name
guchar * name
Definition: cr-fonts.h:64
FONT_STYLE_ITALIC
@ FONT_STYLE_ITALIC
Definition: cr-fonts.h:180
FONT_STRETCH_ULTRA_EXPANDED
@ FONT_STRETCH_ULTRA_EXPANDED
Definition: cr-fonts.h:223
CRStatus
CRStatus
The status type returned by the methods of the croco library.
Definition: cr-utils.h:43
cr_font_size_to_string
gchar * cr_font_size_to_string(CRFontSize const *a_this)
cr_font_size_to_string: @a_this: the current instance of CRFontSize
Definition: cr-fonts.c:517
cr_font_size_set_absolute_font_size
enum CRStatus cr_font_size_set_absolute_font_size(CRFontSize *a_this, enum CRNumType a_num_type, gdouble a_value)
cr_font_size_set_absolute_font_size: @a_this: the current instance of CRFontSize @a_num_type: the typ...
Definition: cr-fonts.c:463
cr_font_size_adjust_destroy
void cr_font_size_adjust_destroy(CRFontSizeAdjust *a_this)
cr_font_size_adjust_destroy: @a_this: the current instance of CRFontSizeAdjust.
Definition: cr-fonts.c:941
FONT_FAMILY_NON_GENERIC
@ FONT_FAMILY_NON_GENERIC
Definition: cr-fonts.h:47
CRRelativeFontSize
CRRelativeFontSize
The different types of relative font size.
Definition: cr-fonts.h:106
cr_font_size_set_to_inherit
enum CRStatus cr_font_size_set_to_inherit(CRFontSize *a_this)
cr_font_size_set_to_inherit: @a_this: the current instance of CRFontSize
Definition: cr-fonts.c:485
_CRFontSizeAdjust::type
enum CRFontSizeAdjustType type
Definition: cr-fonts.h:173
_CRFontSize::predefined
enum CRPredefinedAbsoluteFontSize predefined
Definition: cr-fonts.h:158
RELATIVE_FONT_SIZE
@ RELATIVE_FONT_SIZE
If the type of CRFontSize is RELATIVE_FONT_SIZE, the CRFontSize::value.relative field will be defined...
Definition: cr-fonts.h:141
FONT_STRETCH_INHERIT
@ FONT_STRETCH_INHERIT
Definition: cr-fonts.h:224
cr_font_family_set_name
enum CRStatus cr_font_family_set_name(CRFontFamily *a_this, guchar *a_name)
cr_font_family_set_name: @a_this: the current instance of CRFontFamily.
Definition: cr-fonts.c:221
FONT_VARIANT_SMALL_CAPS
@ FONT_VARIANT_SMALL_CAPS
Definition: cr-fonts.h:188
FONT_SIZE_SMALL
@ FONT_SIZE_SMALL
Definition: cr-fonts.h:86
cr_font_stretch_to_string
const gchar * cr_font_stretch_to_string(enum CRFontStretch a_code)
cr_font_stretch_to_string: @a_code: the instance of CRFontStretch to consider.
Definition: cr-fonts.c:853
FONT_SIZE_X_SMALL
@ FONT_SIZE_X_SMALL
Definition: cr-fonts.h:85
cr_font_size_is_predefined_absolute_font_size
gboolean cr_font_size_is_predefined_absolute_font_size(enum CRPredefinedAbsoluteFontSize a_font_size)
cr_font_size_is_predefined_absolute_font_size: @a_font_size: the font size to consider.
Definition: cr-fonts.c:659
cr_utils_trace_info
#define cr_utils_trace_info(a_msg)
Traces an info message.
Definition: cr-utils.h:127
FONT_SIZE_LARGE
@ FONT_SIZE_LARGE
Definition: cr-fonts.h:88
FONT_FAMILY_SERIF
@ FONT_FAMILY_SERIF
Definition: cr-fonts.h:43
cr_font_size_adjust_new
CRFontSizeAdjust * cr_font_size_adjust_new(void)
cr_font_size_adjust_new:
Definition: cr-fonts.c:921
FONT_WEIGHT_500
@ FONT_WEIGHT_500
Definition: cr-fonts.h:202
_CRFontSize::relative
enum CRRelativeFontSize relative
Definition: cr-fonts.h:159
FONT_STRETCH_CONDENSED
@ FONT_STRETCH_CONDENSED
Definition: cr-fonts.h:218
CRFontStyle
CRFontStyle
Definition: cr-fonts.h:177
cr_font_size_adjust_to_string
gchar * cr_font_size_adjust_to_string(CRFontSizeAdjust const *a_this)
cr_font_size_adjust_to_string: @a_this: the instance of CRFontSizeAdjust.
Definition: cr-fonts.c:676
_CRFontFamily
Definition: cr-fonts.h:55
ABSOLUTE_FONT_SIZE
@ ABSOLUTE_FONT_SIZE
If the type of CRFontSize is ABSOLUTE_FONT_SIZE, the CRFontSize::value.absolute field will be defined...
Definition: cr-fonts.h:133
_CRFontSize
Definition: cr-fonts.h:155