tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / vcl / inc / unx / glyphcache.hxx
bloba469f628a873ae163ccf9babb9e7348a04da2612
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 #pragma once
22 #include <sal/config.h>
24 #include <memory>
25 #include <freetype/config/ftheader.h>
26 #include FT_FREETYPE_H
27 #include FT_GLYPH_H
29 #include <vcl/dllapi.h>
30 #include <vcl/outdev.hxx>
32 #include <fontattributes.hxx>
33 #include <font/FontMetricData.hxx>
34 #include <glyphid.hxx>
36 #include <unordered_map>
38 class FreetypeFont;
39 class FreetypeFontFile;
40 class FreetypeFontInstance;
41 class FreetypeFontInfo;
42 class FontConfigFontOptions;
43 namespace vcl::font
45 class PhysicalFontCollection;
47 class FreetypeFont;
48 class SvpGcpHelper;
50 namespace basegfx { class B2DPolyPolygon; }
51 namespace vcl { struct FontCapabilities; }
53 /**
54 * The FreetypeManager caches various aspects of Freetype fonts
56 * It mainly consists of two std::unordered_map lists, which hold the items of the cache.
58 * They form kind of a tree, with FreetypeFontFile as the roots, referenced by multiple FreetypeFontInfo
59 * entries, which are referenced by the FreetypeFont items.
61 * All of these items have reference counters, but these don't control the items life-cycle, but that of
62 * the managed resources.
64 * The respective resources are:
65 * FreetypeFontFile = holds the mmapped font file, as long as it's used by any FreetypeFontInfo.
66 * FreetypeFontInfo = holds the FT_FaceRec_ object, as long as it's used by any FreetypeFont.
67 * FreetypeFont = holds the FT_SizeRec_ and is owned by a FreetypeFontInstance
69 * FreetypeFontInfo therefore is embedded in the Freetype subclass of PhysicalFontFace.
70 * FreetypeFont is owned by FreetypeFontInstance, the Freetype subclass of LogicalFontInstance.
72 * Nowadays there is not really a reason to have separate files for the classes, as the FreetypeManager
73 * is just about handling of Freetype based fonts, not some abstract glyphs.
74 **/
75 class VCL_DLLPUBLIC FreetypeManager final
77 public:
78 SAL_DLLPRIVATE ~FreetypeManager();
80 static FreetypeManager& get();
82 void AddFontFile(const OString& rNormalizedName,
83 int nFaceNum, int nVariantNum,
84 sal_IntPtr nFontId,
85 const FontAttributes&);
87 SAL_DLLPRIVATE void AnnounceFonts( vcl::font::PhysicalFontCollection* ) const;
89 void ClearFontCache();
91 SAL_DLLPRIVATE FreetypeFont* CreateFont(FreetypeFontInstance* pLogicalFont);
93 private:
94 // to access the constructor (can't use InitFreetypeManager function, because it's private?!)
95 friend class GenericUnixSalData;
96 SAL_DLLPRIVATE explicit FreetypeManager();
98 SAL_DLLPRIVATE static void InitFreetype();
99 SAL_DLLPRIVATE FreetypeFontFile* FindFontFile(const OString& rNativeFileName);
101 typedef std::unordered_map<sal_IntPtr, std::shared_ptr<FreetypeFontInfo>> FontInfoList;
102 typedef std::unordered_map<const char*, std::unique_ptr<FreetypeFontFile>, rtl::CStringHash, rtl::CStringEqual> FontFileList;
104 FontInfoList m_aFontInfoList;
106 FontFileList m_aFontFileList;
109 class VCL_DLLPUBLIC FreetypeFont final
111 public:
112 SAL_DLLPRIVATE ~FreetypeFont();
114 SAL_DLLPRIVATE const OString& GetFontFileName() const;
115 SAL_DLLPRIVATE int GetFontFaceIndex() const;
116 SAL_DLLPRIVATE int GetFontFaceVariation() const;
117 bool TestFont() const { return mbFaceOk;}
118 SAL_DLLPRIVATE FT_Face GetFtFace() const;
119 const FontConfigFontOptions* GetFontOptions() const;
121 SAL_DLLPRIVATE void GetFontMetric(FontMetricDataRef const &) const;
123 SAL_DLLPRIVATE bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const;
124 bool GetAntialiasAdvice() const;
126 private:
127 friend class FreetypeFontInstance;
128 friend class FreetypeManager;
130 SAL_DLLPRIVATE explicit FreetypeFont(FreetypeFontInstance&, std::shared_ptr<FreetypeFontInfo> rFontInfo);
132 SAL_DLLPRIVATE void ApplyGlyphTransform(bool bVertical, FT_Glyph) const;
134 FreetypeFontInstance& mrFontInstance;
136 // 16.16 fixed point values used for a rotated font
137 tools::Long mnCos;
138 tools::Long mnSin;
140 int mnWidth;
141 int mnPrioAntiAlias;
142 std::shared_ptr<FreetypeFontInfo> mxFontInfo;
143 double mfStretch;
144 FT_FaceRec_* maFaceFT;
145 FT_SizeRec_* maSizeFT;
147 mutable std::unique_ptr<FontConfigFontOptions> mxFontOptions;
149 bool mbFaceOk;
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */