xref: /trunk/main/vcl/inc/outdev.h (revision 2123d757)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_OUTDEV_H
25 #define _SV_OUTDEV_H
26 
27 #include <tools/solar.h>
28 #include <outfont.hxx>
29 
30 #include <vector>
31 #include <list>
32 #include <set>
33 
34 class Size;
35 class Font;
36 class VirtualDevice;
37 class ImplServerGraphics;
38 class ImplGetDevFontList;
39 class GetDevSizeList;
40 
41 // -----------------------
42 // - ImplDevFontListData -
43 // -----------------------
44 
45 // flags for mnMatchType member
46 #define IMPL_DEVFONT_SCALABLE       ((sal_uIntPtr)0x00000001)
47 #define IMPL_DEVFONT_SYMBOL         ((sal_uIntPtr)0x00000002)
48 #define IMPL_DEVFONT_NONESYMBOL     ((sal_uIntPtr)0x00000004)
49 #define IMPL_DEVFONT_LIGHT          ((sal_uIntPtr)0x00000010)
50 #define IMPL_DEVFONT_BOLD           ((sal_uIntPtr)0x00000020)
51 #define IMPL_DEVFONT_NORMAL         ((sal_uIntPtr)0x00000040)
52 #define IMPL_DEVFONT_NONEITALIC     ((sal_uIntPtr)0x00000100)
53 #define IMPL_DEVFONT_ITALIC         ((sal_uIntPtr)0x00000200)
54 
55 // TODO: rename ImplDevFontListData to PhysicalFontFamily
56 class ImplDevFontListData
57 {
58 public:
59                         ImplDevFontListData( const String& rSearchName );
60                         ~ImplDevFontListData();
61 
GetFamilyName() const62     const String&       GetFamilyName() const    { return maName; }
GetSearchName() const63     const String&       GetSearchName() const    { return maSearchName; }
GetAliasNames() const64     const String&       GetAliasNames() const    { return maMapNames; }
IsScalable() const65     bool                IsScalable() const       { return mpFirst->IsScalable(); }
GetMinQuality() const66     int                 GetMinQuality() const    { return mnMinQuality; }
67 
68     bool                AddFontFace( ImplFontData* );
69     void                InitMatchData( const utl::FontSubstConfiguration&,
70                             const String& rSearchName );
71     ImplFontData*       FindBestFontFace( const ImplFontSelectData& rFSD ) const;
72 
73     void                GetFontHeights( std::set<int>& rHeights ) const;
74     void                UpdateDevFontList( ImplGetDevFontList& ) const;
75     void                UpdateCloneFontList( ImplDevFontList&,
76                             bool bScalable, bool bEmbeddable ) const;
77 
78 private:
79 friend class ImplDevFontList; // TODO: remove soon
80     ImplFontData*       mpFirst;            // linked list of physical font faces
81     String              maName;             // Fontname (original font family name)
82     String              maSearchName;       // normalized font family name
83     String              maMapNames;         // fontname aliases
84     sal_uIntPtr               mnTypeFaces;        // Typeface Flags
85     sal_uIntPtr               mnMatchType;        // MATCH - Type
86     String              maMatchFamilyName;  // MATCH - FamilyName
87     FontWeight          meMatchWeight;      // MATCH - Weight
88     FontWidth           meMatchWidth;       // MATCH - Width
89     FontFamily          meFamily;
90     FontPitch           mePitch;
91     int                 mnMinQuality;       // quality of the worst font face
92 };
93 
94 
95 // ----------------------
96 // - ImplGetDevFontList -
97 // ----------------------
98 
99 // an ImplGetDevFontList is created by an ImplDevFontList
100 // it becomes invalid when original ImplDevFontList is modified
101 class ImplGetDevFontList
102 {
103 private:
104     std::vector<ImplFontData*> maDevFontVector;
105 
106 public:
ImplGetDevFontList()107                         ImplGetDevFontList()        { maDevFontVector.reserve(1024); }
Add(ImplFontData * pFace)108     void                Add( ImplFontData* pFace )  { maDevFontVector.push_back( pFace ); }
Get(int nIndex) const109     ImplFontData*       Get( int nIndex ) const     { return maDevFontVector[ nIndex ]; }
Count() const110     int                 Count() const               { return maDevFontVector.size(); }
111 };
112 
113 // ----------------------
114 // - ImplGetDevSizeList -
115 // ----------------------
116 
117 class ImplGetDevSizeList
118 {
119 private:
120     String              maFontName;
121     std::vector<int>    maSizeList;
122 
123 public:
ImplGetDevSizeList(const String & rFontName)124                         ImplGetDevSizeList( const String& rFontName )
125                         : maFontName( rFontName ) { maSizeList.reserve( 32 ); }
Add(int nHeight)126     void                Add( int nHeight )      { maSizeList.push_back( nHeight ); }
Count() const127     int                 Count() const           { return maSizeList.size(); }
Get(int nIndex) const128     int                 Get( int nIndex ) const { return maSizeList[ nIndex ]; }
GetFontName() const129     const String&       GetFontName() const     { return maFontName; }
130 };
131 
132 // ------------------------
133 // - ImplFontSubstitution -
134 // ------------------------
135 // nowadays these substitutions are needed for backward compatibility and tight platform integration:
136 // - substitutions from configuration entries (Tools->Options->FontReplacement and/or fontconfig)
137 // - device specific substitutions (e.g. for PS printer builtin fonts)
138 // - substitutions for missing fonts defined by configuration entries (generic and/or platform dependent fallbacks)
139 // - substitutions for missing fonts defined by multi-token fontnames (e.g. fontname="SpecialFont;FallbackA;FallbackB")
140 // - substitutions for incomplete fonts (implicit, generic, EUDC and/or platform dependent fallbacks)
141 // - substitutions for missing symbol fonts by translating code points into other symbol fonts
142 
143 class ImplFontSubstitution
144 {
145     // TODO: there is more commonality between the different substitutions
146 protected:
~ImplFontSubstitution()147     virtual ~ImplFontSubstitution() {}
148 };
149 
150 // ImplDirectFontSubstitution is for Tools->Options->FontReplacement and PsPrinter substitutions
151 // The clss is just a simple port of the unmaintainable manual-linked-list based mechanism
152 // TODO: get rid of this class when the Tools->Options->FontReplacement tabpage is gone for good
153 
154 struct ImplFontSubstEntry
155 {
156     String                  maName;
157     String                  maReplaceName;
158     String                  maSearchName;
159     String                  maSearchReplaceName;
160     sal_uInt16                  mnFlags;
161 
162     ImplFontSubstEntry(  const String& rFontName, const String& rSubstFontName, sal_uInt16 nSubstFlags );
163 };
164 
165 class ImplDirectFontSubstitution
166 :   public ImplFontSubstitution
167 {
168 private:
169     typedef std::list<ImplFontSubstEntry> FontSubstList;
170     FontSubstList maFontSubstList;
171 public:
172     void    AddFontSubstitute( const String& rFontName, const String& rSubstName, sal_uInt16 nFlags );
173     void    RemoveFontSubstitute( int nIndex );
174     bool    GetFontSubstitute( int nIndex, String& rFontName, String& rSubstName, sal_uInt16& rFlags ) const;
GetFontSubstituteCount() const175     int     GetFontSubstituteCount() const { return maFontSubstList.size(); };
Empty() const176     bool    Empty() const { return maFontSubstList.empty(); }
Clear()177     void    Clear() { maFontSubstList.clear(); }
178 
179     bool    FindFontSubstitute( String& rSubstName, const String& rFontName, sal_uInt16 nFlags ) const;
180 };
181 
182 // PreMatchFontSubstitution
183 // abstracts the concept of a configured font substitution
184 // before the availability of the originally selected font has been checked
185 class ImplPreMatchFontSubstitution
186 :   public ImplFontSubstitution
187 {
188 public:
189     virtual bool FindFontSubstitute( ImplFontSelectData& ) const = 0;
190 };
191 
192 // ImplGlyphFallbackFontSubstitution
193 // abstracts the concept of finding the best font to support an incomplete font
194 class ImplGlyphFallbackFontSubstitution
195 :   public ImplFontSubstitution
196 {
197 public:
198     virtual bool FindFontSubstitute( ImplFontSelectData&, rtl::OUString& rMissingCodes ) const = 0;
199 };
200 
201 // -----------------
202 // - ImplFontCache -
203 // -----------------
204 // TODO: closely couple with ImplDevFontList
205 
206 class ImplFontCache
207 {
208 private:
209     ImplFontEntry*      mpFirstEntry;
210     int                 mnRef0Count;    // number of unreferenced ImplFontEntries
211     bool                mbPrinter;
212 
213     // cache of recently used font instances
214     struct IFSD_Equal { bool operator()( const ImplFontSelectData&, const ImplFontSelectData& ) const; };
215     struct IFSD_Hash { size_t operator()( const ImplFontSelectData& ) const; };
216     typedef ::std::hash_map<ImplFontSelectData,ImplFontEntry*,IFSD_Hash,IFSD_Equal > FontInstanceList;
217     FontInstanceList    maFontInstanceList;
218 
219     // cache of recently requested font names vs. selected font names
220     typedef ::std::hash_map<String,String,FontNameHash> FontNameList;
221     FontNameList        maFontNameList;
222 
223 public:
224                         ImplFontCache( bool bPrinter );
225                         ~ImplFontCache();
226 
227     ImplFontEntry*      GetFontEntry( ImplDevFontList*,
228                              const Font&, const Size& rPixelSize, float fExactHeight,
229 				ImplDirectFontSubstitution* pDevSpecific );
230     ImplFontEntry*      GetFontEntry( ImplDevFontList*,
231 		            ImplFontSelectData&, ImplDirectFontSubstitution* pDevSpecific );
232     ImplFontEntry*      GetGlyphFallbackFont( ImplDevFontList*, ImplFontSelectData&,
233                             int nFallbackLevel, rtl::OUString& rMissingCodes );
234     void                Release( ImplFontEntry* );
235     void                Invalidate();
236 };
237 
238 // ------------------
239 // - ImplOutDevData -
240 // ------------------
241 
242 namespace vcl { struct ControlLayoutData; }
243 // #i75163#
244 namespace basegfx { class B2DHomMatrix; }
245 
246 struct ImplOutDevData
247 {
248     VirtualDevice*				mpRotateDev;
249     vcl::ControlLayoutData*		mpRecordLayout;
250 	Rectangle					maRecordRect;
251     ImplDirectFontSubstitution		maDevFontSubst;
252 
253 	// #i75163#
254 	basegfx::B2DHomMatrix*		mpViewTransform;
255 	basegfx::B2DHomMatrix*		mpInverseViewTransform;
256 };
257 
258 void ImplFreeOutDevFontData();
259 
260 #endif // _SV_OUTDEV_H
261