00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __RE_OGLTextureFont__
00023 #define __RE_OGLTextureFont__
00024
00025 #include "RE_API.h"
00026
00027 #include <SYS/SYS_Types.h>
00028 #include <SYS/SYS_Math.h>
00029
00030 #include <UT/UT_AssocArray.h>
00031 #include <UT/UT_RefArray.h>
00032
00033 #include "RE_OGLFont.h"
00034
00035 class RE_OGLFontCache;
00036 class RE_Render;
00037 class re_DeferTexFont;
00038
00039 #define RE_TEXTURE_FONT_LOW_CODEPOINTS 256
00040
00041 struct reGlyphInfo
00042 {
00043 reGlyphInfo()
00044 : myBearingX(0),
00045 myBearingY(0),
00046 myAdvanceX(0),
00047 myGlyphWidth(0),
00048 myGlyphHeight(0),
00049 myGlyphData(NULL),
00050 myDisplayList(0),
00051 myTextureIndex(0)
00052 {}
00053
00054 ~reGlyphInfo()
00055 {
00056 delete[] myGlyphData;
00057 }
00058
00059
00060
00061 int myBearingX;
00062
00063
00064
00065 int myBearingY;
00066
00067
00068
00069
00070
00071 int myAdvanceX;
00072
00073
00074
00075
00076
00077 int myGlyphWidth, myGlyphHeight;
00078
00079
00080 double myStartS, myEndS;
00081 double myStartT, myEndT;
00082
00083
00084 unsigned char *myGlyphData;
00085
00086
00087
00088 int myTextureIndex;
00089
00090
00091 int myDisplayList;
00092 };
00093
00094 class RE_API RE_OGLTextureFont : public RE_OGLFont
00095 {
00096 public:
00097 RE_OGLTextureFont(const char *name, float size,
00098 RE_OGLFontCache *cache);
00099 virtual ~RE_OGLTextureFont();
00100
00101 virtual void render(RE_Render *r, const char *s);
00102 virtual int getCharWidth(char c, char prev);
00103 virtual int getStringWidth(const char *s);
00104
00105 template <typename T>
00106 static bool loadFontFile(const char *filename, T *owner);
00107
00108 typedef UT_AssocArray<int, reGlyphInfo> reGlyphInfoArray;
00109 typedef UT_AssocArray<int, int8> reGlyphKerningArray;
00110 typedef UT_AssocArray<int, reGlyphKerningArray> reKerningArray;
00111
00112 typedef UT_RefArray<reGlyphInfo> reLowGlyphInfoArray;
00113 typedef UT_RefArray<int8> reLowGlyphKerningArray;
00114 typedef UT_RefArray<reLowGlyphKerningArray> reLowKerningArray;
00115
00116 static void beginFontDefer(RE_Render *r);
00117 static void flushFontDefer(RE_Render *r);
00118 static void endFontDefer(RE_Render *r);
00119 protected:
00120
00121 virtual void loadFont();
00122 virtual void genDisplayLists(RE_Render *r);
00123
00124 private:
00125 template <typename T>
00126 static bool loadGlyph(int codepoint, UT_IStream &in, T *owner);
00127
00128 static void processDeferredFonts(RE_Render *r,
00129 re_DeferTexFont *font);
00130
00131
00132
00133
00134 reGlyphInfo &newGlyphInfo(int codepoint);
00135
00136 bool loadFont(const char *fontname);
00137 void createTextures(RE_Render *r);
00138 void doRenderGlyph(RE_Render *r,
00139 const reGlyphInfo &gi) const;
00140
00141
00142
00143 int getKerning(int left, int right) const;
00144
00145 void initGlyphTexture(reGlyphInfo &gi,
00146 unsigned char *texbuf,
00147 int &curx, int &pos,
00148 int texwidth, int texheight);
00149
00150 private:
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 reGlyphInfoArray myGlyphInfo;
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 reKerningArray myKerningInfo;
00175
00176
00177
00178
00179
00180 reLowGlyphInfoArray myLowGlyphInfo;
00181
00182
00183
00184
00185 reLowKerningArray myLowKerningInfo;
00186
00187
00188 bool myTexturesCreated;
00189
00190
00191
00192 UT_RefArray<uint> myTextureIDs;
00193
00194
00195 int myFaceHeight;
00196
00197
00198 static UT_String ourFontDirectory;
00199 };
00200
00201 #include "RE_OGLTextureFontTemplate.C"
00202
00203 #endif