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
179 std::vector<OUString> m_aCurrentRequests;
181
182 DECL_DLLPRIVATE_LINK( autoInstallFontLangSupport, Timer*, void );
184public:
186 friend class ::GenericUnixSalData;
187 static PrintFontManager& get(); // one instance only
188
189 // There may be multiple font ids for font collections
190 std::vector<fontID> addFontFile( std::u16string_view rFileUrl );
191
193
194 // returns the ids of all managed fonts.
195 void getFontList( std::vector< fontID >& rFontIDs );
196
197 // get fast font info for a specific font
198 bool getFontFastInfo( fontID nFontID, FastPrintFontInfo& rInfo ) const;
199
200 // routines to get font info in small pieces
201
202 // get a specific fonts PSName name
203 OUString getPSName( fontID nFontID );
204
205 // get a specific fonts system dependent filename
206 OString getFontFileSysPath( fontID nFontID ) const
207 {
208 return getFontFile( *getFont( nFontID ) );
209 }
210
211 // get the ttc face number
212 int getFontFaceNumber( fontID nFontID ) const;
213
214 // get the ttc face variation
215 int getFontFaceVariation( fontID nFontID ) const;
216
217 // get a specific fonts ascend
218 int getFontAscend( fontID nFontID );
219
220 // get a specific fonts descent
221 int getFontDescend( fontID nFontID );
222
223 // font administration functions
224
225 /* system dependent font matching
226
227 <p>
228 <code>matchFont</code> matches a pattern of font characteristics
229 and returns the closest match if possible. If a match was found
230 the <code>FastPrintFontInfo</code> passed in as parameter
231 will be update to the found matching font.
232 </p>
233 <p>
234 implementation note: currently the function is only implemented
235 for fontconfig.
236 </p>
237
238 @param rInfo
239 out of the FastPrintFontInfo structure the following
240 fields will be used for the match:
241 <ul>
242 <li>family name</li>
243 <li>italic</li>
244 <li>width</li>
245 <li>weight</li>
246 <li>pitch</li>
247 </ul>
248
249 @param rLocale
250 if <code>rLocal</code> contains non empty strings the corresponding
251 locale will be used for font matching also; e.g. "Sans" can result
252 in different fonts in e.g. english and japanese
253 */
254 void matchFont( FastPrintFontInfo& rInfo, const css::lang::Locale& rLocale );
255
256 static std::unique_ptr<FontConfigFontOptions> getFontOptions(const FontAttributes& rFontAttributes, int nSize);
257
258 void Substitute(vcl::font::FontSelectPattern &rPattern, OUString& rMissingCodes);
259
260};
261
262} // namespace
263
264/* 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
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