Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / inc / unx / freetype_glyphcache.hxx
blob93788953a3ad0fe6258928dae0fff76e3e4eabcd
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_GENERIC_GLYPHS_GCACH_FTYP_HXX
21 #define INCLUDED_VCL_GENERIC_GLYPHS_GCACH_FTYP_HXX
23 #include "unx/glyphcache.hxx"
24 #include "PhysicalFontFace.hxx"
26 // FreetypeFontFile has the responsibility that a font file is only mapped once.
27 // (#86621#) the old directly ft-managed solution caused it to be mapped
28 // in up to nTTC*nSizes*nOrientation*nSynthetic times
29 class FreetypeFontFile
31 public:
32 static FreetypeFontFile* FindFontFile( const OString& rNativeFileName );
34 bool Map();
35 void Unmap();
37 const unsigned char* GetBuffer() const { return mpFileMap; }
38 int GetFileSize() const { return mnFileSize; }
39 const OString& GetFileName() const { return maNativeFileName; }
40 int GetLangBoost() const { return mnLangBoost; }
42 private:
43 explicit FreetypeFontFile( const OString& rNativeFileName );
45 const OString maNativeFileName;
46 unsigned char* mpFileMap;
47 int mnFileSize;
48 int mnRefCount;
49 int mnLangBoost;
52 // FreetypeFontInfo corresponds to an unscaled font face
53 class FreetypeFontInfo
55 public:
56 FreetypeFontInfo( const FontAttributes&,
57 const OString& rNativeFileName,
58 int nFaceNum, sal_IntPtr nFontId);
59 ~FreetypeFontInfo();
61 const unsigned char* GetTable( const char*, sal_uLong* pLength=nullptr ) const;
63 FT_FaceRec_* GetFaceFT();
64 void ReleaseFaceFT();
66 const OString& GetFontFileName() const { return mpFontFile->GetFileName(); }
67 int GetFontFaceIndex() const { return mnFaceNum; }
68 sal_IntPtr GetFontId() const { return mnFontId; }
69 bool IsSymbolFont() const { return maDevFontAttributes.IsSymbolFont(); }
70 const FontAttributes& GetFontAttributes() const { return maDevFontAttributes; }
72 void AnnounceFont( PhysicalFontCollection* );
74 bool GetFontCodeRanges( CmapResult& ) const;
75 const FontCharMapRef& GetFontCharMap();
77 private:
78 FT_FaceRec_* maFaceFT;
79 FreetypeFontFile* mpFontFile;
80 const int mnFaceNum;
81 int mnRefCount;
82 sal_IntPtr mnFontId;
83 FontAttributes maDevFontAttributes;
85 FontCharMapRef mxFontCharMap;
88 class FreetypeManager
90 public:
91 FreetypeManager();
92 ~FreetypeManager();
94 void AddFontFile( const OString& rNormalizedName,
95 int nFaceNum, sal_IntPtr nFontId, const FontAttributes&);
96 void AnnounceFonts( PhysicalFontCollection* ) const;
97 void ClearFontList();
99 FreetypeFont* CreateFont( const FontSelectPattern& );
101 private:
102 typedef std::unordered_map<sal_IntPtr,FreetypeFontInfo*> FontList;
103 FontList maFontList;
105 sal_IntPtr mnMaxFontId;
108 class FreetypeFontFace : public PhysicalFontFace
110 private:
111 FreetypeFontInfo* mpFreetypeFontInfo;
113 public:
114 FreetypeFontFace( FreetypeFontInfo*, const FontAttributes& );
116 virtual LogicalFontInstance* CreateFontInstance( FontSelectPattern& ) const override;
117 virtual PhysicalFontFace* Clone() const override { return new FreetypeFontFace( *this ); }
118 virtual sal_IntPtr GetFontId() const override { return mpFreetypeFontInfo->GetFontId(); }
121 #endif // INCLUDED_VCL_GENERIC_GLYPHS_GCACH_FTYP_HXX
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */