~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-tools/tinatool/gphx/gdk2/gphxGdk_fonts.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :  TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/gphx/gdk2/gphxGdk_fonts.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.2 $
 39  * CVS Id  :  $Id: gphxGdk_fonts.c,v 1.2 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Author  :  giob@man.ac.uk, paul.bromiley@manchester.ac.uk
 42  *
 43  *********
 44 */
 45 /** 
 46  *  @file  gphxGdk_fonts.c
 47  *  @brief Functions to set and change fonts.
 48  *
 49  *  Note: the functions in this file are duplicated for each graphics lib (x11, GDK, etc ...).
 50  *
 51  */
 52 
 53 
 54 #include "gphxGdk_fonts.h"
 55 
 56 #if HAVE_CONFIG_H
 57   #include <config.h>
 58 #endif
 59 
 60 #include <string.h>
 61 #include <gtk/gtk.h>
 62 #include <tinatool/gphx/gdk2/gphx_GdkDef.h>
 63 
 64 static char default_font_name[256] = "6x10";
 65 
 66 /**
 67  * @brief  Setter for default_font_name.  
 68  * @param  font_name  Set the file scope static default_font_name to font_name.
 69  */
 70 void    default_font_set(char *font_name)
 71 {
 72   (void) strcpy(default_font_name, font_name);
 73 }
 74 
 75 /**
 76  * @brief  Getter for default_font_name.  
 77  * @return char *   Return the file scope static default_font_name.
 78  */
 79 char   *default_font_get(void)
 80 {
 81   return default_font_name;
 82 }
 83 
 84 /**
 85  * @brief  Compare names of two Font_data structs and return the second if they match.  
 86  * @param  key    Pointer to Font_data struct for comparison.
 87  * @param  data   Pointer to Font_data struct to be compared.
 88  * @return void *   Void pointer to data, if its name matches that of key.
 89  */
 90 static void *font_match(Font_data *key, Font_data *data)
 91 {
 92   void *data_if_match;
 93 
 94   data_if_match = !strcmp(key->font_name, data->font_name) ? (void *) data : NULL;
 95 
 96   return data_if_match;
 97 }
 98 
 99 /**
100  * @brief  Find the font matching font_name.  
101  * @param  font_name   String name of font.
102  * @return GdkFont *   Pointer to corresponding GdkFont.
103  */
104 static GdkFont *font_find(char *font_name)
105 {
106     Font_data    *font_data = NULL;
107     Font_data     font_data_key;
108     GdkFont      *temp;
109 
110     static List  *font_database = NULL;
111 
112     font_data_key.font_name = font_name;
113 
114     font_data = (Font_data *) list_query(font_database, font_match,
115                                          (void *) &font_data_key);
116 
117     if (font_data)
118     {
119 
120         /****
121           format("Font: %s got from database.\n", font_name);
122           ****/
123     } else if (temp = gdk_font_load((gchar *)font_name))
124     {
125         font_data = ts_ralloc(Font_data);
126 
127         font_data->font_name = string_copy(font_name);
128         font_data->font      = temp;
129 
130         font_database = ref_addtostart(font_database, (void *) font_data, 0);
131     }
132                 /*
133                  *  failed to find None
134                  * 
135     return (font_data ? font_data->font : None);
136                 */
137     return (font_data ? font_data->font : NULL);
138 }
139 
140 
141 /* Set a named font in a graphics context.  Returns the font
142  * (or 0 if font_name not found).  
143  */
144 /**
145  * @brief  Set the named font in the specified graphics context.  
146  * @param  gc         Pointer to graphics context for which to set font.
147  * @param  font_name  String name of font.
148  * @return GdkFont *  Pointer to GdkFont to be set.
149  */
150 static GdkFont *named_font_set(GdkGC *gc, char *font_name)
151 {
152     GdkFont *font = NULL;
153 
154     if (!*font_name)
155     {
156         font_name = default_font_name;
157     }
158     font = font_find(font_name);
159 
160     if (font)
161     {
162         gdk_gc_set_font(gc, font);
163     } else
164     {
165         format("named_font_set: Can't find font: %s.\n", font_name);
166     }
167     return font;
168 }
169 
170 
171 /* Set a named font (char*) in a tv_screen.  Sets tv_screen->gc->font to
172  * the corresponding font (GdkFont*) */
173 /**
174  * @brief  Set a named font in the graphics context of a tv_screen.  
175  * @param  tv_screen  Pointer to Tv_screen for which to set font.
176  * @param  font_name  String name of font.
177  */
178 void    tv_screen_named_font_set(Tv_screen *tv_screen, char *font_name)
179 {
180     if (tv_screen)
181     {
182         GdkGC      *gc = tv_screen->gc;
183 
184         (void) named_font_set(gc, font_name);
185     }
186 }
187 
188 /**
189  * @brief  Get extents of string in named font on given Tv_screen.  
190  * @param  tv_screen  Pointer to Tv_screen for which to get string text extents.
191  * @param  font_name  String name of font.
192  * @param  string     String for which to get extents.
193  * @param  xmin       Pointer to store x-co-ordinate of left edge of string.
194  * @param  xmax       Pointer to store x-co-ordinate of right edge of string.
195  * @param  ymin       Pointer to store y-co-ordinate of bottom edge of string.
196  * @param  ymax       Pointer to store y-co-ordinate of top edge of string.
197  */
198 void    tv_screen_get_text_extent(Tv_screen *tv_screen, char *font_name, char *string, 
199                                   int *xmin, int *xmax, int *ymin, int *ymax)
200 {
201     if (!font_name || !*font_name)
202     {
203         font_name = default_font_name;
204     }
205     if (tv_screen)
206     {
207         GdkFont *font = font_find(font_name);
208         int      len, width;
209 
210         if (font)
211         {
212            len = strlen(string);
213            gdk_text_extents(font, (gchar *)string, (gint)len, xmin, xmax, &width, ymin, ymax);
214         }
215         else
216             *xmin = *xmax = *ymin = *ymax = 0;
217     } else
218     {
219         *xmin = *xmax = *ymin = *ymax = 0;
220     }
221 }
222 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.