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