1*9f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9f62ea84SAndrew Rist * distributed with this work for additional information 6*9f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 9*9f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 10*9f62ea84SAndrew Rist * 11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*9f62ea84SAndrew Rist * 13*9f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9f62ea84SAndrew Rist * software distributed under the License is distributed on an 15*9f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 17*9f62ea84SAndrew Rist * specific language governing permissions and limitations 18*9f62ea84SAndrew Rist * under the License. 19*9f62ea84SAndrew Rist * 20*9f62ea84SAndrew Rist *************************************************************/ 21*9f62ea84SAndrew Rist 22*9f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <string.h> 28cdf0e10cSrcweir #include <malloc.h> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include "rtl/logfile.hxx" 31cdf0e10cSrcweir #include "rtl/tencinfo.h" 32cdf0e10cSrcweir #include "rtl/textcvt.h" 33cdf0e10cSrcweir #include "rtl/bootstrap.hxx" 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include "i18npool/mslangid.hxx" 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include "osl/module.h" 38cdf0e10cSrcweir #include "osl/file.hxx" 39cdf0e10cSrcweir #include "osl/thread.hxx" 40cdf0e10cSrcweir #include "osl/process.h" 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include "basegfx/polygon/b2dpolygon.hxx" 43cdf0e10cSrcweir #include "basegfx/polygon/b2dpolypolygon.hxx" 44cdf0e10cSrcweir #include "basegfx/matrix/b2dhommatrix.hxx" 45cdf0e10cSrcweir #include "basegfx/matrix/b2dhommatrixtools.hxx" 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include "unotools/fontcfg.hxx" // for IMPL_FONT_ATTR_SYMBOL 48cdf0e10cSrcweir 49cdf0e10cSrcweir #include "vcl/font.hxx" 50cdf0e10cSrcweir #include "vcl/svapp.hxx" 51cdf0e10cSrcweir 52cdf0e10cSrcweir #include "tools/poly.hxx" 53cdf0e10cSrcweir #include "tools/debug.hxx" 54cdf0e10cSrcweir #include "tools/stream.hxx" 55cdf0e10cSrcweir 56cdf0e10cSrcweir #include <tools/prewin.h> 57cdf0e10cSrcweir #include <windows.h> 58cdf0e10cSrcweir #include <tools/postwin.h> 59cdf0e10cSrcweir 60cdf0e10cSrcweir #include <vcl/sysdata.hxx> 61cdf0e10cSrcweir 62cdf0e10cSrcweir #include "win/wincomp.hxx" 63cdf0e10cSrcweir #include "win/saldata.hxx" 64cdf0e10cSrcweir #include "win/salgdi.h" 65cdf0e10cSrcweir 66cdf0e10cSrcweir #include "outfont.hxx" 67cdf0e10cSrcweir #include "fontsubset.hxx" 68cdf0e10cSrcweir #include "sallayout.hxx" 69cdf0e10cSrcweir #include "outdev.h" // for ImplGlyphFallbackFontSubstitution 70cdf0e10cSrcweir #include "sft.hxx" 71cdf0e10cSrcweir 72cdf0e10cSrcweir #ifdef GCP_KERN_HACK 73cdf0e10cSrcweir #include <algorithm> 74cdf0e10cSrcweir #endif 75cdf0e10cSrcweir 76cdf0e10cSrcweir #ifdef ENABLE_GRAPHITE 77cdf0e10cSrcweir #include <graphite/GrClient.h> 78cdf0e10cSrcweir #include <graphite/WinFont.h> 79cdf0e10cSrcweir #endif 80cdf0e10cSrcweir 81cdf0e10cSrcweir #include <vector> 82cdf0e10cSrcweir #include <set> 83cdf0e10cSrcweir #include <map> 84cdf0e10cSrcweir 85cdf0e10cSrcweir using namespace vcl; 86cdf0e10cSrcweir 87cdf0e10cSrcweir static const int MAXFONTHEIGHT = 2048; 88cdf0e10cSrcweir 89cdf0e10cSrcweir // ----------- 90cdf0e10cSrcweir // - Inlines - 91cdf0e10cSrcweir // ----------- 92cdf0e10cSrcweir 93cdf0e10cSrcweir inline FIXED FixedFromDouble( double d ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir const long l = (long) ( d * 65536. ); 96cdf0e10cSrcweir return *(FIXED*) &l; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir // ----------------------------------------------------------------------- 100cdf0e10cSrcweir 101cdf0e10cSrcweir inline int IntTimes256FromFixed(FIXED f) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir int nFixedTimes256 = (f.value << 8) + ((f.fract+0x80) >> 8); 104cdf0e10cSrcweir return nFixedTimes256; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir // ======================================================================= 108cdf0e10cSrcweir 109cdf0e10cSrcweir // these variables can be static because they store system wide settings 110cdf0e10cSrcweir static bool bImplSalCourierScalable = false; 111cdf0e10cSrcweir static bool bImplSalCourierNew = false; 112cdf0e10cSrcweir 113cdf0e10cSrcweir 114cdf0e10cSrcweir // ======================================================================= 115cdf0e10cSrcweir 116cdf0e10cSrcweir // ----------------------------------------------------------------------- 117cdf0e10cSrcweir 118cdf0e10cSrcweir // TODO: also support temporary TTC font files 119cdf0e10cSrcweir typedef std::map< String, ImplDevFontAttributes > FontAttrMap; 120cdf0e10cSrcweir 121cdf0e10cSrcweir class ImplFontAttrCache 122cdf0e10cSrcweir { 123cdf0e10cSrcweir private: 124cdf0e10cSrcweir FontAttrMap aFontAttributes; 125cdf0e10cSrcweir rtl::OUString aCacheFileName; 126cdf0e10cSrcweir String aBaseURL; 127cdf0e10cSrcweir sal_Bool bModified; 128cdf0e10cSrcweir 129cdf0e10cSrcweir protected: 130cdf0e10cSrcweir String OptimizeURL( const String& rURL ) const; 131cdf0e10cSrcweir 132cdf0e10cSrcweir enum{ MAGIC = 0x12349876 }; // change if fontattrcache format changes 133cdf0e10cSrcweir 134cdf0e10cSrcweir public: 135cdf0e10cSrcweir ImplFontAttrCache( const String& rCacheFileName, const String& rBaseURL ); 136cdf0e10cSrcweir ~ImplFontAttrCache(); 137cdf0e10cSrcweir 138cdf0e10cSrcweir ImplDevFontAttributes GetFontAttr( const String& rFontFileName ) const; 139cdf0e10cSrcweir void AddFontAttr( const String& rFontFileName, const ImplDevFontAttributes& ); 140cdf0e10cSrcweir }; 141cdf0e10cSrcweir 142cdf0e10cSrcweir ImplFontAttrCache::ImplFontAttrCache( const String& rFileNameURL, const String& rBaseURL ) : aBaseURL( rBaseURL ) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir bModified = FALSE; 145cdf0e10cSrcweir aBaseURL.ToLowerAscii(); // Windows only, no problem... 146cdf0e10cSrcweir 147cdf0e10cSrcweir // open the cache file 148cdf0e10cSrcweir osl::FileBase::getSystemPathFromFileURL( rFileNameURL, aCacheFileName ); 149cdf0e10cSrcweir SvFileStream aCacheFile( aCacheFileName, STREAM_READ ); 150cdf0e10cSrcweir if( !aCacheFile.IsOpen() ) 151cdf0e10cSrcweir return; 152cdf0e10cSrcweir 153cdf0e10cSrcweir // check the cache version 154cdf0e10cSrcweir sal_uInt32 nCacheMagic; 155cdf0e10cSrcweir aCacheFile >> nCacheMagic; 156cdf0e10cSrcweir if( nCacheMagic != ImplFontAttrCache::MAGIC ) 157cdf0e10cSrcweir return; // ignore cache and rewrite if no match 158cdf0e10cSrcweir 159cdf0e10cSrcweir // read the cache entries from the file 160cdf0e10cSrcweir String aFontFileURL, aFontName; 161cdf0e10cSrcweir ImplDevFontAttributes aDFA; 162cdf0e10cSrcweir for(;;) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir aCacheFile.ReadByteString( aFontFileURL, RTL_TEXTENCODING_UTF8 ); 165cdf0e10cSrcweir if( !aFontFileURL.Len() ) 166cdf0e10cSrcweir break; 167cdf0e10cSrcweir aCacheFile.ReadByteString( aDFA.maName, RTL_TEXTENCODING_UTF8 ); 168cdf0e10cSrcweir 169cdf0e10cSrcweir short n; 170cdf0e10cSrcweir aCacheFile >> n; aDFA.meWeight = static_cast<FontWeight>(n); 171cdf0e10cSrcweir aCacheFile >> n; aDFA.meItalic = static_cast<FontItalic>(n); 172cdf0e10cSrcweir aCacheFile >> n; aDFA.mePitch = static_cast<FontPitch>(n); 173cdf0e10cSrcweir aCacheFile >> n; aDFA.meWidthType = static_cast<FontWidth>(n); 174cdf0e10cSrcweir aCacheFile >> n; aDFA.meFamily = static_cast<FontFamily>(n); 175cdf0e10cSrcweir aCacheFile >> n; aDFA.mbSymbolFlag = (n != 0); 176cdf0e10cSrcweir 177cdf0e10cSrcweir aCacheFile.ReadByteStringLine( aDFA.maStyleName, RTL_TEXTENCODING_UTF8 ); 178cdf0e10cSrcweir 179cdf0e10cSrcweir aFontAttributes[ aFontFileURL ] = aDFA; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir ImplFontAttrCache::~ImplFontAttrCache() 184cdf0e10cSrcweir { 185cdf0e10cSrcweir if ( bModified ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir SvFileStream aCacheFile( aCacheFileName, STREAM_WRITE|STREAM_TRUNC ); 188cdf0e10cSrcweir if ( aCacheFile.IsWritable() ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir sal_uInt32 nCacheMagic = ImplFontAttrCache::MAGIC; 191cdf0e10cSrcweir aCacheFile << nCacheMagic; 192cdf0e10cSrcweir 193cdf0e10cSrcweir // write the cache entries to the file 194cdf0e10cSrcweir FontAttrMap::const_iterator aIter = aFontAttributes.begin(); 195cdf0e10cSrcweir while ( aIter != aFontAttributes.end() ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir const String rFontFileURL( (*aIter).first ); 198cdf0e10cSrcweir const ImplDevFontAttributes& rDFA( (*aIter).second ); 199cdf0e10cSrcweir aCacheFile.WriteByteString( rFontFileURL, RTL_TEXTENCODING_UTF8 ); 200cdf0e10cSrcweir aCacheFile.WriteByteString( rDFA.maName, RTL_TEXTENCODING_UTF8 ); 201cdf0e10cSrcweir 202cdf0e10cSrcweir aCacheFile << static_cast<short>(rDFA.meWeight); 203cdf0e10cSrcweir aCacheFile << static_cast<short>(rDFA.meItalic); 204cdf0e10cSrcweir aCacheFile << static_cast<short>(rDFA.mePitch); 205cdf0e10cSrcweir aCacheFile << static_cast<short>(rDFA.meWidthType); 206cdf0e10cSrcweir aCacheFile << static_cast<short>(rDFA.meFamily); 207cdf0e10cSrcweir aCacheFile << static_cast<short>(rDFA.mbSymbolFlag != false); 208cdf0e10cSrcweir 209cdf0e10cSrcweir aCacheFile.WriteByteStringLine( rDFA.maStyleName, RTL_TEXTENCODING_UTF8 ); 210cdf0e10cSrcweir 211cdf0e10cSrcweir aIter++; 212cdf0e10cSrcweir } 213cdf0e10cSrcweir // EOF Marker 214cdf0e10cSrcweir String aEmptyStr; 215cdf0e10cSrcweir aCacheFile.WriteByteString( aEmptyStr, RTL_TEXTENCODING_UTF8 ); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir } 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir String ImplFontAttrCache::OptimizeURL( const String& rURL ) const 221cdf0e10cSrcweir { 222cdf0e10cSrcweir String aOptimizedFontFileURL( rURL ); 223cdf0e10cSrcweir aOptimizedFontFileURL.ToLowerAscii(); // Windows only, no problem... 224cdf0e10cSrcweir if ( aOptimizedFontFileURL.CompareTo( aBaseURL, aBaseURL.Len() ) == COMPARE_EQUAL ) 225cdf0e10cSrcweir aOptimizedFontFileURL = aOptimizedFontFileURL.Copy( aBaseURL.Len() ); 226cdf0e10cSrcweir return aOptimizedFontFileURL; 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir ImplDevFontAttributes ImplFontAttrCache::GetFontAttr( const String& rFontFileName ) const 230cdf0e10cSrcweir { 231cdf0e10cSrcweir ImplDevFontAttributes aDFA; 232cdf0e10cSrcweir FontAttrMap::const_iterator it = aFontAttributes.find( OptimizeURL( rFontFileName ) ); 233cdf0e10cSrcweir if( it != aFontAttributes.end() ) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir aDFA = it->second; 236cdf0e10cSrcweir } 237cdf0e10cSrcweir return aDFA; 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir void ImplFontAttrCache::AddFontAttr( const String& rFontFileName, const ImplDevFontAttributes& rDFA ) 241cdf0e10cSrcweir { 242cdf0e10cSrcweir DBG_ASSERT( rFontFileName.Len() && rDFA.maName.Len(), "ImplFontNameCache::AddFontName - invalid data!" ); 243cdf0e10cSrcweir if ( rFontFileName.Len() && rDFA.maName.Len() ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir aFontAttributes.insert( FontAttrMap::value_type( OptimizeURL( rFontFileName ), rDFA ) ); 246cdf0e10cSrcweir bModified = TRUE; 247cdf0e10cSrcweir } 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250cdf0e10cSrcweir // ======================================================================= 251cdf0e10cSrcweir 252cdf0e10cSrcweir // raw font data with a scoped lifetime 253cdf0e10cSrcweir class RawFontData 254cdf0e10cSrcweir { 255cdf0e10cSrcweir public: 256cdf0e10cSrcweir explicit RawFontData( HDC, DWORD nTableTag=0 ); 257cdf0e10cSrcweir ~RawFontData() { delete[] mpRawBytes; } 258cdf0e10cSrcweir const unsigned char* get() const { return mpRawBytes; } 259cdf0e10cSrcweir const unsigned char* steal() { unsigned char* p = mpRawBytes; mpRawBytes = NULL; return p; } 260cdf0e10cSrcweir const int size() const { return mnByteCount; } 261cdf0e10cSrcweir 262cdf0e10cSrcweir private: 263cdf0e10cSrcweir unsigned char* mpRawBytes; 264cdf0e10cSrcweir int mnByteCount; 265cdf0e10cSrcweir }; 266cdf0e10cSrcweir 267cdf0e10cSrcweir RawFontData::RawFontData( HDC hDC, DWORD nTableTag ) 268cdf0e10cSrcweir : mpRawBytes( NULL ) 269cdf0e10cSrcweir , mnByteCount( 0 ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir // get required size in bytes 272cdf0e10cSrcweir mnByteCount = ::GetFontData( hDC, nTableTag, 0, NULL, 0 ); 273cdf0e10cSrcweir if( mnByteCount == GDI_ERROR ) 274cdf0e10cSrcweir return; 275cdf0e10cSrcweir else if( !mnByteCount ) 276cdf0e10cSrcweir return; 277cdf0e10cSrcweir 278cdf0e10cSrcweir // allocate the array 279cdf0e10cSrcweir mpRawBytes = new unsigned char[ mnByteCount ]; 280cdf0e10cSrcweir 281cdf0e10cSrcweir // get raw data in chunks small enough for GetFontData() 282cdf0e10cSrcweir int nRawDataOfs = 0; 283cdf0e10cSrcweir DWORD nMaxChunkSize = 0x100000; 284cdf0e10cSrcweir for(;;) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir // calculate remaining raw data to get 287cdf0e10cSrcweir DWORD nFDGet = mnByteCount - nRawDataOfs; 288cdf0e10cSrcweir if( nFDGet <= 0 ) 289cdf0e10cSrcweir break; 290cdf0e10cSrcweir // #i56745# limit GetFontData requests 291cdf0e10cSrcweir if( nFDGet > nMaxChunkSize ) 292cdf0e10cSrcweir nFDGet = nMaxChunkSize; 293cdf0e10cSrcweir const DWORD nFDGot = ::GetFontData( hDC, nTableTag, nRawDataOfs, 294cdf0e10cSrcweir (void*)(mpRawBytes + nRawDataOfs), nFDGet ); 295cdf0e10cSrcweir if( !nFDGot ) 296cdf0e10cSrcweir break; 297cdf0e10cSrcweir else if( nFDGot != GDI_ERROR ) 298cdf0e10cSrcweir nRawDataOfs += nFDGot; 299cdf0e10cSrcweir else 300cdf0e10cSrcweir { 301cdf0e10cSrcweir // was the chunk too big? reduce it 302cdf0e10cSrcweir nMaxChunkSize /= 2; 303cdf0e10cSrcweir if( nMaxChunkSize < 0x10000 ) 304cdf0e10cSrcweir break; 305cdf0e10cSrcweir } 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir // cleanup if the raw data is incomplete 309cdf0e10cSrcweir if( nRawDataOfs != mnByteCount ) 310cdf0e10cSrcweir { 311cdf0e10cSrcweir delete[] mpRawBytes; 312cdf0e10cSrcweir mpRawBytes = NULL; 313cdf0e10cSrcweir } 314cdf0e10cSrcweir } 315cdf0e10cSrcweir 316cdf0e10cSrcweir // =========================================================================== 317cdf0e10cSrcweir // platform specific font substitution hooks for glyph fallback enhancement 318cdf0e10cSrcweir // TODO: move into i18n module (maybe merge with svx/ucsubset.* 319cdf0e10cSrcweir // or merge with i18nutil/source/utility/unicode_data.h) 320cdf0e10cSrcweir struct Unicode2LangType 321cdf0e10cSrcweir { 322cdf0e10cSrcweir sal_UCS4 mnMinCode; 323cdf0e10cSrcweir sal_UCS4 mnMaxCode; 324cdf0e10cSrcweir LanguageType mnLangID; 325cdf0e10cSrcweir }; 326cdf0e10cSrcweir 327cdf0e10cSrcweir // entries marked with default-CJK get replaced with the default-CJK language 328cdf0e10cSrcweir #define LANGUAGE_DEFAULT_CJK 0xFFF0 329cdf0e10cSrcweir 330cdf0e10cSrcweir // map unicode ranges to languages supported by OOo 331cdf0e10cSrcweir // NOTE: due to the binary search used this list must be sorted by mnMinCode 332cdf0e10cSrcweir static Unicode2LangType aLangFromCodeChart[]= { 333cdf0e10cSrcweir {0x0000, 0x007F, LANGUAGE_ENGLISH}, // Basic Latin 334cdf0e10cSrcweir {0x0080, 0x024F, LANGUAGE_ENGLISH}, // Latin Extended-A and Latin Extended-B 335cdf0e10cSrcweir {0x0250, 0x02AF, LANGUAGE_SYSTEM}, // IPA Extensions 336cdf0e10cSrcweir {0x0370, 0x03FF, LANGUAGE_GREEK}, // Greek 337cdf0e10cSrcweir {0x0590, 0x05FF, LANGUAGE_HEBREW}, // Hebrew 338cdf0e10cSrcweir {0x0600, 0x06FF, LANGUAGE_ARABIC_PRIMARY_ONLY}, // Arabic 339cdf0e10cSrcweir {0x0900, 0x097F, LANGUAGE_HINDI}, // Devanagari 340cdf0e10cSrcweir {0x0980, 0x09FF, LANGUAGE_BENGALI}, // Bengali 341cdf0e10cSrcweir {0x0A80, 0x0AFF, LANGUAGE_GUJARATI}, // Gujarati 342cdf0e10cSrcweir {0x0B00, 0x0B7F, LANGUAGE_ORIYA}, // Oriya 343cdf0e10cSrcweir {0x0B80, 0x0BFF, LANGUAGE_TAMIL}, // Tamil 344cdf0e10cSrcweir {0x0C00, 0x0C7F, LANGUAGE_TELUGU}, // Telugu 345cdf0e10cSrcweir {0x0C80, 0x0CFF, LANGUAGE_KANNADA}, // Kannada 346cdf0e10cSrcweir {0x0D00, 0x0D7F, LANGUAGE_MALAYALAM}, // Malayalam 347cdf0e10cSrcweir {0x0D80, 0x0D7F, LANGUAGE_SINHALESE_SRI_LANKA}, // Sinhala 348cdf0e10cSrcweir {0x0E00, 0x0E7F, LANGUAGE_THAI}, // Thai 349cdf0e10cSrcweir {0x0E80, 0x0EFF, LANGUAGE_LAO}, // Lao 350cdf0e10cSrcweir {0x0F00, 0x0FFF, LANGUAGE_TIBETAN}, // Tibetan 351cdf0e10cSrcweir {0x1000, 0x109F, LANGUAGE_BURMESE}, // Burmese 352cdf0e10cSrcweir {0x10A0, 0x10FF, LANGUAGE_GEORGIAN}, // Georgian 353cdf0e10cSrcweir {0x1100, 0x11FF, LANGUAGE_KOREAN}, // Hangul Jamo, Korean-specific 354cdf0e10cSrcweir // {0x1200, 0x139F, LANGUAGE_AMHARIC_ETHIOPIA}, // Ethiopic 355cdf0e10cSrcweir // {0x1200, 0x139F, LANGUAGE_TIGRIGNA_ETHIOPIA}, // Ethiopic 356cdf0e10cSrcweir {0x13A0, 0x13FF, LANGUAGE_CHEROKEE_UNITED_STATES}, // Cherokee 357cdf0e10cSrcweir // {0x1400, 0x167F, LANGUAGE_CANADIAN_ABORIGINAL}, // Canadian Aboriginial Syllabics 358cdf0e10cSrcweir // {0x1680, 0x169F, LANGUAGE_OGHAM}, // Ogham 359cdf0e10cSrcweir // {0x16A0, 0x16F0, LANGUAGE_RUNIC}, // Runic 360cdf0e10cSrcweir // {0x1700, 0x171F, LANGUAGE_TAGALOG}, // Tagalog 361cdf0e10cSrcweir // {0x1720, 0x173F, LANGUAGE_HANUNOO}, // Hanunoo 362cdf0e10cSrcweir // {0x1740, 0x175F, LANGUAGE_BUHID}, // Buhid 363cdf0e10cSrcweir // {0x1760, 0x177F, LANGUAGE_TAGBANWA}, // Tagbanwa 364cdf0e10cSrcweir {0x1780, 0x17FF, LANGUAGE_KHMER}, // Khmer 365cdf0e10cSrcweir {0x18A0, 0x18AF, LANGUAGE_MONGOLIAN}, // Mongolian 366cdf0e10cSrcweir // {0x1900, 0x194F, LANGUAGE_LIMBU}, // Limbu 367cdf0e10cSrcweir // {0x1950, 0x197F, LANGUAGE_TAILE}, // Tai Le 368cdf0e10cSrcweir // {0x1980, 0x19DF, LANGUAGE_TAILUE}, // Tai Lue 369cdf0e10cSrcweir {0x19E0, 0x19FF, LANGUAGE_KHMER}, // Khmer Symbols 370cdf0e10cSrcweir // {0x1A00, 0x1A1F, LANGUAGE_BUGINESE}, // Buginese/Lontara 371cdf0e10cSrcweir // {0x1B00, 0x1B7F, LANGUAGE_BALINESE}, // Balinese 372cdf0e10cSrcweir // {0x1D00, 0x1DFF, LANGUAGE_NONE}, // Phonetic Symbols 373cdf0e10cSrcweir {0x1E00, 0x1EFF, LANGUAGE_ENGLISH}, // Latin Extended Additional 374cdf0e10cSrcweir {0x1F00, 0x1FFF, LANGUAGE_GREEK}, // Greek Extended 375cdf0e10cSrcweir {0x2C60, 0x2C7F, LANGUAGE_ENGLISH}, // Latin Extended-C 376cdf0e10cSrcweir {0x2E80, 0x2FFf, LANGUAGE_CHINESE_SIMPLIFIED}, // CJK Radicals Supplement + Kangxi Radical + Ideographic Description Characters 377cdf0e10cSrcweir {0x3000, 0x303F, LANGUAGE_DEFAULT_CJK}, // CJK Symbols and punctuation 378cdf0e10cSrcweir {0x3040, 0x30FF, LANGUAGE_JAPANESE}, // Japanese Hiragana + Katakana 379cdf0e10cSrcweir {0x3100, 0x312F, LANGUAGE_CHINESE_TRADITIONAL}, // Bopomofo 380cdf0e10cSrcweir {0x3130, 0x318F, LANGUAGE_KOREAN}, // Hangul Compatibility Jamo, Kocrean-specific 381cdf0e10cSrcweir {0x3190, 0x319F, LANGUAGE_JAPANESE}, // Kanbun 382cdf0e10cSrcweir {0x31A0, 0x31BF, LANGUAGE_CHINESE_TRADITIONAL}, // Bopomofo Extended 383cdf0e10cSrcweir {0x31C0, 0x31EF, LANGUAGE_DEFAULT_CJK}, // CJK Ideographs 384cdf0e10cSrcweir {0x31F0, 0x31FF, LANGUAGE_JAPANESE}, // Japanese Katakana Phonetic Extensions 385cdf0e10cSrcweir {0x3200, 0x321F, LANGUAGE_KOREAN}, // Parenthesized Hangul 386cdf0e10cSrcweir {0x3220, 0x325F, LANGUAGE_DEFAULT_CJK}, // Parenthesized Ideographs 387cdf0e10cSrcweir {0x3260, 0x327F, LANGUAGE_KOREAN}, // Circled Hangul 388cdf0e10cSrcweir {0x3280, 0x32CF, LANGUAGE_DEFAULT_CJK}, // Circled Ideographs 389cdf0e10cSrcweir {0x32d0, 0x32FF, LANGUAGE_JAPANESE}, // Japanese Circled Katakana 390cdf0e10cSrcweir {0x3400, 0x4DBF, LANGUAGE_DEFAULT_CJK}, // CJK Unified Ideographs Extension A 391cdf0e10cSrcweir {0x4E00, 0x9FCF, LANGUAGE_DEFAULT_CJK}, // Unified CJK Ideographs 392cdf0e10cSrcweir {0xA720, 0xA7FF, LANGUAGE_ENGLISH}, // Latin Extended-D 393cdf0e10cSrcweir {0xAC00, 0xD7AF, LANGUAGE_KOREAN}, // Hangul Syllables, Korean-specific 394cdf0e10cSrcweir {0xF900, 0xFAFF, LANGUAGE_DEFAULT_CJK}, // CJK Compatibility Ideographs 395cdf0e10cSrcweir {0xFB00, 0xFB4F, LANGUAGE_HEBREW}, // Hebrew Presentation Forms 396cdf0e10cSrcweir {0xFB50, 0xFDFF, LANGUAGE_ARABIC_PRIMARY_ONLY}, // Arabic Presentation Forms-A 397cdf0e10cSrcweir {0xFE70, 0xFEFE, LANGUAGE_ARABIC_PRIMARY_ONLY}, // Arabic Presentation Forms-B 398cdf0e10cSrcweir {0xFF65, 0xFF9F, LANGUAGE_JAPANESE}, // Japanese Halfwidth Katakana variant 399cdf0e10cSrcweir {0xFFA0, 0xFFDC, LANGUAGE_KOREAN}, // Kocrean halfwidth hangual variant 400cdf0e10cSrcweir {0x10140, 0x1018F, LANGUAGE_GREEK}, // Ancient Greak numbers 401cdf0e10cSrcweir {0x1D200, 0x1D24F, LANGUAGE_GREEK}, // Ancient Greek Musical 402cdf0e10cSrcweir {0x20000, 0x2A6DF, LANGUAGE_DEFAULT_CJK}, // CJK Unified Ideographs Extension B 403cdf0e10cSrcweir {0x2F800, 0x2FA1F, LANGUAGE_DEFAULT_CJK} // CJK Compatibility Ideographs Supplement 404cdf0e10cSrcweir }; 405cdf0e10cSrcweir 406cdf0e10cSrcweir // get language matching to the missing char 407cdf0e10cSrcweir LanguageType MapCharToLanguage( sal_UCS4 uChar ) 408cdf0e10cSrcweir { 409cdf0e10cSrcweir // entries marked with default-CJK get replaced with the prefered CJK language 410cdf0e10cSrcweir static bool bFirst = true; 411cdf0e10cSrcweir if( bFirst ) 412cdf0e10cSrcweir { 413cdf0e10cSrcweir bFirst = false; 414cdf0e10cSrcweir 415cdf0e10cSrcweir // use method suggested in #i97086# to determnine the systems default language 416cdf0e10cSrcweir // TODO: move into i18npool or sal/osl/w32/nlsupport.c 417cdf0e10cSrcweir LanguageType nDefaultLang = 0; 418cdf0e10cSrcweir HKEY hKey = NULL; 419cdf0e10cSrcweir LONG lResult = ::RegOpenKeyExA( HKEY_LOCAL_MACHINE, 420cdf0e10cSrcweir "SYSTEM\\CurrentControlSet\\Control\\Nls\\Language", 421cdf0e10cSrcweir 0, KEY_QUERY_VALUE, &hKey ); 422cdf0e10cSrcweir char aKeyValBuf[16]; 423cdf0e10cSrcweir DWORD nKeyValSize = sizeof(aKeyValBuf); 424cdf0e10cSrcweir if( ERROR_SUCCESS == lResult ) 425cdf0e10cSrcweir lResult = RegQueryValueExA( hKey, "Default", NULL, NULL, (LPBYTE)aKeyValBuf, &nKeyValSize ); 426cdf0e10cSrcweir aKeyValBuf[ sizeof(aKeyValBuf)-1 ] = '\0'; 427cdf0e10cSrcweir if( ERROR_SUCCESS == lResult ) 428cdf0e10cSrcweir nDefaultLang = (LanguageType)rtl_str_toInt32( aKeyValBuf, 16 ); 429cdf0e10cSrcweir 430cdf0e10cSrcweir // TODO: use the default-CJK language selected in 431cdf0e10cSrcweir // Tools->Options->LangSettings->Languages when it becomes available here 432cdf0e10cSrcweir if( !nDefaultLang ) 433cdf0e10cSrcweir nDefaultLang = Application::GetSettings().GetUILanguage(); 434cdf0e10cSrcweir 435cdf0e10cSrcweir LanguageType nDefaultCJK = LANGUAGE_CHINESE; 436cdf0e10cSrcweir switch( nDefaultLang ) 437cdf0e10cSrcweir { 438cdf0e10cSrcweir case LANGUAGE_JAPANESE: 439cdf0e10cSrcweir case LANGUAGE_KOREAN: 440cdf0e10cSrcweir case LANGUAGE_KOREAN_JOHAB: 441cdf0e10cSrcweir case LANGUAGE_CHINESE_SIMPLIFIED: 442cdf0e10cSrcweir case LANGUAGE_CHINESE_TRADITIONAL: 443cdf0e10cSrcweir case LANGUAGE_CHINESE_SINGAPORE: 444cdf0e10cSrcweir case LANGUAGE_CHINESE_HONGKONG: 445cdf0e10cSrcweir case LANGUAGE_CHINESE_MACAU: 446cdf0e10cSrcweir nDefaultCJK = nDefaultLang; 447cdf0e10cSrcweir break; 448cdf0e10cSrcweir default: 449cdf0e10cSrcweir nDefaultCJK = LANGUAGE_CHINESE; 450cdf0e10cSrcweir break; 451cdf0e10cSrcweir } 452cdf0e10cSrcweir 453cdf0e10cSrcweir // change the marked entries to prefered language 454cdf0e10cSrcweir static const int nCount = (sizeof(aLangFromCodeChart) / sizeof(*aLangFromCodeChart)); 455cdf0e10cSrcweir for( int i = 0; i < nCount; ++i ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir if( aLangFromCodeChart[ i].mnLangID == LANGUAGE_DEFAULT_CJK ) 458cdf0e10cSrcweir aLangFromCodeChart[ i].mnLangID = nDefaultCJK; 459cdf0e10cSrcweir } 460cdf0e10cSrcweir } 461cdf0e10cSrcweir 462cdf0e10cSrcweir // binary search 463cdf0e10cSrcweir int nLow = 0; 464cdf0e10cSrcweir int nHigh = (sizeof(aLangFromCodeChart) / sizeof(*aLangFromCodeChart)) - 1; 465cdf0e10cSrcweir while( nLow <= nHigh ) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir int nMiddle = (nHigh + nLow) / 2; 468cdf0e10cSrcweir if( uChar < aLangFromCodeChart[ nMiddle].mnMinCode ) 469cdf0e10cSrcweir nHigh = nMiddle - 1; 470cdf0e10cSrcweir else if( uChar > aLangFromCodeChart[ nMiddle].mnMaxCode ) 471cdf0e10cSrcweir nLow = nMiddle + 1; 472cdf0e10cSrcweir else 473cdf0e10cSrcweir return aLangFromCodeChart[ nMiddle].mnLangID; 474cdf0e10cSrcweir } 475cdf0e10cSrcweir 476cdf0e10cSrcweir return LANGUAGE_DONTKNOW; 477cdf0e10cSrcweir } 478cdf0e10cSrcweir 479cdf0e10cSrcweir class WinGlyphFallbackSubstititution 480cdf0e10cSrcweir : public ImplGlyphFallbackFontSubstitution 481cdf0e10cSrcweir { 482cdf0e10cSrcweir public: 483cdf0e10cSrcweir explicit WinGlyphFallbackSubstititution( HDC ); 484cdf0e10cSrcweir 485cdf0e10cSrcweir bool FindFontSubstitute( ImplFontSelectData&, rtl::OUString& rMissingChars ) const; 486cdf0e10cSrcweir private: 487cdf0e10cSrcweir HDC mhDC; 488cdf0e10cSrcweir bool HasMissingChars( const ImplFontData*, const rtl::OUString& rMissingChars ) const; 489cdf0e10cSrcweir }; 490cdf0e10cSrcweir 491cdf0e10cSrcweir inline WinGlyphFallbackSubstititution::WinGlyphFallbackSubstititution( HDC hDC ) 492cdf0e10cSrcweir : mhDC( hDC ) 493cdf0e10cSrcweir {} 494cdf0e10cSrcweir 495cdf0e10cSrcweir void ImplGetLogFontFromFontSelect( HDC, const ImplFontSelectData*, 496cdf0e10cSrcweir LOGFONTW&, bool /*bTestVerticalAvail*/ ); 497cdf0e10cSrcweir 498cdf0e10cSrcweir // does a font face hold the given missing characters? 499cdf0e10cSrcweir bool WinGlyphFallbackSubstititution::HasMissingChars( const ImplFontData* pFace, const rtl::OUString& rMissingChars ) const 500cdf0e10cSrcweir { 501cdf0e10cSrcweir const ImplWinFontData* pWinFont = static_cast<const ImplWinFontData*>(pFace); 502cdf0e10cSrcweir const ImplFontCharMap* pCharMap = pWinFont->GetImplFontCharMap(); 503cdf0e10cSrcweir if( !pCharMap ) 504cdf0e10cSrcweir { 505cdf0e10cSrcweir // construct a Size structure as the parameter of constructor of class ImplFontSelectData 506cdf0e10cSrcweir const Size aSize( pFace->GetWidth(), pFace->GetHeight() ); 507cdf0e10cSrcweir // create a ImplFontSelectData object for getting s LOGFONT 508cdf0e10cSrcweir const ImplFontSelectData aFSD( *pFace, aSize, (float)aSize.Height(), 0, false ); 509cdf0e10cSrcweir // construct log font 510cdf0e10cSrcweir LOGFONTW aLogFont; 511cdf0e10cSrcweir ImplGetLogFontFromFontSelect( mhDC, &aFSD, aLogFont, true ); 512cdf0e10cSrcweir 513cdf0e10cSrcweir // create HFONT from log font 514cdf0e10cSrcweir HFONT hNewFont = ::CreateFontIndirectW( &aLogFont ); 515cdf0e10cSrcweir // select the new font into device 516cdf0e10cSrcweir HFONT hOldFont = ::SelectFont( mhDC, hNewFont ); 517cdf0e10cSrcweir 518cdf0e10cSrcweir // read CMAP table to update their pCharMap 519cdf0e10cSrcweir pWinFont->UpdateFromHDC( mhDC );; 520cdf0e10cSrcweir 521cdf0e10cSrcweir // cleanup temporary font 522cdf0e10cSrcweir ::SelectFont( mhDC, hOldFont ); 523cdf0e10cSrcweir ::DeleteFont( hNewFont ); 524cdf0e10cSrcweir 525cdf0e10cSrcweir // get the new charmap 526cdf0e10cSrcweir pCharMap = pWinFont->GetImplFontCharMap(); 527cdf0e10cSrcweir } 528cdf0e10cSrcweir 529cdf0e10cSrcweir // avoid fonts with unknown CMAP subtables for glyph fallback 530cdf0e10cSrcweir if( !pCharMap || pCharMap->IsDefaultMap() ) 531cdf0e10cSrcweir return false; 532cdf0e10cSrcweir pCharMap->AddReference(); 533cdf0e10cSrcweir 534cdf0e10cSrcweir int nMatchCount = 0; 535cdf0e10cSrcweir // static const int nMaxMatchCount = 1; // TODO: tolerate more missing characters? 536cdf0e10cSrcweir const sal_Int32 nStrLen = rMissingChars.getLength(); 537cdf0e10cSrcweir for( sal_Int32 nStrIdx = 0; nStrIdx < nStrLen; ++nStrIdx ) 538cdf0e10cSrcweir { 539cdf0e10cSrcweir const sal_UCS4 uChar = rMissingChars.iterateCodePoints( &nStrIdx ); 540cdf0e10cSrcweir nMatchCount += pCharMap->HasChar( uChar ); 541cdf0e10cSrcweir break; // for now 542cdf0e10cSrcweir } 543cdf0e10cSrcweir pCharMap->DeReference(); 544cdf0e10cSrcweir 545cdf0e10cSrcweir const bool bHasMatches = (nMatchCount > 0); 546cdf0e10cSrcweir return bHasMatches; 547cdf0e10cSrcweir } 548cdf0e10cSrcweir 549cdf0e10cSrcweir // find a fallback font for missing characters 550cdf0e10cSrcweir // TODO: should stylistic matches be searched and prefered? 551cdf0e10cSrcweir bool WinGlyphFallbackSubstititution::FindFontSubstitute( ImplFontSelectData& rFontSelData, rtl::OUString& rMissingChars ) const 552cdf0e10cSrcweir { 553cdf0e10cSrcweir // guess a locale matching to the missing chars 554cdf0e10cSrcweir com::sun::star::lang::Locale aLocale; 555cdf0e10cSrcweir 556cdf0e10cSrcweir sal_Int32 nStrIdx = 0; 557cdf0e10cSrcweir const sal_Int32 nStrLen = rMissingChars.getLength(); 558cdf0e10cSrcweir while( nStrIdx < nStrLen ) 559cdf0e10cSrcweir { 560cdf0e10cSrcweir const sal_UCS4 uChar = rMissingChars.iterateCodePoints( &nStrIdx ); 561cdf0e10cSrcweir const LanguageType eLang = MapCharToLanguage( uChar ); 562cdf0e10cSrcweir if( eLang == LANGUAGE_DONTKNOW ) 563cdf0e10cSrcweir continue; 564cdf0e10cSrcweir MsLangId::convertLanguageToLocale( eLang, aLocale ); 565cdf0e10cSrcweir break; 566cdf0e10cSrcweir } 567cdf0e10cSrcweir 568cdf0e10cSrcweir // fall back to default UI locale if the missing characters are inconclusive 569cdf0e10cSrcweir if( nStrIdx >= nStrLen ) 570cdf0e10cSrcweir aLocale = Application::GetSettings().GetUILocale(); 571cdf0e10cSrcweir 572cdf0e10cSrcweir // first level fallback: 573cdf0e10cSrcweir // try use the locale specific default fonts defined in VCL.xcu 574cdf0e10cSrcweir const ImplDevFontList* pDevFontList = ImplGetSVData()->maGDIData.mpScreenFontList; 575cdf0e10cSrcweir /*const*/ ImplDevFontListData* pDevFont = pDevFontList->ImplFindByLocale( aLocale ); 576cdf0e10cSrcweir if( pDevFont ) 577cdf0e10cSrcweir { 578cdf0e10cSrcweir const ImplFontData* pFace = pDevFont->FindBestFontFace( rFontSelData ); 579cdf0e10cSrcweir if( HasMissingChars( pFace, rMissingChars ) ) 580cdf0e10cSrcweir { 581cdf0e10cSrcweir rFontSelData.maSearchName = pDevFont->GetSearchName(); 582cdf0e10cSrcweir return true; 583cdf0e10cSrcweir } 584cdf0e10cSrcweir } 585cdf0e10cSrcweir 586cdf0e10cSrcweir // are the missing characters symbols? 587cdf0e10cSrcweir pDevFont = pDevFontList->ImplFindByAttributes( IMPL_FONT_ATTR_SYMBOL, 588cdf0e10cSrcweir rFontSelData.meWeight, rFontSelData.meWidthType, 589cdf0e10cSrcweir rFontSelData.meFamily, rFontSelData.meItalic, rFontSelData.maSearchName ); 590cdf0e10cSrcweir if( pDevFont ) 591cdf0e10cSrcweir { 592cdf0e10cSrcweir const ImplFontData* pFace = pDevFont->FindBestFontFace( rFontSelData ); 593cdf0e10cSrcweir if( HasMissingChars( pFace, rMissingChars ) ) 594cdf0e10cSrcweir { 595cdf0e10cSrcweir rFontSelData.maSearchName = pDevFont->GetSearchName(); 596cdf0e10cSrcweir return true; 597cdf0e10cSrcweir } 598cdf0e10cSrcweir } 599cdf0e10cSrcweir 600cdf0e10cSrcweir // last level fallback, check each font type face one by one 601cdf0e10cSrcweir const ImplGetDevFontList* pTestFontList = pDevFontList->GetDevFontList(); 602cdf0e10cSrcweir // limit the count of fonts to be checked to prevent hangs 603cdf0e10cSrcweir static const int MAX_GFBFONT_COUNT = 600; 604cdf0e10cSrcweir int nTestFontCount = pTestFontList->Count(); 605cdf0e10cSrcweir if( nTestFontCount > MAX_GFBFONT_COUNT ) 606cdf0e10cSrcweir nTestFontCount = MAX_GFBFONT_COUNT; 607cdf0e10cSrcweir 608cdf0e10cSrcweir for( int i = 0; i < nTestFontCount; ++i ) 609cdf0e10cSrcweir { 610cdf0e10cSrcweir const ImplFontData* pFace = pTestFontList->Get( i ); 611cdf0e10cSrcweir if( !HasMissingChars( pFace, rMissingChars ) ) 612cdf0e10cSrcweir continue; 613cdf0e10cSrcweir rFontSelData.maSearchName = pFace->maName; 614cdf0e10cSrcweir return true; 615cdf0e10cSrcweir } 616cdf0e10cSrcweir 617cdf0e10cSrcweir return false; 618cdf0e10cSrcweir } 619cdf0e10cSrcweir 620cdf0e10cSrcweir // ======================================================================= 621cdf0e10cSrcweir 622cdf0e10cSrcweir struct ImplEnumInfo 623cdf0e10cSrcweir { 624cdf0e10cSrcweir HDC mhDC; 625cdf0e10cSrcweir ImplDevFontList* mpList; 626cdf0e10cSrcweir String* mpName; 627cdf0e10cSrcweir LOGFONTA* mpLogFontA; 628cdf0e10cSrcweir LOGFONTW* mpLogFontW; 629cdf0e10cSrcweir UINT mnPreferedCharSet; 630cdf0e10cSrcweir bool mbCourier; 631cdf0e10cSrcweir bool mbImplSalCourierScalable; 632cdf0e10cSrcweir bool mbImplSalCourierNew; 633cdf0e10cSrcweir bool mbPrinter; 634cdf0e10cSrcweir int mnFontCount; 635cdf0e10cSrcweir }; 636cdf0e10cSrcweir 637cdf0e10cSrcweir // ======================================================================= 638cdf0e10cSrcweir 639cdf0e10cSrcweir static CharSet ImplCharSetToSal( BYTE nCharSet ) 640cdf0e10cSrcweir { 641cdf0e10cSrcweir rtl_TextEncoding eTextEncoding; 642cdf0e10cSrcweir 643cdf0e10cSrcweir if ( nCharSet == OEM_CHARSET ) 644cdf0e10cSrcweir { 645cdf0e10cSrcweir UINT nCP = (sal_uInt16)GetOEMCP(); 646cdf0e10cSrcweir switch ( nCP ) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir // It is unclear why these two (undefined?) code page numbers are 649cdf0e10cSrcweir // handled specially here: 650cdf0e10cSrcweir case 1004: eTextEncoding = RTL_TEXTENCODING_MS_1252; break; 651cdf0e10cSrcweir case 65400: eTextEncoding = RTL_TEXTENCODING_SYMBOL; break; 652cdf0e10cSrcweir default: 653cdf0e10cSrcweir eTextEncoding = rtl_getTextEncodingFromWindowsCodePage(nCP); 654cdf0e10cSrcweir break; 655cdf0e10cSrcweir }; 656cdf0e10cSrcweir } 657cdf0e10cSrcweir else 658cdf0e10cSrcweir { 659cdf0e10cSrcweir if( nCharSet ) 660cdf0e10cSrcweir eTextEncoding = rtl_getTextEncodingFromWindowsCharset( nCharSet ); 661cdf0e10cSrcweir else 662cdf0e10cSrcweir eTextEncoding = RTL_TEXTENCODING_UNICODE; 663cdf0e10cSrcweir } 664cdf0e10cSrcweir 665cdf0e10cSrcweir return eTextEncoding; 666cdf0e10cSrcweir } 667cdf0e10cSrcweir 668cdf0e10cSrcweir // ----------------------------------------------------------------------- 669cdf0e10cSrcweir 670cdf0e10cSrcweir static FontFamily ImplFamilyToSal( BYTE nFamily ) 671cdf0e10cSrcweir { 672cdf0e10cSrcweir switch ( nFamily & 0xF0 ) 673cdf0e10cSrcweir { 674cdf0e10cSrcweir case FF_DECORATIVE: 675cdf0e10cSrcweir return FAMILY_DECORATIVE; 676cdf0e10cSrcweir 677cdf0e10cSrcweir case FF_MODERN: 678cdf0e10cSrcweir return FAMILY_MODERN; 679cdf0e10cSrcweir 680cdf0e10cSrcweir case FF_ROMAN: 681cdf0e10cSrcweir return FAMILY_ROMAN; 682cdf0e10cSrcweir 683cdf0e10cSrcweir case FF_SCRIPT: 684cdf0e10cSrcweir return FAMILY_SCRIPT; 685cdf0e10cSrcweir 686cdf0e10cSrcweir case FF_SWISS: 687cdf0e10cSrcweir return FAMILY_SWISS; 688cdf0e10cSrcweir 689cdf0e10cSrcweir default: 690cdf0e10cSrcweir break; 691cdf0e10cSrcweir } 692cdf0e10cSrcweir 693cdf0e10cSrcweir return FAMILY_DONTKNOW; 694cdf0e10cSrcweir } 695cdf0e10cSrcweir 696cdf0e10cSrcweir // ----------------------------------------------------------------------- 697cdf0e10cSrcweir 698cdf0e10cSrcweir static BYTE ImplFamilyToWin( FontFamily eFamily ) 699cdf0e10cSrcweir { 700cdf0e10cSrcweir switch ( eFamily ) 701cdf0e10cSrcweir { 702cdf0e10cSrcweir case FAMILY_DECORATIVE: 703cdf0e10cSrcweir return FF_DECORATIVE; 704cdf0e10cSrcweir 705cdf0e10cSrcweir case FAMILY_MODERN: 706cdf0e10cSrcweir return FF_MODERN; 707cdf0e10cSrcweir 708cdf0e10cSrcweir case FAMILY_ROMAN: 709cdf0e10cSrcweir return FF_ROMAN; 710cdf0e10cSrcweir 711cdf0e10cSrcweir case FAMILY_SCRIPT: 712cdf0e10cSrcweir return FF_SCRIPT; 713cdf0e10cSrcweir 714cdf0e10cSrcweir case FAMILY_SWISS: 715cdf0e10cSrcweir return FF_SWISS; 716cdf0e10cSrcweir 717cdf0e10cSrcweir case FAMILY_SYSTEM: 718cdf0e10cSrcweir return FF_SWISS; 719cdf0e10cSrcweir 720cdf0e10cSrcweir default: 721cdf0e10cSrcweir break; 722cdf0e10cSrcweir } 723cdf0e10cSrcweir 724cdf0e10cSrcweir return FF_DONTCARE; 725cdf0e10cSrcweir } 726cdf0e10cSrcweir 727cdf0e10cSrcweir // ----------------------------------------------------------------------- 728cdf0e10cSrcweir 729cdf0e10cSrcweir static FontWeight ImplWeightToSal( int nWeight ) 730cdf0e10cSrcweir { 731cdf0e10cSrcweir if ( nWeight <= FW_THIN ) 732cdf0e10cSrcweir return WEIGHT_THIN; 733cdf0e10cSrcweir else if ( nWeight <= FW_ULTRALIGHT ) 734cdf0e10cSrcweir return WEIGHT_ULTRALIGHT; 735cdf0e10cSrcweir else if ( nWeight <= FW_LIGHT ) 736cdf0e10cSrcweir return WEIGHT_LIGHT; 737cdf0e10cSrcweir else if ( nWeight < FW_MEDIUM ) 738cdf0e10cSrcweir return WEIGHT_NORMAL; 739cdf0e10cSrcweir else if ( nWeight == FW_MEDIUM ) 740cdf0e10cSrcweir return WEIGHT_MEDIUM; 741cdf0e10cSrcweir else if ( nWeight <= FW_SEMIBOLD ) 742cdf0e10cSrcweir return WEIGHT_SEMIBOLD; 743cdf0e10cSrcweir else if ( nWeight <= FW_BOLD ) 744cdf0e10cSrcweir return WEIGHT_BOLD; 745cdf0e10cSrcweir else if ( nWeight <= FW_ULTRABOLD ) 746cdf0e10cSrcweir return WEIGHT_ULTRABOLD; 747cdf0e10cSrcweir else 748cdf0e10cSrcweir return WEIGHT_BLACK; 749cdf0e10cSrcweir } 750cdf0e10cSrcweir 751cdf0e10cSrcweir // ----------------------------------------------------------------------- 752cdf0e10cSrcweir 753cdf0e10cSrcweir static int ImplWeightToWin( FontWeight eWeight ) 754cdf0e10cSrcweir { 755cdf0e10cSrcweir switch ( eWeight ) 756cdf0e10cSrcweir { 757cdf0e10cSrcweir case WEIGHT_THIN: 758cdf0e10cSrcweir return FW_THIN; 759cdf0e10cSrcweir 760cdf0e10cSrcweir case WEIGHT_ULTRALIGHT: 761cdf0e10cSrcweir return FW_ULTRALIGHT; 762cdf0e10cSrcweir 763cdf0e10cSrcweir case WEIGHT_LIGHT: 764cdf0e10cSrcweir return FW_LIGHT; 765cdf0e10cSrcweir 766cdf0e10cSrcweir case WEIGHT_SEMILIGHT: 767cdf0e10cSrcweir case WEIGHT_NORMAL: 768cdf0e10cSrcweir return FW_NORMAL; 769cdf0e10cSrcweir 770cdf0e10cSrcweir case WEIGHT_MEDIUM: 771cdf0e10cSrcweir return FW_MEDIUM; 772cdf0e10cSrcweir 773cdf0e10cSrcweir case WEIGHT_SEMIBOLD: 774cdf0e10cSrcweir return FW_SEMIBOLD; 775cdf0e10cSrcweir 776cdf0e10cSrcweir case WEIGHT_BOLD: 777cdf0e10cSrcweir return FW_BOLD; 778cdf0e10cSrcweir 779cdf0e10cSrcweir case WEIGHT_ULTRABOLD: 780cdf0e10cSrcweir return FW_ULTRABOLD; 781cdf0e10cSrcweir 782cdf0e10cSrcweir case WEIGHT_BLACK: 783cdf0e10cSrcweir return FW_BLACK; 784cdf0e10cSrcweir 785cdf0e10cSrcweir default: 786cdf0e10cSrcweir break; 787cdf0e10cSrcweir } 788cdf0e10cSrcweir 789cdf0e10cSrcweir return 0; 790cdf0e10cSrcweir } 791cdf0e10cSrcweir 792cdf0e10cSrcweir // ----------------------------------------------------------------------- 793cdf0e10cSrcweir 794cdf0e10cSrcweir inline FontPitch ImplLogPitchToSal( BYTE nPitch ) 795cdf0e10cSrcweir { 796cdf0e10cSrcweir if ( nPitch & FIXED_PITCH ) 797cdf0e10cSrcweir return PITCH_FIXED; 798cdf0e10cSrcweir else 799cdf0e10cSrcweir return PITCH_VARIABLE; 800cdf0e10cSrcweir } 801cdf0e10cSrcweir 802cdf0e10cSrcweir // ----------------------------------------------------------------------- 803cdf0e10cSrcweir 804cdf0e10cSrcweir inline FontPitch ImplMetricPitchToSal( BYTE nPitch ) 805cdf0e10cSrcweir { 806cdf0e10cSrcweir // Sausaecke bei MS !! siehe NT Hilfe 807cdf0e10cSrcweir if ( !(nPitch & TMPF_FIXED_PITCH) ) 808cdf0e10cSrcweir return PITCH_FIXED; 809cdf0e10cSrcweir else 810cdf0e10cSrcweir return PITCH_VARIABLE; 811cdf0e10cSrcweir } 812cdf0e10cSrcweir 813cdf0e10cSrcweir // ----------------------------------------------------------------------- 814cdf0e10cSrcweir 815cdf0e10cSrcweir inline BYTE ImplPitchToWin( FontPitch ePitch ) 816cdf0e10cSrcweir { 817cdf0e10cSrcweir if ( ePitch == PITCH_FIXED ) 818cdf0e10cSrcweir return FIXED_PITCH; 819cdf0e10cSrcweir else if ( ePitch == PITCH_VARIABLE ) 820cdf0e10cSrcweir return VARIABLE_PITCH; 821cdf0e10cSrcweir else 822cdf0e10cSrcweir return DEFAULT_PITCH; 823cdf0e10cSrcweir } 824cdf0e10cSrcweir 825cdf0e10cSrcweir // ----------------------------------------------------------------------- 826cdf0e10cSrcweir 827cdf0e10cSrcweir static ImplDevFontAttributes WinFont2DevFontAttributes( const ENUMLOGFONTEXA& rEnumFont, 828cdf0e10cSrcweir const NEWTEXTMETRICA& rMetric, DWORD nFontType ) 829cdf0e10cSrcweir { 830cdf0e10cSrcweir ImplDevFontAttributes aDFA; 831cdf0e10cSrcweir 832cdf0e10cSrcweir const LOGFONTA rLogFont = rEnumFont.elfLogFont; 833cdf0e10cSrcweir 834cdf0e10cSrcweir // get font face attributes 835cdf0e10cSrcweir aDFA.meFamily = ImplFamilyToSal( rLogFont.lfPitchAndFamily ); 836cdf0e10cSrcweir aDFA.meWidthType = WIDTH_DONTKNOW; 837cdf0e10cSrcweir aDFA.meWeight = ImplWeightToSal( rLogFont.lfWeight ); 838cdf0e10cSrcweir aDFA.meItalic = (rLogFont.lfItalic) ? ITALIC_NORMAL : ITALIC_NONE; 839cdf0e10cSrcweir aDFA.mePitch = ImplLogPitchToSal( rLogFont.lfPitchAndFamily ); 840cdf0e10cSrcweir aDFA.mbSymbolFlag = (rLogFont.lfCharSet == SYMBOL_CHARSET); 841cdf0e10cSrcweir 842cdf0e10cSrcweir // get the font face name 843cdf0e10cSrcweir aDFA.maName = ImplSalGetUniString( rLogFont.lfFaceName ); 844cdf0e10cSrcweir 845cdf0e10cSrcweir // use the face's style name only if it looks reasonable 846cdf0e10cSrcweir const char* pStyleName = (const char*)rEnumFont.elfStyle; 847cdf0e10cSrcweir const char* pEnd = pStyleName + sizeof( rEnumFont.elfStyle ); 848cdf0e10cSrcweir const char* p = pStyleName; 849cdf0e10cSrcweir for(; *p && (p < pEnd); ++p ) 850cdf0e10cSrcweir if( (0x00 < *p) && (*p < 0x20) ) 851cdf0e10cSrcweir break; 852cdf0e10cSrcweir if( p < pEnd ) 853cdf0e10cSrcweir aDFA.maStyleName = ImplSalGetUniString( pStyleName ); 854cdf0e10cSrcweir 855cdf0e10cSrcweir // get device specific font attributes 856cdf0e10cSrcweir aDFA.mbOrientation = (nFontType & RASTER_FONTTYPE) == 0; 857cdf0e10cSrcweir aDFA.mbDevice = (rMetric.tmPitchAndFamily & TMPF_DEVICE) != 0; 858cdf0e10cSrcweir 859cdf0e10cSrcweir aDFA.mbEmbeddable = false; 860cdf0e10cSrcweir aDFA.mbSubsettable = false; 861cdf0e10cSrcweir if( 0 != (rMetric.ntmFlags & (NTM_TT_OPENTYPE | NTM_PS_OPENTYPE)) 862cdf0e10cSrcweir || 0 != (rMetric.tmPitchAndFamily & TMPF_TRUETYPE)) 863cdf0e10cSrcweir aDFA.mbSubsettable = true; 864cdf0e10cSrcweir else if( 0 != (rMetric.ntmFlags & NTM_TYPE1) ) // TODO: implement subsetting for type1 too 865cdf0e10cSrcweir aDFA.mbEmbeddable = true; 866cdf0e10cSrcweir 867cdf0e10cSrcweir // heuristics for font quality 868cdf0e10cSrcweir // - standard-type1 > opentypeTT > truetype > non-standard-type1 > raster 869cdf0e10cSrcweir // - subsetting > embedding > none 870cdf0e10cSrcweir aDFA.mnQuality = 0; 871cdf0e10cSrcweir if( rMetric.tmPitchAndFamily & TMPF_TRUETYPE ) 872cdf0e10cSrcweir aDFA.mnQuality += 50; 873cdf0e10cSrcweir if( 0 != (rMetric.ntmFlags & (NTM_TT_OPENTYPE | NTM_PS_OPENTYPE)) ) 874cdf0e10cSrcweir aDFA.mnQuality += 10; 875cdf0e10cSrcweir if( aDFA.mbSubsettable ) 876cdf0e10cSrcweir aDFA.mnQuality += 200; 877cdf0e10cSrcweir else if( aDFA.mbEmbeddable ) 878cdf0e10cSrcweir aDFA.mnQuality += 100; 879cdf0e10cSrcweir 880cdf0e10cSrcweir // #i38665# prefer Type1 versions of the standard postscript fonts 881cdf0e10cSrcweir if( aDFA.mbEmbeddable ) 882cdf0e10cSrcweir { 883cdf0e10cSrcweir if( aDFA.maName.EqualsAscii( "AvantGarde" ) 884cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "Bookman" ) 885cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "Courier" ) 886cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "Helvetica" ) 887cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "NewCenturySchlbk" ) 888cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "Palatino" ) 889cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "Symbol" ) 890cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "Times" ) 891cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "ZapfChancery" ) 892cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "ZapfDingbats" ) ) 893cdf0e10cSrcweir aDFA.mnQuality += 500; 894cdf0e10cSrcweir } 895cdf0e10cSrcweir 896cdf0e10cSrcweir // TODO: add alias names 897cdf0e10cSrcweir return aDFA; 898cdf0e10cSrcweir } 899cdf0e10cSrcweir 900cdf0e10cSrcweir // ----------------------------------------------------------------------- 901cdf0e10cSrcweir 902cdf0e10cSrcweir static ImplDevFontAttributes WinFont2DevFontAttributes( const ENUMLOGFONTEXW& rEnumFont, 903cdf0e10cSrcweir const NEWTEXTMETRICW& rMetric, DWORD nFontType ) 904cdf0e10cSrcweir { 905cdf0e10cSrcweir ImplDevFontAttributes aDFA; 906cdf0e10cSrcweir 907cdf0e10cSrcweir const LOGFONTW rLogFont = rEnumFont.elfLogFont; 908cdf0e10cSrcweir 909cdf0e10cSrcweir // get font face attributes 910cdf0e10cSrcweir aDFA.meFamily = ImplFamilyToSal( rLogFont.lfPitchAndFamily ); 911cdf0e10cSrcweir aDFA.meWidthType = WIDTH_DONTKNOW; 912cdf0e10cSrcweir aDFA.meWeight = ImplWeightToSal( rLogFont.lfWeight ); 913cdf0e10cSrcweir aDFA.meItalic = (rLogFont.lfItalic) ? ITALIC_NORMAL : ITALIC_NONE; 914cdf0e10cSrcweir aDFA.mePitch = ImplLogPitchToSal( rLogFont.lfPitchAndFamily ); 915cdf0e10cSrcweir aDFA.mbSymbolFlag = (rLogFont.lfCharSet == SYMBOL_CHARSET); 916cdf0e10cSrcweir 917cdf0e10cSrcweir // get the font face name 918cdf0e10cSrcweir aDFA.maName = reinterpret_cast<const sal_Unicode*>(rLogFont.lfFaceName); 919cdf0e10cSrcweir 920cdf0e10cSrcweir // use the face's style name only if it looks reasonable 921cdf0e10cSrcweir const wchar_t* pStyleName = rEnumFont.elfStyle; 922cdf0e10cSrcweir const wchar_t* pEnd = pStyleName + sizeof(rEnumFont.elfStyle)/sizeof(*rEnumFont.elfStyle); 923cdf0e10cSrcweir const wchar_t* p = pStyleName; 924cdf0e10cSrcweir for(; *p && (p < pEnd); ++p ) 925cdf0e10cSrcweir if( *p < 0x0020 ) 926cdf0e10cSrcweir break; 927cdf0e10cSrcweir if( p < pEnd ) 928cdf0e10cSrcweir aDFA.maStyleName = reinterpret_cast<const sal_Unicode*>(pStyleName); 929cdf0e10cSrcweir 930cdf0e10cSrcweir // get device specific font attributes 931cdf0e10cSrcweir aDFA.mbOrientation = (nFontType & RASTER_FONTTYPE) == 0; 932cdf0e10cSrcweir aDFA.mbDevice = (rMetric.tmPitchAndFamily & TMPF_DEVICE) != 0; 933cdf0e10cSrcweir 934cdf0e10cSrcweir aDFA.mbEmbeddable = false; 935cdf0e10cSrcweir aDFA.mbSubsettable = false; 936cdf0e10cSrcweir if( 0 != (rMetric.ntmFlags & (NTM_TT_OPENTYPE | NTM_PS_OPENTYPE)) 937cdf0e10cSrcweir || 0 != (rMetric.tmPitchAndFamily & TMPF_TRUETYPE)) 938cdf0e10cSrcweir aDFA.mbSubsettable = true; 939cdf0e10cSrcweir else if( 0 != (rMetric.ntmFlags & NTM_TYPE1) ) // TODO: implement subsetting for type1 too 940cdf0e10cSrcweir aDFA.mbEmbeddable = true; 941cdf0e10cSrcweir 942cdf0e10cSrcweir // heuristics for font quality 943cdf0e10cSrcweir // - standard-type1 > opentypeTT > truetype > non-standard-type1 > raster 944cdf0e10cSrcweir // - subsetting > embedding > none 945cdf0e10cSrcweir aDFA.mnQuality = 0; 946cdf0e10cSrcweir if( rMetric.tmPitchAndFamily & TMPF_TRUETYPE ) 947cdf0e10cSrcweir aDFA.mnQuality += 50; 948cdf0e10cSrcweir if( 0 != (rMetric.ntmFlags & (NTM_TT_OPENTYPE | NTM_PS_OPENTYPE)) ) 949cdf0e10cSrcweir aDFA.mnQuality += 10; 950cdf0e10cSrcweir if( aDFA.mbSubsettable ) 951cdf0e10cSrcweir aDFA.mnQuality += 200; 952cdf0e10cSrcweir else if( aDFA.mbEmbeddable ) 953cdf0e10cSrcweir aDFA.mnQuality += 100; 954cdf0e10cSrcweir 955cdf0e10cSrcweir // #i38665# prefer Type1 versions of the standard postscript fonts 956cdf0e10cSrcweir if( aDFA.mbEmbeddable ) 957cdf0e10cSrcweir { 958cdf0e10cSrcweir if( aDFA.maName.EqualsAscii( "AvantGarde" ) 959cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "Bookman" ) 960cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "Courier" ) 961cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "Helvetica" ) 962cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "NewCenturySchlbk" ) 963cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "Palatino" ) 964cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "Symbol" ) 965cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "Times" ) 966cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "ZapfChancery" ) 967cdf0e10cSrcweir || aDFA.maName.EqualsAscii( "ZapfDingbats" ) ) 968cdf0e10cSrcweir aDFA.mnQuality += 500; 969cdf0e10cSrcweir } 970cdf0e10cSrcweir 971cdf0e10cSrcweir // TODO: add alias names 972cdf0e10cSrcweir return aDFA; 973cdf0e10cSrcweir } 974cdf0e10cSrcweir 975cdf0e10cSrcweir // ----------------------------------------------------------------------- 976cdf0e10cSrcweir 977cdf0e10cSrcweir static ImplWinFontData* ImplLogMetricToDevFontDataA( const ENUMLOGFONTEXA* pLogFont, 978cdf0e10cSrcweir const NEWTEXTMETRICA* pMetric, 979cdf0e10cSrcweir DWORD nFontType ) 980cdf0e10cSrcweir { 981cdf0e10cSrcweir int nHeight = 0; 982cdf0e10cSrcweir if ( nFontType & RASTER_FONTTYPE ) 983cdf0e10cSrcweir nHeight = pMetric->tmHeight - pMetric->tmInternalLeading; 984cdf0e10cSrcweir 985cdf0e10cSrcweir ImplWinFontData* pData = new ImplWinFontData( 986cdf0e10cSrcweir WinFont2DevFontAttributes(*pLogFont, *pMetric, nFontType), 987cdf0e10cSrcweir nHeight, 988cdf0e10cSrcweir pLogFont->elfLogFont.lfCharSet, 989cdf0e10cSrcweir pMetric->tmPitchAndFamily ); 990cdf0e10cSrcweir 991cdf0e10cSrcweir return pData; 992cdf0e10cSrcweir } 993cdf0e10cSrcweir 994cdf0e10cSrcweir // ----------------------------------------------------------------------- 995cdf0e10cSrcweir 996cdf0e10cSrcweir static ImplWinFontData* ImplLogMetricToDevFontDataW( const ENUMLOGFONTEXW* pLogFont, 997cdf0e10cSrcweir const NEWTEXTMETRICW* pMetric, 998cdf0e10cSrcweir DWORD nFontType ) 999cdf0e10cSrcweir { 1000cdf0e10cSrcweir int nHeight = 0; 1001cdf0e10cSrcweir if ( nFontType & RASTER_FONTTYPE ) 1002cdf0e10cSrcweir nHeight = pMetric->tmHeight - pMetric->tmInternalLeading; 1003cdf0e10cSrcweir 1004cdf0e10cSrcweir ImplWinFontData* pData = new ImplWinFontData( 1005cdf0e10cSrcweir WinFont2DevFontAttributes(*pLogFont, *pMetric, nFontType), 1006cdf0e10cSrcweir nHeight, 1007cdf0e10cSrcweir pLogFont->elfLogFont.lfCharSet, 1008cdf0e10cSrcweir pMetric->tmPitchAndFamily ); 1009cdf0e10cSrcweir 1010cdf0e10cSrcweir return pData; 1011cdf0e10cSrcweir } 1012cdf0e10cSrcweir 1013cdf0e10cSrcweir // ----------------------------------------------------------------------- 1014cdf0e10cSrcweir 1015cdf0e10cSrcweir void ImplSalLogFontToFontA( HDC hDC, const LOGFONTA& rLogFont, Font& rFont ) 1016cdf0e10cSrcweir { 1017cdf0e10cSrcweir String aFontName( ImplSalGetUniString( rLogFont.lfFaceName ) ); 1018cdf0e10cSrcweir if ( aFontName.Len() ) 1019cdf0e10cSrcweir { 1020cdf0e10cSrcweir rFont.SetName( aFontName ); 1021cdf0e10cSrcweir rFont.SetCharSet( ImplCharSetToSal( rLogFont.lfCharSet ) ); 1022cdf0e10cSrcweir rFont.SetFamily( ImplFamilyToSal( rLogFont.lfPitchAndFamily ) ); 1023cdf0e10cSrcweir rFont.SetPitch( ImplLogPitchToSal( rLogFont.lfPitchAndFamily ) ); 1024cdf0e10cSrcweir rFont.SetWeight( ImplWeightToSal( rLogFont.lfWeight ) ); 1025cdf0e10cSrcweir 1026cdf0e10cSrcweir long nFontHeight = rLogFont.lfHeight; 1027cdf0e10cSrcweir if ( nFontHeight < 0 ) 1028cdf0e10cSrcweir nFontHeight = -nFontHeight; 1029cdf0e10cSrcweir long nDPIY = GetDeviceCaps( hDC, LOGPIXELSY ); 1030cdf0e10cSrcweir if( !nDPIY ) 1031cdf0e10cSrcweir nDPIY = 600; 1032cdf0e10cSrcweir nFontHeight *= 72; 1033cdf0e10cSrcweir nFontHeight += nDPIY/2; 1034cdf0e10cSrcweir nFontHeight /= nDPIY; 1035cdf0e10cSrcweir rFont.SetSize( Size( 0, nFontHeight ) ); 1036cdf0e10cSrcweir rFont.SetOrientation( (short)rLogFont.lfEscapement ); 1037cdf0e10cSrcweir if ( rLogFont.lfItalic ) 1038cdf0e10cSrcweir rFont.SetItalic( ITALIC_NORMAL ); 1039cdf0e10cSrcweir else 1040cdf0e10cSrcweir rFont.SetItalic( ITALIC_NONE ); 1041cdf0e10cSrcweir if ( rLogFont.lfUnderline ) 1042cdf0e10cSrcweir rFont.SetUnderline( UNDERLINE_SINGLE ); 1043cdf0e10cSrcweir else 1044cdf0e10cSrcweir rFont.SetUnderline( UNDERLINE_NONE ); 1045cdf0e10cSrcweir if ( rLogFont.lfStrikeOut ) 1046cdf0e10cSrcweir rFont.SetStrikeout( STRIKEOUT_SINGLE ); 1047cdf0e10cSrcweir else 1048cdf0e10cSrcweir rFont.SetStrikeout( STRIKEOUT_NONE ); 1049cdf0e10cSrcweir } 1050cdf0e10cSrcweir } 1051cdf0e10cSrcweir 1052cdf0e10cSrcweir // ----------------------------------------------------------------------- 1053cdf0e10cSrcweir 1054cdf0e10cSrcweir void ImplSalLogFontToFontW( HDC hDC, const LOGFONTW& rLogFont, Font& rFont ) 1055cdf0e10cSrcweir { 1056cdf0e10cSrcweir XubString aFontName( reinterpret_cast<const xub_Unicode*>(rLogFont.lfFaceName) ); 1057cdf0e10cSrcweir if ( aFontName.Len() ) 1058cdf0e10cSrcweir { 1059cdf0e10cSrcweir rFont.SetName( aFontName ); 1060cdf0e10cSrcweir rFont.SetCharSet( ImplCharSetToSal( rLogFont.lfCharSet ) ); 1061cdf0e10cSrcweir rFont.SetFamily( ImplFamilyToSal( rLogFont.lfPitchAndFamily ) ); 1062cdf0e10cSrcweir rFont.SetPitch( ImplLogPitchToSal( rLogFont.lfPitchAndFamily ) ); 1063cdf0e10cSrcweir rFont.SetWeight( ImplWeightToSal( rLogFont.lfWeight ) ); 1064cdf0e10cSrcweir 1065cdf0e10cSrcweir long nFontHeight = rLogFont.lfHeight; 1066cdf0e10cSrcweir if ( nFontHeight < 0 ) 1067cdf0e10cSrcweir nFontHeight = -nFontHeight; 1068cdf0e10cSrcweir long nDPIY = GetDeviceCaps( hDC, LOGPIXELSY ); 1069cdf0e10cSrcweir if( !nDPIY ) 1070cdf0e10cSrcweir nDPIY = 600; 1071cdf0e10cSrcweir nFontHeight *= 72; 1072cdf0e10cSrcweir nFontHeight += nDPIY/2; 1073cdf0e10cSrcweir nFontHeight /= nDPIY; 1074cdf0e10cSrcweir rFont.SetSize( Size( 0, nFontHeight ) ); 1075cdf0e10cSrcweir rFont.SetOrientation( (short)rLogFont.lfEscapement ); 1076cdf0e10cSrcweir if ( rLogFont.lfItalic ) 1077cdf0e10cSrcweir rFont.SetItalic( ITALIC_NORMAL ); 1078cdf0e10cSrcweir else 1079cdf0e10cSrcweir rFont.SetItalic( ITALIC_NONE ); 1080cdf0e10cSrcweir if ( rLogFont.lfUnderline ) 1081cdf0e10cSrcweir rFont.SetUnderline( UNDERLINE_SINGLE ); 1082cdf0e10cSrcweir else 1083cdf0e10cSrcweir rFont.SetUnderline( UNDERLINE_NONE ); 1084cdf0e10cSrcweir if ( rLogFont.lfStrikeOut ) 1085cdf0e10cSrcweir rFont.SetStrikeout( STRIKEOUT_SINGLE ); 1086cdf0e10cSrcweir else 1087cdf0e10cSrcweir rFont.SetStrikeout( STRIKEOUT_NONE ); 1088cdf0e10cSrcweir } 1089cdf0e10cSrcweir } 1090cdf0e10cSrcweir 1091cdf0e10cSrcweir // ======================================================================= 1092cdf0e10cSrcweir 1093cdf0e10cSrcweir ImplWinFontData::ImplWinFontData( const ImplDevFontAttributes& rDFS, 1094cdf0e10cSrcweir int nHeight, BYTE eWinCharSet, BYTE nPitchAndFamily ) 1095cdf0e10cSrcweir : ImplFontData( rDFS, 0 ), 1096cdf0e10cSrcweir meWinCharSet( eWinCharSet ), 1097cdf0e10cSrcweir mnPitchAndFamily( nPitchAndFamily ), 1098cdf0e10cSrcweir mpFontCharSets( NULL ), 1099cdf0e10cSrcweir mpUnicodeMap( NULL ), 1100cdf0e10cSrcweir mbGsubRead( false ), 1101cdf0e10cSrcweir mbDisableGlyphApi( false ), 1102cdf0e10cSrcweir mbHasKoreanRange( false ), 1103cdf0e10cSrcweir mbHasCJKSupport( false ), 1104cdf0e10cSrcweir #ifdef ENABLE_GRAPHITE 1105cdf0e10cSrcweir mbHasGraphiteSupport( false ), 1106cdf0e10cSrcweir #endif 1107cdf0e10cSrcweir mbHasArabicSupport ( false ), 1108cdf0e10cSrcweir mbAliasSymbolsLow( false ), 1109cdf0e10cSrcweir mbAliasSymbolsHigh( false ), 1110cdf0e10cSrcweir mnId( 0 ), 1111cdf0e10cSrcweir mpEncodingVector( NULL ) 1112cdf0e10cSrcweir { 1113cdf0e10cSrcweir SetBitmapSize( 0, nHeight ); 1114cdf0e10cSrcweir 1115cdf0e10cSrcweir if( eWinCharSet == SYMBOL_CHARSET ) 1116cdf0e10cSrcweir { 1117cdf0e10cSrcweir if( (nPitchAndFamily & TMPF_TRUETYPE) != 0 ) 1118cdf0e10cSrcweir { 1119cdf0e10cSrcweir // truetype fonts need their symbols as U+F0xx 1120cdf0e10cSrcweir mbAliasSymbolsHigh = true; 1121cdf0e10cSrcweir } 1122cdf0e10cSrcweir else if( (nPitchAndFamily & (TMPF_VECTOR|TMPF_DEVICE)) 1123cdf0e10cSrcweir == (TMPF_VECTOR|TMPF_DEVICE) ) 1124cdf0e10cSrcweir { 1125cdf0e10cSrcweir // scalable device fonts (e.g. builtin printer fonts) 1126cdf0e10cSrcweir // need their symbols as U+00xx 1127cdf0e10cSrcweir mbAliasSymbolsLow = true; 1128cdf0e10cSrcweir } 1129cdf0e10cSrcweir else if( (nPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE)) == 0 ) 1130cdf0e10cSrcweir { 1131cdf0e10cSrcweir // bitmap fonts need their symbols as U+F0xx 1132cdf0e10cSrcweir mbAliasSymbolsHigh = true; 1133cdf0e10cSrcweir } 1134cdf0e10cSrcweir } 1135cdf0e10cSrcweir } 1136cdf0e10cSrcweir 1137cdf0e10cSrcweir // ----------------------------------------------------------------------- 1138cdf0e10cSrcweir 1139cdf0e10cSrcweir ImplWinFontData::~ImplWinFontData() 1140cdf0e10cSrcweir { 1141cdf0e10cSrcweir delete[] mpFontCharSets; 1142cdf0e10cSrcweir 1143cdf0e10cSrcweir if( mpUnicodeMap ) 1144cdf0e10cSrcweir mpUnicodeMap->DeReference(); 1145cdf0e10cSrcweir delete mpEncodingVector; 1146cdf0e10cSrcweir } 1147cdf0e10cSrcweir 1148cdf0e10cSrcweir // ----------------------------------------------------------------------- 1149cdf0e10cSrcweir 1150cdf0e10cSrcweir sal_IntPtr ImplWinFontData::GetFontId() const 1151cdf0e10cSrcweir { 1152cdf0e10cSrcweir return mnId; 1153cdf0e10cSrcweir } 1154cdf0e10cSrcweir 1155cdf0e10cSrcweir // ----------------------------------------------------------------------- 1156cdf0e10cSrcweir 1157cdf0e10cSrcweir void ImplWinFontData::UpdateFromHDC( HDC hDC ) const 1158cdf0e10cSrcweir { 1159cdf0e10cSrcweir // short circuit if already initialized 1160cdf0e10cSrcweir if( mpUnicodeMap != NULL ) 1161cdf0e10cSrcweir return; 1162cdf0e10cSrcweir 1163cdf0e10cSrcweir ReadCmapTable( hDC ); 1164cdf0e10cSrcweir ReadOs2Table( hDC ); 1165cdf0e10cSrcweir #ifdef ENABLE_GRAPHITE 1166cdf0e10cSrcweir static const char* pDisableGraphiteText = getenv( "SAL_DISABLE_GRAPHITE" ); 1167cdf0e10cSrcweir if( !pDisableGraphiteText || (pDisableGraphiteText[0] == '0') ) 1168cdf0e10cSrcweir { 1169cdf0e10cSrcweir mbHasGraphiteSupport = gr::WinFont::FontHasGraphiteTables(hDC); 1170cdf0e10cSrcweir } 1171cdf0e10cSrcweir #endif 1172cdf0e10cSrcweir 1173cdf0e10cSrcweir // even if the font works some fonts have problems with the glyph API 1174cdf0e10cSrcweir // => the heuristic below tries to figure out which fonts have the problem 1175cdf0e10cSrcweir TEXTMETRICA aTextMetric; 1176cdf0e10cSrcweir if( ::GetTextMetricsA( hDC, &aTextMetric ) ) 1177cdf0e10cSrcweir if( !(aTextMetric.tmPitchAndFamily & TMPF_TRUETYPE) 1178cdf0e10cSrcweir || (aTextMetric.tmPitchAndFamily & TMPF_DEVICE) ) 1179cdf0e10cSrcweir mbDisableGlyphApi = true; 1180cdf0e10cSrcweir 1181cdf0e10cSrcweir #if 0 1182cdf0e10cSrcweir // #110548# more important than #107885# => TODO: better solution 1183cdf0e10cSrcweir DWORD nFLI = GetFontLanguageInfo( hDC ); 1184cdf0e10cSrcweir if( 0 == (nFLI & GCP_GLYPHSHAPE) ) 1185cdf0e10cSrcweir mbDisableGlyphApi = true; 1186cdf0e10cSrcweir #endif 1187cdf0e10cSrcweir } 1188cdf0e10cSrcweir 1189cdf0e10cSrcweir // ----------------------------------------------------------------------- 1190cdf0e10cSrcweir 1191cdf0e10cSrcweir bool ImplWinFontData::HasGSUBstitutions( HDC hDC ) const 1192cdf0e10cSrcweir { 1193cdf0e10cSrcweir if( !mbGsubRead ) 1194cdf0e10cSrcweir ReadGsubTable( hDC ); 1195cdf0e10cSrcweir return !maGsubTable.empty(); 1196cdf0e10cSrcweir } 1197cdf0e10cSrcweir 1198cdf0e10cSrcweir // ----------------------------------------------------------------------- 1199cdf0e10cSrcweir 1200cdf0e10cSrcweir bool ImplWinFontData::IsGSUBstituted( sal_UCS4 cChar ) const 1201cdf0e10cSrcweir { 1202cdf0e10cSrcweir return( maGsubTable.find( cChar ) != maGsubTable.end() ); 1203cdf0e10cSrcweir } 1204cdf0e10cSrcweir 1205cdf0e10cSrcweir // ----------------------------------------------------------------------- 1206cdf0e10cSrcweir 1207cdf0e10cSrcweir const ImplFontCharMap* ImplWinFontData::GetImplFontCharMap() const 1208cdf0e10cSrcweir { 1209cdf0e10cSrcweir if( !mpUnicodeMap ) 1210cdf0e10cSrcweir return NULL; 1211cdf0e10cSrcweir return mpUnicodeMap; 1212cdf0e10cSrcweir } 1213cdf0e10cSrcweir 1214cdf0e10cSrcweir // ----------------------------------------------------------------------- 1215cdf0e10cSrcweir 1216cdf0e10cSrcweir static unsigned GetUInt( const unsigned char* p ) { return((p[0]<<24)+(p[1]<<16)+(p[2]<<8)+p[3]);} 1217cdf0e10cSrcweir static unsigned GetUShort( const unsigned char* p ){ return((p[0]<<8)+p[1]);} 1218cdf0e10cSrcweir //static signed GetSShort( const unsigned char* p ){ return((short)((p[0]<<8)+p[1]));} 1219cdf0e10cSrcweir static inline DWORD CalcTag( const char p[4]) { return (p[0]+(p[1]<<8)+(p[2]<<16)+(p[3]<<24)); } 1220cdf0e10cSrcweir 1221cdf0e10cSrcweir void ImplWinFontData::ReadOs2Table( HDC hDC ) const 1222cdf0e10cSrcweir { 1223cdf0e10cSrcweir const DWORD Os2Tag = CalcTag( "OS/2" ); 1224cdf0e10cSrcweir DWORD nLength = ::GetFontData( hDC, Os2Tag, 0, NULL, 0 ); 1225cdf0e10cSrcweir if( (nLength == GDI_ERROR) || !nLength ) 1226cdf0e10cSrcweir return; 1227cdf0e10cSrcweir std::vector<unsigned char> aOS2map( nLength ); 1228cdf0e10cSrcweir unsigned char* pOS2map = &aOS2map[0]; 1229cdf0e10cSrcweir ::GetFontData( hDC, Os2Tag, 0, pOS2map, nLength ); 1230cdf0e10cSrcweir sal_uInt32 nVersion = GetUShort( pOS2map ); 1231cdf0e10cSrcweir if ( nVersion >= 0x0001 && nLength >= 58 ) 1232cdf0e10cSrcweir { 1233cdf0e10cSrcweir // We need at least version 0x0001 (TrueType rev 1.66) 1234cdf0e10cSrcweir // to have access to the needed struct members. 1235cdf0e10cSrcweir sal_uInt32 ulUnicodeRange1 = GetUInt( pOS2map + 42 ); 1236cdf0e10cSrcweir sal_uInt32 ulUnicodeRange2 = GetUInt( pOS2map + 46 ); 1237cdf0e10cSrcweir #if 0 1238cdf0e10cSrcweir sal_uInt32 ulUnicodeRange3 = GetUInt( pOS2map + 50 ); 1239cdf0e10cSrcweir sal_uInt32 ulUnicodeRange4 = GetUInt( pOS2map + 54 ); 1240cdf0e10cSrcweir #endif 1241cdf0e10cSrcweir 1242cdf0e10cSrcweir // Check for CJK capabilities of the current font 1243cdf0e10cSrcweir mbHasCJKSupport = (ulUnicodeRange2 & 0x2DF00000); 1244cdf0e10cSrcweir mbHasKoreanRange= (ulUnicodeRange1 & 0x10000000) 1245cdf0e10cSrcweir | (ulUnicodeRange2 & 0x01100000); 1246cdf0e10cSrcweir mbHasArabicSupport = (ulUnicodeRange1 & 0x00002000); 1247cdf0e10cSrcweir } 1248cdf0e10cSrcweir } 1249cdf0e10cSrcweir 1250cdf0e10cSrcweir // ----------------------------------------------------------------------- 1251cdf0e10cSrcweir 1252cdf0e10cSrcweir void ImplWinFontData::ReadGsubTable( HDC hDC ) const 1253cdf0e10cSrcweir { 1254cdf0e10cSrcweir mbGsubRead = true; 1255cdf0e10cSrcweir 1256cdf0e10cSrcweir // check the existence of a GSUB table 1257cdf0e10cSrcweir const DWORD GsubTag = CalcTag( "GSUB" ); 1258cdf0e10cSrcweir DWORD nRC = ::GetFontData( hDC, GsubTag, 0, NULL, 0 ); 1259cdf0e10cSrcweir if( (nRC == GDI_ERROR) || !nRC ) 1260cdf0e10cSrcweir return; 1261cdf0e10cSrcweir 1262cdf0e10cSrcweir // parse the GSUB table through sft 1263cdf0e10cSrcweir // TODO: parse it directly 1264cdf0e10cSrcweir 1265cdf0e10cSrcweir // sft needs the full font file data => get it 1266cdf0e10cSrcweir const RawFontData aRawFontData( hDC ); 1267cdf0e10cSrcweir if( !aRawFontData.get() ) 1268cdf0e10cSrcweir return; 1269cdf0e10cSrcweir 1270cdf0e10cSrcweir // open font file 1271cdf0e10cSrcweir sal_uInt32 nFaceNum = 0; 1272cdf0e10cSrcweir if( !*aRawFontData.get() ) // TTC candidate 1273cdf0e10cSrcweir nFaceNum = ~0U; // indicate "TTC font extracts only" 1274cdf0e10cSrcweir 1275cdf0e10cSrcweir TrueTypeFont* pTTFont = NULL; 1276cdf0e10cSrcweir ::OpenTTFontBuffer( (void*)aRawFontData.get(), aRawFontData.size(), nFaceNum, &pTTFont ); 1277cdf0e10cSrcweir if( !pTTFont ) 1278cdf0e10cSrcweir return; 1279cdf0e10cSrcweir 1280cdf0e10cSrcweir // add vertically substituted characters to list 1281cdf0e10cSrcweir static const sal_Unicode aGSUBCandidates[] = { 1282cdf0e10cSrcweir 0x0020, 0x0080, // ASCII 1283cdf0e10cSrcweir 0x2000, 0x2600, // misc 1284cdf0e10cSrcweir 0x3000, 0x3100, // CJK punctutation 1285cdf0e10cSrcweir 0x3300, 0x3400, // squared words 1286cdf0e10cSrcweir 0xFF00, 0xFFF0, // halfwidth|fullwidth forms 1287cdf0e10cSrcweir 0 }; 1288cdf0e10cSrcweir 1289cdf0e10cSrcweir for( const sal_Unicode* pPair = aGSUBCandidates; *pPair; pPair += 2 ) 1290cdf0e10cSrcweir for( sal_Unicode cChar = pPair[0]; cChar < pPair[1]; ++cChar ) 1291cdf0e10cSrcweir if( ::MapChar( pTTFont, cChar, 0 ) != ::MapChar( pTTFont, cChar, 1 ) ) 1292cdf0e10cSrcweir maGsubTable.insert( cChar ); // insert GSUBbed unicodes 1293cdf0e10cSrcweir 1294cdf0e10cSrcweir CloseTTFont( pTTFont ); 1295cdf0e10cSrcweir } 1296cdf0e10cSrcweir 1297cdf0e10cSrcweir // ----------------------------------------------------------------------- 1298cdf0e10cSrcweir 1299cdf0e10cSrcweir void ImplWinFontData::ReadCmapTable( HDC hDC ) const 1300cdf0e10cSrcweir { 1301cdf0e10cSrcweir if( mpUnicodeMap != NULL ) 1302cdf0e10cSrcweir return; 1303cdf0e10cSrcweir 1304cdf0e10cSrcweir bool bIsSymbolFont = (meWinCharSet == SYMBOL_CHARSET); 1305cdf0e10cSrcweir // get the CMAP table from the font which is selected into the DC 1306cdf0e10cSrcweir const DWORD nCmapTag = CalcTag( "cmap" ); 1307cdf0e10cSrcweir const RawFontData aRawFontData( hDC, nCmapTag ); 1308cdf0e10cSrcweir // parse the CMAP table if available 1309cdf0e10cSrcweir if( aRawFontData.get() ) { 1310cdf0e10cSrcweir CmapResult aResult; 1311cdf0e10cSrcweir ParseCMAP( aRawFontData.get(), aRawFontData.size(), aResult ); 1312cdf0e10cSrcweir mbDisableGlyphApi |= aResult.mbRecoded; 1313cdf0e10cSrcweir aResult.mbSymbolic = bIsSymbolFont; 1314cdf0e10cSrcweir if( aResult.mnRangeCount > 0 ) 1315cdf0e10cSrcweir mpUnicodeMap = new ImplFontCharMap( aResult ); 1316cdf0e10cSrcweir } 1317cdf0e10cSrcweir 1318cdf0e10cSrcweir if( !mpUnicodeMap ) 1319cdf0e10cSrcweir mpUnicodeMap = ImplFontCharMap::GetDefaultMap( bIsSymbolFont ); 1320cdf0e10cSrcweir mpUnicodeMap->AddReference(); 1321cdf0e10cSrcweir } 1322cdf0e10cSrcweir 1323cdf0e10cSrcweir // ======================================================================= 1324cdf0e10cSrcweir 1325cdf0e10cSrcweir void WinSalGraphics::SetTextColor( SalColor nSalColor ) 1326cdf0e10cSrcweir { 1327cdf0e10cSrcweir COLORREF aCol = PALETTERGB( SALCOLOR_RED( nSalColor ), 1328cdf0e10cSrcweir SALCOLOR_GREEN( nSalColor ), 1329cdf0e10cSrcweir SALCOLOR_BLUE( nSalColor ) ); 1330cdf0e10cSrcweir 1331cdf0e10cSrcweir if( !mbPrinter && 1332cdf0e10cSrcweir GetSalData()->mhDitherPal && 1333cdf0e10cSrcweir ImplIsSysColorEntry( nSalColor ) ) 1334cdf0e10cSrcweir { 1335cdf0e10cSrcweir aCol = PALRGB_TO_RGB( aCol ); 1336cdf0e10cSrcweir } 1337cdf0e10cSrcweir 1338cdf0e10cSrcweir ::SetTextColor( mhDC, aCol ); 1339cdf0e10cSrcweir } 1340cdf0e10cSrcweir 1341cdf0e10cSrcweir // ----------------------------------------------------------------------- 1342cdf0e10cSrcweir 1343cdf0e10cSrcweir int CALLBACK SalEnumQueryFontProcExW( const ENUMLOGFONTEXW*, 1344cdf0e10cSrcweir const NEWTEXTMETRICEXW*, 1345cdf0e10cSrcweir DWORD, LPARAM lParam ) 1346cdf0e10cSrcweir { 1347cdf0e10cSrcweir *((bool*)(void*)lParam) = true; 1348cdf0e10cSrcweir return 0; 1349cdf0e10cSrcweir } 1350cdf0e10cSrcweir 1351cdf0e10cSrcweir // ----------------------------------------------------------------------- 1352cdf0e10cSrcweir 1353cdf0e10cSrcweir int CALLBACK SalEnumQueryFontProcExA( const ENUMLOGFONTEXA*, 1354cdf0e10cSrcweir const NEWTEXTMETRICEXA*, 1355cdf0e10cSrcweir DWORD, LPARAM lParam ) 1356cdf0e10cSrcweir { 1357cdf0e10cSrcweir *((bool*)(void*)lParam) = true; 1358cdf0e10cSrcweir return 0; 1359cdf0e10cSrcweir } 1360cdf0e10cSrcweir 1361cdf0e10cSrcweir // ----------------------------------------------------------------------- 1362cdf0e10cSrcweir 1363cdf0e10cSrcweir bool ImplIsFontAvailable( HDC hDC, const UniString& rName ) 1364cdf0e10cSrcweir { 1365cdf0e10cSrcweir // Test, if Font available 1366cdf0e10cSrcweir LOGFONTW aLogFont; 1367cdf0e10cSrcweir memset( &aLogFont, 0, sizeof( aLogFont ) ); 1368cdf0e10cSrcweir aLogFont.lfCharSet = DEFAULT_CHARSET; 1369cdf0e10cSrcweir 1370cdf0e10cSrcweir UINT nNameLen = rName.Len(); 1371cdf0e10cSrcweir if ( nNameLen > (sizeof( aLogFont.lfFaceName )/sizeof( wchar_t ))-1 ) 1372cdf0e10cSrcweir nNameLen = (sizeof( aLogFont.lfFaceName )/sizeof( wchar_t ))-1; 1373cdf0e10cSrcweir memcpy( aLogFont.lfFaceName, rName.GetBuffer(), nNameLen*sizeof( wchar_t ) ); 1374cdf0e10cSrcweir aLogFont.lfFaceName[nNameLen] = 0; 1375cdf0e10cSrcweir 1376cdf0e10cSrcweir bool bAvailable = false; 1377cdf0e10cSrcweir EnumFontFamiliesExW( hDC, &aLogFont, (FONTENUMPROCW)SalEnumQueryFontProcExW, 1378cdf0e10cSrcweir (LPARAM)(void*)&bAvailable, 0 ); 1379cdf0e10cSrcweir 1380cdf0e10cSrcweir return bAvailable; 1381cdf0e10cSrcweir } 1382cdf0e10cSrcweir 1383cdf0e10cSrcweir // ----------------------------------------------------------------------- 1384cdf0e10cSrcweir 1385cdf0e10cSrcweir void ImplGetLogFontFromFontSelect( HDC hDC, 1386cdf0e10cSrcweir const ImplFontSelectData* pFont, 1387cdf0e10cSrcweir LOGFONTW& rLogFont, 1388cdf0e10cSrcweir bool /*bTestVerticalAvail*/ ) 1389cdf0e10cSrcweir { 1390cdf0e10cSrcweir UniString aName; 1391cdf0e10cSrcweir if ( pFont->mpFontData ) 1392cdf0e10cSrcweir aName = pFont->mpFontData->maName; 1393cdf0e10cSrcweir else 1394cdf0e10cSrcweir aName = pFont->maName.GetToken( 0 ); 1395cdf0e10cSrcweir 1396cdf0e10cSrcweir UINT nNameLen = aName.Len(); 1397cdf0e10cSrcweir if ( nNameLen > (sizeof( rLogFont.lfFaceName )/sizeof( wchar_t ))-1 ) 1398cdf0e10cSrcweir nNameLen = (sizeof( rLogFont.lfFaceName )/sizeof( wchar_t ))-1; 1399cdf0e10cSrcweir memcpy( rLogFont.lfFaceName, aName.GetBuffer(), nNameLen*sizeof( wchar_t ) ); 1400cdf0e10cSrcweir rLogFont.lfFaceName[nNameLen] = 0; 1401cdf0e10cSrcweir 1402cdf0e10cSrcweir if( !pFont->mpFontData ) 1403cdf0e10cSrcweir { 1404cdf0e10cSrcweir rLogFont.lfCharSet = pFont->IsSymbolFont() ? SYMBOL_CHARSET : DEFAULT_CHARSET; 1405cdf0e10cSrcweir rLogFont.lfPitchAndFamily = ImplPitchToWin( pFont->mePitch ) 1406cdf0e10cSrcweir | ImplFamilyToWin( pFont->meFamily ); 1407cdf0e10cSrcweir } 1408cdf0e10cSrcweir else 1409cdf0e10cSrcweir { 1410cdf0e10cSrcweir const ImplWinFontData* pWinFontData = static_cast<const ImplWinFontData*>( pFont->mpFontData ); 1411cdf0e10cSrcweir rLogFont.lfCharSet = pWinFontData->GetCharSet(); 1412cdf0e10cSrcweir rLogFont.lfPitchAndFamily = pWinFontData->GetPitchAndFamily(); 1413cdf0e10cSrcweir } 1414cdf0e10cSrcweir 1415cdf0e10cSrcweir rLogFont.lfWeight = ImplWeightToWin( pFont->meWeight ); 1416cdf0e10cSrcweir rLogFont.lfHeight = (LONG)-pFont->mnHeight; 1417cdf0e10cSrcweir rLogFont.lfWidth = (LONG)pFont->mnWidth; 1418cdf0e10cSrcweir rLogFont.lfUnderline = 0; 1419cdf0e10cSrcweir rLogFont.lfStrikeOut = 0; 1420cdf0e10cSrcweir rLogFont.lfItalic = (pFont->meItalic) != ITALIC_NONE; 1421cdf0e10cSrcweir rLogFont.lfEscapement = pFont->mnOrientation; 1422cdf0e10cSrcweir rLogFont.lfOrientation = rLogFont.lfEscapement; 1423cdf0e10cSrcweir rLogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; 1424cdf0e10cSrcweir rLogFont.lfQuality = DEFAULT_QUALITY; 1425cdf0e10cSrcweir rLogFont.lfOutPrecision = OUT_TT_PRECIS; 1426cdf0e10cSrcweir if ( pFont->mnOrientation ) 1427cdf0e10cSrcweir rLogFont.lfClipPrecision |= CLIP_LH_ANGLES; 1428cdf0e10cSrcweir 1429cdf0e10cSrcweir // disable antialiasing if requested 1430cdf0e10cSrcweir if ( pFont->mbNonAntialiased ) 1431cdf0e10cSrcweir rLogFont.lfQuality = NONANTIALIASED_QUALITY; 1432cdf0e10cSrcweir 1433cdf0e10cSrcweir // select vertical mode if requested and available 1434cdf0e10cSrcweir if( pFont->mbVertical && nNameLen ) 1435cdf0e10cSrcweir { 1436cdf0e10cSrcweir // vertical fonts start with an '@' 1437cdf0e10cSrcweir memmove( &rLogFont.lfFaceName[1], &rLogFont.lfFaceName[0], 1438cdf0e10cSrcweir sizeof(rLogFont.lfFaceName)-sizeof(rLogFont.lfFaceName[0]) ); 1439cdf0e10cSrcweir rLogFont.lfFaceName[0] = '@'; 1440cdf0e10cSrcweir 1441cdf0e10cSrcweir // check availability of vertical mode for this font 1442cdf0e10cSrcweir bool bAvailable = false; 1443cdf0e10cSrcweir EnumFontFamiliesExW( hDC, &rLogFont, (FONTENUMPROCW)SalEnumQueryFontProcExW, 1444cdf0e10cSrcweir (LPARAM)&bAvailable, 0 ); 1445cdf0e10cSrcweir 1446cdf0e10cSrcweir if( !bAvailable ) 1447cdf0e10cSrcweir { 1448cdf0e10cSrcweir // restore non-vertical name if not vertical mode isn't available 1449cdf0e10cSrcweir memcpy( &rLogFont.lfFaceName[0], aName.GetBuffer(), nNameLen*sizeof(wchar_t) ); 1450cdf0e10cSrcweir if( nNameLen < LF_FACESIZE ) 1451cdf0e10cSrcweir rLogFont.lfFaceName[nNameLen] = '\0'; 1452cdf0e10cSrcweir } 1453cdf0e10cSrcweir } 1454cdf0e10cSrcweir } 1455cdf0e10cSrcweir 1456cdf0e10cSrcweir // ----------------------------------------------------------------------- 1457cdf0e10cSrcweir 1458cdf0e10cSrcweir static void ImplGetLogFontFromFontSelect( HDC hDC, 1459cdf0e10cSrcweir const ImplFontSelectData* pFont, 1460cdf0e10cSrcweir LOGFONTA& rLogFont, 1461cdf0e10cSrcweir bool /*bTestVerticalAvail*/ ) 1462cdf0e10cSrcweir { 1463cdf0e10cSrcweir ByteString aName; 1464cdf0e10cSrcweir if( pFont->mpFontData ) 1465cdf0e10cSrcweir aName = ImplSalGetWinAnsiString( pFont->mpFontData->maName ); 1466cdf0e10cSrcweir else 1467cdf0e10cSrcweir aName = ImplSalGetWinAnsiString( pFont->maName.GetToken( 0 ) ); 1468cdf0e10cSrcweir 1469cdf0e10cSrcweir int nNameLen = aName.Len(); 1470cdf0e10cSrcweir if( nNameLen > LF_FACESIZE ) 1471cdf0e10cSrcweir nNameLen = LF_FACESIZE; 1472cdf0e10cSrcweir memcpy( rLogFont.lfFaceName, aName.GetBuffer(), nNameLen ); 1473cdf0e10cSrcweir if( nNameLen < LF_FACESIZE ) 1474cdf0e10cSrcweir rLogFont.lfFaceName[nNameLen] = '\0'; 1475cdf0e10cSrcweir 1476cdf0e10cSrcweir if( !pFont->mpFontData ) 1477cdf0e10cSrcweir { 1478cdf0e10cSrcweir rLogFont.lfCharSet = pFont->IsSymbolFont() ? SYMBOL_CHARSET : DEFAULT_CHARSET; 1479cdf0e10cSrcweir rLogFont.lfPitchAndFamily = ImplPitchToWin( pFont->mePitch ) 1480cdf0e10cSrcweir | ImplFamilyToWin( pFont->meFamily ); 1481cdf0e10cSrcweir } 1482cdf0e10cSrcweir else 1483cdf0e10cSrcweir { 1484cdf0e10cSrcweir const ImplWinFontData* pWinFontData = static_cast<const ImplWinFontData*>( pFont->mpFontData ); 1485cdf0e10cSrcweir rLogFont.lfCharSet = pWinFontData->GetCharSet(); 1486cdf0e10cSrcweir rLogFont.lfPitchAndFamily = pWinFontData->GetPitchAndFamily(); 1487cdf0e10cSrcweir } 1488cdf0e10cSrcweir 1489cdf0e10cSrcweir rLogFont.lfWeight = ImplWeightToWin( pFont->meWeight ); 1490cdf0e10cSrcweir rLogFont.lfHeight = (LONG)-pFont->mnHeight; 1491cdf0e10cSrcweir rLogFont.lfWidth = (LONG)pFont->mnWidth; 1492cdf0e10cSrcweir rLogFont.lfUnderline = 0; 1493cdf0e10cSrcweir rLogFont.lfStrikeOut = 0; 1494cdf0e10cSrcweir rLogFont.lfItalic = (pFont->meItalic) != ITALIC_NONE; 1495cdf0e10cSrcweir rLogFont.lfEscapement = pFont->mnOrientation; 1496cdf0e10cSrcweir rLogFont.lfOrientation = rLogFont.lfEscapement; // ignored by W98 1497cdf0e10cSrcweir rLogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; 1498cdf0e10cSrcweir rLogFont.lfQuality = DEFAULT_QUALITY; 1499cdf0e10cSrcweir rLogFont.lfOutPrecision = OUT_TT_PRECIS; 1500cdf0e10cSrcweir if( pFont->mnOrientation ) 1501cdf0e10cSrcweir rLogFont.lfClipPrecision |= CLIP_LH_ANGLES; 1502cdf0e10cSrcweir 1503cdf0e10cSrcweir // disable antialiasing if requested 1504cdf0e10cSrcweir if( pFont->mbNonAntialiased ) 1505cdf0e10cSrcweir rLogFont.lfQuality = NONANTIALIASED_QUALITY; 1506cdf0e10cSrcweir 1507cdf0e10cSrcweir // select vertical mode if requested and available 1508cdf0e10cSrcweir if( pFont->mbVertical && nNameLen ) 1509cdf0e10cSrcweir { 1510cdf0e10cSrcweir // vertical fonts start with an '@' 1511cdf0e10cSrcweir memmove( &rLogFont.lfFaceName[1], &rLogFont.lfFaceName[0], 1512cdf0e10cSrcweir sizeof(rLogFont.lfFaceName)-sizeof(rLogFont.lfFaceName[0]) ); 1513cdf0e10cSrcweir rLogFont.lfFaceName[0] = '@'; 1514cdf0e10cSrcweir 1515cdf0e10cSrcweir // check availability of vertical mode for this font 1516cdf0e10cSrcweir bool bAvailable = false; 1517cdf0e10cSrcweir EnumFontFamiliesExA( hDC, &rLogFont, (FONTENUMPROCA)SalEnumQueryFontProcExA, 1518cdf0e10cSrcweir (LPARAM)&bAvailable, 0 ); 1519cdf0e10cSrcweir 1520cdf0e10cSrcweir if( !bAvailable ) 1521cdf0e10cSrcweir { 1522cdf0e10cSrcweir // restore non-vertical name if vertical mode is not supported 1523cdf0e10cSrcweir memcpy( rLogFont.lfFaceName, aName.GetBuffer(), nNameLen ); 1524cdf0e10cSrcweir if( nNameLen < LF_FACESIZE ) 1525cdf0e10cSrcweir rLogFont.lfFaceName[nNameLen] = '\0'; 1526cdf0e10cSrcweir } 1527cdf0e10cSrcweir } 1528cdf0e10cSrcweir } 1529cdf0e10cSrcweir 1530cdf0e10cSrcweir // ----------------------------------------------------------------------- 1531cdf0e10cSrcweir 1532cdf0e10cSrcweir HFONT WinSalGraphics::ImplDoSetFont( ImplFontSelectData* i_pFont, float& o_rFontScale, HFONT& o_rOldFont ) 1533cdf0e10cSrcweir { 1534cdf0e10cSrcweir HFONT hNewFont = 0; 1535cdf0e10cSrcweir 1536cdf0e10cSrcweir HDC hdcScreen = 0; 1537cdf0e10cSrcweir if( mbVirDev ) 1538cdf0e10cSrcweir // only required for virtual devices, see below for details 1539cdf0e10cSrcweir hdcScreen = GetDC(0); 1540cdf0e10cSrcweir 1541cdf0e10cSrcweir if( true/*aSalShlData.mbWNT*/ ) 1542cdf0e10cSrcweir { 1543cdf0e10cSrcweir LOGFONTW aLogFont; 1544cdf0e10cSrcweir ImplGetLogFontFromFontSelect( mhDC, i_pFont, aLogFont, true ); 1545cdf0e10cSrcweir 1546cdf0e10cSrcweir // on the display we prefer Courier New when Courier is a 1547cdf0e10cSrcweir // bitmap only font and we need to stretch or rotate it 1548cdf0e10cSrcweir if( mbScreen 1549cdf0e10cSrcweir && (i_pFont->mnWidth != 0 1550cdf0e10cSrcweir || i_pFont->mnOrientation != 0 1551cdf0e10cSrcweir || i_pFont->mpFontData == NULL 1552cdf0e10cSrcweir || (i_pFont->mpFontData->GetHeight() != i_pFont->mnHeight)) 1553cdf0e10cSrcweir && !bImplSalCourierScalable 1554cdf0e10cSrcweir && bImplSalCourierNew 1555cdf0e10cSrcweir && (ImplSalWICompareAscii( aLogFont.lfFaceName, "Courier" ) == 0) ) 1556cdf0e10cSrcweir lstrcpynW( aLogFont.lfFaceName, L"Courier New", 11 ); 1557cdf0e10cSrcweir 1558cdf0e10cSrcweir // #i47675# limit font requests to MAXFONTHEIGHT 1559cdf0e10cSrcweir // TODO: share MAXFONTHEIGHT font instance 1560cdf0e10cSrcweir if( (-aLogFont.lfHeight <= MAXFONTHEIGHT) 1561cdf0e10cSrcweir && (+aLogFont.lfWidth <= MAXFONTHEIGHT) ) 1562cdf0e10cSrcweir { 1563cdf0e10cSrcweir o_rFontScale = 1.0; 1564cdf0e10cSrcweir } 1565cdf0e10cSrcweir else if( -aLogFont.lfHeight >= +aLogFont.lfWidth ) 1566cdf0e10cSrcweir { 1567cdf0e10cSrcweir o_rFontScale = -aLogFont.lfHeight / (float)MAXFONTHEIGHT; 1568cdf0e10cSrcweir aLogFont.lfHeight = -MAXFONTHEIGHT; 1569cdf0e10cSrcweir aLogFont.lfWidth = FRound( aLogFont.lfWidth / o_rFontScale ); 1570cdf0e10cSrcweir } 1571cdf0e10cSrcweir else // #i95867# also limit font widths 1572cdf0e10cSrcweir { 1573cdf0e10cSrcweir o_rFontScale = +aLogFont.lfWidth / (float)MAXFONTHEIGHT; 1574cdf0e10cSrcweir aLogFont.lfWidth = +MAXFONTHEIGHT; 1575cdf0e10cSrcweir aLogFont.lfHeight = FRound( aLogFont.lfHeight / o_rFontScale ); 1576cdf0e10cSrcweir } 1577cdf0e10cSrcweir 1578cdf0e10cSrcweir hNewFont = ::CreateFontIndirectW( &aLogFont ); 1579cdf0e10cSrcweir if( hdcScreen ) 1580cdf0e10cSrcweir { 1581cdf0e10cSrcweir // select font into screen hdc first to get an antialiased font 1582cdf0e10cSrcweir // see knowledge base article 305290: 1583cdf0e10cSrcweir // "PRB: Fonts Not Drawn Antialiased on Device Context for DirectDraw Surface" 1584cdf0e10cSrcweir SelectFont( hdcScreen, SelectFont( hdcScreen , hNewFont ) ); 1585cdf0e10cSrcweir } 1586cdf0e10cSrcweir o_rOldFont = ::SelectFont( mhDC, hNewFont ); 1587cdf0e10cSrcweir 1588cdf0e10cSrcweir TEXTMETRICW aTextMetricW; 1589cdf0e10cSrcweir if( !::GetTextMetricsW( mhDC, &aTextMetricW ) ) 1590cdf0e10cSrcweir { 1591cdf0e10cSrcweir // the selected font doesn't work => try a replacement 1592cdf0e10cSrcweir // TODO: use its font fallback instead 1593cdf0e10cSrcweir lstrcpynW( aLogFont.lfFaceName, L"Courier New", 11 ); 1594cdf0e10cSrcweir aLogFont.lfPitchAndFamily = FIXED_PITCH; 1595cdf0e10cSrcweir HFONT hNewFont2 = CreateFontIndirectW( &aLogFont ); 1596cdf0e10cSrcweir SelectFont( mhDC, hNewFont2 ); 1597cdf0e10cSrcweir DeleteFont( hNewFont ); 1598cdf0e10cSrcweir hNewFont = hNewFont2; 1599cdf0e10cSrcweir } 1600cdf0e10cSrcweir } 1601cdf0e10cSrcweir 1602cdf0e10cSrcweir if( hdcScreen ) 1603cdf0e10cSrcweir ::ReleaseDC( NULL, hdcScreen ); 1604cdf0e10cSrcweir 1605cdf0e10cSrcweir return hNewFont; 1606cdf0e10cSrcweir } 1607cdf0e10cSrcweir 1608cdf0e10cSrcweir sal_uInt16 WinSalGraphics::SetFont( ImplFontSelectData* pFont, int nFallbackLevel ) 1609cdf0e10cSrcweir { 1610cdf0e10cSrcweir // return early if there is no new font 1611cdf0e10cSrcweir if( !pFont ) 1612cdf0e10cSrcweir { 1613cdf0e10cSrcweir // deselect still active font 1614cdf0e10cSrcweir if( mhDefFont ) 1615cdf0e10cSrcweir ::SelectFont( mhDC, mhDefFont ); 1616cdf0e10cSrcweir // release no longer referenced font handles 1617cdf0e10cSrcweir for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i ) 1618cdf0e10cSrcweir { 1619cdf0e10cSrcweir if( mhFonts[i] ) 1620cdf0e10cSrcweir ::DeleteFont( mhFonts[i] ); 1621cdf0e10cSrcweir mhFonts[ i ] = 0; 1622cdf0e10cSrcweir } 1623cdf0e10cSrcweir mhDefFont = 0; 1624cdf0e10cSrcweir return 0; 1625cdf0e10cSrcweir } 1626cdf0e10cSrcweir 1627cdf0e10cSrcweir DBG_ASSERT( pFont->mpFontData, "WinSalGraphics mpFontData==NULL"); 1628cdf0e10cSrcweir mpWinFontEntry[ nFallbackLevel ] = reinterpret_cast<ImplWinFontEntry*>( pFont->mpFontEntry ); 1629cdf0e10cSrcweir mpWinFontData[ nFallbackLevel ] = static_cast<const ImplWinFontData*>( pFont->mpFontData ); 1630cdf0e10cSrcweir 1631cdf0e10cSrcweir HFONT hOldFont = 0; 1632cdf0e10cSrcweir HFONT hNewFont = ImplDoSetFont( pFont, mfFontScale, hOldFont ); 1633cdf0e10cSrcweir 1634cdf0e10cSrcweir if( !mhDefFont ) 1635cdf0e10cSrcweir { 1636cdf0e10cSrcweir // keep default font 1637cdf0e10cSrcweir mhDefFont = hOldFont; 1638cdf0e10cSrcweir } 1639cdf0e10cSrcweir else 1640cdf0e10cSrcweir { 1641cdf0e10cSrcweir // release no longer referenced font handles 1642cdf0e10cSrcweir for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i ) 1643cdf0e10cSrcweir { 1644cdf0e10cSrcweir if( mhFonts[i] ) 1645cdf0e10cSrcweir { 1646cdf0e10cSrcweir ::DeleteFont( mhFonts[i] ); 1647cdf0e10cSrcweir mhFonts[i] = 0; 1648cdf0e10cSrcweir } 1649cdf0e10cSrcweir } 1650cdf0e10cSrcweir } 1651cdf0e10cSrcweir 1652cdf0e10cSrcweir // store new font in correct layer 1653cdf0e10cSrcweir mhFonts[ nFallbackLevel ] = hNewFont; 1654cdf0e10cSrcweir // now the font is live => update font face 1655cdf0e10cSrcweir if( mpWinFontData[ nFallbackLevel ] ) 1656cdf0e10cSrcweir mpWinFontData[ nFallbackLevel ]->UpdateFromHDC( mhDC ); 1657cdf0e10cSrcweir 1658cdf0e10cSrcweir if( !nFallbackLevel ) 1659cdf0e10cSrcweir { 1660cdf0e10cSrcweir mbFontKernInit = TRUE; 1661cdf0e10cSrcweir if ( mpFontKernPairs ) 1662cdf0e10cSrcweir { 1663cdf0e10cSrcweir delete[] mpFontKernPairs; 1664cdf0e10cSrcweir mpFontKernPairs = NULL; 1665cdf0e10cSrcweir } 1666cdf0e10cSrcweir mnFontKernPairCount = 0; 1667cdf0e10cSrcweir } 1668cdf0e10cSrcweir 1669cdf0e10cSrcweir mnFontCharSetCount = 0; 1670cdf0e10cSrcweir 1671cdf0e10cSrcweir // some printers have higher internal resolution, so their 1672cdf0e10cSrcweir // text output would be different from what we calculated 1673cdf0e10cSrcweir // => suggest DrawTextArray to workaround this problem 1674cdf0e10cSrcweir if ( mbPrinter ) 1675cdf0e10cSrcweir return SAL_SETFONT_USEDRAWTEXTARRAY; 1676cdf0e10cSrcweir else 1677cdf0e10cSrcweir return 0; 1678cdf0e10cSrcweir } 1679cdf0e10cSrcweir 1680cdf0e10cSrcweir // ----------------------------------------------------------------------- 1681cdf0e10cSrcweir 1682cdf0e10cSrcweir void WinSalGraphics::GetFontMetric( ImplFontMetricData* pMetric, int nFallbackLevel ) 1683cdf0e10cSrcweir { 1684cdf0e10cSrcweir // temporarily change the HDC to the font in the fallback level 1685cdf0e10cSrcweir HFONT hOldFont = SelectFont( mhDC, mhFonts[nFallbackLevel] ); 1686cdf0e10cSrcweir 1687cdf0e10cSrcweir wchar_t aFaceName[LF_FACESIZE+60]; 1688cdf0e10cSrcweir if( ::GetTextFaceW( mhDC, sizeof(aFaceName)/sizeof(wchar_t), aFaceName ) ) 1689cdf0e10cSrcweir pMetric->maName = reinterpret_cast<const sal_Unicode*>(aFaceName); 1690cdf0e10cSrcweir 1691cdf0e10cSrcweir // get the font metric 1692cdf0e10cSrcweir TEXTMETRICA aWinMetric; 1693cdf0e10cSrcweir const bool bOK = GetTextMetricsA( mhDC, &aWinMetric ); 1694cdf0e10cSrcweir // restore the HDC to the font in the base level 1695cdf0e10cSrcweir SelectFont( mhDC, hOldFont ); 1696cdf0e10cSrcweir if( !bOK ) 1697cdf0e10cSrcweir return; 1698cdf0e10cSrcweir 1699cdf0e10cSrcweir // device independent font attributes 1700cdf0e10cSrcweir pMetric->meFamily = ImplFamilyToSal( aWinMetric.tmPitchAndFamily );; 1701cdf0e10cSrcweir pMetric->mbSymbolFlag = (aWinMetric.tmCharSet == SYMBOL_CHARSET); 1702cdf0e10cSrcweir pMetric->meWeight = ImplWeightToSal( aWinMetric.tmWeight ); 1703cdf0e10cSrcweir pMetric->mePitch = ImplMetricPitchToSal( aWinMetric.tmPitchAndFamily ); 1704cdf0e10cSrcweir pMetric->meItalic = aWinMetric.tmItalic ? ITALIC_NORMAL : ITALIC_NONE; 1705cdf0e10cSrcweir pMetric->mnSlant = 0; 1706cdf0e10cSrcweir 1707cdf0e10cSrcweir // device dependend font attributes 1708cdf0e10cSrcweir pMetric->mbDevice = (aWinMetric.tmPitchAndFamily & TMPF_DEVICE) != 0; 1709cdf0e10cSrcweir pMetric->mbScalableFont = (aWinMetric.tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE)) != 0; 1710cdf0e10cSrcweir if( pMetric->mbScalableFont ) 1711cdf0e10cSrcweir { 1712cdf0e10cSrcweir // check if there are kern pairs 1713cdf0e10cSrcweir // TODO: does this work with GPOS kerning? 1714cdf0e10cSrcweir DWORD nKernPairs = ::GetKerningPairsA( mhDC, 0, NULL ); 1715cdf0e10cSrcweir pMetric->mbKernableFont = (nKernPairs > 0); 1716cdf0e10cSrcweir } 1717cdf0e10cSrcweir else 1718cdf0e10cSrcweir { 1719cdf0e10cSrcweir // bitmap fonts cannot be rotated directly 1720cdf0e10cSrcweir pMetric->mnOrientation = 0; 1721cdf0e10cSrcweir // bitmap fonts have no kerning 1722cdf0e10cSrcweir pMetric->mbKernableFont = false; 1723cdf0e10cSrcweir } 1724cdf0e10cSrcweir 1725cdf0e10cSrcweir // transformation dependend font metrics 1726cdf0e10cSrcweir pMetric->mnWidth = static_cast<int>( mfFontScale * aWinMetric.tmAveCharWidth ); 1727cdf0e10cSrcweir pMetric->mnIntLeading = static_cast<int>( mfFontScale * aWinMetric.tmInternalLeading ); 1728cdf0e10cSrcweir pMetric->mnExtLeading = static_cast<int>( mfFontScale * aWinMetric.tmExternalLeading ); 1729cdf0e10cSrcweir pMetric->mnAscent = static_cast<int>( mfFontScale * aWinMetric.tmAscent ); 1730cdf0e10cSrcweir pMetric->mnDescent = static_cast<int>( mfFontScale * aWinMetric.tmDescent ); 1731cdf0e10cSrcweir 1732cdf0e10cSrcweir // #107888# improved metric compatibility for Asian fonts... 1733cdf0e10cSrcweir // TODO: assess workaround below for CWS >= extleading 1734cdf0e10cSrcweir // TODO: evaluate use of aWinMetric.sTypo* members for CJK 1735cdf0e10cSrcweir if( mpWinFontData[nFallbackLevel] && mpWinFontData[nFallbackLevel]->SupportsCJK() ) 1736cdf0e10cSrcweir { 1737cdf0e10cSrcweir pMetric->mnIntLeading += pMetric->mnExtLeading; 1738cdf0e10cSrcweir 1739cdf0e10cSrcweir // #109280# The line height for Asian fonts is too small. 1740cdf0e10cSrcweir // Therefore we add half of the external leading to the 1741cdf0e10cSrcweir // ascent, the other half is added to the descent. 1742cdf0e10cSrcweir const long nHalfTmpExtLeading = pMetric->mnExtLeading / 2; 1743cdf0e10cSrcweir const long nOtherHalfTmpExtLeading = pMetric->mnExtLeading - nHalfTmpExtLeading; 1744cdf0e10cSrcweir 1745cdf0e10cSrcweir // #110641# external leading for Asian fonts. 1746cdf0e10cSrcweir // The factor 0.3 has been confirmed with experiments. 1747cdf0e10cSrcweir long nCJKExtLeading = static_cast<long>(0.30 * (pMetric->mnAscent + pMetric->mnDescent)); 1748cdf0e10cSrcweir nCJKExtLeading -= pMetric->mnExtLeading; 1749cdf0e10cSrcweir pMetric->mnExtLeading = (nCJKExtLeading > 0) ? nCJKExtLeading : 0; 1750cdf0e10cSrcweir 1751cdf0e10cSrcweir pMetric->mnAscent += nHalfTmpExtLeading; 1752cdf0e10cSrcweir pMetric->mnDescent += nOtherHalfTmpExtLeading; 1753cdf0e10cSrcweir } 1754cdf0e10cSrcweir 1755cdf0e10cSrcweir pMetric->mnMinKashida = GetMinKashidaWidth(); 1756cdf0e10cSrcweir } 1757cdf0e10cSrcweir 1758cdf0e10cSrcweir // ----------------------------------------------------------------------- 1759cdf0e10cSrcweir 1760cdf0e10cSrcweir int CALLBACK SalEnumCharSetsProcExA( const ENUMLOGFONTEXA* pLogFont, 1761cdf0e10cSrcweir const NEWTEXTMETRICEXA* /*pMetric*/, 1762cdf0e10cSrcweir DWORD /*nFontType*/, LPARAM lParam ) 1763cdf0e10cSrcweir { 1764cdf0e10cSrcweir WinSalGraphics* pData = (WinSalGraphics*)lParam; 1765cdf0e10cSrcweir // Charset already in the list? 1766cdf0e10cSrcweir for ( BYTE i = 0; i < pData->mnFontCharSetCount; i++ ) 1767cdf0e10cSrcweir { 1768cdf0e10cSrcweir if ( pData->mpFontCharSets[i] == pLogFont->elfLogFont.lfCharSet ) 1769cdf0e10cSrcweir return 1; 1770cdf0e10cSrcweir } 1771cdf0e10cSrcweir pData->mpFontCharSets[pData->mnFontCharSetCount] = pLogFont->elfLogFont.lfCharSet; 1772cdf0e10cSrcweir pData->mnFontCharSetCount++; 1773cdf0e10cSrcweir return 1; 1774cdf0e10cSrcweir } 1775cdf0e10cSrcweir 1776cdf0e10cSrcweir // ----------------------------------------------------------------------- 1777cdf0e10cSrcweir 1778cdf0e10cSrcweir static void ImplGetAllFontCharSets( WinSalGraphics* pData ) 1779cdf0e10cSrcweir { 1780cdf0e10cSrcweir if ( !pData->mpFontCharSets ) 1781cdf0e10cSrcweir pData->mpFontCharSets = new BYTE[256]; 1782cdf0e10cSrcweir 1783cdf0e10cSrcweir LOGFONTA aLogFont; 1784cdf0e10cSrcweir memset( &aLogFont, 0, sizeof( aLogFont ) ); 1785cdf0e10cSrcweir aLogFont.lfCharSet = DEFAULT_CHARSET; 1786cdf0e10cSrcweir GetTextFaceA( pData->mhDC, sizeof( aLogFont.lfFaceName ), aLogFont.lfFaceName ); 1787cdf0e10cSrcweir EnumFontFamiliesExA( pData->mhDC, &aLogFont, (FONTENUMPROCA)SalEnumCharSetsProcExA, 1788cdf0e10cSrcweir (LPARAM)(void*)pData, 0 ); 1789cdf0e10cSrcweir } 1790cdf0e10cSrcweir 1791cdf0e10cSrcweir // ----------------------------------------------------------------------- 1792cdf0e10cSrcweir 1793cdf0e10cSrcweir static void ImplAddKerningPairs( WinSalGraphics* pData ) 1794cdf0e10cSrcweir { 1795cdf0e10cSrcweir sal_uLong nPairs = ::GetKerningPairsA( pData->mhDC, 0, NULL ); 1796cdf0e10cSrcweir if ( !nPairs ) 1797cdf0e10cSrcweir return; 1798cdf0e10cSrcweir 1799cdf0e10cSrcweir CHARSETINFO aInfo; 1800cdf0e10cSrcweir if ( !TranslateCharsetInfo( (DWORD*)(sal_uLong)GetTextCharset( pData->mhDC ), &aInfo, TCI_SRCCHARSET ) ) 1801cdf0e10cSrcweir return; 1802cdf0e10cSrcweir 1803cdf0e10cSrcweir if ( !pData->mpFontKernPairs ) 1804cdf0e10cSrcweir pData->mpFontKernPairs = new KERNINGPAIR[nPairs]; 1805cdf0e10cSrcweir else 1806cdf0e10cSrcweir { 1807cdf0e10cSrcweir KERNINGPAIR* pOldPairs = pData->mpFontKernPairs; 1808cdf0e10cSrcweir pData->mpFontKernPairs = new KERNINGPAIR[nPairs+pData->mnFontKernPairCount]; 1809cdf0e10cSrcweir memcpy( pData->mpFontKernPairs, pOldPairs, 1810cdf0e10cSrcweir pData->mnFontKernPairCount*sizeof( KERNINGPAIR ) ); 1811cdf0e10cSrcweir delete[] pOldPairs; 1812cdf0e10cSrcweir } 1813cdf0e10cSrcweir 1814cdf0e10cSrcweir UINT nCP = aInfo.ciACP; 1815cdf0e10cSrcweir sal_uLong nOldPairs = pData->mnFontKernPairCount; 1816cdf0e10cSrcweir KERNINGPAIR* pTempPair = pData->mpFontKernPairs+pData->mnFontKernPairCount; 1817cdf0e10cSrcweir nPairs = ::GetKerningPairsA( pData->mhDC, nPairs, pTempPair ); 1818cdf0e10cSrcweir for ( sal_uLong i = 0; i < nPairs; i++ ) 1819cdf0e10cSrcweir { 1820cdf0e10cSrcweir unsigned char aBuf[2]; 1821cdf0e10cSrcweir wchar_t nChar; 1822cdf0e10cSrcweir int nLen; 1823cdf0e10cSrcweir sal_Bool bAdd = TRUE; 1824cdf0e10cSrcweir 1825cdf0e10cSrcweir // None-ASCII?, then we must convert the char 1826cdf0e10cSrcweir if ( (pTempPair->wFirst > 125) || (pTempPair->wFirst == 92) ) 1827cdf0e10cSrcweir { 1828cdf0e10cSrcweir if ( pTempPair->wFirst < 256 ) 1829cdf0e10cSrcweir { 1830cdf0e10cSrcweir aBuf[0] = (unsigned char)pTempPair->wFirst; 1831cdf0e10cSrcweir nLen = 1; 1832cdf0e10cSrcweir } 1833cdf0e10cSrcweir else 1834cdf0e10cSrcweir { 1835cdf0e10cSrcweir aBuf[0] = (unsigned char)(pTempPair->wFirst >> 8); 1836cdf0e10cSrcweir aBuf[1] = (unsigned char)(pTempPair->wFirst & 0xFF); 1837cdf0e10cSrcweir nLen = 2; 1838cdf0e10cSrcweir } 1839cdf0e10cSrcweir if ( MultiByteToWideChar( nCP, MB_PRECOMPOSED | MB_USEGLYPHCHARS, 1840cdf0e10cSrcweir (const char*)aBuf, nLen, &nChar, 1 ) ) 1841cdf0e10cSrcweir pTempPair->wFirst = nChar; 1842cdf0e10cSrcweir else 1843cdf0e10cSrcweir bAdd = FALSE; 1844cdf0e10cSrcweir } 1845cdf0e10cSrcweir if ( (pTempPair->wSecond > 125) || (pTempPair->wSecond == 92) ) 1846cdf0e10cSrcweir { 1847cdf0e10cSrcweir if ( pTempPair->wSecond < 256 ) 1848cdf0e10cSrcweir { 1849cdf0e10cSrcweir aBuf[0] = (unsigned char)pTempPair->wSecond; 1850cdf0e10cSrcweir nLen = 1; 1851cdf0e10cSrcweir } 1852cdf0e10cSrcweir else 1853cdf0e10cSrcweir { 1854cdf0e10cSrcweir aBuf[0] = (unsigned char)(pTempPair->wSecond >> 8); 1855cdf0e10cSrcweir aBuf[1] = (unsigned char)(pTempPair->wSecond & 0xFF); 1856cdf0e10cSrcweir nLen = 2; 1857cdf0e10cSrcweir } 1858cdf0e10cSrcweir if ( MultiByteToWideChar( nCP, MB_PRECOMPOSED | MB_USEGLYPHCHARS, 1859cdf0e10cSrcweir (const char*)aBuf, nLen, &nChar, 1 ) ) 1860cdf0e10cSrcweir pTempPair->wSecond = nChar; 1861cdf0e10cSrcweir else 1862cdf0e10cSrcweir bAdd = FALSE; 1863cdf0e10cSrcweir } 1864cdf0e10cSrcweir 1865cdf0e10cSrcweir // TODO: get rid of linear search! 1866cdf0e10cSrcweir KERNINGPAIR* pTempPair2 = pData->mpFontKernPairs; 1867cdf0e10cSrcweir for ( sal_uLong j = 0; j < nOldPairs; j++ ) 1868cdf0e10cSrcweir { 1869cdf0e10cSrcweir if ( (pTempPair2->wFirst == pTempPair->wFirst) && 1870cdf0e10cSrcweir (pTempPair2->wSecond == pTempPair->wSecond) ) 1871cdf0e10cSrcweir { 1872cdf0e10cSrcweir bAdd = FALSE; 1873cdf0e10cSrcweir break; 1874cdf0e10cSrcweir } 1875cdf0e10cSrcweir pTempPair2++; 1876cdf0e10cSrcweir } 1877cdf0e10cSrcweir 1878cdf0e10cSrcweir if ( bAdd ) 1879cdf0e10cSrcweir { 1880cdf0e10cSrcweir KERNINGPAIR* pDestPair = pData->mpFontKernPairs+pData->mnFontKernPairCount; 1881cdf0e10cSrcweir if ( pDestPair != pTempPair ) 1882cdf0e10cSrcweir memcpy( pDestPair, pTempPair, sizeof( KERNINGPAIR ) ); 1883cdf0e10cSrcweir pData->mnFontKernPairCount++; 1884cdf0e10cSrcweir } 1885cdf0e10cSrcweir 1886cdf0e10cSrcweir pTempPair++; 1887cdf0e10cSrcweir } 1888cdf0e10cSrcweir } 1889cdf0e10cSrcweir 1890cdf0e10cSrcweir // ----------------------------------------------------------------------- 1891cdf0e10cSrcweir 1892cdf0e10cSrcweir sal_uLong WinSalGraphics::GetKernPairs( sal_uLong nPairs, ImplKernPairData* pKernPairs ) 1893cdf0e10cSrcweir { 1894cdf0e10cSrcweir DBG_ASSERT( sizeof( KERNINGPAIR ) == sizeof( ImplKernPairData ), 1895cdf0e10cSrcweir "WinSalGraphics::GetKernPairs(): KERNINGPAIR != ImplKernPairData" ); 1896cdf0e10cSrcweir 1897cdf0e10cSrcweir if ( mbFontKernInit ) 1898cdf0e10cSrcweir { 1899cdf0e10cSrcweir if( mpFontKernPairs ) 1900cdf0e10cSrcweir { 1901cdf0e10cSrcweir delete[] mpFontKernPairs; 1902cdf0e10cSrcweir mpFontKernPairs = NULL; 1903cdf0e10cSrcweir } 1904cdf0e10cSrcweir mnFontKernPairCount = 0; 1905cdf0e10cSrcweir 1906cdf0e10cSrcweir KERNINGPAIR* pPairs = NULL; 1907cdf0e10cSrcweir int nCount = ::GetKerningPairsW( mhDC, 0, NULL ); 1908cdf0e10cSrcweir if( nCount ) 1909cdf0e10cSrcweir { 1910cdf0e10cSrcweir #ifdef GCP_KERN_HACK 1911cdf0e10cSrcweir pPairs = new KERNINGPAIR[ nCount+1 ]; 1912cdf0e10cSrcweir mpFontKernPairs = pPairs; 1913cdf0e10cSrcweir mnFontKernPairCount = nCount; 1914cdf0e10cSrcweir ::GetKerningPairsW( mhDC, nCount, pPairs ); 1915cdf0e10cSrcweir #else // GCP_KERN_HACK 1916cdf0e10cSrcweir pPairs = pKernPairs; 1917cdf0e10cSrcweir nCount = (nCount < nPairs) : nCount : nPairs; 1918cdf0e10cSrcweir ::GetKerningPairsW( mhDC, nCount, pPairs ); 1919cdf0e10cSrcweir return nCount; 1920cdf0e10cSrcweir #endif // GCP_KERN_HACK 1921cdf0e10cSrcweir } 1922cdf0e10cSrcweir 1923cdf0e10cSrcweir mbFontKernInit = FALSE; 1924cdf0e10cSrcweir 1925cdf0e10cSrcweir std::sort( mpFontKernPairs, mpFontKernPairs + mnFontKernPairCount, ImplCmpKernData ); 1926cdf0e10cSrcweir } 1927cdf0e10cSrcweir 1928cdf0e10cSrcweir if( !pKernPairs ) 1929cdf0e10cSrcweir return mnFontKernPairCount; 1930cdf0e10cSrcweir else if( mpFontKernPairs ) 1931cdf0e10cSrcweir { 1932cdf0e10cSrcweir if ( nPairs < mnFontKernPairCount ) 1933cdf0e10cSrcweir nPairs = mnFontKernPairCount; 1934cdf0e10cSrcweir memcpy( pKernPairs, mpFontKernPairs, 1935cdf0e10cSrcweir nPairs*sizeof( ImplKernPairData ) ); 1936cdf0e10cSrcweir return nPairs; 1937cdf0e10cSrcweir } 1938cdf0e10cSrcweir 1939cdf0e10cSrcweir return 0; 1940cdf0e10cSrcweir } 1941cdf0e10cSrcweir 1942cdf0e10cSrcweir // ----------------------------------------------------------------------- 1943cdf0e10cSrcweir 1944cdf0e10cSrcweir const ImplFontCharMap* WinSalGraphics::GetImplFontCharMap() const 1945cdf0e10cSrcweir { 1946cdf0e10cSrcweir if( !mpWinFontData[0] ) 1947cdf0e10cSrcweir return ImplFontCharMap::GetDefaultMap(); 1948cdf0e10cSrcweir return mpWinFontData[0]->GetImplFontCharMap(); 1949cdf0e10cSrcweir } 1950cdf0e10cSrcweir 1951cdf0e10cSrcweir // ----------------------------------------------------------------------- 1952cdf0e10cSrcweir 1953cdf0e10cSrcweir int CALLBACK SalEnumFontsProcExA( const ENUMLOGFONTEXA* pLogFont, 1954cdf0e10cSrcweir const NEWTEXTMETRICEXA* pMetric, 1955cdf0e10cSrcweir DWORD nFontType, LPARAM lParam ) 1956cdf0e10cSrcweir { 1957cdf0e10cSrcweir ImplEnumInfo* pInfo = (ImplEnumInfo*)(void*)lParam; 1958cdf0e10cSrcweir if ( !pInfo->mpName ) 1959cdf0e10cSrcweir { 1960cdf0e10cSrcweir // Ignore vertical fonts 1961cdf0e10cSrcweir if ( pLogFont->elfLogFont.lfFaceName[0] != '@' ) 1962cdf0e10cSrcweir { 1963cdf0e10cSrcweir if ( !pInfo->mbImplSalCourierNew ) 1964cdf0e10cSrcweir pInfo->mbImplSalCourierNew = stricmp( pLogFont->elfLogFont.lfFaceName, "Courier New" ) == 0; 1965cdf0e10cSrcweir if ( !pInfo->mbImplSalCourierScalable ) 1966cdf0e10cSrcweir pInfo->mbCourier = stricmp( pLogFont->elfLogFont.lfFaceName, "Courier" ) == 0; 1967cdf0e10cSrcweir else 1968cdf0e10cSrcweir pInfo->mbCourier = FALSE; 1969cdf0e10cSrcweir String aName( ImplSalGetUniString( pLogFont->elfLogFont.lfFaceName ) ); 1970cdf0e10cSrcweir pInfo->mpName = &aName; 1971cdf0e10cSrcweir strncpy( pInfo->mpLogFontA->lfFaceName, pLogFont->elfLogFont.lfFaceName, LF_FACESIZE ); 1972cdf0e10cSrcweir pInfo->mpLogFontA->lfCharSet = pLogFont->elfLogFont.lfCharSet; 1973cdf0e10cSrcweir EnumFontFamiliesExA( pInfo->mhDC, pInfo->mpLogFontA, (FONTENUMPROCA)SalEnumFontsProcExA, 1974cdf0e10cSrcweir (LPARAM)(void*)pInfo, 0 ); 1975cdf0e10cSrcweir pInfo->mpLogFontA->lfFaceName[0] = '\0'; 1976cdf0e10cSrcweir pInfo->mpLogFontA->lfCharSet = DEFAULT_CHARSET; 1977cdf0e10cSrcweir pInfo->mpName = NULL; 1978cdf0e10cSrcweir pInfo->mbCourier = FALSE; 1979cdf0e10cSrcweir } 1980cdf0e10cSrcweir } 1981cdf0e10cSrcweir else 1982cdf0e10cSrcweir { 1983cdf0e10cSrcweir // ignore non-scalable non-device font on printer 1984cdf0e10cSrcweir if( pInfo->mbPrinter ) 1985cdf0e10cSrcweir if( (nFontType & RASTER_FONTTYPE) && !(nFontType & DEVICE_FONTTYPE) ) 1986cdf0e10cSrcweir return 1; 1987cdf0e10cSrcweir 1988cdf0e10cSrcweir ImplWinFontData* pData = ImplLogMetricToDevFontDataA( pLogFont, &(pMetric->ntmTm), nFontType ); 1989cdf0e10cSrcweir pData->SetFontId( sal_IntPtr( pInfo->mnFontCount++ ) ); 1990cdf0e10cSrcweir 1991cdf0e10cSrcweir // prefer the system character set, so that we get as much as 1992cdf0e10cSrcweir // possible important characters. In the other case we could only 1993cdf0e10cSrcweir // display a limited set of characters (#87309#) 1994cdf0e10cSrcweir if ( pInfo->mnPreferedCharSet == pLogFont->elfLogFont.lfCharSet ) 1995cdf0e10cSrcweir pData->mnQuality += 100; 1996cdf0e10cSrcweir 1997cdf0e10cSrcweir // knowing Courier to be scalable is nice 1998cdf0e10cSrcweir if( pInfo->mbCourier ) 1999cdf0e10cSrcweir pInfo->mbImplSalCourierScalable |= pData->IsScalable(); 2000cdf0e10cSrcweir 2001cdf0e10cSrcweir pInfo->mpList->Add( pData ); 2002cdf0e10cSrcweir } 2003cdf0e10cSrcweir 2004cdf0e10cSrcweir return 1; 2005cdf0e10cSrcweir } 2006cdf0e10cSrcweir 2007cdf0e10cSrcweir // ----------------------------------------------------------------------- 2008cdf0e10cSrcweir 2009cdf0e10cSrcweir int CALLBACK SalEnumFontsProcExW( const ENUMLOGFONTEXW* pLogFont, 2010cdf0e10cSrcweir const NEWTEXTMETRICEXW* pMetric, 2011cdf0e10cSrcweir DWORD nFontType, LPARAM lParam ) 2012cdf0e10cSrcweir { 2013cdf0e10cSrcweir ImplEnumInfo* pInfo = (ImplEnumInfo*)(void*)lParam; 2014cdf0e10cSrcweir if ( !pInfo->mpName ) 2015cdf0e10cSrcweir { 2016cdf0e10cSrcweir // Ignore vertical fonts 2017cdf0e10cSrcweir if ( pLogFont->elfLogFont.lfFaceName[0] != '@' ) 2018cdf0e10cSrcweir { 2019cdf0e10cSrcweir if ( !pInfo->mbImplSalCourierNew ) 2020cdf0e10cSrcweir pInfo->mbImplSalCourierNew = ImplSalWICompareAscii( pLogFont->elfLogFont.lfFaceName, "Courier New" ) == 0; 2021cdf0e10cSrcweir if ( !pInfo->mbImplSalCourierScalable ) 2022cdf0e10cSrcweir pInfo->mbCourier = ImplSalWICompareAscii( pLogFont->elfLogFont.lfFaceName, "Courier" ) == 0; 2023cdf0e10cSrcweir else 2024cdf0e10cSrcweir pInfo->mbCourier = FALSE; 2025cdf0e10cSrcweir String aName( reinterpret_cast<const sal_Unicode*>(pLogFont->elfLogFont.lfFaceName) ); 2026cdf0e10cSrcweir pInfo->mpName = &aName; 2027cdf0e10cSrcweir memcpy( pInfo->mpLogFontW->lfFaceName, pLogFont->elfLogFont.lfFaceName, (aName.Len()+1)*sizeof( wchar_t ) ); 2028cdf0e10cSrcweir pInfo->mpLogFontW->lfCharSet = pLogFont->elfLogFont.lfCharSet; 2029cdf0e10cSrcweir EnumFontFamiliesExW( pInfo->mhDC, pInfo->mpLogFontW, (FONTENUMPROCW)SalEnumFontsProcExW, 2030cdf0e10cSrcweir (LPARAM)(void*)pInfo, 0 ); 2031cdf0e10cSrcweir pInfo->mpLogFontW->lfFaceName[0] = '\0'; 2032cdf0e10cSrcweir pInfo->mpLogFontW->lfCharSet = DEFAULT_CHARSET; 2033cdf0e10cSrcweir pInfo->mpName = NULL; 2034cdf0e10cSrcweir pInfo->mbCourier = FALSE; 2035cdf0e10cSrcweir } 2036cdf0e10cSrcweir } 2037cdf0e10cSrcweir else 2038cdf0e10cSrcweir { 2039cdf0e10cSrcweir // ignore non-scalable non-device font on printer 2040cdf0e10cSrcweir if( pInfo->mbPrinter ) 2041cdf0e10cSrcweir if( (nFontType & RASTER_FONTTYPE) && !(nFontType & DEVICE_FONTTYPE) ) 2042cdf0e10cSrcweir return 1; 2043cdf0e10cSrcweir 2044cdf0e10cSrcweir ImplWinFontData* pData = ImplLogMetricToDevFontDataW( pLogFont, &(pMetric->ntmTm), nFontType ); 2045cdf0e10cSrcweir pData->SetFontId( sal_IntPtr( pInfo->mnFontCount++ ) ); 2046cdf0e10cSrcweir 2047cdf0e10cSrcweir // knowing Courier to be scalable is nice 2048cdf0e10cSrcweir if( pInfo->mbCourier ) 2049cdf0e10cSrcweir pInfo->mbImplSalCourierScalable |= pData->IsScalable(); 2050cdf0e10cSrcweir 2051cdf0e10cSrcweir pInfo->mpList->Add( pData ); 2052cdf0e10cSrcweir } 2053cdf0e10cSrcweir 2054cdf0e10cSrcweir return 1; 2055cdf0e10cSrcweir } 2056cdf0e10cSrcweir 2057cdf0e10cSrcweir // ----------------------------------------------------------------------- 2058cdf0e10cSrcweir 2059cdf0e10cSrcweir struct TempFontItem 2060cdf0e10cSrcweir { 2061cdf0e10cSrcweir ::rtl::OUString maFontFilePath; 2062cdf0e10cSrcweir ::rtl::OString maResourcePath; 2063cdf0e10cSrcweir TempFontItem* mpNextItem; 2064cdf0e10cSrcweir }; 2065cdf0e10cSrcweir 2066cdf0e10cSrcweir #ifdef FR_PRIVATE 2067cdf0e10cSrcweir static int WINAPI __AddFontResourceExW( LPCWSTR lpszfileName, DWORD fl, PVOID pdv ) 2068cdf0e10cSrcweir { 2069cdf0e10cSrcweir typedef int (WINAPI *AddFontResourceExW_FUNC)(LPCWSTR, DWORD, PVOID ); 2070cdf0e10cSrcweir 2071cdf0e10cSrcweir static AddFontResourceExW_FUNC pFunc = NULL; 2072cdf0e10cSrcweir static HMODULE hmGDI = NULL; 2073cdf0e10cSrcweir 2074cdf0e10cSrcweir if ( !pFunc && !hmGDI ) 2075cdf0e10cSrcweir { 2076cdf0e10cSrcweir hmGDI = GetModuleHandleA( "GDI32" ); 2077cdf0e10cSrcweir if ( hmGDI ) 2078cdf0e10cSrcweir pFunc = reinterpret_cast<AddFontResourceExW_FUNC>( GetProcAddress( hmGDI, "AddFontResourceExW" ) ); 2079cdf0e10cSrcweir } 2080cdf0e10cSrcweir 2081cdf0e10cSrcweir if ( pFunc ) 2082cdf0e10cSrcweir return pFunc( lpszfileName, fl, pdv ); 2083cdf0e10cSrcweir else 2084cdf0e10cSrcweir { 2085cdf0e10cSrcweir SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); 2086cdf0e10cSrcweir return 0; 2087cdf0e10cSrcweir } 2088cdf0e10cSrcweir } 2089cdf0e10cSrcweir #endif 2090cdf0e10cSrcweir 2091cdf0e10cSrcweir bool ImplAddTempFont( SalData& rSalData, const String& rFontFileURL ) 2092cdf0e10cSrcweir { 2093cdf0e10cSrcweir int nRet = 0; 2094cdf0e10cSrcweir ::rtl::OUString aUSytemPath; 2095cdf0e10cSrcweir OSL_VERIFY( !osl::FileBase::getSystemPathFromFileURL( rFontFileURL, aUSytemPath ) ); 2096cdf0e10cSrcweir 2097cdf0e10cSrcweir #ifdef FR_PRIVATE 2098cdf0e10cSrcweir nRet = __AddFontResourceExW( reinterpret_cast<LPCWSTR>(aUSytemPath.getStr()), FR_PRIVATE, NULL ); 2099cdf0e10cSrcweir #endif 2100cdf0e10cSrcweir 2101cdf0e10cSrcweir if ( !nRet ) 2102cdf0e10cSrcweir { 2103cdf0e10cSrcweir static int nCounter = 0; 2104cdf0e10cSrcweir char aFileName[] = "soAA.fot"; 2105cdf0e10cSrcweir aFileName[2] = sal::static_int_cast<char>('A' + (15 & (nCounter>>4))); 2106cdf0e10cSrcweir aFileName[3] = sal::static_int_cast<char>('A' + (15 & nCounter)); 2107cdf0e10cSrcweir char aResourceName[512]; 2108cdf0e10cSrcweir int nMaxLen = sizeof(aResourceName)/sizeof(*aResourceName) - 16; 2109cdf0e10cSrcweir int nLen = ::GetTempPathA( nMaxLen, aResourceName ); 2110cdf0e10cSrcweir ::strncpy( aResourceName + nLen, aFileName, sizeof( aResourceName )- nLen ); 2111cdf0e10cSrcweir // security: end buffer in any case 2112cdf0e10cSrcweir aResourceName[ (sizeof(aResourceName)/sizeof(*aResourceName))-1 ] = 0; 2113cdf0e10cSrcweir ::DeleteFileA( aResourceName ); 2114cdf0e10cSrcweir 2115cdf0e10cSrcweir rtl_TextEncoding theEncoding = osl_getThreadTextEncoding(); 2116cdf0e10cSrcweir ::rtl::OString aCFileName = rtl::OUStringToOString( aUSytemPath, theEncoding ); 2117cdf0e10cSrcweir // TODO: font should be private => need to investigate why it doesn't work then 2118cdf0e10cSrcweir if( !::CreateScalableFontResourceA( 0, aResourceName, aCFileName.getStr(), NULL ) ) 2119cdf0e10cSrcweir return false; 2120cdf0e10cSrcweir ++nCounter; 2121cdf0e10cSrcweir 2122cdf0e10cSrcweir nRet = ::AddFontResourceA( aResourceName ); 2123cdf0e10cSrcweir if( nRet > 0 ) 2124cdf0e10cSrcweir { 2125cdf0e10cSrcweir TempFontItem* pNewItem = new TempFontItem; 2126cdf0e10cSrcweir pNewItem->maResourcePath = rtl::OString( aResourceName ); 2127cdf0e10cSrcweir pNewItem->maFontFilePath = aUSytemPath.getStr(); 2128cdf0e10cSrcweir pNewItem->mpNextItem = rSalData.mpTempFontItem; 2129cdf0e10cSrcweir rSalData.mpTempFontItem = pNewItem; 2130cdf0e10cSrcweir } 2131cdf0e10cSrcweir } 2132cdf0e10cSrcweir 2133cdf0e10cSrcweir return (nRet > 0); 2134cdf0e10cSrcweir } 2135cdf0e10cSrcweir 2136cdf0e10cSrcweir // ----------------------------------------------------------------------- 2137cdf0e10cSrcweir 2138cdf0e10cSrcweir void ImplReleaseTempFonts( SalData& rSalData ) 2139cdf0e10cSrcweir { 2140cdf0e10cSrcweir int nCount = 0; 2141cdf0e10cSrcweir while( TempFontItem* p = rSalData.mpTempFontItem ) 2142cdf0e10cSrcweir { 2143cdf0e10cSrcweir ++nCount; 2144cdf0e10cSrcweir if( p->maResourcePath.getLength() ) 2145cdf0e10cSrcweir { 2146cdf0e10cSrcweir const char* pResourcePath = p->maResourcePath.getStr(); 2147cdf0e10cSrcweir ::RemoveFontResourceA( pResourcePath ); 2148cdf0e10cSrcweir ::DeleteFileA( pResourcePath ); 2149cdf0e10cSrcweir } 2150cdf0e10cSrcweir else 2151cdf0e10cSrcweir { 2152cdf0e10cSrcweir ::RemoveFontResourceW( reinterpret_cast<LPCWSTR>(p->maFontFilePath.getStr()) ); 2153cdf0e10cSrcweir } 2154cdf0e10cSrcweir 2155cdf0e10cSrcweir rSalData.mpTempFontItem = p->mpNextItem; 2156cdf0e10cSrcweir delete p; 2157cdf0e10cSrcweir } 2158cdf0e10cSrcweir 2159cdf0e10cSrcweir #ifndef FR_PRIVATE 2160cdf0e10cSrcweir // notify every other application 2161cdf0e10cSrcweir // unless the temp fonts were installed as private fonts 2162cdf0e10cSrcweir if( nCount > 0 ) 2163cdf0e10cSrcweir ::PostMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, NULL ); 2164cdf0e10cSrcweir #endif // FR_PRIVATE 2165cdf0e10cSrcweir } 2166cdf0e10cSrcweir 2167cdf0e10cSrcweir // ----------------------------------------------------------------------- 2168cdf0e10cSrcweir 2169cdf0e10cSrcweir static bool ImplGetFontAttrFromFile( const String& rFontFileURL, 2170cdf0e10cSrcweir ImplDevFontAttributes& rDFA ) 2171cdf0e10cSrcweir { 2172cdf0e10cSrcweir ::rtl::OUString aUSytemPath; 2173cdf0e10cSrcweir OSL_VERIFY( !osl::FileBase::getSystemPathFromFileURL( rFontFileURL, aUSytemPath ) ); 2174cdf0e10cSrcweir 2175cdf0e10cSrcweir // get FontAttributes from a *fot file 2176cdf0e10cSrcweir // TODO: use GetTTGlobalFontInfo() to access the font directly 2177cdf0e10cSrcweir rDFA.mnQuality = 1000; 2178cdf0e10cSrcweir rDFA.mbDevice = true; 2179cdf0e10cSrcweir rDFA.meFamily = FAMILY_DONTKNOW; 2180cdf0e10cSrcweir rDFA.meWidthType = WIDTH_DONTKNOW; 2181cdf0e10cSrcweir rDFA.meWeight = WEIGHT_DONTKNOW; 2182cdf0e10cSrcweir rDFA.meItalic = ITALIC_DONTKNOW; 2183cdf0e10cSrcweir rDFA.mePitch = PITCH_DONTKNOW;; 2184cdf0e10cSrcweir rDFA.mbSubsettable= true; 2185cdf0e10cSrcweir rDFA.mbEmbeddable = false; 2186cdf0e10cSrcweir 2187cdf0e10cSrcweir // Create temporary file name 2188cdf0e10cSrcweir char aFileName[] = "soAAT.fot"; 2189cdf0e10cSrcweir char aResourceName[512]; 2190cdf0e10cSrcweir int nMaxLen = sizeof(aResourceName)/sizeof(*aResourceName) - 16; 2191cdf0e10cSrcweir int nLen = ::GetTempPathA( nMaxLen, aResourceName ); 2192cdf0e10cSrcweir ::strncpy( aResourceName + nLen, aFileName, Max( 0, nMaxLen - nLen )); 2193cdf0e10cSrcweir ::DeleteFileA( aResourceName ); 2194cdf0e10cSrcweir 2195cdf0e10cSrcweir // Create font resource file (typically with a .fot file name extension). 2196cdf0e10cSrcweir rtl_TextEncoding theEncoding = osl_getThreadTextEncoding(); 2197cdf0e10cSrcweir ::rtl::OString aCFileName = rtl::OUStringToOString( aUSytemPath, theEncoding ); 2198cdf0e10cSrcweir ::CreateScalableFontResourceA( 0, aResourceName, aCFileName.getStr(), NULL ); 2199cdf0e10cSrcweir 2200cdf0e10cSrcweir // Open and read the font resource file 2201cdf0e10cSrcweir rtl::OUString aFotFileName = rtl::OStringToOUString( aResourceName, osl_getThreadTextEncoding() ); 2202cdf0e10cSrcweir osl::FileBase::getFileURLFromSystemPath( aFotFileName, aFotFileName ); 2203cdf0e10cSrcweir osl::File aFotFile( aFotFileName ); 2204cdf0e10cSrcweir osl::FileBase::RC aError = aFotFile.open( osl_File_OpenFlag_Read ); 2205cdf0e10cSrcweir if( aError != osl::FileBase::E_None ) 2206cdf0e10cSrcweir return false; 2207cdf0e10cSrcweir 2208cdf0e10cSrcweir sal_uInt64 nBytesRead = 0; 2209cdf0e10cSrcweir char aBuffer[4096]; 2210cdf0e10cSrcweir aFotFile.read( aBuffer, sizeof( aBuffer ), nBytesRead ); 2211cdf0e10cSrcweir // clean up temporary resource file 2212cdf0e10cSrcweir aFotFile.close(); 2213cdf0e10cSrcweir ::DeleteFileA( aResourceName ); 2214cdf0e10cSrcweir 2215cdf0e10cSrcweir // retrieve font family name from byte offset 0x4F6 2216cdf0e10cSrcweir int i = 0x4F6; 2217cdf0e10cSrcweir int nNameOfs = i; 2218cdf0e10cSrcweir while( (i < nBytesRead) && (aBuffer[i++] != 0) ); 2219cdf0e10cSrcweir // skip full name 2220cdf0e10cSrcweir while( (i < nBytesRead) && (aBuffer[i++] != 0) ); 2221cdf0e10cSrcweir // retrieve font style name 2222cdf0e10cSrcweir int nStyleOfs = i; 2223cdf0e10cSrcweir while( (i < nBytesRead) && (aBuffer[i++] != 0) ); 2224cdf0e10cSrcweir if( i >= nBytesRead ) 2225cdf0e10cSrcweir return false; 2226cdf0e10cSrcweir 2227cdf0e10cSrcweir // convert byte strings to unicode 2228cdf0e10cSrcweir rDFA.maName = String( aBuffer + nNameOfs, osl_getThreadTextEncoding() ); 2229cdf0e10cSrcweir rDFA.maStyleName = String( aBuffer + nStyleOfs, osl_getThreadTextEncoding() ); 2230cdf0e10cSrcweir 2231cdf0e10cSrcweir // byte offset 0x4C7: OS2_fsSelection 2232cdf0e10cSrcweir const char nFSS = aBuffer[ 0x4C7 ]; 2233cdf0e10cSrcweir if( nFSS & 0x01 ) // italic 2234cdf0e10cSrcweir rDFA.meItalic = ITALIC_NORMAL; 2235cdf0e10cSrcweir //if( nFSS & 0x20 ) // bold 2236cdf0e10cSrcweir // rDFA.meWeight = WEIGHT_BOLD; 2237cdf0e10cSrcweir if( nFSS & 0x40 ) // regular 2238cdf0e10cSrcweir { 2239cdf0e10cSrcweir rDFA.meWeight = WEIGHT_NORMAL; 2240cdf0e10cSrcweir rDFA.meItalic = ITALIC_NONE; 2241cdf0e10cSrcweir } 2242cdf0e10cSrcweir 2243cdf0e10cSrcweir // byte offsets 0x4D7/0x4D8: wingdi's FW_WEIGHT 2244cdf0e10cSrcweir int nWinWeight = (aBuffer[0x4D7] & 0xFF) + ((aBuffer[0x4D8] & 0xFF) << 8); 2245cdf0e10cSrcweir rDFA.meWeight = ImplWeightToSal( nWinWeight ); 2246cdf0e10cSrcweir 2247cdf0e10cSrcweir rDFA.mbSymbolFlag = false; // TODO 2248cdf0e10cSrcweir rDFA.mePitch = PITCH_DONTKNOW; // TODO 2249cdf0e10cSrcweir 2250cdf0e10cSrcweir // byte offset 0x4DE: pitch&family 2251cdf0e10cSrcweir rDFA.meFamily = ImplFamilyToSal( aBuffer[0x4DE] ); 2252cdf0e10cSrcweir 2253cdf0e10cSrcweir // byte offsets 0x4C8/0x4C9: emunits 2254cdf0e10cSrcweir // byte offsets 0x4CE/0x4CF: winascent 2255cdf0e10cSrcweir // byte offsets 0x4D0/0x4D1: winascent+windescent-emunits 2256cdf0e10cSrcweir // byte offsets 0x4DF/0x4E0: avgwidth 2257cdf0e10cSrcweir //... 2258cdf0e10cSrcweir 2259cdf0e10cSrcweir return true; 2260cdf0e10cSrcweir } 2261cdf0e10cSrcweir 2262cdf0e10cSrcweir // ----------------------------------------------------------------------- 2263cdf0e10cSrcweir 2264cdf0e10cSrcweir bool WinSalGraphics::AddTempDevFont( ImplDevFontList* pFontList, 2265cdf0e10cSrcweir const String& rFontFileURL, const String& rFontName ) 2266cdf0e10cSrcweir { 2267cdf0e10cSrcweir RTL_LOGFILE_TRACE1( "WinSalGraphics::AddTempDevFont(): %s", rtl::OUStringToOString( rFontFileURL, RTL_TEXTENCODING_UTF8 ).getStr() ); 2268cdf0e10cSrcweir 2269cdf0e10cSrcweir ImplDevFontAttributes aDFA; 2270cdf0e10cSrcweir aDFA.maName = rFontName; 2271cdf0e10cSrcweir aDFA.mnQuality = 1000; 2272cdf0e10cSrcweir aDFA.mbDevice = true; 2273cdf0e10cSrcweir 2274cdf0e10cSrcweir // Search Font Name in Cache 2275cdf0e10cSrcweir if( !rFontName.Len() && mpFontAttrCache ) 2276cdf0e10cSrcweir aDFA = mpFontAttrCache->GetFontAttr( rFontFileURL ); 2277cdf0e10cSrcweir 2278cdf0e10cSrcweir // Retrieve font name from font resource 2279cdf0e10cSrcweir if( !aDFA.maName.Len() ) 2280cdf0e10cSrcweir { 2281cdf0e10cSrcweir ImplGetFontAttrFromFile( rFontFileURL, aDFA ); 2282cdf0e10cSrcweir if( mpFontAttrCache && aDFA.maName.Len() ) 2283cdf0e10cSrcweir mpFontAttrCache->AddFontAttr( rFontFileURL, aDFA ); 2284cdf0e10cSrcweir } 2285cdf0e10cSrcweir 2286cdf0e10cSrcweir if ( !aDFA.maName.Len() ) 2287cdf0e10cSrcweir return false; 2288cdf0e10cSrcweir 2289cdf0e10cSrcweir // remember temp font for cleanup later 2290cdf0e10cSrcweir if( !ImplAddTempFont( *GetSalData(), rFontFileURL ) ) 2291cdf0e10cSrcweir return false; 2292cdf0e10cSrcweir 2293cdf0e10cSrcweir UINT nPreferedCharSet = DEFAULT_CHARSET; 2294cdf0e10cSrcweir 2295cdf0e10cSrcweir // create matching FontData struct 2296cdf0e10cSrcweir aDFA.mbSymbolFlag = false; // TODO: how to know it without accessing the font? 2297cdf0e10cSrcweir aDFA.meFamily = FAMILY_DONTKNOW; 2298cdf0e10cSrcweir aDFA.meWidthType = WIDTH_DONTKNOW; 2299cdf0e10cSrcweir aDFA.meWeight = WEIGHT_DONTKNOW; 2300cdf0e10cSrcweir aDFA.meItalic = ITALIC_DONTKNOW; 2301cdf0e10cSrcweir aDFA.mePitch = PITCH_DONTKNOW;; 2302cdf0e10cSrcweir aDFA.mbSubsettable= true; 2303cdf0e10cSrcweir aDFA.mbEmbeddable = false; 2304cdf0e10cSrcweir 2305cdf0e10cSrcweir /* 2306cdf0e10cSrcweir // TODO: improve ImplDevFontAttributes using the "font resource file" 2307cdf0e10cSrcweir aDFS.maName = // using "FONTRES:" from file 2308cdf0e10cSrcweir if( rFontName != aDFS.maName ) 2309cdf0e10cSrcweir aDFS.maMapName = aFontName; 2310cdf0e10cSrcweir */ 2311cdf0e10cSrcweir 2312cdf0e10cSrcweir ImplWinFontData* pFontData = new ImplWinFontData( aDFA, 0, 2313cdf0e10cSrcweir sal::static_int_cast<BYTE>(nPreferedCharSet), 2314cdf0e10cSrcweir sal::static_int_cast<BYTE>(TMPF_VECTOR|TMPF_TRUETYPE) ); 2315cdf0e10cSrcweir pFontData->SetFontId( reinterpret_cast<sal_IntPtr>(pFontData) ); 2316cdf0e10cSrcweir pFontList->Add( pFontData ); 2317cdf0e10cSrcweir return true; 2318cdf0e10cSrcweir } 2319cdf0e10cSrcweir 2320cdf0e10cSrcweir // ----------------------------------------------------------------------- 2321cdf0e10cSrcweir 2322cdf0e10cSrcweir void WinSalGraphics::GetDevFontList( ImplDevFontList* pFontList ) 2323cdf0e10cSrcweir { 2324cdf0e10cSrcweir // make sure all fonts are registered at least temporarily 2325cdf0e10cSrcweir static bool bOnce = true; 2326cdf0e10cSrcweir if( bOnce ) 2327cdf0e10cSrcweir { 2328cdf0e10cSrcweir bOnce = false; 2329cdf0e10cSrcweir 2330cdf0e10cSrcweir // determine font path 2331cdf0e10cSrcweir // since we are only interested in fonts that could not be 2332cdf0e10cSrcweir // registered before because of missing administration rights 2333cdf0e10cSrcweir // only the font path of the user installation is needed 2334cdf0e10cSrcweir ::rtl::OUString aPath; 2335cdf0e10cSrcweir osl_getExecutableFile( &aPath.pData ); 2336cdf0e10cSrcweir ::rtl::OUString aExecutableFile( aPath ); 2337cdf0e10cSrcweir aPath = aPath.copy( 0, aPath.lastIndexOf('/') ); 2338cdf0e10cSrcweir String aFontDirUrl = aPath.copy( 0, aPath.lastIndexOf('/') ); 2339cdf0e10cSrcweir aFontDirUrl += String( RTL_CONSTASCII_USTRINGPARAM("/Basis/share/fonts/truetype") ); 2340cdf0e10cSrcweir 2341cdf0e10cSrcweir // collect fonts in font path that could not be registered 2342cdf0e10cSrcweir osl::Directory aFontDir( aFontDirUrl ); 2343cdf0e10cSrcweir osl::FileBase::RC rcOSL = aFontDir.open(); 2344cdf0e10cSrcweir if( rcOSL == osl::FileBase::E_None ) 2345cdf0e10cSrcweir { 2346cdf0e10cSrcweir osl::DirectoryItem aDirItem; 2347cdf0e10cSrcweir String aEmptyString; 2348cdf0e10cSrcweir 2349cdf0e10cSrcweir ::rtl::OUString aBootStrap; 2350cdf0e10cSrcweir rtl::Bootstrap::get( String( RTL_CONSTASCII_USTRINGPARAM( "BRAND_BASE_DIR" ) ), aBootStrap ); 2351cdf0e10cSrcweir aBootStrap += String( RTL_CONSTASCII_USTRINGPARAM( "/program/" SAL_CONFIGFILE( "bootstrap" ) ) ); 2352cdf0e10cSrcweir rtl::Bootstrap aBootstrap( aBootStrap ); 2353cdf0e10cSrcweir ::rtl::OUString aUserPath; 2354cdf0e10cSrcweir aBootstrap.getFrom( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserInstallation" ) ), aUserPath ); 2355cdf0e10cSrcweir aUserPath += String( RTL_CONSTASCII_USTRINGPARAM("/user/config/fontnames.dat") ); 2356cdf0e10cSrcweir String aBaseURL = aPath.copy( 0, aPath.lastIndexOf('/')+1 ); 2357cdf0e10cSrcweir mpFontAttrCache = new ImplFontAttrCache( aUserPath, aBaseURL ); 2358cdf0e10cSrcweir 2359cdf0e10cSrcweir while( aFontDir.getNextItem( aDirItem, 10 ) == osl::FileBase::E_None ) 2360cdf0e10cSrcweir { 2361cdf0e10cSrcweir osl::FileStatus aFileStatus( FileStatusMask_FileURL ); 2362cdf0e10cSrcweir rcOSL = aDirItem.getFileStatus( aFileStatus ); 2363cdf0e10cSrcweir if ( rcOSL == osl::FileBase::E_None ) 2364cdf0e10cSrcweir AddTempDevFont( pFontList, aFileStatus.getFileURL(), aEmptyString ); 2365cdf0e10cSrcweir } 2366cdf0e10cSrcweir 2367cdf0e10cSrcweir delete mpFontAttrCache; // destructor rewrites the cache file if needed 2368cdf0e10cSrcweir mpFontAttrCache = NULL; 2369cdf0e10cSrcweir } 2370cdf0e10cSrcweir } 2371cdf0e10cSrcweir 2372cdf0e10cSrcweir ImplEnumInfo aInfo; 2373cdf0e10cSrcweir aInfo.mhDC = mhDC; 2374cdf0e10cSrcweir aInfo.mpList = pFontList; 2375cdf0e10cSrcweir aInfo.mpName = NULL; 2376cdf0e10cSrcweir aInfo.mpLogFontA = NULL; 2377cdf0e10cSrcweir aInfo.mpLogFontW = NULL; 2378cdf0e10cSrcweir aInfo.mbCourier = false; 2379cdf0e10cSrcweir aInfo.mbPrinter = mbPrinter; 2380cdf0e10cSrcweir aInfo.mnFontCount = 0; 2381cdf0e10cSrcweir if ( !mbPrinter ) 2382cdf0e10cSrcweir { 2383cdf0e10cSrcweir aInfo.mbImplSalCourierScalable = false; 2384cdf0e10cSrcweir aInfo.mbImplSalCourierNew = false; 2385cdf0e10cSrcweir } 2386cdf0e10cSrcweir else 2387cdf0e10cSrcweir { 2388cdf0e10cSrcweir aInfo.mbImplSalCourierScalable = true; 2389cdf0e10cSrcweir aInfo.mbImplSalCourierNew = true; 2390cdf0e10cSrcweir } 2391cdf0e10cSrcweir 2392cdf0e10cSrcweir aInfo.mnPreferedCharSet = DEFAULT_CHARSET; 2393cdf0e10cSrcweir DWORD nCP = GetACP(); 2394cdf0e10cSrcweir CHARSETINFO aCharSetInfo; 2395cdf0e10cSrcweir if ( TranslateCharsetInfo( (DWORD*)nCP, &aCharSetInfo, TCI_SRCCODEPAGE ) ) 2396cdf0e10cSrcweir aInfo.mnPreferedCharSet = aCharSetInfo.ciCharset; 2397cdf0e10cSrcweir 2398cdf0e10cSrcweir LOGFONTW aLogFont; 2399cdf0e10cSrcweir memset( &aLogFont, 0, sizeof( aLogFont ) ); 2400cdf0e10cSrcweir aLogFont.lfCharSet = DEFAULT_CHARSET; 2401cdf0e10cSrcweir aInfo.mpLogFontW = &aLogFont; 2402cdf0e10cSrcweir EnumFontFamiliesExW( mhDC, &aLogFont, 2403cdf0e10cSrcweir (FONTENUMPROCW)SalEnumFontsProcExW, (LPARAM)(void*)&aInfo, 0 ); 2404cdf0e10cSrcweir 2405cdf0e10cSrcweir // Feststellen, was es fuer Courier-Schriften auf dem Bildschirm gibt, 2406cdf0e10cSrcweir // um in SetFont() evt. Courier auf Courier New zu mappen 2407cdf0e10cSrcweir if ( !mbPrinter ) 2408cdf0e10cSrcweir { 2409cdf0e10cSrcweir bImplSalCourierScalable = aInfo.mbImplSalCourierScalable; 2410cdf0e10cSrcweir bImplSalCourierNew = aInfo.mbImplSalCourierNew; 2411cdf0e10cSrcweir } 2412cdf0e10cSrcweir 2413cdf0e10cSrcweir // set glyph fallback hook 2414cdf0e10cSrcweir static WinGlyphFallbackSubstititution aSubstFallback( mhDC ); 2415cdf0e10cSrcweir pFontList->SetFallbackHook( &aSubstFallback ); 2416cdf0e10cSrcweir } 2417cdf0e10cSrcweir 2418cdf0e10cSrcweir // ---------------------------------------------------------------------------- 2419cdf0e10cSrcweir 2420cdf0e10cSrcweir void WinSalGraphics::GetDevFontSubstList( OutputDevice* ) 2421cdf0e10cSrcweir {} 2422cdf0e10cSrcweir 2423cdf0e10cSrcweir // ----------------------------------------------------------------------- 2424cdf0e10cSrcweir 2425cdf0e10cSrcweir sal_Bool WinSalGraphics::GetGlyphBoundRect( long nIndex, Rectangle& rRect ) 2426cdf0e10cSrcweir { 2427cdf0e10cSrcweir HDC hDC = mhDC; 2428cdf0e10cSrcweir 2429cdf0e10cSrcweir // use unity matrix 2430cdf0e10cSrcweir MAT2 aMat; 2431cdf0e10cSrcweir aMat.eM11 = aMat.eM22 = FixedFromDouble( 1.0 ); 2432cdf0e10cSrcweir aMat.eM12 = aMat.eM21 = FixedFromDouble( 0.0 ); 2433cdf0e10cSrcweir 2434cdf0e10cSrcweir UINT nGGOFlags = GGO_METRICS; 2435cdf0e10cSrcweir if( !(nIndex & GF_ISCHAR) ) 2436cdf0e10cSrcweir nGGOFlags |= GGO_GLYPH_INDEX; 2437cdf0e10cSrcweir nIndex &= GF_IDXMASK; 2438cdf0e10cSrcweir 2439cdf0e10cSrcweir GLYPHMETRICS aGM; 2440cdf0e10cSrcweir aGM.gmptGlyphOrigin.x = aGM.gmptGlyphOrigin.y = 0; 2441cdf0e10cSrcweir aGM.gmBlackBoxX = aGM.gmBlackBoxY = 0; 2442cdf0e10cSrcweir DWORD nSize = ::GetGlyphOutlineW( hDC, nIndex, nGGOFlags, &aGM, 0, NULL, &aMat ); 2443cdf0e10cSrcweir if( nSize == GDI_ERROR ) 2444cdf0e10cSrcweir return false; 2445cdf0e10cSrcweir 2446cdf0e10cSrcweir rRect = Rectangle( Point( +aGM.gmptGlyphOrigin.x, -aGM.gmptGlyphOrigin.y ), 2447cdf0e10cSrcweir Size( aGM.gmBlackBoxX, aGM.gmBlackBoxY ) ); 2448cdf0e10cSrcweir rRect.Left() = static_cast<int>( mfFontScale * rRect.Left() ); 2449cdf0e10cSrcweir rRect.Right() = static_cast<int>( mfFontScale * rRect.Right() ); 2450cdf0e10cSrcweir rRect.Top() = static_cast<int>( mfFontScale * rRect.Top() ); 2451cdf0e10cSrcweir rRect.Bottom() = static_cast<int>( mfFontScale * rRect.Bottom() ); 2452cdf0e10cSrcweir return true; 2453cdf0e10cSrcweir } 2454cdf0e10cSrcweir 2455cdf0e10cSrcweir // ----------------------------------------------------------------------- 2456cdf0e10cSrcweir 2457cdf0e10cSrcweir sal_Bool WinSalGraphics::GetGlyphOutline( long nIndex, 2458cdf0e10cSrcweir ::basegfx::B2DPolyPolygon& rB2DPolyPoly ) 2459cdf0e10cSrcweir { 2460cdf0e10cSrcweir rB2DPolyPoly.clear(); 2461cdf0e10cSrcweir 2462cdf0e10cSrcweir HDC hDC = mhDC; 2463cdf0e10cSrcweir 2464cdf0e10cSrcweir // use unity matrix 2465cdf0e10cSrcweir MAT2 aMat; 2466cdf0e10cSrcweir aMat.eM11 = aMat.eM22 = FixedFromDouble( 1.0 ); 2467cdf0e10cSrcweir aMat.eM12 = aMat.eM21 = FixedFromDouble( 0.0 ); 2468cdf0e10cSrcweir 2469cdf0e10cSrcweir UINT nGGOFlags = GGO_NATIVE; 2470cdf0e10cSrcweir if( !(nIndex & GF_ISCHAR) ) 2471cdf0e10cSrcweir nGGOFlags |= GGO_GLYPH_INDEX; 2472cdf0e10cSrcweir nIndex &= GF_IDXMASK; 2473cdf0e10cSrcweir 2474cdf0e10cSrcweir GLYPHMETRICS aGlyphMetrics; 2475cdf0e10cSrcweir const DWORD nSize1 = ::GetGlyphOutlineW( hDC, nIndex, nGGOFlags, &aGlyphMetrics, 0, NULL, &aMat ); 2476cdf0e10cSrcweir if( !nSize1 ) // blank glyphs are ok 2477cdf0e10cSrcweir return TRUE; 2478cdf0e10cSrcweir else if( nSize1 == GDI_ERROR ) 2479cdf0e10cSrcweir return FALSE; 2480cdf0e10cSrcweir 2481cdf0e10cSrcweir BYTE* pData = new BYTE[ nSize1 ]; 2482cdf0e10cSrcweir const DWORD nSize2 = ::GetGlyphOutlineW( hDC, nIndex, nGGOFlags, 2483cdf0e10cSrcweir &aGlyphMetrics, nSize1, pData, &aMat ); 2484cdf0e10cSrcweir 2485cdf0e10cSrcweir if( nSize1 != nSize2 ) 2486cdf0e10cSrcweir return FALSE; 2487cdf0e10cSrcweir 2488cdf0e10cSrcweir // TODO: avoid tools polygon by creating B2DPolygon directly 2489cdf0e10cSrcweir int nPtSize = 512; 2490cdf0e10cSrcweir Point* pPoints = new Point[ nPtSize ]; 2491cdf0e10cSrcweir BYTE* pFlags = new BYTE[ nPtSize ]; 2492cdf0e10cSrcweir 2493cdf0e10cSrcweir TTPOLYGONHEADER* pHeader = (TTPOLYGONHEADER*)pData; 2494cdf0e10cSrcweir while( (BYTE*)pHeader < pData+nSize2 ) 2495cdf0e10cSrcweir { 2496cdf0e10cSrcweir // only outline data is interesting 2497cdf0e10cSrcweir if( pHeader->dwType != TT_POLYGON_TYPE ) 2498cdf0e10cSrcweir break; 2499cdf0e10cSrcweir 2500cdf0e10cSrcweir // get start point; next start points are end points 2501cdf0e10cSrcweir // of previous segment 2502cdf0e10cSrcweir USHORT nPnt = 0; 2503cdf0e10cSrcweir 2504cdf0e10cSrcweir long nX = IntTimes256FromFixed( pHeader->pfxStart.x ); 2505cdf0e10cSrcweir long nY = IntTimes256FromFixed( pHeader->pfxStart.y ); 2506cdf0e10cSrcweir pPoints[ nPnt ] = Point( nX, nY ); 2507cdf0e10cSrcweir pFlags[ nPnt++ ] = POLY_NORMAL; 2508cdf0e10cSrcweir 2509cdf0e10cSrcweir bool bHasOfflinePoints = false; 2510cdf0e10cSrcweir TTPOLYCURVE* pCurve = (TTPOLYCURVE*)( pHeader + 1 ); 2511cdf0e10cSrcweir pHeader = (TTPOLYGONHEADER*)( (BYTE*)pHeader + pHeader->cb ); 2512cdf0e10cSrcweir while( (BYTE*)pCurve < (BYTE*)pHeader ) 2513cdf0e10cSrcweir { 2514cdf0e10cSrcweir int nNeededSize = nPnt + 16 + 3 * pCurve->cpfx; 2515cdf0e10cSrcweir if( nPtSize < nNeededSize ) 2516cdf0e10cSrcweir { 2517cdf0e10cSrcweir Point* pOldPoints = pPoints; 2518cdf0e10cSrcweir BYTE* pOldFlags = pFlags; 2519cdf0e10cSrcweir nPtSize = 2 * nNeededSize; 2520cdf0e10cSrcweir pPoints = new Point[ nPtSize ]; 2521cdf0e10cSrcweir pFlags = new BYTE[ nPtSize ]; 2522cdf0e10cSrcweir for( USHORT i = 0; i < nPnt; ++i ) 2523cdf0e10cSrcweir { 2524cdf0e10cSrcweir pPoints[ i ] = pOldPoints[ i ]; 2525cdf0e10cSrcweir pFlags[ i ] = pOldFlags[ i ]; 2526cdf0e10cSrcweir } 2527cdf0e10cSrcweir delete[] pOldPoints; 2528cdf0e10cSrcweir delete[] pOldFlags; 2529cdf0e10cSrcweir } 2530cdf0e10cSrcweir 2531cdf0e10cSrcweir int i = 0; 2532cdf0e10cSrcweir if( TT_PRIM_LINE == pCurve->wType ) 2533cdf0e10cSrcweir { 2534cdf0e10cSrcweir while( i < pCurve->cpfx ) 2535cdf0e10cSrcweir { 2536cdf0e10cSrcweir nX = IntTimes256FromFixed( pCurve->apfx[ i ].x ); 2537cdf0e10cSrcweir nY = IntTimes256FromFixed( pCurve->apfx[ i ].y ); 2538cdf0e10cSrcweir ++i; 2539cdf0e10cSrcweir pPoints[ nPnt ] = Point( nX, nY ); 2540cdf0e10cSrcweir pFlags[ nPnt ] = POLY_NORMAL; 2541cdf0e10cSrcweir ++nPnt; 2542cdf0e10cSrcweir } 2543cdf0e10cSrcweir } 2544cdf0e10cSrcweir else if( TT_PRIM_QSPLINE == pCurve->wType ) 2545cdf0e10cSrcweir { 2546cdf0e10cSrcweir bHasOfflinePoints = true; 2547cdf0e10cSrcweir while( i < pCurve->cpfx ) 2548cdf0e10cSrcweir { 2549cdf0e10cSrcweir // get control point of quadratic bezier spline 2550cdf0e10cSrcweir nX = IntTimes256FromFixed( pCurve->apfx[ i ].x ); 2551cdf0e10cSrcweir nY = IntTimes256FromFixed( pCurve->apfx[ i ].y ); 2552cdf0e10cSrcweir ++i; 2553cdf0e10cSrcweir Point aControlP( nX, nY ); 2554cdf0e10cSrcweir 2555cdf0e10cSrcweir // calculate first cubic control point 2556cdf0e10cSrcweir // P0 = 1/3 * (PBeg + 2 * PQControl) 2557cdf0e10cSrcweir nX = pPoints[ nPnt-1 ].X() + 2 * aControlP.X(); 2558cdf0e10cSrcweir nY = pPoints[ nPnt-1 ].Y() + 2 * aControlP.Y(); 2559cdf0e10cSrcweir pPoints[ nPnt+0 ] = Point( (2*nX+3)/6, (2*nY+3)/6 ); 2560cdf0e10cSrcweir pFlags[ nPnt+0 ] = POLY_CONTROL; 2561cdf0e10cSrcweir 2562cdf0e10cSrcweir // calculate endpoint of segment 2563cdf0e10cSrcweir nX = IntTimes256FromFixed( pCurve->apfx[ i ].x ); 2564cdf0e10cSrcweir nY = IntTimes256FromFixed( pCurve->apfx[ i ].y ); 2565cdf0e10cSrcweir 2566cdf0e10cSrcweir if ( i+1 >= pCurve->cpfx ) 2567cdf0e10cSrcweir { 2568cdf0e10cSrcweir // endpoint is either last point in segment => advance 2569cdf0e10cSrcweir ++i; 2570cdf0e10cSrcweir } 2571cdf0e10cSrcweir else 2572cdf0e10cSrcweir { 2573cdf0e10cSrcweir // or endpoint is the middle of two control points 2574cdf0e10cSrcweir nX += IntTimes256FromFixed( pCurve->apfx[ i-1 ].x ); 2575cdf0e10cSrcweir nY += IntTimes256FromFixed( pCurve->apfx[ i-1 ].y ); 2576cdf0e10cSrcweir nX = (nX + 1) / 2; 2577cdf0e10cSrcweir nY = (nY + 1) / 2; 2578cdf0e10cSrcweir // no need to advance, because the current point 2579cdf0e10cSrcweir // is the control point in next bezier spline 2580cdf0e10cSrcweir } 2581cdf0e10cSrcweir 2582cdf0e10cSrcweir pPoints[ nPnt+2 ] = Point( nX, nY ); 2583cdf0e10cSrcweir pFlags[ nPnt+2 ] = POLY_NORMAL; 2584cdf0e10cSrcweir 2585cdf0e10cSrcweir // calculate second cubic control point 2586cdf0e10cSrcweir // P1 = 1/3 * (PEnd + 2 * PQControl) 2587cdf0e10cSrcweir nX = pPoints[ nPnt+2 ].X() + 2 * aControlP.X(); 2588cdf0e10cSrcweir nY = pPoints[ nPnt+2 ].Y() + 2 * aControlP.Y(); 2589cdf0e10cSrcweir pPoints[ nPnt+1 ] = Point( (2*nX+3)/6, (2*nY+3)/6 ); 2590cdf0e10cSrcweir pFlags[ nPnt+1 ] = POLY_CONTROL; 2591cdf0e10cSrcweir 2592cdf0e10cSrcweir nPnt += 3; 2593cdf0e10cSrcweir } 2594cdf0e10cSrcweir } 2595cdf0e10cSrcweir 2596cdf0e10cSrcweir // next curve segment 2597cdf0e10cSrcweir pCurve = (TTPOLYCURVE*)&pCurve->apfx[ i ]; 2598cdf0e10cSrcweir } 2599cdf0e10cSrcweir 2600cdf0e10cSrcweir // end point is start point for closed contour 2601cdf0e10cSrcweir // disabled, because Polygon class closes the contour itself 2602cdf0e10cSrcweir // pPoints[nPnt++] = pPoints[0]; 2603cdf0e10cSrcweir // #i35928# 2604cdf0e10cSrcweir // Added again, but add only when not yet closed 2605cdf0e10cSrcweir if(pPoints[nPnt - 1] != pPoints[0]) 2606cdf0e10cSrcweir { 2607cdf0e10cSrcweir if( bHasOfflinePoints ) 2608cdf0e10cSrcweir pFlags[nPnt] = pFlags[0]; 2609cdf0e10cSrcweir 2610cdf0e10cSrcweir pPoints[nPnt++] = pPoints[0]; 2611cdf0e10cSrcweir } 2612cdf0e10cSrcweir 2613cdf0e10cSrcweir // convert y-coordinates W32 -> VCL 2614cdf0e10cSrcweir for( int i = 0; i < nPnt; ++i ) 2615cdf0e10cSrcweir pPoints[i].Y() = -pPoints[i].Y(); 2616cdf0e10cSrcweir 2617cdf0e10cSrcweir // insert into polypolygon 2618cdf0e10cSrcweir Polygon aPoly( nPnt, pPoints, (bHasOfflinePoints ? pFlags : NULL) ); 2619cdf0e10cSrcweir // convert to B2DPolyPolygon 2620cdf0e10cSrcweir // TODO: get rid of the intermediate PolyPolygon 2621cdf0e10cSrcweir rB2DPolyPoly.append( aPoly.getB2DPolygon() ); 2622cdf0e10cSrcweir } 2623cdf0e10cSrcweir 2624cdf0e10cSrcweir delete[] pPoints; 2625cdf0e10cSrcweir delete[] pFlags; 2626cdf0e10cSrcweir 2627cdf0e10cSrcweir delete[] pData; 2628cdf0e10cSrcweir 2629cdf0e10cSrcweir // rescaling needed for the PolyPolygon conversion 2630cdf0e10cSrcweir if( rB2DPolyPoly.count() ) 2631cdf0e10cSrcweir { 2632cdf0e10cSrcweir const double fFactor(mfFontScale/256); 2633cdf0e10cSrcweir rB2DPolyPoly.transform(basegfx::tools::createScaleB2DHomMatrix(fFactor, fFactor)); 2634cdf0e10cSrcweir } 2635cdf0e10cSrcweir 2636cdf0e10cSrcweir return TRUE; 2637cdf0e10cSrcweir } 2638cdf0e10cSrcweir 2639cdf0e10cSrcweir // ----------------------------------------------------------------------- 2640cdf0e10cSrcweir 2641cdf0e10cSrcweir class ScopedFont 2642cdf0e10cSrcweir { 2643cdf0e10cSrcweir public: 2644cdf0e10cSrcweir explicit ScopedFont(WinSalGraphics & rData); 2645cdf0e10cSrcweir 2646cdf0e10cSrcweir ~ScopedFont(); 2647cdf0e10cSrcweir 2648cdf0e10cSrcweir private: 2649cdf0e10cSrcweir WinSalGraphics & m_rData; 2650cdf0e10cSrcweir HFONT m_hOrigFont; 2651cdf0e10cSrcweir }; 2652cdf0e10cSrcweir 2653cdf0e10cSrcweir ScopedFont::ScopedFont(WinSalGraphics & rData): m_rData(rData) 2654cdf0e10cSrcweir { 2655cdf0e10cSrcweir m_hOrigFont = m_rData.mhFonts[0]; 2656cdf0e10cSrcweir m_rData.mhFonts[0] = 0; // avoid deletion of current font 2657cdf0e10cSrcweir } 2658cdf0e10cSrcweir 2659cdf0e10cSrcweir ScopedFont::~ScopedFont() 2660cdf0e10cSrcweir { 2661cdf0e10cSrcweir if( m_hOrigFont ) 2662cdf0e10cSrcweir { 2663cdf0e10cSrcweir // restore original font, destroy temporary font 2664cdf0e10cSrcweir HFONT hTempFont = m_rData.mhFonts[0]; 2665cdf0e10cSrcweir m_rData.mhFonts[0] = m_hOrigFont; 2666cdf0e10cSrcweir SelectObject( m_rData.mhDC, m_hOrigFont ); 2667cdf0e10cSrcweir DeleteObject( hTempFont ); 2668cdf0e10cSrcweir } 2669cdf0e10cSrcweir } 2670cdf0e10cSrcweir 2671cdf0e10cSrcweir class ScopedTrueTypeFont 2672cdf0e10cSrcweir { 2673cdf0e10cSrcweir public: 2674cdf0e10cSrcweir inline ScopedTrueTypeFont(): m_pFont(0) {} 2675cdf0e10cSrcweir 2676cdf0e10cSrcweir ~ScopedTrueTypeFont(); 2677cdf0e10cSrcweir 2678cdf0e10cSrcweir int open(void * pBuffer, sal_uInt32 nLen, sal_uInt32 nFaceNum); 2679cdf0e10cSrcweir 2680cdf0e10cSrcweir inline TrueTypeFont * get() const { return m_pFont; } 2681cdf0e10cSrcweir 2682cdf0e10cSrcweir private: 2683cdf0e10cSrcweir TrueTypeFont * m_pFont; 2684cdf0e10cSrcweir }; 2685cdf0e10cSrcweir 2686cdf0e10cSrcweir ScopedTrueTypeFont::~ScopedTrueTypeFont() 2687cdf0e10cSrcweir { 2688cdf0e10cSrcweir if (m_pFont != 0) 2689cdf0e10cSrcweir CloseTTFont(m_pFont); 2690cdf0e10cSrcweir } 2691cdf0e10cSrcweir 2692cdf0e10cSrcweir int ScopedTrueTypeFont::open(void * pBuffer, sal_uInt32 nLen, 2693cdf0e10cSrcweir sal_uInt32 nFaceNum) 2694cdf0e10cSrcweir { 2695cdf0e10cSrcweir OSL_ENSURE(m_pFont == 0, "already open"); 2696cdf0e10cSrcweir return OpenTTFontBuffer(pBuffer, nLen, nFaceNum, &m_pFont); 2697cdf0e10cSrcweir } 2698cdf0e10cSrcweir 2699cdf0e10cSrcweir sal_Bool WinSalGraphics::CreateFontSubset( const rtl::OUString& rToFile, 2700cdf0e10cSrcweir const ImplFontData* pFont, long* pGlyphIDs, sal_uInt8* pEncoding, 2701cdf0e10cSrcweir sal_Int32* pGlyphWidths, int nGlyphCount, FontSubsetInfo& rInfo ) 2702cdf0e10cSrcweir { 2703cdf0e10cSrcweir // TODO: use more of the central font-subsetting code, move stuff there if needed 2704cdf0e10cSrcweir 2705cdf0e10cSrcweir // create matching ImplFontSelectData 2706cdf0e10cSrcweir // we need just enough to get to the font file data 2707cdf0e10cSrcweir // use height=1000 for easier debugging (to match psprint's font units) 2708cdf0e10cSrcweir ImplFontSelectData aIFSD( *pFont, Size(0,1000), 1000.0, 0, false ); 2709cdf0e10cSrcweir 2710cdf0e10cSrcweir // TODO: much better solution: move SetFont and restoration of old font to caller 2711cdf0e10cSrcweir ScopedFont aOldFont(*this); 2712cdf0e10cSrcweir float fScale = 1.0; 2713cdf0e10cSrcweir HFONT hOldFont = 0; 2714cdf0e10cSrcweir ImplDoSetFont( &aIFSD, fScale, hOldFont ); 2715cdf0e10cSrcweir 2716cdf0e10cSrcweir ImplWinFontData* pWinFontData = (ImplWinFontData*)aIFSD.mpFontData; 2717cdf0e10cSrcweir 2718cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 2719cdf0e10cSrcweir // get font metrics 2720cdf0e10cSrcweir TEXTMETRICA aWinMetric; 2721cdf0e10cSrcweir if( !::GetTextMetricsA( mhDC, &aWinMetric ) ) 2722cdf0e10cSrcweir return FALSE; 2723cdf0e10cSrcweir 2724cdf0e10cSrcweir DBG_ASSERT( !(aWinMetric.tmPitchAndFamily & TMPF_DEVICE), "cannot subset device font" ); 2725cdf0e10cSrcweir DBG_ASSERT( aWinMetric.tmPitchAndFamily & TMPF_TRUETYPE, "can only subset TT font" ); 2726cdf0e10cSrcweir #endif 2727cdf0e10cSrcweir 2728cdf0e10cSrcweir rtl::OUString aSysPath; 2729cdf0e10cSrcweir if( osl_File_E_None != osl_getSystemPathFromFileURL( rToFile.pData, &aSysPath.pData ) ) 2730cdf0e10cSrcweir return FALSE; 2731cdf0e10cSrcweir const rtl_TextEncoding aThreadEncoding = osl_getThreadTextEncoding(); 2732cdf0e10cSrcweir const ByteString aToFile( aSysPath.getStr(), (xub_StrLen)aSysPath.getLength(), aThreadEncoding ); 2733cdf0e10cSrcweir 2734cdf0e10cSrcweir // check if the font has a CFF-table 2735cdf0e10cSrcweir const DWORD nCffTag = CalcTag( "CFF " ); 2736cdf0e10cSrcweir const RawFontData aRawCffData( mhDC, nCffTag ); 2737cdf0e10cSrcweir if( aRawCffData.get() ) 2738cdf0e10cSrcweir { 2739cdf0e10cSrcweir pWinFontData->UpdateFromHDC( mhDC ); 2740cdf0e10cSrcweir const ImplFontCharMap* pCharMap = pWinFontData->GetImplFontCharMap(); 2741cdf0e10cSrcweir pCharMap->AddReference(); 2742cdf0e10cSrcweir 2743cdf0e10cSrcweir long nRealGlyphIds[ 256 ]; 2744cdf0e10cSrcweir for( int i = 0; i < nGlyphCount; ++i ) 2745cdf0e10cSrcweir { 2746cdf0e10cSrcweir // TODO: remap notdef glyph if needed 2747cdf0e10cSrcweir // TODO: use GDI's GetGlyphIndices instead? Does it handle GSUB properly? 2748cdf0e10cSrcweir sal_uInt32 nGlyphIdx = pGlyphIDs[i] & GF_IDXMASK; 2749cdf0e10cSrcweir if( pGlyphIDs[i] & GF_ISCHAR ) // remaining pseudo-glyphs need to be translated 2750cdf0e10cSrcweir nGlyphIdx = pCharMap->GetGlyphIndex( nGlyphIdx ); 2751cdf0e10cSrcweir if( (pGlyphIDs[i] & (GF_ROTMASK|GF_GSUB)) != 0) // TODO: vertical substitution 2752cdf0e10cSrcweir {/*####*/} 2753cdf0e10cSrcweir 2754cdf0e10cSrcweir nRealGlyphIds[i] = nGlyphIdx; 2755cdf0e10cSrcweir } 2756cdf0e10cSrcweir 2757cdf0e10cSrcweir pCharMap->DeReference(); // TODO: and and use a RAII object 2758cdf0e10cSrcweir 2759cdf0e10cSrcweir // provide a font subset from the CFF-table 2760cdf0e10cSrcweir FILE* pOutFile = fopen( aToFile.GetBuffer(), "wb" ); 2761cdf0e10cSrcweir rInfo.LoadFont( FontSubsetInfo::CFF_FONT, aRawCffData.get(), aRawCffData.size() ); 2762cdf0e10cSrcweir bool bRC = rInfo.CreateFontSubset( FontSubsetInfo::TYPE1_PFB, pOutFile, NULL, 2763cdf0e10cSrcweir nRealGlyphIds, pEncoding, nGlyphCount, pGlyphWidths ); 2764cdf0e10cSrcweir fclose( pOutFile ); 2765cdf0e10cSrcweir return bRC; 2766cdf0e10cSrcweir } 2767cdf0e10cSrcweir 2768cdf0e10cSrcweir // get raw font file data 2769cdf0e10cSrcweir const RawFontData xRawFontData( mhDC, NULL ); 2770cdf0e10cSrcweir if( !xRawFontData.get() ) 2771cdf0e10cSrcweir return FALSE; 2772cdf0e10cSrcweir 2773cdf0e10cSrcweir // open font file 2774cdf0e10cSrcweir sal_uInt32 nFaceNum = 0; 2775cdf0e10cSrcweir if( !*xRawFontData.get() ) // TTC candidate 2776cdf0e10cSrcweir nFaceNum = ~0U; // indicate "TTC font extracts only" 2777cdf0e10cSrcweir 2778cdf0e10cSrcweir ScopedTrueTypeFont aSftTTF; 2779cdf0e10cSrcweir int nRC = aSftTTF.open( (void*)xRawFontData.get(), xRawFontData.size(), nFaceNum ); 2780cdf0e10cSrcweir if( nRC != SF_OK ) 2781cdf0e10cSrcweir return FALSE; 2782cdf0e10cSrcweir 2783cdf0e10cSrcweir TTGlobalFontInfo aTTInfo; 2784cdf0e10cSrcweir ::GetTTGlobalFontInfo( aSftTTF.get(), &aTTInfo ); 2785cdf0e10cSrcweir rInfo.m_nFontType = FontSubsetInfo::SFNT_TTF; 2786cdf0e10cSrcweir rInfo.m_aPSName = ImplSalGetUniString( aTTInfo.psname ); 278759213536SEike Rathke rInfo.m_nAscent = aTTInfo.winAscent; 278859213536SEike Rathke rInfo.m_nDescent = aTTInfo.winDescent; 2789cdf0e10cSrcweir rInfo.m_aFontBBox = Rectangle( Point( aTTInfo.xMin, aTTInfo.yMin ), 2790cdf0e10cSrcweir Point( aTTInfo.xMax, aTTInfo.yMax ) ); 2791cdf0e10cSrcweir rInfo.m_nCapHeight = aTTInfo.yMax; // Well ... 2792cdf0e10cSrcweir 2793cdf0e10cSrcweir // subset TTF-glyphs and get their properties 2794cdf0e10cSrcweir // take care that subset fonts require the NotDef glyph in pos 0 2795cdf0e10cSrcweir int nOrigCount = nGlyphCount; 2796cdf0e10cSrcweir sal_uInt16 aShortIDs[ 256 ]; 2797cdf0e10cSrcweir sal_uInt8 aTempEncs[ 256 ]; 2798cdf0e10cSrcweir 2799cdf0e10cSrcweir int nNotDef=-1, i; 2800cdf0e10cSrcweir for( i = 0; i < nGlyphCount; ++i ) 2801cdf0e10cSrcweir { 2802cdf0e10cSrcweir aTempEncs[i] = pEncoding[i]; 2803cdf0e10cSrcweir sal_uInt32 nGlyphIdx = pGlyphIDs[i] & GF_IDXMASK; 2804cdf0e10cSrcweir if( pGlyphIDs[i] & GF_ISCHAR ) 2805cdf0e10cSrcweir { 2806cdf0e10cSrcweir sal_Unicode cChar = static_cast<sal_Unicode>(nGlyphIdx); // TODO: sal_UCS4 2807cdf0e10cSrcweir const bool bVertical = ((pGlyphIDs[i] & (GF_ROTMASK|GF_GSUB)) != 0); 2808cdf0e10cSrcweir nGlyphIdx = ::MapChar( aSftTTF.get(), cChar, bVertical ); 2809cdf0e10cSrcweir if( (nGlyphIdx == 0) && pFont->IsSymbolFont() ) 2810cdf0e10cSrcweir { 2811cdf0e10cSrcweir // #i12824# emulate symbol aliasing U+FXXX <-> U+0XXX 2812cdf0e10cSrcweir cChar = (cChar & 0xF000) ? (cChar & 0x00FF) : (cChar | 0xF000); 2813cdf0e10cSrcweir nGlyphIdx = ::MapChar( aSftTTF.get(), cChar, bVertical ); 2814cdf0e10cSrcweir } 2815cdf0e10cSrcweir } 2816cdf0e10cSrcweir aShortIDs[i] = static_cast<sal_uInt16>( nGlyphIdx ); 2817cdf0e10cSrcweir if( !nGlyphIdx ) 2818cdf0e10cSrcweir if( nNotDef < 0 ) 2819cdf0e10cSrcweir nNotDef = i; // first NotDef glyph found 2820cdf0e10cSrcweir } 2821cdf0e10cSrcweir 2822cdf0e10cSrcweir if( nNotDef != 0 ) 2823cdf0e10cSrcweir { 2824cdf0e10cSrcweir // add fake NotDef glyph if needed 2825cdf0e10cSrcweir if( nNotDef < 0 ) 2826cdf0e10cSrcweir nNotDef = nGlyphCount++; 2827cdf0e10cSrcweir 2828cdf0e10cSrcweir // NotDef glyph must be in pos 0 => swap glyphids 2829cdf0e10cSrcweir aShortIDs[ nNotDef ] = aShortIDs[0]; 2830cdf0e10cSrcweir aTempEncs[ nNotDef ] = aTempEncs[0]; 2831cdf0e10cSrcweir aShortIDs[0] = 0; 2832cdf0e10cSrcweir aTempEncs[0] = 0; 2833cdf0e10cSrcweir } 2834cdf0e10cSrcweir DBG_ASSERT( nGlyphCount < 257, "too many glyphs for subsetting" ); 2835cdf0e10cSrcweir 2836cdf0e10cSrcweir // fill pWidth array 2837cdf0e10cSrcweir TTSimpleGlyphMetrics* pMetrics = 2838cdf0e10cSrcweir ::GetTTSimpleGlyphMetrics( aSftTTF.get(), aShortIDs, nGlyphCount, aIFSD.mbVertical ); 2839cdf0e10cSrcweir if( !pMetrics ) 2840cdf0e10cSrcweir return FALSE; 2841cdf0e10cSrcweir sal_uInt16 nNotDefAdv = pMetrics[0].adv; 2842cdf0e10cSrcweir pMetrics[0].adv = pMetrics[nNotDef].adv; 2843cdf0e10cSrcweir pMetrics[nNotDef].adv = nNotDefAdv; 2844cdf0e10cSrcweir for( i = 0; i < nOrigCount; ++i ) 2845cdf0e10cSrcweir pGlyphWidths[i] = pMetrics[i].adv; 2846cdf0e10cSrcweir free( pMetrics ); 2847cdf0e10cSrcweir 2848cdf0e10cSrcweir // write subset into destination file 2849cdf0e10cSrcweir nRC = ::CreateTTFromTTGlyphs( aSftTTF.get(), aToFile.GetBuffer(), aShortIDs, 2850cdf0e10cSrcweir aTempEncs, nGlyphCount, 0, NULL, 0 ); 2851cdf0e10cSrcweir return (nRC == SF_OK); 2852cdf0e10cSrcweir } 2853cdf0e10cSrcweir 2854cdf0e10cSrcweir //-------------------------------------------------------------------------- 2855cdf0e10cSrcweir 2856cdf0e10cSrcweir const void* WinSalGraphics::GetEmbedFontData( const ImplFontData* pFont, 2857cdf0e10cSrcweir const sal_Unicode* pUnicodes, sal_Int32* pCharWidths, 2858cdf0e10cSrcweir FontSubsetInfo& rInfo, long* pDataLen ) 2859cdf0e10cSrcweir { 2860cdf0e10cSrcweir // create matching ImplFontSelectData 2861cdf0e10cSrcweir // we need just enough to get to the font file data 2862cdf0e10cSrcweir ImplFontSelectData aIFSD( *pFont, Size(0,1000), 1000.0, 0, false ); 2863cdf0e10cSrcweir 2864cdf0e10cSrcweir // TODO: much better solution: move SetFont and restoration of old font to caller 2865cdf0e10cSrcweir ScopedFont aOldFont(*this); 2866cdf0e10cSrcweir SetFont( &aIFSD, 0 ); 2867cdf0e10cSrcweir 2868cdf0e10cSrcweir // get the raw font file data 2869cdf0e10cSrcweir RawFontData aRawFontData( mhDC ); 2870cdf0e10cSrcweir *pDataLen = aRawFontData.size(); 2871cdf0e10cSrcweir if( !aRawFontData.get() ) 2872cdf0e10cSrcweir return NULL; 2873cdf0e10cSrcweir 2874cdf0e10cSrcweir // get important font properties 2875cdf0e10cSrcweir TEXTMETRICA aTm; 2876cdf0e10cSrcweir if( !::GetTextMetricsA( mhDC, &aTm ) ) 2877cdf0e10cSrcweir *pDataLen = 0; 2878cdf0e10cSrcweir const bool bPFA = (*aRawFontData.get() < 0x80); 2879cdf0e10cSrcweir rInfo.m_nFontType = bPFA ? FontSubsetInfo::TYPE1_PFA : FontSubsetInfo::TYPE1_PFB; 2880cdf0e10cSrcweir WCHAR aFaceName[64]; 2881cdf0e10cSrcweir int nFNLen = ::GetTextFaceW( mhDC, 64, aFaceName ); 2882cdf0e10cSrcweir // #i59854# strip eventual null byte 2883cdf0e10cSrcweir while( nFNLen > 0 && aFaceName[nFNLen-1] == 0 ) 2884cdf0e10cSrcweir nFNLen--; 2885cdf0e10cSrcweir if( nFNLen == 0 ) 2886cdf0e10cSrcweir *pDataLen = 0; 2887cdf0e10cSrcweir rInfo.m_aPSName = String( reinterpret_cast<const sal_Unicode*>(aFaceName), sal::static_int_cast<sal_uInt16>(nFNLen) ); 2888cdf0e10cSrcweir rInfo.m_nAscent = +aTm.tmAscent; 2889cdf0e10cSrcweir rInfo.m_nDescent = -aTm.tmDescent; 2890cdf0e10cSrcweir rInfo.m_aFontBBox = Rectangle( Point( -aTm.tmOverhang, -aTm.tmDescent ), 2891cdf0e10cSrcweir Point( aTm.tmMaxCharWidth, aTm.tmAscent+aTm.tmExternalLeading ) ); 2892cdf0e10cSrcweir rInfo.m_nCapHeight = aTm.tmAscent; // Well ... 2893cdf0e10cSrcweir 2894cdf0e10cSrcweir // get individual character widths 2895cdf0e10cSrcweir for( int i = 0; i < 256; ++i ) 2896cdf0e10cSrcweir { 2897cdf0e10cSrcweir int nCharWidth = 0; 2898cdf0e10cSrcweir const sal_Unicode cChar = pUnicodes[i]; 2899cdf0e10cSrcweir if( !::GetCharWidth32W( mhDC, cChar, cChar, &nCharWidth ) ) 2900cdf0e10cSrcweir *pDataLen = 0; 2901cdf0e10cSrcweir pCharWidths[i] = nCharWidth; 2902cdf0e10cSrcweir } 2903cdf0e10cSrcweir 2904cdf0e10cSrcweir if( !*pDataLen ) 2905cdf0e10cSrcweir return NULL; 2906cdf0e10cSrcweir 2907cdf0e10cSrcweir const unsigned char* pData = aRawFontData.steal(); 2908cdf0e10cSrcweir return (void*)pData; 2909cdf0e10cSrcweir } 2910cdf0e10cSrcweir 2911cdf0e10cSrcweir //-------------------------------------------------------------------------- 2912cdf0e10cSrcweir 2913cdf0e10cSrcweir void WinSalGraphics::FreeEmbedFontData( const void* pData, long /*nLen*/ ) 2914cdf0e10cSrcweir { 2915cdf0e10cSrcweir delete[] reinterpret_cast<char*>(const_cast<void*>(pData)); 2916cdf0e10cSrcweir } 2917cdf0e10cSrcweir 2918cdf0e10cSrcweir //-------------------------------------------------------------------------- 2919cdf0e10cSrcweir 2920cdf0e10cSrcweir const Ucs2SIntMap* WinSalGraphics::GetFontEncodingVector( const ImplFontData* pFont, const Ucs2OStrMap** pNonEncoded ) 2921cdf0e10cSrcweir { 2922cdf0e10cSrcweir // TODO: even for builtin fonts we get here... why? 2923cdf0e10cSrcweir if( !pFont->IsEmbeddable() ) 2924cdf0e10cSrcweir return NULL; 2925cdf0e10cSrcweir 2926cdf0e10cSrcweir // fill the encoding vector 2927cdf0e10cSrcweir // currently no nonencoded vector 2928cdf0e10cSrcweir if( pNonEncoded ) 2929cdf0e10cSrcweir *pNonEncoded = NULL; 2930cdf0e10cSrcweir 2931cdf0e10cSrcweir const ImplWinFontData* pWinFontData = static_cast<const ImplWinFontData*>(pFont); 2932cdf0e10cSrcweir const Ucs2SIntMap* pEncoding = pWinFontData->GetEncodingVector(); 2933cdf0e10cSrcweir if( pEncoding == NULL ) 2934cdf0e10cSrcweir { 2935cdf0e10cSrcweir Ucs2SIntMap* pNewEncoding = new Ucs2SIntMap; 2936cdf0e10cSrcweir #if 0 2937cdf0e10cSrcweir // TODO: get correct encoding vector 2938cdf0e10cSrcweir GLYPHSET aGlyphSet; 2939cdf0e10cSrcweir aGlyphSet.cbThis = sizeof(aGlyphSet); 2940cdf0e10cSrcweir DWORD aW = ::GetFontUnicodeRanges( mhDC, &aGlyphSet); 2941cdf0e10cSrcweir #else 2942cdf0e10cSrcweir for( sal_Unicode i = 32; i < 256; ++i ) 2943cdf0e10cSrcweir (*pNewEncoding)[i] = i; 2944cdf0e10cSrcweir #endif 2945cdf0e10cSrcweir pWinFontData->SetEncodingVector( pNewEncoding ); 2946cdf0e10cSrcweir pEncoding = pNewEncoding; 2947cdf0e10cSrcweir } 2948cdf0e10cSrcweir 2949cdf0e10cSrcweir return pEncoding; 2950cdf0e10cSrcweir } 2951cdf0e10cSrcweir 2952cdf0e10cSrcweir //-------------------------------------------------------------------------- 2953cdf0e10cSrcweir 2954cdf0e10cSrcweir void WinSalGraphics::GetGlyphWidths( const ImplFontData* pFont, 2955cdf0e10cSrcweir bool bVertical, 2956cdf0e10cSrcweir Int32Vector& rWidths, 2957cdf0e10cSrcweir Ucs2UIntMap& rUnicodeEnc ) 2958cdf0e10cSrcweir { 2959cdf0e10cSrcweir // create matching ImplFontSelectData 2960cdf0e10cSrcweir // we need just enough to get to the font file data 2961cdf0e10cSrcweir ImplFontSelectData aIFSD( *pFont, Size(0,1000), 1000.0, 0, false ); 2962cdf0e10cSrcweir 2963cdf0e10cSrcweir // TODO: much better solution: move SetFont and restoration of old font to caller 2964cdf0e10cSrcweir ScopedFont aOldFont(*this); 2965cdf0e10cSrcweir 2966cdf0e10cSrcweir float fScale = 0.0; 2967cdf0e10cSrcweir HFONT hOldFont = 0; 2968cdf0e10cSrcweir ImplDoSetFont( &aIFSD, fScale, hOldFont ); 2969cdf0e10cSrcweir 2970cdf0e10cSrcweir if( pFont->IsSubsettable() ) 2971cdf0e10cSrcweir { 2972cdf0e10cSrcweir // get raw font file data 2973cdf0e10cSrcweir const RawFontData xRawFontData( mhDC ); 2974cdf0e10cSrcweir if( !xRawFontData.get() ) 2975cdf0e10cSrcweir return; 2976cdf0e10cSrcweir 2977cdf0e10cSrcweir // open font file 2978cdf0e10cSrcweir sal_uInt32 nFaceNum = 0; 2979cdf0e10cSrcweir if( !*xRawFontData.get() ) // TTC candidate 2980cdf0e10cSrcweir nFaceNum = ~0U; // indicate "TTC font extracts only" 2981cdf0e10cSrcweir 2982cdf0e10cSrcweir ScopedTrueTypeFont aSftTTF; 2983cdf0e10cSrcweir int nRC = aSftTTF.open( (void*)xRawFontData.get(), xRawFontData.size(), nFaceNum ); 2984cdf0e10cSrcweir if( nRC != SF_OK ) 2985cdf0e10cSrcweir return; 2986cdf0e10cSrcweir 2987cdf0e10cSrcweir int nGlyphs = GetTTGlyphCount( aSftTTF.get() ); 2988cdf0e10cSrcweir if( nGlyphs > 0 ) 2989cdf0e10cSrcweir { 2990cdf0e10cSrcweir rWidths.resize(nGlyphs); 2991cdf0e10cSrcweir std::vector<sal_uInt16> aGlyphIds(nGlyphs); 2992cdf0e10cSrcweir for( int i = 0; i < nGlyphs; i++ ) 2993cdf0e10cSrcweir aGlyphIds[i] = sal_uInt16(i); 2994cdf0e10cSrcweir TTSimpleGlyphMetrics* pMetrics = ::GetTTSimpleGlyphMetrics( aSftTTF.get(), 2995cdf0e10cSrcweir &aGlyphIds[0], 2996cdf0e10cSrcweir nGlyphs, 2997cdf0e10cSrcweir bVertical ? 1 : 0 ); 2998cdf0e10cSrcweir if( pMetrics ) 2999cdf0e10cSrcweir { 3000cdf0e10cSrcweir for( int i = 0; i< nGlyphs; i++ ) 3001cdf0e10cSrcweir rWidths[i] = pMetrics[i].adv; 3002cdf0e10cSrcweir free( pMetrics ); 3003cdf0e10cSrcweir rUnicodeEnc.clear(); 3004cdf0e10cSrcweir } 3005cdf0e10cSrcweir const ImplWinFontData* pWinFont = static_cast<const ImplWinFontData*>(pFont); 3006cdf0e10cSrcweir const ImplFontCharMap* pMap = pWinFont->GetImplFontCharMap(); 3007cdf0e10cSrcweir DBG_ASSERT( pMap && pMap->GetCharCount(), "no map" ); 3008cdf0e10cSrcweir pMap->AddReference(); 3009cdf0e10cSrcweir 3010cdf0e10cSrcweir int nCharCount = pMap->GetCharCount(); 3011cdf0e10cSrcweir sal_uInt32 nChar = pMap->GetFirstChar(); 3012cdf0e10cSrcweir for( int i = 0; i < nCharCount; i++ ) 3013cdf0e10cSrcweir { 3014cdf0e10cSrcweir if( nChar < 0x00010000 ) 3015cdf0e10cSrcweir { 3016cdf0e10cSrcweir sal_uInt16 nGlyph = ::MapChar( aSftTTF.get(), 3017cdf0e10cSrcweir static_cast<sal_Ucs>(nChar), 3018cdf0e10cSrcweir bVertical ? 1 : 0 ); 3019cdf0e10cSrcweir if( nGlyph ) 3020cdf0e10cSrcweir rUnicodeEnc[ static_cast<sal_Unicode>(nChar) ] = nGlyph; 3021cdf0e10cSrcweir } 3022cdf0e10cSrcweir nChar = pMap->GetNextChar( nChar ); 3023cdf0e10cSrcweir } 3024cdf0e10cSrcweir 3025cdf0e10cSrcweir pMap->DeReference(); // TODO: and and use a RAII object 3026cdf0e10cSrcweir } 3027cdf0e10cSrcweir } 3028cdf0e10cSrcweir else if( pFont->IsEmbeddable() ) 3029cdf0e10cSrcweir { 3030cdf0e10cSrcweir // get individual character widths 3031cdf0e10cSrcweir rWidths.clear(); 3032cdf0e10cSrcweir rUnicodeEnc.clear(); 3033cdf0e10cSrcweir rWidths.reserve( 224 ); 3034cdf0e10cSrcweir for( sal_Unicode i = 32; i < 256; ++i ) 3035cdf0e10cSrcweir { 3036cdf0e10cSrcweir int nCharWidth = 0; 3037cdf0e10cSrcweir if( ::GetCharWidth32W( mhDC, i, i, &nCharWidth ) ) 3038cdf0e10cSrcweir { 3039cdf0e10cSrcweir rUnicodeEnc[ i ] = rWidths.size(); 3040cdf0e10cSrcweir rWidths.push_back( nCharWidth ); 3041cdf0e10cSrcweir } 3042cdf0e10cSrcweir } 3043cdf0e10cSrcweir } 3044cdf0e10cSrcweir } 3045cdf0e10cSrcweir 3046cdf0e10cSrcweir //-------------------------------------------------------------------------- 3047cdf0e10cSrcweir 3048cdf0e10cSrcweir void WinSalGraphics::DrawServerFontLayout( const ServerFontLayout& ) 3049cdf0e10cSrcweir {} 3050cdf0e10cSrcweir 3051cdf0e10cSrcweir //-------------------------------------------------------------------------- 3052cdf0e10cSrcweir 3053cdf0e10cSrcweir SystemFontData WinSalGraphics::GetSysFontData( int nFallbacklevel ) const 3054cdf0e10cSrcweir { 3055cdf0e10cSrcweir SystemFontData aSysFontData; 3056cdf0e10cSrcweir 3057cdf0e10cSrcweir if (nFallbacklevel >= MAX_FALLBACK) nFallbacklevel = MAX_FALLBACK - 1; 3058cdf0e10cSrcweir if (nFallbacklevel < 0 ) nFallbacklevel = 0; 3059cdf0e10cSrcweir 3060cdf0e10cSrcweir aSysFontData.nSize = sizeof( SystemFontData ); 3061cdf0e10cSrcweir aSysFontData.hFont = mhFonts[nFallbacklevel]; 3062cdf0e10cSrcweir aSysFontData.bFakeBold = false; 3063cdf0e10cSrcweir aSysFontData.bFakeItalic = false; 3064cdf0e10cSrcweir aSysFontData.bAntialias = true; 3065cdf0e10cSrcweir aSysFontData.bVerticalCharacterType = false; 3066cdf0e10cSrcweir 3067cdf0e10cSrcweir OSL_TRACE("\r\n:WinSalGraphics::GetSysFontData(): FontID: %p, Fallback level: %d", 3068cdf0e10cSrcweir aSysFontData.hFont, 3069cdf0e10cSrcweir nFallbacklevel); 3070cdf0e10cSrcweir 3071cdf0e10cSrcweir return aSysFontData; 3072cdf0e10cSrcweir } 3073cdf0e10cSrcweir 3074cdf0e10cSrcweir //-------------------------------------------------------------------------- 3075cdf0e10cSrcweir 3076