Line data Source code
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 : #ifndef _SV_OUTDEV_H
21 : #define _SV_OUTDEV_H
22 :
23 : #include <tools/solar.h>
24 : #include <outfont.hxx>
25 :
26 : #include <vector>
27 : #include <list>
28 : #include <set>
29 :
30 : class Size;
31 : class Font;
32 : class VirtualDevice;
33 : class ImplGetDevFontList;
34 : class GetDevSizeList;
35 :
36 : // -----------------------
37 : // - ImplDevFontListData -
38 : // -----------------------
39 :
40 : // flags for mnMatchType member
41 : #define IMPL_DEVFONT_SCALABLE ((sal_uIntPtr)0x00000001)
42 : #define IMPL_DEVFONT_SYMBOL ((sal_uIntPtr)0x00000002)
43 : #define IMPL_DEVFONT_NONESYMBOL ((sal_uIntPtr)0x00000004)
44 : #define IMPL_DEVFONT_LIGHT ((sal_uIntPtr)0x00000010)
45 : #define IMPL_DEVFONT_BOLD ((sal_uIntPtr)0x00000020)
46 : #define IMPL_DEVFONT_NORMAL ((sal_uIntPtr)0x00000040)
47 : #define IMPL_DEVFONT_NONEITALIC ((sal_uIntPtr)0x00000100)
48 : #define IMPL_DEVFONT_ITALIC ((sal_uIntPtr)0x00000200)
49 :
50 : // TODO: rename ImplDevFontListData to PhysicalFontFamily
51 : class ImplDevFontListData
52 : {
53 : public:
54 : ImplDevFontListData( const String& rSearchName );
55 : ~ImplDevFontListData();
56 :
57 439515 : const OUString& GetFamilyName() const { return maName; }
58 814990 : const String& GetSearchName() const { return maSearchName; }
59 : const OUString& GetAliasNames() const { return maMapNames; }
60 162 : bool IsScalable() const { return mpFirst->IsScalable(); }
61 297 : int GetMinQuality() const { return mnMinQuality; }
62 :
63 : bool AddFontFace( PhysicalFontFace* );
64 : void InitMatchData( const utl::FontSubstConfiguration&,
65 : const String& rSearchName );
66 : PhysicalFontFace* FindBestFontFace( const FontSelectPattern& rFSD ) const;
67 :
68 : void GetFontHeights( std::set<int>& rHeights ) const;
69 : void UpdateDevFontList( ImplGetDevFontList& ) const;
70 : void UpdateCloneFontList( ImplDevFontList&,
71 : bool bScalable, bool bEmbeddable ) const;
72 :
73 : private:
74 : friend class ImplDevFontList; // TODO: remove soon
75 : PhysicalFontFace* mpFirst; // linked list of physical font faces
76 : OUString maName; // Fontname (original font family name)
77 : String maSearchName; // normalized font family name
78 : OUString maMapNames; // fontname aliases
79 : sal_uIntPtr mnTypeFaces; // Typeface Flags
80 : sal_uIntPtr mnMatchType; // MATCH - Type
81 : String maMatchFamilyName; // MATCH - FamilyName
82 : FontWeight meMatchWeight; // MATCH - Weight
83 : FontWidth meMatchWidth; // MATCH - Width
84 : FontFamily meFamily;
85 : FontPitch mePitch;
86 : int mnMinQuality; // quality of the worst font face
87 : };
88 :
89 :
90 : // ----------------------
91 : // - ImplGetDevFontList -
92 : // ----------------------
93 :
94 : // an ImplGetDevFontList is created by an ImplDevFontList
95 : // it becomes invalid when original ImplDevFontList is modified
96 1725 : class ImplGetDevFontList
97 : {
98 : private:
99 : std::vector<PhysicalFontFace*> maDevFontVector;
100 :
101 : public:
102 1741 : ImplGetDevFontList() { maDevFontVector.reserve(1024); }
103 255651 : void Add( PhysicalFontFace* pFace ) { maDevFontVector.push_back( pFace ); }
104 368859 : PhysicalFontFace* Get( int nIndex ) const { return maDevFontVector[ nIndex ]; }
105 371381 : int Count() const { return maDevFontVector.size(); }
106 : };
107 :
108 : // ----------------------
109 : // - ImplGetDevSizeList -
110 : // ----------------------
111 :
112 777 : class ImplGetDevSizeList
113 : {
114 : private:
115 : String maFontName;
116 : std::vector<int> maSizeList;
117 :
118 : public:
119 777 : ImplGetDevSizeList( const String& rFontName )
120 777 : : maFontName( rFontName ) { maSizeList.reserve( 32 ); }
121 0 : void Add( int nHeight ) { maSizeList.push_back( nHeight ); }
122 777 : int Count() const { return maSizeList.size(); }
123 0 : int Get( int nIndex ) const { return maSizeList[ nIndex ]; }
124 : const String& GetFontName() const { return maFontName; }
125 : };
126 :
127 : // ------------------------
128 : // - ImplFontSubstitution -
129 : // ------------------------
130 : // nowadays these substitutions are needed for backward compatibility and tight platform integration:
131 : // - substitutions from configuration entries (Tools->Options->FontReplacement and/or fontconfig)
132 : // - device specific substitutions (e.g. for PS printer builtin fonts)
133 : // - substitutions for missing fonts defined by configuration entries (generic and/or platform dependent fallbacks)
134 : // - substitutions for missing fonts defined by multi-token fontnames (e.g. fontname="SpecialFont;FallbackA;FallbackB")
135 : // - substitutions for incomplete fonts (implicit, generic, EUDC and/or platform dependent fallbacks)
136 : // - substitutions for missing symbol fonts by translating code points into other symbol fonts
137 :
138 1399 : class ImplFontSubstitution
139 : {
140 : // TODO: there is more commonality between the different substitutions
141 : protected:
142 1522 : virtual ~ImplFontSubstitution() {}
143 : };
144 :
145 : // ImplDirectFontSubstitution is for Tools->Options->FontReplacement and PsPrinter substitutions
146 : // The clss is just a simple port of the unmaintainable manual-linked-list based mechanism
147 : // TODO: get rid of this class when the Tools->Options->FontReplacement tabpage is gone for good
148 :
149 0 : struct ImplFontSubstEntry
150 : {
151 : String maName;
152 : String maReplaceName;
153 : OUString maSearchName;
154 : OUString maSearchReplaceName;
155 : sal_uInt16 mnFlags;
156 :
157 : ImplFontSubstEntry( const OUString& rFontName, const OUString& rSubstFontName, sal_uInt16 nSubstFlags );
158 : };
159 :
160 2546 : class ImplDirectFontSubstitution
161 : : public ImplFontSubstitution
162 : {
163 : private:
164 : typedef std::list<ImplFontSubstEntry> FontSubstList;
165 : FontSubstList maFontSubstList;
166 : public:
167 : void AddFontSubstitute( const String& rFontName, const String& rSubstName, sal_uInt16 nFlags );
168 : void RemoveFontSubstitute( int nIndex );
169 0 : int GetFontSubstituteCount() const { return maFontSubstList.size(); };
170 0 : bool Empty() const { return maFontSubstList.empty(); }
171 0 : void Clear() { maFontSubstList.clear(); }
172 :
173 : bool FindFontSubstitute( String& rSubstName, const String& rFontName, sal_uInt16 nFlags ) const;
174 : };
175 :
176 : // PreMatchFontSubstitution
177 : // abstracts the concept of a configured font substitution
178 : // before the availability of the originally selected font has been checked
179 250 : class ImplPreMatchFontSubstitution
180 : : public ImplFontSubstitution
181 : {
182 : public:
183 : virtual bool FindFontSubstitute( FontSelectPattern& ) const = 0;
184 : };
185 :
186 : // ImplGlyphFallbackFontSubstitution
187 : // abstracts the concept of finding the best font to support an incomplete font
188 125 : class ImplGlyphFallbackFontSubstitution
189 : : public ImplFontSubstitution
190 : {
191 : public:
192 : virtual bool FindFontSubstitute( FontSelectPattern&, OUString& rMissingCodes ) const = 0;
193 : };
194 :
195 : // -----------------
196 : // - ImplFontCache -
197 : // -----------------
198 : // TODO: closely couple with ImplDevFontList
199 :
200 : class ImplFontCache
201 : {
202 : private:
203 : ImplFontEntry* mpFirstEntry;
204 : int mnRef0Count; // number of unreferenced ImplFontEntries
205 : bool mbPrinter;
206 :
207 : // cache of recently used font instances
208 : struct IFSD_Equal { bool operator()( const FontSelectPattern&, const FontSelectPattern& ) const; };
209 : struct IFSD_Hash { size_t operator()( const FontSelectPattern& ) const; };
210 : typedef ::boost::unordered_map<FontSelectPattern,ImplFontEntry*,IFSD_Hash,IFSD_Equal > FontInstanceList;
211 : FontInstanceList maFontInstanceList;
212 :
213 : public:
214 : ImplFontCache( bool bPrinter );
215 : ~ImplFontCache();
216 :
217 : ImplFontEntry* GetFontEntry( ImplDevFontList*,
218 : const Font&, const Size& rPixelSize, float fExactHeight,
219 : ImplDirectFontSubstitution* pDevSpecific );
220 : ImplFontEntry* GetFontEntry( ImplDevFontList*,
221 : FontSelectPattern&, ImplDirectFontSubstitution* pDevSpecific );
222 : ImplFontEntry* GetGlyphFallbackFont( ImplDevFontList*, FontSelectPattern&,
223 : int nFallbackLevel, OUString& rMissingCodes );
224 : void Release( ImplFontEntry* );
225 : void Invalidate();
226 : };
227 :
228 : // ------------------
229 : // - ImplOutDevData -
230 : // ------------------
231 :
232 : namespace vcl { struct ControlLayoutData; }
233 : // #i75163#
234 : namespace basegfx { class B2DHomMatrix; }
235 :
236 2546 : struct ImplOutDevData
237 : {
238 : VirtualDevice* mpRotateDev;
239 : vcl::ControlLayoutData* mpRecordLayout;
240 : Rectangle maRecordRect;
241 : ImplDirectFontSubstitution maDevFontSubst;
242 :
243 : // #i75163#
244 : basegfx::B2DHomMatrix* mpViewTransform;
245 : basegfx::B2DHomMatrix* mpInverseViewTransform;
246 : };
247 :
248 : void ImplFreeOutDevFontData();
249 :
250 : #endif // _SV_OUTDEV_H
251 :
252 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|