LibreOffice Module vcl (master)  1
glyphcache.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_VCL_INC_GENERIC_GLYPHCACHE_HXX
21 #define INCLUDED_VCL_INC_GENERIC_GLYPHCACHE_HXX
22 
23 #include <memory>
24 #include <freetype/config/ftheader.h>
25 #include FT_FREETYPE_H
26 #include FT_GLYPH_H
27 
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>
33 
34 #include <fontattributes.hxx>
35 #include <fontinstance.hxx>
36 #include <impfontmetricdata.hxx>
37 
38 #include <unordered_map>
39 
40 class FreetypeFont;
41 class FreetypeFontFile;
43 class FreetypeFontInfo;
46 class FreetypeFont;
47 class SvpGcpHelper;
48 
49 namespace basegfx { class B2DPolyPolygon; }
50 namespace vcl { struct FontCapabilities; }
51 
75 {
76 public:
77  ~FreetypeManager();
78 
79  static FreetypeManager& get();
80 
81  void AddFontFile(const OString& rNormalizedName,
82  int nFaceNum, int nVariantNum,
83  sal_IntPtr nFontId,
84  const FontAttributes&);
85 
86  void AnnounceFonts( PhysicalFontCollection* ) const;
87 
88  void ClearFontCache();
89 
91 
92 private:
93  // to access the constructor (can't use InitFreetypeManager function, because it's private?!)
94  friend class GenericUnixSalData;
95  explicit FreetypeManager();
96 
97  static void InitFreetype();
98  FreetypeFontFile* FindFontFile(const OString& rNativeFileName);
99 
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;
102 
103  FontInfoList m_aFontInfoList;
104  sal_IntPtr m_nMaxFontId;
105 
106  FontFileList m_aFontFileList;
107 };
108 
110 {
111 public:
112  ~FreetypeFont();
113 
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; }
122 
123  void GetFontMetric(ImplFontMetricDataRef const &) const;
124  const unsigned char* GetTable( const char* pName, sal_uLong* pLength ) const;
125  FontCharMapRef GetFontCharMap() const;
126  bool GetFontCapabilities(vcl::FontCapabilities &) const;
127 
128  bool GetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const;
129  bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const;
130  bool GetAntialiasAdvice() const;
131 
132  void SetFontVariationsOnHBFont(hb_font_t* pHbFace) const;
133 
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);
139 
140 private:
141  friend class FreetypeFontInstance;
142  friend class FreetypeManager;
143 
144  explicit FreetypeFont(FreetypeFontInstance&, std::shared_ptr<FreetypeFontInfo>& rFontInfo);
145 
146  void ApplyGlyphTransform(bool bVertical, FT_Glyph) const;
147 
149 
150  // 16.16 fixed point values used for a rotated font
151  long mnCos;
152  long mnSin;
153 
154  int mnWidth;
156  std::shared_ptr<FreetypeFontInfo> mxFontInfo;
157  FT_Int mnLoadFlags;
158  double mfStretch;
159  FT_FaceRec_* maFaceFT;
160  FT_SizeRec_* maSizeFT;
161 
162  mutable std::unique_ptr<FontConfigFontOptions> mxFontOptions;
163 
164  bool mbFaceOk;
166  bool mbArtBold;
167 };
168 
169 #endif // INCLUDED_VCL_INC_GENERIC_GLYPHCACHE_HXX
170 
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FT_SizeRec_ * maSizeFT
Definition: glyphcache.hxx:160
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_uIntPtr sal_uLong
FreetypeFontInstance & mrFontInstance
Definition: glyphcache.hxx:148
sal_IntPtr m_nMaxFontId
Definition: glyphcache.hxx:104
FontFileList m_aFontFileList
Definition: glyphcache.hxx:106
sal_uInt16 sal_GlyphId
Definition: glyphitem.hxx:26
std::unordered_map< const char *, std::unique_ptr< FreetypeFontFile >, rtl::CStringHash, rtl::CStringEqual > FontFileList
Definition: glyphcache.hxx:101
bool NeedsArtificialItalic() const
Definition: glyphcache.hxx:121
bool NeedsArtificialBold() const
Definition: glyphcache.hxx:120
sal_uInt16 char * pName
double mfStretch
Definition: glyphcache.hxx:158
The FreetypeManager caches various aspects of Freetype fonts.
Definition: glyphcache.hxx:74
void CreateFont(SvxFont &rFont, const SfxItemSet &rSet, bool bSearchInParent, SvtScriptType nScriptType)
FT_FaceRec_ * maFaceFT
Definition: glyphcache.hxx:159
std::shared_ptr< FreetypeFontInfo > mxFontInfo
Definition: glyphcache.hxx:156
bool TestFont() const
Definition: glyphcache.hxx:117
FontInfoList m_aFontInfoList
Definition: glyphcache.hxx:103
std::unordered_map< sal_IntPtr, std::shared_ptr< FreetypeFontInfo > > FontInfoList
Definition: glyphcache.hxx:100
std::unique_ptr< FontConfigFontOptions > mxFontOptions
Definition: glyphcache.hxx:162
FT_Int mnLoadFlags
Definition: glyphcache.hxx:157