fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

fl_set_font.cxx
Go to the documentation of this file.
1 //
2 // "$Id$"
3 //
4 // Font utilities for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
19 // Add a font to the internal table.
20 // Also see fl_set_fonts.cxx which adds all possible fonts.
21 
22 #include <FL/Fl.H>
23 #include <FL/x.H>
24 #include <FL/fl_draw.H>
25 #include "flstring.h"
26 #include "Fl_Font.H"
27 #include <stdlib.h>
28 
29 static int table_size;
34 void Fl::set_font(Fl_Font fnum, const char* name) {
35 #ifdef __APPLE__
36  if (!fl_fonts) fl_fonts = Fl_X::calc_fl_fonts();
37 #endif
38  while (fnum >= table_size) {
39  int i = table_size;
40  if (!i) { // don't realloc the built-in table
42  i = FL_FREE_FONT;
44  memcpy(t, fl_fonts, FL_FREE_FONT*sizeof(Fl_Fontdesc));
45  fl_fonts = t;
46  } else {
49  }
50  for (; i < table_size; i++) {
51  fl_fonts[i].fontname[0] = 0;
52  fl_fonts[i].name = 0;
53 #if !defined(WIN32) && !defined(__APPLE__)
54  fl_fonts[i].xlist = 0;
55  fl_fonts[i].n = 0;
56 #endif // !WIN32 && !__APPLE__
57  }
58  }
59  Fl_Fontdesc* s = fl_fonts+fnum;
60  if (s->name) {
61  if (!strcmp(s->name, name)) {s->name = name; return;}
62 #if !defined(WIN32) && !defined(__APPLE__)
63  if (s->xlist && s->n >= 0) XFreeFontNames(s->xlist);
64 #endif
65  for (Fl_Font_Descriptor* f = s->first; f;) {
66  Fl_Font_Descriptor* n = f->next; delete f; f = n;
67  }
68  s->first = 0;
69  }
70  s->name = name;
71  s->fontname[0] = 0;
72 #if !defined(WIN32) && !defined(__APPLE__)
73  s->xlist = 0;
74 #endif
75  s->first = 0;
76  Fl_Display_Device::display_device()->driver()->font(-1, 0);
77 }
79 void Fl::set_font(Fl_Font fnum, Fl_Font from) {
80  Fl::set_font(fnum, get_font(from));
81 }
87 const char* Fl::get_font(Fl_Font fnum) {
88 #ifdef __APPLE__
89  if (!fl_fonts) fl_fonts = Fl_X::calc_fl_fonts();
90 #endif
91  return fl_fonts[fnum].name;
92 }
93 
94 //
95 // End of "$Id$".
96 //
Fl.H
table_size
static int table_size
Definition: fl_set_font.cxx:29
Fl_Fontdesc
Definition: Fl_Font.H:86
Fl_Fontdesc::n
int n
Definition: Fl_Font.H:92
x.H
Fl_Fontdesc::xlist
char ** xlist
Definition: Fl_Font.H:91
Fl_Display_Device::display_device
static Fl_Display_Device * display_device()
Definition: Fl_Device.cxx:83
Fl_Fontdesc::name
const char * name
Definition: Fl_Font.H:87
Fl::get_font
static const char * get_font(Fl_Font)
Definition: fl_set_font.cxx:87
Fl_Surface_Device::driver
void driver(Fl_Graphics_Driver *graphics_driver)
Sets the graphics driver of this drawing surface.
Definition: Fl_Device.H:569
FL_FREE_FONT
const Fl_Font FL_FREE_FONT
first one to allocate
Definition: Enumerations.H:896
fl_draw.H
utility header to pull drawing functions together
Fl_Fontdesc::fontname
char fontname[128]
Definition: Fl_Font.H:88
Fl_Fontdesc::first
Fl_Font_Descriptor * first
Definition: Fl_Font.H:89
Fl::set_font
static void set_font(Fl_Font, const char *)
Definition: fl_set_font.cxx:34
Fl_Font
int Fl_Font
Definition: Enumerations.H:877
f
Fl_Box_Draw_F * f
Definition: fl_boxtype.cxx:285
malloc
voidp malloc()
flstring.h
fl_fonts
FL_EXPORT Fl_Fontdesc * fl_fonts
Definition: fl_font_mac.cxx:22
name
static const char * name
Definition: Fl_arg.cxx:53
Fl_Font.H
Fl_Font_Descriptor
Definition: Fl_Font.H:41