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