1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <sal/config.h>
25 #include <freetype/config/ftheader.h>
26 #include FT_FREETYPE_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>
39 class FreetypeFontFile
;
40 class FreetypeFontInstance
;
41 class FreetypeFontInfo
;
42 class FontConfigFontOptions
;
45 class PhysicalFontCollection
;
50 namespace basegfx
{ class B2DPolyPolygon
; }
51 namespace vcl
{ struct FontCapabilities
; }
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.
75 class VCL_DLLPUBLIC FreetypeManager final
78 SAL_DLLPRIVATE
~FreetypeManager();
80 static FreetypeManager
& get();
82 void AddFontFile(const OString
& rNormalizedName
,
83 int nFaceNum
, int nVariantNum
,
85 const FontAttributes
&);
87 SAL_DLLPRIVATE
void AnnounceFonts( vcl::font::PhysicalFontCollection
* ) const;
89 void ClearFontCache();
91 SAL_DLLPRIVATE FreetypeFont
* CreateFont(FreetypeFontInstance
* pLogicalFont
);
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
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;
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
142 std::shared_ptr
<FreetypeFontInfo
> mxFontInfo
;
144 FT_FaceRec_
* maFaceFT
;
145 FT_SizeRec_
* maSizeFT
;
147 mutable std::unique_ptr
<FontConfigFontOptions
> mxFontOptions
;
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */