Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

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  * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of version 2.1 of 
00010  * the GNU Lesser General Public
00011  * License as published by the Free Software Foundation.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the 
00019  * GNU Lesser General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022  * USA
00023  */
00024 
00025 #include "cr-fonts.h"
00026 #include <string.h>
00027 
00028 
00029 static enum CRStatus
00030 cr_font_family_to_string_real (CRFontFamily *a_this,
00031                                gboolean a_walk_list,
00032                                GString **a_string)
00033 {
00034         guchar * name = NULL ;
00035         enum CRStatus result = CR_OK ;
00036 
00037         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00038 
00039         if (!*a_string)
00040         {
00041                 *a_string = g_string_new (NULL) ;
00042                 g_return_val_if_fail (*a_string,
00043                                       CR_INSTANCIATION_FAILED_ERROR) ;
00044         }
00045 
00046         switch (a_this->type)
00047         {
00048         case FONT_FAMILY_SANS_SERIF:
00049                 name = (guchar*) "sans-serif" ;
00050                 break ;
00051 
00052         case FONT_FAMILY_SERIF:
00053                 name = (guchar*) "sans-serif" ;
00054                 break ;
00055 
00056         case FONT_FAMILY_CURSIVE:
00057                 name = (guchar*) "cursive" ;
00058                 break ;
00059 
00060         case FONT_FAMILY_FANTASY:
00061                 name = (guchar*) "fantasy" ;
00062                 break ;
00063 
00064         case FONT_FAMILY_MONOSPACE:
00065                 name = (guchar*) "monospace" ;
00066                 break ;
00067 
00068         case FONT_FAMILY_NON_GENERIC:
00069                 name = (guchar*) a_this->name;
00070                 break ;
00071 
00072         default:
00073                 name = (guchar*) NULL ;
00074                 break ;
00075         }
00076 
00077         if (name)
00078         {
00079                 if (a_this->prev)
00080                 {
00081                         g_string_append_printf (*a_string,
00082                                                 ", %s", name) ;                        
00083                 }
00084                 else
00085                 {
00086                         g_string_append (*a_string,
00087                                          name) ;
00088                 }
00089         }
00090 
00091         if (a_walk_list == TRUE && a_this->next)
00092         {
00093                 result = cr_font_family_to_string_real (a_this->next,
00094                                                         TRUE, a_string) ;
00095         }
00096 
00097         return result ;
00098 }
00099 
00100 CRFontFamily *
00101 cr_font_family_new (enum CRFontFamilyType a_type, guchar *a_name)
00102 {
00103         CRFontFamily *result = NULL ;
00104 
00105         result = g_try_malloc (sizeof (CRFontFamily)) ;
00106 
00107         if (!result)
00108         {
00109                 cr_utils_trace_info ("Out of memory") ;
00110                 return NULL ;
00111         }
00112 
00113         memset (result, 0, sizeof (CRFontFamily)) ;
00114         result->type = a_type ;
00115 
00116         cr_font_family_set_name (result, a_name) ;
00117 
00118         return result ;
00119 }
00120 
00121 
00122 guchar *
00123 cr_font_family_to_string (CRFontFamily *a_this,
00124                           gboolean a_walk_font_family_list)
00125 {
00126         enum CRStatus status = CR_OK ;
00127         guchar *result = NULL ;
00128         GString *stringue = NULL ;
00129 
00130         g_return_val_if_fail (a_this,
00131                               NULL) ;
00132 
00133         status = cr_font_family_to_string_real (a_this,
00134                                                 a_walk_font_family_list,
00135                                                 &stringue) ;
00136 
00137         if (status == CR_OK && stringue)
00138         {
00139                 result = stringue->str ;
00140                 g_string_free (stringue, FALSE) ;
00141                 stringue = NULL ;
00142                 
00143         }
00144         else
00145         {
00146                 if (stringue)
00147                 {
00148                         g_string_free (stringue, TRUE) ;
00149                         stringue = NULL ;
00150                 }
00151         }
00152 
00153         return result ;
00154 }
00155 enum CRStatus
00156 cr_font_family_set_name (CRFontFamily *a_this, guchar *a_name)
00157 {
00158         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00159 
00160         /*
00161          *only non generic font families can have a name
00162          */
00163 
00164         if (a_this->type != FONT_FAMILY_NON_GENERIC)
00165         {
00166                 return CR_BAD_PARAM_ERROR ;
00167         }
00168 
00169         if (a_this->name)
00170         {
00171                 g_free (a_this->name) ;
00172                 a_this->name = NULL ;
00173         }
00174        
00175         a_this->name = a_name ;
00176         return CR_OK ;
00177 }
00178 
00179 
00180 CRFontFamily *
00181 cr_font_family_append (CRFontFamily *a_this, 
00182                        CRFontFamily *a_family_to_append)
00183 {
00184         CRFontFamily *cur_ff = NULL ;
00185 
00186         g_return_val_if_fail (a_family_to_append,
00187                               NULL) ;
00188 
00189         if (!a_this)
00190                 return a_family_to_append ;
00191 
00192         for (cur_ff = a_this ; 
00193              cur_ff && cur_ff->next; 
00194              cur_ff = cur_ff->next ) ;
00195         
00196         cur_ff->next = a_family_to_append;
00197         a_family_to_append->prev = cur_ff ;
00198 
00199         return a_this ;
00200 
00201         
00202 }
00203 
00204 CRFontFamily *
00205 cr_font_family_prepend (CRFontFamily *a_this, 
00206                         CRFontFamily *a_family_to_prepend)
00207 {
00208         g_return_val_if_fail (a_this && a_family_to_prepend,
00209                               NULL) ;
00210 
00211         if (!a_this)
00212                 return a_family_to_prepend ;
00213 
00214         a_family_to_prepend->next = a_this ;
00215         a_this->prev = a_family_to_prepend ;
00216 
00217         return CR_OK ;  
00218 }
00219 
00220 
00221 enum CRStatus
00222 cr_font_family_destroy (CRFontFamily *a_this)
00223 {
00224         CRFontFamily *cur_ff = NULL ;
00225 
00226         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00227 
00228         for (cur_ff = a_this ; 
00229              cur_ff && cur_ff->next ;
00230              cur_ff = cur_ff->next) 
00231                 ;
00232 
00233         for (; cur_ff ; cur_ff = cur_ff->prev)
00234         {
00235                 if (a_this->name)
00236                 {
00237                         g_free (a_this->name) ;
00238                         a_this->name = NULL ;
00239                 }
00240 
00241                 if (cur_ff->next)
00242                 {
00243                         g_free (cur_ff->next) ;
00244                         
00245                 }
00246 
00247                 if (cur_ff->prev == NULL)
00248                 {
00249                         g_free (a_this) ;
00250                 }
00251         }
00252 
00253         return CR_OK ;          
00254 }
00255 
00256 /***************************************************
00257  *'font-size' manipulation functions definitions
00258  ***************************************************/
00259 
00260 CRFontSize *
00261 cr_font_size_new (void)
00262 {
00263         CRFontSize *result = NULL ;
00264 
00265         result = g_try_malloc (sizeof (CRFontSize)) ;
00266         if (!result)
00267         {
00268                 cr_utils_trace_info ("Out of memory") ;
00269                 return NULL ;
00270         }
00271         memset (result, 0, sizeof (CRFontSize)) ;
00272 
00273         return result ;        
00274 }
00275 
00276 enum CRStatus
00277 cr_font_size_clear (CRFontSize *a_this)
00278 {
00279         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00280 
00281         switch (a_this->type)
00282         {
00283         case PREDEFINED_ABSOLUTE_FONT_SIZE:
00284         case RELATIVE_FONT_SIZE:
00285         case INHERITED_FONT_SIZE:
00286                 memset (a_this, 0, sizeof (CRFontSize)) ;
00287                 break ;
00288 
00289         case ABSOLUTE_FONT_SIZE:
00290                 if (a_this->value.absolute)
00291                 {
00292                         cr_num_destroy (a_this->value.absolute) ;
00293                 }
00294                 memset (a_this, 0, sizeof (CRFontSize)) ;
00295                 break ;
00296 
00297         default:
00298                 return CR_UNKNOWN_TYPE_ERROR ;
00299         }
00300 
00301         return CR_OK ;
00302 }
00303 
00304 enum CRStatus
00305 cr_font_size_copy (CRFontSize *a_dst, CRFontSize *a_src)
00306 {
00307         g_return_val_if_fail (a_dst && a_src, CR_BAD_PARAM_ERROR) ;
00308 
00309         switch (a_src->type)
00310         {
00311         case PREDEFINED_ABSOLUTE_FONT_SIZE:
00312         case RELATIVE_FONT_SIZE:
00313         case INHERITED_FONT_SIZE:
00314                 cr_font_size_clear (a_dst) ;
00315                 memcpy (a_dst, a_src, sizeof (CRFontSize)) ;
00316                 break ;
00317 
00318         case ABSOLUTE_FONT_SIZE:                
00319                 if (a_src->value.absolute)
00320                 {
00321                         cr_font_size_clear (a_dst) ;
00322                         if (!a_dst->value.absolute)
00323                         {
00324                                 a_dst->value.absolute = cr_num_new () ;
00325                         }
00326                         cr_num_copy (a_dst->value.absolute,
00327                                      a_src->value.absolute) ;
00328                         a_dst->type = a_src->type ;
00329                 }
00330                 break ;
00331 
00332         default:
00333                 return CR_UNKNOWN_TYPE_ERROR ;
00334         }
00335         return CR_OK ;
00336 }
00337 
00338 void
00339 cr_font_size_destroy (CRFontSize *a_font_size)
00340 {
00341         g_return_if_fail (a_font_size) ;
00342 
00343         if (a_font_size->type == ABSOLUTE_FONT_SIZE
00344             && a_font_size->value.absolute)
00345         {
00346                 cr_num_destroy (a_font_size->value.absolute) ;
00347                 a_font_size->value.absolute = NULL ;
00348         }
00349 }
00350 
00351 /*******************************************************
00352  *'font-size-adjust' manipulation function definition
00353  *******************************************************/
00354 
00355 CRFontSizeAdjust *
00356 cr_font_size_adjust_new (void)
00357 {
00358         CRFontSizeAdjust *result = NULL ;
00359 
00360         result = g_try_malloc (sizeof (CRFontSizeAdjust)) ;
00361         if (!result)
00362         {
00363                 cr_utils_trace_info ("Out of memory") ;
00364                 return NULL ;
00365         }
00366         memset (result, 0, sizeof (CRFontSizeAdjust)) ;
00367 
00368         return result ;
00369 }
00370 
00371 void
00372 cr_font_size_adjust_destroy (CRFontSizeAdjust *a_this)
00373 {
00374         g_return_if_fail (a_this) ;
00375 
00376         if (a_this->type == FONT_SIZE_ADJUST_NUMBER
00377             && a_this->num)
00378         {
00379                 cr_num_destroy (a_this->num) ;
00380                 a_this->num = NULL ;
00381         }
00382 }

Generated on Wed Oct 1 01:36:45 2003 for Libcroco by doxygen 1.3.3