1 /* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
4 * This file is part of The Croco Library
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of version 3 of
9 * the GNU General Public
10 * License as published by the Free Software Foundation.
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.
17 * You should have received a copy of the
18 * GNU 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
23 *See COPYRIGHTS file for copyright information
31 cr_font_family_to_string_real (CRFontFamily * a_this,
32 gboolean a_walk_list, GString ** a_string)
35 enum CRStatus result = CR_OK;
38 *a_string = g_string_new (NULL);
39 g_return_val_if_fail (*a_string,
40 CR_INSTANCIATION_FAILED_ERROR);
44 g_string_append (*a_string, "NULL");
48 switch (a_this->type) {
49 case FONT_FAMILY_SANS_SERIF:
50 name = (guchar *) "sans-serif";
53 case FONT_FAMILY_SERIF:
54 name = (guchar *) "sans-serif";
57 case FONT_FAMILY_CURSIVE:
58 name = (guchar *) "cursive";
61 case FONT_FAMILY_FANTASY:
62 name = (guchar *) "fantasy";
65 case FONT_FAMILY_MONOSPACE:
66 name = (guchar *) "monospace";
69 case FONT_FAMILY_NON_GENERIC:
70 name = (guchar *) a_this->name;
74 name = (guchar *) NULL;
80 g_string_append_printf (*a_string, ", %s", name);
82 g_string_append (*a_string, name);
85 if (a_walk_list == TRUE && a_this->next) {
86 result = cr_font_family_to_string_real (a_this->next,
93 cr_predefined_absolute_font_size_to_string (enum CRPredefinedAbsoluteFontSize
99 case FONT_SIZE_XX_SMALL:
100 str = (gchar *) "xx-small";
102 case FONT_SIZE_X_SMALL:
103 str = (gchar *) "x-small";
105 case FONT_SIZE_SMALL:
106 str = (gchar *) "small";
108 case FONT_SIZE_MEDIUM:
109 str = (gchar *) "medium";
111 case FONT_SIZE_LARGE:
112 str = (gchar *) "large";
114 case FONT_SIZE_X_LARGE:
115 str = (gchar *) "x-large";
117 case FONT_SIZE_XX_LARGE:
118 str = (gchar *) "xx-large";
121 str = (gchar *) "unknown absolute font size value";
127 cr_relative_font_size_to_string (enum CRRelativeFontSize a_code)
132 case FONT_SIZE_LARGER:
133 str = (gchar *) "larger";
135 case FONT_SIZE_SMALLER:
136 str = (gchar *) "smaller";
139 str = (gchar *) "unknown relative font size value";
146 * cr_font_family_new:
147 * @a_type: the type of font family to create.
148 * @a_name: the name of the font family:
150 * create a font family.
152 * Returns the newly built font family.
155 cr_font_family_new (enum CRFontFamilyType a_type, guchar * a_name)
157 CRFontFamily *result = NULL;
159 result = g_try_malloc (sizeof (CRFontFamily));
162 cr_utils_trace_info ("Out of memory");
166 memset (result, 0, sizeof (CRFontFamily));
167 result->type = a_type;
169 cr_font_family_set_name (result, a_name);
175 * cr_font_family_to_string:
176 * @a_this: the current instance of #CRFontFamily.
177 * @a_walk_font_family_list: wether the serialize the entire list.
179 * Returns the seriliazed font family. The caller has to free it using
183 cr_font_family_to_string (CRFontFamily * a_this,
184 gboolean a_walk_font_family_list)
186 enum CRStatus status = CR_OK;
187 guchar *result = NULL;
188 GString *stringue = NULL;
191 result = g_strdup ("NULL");
192 g_return_val_if_fail (result, NULL);
195 status = cr_font_family_to_string_real (a_this,
196 a_walk_font_family_list,
199 if (status == CR_OK && stringue) {
200 result = stringue->str;
201 g_string_free (stringue, FALSE);
206 g_string_free (stringue, TRUE);
215 * cr_font_family_set_name:
216 * @a_this: the current instance of #CRFontFamily.
217 * @a_name: the new name
219 * Returns CR_OK upon sucessful completion, an error code otherwise.
222 cr_font_family_set_name (CRFontFamily * a_this, guchar * a_name)
224 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
227 *only non generic font families can have a name
230 if (a_this->type != FONT_FAMILY_NON_GENERIC) {
231 return CR_BAD_PARAM_ERROR;
235 g_free (a_this->name);
239 a_this->name = a_name;
244 * cr_font_family_append:
245 * @a_this: the current instance of #CRFontFamily.
246 * @a_family_to_append: the font family to append to the list
248 * Returns the new font family list.
251 cr_font_family_append (CRFontFamily * a_this,
252 CRFontFamily * a_family_to_append)
254 CRFontFamily *cur_ff = NULL;
256 g_return_val_if_fail (a_family_to_append, NULL);
259 return a_family_to_append;
261 for (cur_ff = a_this; cur_ff && cur_ff->next; cur_ff = cur_ff->next) ;
263 cur_ff->next = a_family_to_append;
264 a_family_to_append->prev = cur_ff;
271 * cr_font_family_prepend:
272 * @a_this: the current instance #CRFontFamily.
273 * @a_family_to_prepend: the font family to prepend to the list.
275 * Returns the font family list.
278 cr_font_family_prepend (CRFontFamily * a_this,
279 CRFontFamily * a_family_to_prepend)
281 g_return_val_if_fail (a_this && a_family_to_prepend, NULL);
284 return a_family_to_prepend;
286 a_family_to_prepend->next = a_this;
287 a_this->prev = a_family_to_prepend;
293 * cr_font_family_destroy:
294 * @a_this: the current instance of #CRFontFamily.
296 * Returns CR_OK upon sucessful completion, an error code otherwise.
299 cr_font_family_destroy (CRFontFamily * a_this)
301 CRFontFamily *cur_ff = NULL;
303 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
305 for (cur_ff = a_this; cur_ff && cur_ff->next; cur_ff = cur_ff->next) ;
307 for (; cur_ff; cur_ff = cur_ff->prev) {
309 g_free (a_this->name);
314 g_free (cur_ff->next);
318 if (cur_ff->prev == NULL) {
326 /***************************************************
327 *'font-size' manipulation functions definitions
328 ***************************************************/
333 * Returns the newly created font size.
336 cr_font_size_new (void)
338 CRFontSize *result = NULL;
340 result = g_try_malloc (sizeof (CRFontSize));
342 cr_utils_trace_info ("Out of memory");
345 memset (result, 0, sizeof (CRFontSize));
351 * cr_font_size_clear:
352 * @a_this: the current instance of #CRFontSize
354 * Returns CR_OK upon successful completion, an error code otherwise.
357 cr_font_size_clear (CRFontSize * a_this)
359 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
361 switch (a_this->type) {
362 case PREDEFINED_ABSOLUTE_FONT_SIZE:
363 case RELATIVE_FONT_SIZE:
364 case INHERITED_FONT_SIZE:
365 memset (a_this, 0, sizeof (CRFontSize));
368 case ABSOLUTE_FONT_SIZE:
369 memset (a_this, 0, sizeof (CRFontSize));
373 return CR_UNKNOWN_TYPE_ERROR;
381 * @a_dst: the destination #CRFontSize (where to copy to).
382 * @a_src: the source #CRFontSize (where to copy from).
384 * Returns CR_OK upon successful completion, an error code otherwise.
387 cr_font_size_copy (CRFontSize * a_dst, CRFontSize * a_src)
389 g_return_val_if_fail (a_dst && a_src, CR_BAD_PARAM_ERROR);
391 switch (a_src->type) {
392 case PREDEFINED_ABSOLUTE_FONT_SIZE:
393 case RELATIVE_FONT_SIZE:
394 case INHERITED_FONT_SIZE:
395 cr_font_size_clear (a_dst);
396 memcpy (a_dst, a_src, sizeof (CRFontSize));
399 case ABSOLUTE_FONT_SIZE:
400 cr_font_size_clear (a_dst);
401 cr_num_copy (&a_dst->value.absolute,
402 &a_src->value.absolute);
403 a_dst->type = a_src->type;
407 return CR_UNKNOWN_TYPE_ERROR;
413 * cr_font_size_set_predefined_absolute_font_size:
414 * @a_this: the current instance of #CRFontSize.
415 * @a_predefined: what to set.
417 * Returns CR_OK upon sucessful completion, an error code otherwise.
420 cr_font_size_set_predefined_absolute_font_size (CRFontSize *a_this,
421 enum CRPredefinedAbsoluteFontSize a_predefined)
423 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
424 g_return_val_if_fail (a_predefined >= PREDEFINED_ABSOLUTE_FONT_SIZE
425 && a_predefined < NB_FONT_SIZE_TYPE,
426 CR_BAD_PARAM_ERROR) ;
428 a_this->type = PREDEFINED_ABSOLUTE_FONT_SIZE ;
429 a_this->value.predefined = a_predefined ;
435 * cr_font_size_set_relative_font_size:
436 * @a_this: the current instance of #CRFontSize
437 * @a_relative: the new relative font size
439 * Returns CR_OK upon successful completion, an error code otherwise.
442 cr_font_size_set_relative_font_size (CRFontSize *a_this,
443 enum CRRelativeFontSize a_relative)
445 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
446 g_return_val_if_fail (a_relative >= FONT_SIZE_LARGER
447 && a_relative < NB_RELATIVE_FONT_SIZE,
448 CR_BAD_PARAM_ERROR) ;
450 a_this->type = RELATIVE_FONT_SIZE ;
451 a_this->value.relative = a_relative ;
456 * cr_font_size_set_absolute_font_size:
457 * @a_this: the current instance of #CRFontSize
458 * @a_num_type: the type of number to set.
459 * @a_value: the actual value to set.
461 * Returns CR_OK upon succesful completion, an error code otherwise.
464 cr_font_size_set_absolute_font_size (CRFontSize *a_this,
465 enum CRNumType a_num_type,
468 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
469 g_return_val_if_fail (a_num_type >= NUM_AUTO
470 && a_num_type < NB_NUM_TYPE,
471 CR_BAD_PARAM_ERROR) ;
473 a_this->type = ABSOLUTE_FONT_SIZE ;
474 cr_num_set (&a_this->value.absolute,
475 a_value, a_num_type) ;
480 * cr_font_size_set_to_inherit:
481 * @a_this: the current instance of #CRFontSize
483 * Returns CR_OK upon succesful completion, an error code otherwise.
486 cr_font_size_set_to_inherit (CRFontSize *a_this)
488 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
490 cr_font_size_clear (a_this) ;
491 a_this->type = INHERITED_FONT_SIZE ;
497 * cr_font_size_is_set_to_inherit:
498 * @a_this: the current instance of #CRFontSize.
500 * Returns TRUE if the current instance is set to 'inherit'.
503 cr_font_size_is_set_to_inherit (CRFontSize *a_this)
505 g_return_val_if_fail (a_this, FALSE) ;
507 return a_this->type == INHERITED_FONT_SIZE ;
511 * cr_font_size_to_string:
512 * @a_this: the current instance of #CRFontSize
514 * Returns the serialized form of #CRFontSize. The returned string
515 * has to bee freed using g_free().
518 cr_font_size_to_string (CRFontSize * a_this)
523 str = g_strdup ("NULL");
524 g_return_val_if_fail (str, NULL);
527 switch (a_this->type) {
528 case PREDEFINED_ABSOLUTE_FONT_SIZE:
529 str = g_strdup (cr_predefined_absolute_font_size_to_string
530 (a_this->value.predefined));
532 case ABSOLUTE_FONT_SIZE:
533 str = cr_num_to_string (&a_this->value.absolute);
535 case RELATIVE_FONT_SIZE:
536 str = g_strdup (cr_relative_font_size_to_string
537 (a_this->value.relative));
539 case INHERITED_FONT_SIZE:
540 str = g_strdup ("inherit");
549 * cr_font_size_get_smaller_predefined:
550 * @a_font_size: the font size to consider.
551 * @a_smaller_size: out parameter. The a smaller value than @a_font_size.
554 cr_font_size_get_smaller_predefined_font_size
555 (enum CRPredefinedAbsoluteFontSize a_font_size,
556 enum CRPredefinedAbsoluteFontSize *a_smaller_size)
558 enum CRPredefinedAbsoluteFontSize result = FONT_SIZE_MEDIUM ;
560 g_return_if_fail (a_smaller_size) ;
561 g_return_if_fail (a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES
562 && a_font_size >= FONT_SIZE_XX_SMALL) ;
564 switch (a_font_size) {
565 case FONT_SIZE_XX_SMALL:
566 result = FONT_SIZE_XX_SMALL ;
568 case FONT_SIZE_X_SMALL:
569 result = FONT_SIZE_XX_SMALL ;
571 case FONT_SIZE_SMALL:
572 result = FONT_SIZE_X_SMALL;
574 case FONT_SIZE_MEDIUM:
575 result = FONT_SIZE_SMALL;
577 case FONT_SIZE_LARGE:
578 result = FONT_SIZE_MEDIUM;
580 case FONT_SIZE_X_LARGE:
581 result = FONT_SIZE_LARGE;
583 case FONT_SIZE_XX_LARGE:
584 result = FONT_SIZE_XX_LARGE;
586 case FONT_SIZE_INHERIT:
587 cr_utils_trace_info ("can't return a smaller size for FONT_SIZE_INHERIT") ;
588 result = FONT_SIZE_MEDIUM ;
591 cr_utils_trace_info ("Unknown FONT_SIZE") ;
592 result = FONT_SIZE_MEDIUM ;
595 *a_smaller_size = result ;
600 * cr_font_size_get_larger_predefined_font_size:
601 * @a_font_size: the font size to consider.
602 * @a_larger_size: out parameter. the font size considered larger than
607 cr_font_size_get_larger_predefined_font_size
608 (enum CRPredefinedAbsoluteFontSize a_font_size,
609 enum CRPredefinedAbsoluteFontSize *a_larger_size)
611 enum CRPredefinedAbsoluteFontSize result = FONT_SIZE_MEDIUM ;
613 g_return_if_fail (a_larger_size) ;
614 g_return_if_fail (a_font_size >= FONT_SIZE_XX_SMALL
615 && a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES) ;
617 switch (a_font_size) {
618 case FONT_SIZE_XX_SMALL:
619 result = FONT_SIZE_X_SMALL ;
621 case FONT_SIZE_X_SMALL:
622 result = FONT_SIZE_SMALL ;
624 case FONT_SIZE_SMALL:
625 result = FONT_SIZE_MEDIUM;
627 case FONT_SIZE_MEDIUM:
628 result = FONT_SIZE_LARGE;
630 case FONT_SIZE_LARGE:
631 result = FONT_SIZE_X_LARGE;
633 case FONT_SIZE_X_LARGE:
634 result = FONT_SIZE_XX_LARGE ;
636 case FONT_SIZE_XX_LARGE:
637 result = FONT_SIZE_XX_LARGE;
639 case FONT_SIZE_INHERIT:
640 cr_utils_trace_info ("can't return a bigger size for FONT_SIZE_INHERIT") ;
641 result = FONT_SIZE_MEDIUM ;
644 cr_utils_trace_info ("Unknown FONT_SIZE") ;
645 result = FONT_SIZE_MEDIUM ;
648 *a_larger_size = result ;
652 * cr_font_size_is_predefined_absolute_font_size:
653 * @a_font_size: the font size to consider.
655 * Returns TRUE if the instance is an predefined absolute font size, FALSE
659 cr_font_size_is_predefined_absolute_font_size
660 (enum CRPredefinedAbsoluteFontSize a_font_size)
662 if (a_font_size >= FONT_SIZE_XX_SMALL
663 && a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES) {
671 * cr_font_size_adjust_to_string:
672 * @a_this: the instance of #CRFontSizeAdjust.
674 * Returns the serialized form of #CRFontSizeAdjust
677 cr_font_size_adjust_to_string (CRFontSizeAdjust * a_this)
682 str = g_strdup ("NULL");
683 g_return_val_if_fail (str, NULL);
687 switch (a_this->type) {
688 case FONT_SIZE_ADJUST_NONE:
689 str = g_strdup ("none");
691 case FONT_SIZE_ADJUST_NUMBER:
693 str = cr_num_to_string (a_this->num);
695 str = g_strdup ("unknow font-size-adjust property value"); /* Should raise an error no?*/
697 case FONT_SIZE_ADJUST_INHERIT:
698 str = g_strdup ("inherit");
704 * cr_font_style_to_string:
705 * @a_code the current instance of #CRFontStyle
707 * Returns the serialized #CRFontStyle. The caller must free the returned
708 * string using g_free().
711 cr_font_style_to_string (enum CRFontStyle a_code)
716 case FONT_STYLE_NORMAL:
717 str = (gchar *) "normal";
719 case FONT_STYLE_ITALIC:
720 str = (gchar *) "italic";
722 case FONT_STYLE_OBLIQUE:
723 str = (gchar *) "oblique";
725 case FONT_STYLE_INHERIT:
726 str = (gchar *) "inherit";
729 str = (gchar *) "unknown font style value";
736 * cr_font_variant_to_string:
737 * @a_code: the current instance of #CRFontVariant.
739 * Returns the serialized form of #CRFontVariant. The caller has
740 * to free the returned string using g_free().
743 cr_font_variant_to_string (enum CRFontVariant a_code)
748 case FONT_VARIANT_NORMAL:
749 str = (gchar *) "normal";
751 case FONT_VARIANT_SMALL_CAPS:
752 str = (gchar *) "small-caps";
754 case FONT_VARIANT_INHERIT:
755 str = (gchar *) "inherit";
762 * cr_font_weight_get_bolder:
763 * @a_weight: the #CRFontWeight to consider.
765 * Returns a font weight bolder than @a_weight
768 cr_font_weight_get_bolder (enum CRFontWeight a_weight)
770 if (a_weight >= NB_FONT_WEIGHTS) {
771 return FONT_WEIGHT_900 ;
772 } else if (a_weight < FONT_WEIGHT_NORMAL) {
773 return FONT_WEIGHT_NORMAL ;
774 } else if (a_weight == FONT_WEIGHT_BOLDER
775 || a_weight == FONT_WEIGHT_BOLDER) {
776 cr_utils_trace_info ("FONT_WEIGHT_BOLDER or FONT_WEIGHT_LIGHTER should not appear here") ;
777 return FONT_WEIGHT_NORMAL ;
779 return a_weight << 1 ;
784 * cr_font_weight_to_string:
785 * @a_code: the font weight to consider.
787 * Returns the serialized form of #CRFontWeight.
790 cr_font_weight_to_string (enum CRFontWeight a_code)
795 case FONT_WEIGHT_NORMAL:
796 str = (gchar *) "normal";
798 case FONT_WEIGHT_BOLD:
799 str = (gchar *) "bold";
801 case FONT_WEIGHT_BOLDER:
802 str = (gchar *) "bolder";
804 case FONT_WEIGHT_LIGHTER:
805 str = (gchar *) "lighter";
807 case FONT_WEIGHT_100:
808 str = (gchar *) "100";
810 case FONT_WEIGHT_200:
811 str = (gchar *) "200";
813 case FONT_WEIGHT_300:
814 str = (gchar *) "300";
816 case FONT_WEIGHT_400:
817 str = (gchar *) "400";
819 case FONT_WEIGHT_500:
820 str = (gchar *) "500";
822 case FONT_WEIGHT_600:
823 str = (gchar *) "600";
825 case FONT_WEIGHT_700:
826 str = (gchar *) "700";
828 case FONT_WEIGHT_800:
829 str = (gchar *) "800";
831 case FONT_WEIGHT_900:
832 str = (gchar *) "900";
834 case FONT_WEIGHT_INHERIT:
835 str = (gchar *) "inherit";
838 str = (gchar *) "unknown font-weight property value";
845 * cr_font_stretch_to_string:
846 * @a_code: the instance of #CRFontStretch to consider.
848 * Returns the serialized form of #CRFontStretch.
851 cr_font_stretch_to_string (enum CRFontStretch a_code)
856 case FONT_STRETCH_NORMAL:
857 str = (gchar *) "normal";
859 case FONT_STRETCH_WIDER:
860 str = (gchar *) "wider";
862 case FONT_STRETCH_NARROWER:
863 str = (gchar *) "narrower";
865 case FONT_STRETCH_ULTRA_CONDENSED:
866 str = (gchar *) "ultra-condensed";
868 case FONT_STRETCH_EXTRA_CONDENSED:
869 str = (gchar *) "extra-condensed";
871 case FONT_STRETCH_CONDENSED:
872 str = (gchar *) "condensed";
874 case FONT_STRETCH_SEMI_CONDENSED:
875 str = (gchar *) "semi-condensed";
877 case FONT_STRETCH_SEMI_EXPANDED:
878 str = (gchar *) "semi-expanded";
880 case FONT_STRETCH_EXPANDED:
881 str = (gchar *) "expanded";
883 case FONT_STRETCH_EXTRA_EXPANDED:
884 str = (gchar *) "extra-expaned";
886 case FONT_STRETCH_ULTRA_EXPANDED:
887 str = (gchar *) "ultra-expanded";
889 case FONT_STRETCH_INHERIT:
890 str = (gchar *) "inherit";
897 * cr_font_size_destroy:
898 * @a_font_size: the font size to destroy
902 cr_font_size_destroy (CRFontSize * a_font_size)
904 g_return_if_fail (a_font_size);
906 g_free (a_font_size) ;
909 /*******************************************************
910 *'font-size-adjust' manipulation function definition
911 *******************************************************/
914 * cr_font_size_adjust_new:
916 * Returns a newly built instance of #CRFontSizeAdjust
919 cr_font_size_adjust_new (void)
921 CRFontSizeAdjust *result = NULL;
923 result = g_try_malloc (sizeof (CRFontSizeAdjust));
925 cr_utils_trace_info ("Out of memory");
928 memset (result, 0, sizeof (CRFontSizeAdjust));
934 * cr_font_size_adjust_destroy:
935 * @a_this: the current instance of #CRFontSizeAdjust.
939 cr_font_size_adjust_destroy (CRFontSizeAdjust * a_this)
941 g_return_if_fail (a_this);
943 if (a_this->type == FONT_SIZE_ADJUST_NUMBER && a_this->num) {
944 cr_num_destroy (a_this->num);