Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / inc / outdev.h
blobf40d5bd042092f55cce01130bf16f5c7e95bcb29
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_INC_OUTDEV_H
21 #define INCLUDED_VCL_INC_OUTDEV_H
23 #include <list>
24 #include <set>
25 #include <vector>
27 #include <tools/gen.hxx>
28 #include <vcl/vclptr.hxx>
30 #include "outfont.hxx"
31 #include "PhysicalFontFace.hxx"
33 class Size;
34 namespace vcl { class Font; }
35 class VirtualDevice;
36 class ImplGetDevFontList;
37 class GetDevSizeList;
38 class PhysicalFontCollection;
39 enum class AddFontSubstituteFlags;
41 // an ImplGetDevFontList is created by an PhysicalFontCollection
42 // it becomes invalid when original PhysicalFontCollection is modified
43 class ImplGetDevFontList
45 private:
46 std::vector<PhysicalFontFace*> maDevFontVector;
48 public:
49 ImplGetDevFontList() { maDevFontVector.reserve(1024); }
50 void Add( PhysicalFontFace* pFace ) { maDevFontVector.push_back( pFace ); }
51 PhysicalFontFace* Get( int nIndex ) const { return maDevFontVector[ nIndex ]; }
52 int Count() const { return maDevFontVector.size(); }
55 class ImplGetDevSizeList
57 private:
58 OUString maFontName;
59 std::vector<int> maSizeList;
61 public:
62 ImplGetDevSizeList( const OUString& rFontName )
63 : maFontName( rFontName ) { maSizeList.reserve( 32 ); }
64 void Add( int nHeight ) { maSizeList.push_back( nHeight ); }
65 int Count() const { return maSizeList.size(); }
66 int Get( int nIndex ) const { return maSizeList[ nIndex ]; }
67 const OUString& GetFontName() const { return maFontName; }
70 // nowadays these substitutions are needed for backward compatibility and tight platform integration:
71 // - substitutions from configuration entries (Tools->Options->FontReplacement and/or fontconfig)
72 // - device specific substitutions (e.g. for PS printer builtin fonts)
73 // - substitutions for missing fonts defined by configuration entries (generic and/or platform dependent fallbacks)
74 // - substitutions for missing fonts defined by multi-token fontnames (e.g. fontname="SpecialFont;FallbackA;FallbackB")
75 // - substitutions for incomplete fonts (implicit, generic, EUDC and/or platform dependent fallbacks)
76 // - substitutions for missing symbol fonts by translating code points into other symbol fonts
78 class ImplFontSubstitution
80 // TODO: there is more commonality between the different substitutions
81 protected:
82 virtual ~ImplFontSubstitution() {}
85 // ImplDirectFontSubstitution is for Tools->Options->FontReplacement and PsPrinter substitutions
86 // The clss is just a simple port of the unmaintainable manual-linked-list based mechanism
87 // TODO: get rid of this class when the Tools->Options->FontReplacement tabpage is gone for good
89 struct ImplFontSubstEntry
91 OUString maName;
92 OUString maReplaceName;
93 OUString maSearchName;
94 OUString maSearchReplaceName;
95 AddFontSubstituteFlags mnFlags;
97 ImplFontSubstEntry( const OUString& rFontName, const OUString& rSubstFontName, AddFontSubstituteFlags nSubstFlags );
100 class ImplDirectFontSubstitution
101 : public ImplFontSubstitution
103 private:
104 typedef std::list<ImplFontSubstEntry> FontSubstList;
105 FontSubstList maFontSubstList;
106 public:
107 void AddFontSubstitute( const OUString& rFontName, const OUString& rSubstName, AddFontSubstituteFlags nFlags );
108 void RemoveFontSubstitute( int nIndex );
109 int GetFontSubstituteCount() const { return maFontSubstList.size(); };
110 bool Empty() const { return maFontSubstList.empty(); }
111 void Clear() { maFontSubstList.clear(); }
113 bool FindFontSubstitute( OUString& rSubstName, const OUString& rFontName, AddFontSubstituteFlags nFlags ) const;
116 // PreMatchFontSubstitution
117 // abstracts the concept of a configured font substitution
118 // before the availability of the originally selected font has been checked
119 class ImplPreMatchFontSubstitution
120 : public ImplFontSubstitution
122 public:
123 virtual bool FindFontSubstitute( FontSelectPattern& ) const = 0;
126 // ImplGlyphFallbackFontSubstitution
127 // abstracts the concept of finding the best font to support an incomplete font
128 class ImplGlyphFallbackFontSubstitution
129 : public ImplFontSubstitution
131 public:
132 virtual bool FindFontSubstitute( FontSelectPattern&, OUString& rMissingCodes ) const = 0;
135 // TODO: closely couple with PhysicalFontCollection
137 class ImplFontCache
139 private:
140 ImplFontEntry* mpFirstEntry;
141 int mnRef0Count; // number of unreferenced ImplFontEntries
143 // cache of recently used font instances
144 struct IFSD_Equal { bool operator()( const FontSelectPattern&, const FontSelectPattern& ) const; };
145 struct IFSD_Hash { size_t operator()( const FontSelectPattern& ) const; };
146 typedef std::unordered_map<FontSelectPattern,ImplFontEntry*,IFSD_Hash,IFSD_Equal > FontInstanceList;
147 FontInstanceList maFontInstanceList;
149 int CountUnreferencedEntries() const;
151 public:
152 ImplFontCache();
153 ~ImplFontCache();
155 ImplFontEntry* GetFontEntry( PhysicalFontCollection*,
156 const vcl::Font&, const Size& rPixelSize, float fExactHeight);
157 ImplFontEntry* GetFontEntry( PhysicalFontCollection*, FontSelectPattern& );
158 ImplFontEntry* GetGlyphFallbackFont( PhysicalFontCollection*, FontSelectPattern&,
159 int nFallbackLevel, OUString& rMissingCodes );
161 /// Increase the refcount of the given ImplFontEntry.
162 void Acquire(ImplFontEntry*);
163 /// Decrease the refcount and potentially cleanup the entries with zero refcount from the cache.
164 void Release(ImplFontEntry*);
166 void Invalidate();
169 namespace vcl { struct ControlLayoutData; }
170 // #i75163#
171 namespace basegfx { class B2DHomMatrix; }
173 struct ImplOutDevData
175 VclPtr<VirtualDevice> mpRotateDev;
176 vcl::ControlLayoutData* mpRecordLayout;
177 Rectangle maRecordRect;
179 // #i75163#
180 basegfx::B2DHomMatrix* mpViewTransform;
181 basegfx::B2DHomMatrix* mpInverseViewTransform;
184 void ImplFontSubstitute( OUString& rFontName );
186 #endif // INCLUDED_VCL_INC_OUTDEV_H
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */