/src/libreoffice/vcl/inc/unx/fontmanager.hxx
Line | Count | Source |
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 <o3tl/sorted_vector.hxx> |
25 | | #include <tools/fontenum.hxx> |
26 | | #include <vcl/dllapi.h> |
27 | | #include <vcl/timer.hxx> |
28 | | #include <com/sun/star/lang/Locale.hpp> |
29 | | #include <unx/fc_fontoptions.hxx> |
30 | | |
31 | | #include <font/PhysicalFontFace.hxx> |
32 | | |
33 | | #include <set> |
34 | | #include <memory> |
35 | | #include <string_view> |
36 | | #include <vector> |
37 | | #include <unordered_map> |
38 | | |
39 | | /* |
40 | | * some words on metrics: every length returned by PrintFontManager and |
41 | | * friends are PostScript afm style, that is they are 1/1000 font height |
42 | | */ |
43 | | |
44 | | class FontConfigFontOptions; |
45 | | namespace vcl::font |
46 | | { |
47 | | class FontSelectPattern; |
48 | | } |
49 | | class GenericUnixSalData; |
50 | | |
51 | | namespace psp { |
52 | | typedef int fontID; |
53 | | |
54 | | // a class to manage printable fonts |
55 | | |
56 | | class VCL_PLUGIN_PUBLIC PrintFontManager |
57 | | { |
58 | | friend struct PrintFont; |
59 | | |
60 | | struct SAL_DLLPRIVATE PrintFont |
61 | | { |
62 | | FontAttributes m_aFontAttributes; |
63 | | |
64 | | int m_nDirectory; // atom containing system dependent path |
65 | | OString m_aFontFile; // relative to directory |
66 | | int m_nCollectionEntry; // 0 for regular fonts, 0 to ... for fonts stemming from collections |
67 | | int m_nVariationEntry; // 0 for regular fonts, 0 to ... for fonts stemming from font variations |
68 | | |
69 | | explicit PrintFont(); |
70 | | }; |
71 | | |
72 | | fontID m_nNextFontID; |
73 | | std::unordered_map< fontID, PrintFont > m_aFonts; |
74 | | // for speeding up findFontFileID |
75 | | std::unordered_map< OString, o3tl::sorted_vector< fontID > > |
76 | | m_aFontFileToFontID; |
77 | | |
78 | | std::unordered_map< OString, int > |
79 | | m_aDirToAtom; |
80 | | std::unordered_map< int, OString > m_aAtomToDir; |
81 | | int m_nNextDirAtom; |
82 | | |
83 | | OString getFontFile(const PrintFont& rFont) const; |
84 | | |
85 | | std::vector<PrintFont> analyzeFontFile(int nDirID, const OString& rFileName) const; |
86 | | bool analyzeSfntFile(PrintFont& rFont) const; |
87 | | // finds the font id for the nFaceIndex face in this font file |
88 | | // There may be multiple font ids for font collections |
89 | | fontID findFontFileID(int nDirID, const OString& rFile, int nFaceIndex, int nVariationIndex) const; |
90 | | |
91 | | // There may be multiple font ids for font collections |
92 | | std::vector<fontID> findFontFileIDs( int nDirID, const OString& rFile ) const; |
93 | | |
94 | | static FontFamily matchFamilyName( std::u16string_view rFamily ); |
95 | | |
96 | | OString getDirectory( int nAtom ) const; |
97 | | int getDirectoryAtom( const OString& rDirectory ); |
98 | | |
99 | | /* try to initialize fonts from libfontconfig |
100 | | |
101 | | called from <code>initialize()</code> |
102 | | */ |
103 | | static void initFontconfig(); |
104 | | void countFontconfigFonts(); |
105 | | /* deinitialize fontconfig |
106 | | */ |
107 | | static void deinitFontconfig(); |
108 | | |
109 | | /* register an application specific font directory for libfontconfig |
110 | | |
111 | | since fontconfig is asked for font substitutes before OOo will check for font availability |
112 | | and fontconfig will happily substitute fonts it doesn't know (e.g. "Arial Narrow" -> "DejaVu Sans Book"!) |
113 | | it becomes necessary to tell the library about all the hidden font treasures |
114 | | */ |
115 | | static void addFontconfigDir(const OString& rDirectory); |
116 | | |
117 | | /* register an application specific font file for libfontconfig */ |
118 | | static void addFontconfigFile(const OString& rFile); |
119 | | |
120 | | /* deregister an application specific font file from libfontconfig */ |
121 | | static void removeFontconfigFile(std::string_view aFile); |
122 | | |
123 | | std::set<OString> m_aPreviousLangSupportRequests; |
124 | | std::vector<OUString> m_aCurrentRequests; |
125 | | Timer m_aFontInstallerTimer; |
126 | | |
127 | | DECL_DLLPRIVATE_LINK( autoInstallFontLangSupport, Timer*, void ); |
128 | | PrintFontManager(); |
129 | | public: |
130 | | ~PrintFontManager(); |
131 | | friend class ::GenericUnixSalData; |
132 | | static PrintFontManager& get(); // one instance only |
133 | | |
134 | | // There may be multiple font ids for font collections |
135 | | std::vector<fontID> findFontFileIDs( std::u16string_view rFileUrl ) const; |
136 | | |
137 | | // There may be multiple font ids for font collections |
138 | | std::vector<fontID> addFontFile( std::u16string_view rFileUrl ); |
139 | | |
140 | | void removeFontFile( std::u16string_view rFileUrl ); |
141 | | |
142 | | const PrintFont* getFont( fontID nID ) const |
143 | 3.98k | { |
144 | 3.98k | auto it = m_aFonts.find( nID ); |
145 | 3.98k | return it == m_aFonts.end() ? nullptr : &it->second; |
146 | 3.98k | } |
147 | | |
148 | | // returns the ids of all managed fonts. |
149 | | std::vector<fontID> getFontList(); |
150 | | |
151 | | // routines to get font info in small pieces |
152 | | |
153 | | // get a specific fonts system dependent filename |
154 | | OString getFontFileSysPath( fontID nFontID ) const |
155 | 996 | { |
156 | 996 | return getFontFile( *getFont( nFontID ) ); |
157 | 996 | } |
158 | | |
159 | | // get the ttc face number |
160 | | int getFontFaceNumber( fontID nFontID ) const; |
161 | | |
162 | | // get the ttc face variation |
163 | | int getFontFaceVariation( fontID nFontID ) const; |
164 | | |
165 | | // font administration functions |
166 | | |
167 | | /* system dependent font matching |
168 | | |
169 | | <p> |
170 | | <code>matchFont</code> matches a pattern of font characteristics |
171 | | and returns the closest match if possible. If a match was found |
172 | | it will update rDFA to the found matching font. |
173 | | </p> |
174 | | <p> |
175 | | implementation note: currently the function is only implemented |
176 | | for fontconfig. |
177 | | </p> |
178 | | |
179 | | @param rDFA |
180 | | out of the FontAttributes structure the following |
181 | | fields will be used for the match: |
182 | | <ul> |
183 | | <li>family name</li> |
184 | | <li>italic</li> |
185 | | <li>width</li> |
186 | | <li>weight</li> |
187 | | <li>pitch</li> |
188 | | </ul> |
189 | | |
190 | | @param rLocale |
191 | | if <code>rLocal</code> contains non empty strings the corresponding |
192 | | locale will be used for font matching also; e.g. "Sans" can result |
193 | | in different fonts in e.g. english and japanese |
194 | | */ |
195 | | bool matchFont(FontAttributes& rDFA, const css::lang::Locale& rLocale); |
196 | | |
197 | | static std::unique_ptr<FontConfigFontOptions> getFontOptions(const FontAttributes& rFontAttributes, int nSize); |
198 | | |
199 | | void Substitute(vcl::font::FontSelectPattern &rPattern, OUString& rMissingCodes); |
200 | | |
201 | | }; |
202 | | |
203 | | } // namespace |
204 | | |
205 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |