1//========================================================================
2//
3// SplashFont.h
4//
5//========================================================================
6
7//========================================================================
8//
9// Modified under the Poppler project - http://poppler.freedesktop.org
10//
11// All changes made under the Poppler project to this file are licensed
12// under GPL version 2 or later
13//
14// Copyright (C) 2007-2008, 2018, 2019 Albert Astals Cid <aacid@kde.org>
15// Copyright (C) 2018 Oliver Sander <oliver.sander@tu-dresden.de>
16//
17// To see a description of the changes please see the Changelog file that
18// came with your tarball or type make ChangeLog if you are building from git
19//
20//========================================================================
21
22#ifndef SPLASHFONT_H
23#define SPLASHFONT_H
24
25#include "SplashTypes.h"
26#include "SplashClip.h"
27
28struct SplashGlyphBitmap;
29struct SplashFontCacheTag;
30class SplashFontFile;
31class SplashPath;
32
33//------------------------------------------------------------------------
34
35// Fractional positioning uses this many bits to the right of the
36// decimal points.
37#define splashFontFractionBits 2
38#define splashFontFraction (1 << splashFontFractionBits)
39#define splashFontFractionMul ((SplashCoord)1 / (SplashCoord)splashFontFraction)
40
41//------------------------------------------------------------------------
42// SplashFont
43//------------------------------------------------------------------------
44
45class SplashFont
46{
47public:
48 SplashFont(SplashFontFile *fontFileA, const SplashCoord *matA, const SplashCoord *textMatA, bool aaA);
49
50 // This must be called after the constructor, so that the subclass
51 // constructor has a chance to compute the bbox.
52 void initCache();
53
54 virtual ~SplashFont();
55
56 SplashFont(const SplashFont &) = delete;
57 SplashFont &operator=(const SplashFont &) = delete;
58
59 SplashFontFile *getFontFile() { return fontFile; }
60
61 // Return true if <this> matches the specified font file and matrix.
62 bool matches(SplashFontFile *fontFileA, const SplashCoord *matA, const SplashCoord *textMatA) const
63 {
64 return fontFileA == fontFile && matA[0] == mat[0] && matA[1] == mat[1] && matA[2] == mat[2] && matA[3] == mat[3] && textMatA[0] == textMat[0] && textMatA[1] == textMat[1] && textMatA[2] == textMat[2] && textMatA[3] == textMat[3];
65 }
66
67 // Get a glyph - this does a cache lookup first, and if not found,
68 // creates a new bitmap and adds it to the cache. The <xFrac> and
69 // <yFrac> values are splashFontFractionBits bits each, representing
70 // the numerators of fractions in [0, 1), where the denominator is
71 // splashFontFraction = 1 << splashFontFractionBits. Subclasses
72 // should override this to zero out xFrac and/or yFrac if they don't
73 // support fractional coordinates.
74 virtual bool getGlyph(int c, int xFrac, int yFrac, SplashGlyphBitmap *bitmap, int x0, int y0, SplashClip *clip, SplashClipResult *clipRes);
75
76 // Rasterize a glyph. The <xFrac> and <yFrac> values are the same
77 // as described for getGlyph.
78 virtual bool makeGlyph(int c, int xFrac, int yFrac, SplashGlyphBitmap *bitmap, int x0, int y0, SplashClip *clip, SplashClipResult *clipRes) = 0;
79
80 // Return the path for a glyph.
81 virtual SplashPath *getGlyphPath(int c) = 0;
82
83 // Return the advance of a glyph. (in 0..1 range)
84 // < 0 means not known
85 virtual double getGlyphAdvance(int c) { return -1; }
86
87 // Return the font transform matrix.
88 SplashCoord *getMatrix() { return mat; }
89
90 // Return the glyph bounding box.
91 void getBBox(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA)
92 {
93 *xMinA = xMin;
94 *yMinA = yMin;
95 *xMaxA = xMax;
96 *yMaxA = yMax;
97 }
98
99protected:
100 SplashFontFile *fontFile;
101 SplashCoord mat[4]; // font transform matrix
102 // (text space -> device space)
103 SplashCoord textMat[4]; // text transform matrix
104 // (text space -> user space)
105 bool aa; // anti-aliasing
106 int xMin, yMin, xMax, yMax; // glyph bounding box
107 unsigned char *cache; // glyph bitmap cache
108 SplashFontCacheTag * // cache tags
109 cacheTags;
110 int glyphW, glyphH; // size of glyph bitmaps
111 int glyphSize; // size of glyph bitmaps, in bytes
112 int cacheSets; // number of sets in cache
113 int cacheAssoc; // cache associativity (glyphs per set)
114};
115
116#endif
117

source code of poppler/splash/SplashFont.h