Index: inc/salgdi.h =================================================================== RCS file: /cvs/gsl/vcl/aqua/inc/salgdi.h,v retrieving revision 1.28.630.4 diff -u -r1.28.630.4 salgdi.h --- inc/salgdi.h 11 Jul 2007 10:49:31 -0000 1.28.630.4 +++ inc/salgdi.h 17 Jul 2007 06:00:47 -0000 @@ -80,12 +80,15 @@ bool HasChar( sal_uInt32 cChar ) const; void ReadOs2Table() const; + void ReadMacCmapEncoding() const; bool HasCJKSupport() const; private: const ATSUFontID mnFontId; mutable ImplFontCharMap* mpCharMap; mutable bool mbOs2Read; // true if OS2-table related info is valid + mutable bool mbHasOs2Table; + mutable bool mbCmapEncodingRead; // true if cmap encoding of Mac font is read mutable bool mbHasCJKSupport; // #i78970# CJK fonts need extra leading }; Index: source/gdi/salgdi.cxx =================================================================== RCS file: /cvs/gsl/vcl/aqua/source/gdi/salgdi.cxx,v retrieving revision 1.60.262.6 diff -u -r1.60.262.6 salgdi.cxx --- source/gdi/salgdi.cxx 12 Jul 2007 19:47:12 -0000 1.60.262.6 +++ source/gdi/salgdi.cxx 17 Jul 2007 06:00:47 -0000 @@ -95,6 +95,8 @@ , mnFontId( nFontId ) , mpCharMap( NULL ) , mbOs2Read( false ) +, mbHasOs2Table( false ) +, mbCmapEncodingRead( false ) , mbHasCJKSupport( false ) {} @@ -208,6 +210,7 @@ if( eStatus != noErr ) return; DBG_ASSERT( (nBufSize==nRawLength), "ImplMacFontData::ReadOs2Table : ByteCount mismatch!\n"); + mbHasOs2Table = true; // parse the OS/2 raw data // TODO: also analyze panose info, etc. @@ -223,11 +226,65 @@ } } +void ImplMacFontData::ReadMacCmapEncoding( void ) const +{ + // read this only once per font + if( mbCmapEncodingRead ) + return; + mbCmapEncodingRead = true; + + ATSFontRef rFont = FMGetATSFontRefFromFont( mnFontId ); + ByteCount nBufSize = 0; + OSStatus eStatus = ATSFontGetTable( rFont, GetTag("cmap"), 0, 0, NULL, &nBufSize ); + DBG_ASSERT( (eStatus==noErr), "ImplMacFontData::ReadMacCmapEncoding : ATSFontGetTable1 failed!\n"); + if( eStatus != noErr ) + return; + + ByteVector aBuffer; + aBuffer.resize( nBufSize ); + + ByteCount nRawLength = 0; + eStatus = ATSFontGetTable( rFont, GetTag("cmap"), 0, nBufSize, (void*)&aBuffer[0], &nRawLength ); + DBG_ASSERT( (eStatus==noErr), "ImplMacFontData::ReadMacCmapEncoding : ATSFontGetTable2 failed!\n"); + if( eStatus != noErr ) + return; + DBG_ASSERT( (nBufSize==nRawLength), "ImplMacFontData::ReadMacCmapEncoding : ByteCount mismatch!\n"); + + const unsigned char* pCmap = &aBuffer[0]; + + if (nRawLength < 24 ) + return; + if( GetUShort( pCmap ) != 0x0000 ) + return; + + // check if the fonts needs the "CJK extra leading" heuristic + int nSubTables = GetUShort( pCmap + 2 ); + + for( const unsigned char* p = pCmap + 4; --nSubTables >= 0; p += 8 ) + { + int nPlatform = GetUShort( p ); + if( nPlatform == kFontMacintoshPlatform ) { + int nEncoding = GetUShort (p + 2 ); + if( nEncoding == kFontJapaneseScript || + nEncoding == kFontTraditionalChineseScript || + nEncoding == kFontKoreanScript || + nEncoding == kFontSimpleChineseScript ) + { + mbHasCJKSupport = true; + break; + } + } + } +} + // ----------------------------------------------------------------------- bool ImplMacFontData::HasCJKSupport( void ) const { ReadOs2Table(); + if( !mbHasOs2Table ) + ReadMacCmapEncoding(); + return mbHasCJKSupport; }