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