2 // "$Id: fl_set_font.cxx 7903 2010-11-28 21:06:39Z matt $"
4 // Font utilities for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // Add a font to the internal table.
29 // Also see fl_set_fonts.cxx which adds all possible fonts.
33 #include <FL/fl_draw.H>
38 static int table_size
;
40 Changes a face. The string pointer is simply stored,
41 the string is not copied, so the string must be in static memory.
43 void Fl::set_font(Fl_Font fnum
, const char* name
) {
44 while (fnum
>= table_size
) {
46 if (!i
) { // don't realloc the built-in table
47 table_size
= 2*FL_FREE_FONT
;
49 Fl_Fontdesc
* t
= (Fl_Fontdesc
*)malloc(table_size
*sizeof(Fl_Fontdesc
));
50 memcpy(t
, fl_fonts
, FL_FREE_FONT
*sizeof(Fl_Fontdesc
));
53 table_size
= 2*table_size
;
54 fl_fonts
=(Fl_Fontdesc
*)realloc(fl_fonts
, table_size
*sizeof(Fl_Fontdesc
));
56 for (; i
< table_size
; i
++) {
57 fl_fonts
[i
].fontname
[0] = 0;
59 #if !defined(WIN32) && !defined(__APPLE__)
60 fl_fonts
[i
].xlist
= 0;
62 #endif // !WIN32 && !__APPLE__
65 Fl_Fontdesc
* s
= fl_fonts
+fnum
;
67 if (!strcmp(s
->name
, name
)) {s
->name
= name
; return;}
68 #if !defined(WIN32) && !defined(__APPLE__)
69 if (s
->xlist
&& s
->n
>= 0) XFreeFontNames(s
->xlist
);
71 for (Fl_Font_Descriptor
* f
= s
->first
; f
;) {
72 Fl_Font_Descriptor
* n
= f
->next
; delete f
; f
= n
;
78 #if !defined(WIN32) && !defined(__APPLE__)
84 /** Copies one face to another. */
85 void Fl::set_font(Fl_Font fnum
, Fl_Font from
) {
86 Fl::set_font(fnum
, get_font(from
));
89 Gets the string for this face. This string is different for each
90 face. Under X this value is passed to XListFonts to get all the sizes
93 const char* Fl::get_font(Fl_Font fnum
) {return fl_fonts
[fnum
].name
;}
96 // End of "$Id: fl_set_font.cxx 7903 2010-11-28 21:06:39Z matt $".