|
fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) ![]() |
00001 // 00002 // "$Id: fl_set_font.cxx 7903 2010-11-28 21:06:39Z matt $" 00003 // 00004 // Font utilities for the Fast Light Tool Kit (FLTK). 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library 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 GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00027 00028 // Add a font to the internal table. 00029 // Also see fl_set_fonts.cxx which adds all possible fonts. 00030 00031 #include <FL/Fl.H> 00032 #include <FL/x.H> 00033 #include <FL/fl_draw.H> 00034 #include "flstring.h" 00035 #include "Fl_Font.H" 00036 #include <stdlib.h> 00037 00038 static int table_size; 00043 void Fl::set_font(Fl_Font fnum, const char* name) { 00044 while (fnum >= table_size) { 00045 int i = table_size; 00046 if (!i) { // don't realloc the built-in table 00047 table_size = 2*FL_FREE_FONT; 00048 i = FL_FREE_FONT; 00049 Fl_Fontdesc* t = (Fl_Fontdesc*)malloc(table_size*sizeof(Fl_Fontdesc)); 00050 memcpy(t, fl_fonts, FL_FREE_FONT*sizeof(Fl_Fontdesc)); 00051 fl_fonts = t; 00052 } else { 00053 table_size = 2*table_size; 00054 fl_fonts=(Fl_Fontdesc*)realloc(fl_fonts, table_size*sizeof(Fl_Fontdesc)); 00055 } 00056 for (; i < table_size; i++) { 00057 fl_fonts[i].fontname[0] = 0; 00058 fl_fonts[i].name = 0; 00059 #if !defined(WIN32) && !defined(__APPLE__) 00060 fl_fonts[i].xlist = 0; 00061 fl_fonts[i].n = 0; 00062 #endif // !WIN32 && !__APPLE__ 00063 } 00064 } 00065 Fl_Fontdesc* s = fl_fonts+fnum; 00066 if (s->name) { 00067 if (!strcmp(s->name, name)) {s->name = name; return;} 00068 #if !defined(WIN32) && !defined(__APPLE__) 00069 if (s->xlist && s->n >= 0) XFreeFontNames(s->xlist); 00070 #endif 00071 for (Fl_Font_Descriptor* f = s->first; f;) { 00072 Fl_Font_Descriptor* n = f->next; delete f; f = n; 00073 } 00074 s->first = 0; 00075 } 00076 s->name = name; 00077 s->fontname[0] = 0; 00078 #if !defined(WIN32) && !defined(__APPLE__) 00079 s->xlist = 0; 00080 #endif 00081 s->first = 0; 00082 fl_font(-1, 0); 00083 } 00085 void Fl::set_font(Fl_Font fnum, Fl_Font from) { 00086 Fl::set_font(fnum, get_font(from)); 00087 } 00093 const char* Fl::get_font(Fl_Font fnum) {return fl_fonts[fnum].name;} 00094 00095 // 00096 // End of "$Id: fl_set_font.cxx 7903 2010-11-28 21:06:39Z matt $". 00097 //