Libcroco
cr-fonts.c
Go to the documentation of this file.
00001 /* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
00002 
00003 /*
00004  * This file is part of The Croco Library
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of version 2.1 of 
00009  * the GNU Lesser General Public
00010  * License as published by the Free Software Foundation.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the 
00018  * GNU Lesser General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021  * USA
00022  *
00023  *See COPYRIGHTS file for copyright information
00024  */
00025 
00026 #include "cr-fonts.h"
00027 #include <string.h>
00028 
00029 static enum CRStatus
00030 cr_font_family_to_string_real (CRFontFamily const * a_this,
00031                                gboolean a_walk_list, GString ** a_string)
00032 {
00033         guchar const *name = NULL;
00034         enum CRStatus result = CR_OK;
00035 
00036         if (!*a_string) {
00037                 *a_string = g_string_new (NULL);
00038                 g_return_val_if_fail (*a_string,
00039                                       CR_INSTANCIATION_FAILED_ERROR);
00040         }
00041 
00042         if (!a_this) {
00043                 g_string_append (*a_string, "NULL");
00044                 return CR_OK;
00045         }
00046 
00047         switch (a_this->type) {
00048         case FONT_FAMILY_SANS_SERIF:
00049                 name = (guchar const *) "sans-serif";
00050                 break;
00051 
00052         case FONT_FAMILY_SERIF:
00053                 name = (guchar const *) "sans-serif";
00054                 break;
00055 
00056         case FONT_FAMILY_CURSIVE:
00057                 name = (guchar const *) "cursive";
00058                 break;
00059 
00060         case FONT_FAMILY_FANTASY:
00061                 name = (guchar const *) "fantasy";
00062                 break;
00063 
00064         case FONT_FAMILY_MONOSPACE:
00065                 name = (guchar const *) "monospace";
00066                 break;
00067 
00068         case FONT_FAMILY_NON_GENERIC:
00069                 name = (guchar const *) a_this->name;
00070                 break;
00071 
00072         default:
00073                 name = NULL;
00074                 break;
00075         }
00076 
00077         if (name) {
00078                 if (a_this->prev) {
00079                         g_string_append_printf (*a_string, ", %s", name);
00080                 } else {
00081                         g_string_append (*a_string, name);
00082                 }
00083         }
00084         if (a_walk_list == TRUE && a_this->next) {
00085                 result = cr_font_family_to_string_real (a_this->next,
00086                                                         TRUE, a_string);
00087         }
00088         return result;
00089 }
00090 
00091 static const gchar *
00092 cr_predefined_absolute_font_size_to_string (enum CRPredefinedAbsoluteFontSize
00093                                             a_code)
00094 {
00095         gchar const *str = NULL;
00096 
00097         switch (a_code) {
00098         case FONT_SIZE_XX_SMALL:
00099                 str = "xx-small";
00100                 break;
00101         case FONT_SIZE_X_SMALL:
00102                 str = "x-small";
00103                 break;
00104         case FONT_SIZE_SMALL:
00105                 str = "small";
00106                 break;
00107         case FONT_SIZE_MEDIUM:
00108                 str = "medium";
00109                 break;
00110         case FONT_SIZE_LARGE:
00111                 str = "large";
00112                 break;
00113         case FONT_SIZE_X_LARGE:
00114                 str = "x-large";
00115                 break;
00116         case FONT_SIZE_XX_LARGE:
00117                 str = "xx-large";
00118                 break;
00119         default:
00120                 str = "unknown absolute font size value";
00121         }
00122         return str;
00123 }
00124 
00125 static const gchar *
00126 cr_relative_font_size_to_string (enum CRRelativeFontSize a_code)
00127 {
00128         gchar const *str = NULL;
00129 
00130         switch (a_code) {
00131         case FONT_SIZE_LARGER:
00132                 str = "larger";
00133                 break;
00134         case FONT_SIZE_SMALLER:
00135                 str = "smaller";
00136                 break;
00137         default:
00138                 str = "unknown relative font size value";
00139                 break;
00140         }
00141         return str;
00142 }
00143 
00144 /**
00145  * cr_font_family_new:
00146  * @a_type: the type of font family to create.
00147  * @a_name: the name of the font family.
00148  *
00149  * create a font family.
00150  *
00151  * Returns the newly built font family.
00152  */
00153 CRFontFamily *
00154 cr_font_family_new (enum CRFontFamilyType a_type, guchar * a_name)
00155 {
00156         CRFontFamily *result = NULL;
00157 
00158         result = g_try_malloc (sizeof (CRFontFamily));
00159 
00160         if (!result) {
00161                 cr_utils_trace_info ("Out of memory");
00162                 return NULL;
00163         }
00164 
00165         memset (result, 0, sizeof (CRFontFamily));
00166         result->type = a_type;
00167 
00168         cr_font_family_set_name (result, a_name);
00169 
00170         return result;
00171 }
00172 
00173 /**
00174  * cr_font_family_to_string:
00175  * @a_this: the current instance of #CRFontFamily.
00176  * @a_walk_font_family_list: wether the serialize the entire list.
00177  *
00178  * Returns the seriliazed font family. The caller has to free it using
00179  * g_free().
00180  */
00181 guchar *
00182 cr_font_family_to_string (CRFontFamily const * a_this,
00183                           gboolean a_walk_font_family_list)
00184 {
00185         enum CRStatus status = CR_OK;
00186         guchar *result = NULL;
00187         GString *stringue = NULL;
00188 
00189         if (!a_this) {
00190                 result = g_strdup ("NULL");
00191                 g_return_val_if_fail (result, NULL);
00192                 return result;
00193         }
00194         status = cr_font_family_to_string_real (a_this,
00195                                                 a_walk_font_family_list,
00196                                                 &stringue);
00197 
00198         if (status == CR_OK && stringue) {
00199                 result = stringue->str;
00200                 g_string_free (stringue, FALSE);
00201                 stringue = NULL;
00202 
00203         } else {
00204                 if (stringue) {
00205                         g_string_free (stringue, TRUE);
00206                         stringue = NULL;
00207                 }
00208         }
00209 
00210         return result;
00211 }
00212 
00213 /**
00214  * cr_font_family_set_name:
00215  * @a_this: the current instance of #CRFontFamily.
00216  * @a_name: the new name
00217  *
00218  * Returns CR_OK upon sucessful completion, an error code otherwise.
00219  */
00220 enum CRStatus
00221 cr_font_family_set_name (CRFontFamily * a_this, guchar * a_name)
00222 {
00223         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00224 
00225         /*
00226          *only non generic font families can have a name
00227          */
00228 
00229         if (a_this->type != FONT_FAMILY_NON_GENERIC) {
00230                 return CR_BAD_PARAM_ERROR;
00231         }
00232 
00233         if (a_this->name) {
00234                 g_free (a_this->name);
00235                 a_this->name = NULL;
00236         }
00237 
00238         a_this->name = a_name;
00239         return CR_OK;
00240 }
00241 
00242 /**
00243  * cr_font_family_append:
00244  * @a_this: the current instance of #CRFontFamily.
00245  * @a_family_to_append: the font family to append to the list
00246  *
00247  * Returns the new font family list.
00248  */
00249 CRFontFamily *
00250 cr_font_family_append (CRFontFamily * a_this,
00251                        CRFontFamily * a_family_to_append)
00252 {
00253         CRFontFamily *cur_ff = NULL;
00254 
00255         g_return_val_if_fail (a_family_to_append, NULL);
00256 
00257         if (!a_this)
00258                 return a_family_to_append;
00259 
00260         for (cur_ff = a_this; cur_ff && cur_ff->next; cur_ff = cur_ff->next) ;
00261 
00262         cur_ff->next = a_family_to_append;
00263         a_family_to_append->prev = cur_ff;
00264 
00265         return a_this;
00266 
00267 }
00268 
00269 /**
00270  * cr_font_family_prepend:
00271  * @a_this: the current instance #CRFontFamily.
00272  * @a_family_to_prepend: the font family to prepend to the list.
00273  *
00274  * Returns the font family list.
00275  */
00276 CRFontFamily *
00277 cr_font_family_prepend (CRFontFamily * a_this,
00278                         CRFontFamily * a_family_to_prepend)
00279 {
00280         g_return_val_if_fail (a_this && a_family_to_prepend, NULL);
00281 
00282         if (!a_this)
00283                 return a_family_to_prepend;
00284 
00285         a_family_to_prepend->next = a_this;
00286         a_this->prev = a_family_to_prepend;
00287 
00288         return a_family_to_prepend;
00289 }
00290 
00291 /**
00292  * cr_font_family_destroy:
00293  * @a_this: the current instance of #CRFontFamily.
00294  *
00295  * Returns CR_OK upon sucessful completion, an error code otherwise.
00296  */
00297 enum CRStatus
00298 cr_font_family_destroy (CRFontFamily * a_this)
00299 {
00300         CRFontFamily *cur_ff = NULL;
00301 
00302         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00303 
00304         for (cur_ff = a_this; cur_ff && cur_ff->next; cur_ff = cur_ff->next) ;
00305 
00306         for (; cur_ff; cur_ff = cur_ff->prev) {
00307                 if (a_this->name) {
00308                         g_free (a_this->name);
00309                         a_this->name = NULL;
00310                 }
00311 
00312                 if (cur_ff->next) {
00313                         g_free (cur_ff->next);
00314 
00315                 }
00316 
00317                 if (cur_ff->prev == NULL) {
00318                         g_free (a_this);
00319                 }
00320         }
00321 
00322         return CR_OK;
00323 }
00324 
00325 /***************************************************
00326  *'font-size' manipulation functions definitions
00327  ***************************************************/
00328 
00329 /**
00330  * cr_font_size_new:
00331  *
00332  * Returns the newly created font size.
00333  */
00334 CRFontSize *
00335 cr_font_size_new (void)
00336 {
00337         CRFontSize *result = NULL;
00338 
00339         result = g_try_malloc (sizeof (CRFontSize));
00340         if (!result) {
00341                 cr_utils_trace_info ("Out of memory");
00342                 return NULL;
00343         }
00344         memset (result, 0, sizeof (CRFontSize));
00345 
00346         return result;
00347 }
00348 
00349 /**
00350  * cr_font_size_clear:
00351  * @a_this: the current instance of #CRFontSize
00352  *
00353  * Returns CR_OK upon successful completion, an error code otherwise.
00354  */
00355 enum CRStatus
00356 cr_font_size_clear (CRFontSize * a_this)
00357 {
00358         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00359 
00360         switch (a_this->type) {
00361         case PREDEFINED_ABSOLUTE_FONT_SIZE:
00362         case RELATIVE_FONT_SIZE:
00363         case INHERITED_FONT_SIZE:
00364                 memset (a_this, 0, sizeof (CRFontSize));
00365                 break;
00366 
00367         case ABSOLUTE_FONT_SIZE:
00368                 memset (a_this, 0, sizeof (CRFontSize));
00369                 break;
00370 
00371         default:
00372                 return CR_UNKNOWN_TYPE_ERROR;
00373         }
00374 
00375         return CR_OK;
00376 }
00377 
00378 /**
00379  * cr_font_size_copy:
00380  * @a_dst: the destination #CRFontSize (where to copy to).
00381  * @a_src: the source #CRFontSize (where to copy from).
00382  *
00383  * Returns CR_OK upon successful completion, an error code otherwise.
00384  */
00385 enum CRStatus
00386 cr_font_size_copy (CRFontSize * a_dst, CRFontSize const * a_src)
00387 {
00388         g_return_val_if_fail (a_dst && a_src, CR_BAD_PARAM_ERROR);
00389 
00390         switch (a_src->type) {
00391         case PREDEFINED_ABSOLUTE_FONT_SIZE:
00392         case RELATIVE_FONT_SIZE:
00393         case INHERITED_FONT_SIZE:
00394                 cr_font_size_clear (a_dst);
00395                 memcpy (a_dst, a_src, sizeof (CRFontSize));
00396                 break;
00397 
00398         case ABSOLUTE_FONT_SIZE:
00399                 cr_font_size_clear (a_dst);
00400                 cr_num_copy (&a_dst->value.absolute,
00401                              &a_src->value.absolute);
00402                 a_dst->type = a_src->type;
00403                 break;
00404 
00405         default:
00406                 return CR_UNKNOWN_TYPE_ERROR;
00407         }
00408         return CR_OK;
00409 }
00410 
00411 /**
00412  * cr_font_size_set_predefined_absolute_font_size:
00413  * @a_this: the current instance of #CRFontSize.
00414  * @a_predefined: what to set.
00415  *
00416  * Returns CR_OK upon sucessful completion, an error code otherwise.
00417  */
00418 enum CRStatus 
00419 cr_font_size_set_predefined_absolute_font_size (CRFontSize *a_this, 
00420                                                 enum CRPredefinedAbsoluteFontSize a_predefined)
00421 {
00422         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00423         g_return_val_if_fail (a_predefined >= PREDEFINED_ABSOLUTE_FONT_SIZE
00424                               && a_predefined < NB_FONT_SIZE_TYPE,
00425                               CR_BAD_PARAM_ERROR) ;
00426 
00427         a_this->type = PREDEFINED_ABSOLUTE_FONT_SIZE ;
00428         a_this->value.predefined = a_predefined ;
00429 
00430         return CR_OK ;
00431 }
00432 
00433 /**
00434  * cr_font_size_set_relative_font_size:
00435  * @a_this: the current instance of #CRFontSize
00436  * @a_relative: the new relative font size
00437  *
00438  * Returns CR_OK upon successful completion, an error code otherwise.
00439  */
00440 enum CRStatus 
00441 cr_font_size_set_relative_font_size (CRFontSize *a_this,
00442                                      enum CRRelativeFontSize a_relative)
00443 {
00444         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00445         g_return_val_if_fail (a_relative >= FONT_SIZE_LARGER
00446                               && a_relative < NB_RELATIVE_FONT_SIZE,
00447                               CR_BAD_PARAM_ERROR) ;
00448         
00449         a_this->type = RELATIVE_FONT_SIZE ;
00450         a_this->value.relative = a_relative ;
00451         return CR_OK ;
00452 }
00453 
00454 /**
00455  * cr_font_size_set_absolute_font_size:
00456  * @a_this: the current instance of #CRFontSize
00457  * @a_num_type: the type of number to set.
00458  * @a_value: the actual value to set.
00459  *
00460  * Returns CR_OK upon succesful completion, an error code otherwise.
00461  */
00462 enum CRStatus 
00463 cr_font_size_set_absolute_font_size (CRFontSize *a_this,
00464                                      enum CRNumType a_num_type,
00465                                      gdouble a_value)
00466 {
00467         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00468         g_return_val_if_fail (a_num_type >= NUM_AUTO
00469                               && a_num_type < NB_NUM_TYPE,
00470                               CR_BAD_PARAM_ERROR) ;
00471 
00472         a_this->type = ABSOLUTE_FONT_SIZE ;
00473         cr_num_set (&a_this->value.absolute,
00474                     a_value, a_num_type) ;        
00475         return CR_OK ;
00476 }
00477 
00478 /**
00479  * cr_font_size_set_to_inherit:
00480  * @a_this: the current instance of #CRFontSize 
00481  *
00482  * Returns CR_OK upon succesful completion, an error code otherwise.
00483  */
00484 enum CRStatus
00485 cr_font_size_set_to_inherit (CRFontSize *a_this)
00486 {
00487         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00488 
00489         cr_font_size_clear (a_this) ;
00490         a_this->type = INHERITED_FONT_SIZE ;
00491 
00492         return CR_OK ;
00493 }
00494 
00495 /**
00496  * cr_font_size_is_set_to_inherit:
00497  * @a_this: the current instance of #CRFontSize.
00498  *
00499  * Returns TRUE if the current instance is set to 'inherit'. 
00500  */
00501 gboolean
00502 cr_font_size_is_set_to_inherit (CRFontSize const *a_this)
00503 {
00504         g_return_val_if_fail (a_this, FALSE) ;
00505 
00506         return a_this->type == INHERITED_FONT_SIZE ;
00507 }
00508 
00509 /**
00510  * cr_font_size_to_string:
00511  * @a_this: the current instance of #CRFontSize
00512  *
00513  * Returns the serialized form of #CRFontSize. The returned string
00514  * has to bee freed using g_free().
00515  */
00516 gchar *
00517 cr_font_size_to_string (CRFontSize const * a_this)
00518 {
00519         gchar *str = NULL;
00520 
00521         if (!a_this) {
00522                 str = g_strdup ("NULL");
00523                 g_return_val_if_fail (str, NULL);
00524                 return str;
00525         }
00526         switch (a_this->type) {
00527         case PREDEFINED_ABSOLUTE_FONT_SIZE:
00528                 str = g_strdup (cr_predefined_absolute_font_size_to_string
00529                                 (a_this->value.predefined));
00530                 break;
00531         case ABSOLUTE_FONT_SIZE:
00532                 str = cr_num_to_string (&a_this->value.absolute);
00533                 break;
00534         case RELATIVE_FONT_SIZE:
00535                 str = g_strdup (cr_relative_font_size_to_string
00536                                 (a_this->value.relative));
00537                 break;
00538         case INHERITED_FONT_SIZE:
00539                 str = g_strdup ("inherit");
00540                 break;
00541         default:
00542                 break;
00543         }
00544         return str;
00545 }
00546 
00547 /**
00548  * cr_font_size_get_smaller_predefined:
00549  * @a_font_size: the font size to consider.
00550  * @a_smaller_size: out parameter. The a smaller value than @a_font_size. 
00551  */
00552 void 
00553 cr_font_size_get_smaller_predefined_font_size 
00554                                 (enum CRPredefinedAbsoluteFontSize a_font_size,
00555                                  enum CRPredefinedAbsoluteFontSize *a_smaller_size)
00556 {
00557         enum CRPredefinedAbsoluteFontSize result = FONT_SIZE_MEDIUM ;
00558 
00559         g_return_if_fail (a_smaller_size) ;
00560         g_return_if_fail (a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES
00561                           && a_font_size >= FONT_SIZE_XX_SMALL) ;
00562 
00563         switch (a_font_size) {
00564         case FONT_SIZE_XX_SMALL:
00565                 result =  FONT_SIZE_XX_SMALL ;
00566                 break ;
00567         case FONT_SIZE_X_SMALL:
00568                 result =  FONT_SIZE_XX_SMALL ;
00569                 break ;
00570         case FONT_SIZE_SMALL:
00571                 result =  FONT_SIZE_X_SMALL;
00572                 break ;
00573         case FONT_SIZE_MEDIUM:
00574                 result =  FONT_SIZE_SMALL;
00575                 break ;
00576         case FONT_SIZE_LARGE:
00577                 result =  FONT_SIZE_MEDIUM;
00578                 break ;
00579         case FONT_SIZE_X_LARGE:
00580                 result =  FONT_SIZE_LARGE;
00581                 break ;
00582         case FONT_SIZE_XX_LARGE:
00583                 result =  FONT_SIZE_XX_LARGE;
00584                 break ;
00585         case FONT_SIZE_INHERIT:
00586                 cr_utils_trace_info ("can't return a smaller size for FONT_SIZE_INHERIT") ;                
00587                 result =  FONT_SIZE_MEDIUM ;
00588                 break ;
00589         default:
00590                 cr_utils_trace_info ("Unknown FONT_SIZE") ;
00591                 result = FONT_SIZE_MEDIUM ;
00592                 break ;
00593         }
00594         *a_smaller_size = result ;
00595 }
00596 
00597 
00598 /**
00599  * cr_font_size_get_larger_predefined_font_size:
00600  * @a_font_size: the font size to consider.
00601  * @a_larger_size: out parameter. the font size considered larger than
00602  * @a_font_size.
00603  *
00604  */
00605 void 
00606 cr_font_size_get_larger_predefined_font_size 
00607                         (enum CRPredefinedAbsoluteFontSize a_font_size,
00608                          enum CRPredefinedAbsoluteFontSize *a_larger_size)
00609 {
00610         enum CRPredefinedAbsoluteFontSize result = FONT_SIZE_MEDIUM ;
00611         
00612         g_return_if_fail (a_larger_size) ;
00613         g_return_if_fail (a_font_size >= FONT_SIZE_XX_SMALL 
00614                           && a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES) ;
00615 
00616         switch (a_font_size) {
00617         case FONT_SIZE_XX_SMALL:
00618                 result =  FONT_SIZE_X_SMALL ;
00619                 break ;
00620         case FONT_SIZE_X_SMALL:
00621                 result =  FONT_SIZE_SMALL ;
00622                 break ;
00623         case FONT_SIZE_SMALL:
00624                 result =  FONT_SIZE_MEDIUM;
00625                 break ;
00626         case FONT_SIZE_MEDIUM:
00627                 result =  FONT_SIZE_LARGE;
00628                 break ;
00629         case FONT_SIZE_LARGE:
00630                 result =  FONT_SIZE_X_LARGE;
00631                 break ;
00632         case FONT_SIZE_X_LARGE:
00633                 result =  FONT_SIZE_XX_LARGE ;
00634                 break ;
00635         case FONT_SIZE_XX_LARGE:
00636                 result =  FONT_SIZE_XX_LARGE;
00637                 break ;
00638         case FONT_SIZE_INHERIT:
00639                 cr_utils_trace_info ("can't return a bigger size for FONT_SIZE_INHERIT") ;                
00640                 result =  FONT_SIZE_MEDIUM ;
00641                 break ;
00642         default:
00643                 cr_utils_trace_info ("Unknown FONT_SIZE") ;
00644                 result = FONT_SIZE_MEDIUM ;
00645                 break ;
00646         }
00647         *a_larger_size = result ;
00648 }
00649 
00650 /**
00651  * cr_font_size_is_predefined_absolute_font_size:
00652  * @a_font_size: the font size to consider.
00653  *
00654  * Returns TRUE if the instance is an predefined absolute font size, FALSE
00655  * otherwise.
00656  */
00657 gboolean
00658 cr_font_size_is_predefined_absolute_font_size 
00659                                 (enum CRPredefinedAbsoluteFontSize a_font_size)
00660 {
00661         if (a_font_size >= FONT_SIZE_XX_SMALL
00662             && a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES) {
00663                 return TRUE ;
00664         } else {
00665                 return FALSE ;
00666         }
00667 }
00668 
00669 /**
00670  * cr_font_size_adjust_to_string:
00671  * @a_this: the instance of #CRFontSizeAdjust.
00672  *
00673  * Returns the serialized form of #CRFontSizeAdjust
00674  */
00675 gchar *
00676 cr_font_size_adjust_to_string (CRFontSizeAdjust const * a_this)
00677 {
00678         gchar *str = NULL;
00679 
00680         if (!a_this) {
00681                 str = g_strdup ("NULL");
00682                 g_return_val_if_fail (str, NULL);
00683                 return str;
00684         }
00685 
00686         switch (a_this->type) {
00687         case FONT_SIZE_ADJUST_NONE:
00688                 str = g_strdup ("none");
00689                 break;
00690         case FONT_SIZE_ADJUST_NUMBER:
00691                 if (a_this->num)
00692                         str = cr_num_to_string (a_this->num);
00693                 else
00694                         str = g_strdup ("unknow font-size-adjust property value"); /* Should raise an error no?*/
00695                 break;
00696         case FONT_SIZE_ADJUST_INHERIT:
00697                 str = g_strdup ("inherit");
00698         }
00699         return str;
00700 }
00701 
00702 /**
00703  * cr_font_style_to_string:
00704  * @a_code: the current instance of #CRFontStyle .
00705  *
00706  * Returns the serialized #CRFontStyle. The caller must free the returned
00707  * string using g_free().
00708  */
00709 const gchar *
00710 cr_font_style_to_string (enum CRFontStyle a_code)
00711 {
00712         gchar *str = NULL;
00713 
00714         switch (a_code) {
00715         case FONT_STYLE_NORMAL:
00716                 str = (gchar *) "normal";
00717                 break;
00718         case FONT_STYLE_ITALIC:
00719                 str = (gchar *) "italic";
00720                 break;
00721         case FONT_STYLE_OBLIQUE:
00722                 str = (gchar *) "oblique";
00723                 break;
00724         case FONT_STYLE_INHERIT:
00725                 str = (gchar *) "inherit";
00726                 break;
00727         default:
00728                 str = (gchar *) "unknown font style value";
00729                 break;
00730         }
00731         return str;
00732 }
00733 
00734 /**
00735  * cr_font_variant_to_string:
00736  * @a_code: the current instance of #CRFontVariant.
00737  *
00738  * Returns the serialized form of #CRFontVariant. The caller has
00739  * to free the returned string using g_free().
00740  */
00741 const gchar *
00742 cr_font_variant_to_string (enum CRFontVariant a_code)
00743 {
00744         gchar *str = NULL;
00745 
00746         switch (a_code) {
00747         case FONT_VARIANT_NORMAL:
00748                 str = (gchar *) "normal";
00749                 break;
00750         case FONT_VARIANT_SMALL_CAPS:
00751                 str = (gchar *) "small-caps";
00752                 break;
00753         case FONT_VARIANT_INHERIT:
00754                 str = (gchar *) "inherit";
00755                 break;
00756         }
00757         return str;
00758 }
00759 
00760 /**
00761  * cr_font_weight_get_bolder:
00762  * @a_weight: the #CRFontWeight to consider.
00763  *
00764  * Returns a font weight bolder than @a_weight
00765  */
00766 enum CRFontWeight
00767 cr_font_weight_get_bolder (enum CRFontWeight a_weight)
00768 {
00769         if (a_weight == FONT_WEIGHT_INHERIT) {
00770                 cr_utils_trace_info ("can't return a bolder weight for FONT_WEIGHT_INHERIT") ;
00771                 return a_weight;
00772         } else if (a_weight >= FONT_WEIGHT_900) {
00773                 return FONT_WEIGHT_900 ;
00774         } else if (a_weight < FONT_WEIGHT_NORMAL) {
00775                 return FONT_WEIGHT_NORMAL ;
00776         } else if (a_weight == FONT_WEIGHT_BOLDER
00777                    || a_weight == FONT_WEIGHT_BOLDER) {
00778                 cr_utils_trace_info ("FONT_WEIGHT_BOLDER or FONT_WEIGHT_LIGHTER should not appear here") ;
00779                 return FONT_WEIGHT_NORMAL ;
00780         } else {
00781                 return a_weight << 1 ;
00782         }
00783 }
00784 
00785 /**
00786  * cr_font_weight_to_string:
00787  * @a_code: the font weight to consider.
00788  *
00789  * Returns the serialized form of #CRFontWeight.
00790  */
00791 const gchar *
00792 cr_font_weight_to_string (enum CRFontWeight a_code)
00793 {
00794         gchar *str = NULL;
00795 
00796         switch (a_code) {
00797         case FONT_WEIGHT_NORMAL:
00798                 str = (gchar *) "normal";
00799                 break;
00800         case FONT_WEIGHT_BOLD:
00801                 str = (gchar *) "bold";
00802                 break;
00803         case FONT_WEIGHT_BOLDER:
00804                 str = (gchar *) "bolder";
00805                 break;
00806         case FONT_WEIGHT_LIGHTER:
00807                 str = (gchar *) "lighter";
00808                 break;
00809         case FONT_WEIGHT_100:
00810                 str = (gchar *) "100";
00811                 break;
00812         case FONT_WEIGHT_200:
00813                 str = (gchar *) "200";
00814                 break;
00815         case FONT_WEIGHT_300:
00816                 str = (gchar *) "300";
00817                 break;
00818         case FONT_WEIGHT_400:
00819                 str = (gchar *) "400";
00820                 break;
00821         case FONT_WEIGHT_500:
00822                 str = (gchar *) "500";
00823                 break;
00824         case FONT_WEIGHT_600:
00825                 str = (gchar *) "600";
00826                 break;
00827         case FONT_WEIGHT_700:
00828                 str = (gchar *) "700";
00829                 break;
00830         case FONT_WEIGHT_800:
00831                 str = (gchar *) "800";
00832                 break;
00833         case FONT_WEIGHT_900:
00834                 str = (gchar *) "900";
00835                 break;
00836         case FONT_WEIGHT_INHERIT:
00837                 str = (gchar *) "inherit";
00838                 break;
00839         default:
00840                 str = (gchar *) "unknown font-weight property value";
00841                 break;
00842         }
00843         return str;
00844 }
00845 
00846 /**
00847  * cr_font_stretch_to_string:
00848  * @a_code: the instance of #CRFontStretch to consider.
00849  *
00850  * Returns the serialized form of #CRFontStretch.
00851  */
00852 const gchar *
00853 cr_font_stretch_to_string (enum CRFontStretch a_code)
00854 {
00855         gchar *str = NULL;
00856 
00857         switch (a_code) {
00858         case FONT_STRETCH_NORMAL:
00859                 str = (gchar *) "normal";
00860                 break;
00861         case FONT_STRETCH_WIDER:
00862                 str = (gchar *) "wider";
00863                 break;
00864         case FONT_STRETCH_NARROWER:
00865                 str = (gchar *) "narrower";
00866                 break;
00867         case FONT_STRETCH_ULTRA_CONDENSED:
00868                 str = (gchar *) "ultra-condensed";
00869                 break;
00870         case FONT_STRETCH_EXTRA_CONDENSED:
00871                 str = (gchar *) "extra-condensed";
00872                 break;
00873         case FONT_STRETCH_CONDENSED:
00874                 str = (gchar *) "condensed";
00875                 break;
00876         case FONT_STRETCH_SEMI_CONDENSED:
00877                 str = (gchar *) "semi-condensed";
00878                 break;
00879         case FONT_STRETCH_SEMI_EXPANDED:
00880                 str = (gchar *) "semi-expanded";
00881                 break;
00882         case FONT_STRETCH_EXPANDED:
00883                 str = (gchar *) "expanded";
00884                 break;
00885         case FONT_STRETCH_EXTRA_EXPANDED:
00886                 str = (gchar *) "extra-expaned";
00887                 break;
00888         case FONT_STRETCH_ULTRA_EXPANDED:
00889                 str = (gchar *) "ultra-expanded";
00890                 break;
00891         case FONT_STRETCH_INHERIT:
00892                 str = (gchar *) "inherit";
00893                 break;
00894         }
00895         return str;
00896 }
00897 
00898 /**
00899  * cr_font_size_destroy:
00900  * @a_font_size: the font size to destroy
00901  *
00902  */
00903 void
00904 cr_font_size_destroy (CRFontSize * a_font_size)
00905 {
00906         g_return_if_fail (a_font_size);
00907 
00908         g_free (a_font_size) ;
00909 }
00910 
00911 /*******************************************************
00912  *'font-size-adjust' manipulation function definition
00913  *******************************************************/
00914 
00915 /**
00916  * cr_font_size_adjust_new:
00917  *
00918  * Returns a newly built instance of #CRFontSizeAdjust
00919  */
00920 CRFontSizeAdjust *
00921 cr_font_size_adjust_new (void)
00922 {
00923         CRFontSizeAdjust *result = NULL;
00924 
00925         result = g_try_malloc (sizeof (CRFontSizeAdjust));
00926         if (!result) {
00927                 cr_utils_trace_info ("Out of memory");
00928                 return NULL;
00929         }
00930         memset (result, 0, sizeof (CRFontSizeAdjust));
00931 
00932         return result;
00933 }
00934 
00935 /**
00936  * cr_font_size_adjust_destroy:
00937  * @a_this: the current instance of #CRFontSizeAdjust.
00938  *
00939  */
00940 void
00941 cr_font_size_adjust_destroy (CRFontSizeAdjust * a_this)
00942 {
00943         g_return_if_fail (a_this);
00944 
00945         if (a_this->type == FONT_SIZE_ADJUST_NUMBER && a_this->num) {
00946                 cr_num_destroy (a_this->num);
00947                 a_this->num = NULL;
00948         }
00949 }