bump product version to 7.2.5.1
[LibreOffice.git] / vcl / inc / unx / glyphcache.hxx
blobb41076844df253d68c55fe4f9937c5df547908be
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_INC_GENERIC_GLYPHCACHE_HXX
21 #define INCLUDED_VCL_INC_GENERIC_GLYPHCACHE_HXX
23 #include <memory>
24 #include <freetype/config/ftheader.h>
25 #include FT_FREETYPE_H
26 #include FT_GLYPH_H
28 #include <tools/gen.hxx>
29 #include <tools/solar.h>
30 #include <unx/gendata.hxx>
31 #include <vcl/dllapi.h>
32 #include <vcl/outdev.hxx>
34 #include <fontattributes.hxx>
35 #include <fontinstance.hxx>
36 #include <impfontmetricdata.hxx>
38 #include <unordered_map>
40 class FreetypeFont;
41 class FreetypeFontFile;
42 class FreetypeFontInstance;
43 class FreetypeFontInfo;
44 class FontConfigFontOptions;
45 class PhysicalFontCollection;
46 class FreetypeFont;
47 class SvpGcpHelper;
49 namespace basegfx { class B2DPolyPolygon; }
50 namespace vcl { struct FontCapabilities; }
52 /**
53 * The FreetypeManager caches various aspects of Freetype fonts
55 * It mainly consists of two std::unordered_map lists, which hold the items of the cache.
57 * They form kind of a tree, with FreetypeFontFile as the roots, referenced by multiple FreetypeFontInfo
58 * entries, which are referenced by the FreetypeFont items.
60 * All of these items have reference counters, but these don't control the items life-cycle, but that of
61 * the managed resources.
63 * The respective resources are:
64 * FreetypeFontFile = holds the mmapped font file, as long as it's used by any FreetypeFontInfo.
65 * FreetypeFontInfo = holds the FT_FaceRec_ object, as long as it's used by any FreetypeFont.
66 * FreetypeFont = holds the FT_SizeRec_ and is owned by a FreetypeFontInstance
68 * FreetypeFontInfo therefore is embedded in the Freetype subclass of PhysicalFontFace.
69 * FreetypeFont is owned by FreetypeFontInstance, the Freetype subclass of LogicalFontInstance.
71 * Nowadays there is not really a reason to have separate files for the classes, as the FreetypeManager
72 * is just about handling of Freetype based fonts, not some abstract glyphs.
73 **/
74 class VCL_DLLPUBLIC FreetypeManager final
76 public:
77 ~FreetypeManager();
79 static FreetypeManager& get();
81 void AddFontFile(const OString& rNormalizedName,
82 int nFaceNum, int nVariantNum,
83 sal_IntPtr nFontId,
84 const FontAttributes&);
86 void AnnounceFonts( PhysicalFontCollection* ) const;
88 void ClearFontCache();
90 FreetypeFont* CreateFont(FreetypeFontInstance* pLogicalFont);
92 private:
93 // to access the constructor (can't use InitFreetypeManager function, because it's private?!)
94 friend class GenericUnixSalData;
95 explicit FreetypeManager();
97 static void InitFreetype();
98 FreetypeFontFile* FindFontFile(const OString& rNativeFileName);
100 typedef std::unordered_map<sal_IntPtr, std::shared_ptr<FreetypeFontInfo>> FontInfoList;
101 typedef std::unordered_map<const char*, std::unique_ptr<FreetypeFontFile>, rtl::CStringHash, rtl::CStringEqual> FontFileList;
103 FontInfoList m_aFontInfoList;
104 sal_IntPtr m_nMaxFontId;
106 FontFileList m_aFontFileList;
109 class VCL_DLLPUBLIC FreetypeFont final
111 public:
112 ~FreetypeFont();
114 const OString& GetFontFileName() const;
115 int GetFontFaceIndex() const;
116 int GetFontFaceVariation() const;
117 bool TestFont() const { return mbFaceOk;}
118 FT_Face GetFtFace() const;
119 const FontConfigFontOptions* GetFontOptions() const;
120 bool NeedsArtificialBold() const { return mbArtBold; }
121 bool NeedsArtificialItalic() const { return mbArtItalic; }
123 void GetFontMetric(ImplFontMetricDataRef const &) const;
124 const unsigned char* GetTable( const char* pName, sal_uLong* pLength ) const;
125 const FontCharMapRef & GetFontCharMap() const;
126 bool GetFontCapabilities(vcl::FontCapabilities &) const;
128 bool GetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const;
129 bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const;
130 bool GetAntialiasAdvice() const;
132 void SetFontVariationsOnHBFont(hb_font_t* pHbFace) const;
134 // tdf#127189 FreeType <= 2.8 will fail to render stretched horizontal brace glyphs
135 // in starmath at a fairly low stretch ratio. This appears fixed in 2.9 with
136 // https://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=91015cb41d8f56777f93394f5a60914bc0c0f330
137 // "Improve complex rendering at high ppem"
138 static bool AlmostHorizontalDrainsRenderingPool(int nRatio, const FontSelectPattern& rFSD);
140 private:
141 friend class FreetypeFontInstance;
142 friend class FreetypeManager;
144 explicit FreetypeFont(FreetypeFontInstance&, const std::shared_ptr<FreetypeFontInfo>& rFontInfo);
146 void ApplyGlyphTransform(bool bVertical, FT_Glyph) const;
148 FreetypeFontInstance& mrFontInstance;
150 // 16.16 fixed point values used for a rotated font
151 tools::Long mnCos;
152 tools::Long mnSin;
154 int mnWidth;
155 int mnPrioAntiAlias;
156 std::shared_ptr<FreetypeFontInfo> mxFontInfo;
157 FT_Int mnLoadFlags;
158 double mfStretch;
159 FT_FaceRec_* maFaceFT;
160 FT_SizeRec_* maSizeFT;
162 mutable std::unique_ptr<FontConfigFontOptions> mxFontOptions;
164 bool mbFaceOk;
165 bool mbArtItalic;
166 bool mbArtBold;
169 #endif // INCLUDED_VCL_INC_GENERIC_GLYPHCACHE_HXX
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */