Debian Codegraph @

libs/xpdf/xpdf-src/splash/SplashFont.h

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