LibreOffice Module vcl (master)  1
freetype_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 #pragma once
21 
22 #include <sal/config.h>
23 
24 #include <unx/glyphcache.hxx>
26 #include <fontinstance.hxx>
27 #include <vcl/glyphitem.hxx>
28 
29 class CmapResult;
30 
31 // FreetypeFontFile has the responsibility that a font file is only mapped once.
32 // (#86621#) the old directly ft-managed solution caused it to be mapped
33 // in up to nTTC*nSizes*nOrientation*nSynthetic times
34 class FreetypeFontFile final
35 {
36 public:
37  bool Map();
38  void Unmap();
39 
40  const unsigned char* GetBuffer() const { return mpFileMap; }
41  int GetFileSize() const { return mnFileSize; }
42  const OString& GetFileName() const { return maNativeFileName; }
43  int GetLangBoost() const { return mnLangBoost; }
44 
45 private:
46  friend class FreetypeManager;
47  explicit FreetypeFontFile( const OString& rNativeFileName );
48 
49  const OString maNativeFileName;
50  unsigned char* mpFileMap;
54 };
55 
56 // FreetypeFontInfo corresponds to an unscaled font face
57 class FreetypeFontInfo final
58 {
59 public:
61 
62  const unsigned char* GetTable( const char*, sal_uLong* pLength) const;
63 
64  FT_FaceRec_* GetFaceFT();
65  void ReleaseFaceFT();
66 
67  const OString& GetFontFileName() const { return mpFontFile->GetFileName(); }
68  int GetFontFaceIndex() const { return mnFaceNum; }
69  int GetFontFaceVariation() const { return mnFaceVariation; }
70  sal_IntPtr GetFontId() const { return mnFontId; }
71  bool IsSymbolFont() const { return maDevFontAttributes.IsSymbolFont(); }
73 
75 
76  const FontCharMapRef & GetFontCharMap() const;
78 
79 private:
80  friend class FreetypeManager;
81  explicit FreetypeFontInfo(const FontAttributes&, FreetypeFontFile* const pFontFile,
82  int nFaceNum, int nFaceVariation, sal_IntPtr nFontId);
83 
84  FT_FaceRec_* maFaceFT;
86  const int mnFaceNum;
87  const int mnFaceVariation;
89  sal_IntPtr mnFontId;
91 
93 };
94 
96 {
97 private:
99 
100 public:
102 
104  virtual sal_IntPtr GetFontId() const override { return mpFreetypeFontInfo->GetFontId(); }
105 
106  FontCharMapRef GetFontCharMap() const override { return mpFreetypeFontInfo->GetFontCharMap(); }
107  inline bool GetFontCapabilities(vcl::FontCapabilities&) const override;
108 };
109 
111 {
112  return mpFreetypeFontInfo->GetFontCapabilities(rFontCapabilities);
113 }
114 
115 class SAL_DLLPUBLIC_RTTI FreetypeFontInstance final : public LogicalFontInstance
116 {
118 
119  std::unique_ptr<FreetypeFont> mxFreetypeFont;
120 
121  virtual hb_font_t* ImplInitHbFont() override;
122  virtual bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const override;
123 
125 
126 public:
127  virtual ~FreetypeFontInstance() override;
128 
129  FreetypeFont& GetFreetypeFont() const { return *mxFreetypeFont; }
130 
131  virtual bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const override;
132 };
133 
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FontCharMapRef mxFontCharMap
FreetypeFont & GetFreetypeFont() const
void AnnounceFont(vcl::font::PhysicalFontCollection *)
sal_uIntPtr sal_uLong
sal_IntPtr GetFontId() const
const OString maNativeFileName
sal_uInt16 sal_GlyphId
Definition: glyphitem.hxx:29
virtual sal_IntPtr GetFontId() const override
int GetFontFaceVariation() const
FreetypeFontFile *const mpFontFile
unsigned char * mpFileMap
FontCharMapRef GetFontCharMap() const override
int GetFontFaceIndex() const
The FreetypeManager caches various aspects of Freetype fonts.
Definition: glyphcache.hxx:78
const OString & GetFileName() const
const unsigned char * GetBuffer() const
FreetypeFontFile(const OString &rNativeFileName)
virtual bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle &, bool) const =0
const OString & GetFontFileName() const
virtual rtl::Reference< LogicalFontInstance > CreateFontInstance(const vcl::font::FontSelectPattern &) const override
abstract base class for physical font faces
FreetypeFontInfo(const FontAttributes &, FreetypeFontFile *const pFontFile, int nFaceNum, int nFaceVariation, sal_IntPtr nFontId)
const FontCharMapRef & GetFontCharMap() const
FontAttributes maDevFontAttributes
FreetypeFontInfo * mpFreetypeFontInfo
bool GetFontCapabilities(vcl::FontCapabilities &) const
std::unique_ptr< FreetypeFont > mxFreetypeFont
const FontAttributes & GetFontAttributes() const
FreetypeFontFace(FreetypeFontInfo *, const FontAttributes &)
virtual hb_font_t * ImplInitHbFont()
virtual bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon &, bool) const =0
bool IsSymbolFont() const
bool GetFontCapabilities(vcl::FontCapabilities &) const override
FT_FaceRec_ * GetFaceFT()
bool IsSymbolFont() const
const unsigned char * GetTable(const char *, sal_uLong *pLength) const