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 INCLUDED_VCL_INC_OUTDEV_H
21 #define INCLUDED_VCL_INC_OUTDEV_H
22 
23 #include <set>
24 #include <vector>
25 
26 #include <tools/gen.hxx>
27 #include <vcl/vclptr.hxx>
28 
29 #include "fontinstance.hxx"
30 #include "PhysicalFontFace.hxx"
31 #include "impfontcache.hxx"
32 
33 class Size;
34 namespace vcl { class Font; }
35 class VirtualDevice;
36 class PhysicalFontCollection;
37 enum class AddFontSubstituteFlags;
38 
39 // an ImplDeviceFontList is created by a PhysicalFontCollection
40 // it becomes invalid when original PhysicalFontCollection is modified
41 class ImplDeviceFontList
42 {
43 private:
44     std::vector<rtl::Reference<PhysicalFontFace>> maDevFontVector;
45 
46 public:
ImplDeviceFontList()47                         ImplDeviceFontList()        { maDevFontVector.reserve(1024); }
Add(PhysicalFontFace * pFace)48     void                Add( PhysicalFontFace* pFace )  { maDevFontVector.push_back( pFace ); }
Get(int nIndex)49     PhysicalFontFace*   Get( int nIndex ) const     { return maDevFontVector[ nIndex ].get(); }
Count()50     int                 Count() const               { return maDevFontVector.size(); }
51 };
52 
53 class ImplDeviceFontSizeList
54 {
55 private:
56     std::vector<int>    maSizeList;
57 
58 public:
ImplDeviceFontSizeList()59                         ImplDeviceFontSizeList()
60                         { maSizeList.reserve( 32 ); }
Add(int nHeight)61     void                Add( int nHeight )      { maSizeList.push_back( nHeight ); }
Count()62     int                 Count() const           { return maSizeList.size(); }
Get(int nIndex)63     int                 Get( int nIndex ) const { return maSizeList[ nIndex ]; }
64 };
65 
66 // nowadays these substitutions are needed for backward compatibility and tight platform integration:
67 // - substitutions from configuration entries (Tools->Options->FontReplacement and/or fontconfig)
68 // - device specific substitutions (e.g. for PS printer builtin fonts)
69 // - substitutions for missing fonts defined by configuration entries (generic and/or platform dependent fallbacks)
70 // - substitutions for missing fonts defined by multi-token fontnames (e.g. fontname="SpecialFont;FallbackA;FallbackB")
71 // - substitutions for incomplete fonts (implicit, generic, EUDC and/or platform dependent fallbacks)
72 // - substitutions for missing symbol fonts by translating code points into other symbol fonts
73 
74 class ImplFontSubstitution
75 {
76     // TODO: there is more commonality between the different substitutions
77 protected:
~ImplFontSubstitution()78     virtual ~ImplFontSubstitution() {}
79 };
80 
81 // ImplDirectFontSubstitution is for Tools->Options->FontReplacement and PsPrinter substitutions
82 // The class is just a simple port of the unmaintainable manual-linked-list based mechanism
83 // TODO: get rid of this class when the Tools->Options->FontReplacement tabpage is gone for good
84 
85 struct ImplFontSubstEntry
86 {
87     OUString                  maSearchName;
88     OUString                  maSearchReplaceName;
89     AddFontSubstituteFlags    mnFlags;
90 
91     ImplFontSubstEntry(  const OUString& rFontName, const OUString& rSubstFontName, AddFontSubstituteFlags nSubstFlags );
92 };
93 
94 class ImplDirectFontSubstitution final
95 :   public ImplFontSubstitution
96 {
97 private:
98     std::vector<ImplFontSubstEntry> maFontSubstList;
99 public:
100     void    AddFontSubstitute( const OUString& rFontName, const OUString& rSubstName, AddFontSubstituteFlags nFlags );
101     void    RemoveFontsSubstitute();
102 
103     bool    FindFontSubstitute( OUString& rSubstName, std::u16string_view rFontName ) const;
104 };
105 
106 // PreMatchFontSubstitution
107 // abstracts the concept of a configured font substitution
108 // before the availability of the originally selected font has been checked
109 class ImplPreMatchFontSubstitution
110 :   public ImplFontSubstitution
111 {
112 public:
113     virtual bool FindFontSubstitute(FontSelectPattern&)  const = 0;
114 };
115 
116 // ImplGlyphFallbackFontSubstitution
117 // abstracts the concept of finding the best font to support an incomplete font
118 class ImplGlyphFallbackFontSubstitution
119 :   public ImplFontSubstitution
120 {
121 public:
122     virtual bool FindFontSubstitute(FontSelectPattern&, LogicalFontInstance* pLogicalFont, OUString& rMissingCodes) const = 0;
123 };
124 
125 namespace vcl { struct ControlLayoutData; }
126 // #i75163#
127 namespace basegfx { class B2DHomMatrix; }
128 
129 struct ImplOutDevData
130 {
131     VclPtr<VirtualDevice>       mpRotateDev;
132     vcl::ControlLayoutData*     mpRecordLayout;
133     tools::Rectangle                   maRecordRect;
134 
135     // #i75163#
136     basegfx::B2DHomMatrix*      mpViewTransform;
137     basegfx::B2DHomMatrix*      mpInverseViewTransform;
138 };
139 
140 void ImplFontSubstitute( OUString& rFontName );
141 
142 #endif // INCLUDED_VCL_INC_OUTDEV_H
143 
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
145