LibreOffice Module vcl (master) 1
fontmanager.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#include <config_options.h>
24
25#include <tools/fontenum.hxx>
26#include <vcl/dllapi.h>
27#include <vcl/timer.hxx>
28#include <com/sun/star/lang/Locale.hpp>
30
32
33#include <glyphid.hxx>
34
35#include <map>
36#include <set>
37#include <memory>
38#include <string_view>
39#include <vector>
40#include <unordered_map>
41
42/*
43 * some words on metrics: every length returned by PrintFontManager and
44 * friends are PostScript afm style, that is they are 1/1000 font height
45 */
46
47class FontAttributes;
49namespace vcl::font
50{
51class FontSelectPattern;
52}
53namespace vcl { struct NameRecord; }
55
56namespace psp {
57class PPDParser;
58
59typedef int fontID;
60
62{
63 fontID m_nID; // FontID
64
65 // font attributes
66 OUString m_aFamilyName;
67 OUString m_aStyleName;
68 std::vector< OUString > m_aAliases;
74 rtl_TextEncoding m_aEncoding;
75
77 : m_nID(0)
83 , m_aEncoding(RTL_TEXTENCODING_DONTKNOW)
84 {}
85};
86
87// a class to manage printable fonts
88
90{
91 struct PrintFont;
92 friend struct PrintFont;
93
95 {
96 // font attributes
97 OUString m_aFamilyName;
98 std::vector<OUString> m_aAliases;
99 OUString m_aPSName;
100 OUString m_aStyleName;
106 rtl_TextEncoding m_aEncoding;
110
111 int m_nDirectory; // atom containing system dependent path
112 OString m_aFontFile; // relative to directory
113 int m_nCollectionEntry; // 0 for regular fonts, 0 to ... for fonts stemming from collections
114 int m_nVariationEntry; // 0 for regular fonts, 0 to ... for fonts stemming from font variations
115
116 explicit PrintFont();
117 };
118
120 std::unordered_map< fontID, PrintFont > m_aFonts;
121 // for speeding up findFontFileID
122 std::unordered_map< OString, std::set< fontID > >
124
125 std::unordered_map< OString, int >
127 std::unordered_map< int, OString > m_aAtomToDir;
129
130 OString getFontFile(const PrintFont& rFont) const;
131
132 std::vector<PrintFont> analyzeFontFile(int nDirID, const OString& rFileName, const char *pFormat=nullptr) const;
133 static OUString convertSfntName( const vcl::NameRecord& rNameRecord ); // format font subsetting code
134 static void analyzeSfntFamilyName( void const * pTTFont, std::vector< OUString >& rnames ); // actually a TrueTypeFont* from font subsetting code
135 bool analyzeSfntFile(PrintFont& rFont) const;
136 // finds the font id for the nFaceIndex face in this font file
137 // There may be multiple font ids for font collections
138 fontID findFontFileID(int nDirID, const OString& rFile, int nFaceIndex, int nVariationIndex) const;
139
140 // There may be multiple font ids for font collections
141 std::vector<fontID> findFontFileIDs( int nDirID, const OString& rFile ) const;
142
143 static FontFamily matchFamilyName( std::u16string_view rFamily );
144
145 const PrintFont* getFont( fontID nID ) const
146 {
147 auto it = m_aFonts.find( nID );
148 return it == m_aFonts.end() ? nullptr : &it->second;
149 }
151 {
152 auto it = m_aFonts.find( nID );
153 return it == m_aFonts.end() ? nullptr : &it->second;
154 }
155 static void fillPrintFontInfo(const PrintFont& rFont, FastPrintFontInfo& rInfo);
156
157 OString getDirectory( int nAtom ) const;
158 int getDirectoryAtom( const OString& rDirectory );
159
160 /* try to initialize fonts from libfontconfig
161
162 called from <code>initialize()</code>
163 */
164 static void initFontconfig();
166 /* deinitialize fontconfig
167 */
168 static void deinitFontconfig();
169
170 /* register an application specific font directory for libfontconfig
171
172 since fontconfig is asked for font substitutes before OOo will check for font availability
173 and fontconfig will happily substitute fonts it doesn't know (e.g. "Arial Narrow" -> "DejaVu Sans Book"!)
174 it becomes necessary to tell the library about all the hidden font treasures
175 */
176 static void addFontconfigDir(const OString& rDirectory);
177
178 /* register an application specific font file for libfontconfig */
179 static void addFontconfigFile(const OString& rFile);
180
182 std::vector<OUString> m_aCurrentRequests;
184
185 DECL_DLLPRIVATE_LINK( autoInstallFontLangSupport, Timer*, void );
187public:
189 friend class ::GenericUnixSalData;
190 static PrintFontManager& get(); // one instance only
191
192 // There may be multiple font ids for font collections
193 std::vector<fontID> addFontFile( std::u16string_view rFileUrl );
194
196
197 // returns the ids of all managed fonts.
198 void getFontList( std::vector< fontID >& rFontIDs );
199
200 // get fast font info for a specific font
201 bool getFontFastInfo( fontID nFontID, FastPrintFontInfo& rInfo ) const;
202
203 // routines to get font info in small pieces
204
205 // get a specific fonts PSName name
206 OUString getPSName( fontID nFontID );
207
208 // get a specific fonts system dependent filename
209 OString getFontFileSysPath( fontID nFontID ) const
210 {
211 return getFontFile( *getFont( nFontID ) );
212 }
213
214 // get the ttc face number
215 int getFontFaceNumber( fontID nFontID ) const;
216
217 // get the ttc face variation
218 int getFontFaceVariation( fontID nFontID ) const;
219
220 // get a specific fonts ascend
221 int getFontAscend( fontID nFontID );
222
223 // get a specific fonts descent
224 int getFontDescend( fontID nFontID );
225
226 // font administration functions
227
228 /* system dependent font matching
229
230 <p>
231 <code>matchFont</code> matches a pattern of font characteristics
232 and returns the closest match if possible. If a match was found
233 the <code>FastPrintFontInfo</code> passed in as parameter
234 will be update to the found matching font.
235 </p>
236 <p>
237 implementation note: currently the function is only implemented
238 for fontconfig.
239 </p>
240
241 @param rInfo
242 out of the FastPrintFontInfo structure the following
243 fields will be used for the match:
244 <ul>
245 <li>family name</li>
246 <li>italic</li>
247 <li>width</li>
248 <li>weight</li>
249 <li>pitch</li>
250 </ul>
251
252 @param rLocale
253 if <code>rLocal</code> contains non empty strings the corresponding
254 locale will be used for font matching also; e.g. "Sans" can result
255 in different fonts in e.g. english and japanese
256 */
257 void matchFont( FastPrintFontInfo& rInfo, const css::lang::Locale& rLocale );
258
259 static std::unique_ptr<FontConfigFontOptions> getFontOptions(const FontAttributes& rFontAttributes, int nSize);
260
261 void Substitute(vcl::font::FontSelectPattern &rPattern, OUString& rMissingCodes);
262
263};
264
265} // namespace
266
267/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: timer.hxx:27
static void initFontconfig()
std::set< OString > m_aPreviousLangSupportRequests
OString getFontFileSysPath(fontID nFontID) const
int getFontFaceVariation(fontID nFontID) const
DECL_DLLPRIVATE_LINK(autoInstallFontLangSupport, Timer *, void)
bool analyzeSfntFile(PrintFont &rFont) const
static void fillPrintFontInfo(const PrintFont &rFont, FastPrintFontInfo &rInfo)
static void addFontconfigDir(const OString &rDirectory)
std::unordered_map< fontID, PrintFont > m_aFonts
static FontFamily matchFamilyName(std::u16string_view rFamily)
static void deinitFontconfig()
void getFontList(std::vector< fontID > &rFontIDs)
std::vector< fontID > addFontFile(std::u16string_view rFileUrl)
const PrintFont * getFont(fontID nID) const
std::vector< OUString > m_aCurrentRequests
int getDirectoryAtom(const OString &rDirectory)
std::unordered_map< OString, std::set< fontID > > m_aFontFileToFontID
OString getDirectory(int nAtom) const
int getFontDescend(fontID nFontID)
static void analyzeSfntFamilyName(void const *pTTFont, std::vector< OUString > &rnames)
static OUString convertSfntName(const vcl::NameRecord &rNameRecord)
void matchFont(FastPrintFontInfo &rInfo, const css::lang::Locale &rLocale)
OUString getPSName(fontID nFontID)
static std::unique_ptr< FontConfigFontOptions > getFontOptions(const FontAttributes &rFontAttributes, int nSize)
std::vector< PrintFont > analyzeFontFile(int nDirID, const OString &rFileName, const char *pFormat=nullptr) const
OString getFontFile(const PrintFont &rFont) const
static void addFontconfigFile(const OString &rFile)
bool getFontFastInfo(fontID nFontID, FastPrintFontInfo &rInfo) const
fontID findFontFileID(int nDirID, const OString &rFile, int nFaceIndex, int nVariationIndex) const
std::vector< fontID > findFontFileIDs(int nDirID, const OString &rFile) const
std::unordered_map< int, OString > m_aAtomToDir
std::unordered_map< OString, int > m_aDirToAtom
int getFontAscend(fontID nFontID)
PrintFont * getFont(fontID nID)
int getFontFaceNumber(fontID nFontID) const
void Substitute(vcl::font::FontSelectPattern &rPattern, OUString &rMissingCodes)
static PrintFontManager & get()
#define VCL_DLLPRIVATE
Definition: dllapi.h:31
#define VCL_PLUGIN_PUBLIC
Definition: dllapi.h:40
FontPitch
PITCH_DONTKNOW
FontItalic
ITALIC_DONTKNOW
FontWidth
WIDTH_DONTKNOW
FontFamily
FAMILY_DONTKNOW
WEIGHT_DONTKNOW
int fontID
Definition: fontmanager.hxx:57
FontWeight
A PhysicalFontFaceCollection is created by a PhysicalFontCollection and becomes invalid when original...
rtl_TextEncoding m_aEncoding
Definition: fontmanager.hxx:74
std::vector< OUString > m_aAliases
Definition: fontmanager.hxx:68
std::vector< OUString > m_aAliases
Definition: fontmanager.hxx:98
Structure used by the TrueType Creator and CreateTTFromTTGlyphs()
Definition: sft.hxx:140