/src/xpdf-4.04/splash/SplashFont.h
Line | Count | Source (jump to first uncovered line) |
1 | | //======================================================================== |
2 | | // |
3 | | // SplashFont.h |
4 | | // |
5 | | // Copyright 2003-2013 Glyph & Cog, LLC |
6 | | // |
7 | | //======================================================================== |
8 | | |
9 | | #ifndef SPLASHFONT_H |
10 | | #define SPLASHFONT_H |
11 | | |
12 | | #include <aconf.h> |
13 | | |
14 | | #ifdef USE_GCC_PRAGMAS |
15 | | #pragma interface |
16 | | #endif |
17 | | |
18 | | #include "gtypes.h" |
19 | | #include "SplashTypes.h" |
20 | | #include "SplashMath.h" |
21 | | |
22 | | struct SplashGlyphBitmap; |
23 | | struct SplashFontCacheTag; |
24 | | class SplashFontFile; |
25 | | class SplashPath; |
26 | | |
27 | | //------------------------------------------------------------------------ |
28 | | |
29 | | // Fractional positioning uses this many bits to the right of the |
30 | | // decimal points. |
31 | 0 | #define splashFontFractionBits 2 |
32 | 0 | #define splashFontFraction (1 << splashFontFractionBits) |
33 | | #define splashFontFractionMul \ |
34 | 0 | ((SplashCoord)1 / (SplashCoord)splashFontFraction) |
35 | | |
36 | | //------------------------------------------------------------------------ |
37 | | // SplashFont |
38 | | //------------------------------------------------------------------------ |
39 | | |
40 | | class SplashFont { |
41 | | public: |
42 | | |
43 | | SplashFont(SplashFontFile *fontFileA, SplashCoord *matA, |
44 | | SplashCoord *textMatA, GBool aaA); |
45 | | |
46 | | // This must be called after the constructor, so that the subclass |
47 | | // constructor has a chance to compute the bbox. |
48 | | void initCache(); |
49 | | |
50 | | virtual ~SplashFont(); |
51 | | |
52 | 0 | SplashFontFile *getFontFile() { return fontFile; } |
53 | | |
54 | | // Return true if <this> matches the specified font file and matrix. |
55 | | GBool matches(SplashFontFile *fontFileA, SplashCoord *matA, |
56 | 0 | SplashCoord *textMatA) { |
57 | 0 | return fontFileA == fontFile && |
58 | 0 | splashAbs(matA[0] - mat[0]) < 0.0001 && |
59 | 0 | splashAbs(matA[1] - mat[1]) < 0.0001 && |
60 | 0 | splashAbs(matA[2] - mat[2]) < 0.0001 && |
61 | 0 | splashAbs(matA[3] - mat[3]) < 0.0001 && |
62 | 0 | splashAbs(textMatA[0] - textMat[0]) < 0.0001 && |
63 | 0 | splashAbs(textMatA[1] - textMat[1]) < 0.0001 && |
64 | 0 | splashAbs(textMatA[2] - textMat[2]) < 0.0001 && |
65 | 0 | splashAbs(textMatA[3] - textMat[3]) < 0.0001; |
66 | 0 | } |
67 | | |
68 | | // Get a glyph - this does a cache lookup first, and if not found, |
69 | | // creates a new bitmap and adds it to the cache. The <xFrac> and |
70 | | // <yFrac> values are splashFontFractionBits bits each, representing |
71 | | // the numerators of fractions in [0, 1), where the denominator is |
72 | | // splashFontFraction = 1 << splashFontFractionBits. Subclasses |
73 | | // should override this to zero out xFrac and/or yFrac if they don't |
74 | | // support fractional coordinates. |
75 | | virtual GBool getGlyph(int c, int xFrac, int yFrac, |
76 | | SplashGlyphBitmap *bitmap); |
77 | | |
78 | | // Rasterize a glyph. The <xFrac> and <yFrac> values are the same |
79 | | // as described for getGlyph. |
80 | | virtual GBool makeGlyph(int c, int xFrac, int yFrac, |
81 | | SplashGlyphBitmap *bitmap) = 0; |
82 | | |
83 | | // Return the path for a glyph. |
84 | | virtual SplashPath *getGlyphPath(int c) = 0; |
85 | | |
86 | | // Return the font transform matrix. |
87 | 0 | SplashCoord *getMatrix() { return mat; } |
88 | | |
89 | | // Return the glyph bounding box. |
90 | | void getBBox(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA) |
91 | 0 | { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; } |
92 | | |
93 | | protected: |
94 | | |
95 | | SplashFontFile *fontFile; |
96 | | SplashCoord mat[4]; // font transform matrix |
97 | | // (text space -> device space) |
98 | | SplashCoord textMat[4]; // text transform matrix |
99 | | // (text space -> user space) |
100 | | GBool aa; // anti-aliasing |
101 | | int xMin, yMin, xMax, yMax; // glyph bounding box |
102 | | Guchar *cache; // glyph bitmap cache |
103 | | SplashFontCacheTag * // cache tags |
104 | | cacheTags; |
105 | | int glyphW, glyphH; // size of glyph bitmaps |
106 | | int glyphSize; // size of glyph bitmaps, in bytes |
107 | | int cacheSets; // number of sets in cache |
108 | | int cacheAssoc; // cache associativity (glyphs per set) |
109 | | }; |
110 | | |
111 | | #endif |