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