/src/libreoffice/vcl/inc/unx/glyphcache.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <sal/config.h> |
23 | | |
24 | | #include <memory> |
25 | | #include <freetype/config/ftheader.h> |
26 | | #include FT_FREETYPE_H |
27 | | #include FT_GLYPH_H |
28 | | |
29 | | #include <vcl/dllapi.h> |
30 | | #include <vcl/outdev.hxx> |
31 | | |
32 | | #include <fontattributes.hxx> |
33 | | #include <font/FontMetricData.hxx> |
34 | | #include <glyphid.hxx> |
35 | | |
36 | | #include <unordered_map> |
37 | | |
38 | | class FreetypeFont; |
39 | | class FreetypeFontFile; |
40 | | class FreetypeFontInstance; |
41 | | class FreetypeFontInfo; |
42 | | class FontConfigFontOptions; |
43 | | namespace vcl::font |
44 | | { |
45 | | class PhysicalFontCollection; |
46 | | } |
47 | | |
48 | | namespace basegfx { class B2DPolyPolygon; } |
49 | | |
50 | | /** |
51 | | * The FreetypeManager caches various aspects of Freetype fonts |
52 | | * |
53 | | * It mainly consists of two std::unordered_map lists, which hold the items of the cache. |
54 | | * |
55 | | * They form kind of a tree, with FreetypeFontFile as the roots, referenced by multiple FreetypeFontInfo |
56 | | * entries, which are referenced by the FreetypeFont items. |
57 | | * |
58 | | * All of these items have reference counters, but these don't control the items life-cycle, but that of |
59 | | * the managed resources. |
60 | | * |
61 | | * The respective resources are: |
62 | | * FreetypeFontFile = holds the mmapped font file, as long as it's used by any FreetypeFontInfo. |
63 | | * FreetypeFontInfo = holds the FT_FaceRec_ object, as long as it's used by any FreetypeFont. |
64 | | * FreetypeFont = holds the FT_SizeRec_ and is owned by a FreetypeFontInstance |
65 | | * |
66 | | * FreetypeFontInfo therefore is embedded in the Freetype subclass of PhysicalFontFace. |
67 | | * FreetypeFont is owned by FreetypeFontInstance, the Freetype subclass of LogicalFontInstance. |
68 | | * |
69 | | * Nowadays there is not really a reason to have separate files for the classes, as the FreetypeManager |
70 | | * is just about handling of Freetype based fonts, not some abstract glyphs. |
71 | | **/ |
72 | | class VCL_DLLPUBLIC FreetypeManager final |
73 | | { |
74 | | public: |
75 | | FreetypeManager(const FreetypeManager&) = delete; |
76 | | FreetypeManager& operator=(const FreetypeManager&) = delete; |
77 | | |
78 | | SAL_DLLPRIVATE ~FreetypeManager(); |
79 | | |
80 | | static FreetypeManager& get(); |
81 | | |
82 | | void AddFontFile(const OString& rNormalizedName, |
83 | | int nFaceNum, int nVariantNum, |
84 | | sal_IntPtr nFontId, |
85 | | const FontAttributes&); |
86 | | void RemoveFontFile(sal_IntPtr nFontId); |
87 | | |
88 | | SAL_DLLPRIVATE void AnnounceFonts( vcl::font::PhysicalFontCollection* ) const; |
89 | | |
90 | | void ClearFontCache(); |
91 | | |
92 | | SAL_DLLPRIVATE FreetypeFont* CreateFont(FreetypeFontInstance& rLogicalFont); |
93 | | |
94 | | private: |
95 | | // to access the constructor |
96 | | friend class GenericUnixSalData; |
97 | | SAL_DLLPRIVATE explicit FreetypeManager(); |
98 | | |
99 | | SAL_DLLPRIVATE static void InitFreetype(); |
100 | | SAL_DLLPRIVATE FreetypeFontFile* FindFontFile(const OString& rNativeFileName); |
101 | | |
102 | | typedef std::unordered_map<sal_IntPtr, std::shared_ptr<FreetypeFontInfo>> FontInfoList; |
103 | | typedef std::unordered_map<const char*, std::unique_ptr<FreetypeFontFile>, rtl::CStringHash, rtl::CStringEqual> FontFileList; |
104 | | |
105 | | FontInfoList m_aFontInfoList; |
106 | | |
107 | | FontFileList m_aFontFileList; |
108 | | }; |
109 | | |
110 | | class VCL_DLLPUBLIC FreetypeFont final |
111 | | { |
112 | | public: |
113 | | SAL_DLLPRIVATE ~FreetypeFont(); |
114 | | |
115 | | SAL_DLLPRIVATE const OString& GetFontFileName() const; |
116 | | SAL_DLLPRIVATE int GetFontFaceIndex() const; |
117 | | SAL_DLLPRIVATE int GetFontFaceVariation() const; |
118 | 4.67M | bool TestFont() const { return mbFaceOk;} |
119 | | SAL_DLLPRIVATE FT_Face GetFtFace() const; |
120 | | const FontConfigFontOptions* GetFontOptions() const; |
121 | | |
122 | | SAL_DLLPRIVATE void GetFontMetric(FontMetricDataRef const &) const; |
123 | | |
124 | | SAL_DLLPRIVATE bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const; |
125 | | bool GetAntialiasAdvice() const; |
126 | | |
127 | | private: |
128 | | friend class FreetypeFontInstance; |
129 | | friend class FreetypeManager; |
130 | | |
131 | | SAL_DLLPRIVATE explicit FreetypeFont(FreetypeFontInstance&, std::shared_ptr<FreetypeFontInfo> rFontInfo); |
132 | | |
133 | | SAL_DLLPRIVATE void ApplyGlyphTransform(bool bVertical, FT_Glyph) const; |
134 | | |
135 | | FreetypeFontInstance& mrFontInstance; |
136 | | |
137 | | // 16.16 fixed point values used for a rotated font |
138 | | tools::Long mnCos; |
139 | | tools::Long mnSin; |
140 | | |
141 | | int mnWidth; |
142 | | int mnPrioAntiAlias; |
143 | | std::shared_ptr<FreetypeFontInfo> mxFontInfo; |
144 | | double mfStretch; |
145 | | FT_FaceRec_* maFaceFT; |
146 | | FT_SizeRec_* maSizeFT; |
147 | | |
148 | | mutable std::unique_ptr<FontConfigFontOptions> mxFontOptions; |
149 | | |
150 | | bool mbFaceOk; |
151 | | }; |
152 | | |
153 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |