00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc 00008 * 123 Front Street West, Suite 1401 00009 * Toronto, Ontario 00010 * Canada M5J 2M2 00011 * 416-504-9876 00012 * 00013 * NAME: RE_OGLBitmapFont.h (RE Library, C++) 00014 * 00015 * COMMENTS: 00016 * This class is the owner and renderer of bitmap fonts - that is, fonts 00017 * which are rendered by calling glBitmap. This is as opposed to texture 00018 * fonts, which are rendered by making textured quads. 00019 */ 00020 00021 #ifndef __RE_OGLBitmapFont__ 00022 #define __RE_OGLBitmapFont__ 00023 00024 #include "RE_API.h" 00025 #include "RE_OGLFont.h" 00026 00027 class RE_OGLFontCache; 00028 class RE_OGLBitmapFontGlyph; 00029 class RE_Render; 00030 00031 class RE_API RE_OGLBitmapFont : public RE_OGLFont 00032 { 00033 public: 00034 00035 RE_OGLBitmapFont(const char *name, float size, RE_OGLFontCache *cache); 00036 00037 ~RE_OGLBitmapFont(); 00038 00039 /// These three are overridden from RE_Font. See RE_Font for a description. 00040 virtual void render(RE_Render *r, const char *s); 00041 virtual int getCharWidth(char c, char /* prev */); 00042 virtual int getStringWidth(const char *s); 00043 00044 protected: 00045 00046 /// Overridden from RE_Font. See RE_Font for a description. 00047 virtual void loadFont(); 00048 00049 /// Overridden from RE_OGLFont. See RE_OGLFont for a description. 00050 virtual void genDisplayLists(RE_Render *r); 00051 00052 private: // functions 00053 00054 /// Load the font named name (of the form basename.size, eg Screen.10) 00055 /// and initialize this object using it. Returns true on success, false 00056 /// otherwise. 00057 bool loadFontFromFile(const char *name); 00058 00059 // Helper functions for loadFont() - binary font files. 00060 /// Given an open file pointer to a binary font file, reads a file and 00061 /// initializes this font object. Returns the number of glyphs in the 00062 /// font, or 0 if none were found or an error occurred. 00063 int readBinaryFont(FILE *fp); 00064 00065 /// Load the rasters from a binary font file. The file must already 00066 /// be at the rasters' position. n is the number of shorts to read, 00067 /// aka the raster size. 00068 /// Returns a pointer to the raster data, which the caller must free. 00069 unsigned short *loadBinRasters(int n, FILE *fp); 00070 00071 /// Load the characters from a binary font file. The file must already 00072 /// be at the character's position. nglyphs is the number of glyphs to 00073 /// load. 00074 /// Returns a pointer to the font character array, which the caller 00075 /// must free. 00076 RE_OGLBitmapFontGlyph *loadBinFontchars(int nglyphs, FILE *fp); 00077 00078 // Helper functions for loadFont() - text font files. 00079 /// Given an open file pointer to a text font file, reads a file and 00080 /// initializes this font object. Returns the number of glyphs in the 00081 /// font, or 0 if none were found or an error occurred. 00082 /// Also pass in the filename, for error reporting. 00083 int readTextFont(FILE *fp, const char *filename); 00084 00085 /// Load the rasters from a text font file. The file must already 00086 /// be at the rasters' position. n is the number of shorts to read, 00087 /// aka the raster size. 00088 /// Also pass in the current line number and filename, for error reporting. 00089 /// Returns a pointer to the raster data, which the caller must free. 00090 unsigned short *loadTextRasters(int n, FILE *fp, int *linep, 00091 const char *filename); 00092 00093 /// Load the characters from a text font file. The file must already 00094 /// be at the character's position. nglyphs is the number of glyphs to 00095 /// load. 00096 /// Also pass in the current line number and filename, for error reporting. 00097 /// Returns a pointer to the font character array, which the caller 00098 /// must free. 00099 RE_OGLBitmapFontGlyph *loadTextFontchars(int nglyphs, FILE *fp, 00100 int *linep, 00101 const char *filename); 00102 00103 private: // variables 00104 00105 /// The information (width, height, etc) about every glyph in the font. 00106 RE_OGLBitmapFontGlyph *myFontStats; 00107 00108 /// The rasterized font. Font glyphs store their index into this array. 00109 unsigned short *myFontRasters; 00110 00111 /// The directory where all bitmap fonts are stored. 00112 static UT_String ourFontDirectory; 00113 }; 00114 00115 #endif
1.5.9