filters
SFont.h
00001 //======================================================================== 00002 // 00003 // SFont.h 00004 // 00005 // Base class for font rasterizers. 00006 // 00007 // Copyright 2001-2002 Glyph & Cog, LLC 00008 // 00009 //======================================================================== 00010 00011 #ifndef SFONT_H 00012 #define SFONT_H 00013 00014 #include <aconf.h> 00015 00016 #ifdef USE_GCC_PRAGMAS 00017 #pragma interface 00018 #endif 00019 00020 #include <X11/Xlib.h> 00021 #include <X11/Xutil.h> 00022 #include "gtypes.h" 00023 #include "CharTypes.h" 00024 00025 class GfxState; 00026 00027 //------------------------------------------------------------------------ 00028 00029 class SFontEngine { 00030 public: 00031 00032 SFontEngine(Display *displayA, Visual *visualA, int depthA, 00033 Colormap colormapA); 00034 virtual ~SFontEngine(); 00035 00036 // Use a TrueColor visual. Pixel values are computed as: 00037 // 00038 // (r << rShift) + (g << gShift) + (b << bShift) 00039 // 00040 // where r, g, and b are scaled to the ranges [0,rMax], [0,gMax], 00041 // and [0,bMax], respectively. 00042 virtual void useTrueColor(int rMaxA, int rShiftA, int gMaxA, int gShiftA, 00043 int bMaxA, int bShiftA); 00044 00045 // Use an RGB color cube. <colors> is an array containing 00046 // <nRGB>*<nRGB>*<nRGB> pixel values in red,green,blue order, e.g., 00047 // for <nRGB>=2, there will be 8 entries: 00048 // 00049 // |--- colors[i] ---| 00050 // i red green blue 00051 // - ----- ----- ----- 00052 // 0 0000 0000 0000 00053 // 1 0000 0000 ffff 00054 // 2 0000 ffff 0000 00055 // 3 0000 ffff ffff 00056 // 4 ffff 0000 0000 00057 // 5 ffff 0000 ffff 00058 // 6 ffff ffff 0000 00059 // 7 ffff ffff ffff 00060 // 00061 // The <colors> array is not copied and must remain valid for the 00062 // lifetime of this SFont object. 00063 virtual void useColorCube(Gulong *colorsA, int nRGBA); 00064 00065 protected: 00066 00067 // Find the closest match to (<r>,<g>,<b>). 00068 Gulong findColor(int r, int g, int b); 00069 00070 //----- X parameters 00071 Display *display; 00072 Visual *visual; 00073 int depth; 00074 Colormap colormap; 00075 00076 GBool trueColor; // true for TrueColor, false for RGB cube 00077 00078 //----- TrueColor parameters 00079 int rMax, gMax, bMax; 00080 int rShift, gShift, bShift; 00081 00082 //----- RGB color cube parameters 00083 Gulong *colors; 00084 int nRGB; 00085 }; 00086 00087 //------------------------------------------------------------------------ 00088 00089 class SFontFile { 00090 public: 00091 00092 // A typical subclass will provide a constructor along the lines of: 00093 // 00094 // SomeFontFile(SomeFontEngine *engine, char *fontFileName); 00095 SFontFile(); 00096 00097 virtual ~SFontFile(); 00098 00099 private: 00100 }; 00101 00102 //------------------------------------------------------------------------ 00103 00104 class SFont { 00105 public: 00106 00107 // A typical subclass will provide a constructor along the lines of: 00108 // 00109 // SomeFont(SomeFontFile *fontFile, double *m); 00110 // 00111 // where <m> is a transform matrix consisting of four elements, 00112 // using the PostScript ordering conventions (without any 00113 // translation): 00114 // 00115 // [x' y'] = [x y] * [m0 m1] 00116 // [m2 m3] 00117 // 00118 // This is the level at which fonts are cached, and so the font 00119 // cannot be transformed after it is created. 00120 SFont(); 00121 00122 virtual ~SFont(); 00123 00124 // Draw a character <c>/<u> at <x>,<y> in color (<r>,<g>,<b>). The 00125 // RGB values should each be in the range [0,65535]. Draws into 00126 // <d>, clipped to the rectangle (0,0)-(<w>-1,<h>-1). Returns true 00127 // if the character was drawn successfully. 00128 virtual GBool drawChar(Drawable d, int w, int h, GC gc, 00129 int x, int y, int r, int g, int b, 00130 CharCode c, Unicode u) = 0; 00131 00132 // Add the outline of the specified character to the current path by 00133 // calling state->moveTo, lineTo, and curveTo. Returns true if 00134 // successful. If this SFont subclass doesn't implement character 00135 // paths, returns false immediately without modifying the current 00136 // path. 00137 virtual GBool getCharPath(CharCode c, Unicode u, GfxState *state); 00138 00139 protected: 00140 }; 00141 00142 #endif