Kaydet (Commit) a36dab4a authored tarafından Vladimir Glazounov's avatar Vladimir Glazounov

INTEGRATION: CWS rc2regression01 (1.94.6); FILE MERGED

2003/07/04 11:17:50 hdu 1.94.6.1: #110607# avoid direct FT_*_Size calls
üst 2c56a524
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
* *
* $RCSfile: gcach_ftyp.cxx,v $ * $RCSfile: gcach_ftyp.cxx,v $
* *
* $Revision: 1.96 $ * $Revision: 1.97 $
* last change: $Author: vg $ $Date: 2003-07-02 14:31:59 $ * last change: $Author: vg $ $Date: 2003-07-04 12:51:04 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -97,9 +97,8 @@ ...@@ -97,9 +97,8 @@
// TODO: move file mapping stuff to OSL // TODO: move file mapping stuff to OSL
#if defined(UNX) #if defined(UNX)
#if !defined(MACOSX) && !defined(HPUX) #if !defined(MACOSX) && !defined(HPUX)
// PORTERS: dlfcn is used for code dependend on FT version
#include <dlfcn.h> #include <dlfcn.h>
#else
// PORTERS: dlfcn is used below to determine FT version
#endif #endif
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -121,7 +120,13 @@ ...@@ -121,7 +120,13 @@
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
static FT_Library aLibFT = 0; static FT_Library aLibFT = 0;
// #110607# enable linking with old FT versions
static int nFTVERSION = 0; static int nFTVERSION = 0;
static FT_Error (*pFTNewSize)(FT_Face,FT_Size*);
static FT_Error (*pFTActivateSize)(FT_Size);
static FT_Error (*pFTDoneSize)(FT_Size);
static bool bEnableSizeFT = false;
struct EqStr{ bool operator()(const char* a, const char* b) const { return !strcmp(a,b); } }; struct EqStr{ bool operator()(const char* a, const char* b) const { return !strcmp(a,b); } };
typedef ::std::hash_map<const char*,FtFontFile*,::std::hash<const char*>, EqStr> FontFileList; typedef ::std::hash_map<const char*,FtFontFile*,::std::hash<const char*>, EqStr> FontFileList;
...@@ -187,15 +192,15 @@ bool FtFontFile::Map() ...@@ -187,15 +192,15 @@ bool FtFontFile::Map()
mmap( NULL, mnFileSize, PROT_READ, MAP_SHARED, nFile, 0 ); mmap( NULL, mnFileSize, PROT_READ, MAP_SHARED, nFile, 0 );
close( nFile ); close( nFile );
#elif defined(WIN32) #elif defined(WIN32)
void* pFileDesc = CreateFile( pFileName, GENERIC_READ, FILE_SHARE_READ, void* pFileDesc = ::CreateFile( pFileName, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ); NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
if( pFileDesc == INVALID_HANDLE_VALUE) if( pFileDesc == INVALID_HANDLE_VALUE)
return false; return false;
mnFileSize = GetFileSize( pFileDesc, NULL ); mnFileSize = ::GetFileSize( pFileDesc, NULL );
HANDLE aHandle = ::CreateFileMapping( pFileDesc, NULL, PAGE_READONLY, 0, mnFileSize, "TTF" ); HANDLE aHandle = ::CreateFileMapping( pFileDesc, NULL, PAGE_READONLY, 0, mnFileSize, "TTF" );
mpFileMap = (const unsigned char*)::MapViewOfFile( aHandle, FILE_MAP_READ, 0, 0, mnFileSize ); mpFileMap = (const unsigned char*)::MapViewOfFile( aHandle, FILE_MAP_READ, 0, 0, mnFileSize );
CloseHandle( pFileDesc ); ::CloseHandle( pFileDesc );
#else #else
FILE* pFile = fopen( pFileName, "rb" ); FILE* pFile = fopen( pFileName, "rb" );
if( !pFile ) if( !pFile )
...@@ -295,8 +300,11 @@ FtFontInfo::FtFontInfo( const ImplFontData& rFontData, ...@@ -295,8 +300,11 @@ FtFontInfo::FtFontInfo( const ImplFontData& rFontData,
FT_FaceRec_* FtFontInfo::GetFaceFT() FT_FaceRec_* FtFontInfo::GetFaceFT()
{ {
if( !maFaceFT && mpFontFile->Map() ) // get faceFT once/multiple depending on SizeFT availability
if( (mnRefCount++ <= 0) || !bEnableSizeFT )
{ {
if( !mpFontFile->Map() )
return NULL;
FT_Error rc = FT_New_Memory_Face( aLibFT, FT_Error rc = FT_New_Memory_Face( aLibFT,
(FT_Byte*)mpFontFile->GetBuffer(), (FT_Byte*)mpFontFile->GetBuffer(),
mpFontFile->GetFileSize(), mnFaceNum, &maFaceFT ); mpFontFile->GetFileSize(), mnFaceNum, &maFaceFT );
...@@ -304,17 +312,17 @@ FT_FaceRec_* FtFontInfo::GetFaceFT() ...@@ -304,17 +312,17 @@ FT_FaceRec_* FtFontInfo::GetFaceFT()
maFaceFT = NULL; maFaceFT = NULL;
} }
++mnRefCount;
return maFaceFT; return maFaceFT;
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
void FtFontInfo::ReleaseFaceFT() void FtFontInfo::ReleaseFaceFT( FT_FaceRec_* pFaceFT )
{ {
if( --mnRefCount <= 0 ) // release last/each depending on SizeFT availability
if( (--mnRefCount <= 0) || !bEnableSizeFT )
{ {
FT_Done_Face( maFaceFT ); FT_Done_Face( pFaceFT );
maFaceFT = NULL; maFaceFT = NULL;
mpFontFile->Unmap(); mpFontFile->Unmap();
} }
...@@ -371,28 +379,35 @@ FreetypeManager::FreetypeManager() ...@@ -371,28 +379,35 @@ FreetypeManager::FreetypeManager()
{ {
FT_Error rcFT = FT_Init_FreeType( &aLibFT ); FT_Error rcFT = FT_Init_FreeType( &aLibFT );
#ifdef RTLD_DEFAULT #ifdef RTLD_DEFAULT // true if a good dlfcn.h header was included
// Get version of freetype library to enable workarounds. // Get version of freetype library to enable workarounds.
// Freetype <= 2.0.9 does not have FT_Library_Version(). // Freetype <= 2.0.9 does not have FT_Library_Version().
// Using dl_sym() instead of osl_getSymbol() because latter // Using dl_sym() instead of osl_getSymbol() because latter
// doesn't work for oslModule=NULL // isn't designed to work with oslModule=NULL
void (*pft_library_version)(FT_Library library, void (*pFTLibraryVersion)(FT_Library library,
FT_Int *amajor, FT_Int *aminor, FT_Int *apatch); FT_Int *amajor, FT_Int *aminor, FT_Int *apatch);
pft_library_version = (void (*)(FT_Library library, pFTLibraryVersion = (void (*)(FT_Library library,
FT_Int *amajor, FT_Int *aminor, FT_Int *apatch)) dlsym (RTLD_DEFAULT, "FT_Library_Version"); FT_Int *amajor, FT_Int *aminor, FT_Int *apatch)) dlsym( RTLD_DEFAULT, "FT_Library_Version" );
pFTNewSize = (FT_Error(*)(FT_Face,FT_Size*)) dlsym( RTLD_DEFAULT, "FT_New_Size" );
pFTActivateSize = (FT_Error(*)(FT_Size)) dlsym( RTLD_DEFAULT, "FT_Activate_Size" );
pFTDoneSize = (FT_Error(*)(FT_Size)) dlsym( RTLD_DEFAULT, "FT_Done_Size" );
bEnableSizeFT = (pFTNewSize!=NULL) && (pFTActivateSize!=NULL) && (pFTDoneSize!=NULL);
FT_Int nMajor = 0, nMinor = 0, nPatch = 0;
if( pFTLibraryVersion )
pFTLibraryVersion( aLibFT, &nMajor, &nMinor, &nPatch );
nFTVERSION = nMajor * 1000 + nMinor * 100 + nPatch;
// disable embedded bitmaps for Freetype-2.1.3 unless explicitly
// requested by env var below because it crashes StarOffice on RH9
// TODO: investigate
if( nFTVERSION == 2103 )
nPrioEmbedded = 0;
if (pft_library_version != NULL)
{
// XXX disable embedded bitmaps for Freetype-2.1.3 unless explicitly requested
// below because it crashes StarOffice on RH9
FT_Int nMajor = 0, nMinor = 0, nPatch = 0;
pft_library_version( aLibFT, &nMajor, &nMinor, &nPatch );
nFTVERSION = nMajor * 1000 + nMinor * 100 + nPatch;
if( nFTVERSION == 2103 )
nPrioEmbedded = 0;
}
#else // RTLD_DEFAULT #else // RTLD_DEFAULT
// assume systems without dlsym use supplied library // assume systems where dlsym is not possible use supplied library
nFTVERSION = FTVERSION; nFTVERSION = FTVERSION;
#endif #endif
...@@ -574,16 +589,16 @@ FreetypeServerFont::FreetypeServerFont( const ImplFontSelectData& rFSD, FtFontIn ...@@ -574,16 +589,16 @@ FreetypeServerFont::FreetypeServerFont( const ImplFontSelectData& rFSD, FtFontIn
maRecodeConverter( NULL ), maRecodeConverter( NULL ),
mpLayoutEngine( NULL ) mpLayoutEngine( NULL )
{ {
maFaceFT = pFI->GetFaceFT();
if( !maFaceFT )
return;
#ifdef HDU_DEBUG #ifdef HDU_DEBUG
fprintf( stderr, "FTSF::FTSF(\"%s\", h=%d, w=%d, cs=%d)\n", fprintf( stderr, "FTSF::FTSF(\"%s\", h=%d, w=%d, cs=%d)\n",
pFI->GetFontFileName()->getStr(), rFSD.mnHeight, rFSD.mnWidth, pFI->GetFontFileName()->getStr(), rFSD.mnHeight, rFSD.mnWidth,
pFI->GetFontData().meCharSet ); pFI->GetFontData().meCharSet );
#endif #endif
maFaceFT = pFI->GetFaceFT();
if( !maFaceFT )
return;
FT_Encoding eEncoding = ft_encoding_unicode; FT_Encoding eEncoding = ft_encoding_unicode;
if( mpFontInfo->GetFontData().meCharSet == RTL_TEXTENCODING_SYMBOL ) if( mpFontInfo->GetFontData().meCharSet == RTL_TEXTENCODING_SYMBOL )
{ {
...@@ -654,8 +669,11 @@ FreetypeServerFont::FreetypeServerFont( const ImplFontSelectData& rFSD, FtFontIn ...@@ -654,8 +669,11 @@ FreetypeServerFont::FreetypeServerFont( const ImplFontSelectData& rFSD, FtFontIn
maRecodeConverter = rtl_createUnicodeToTextConverter( eRecodeFrom ); maRecodeConverter = rtl_createUnicodeToTextConverter( eRecodeFrom );
} }
rc = FT_New_Size( maFaceFT, &maSizeFT ); if( bEnableSizeFT )
rc = FT_Activate_Size( maSizeFT ); {
pFTNewSize( maFaceFT, &maSizeFT );
pFTActivateSize( maSizeFT );
}
mnWidth = rFSD.mnWidth; mnWidth = rFSD.mnWidth;
if( !mnWidth ) if( !mnWidth )
...@@ -699,9 +717,9 @@ FreetypeServerFont::~FreetypeServerFont() ...@@ -699,9 +717,9 @@ FreetypeServerFont::~FreetypeServerFont()
rtl_destroyUnicodeToTextConverter( maRecodeConverter ); rtl_destroyUnicodeToTextConverter( maRecodeConverter );
if( maSizeFT ) if( maSizeFT )
FT_Done_Size( maSizeFT ); pFTDoneSize( maSizeFT );
mpFontInfo->ReleaseFaceFT(); mpFontInfo->ReleaseFaceFT( maFaceFT );
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
...@@ -715,7 +733,8 @@ int FreetypeServerFont::GetEmUnits() const ...@@ -715,7 +733,8 @@ int FreetypeServerFont::GetEmUnits() const
void FreetypeServerFont::FetchFontMetric( ImplFontMetricData& rTo, long& rFactor ) const void FreetypeServerFont::FetchFontMetric( ImplFontMetricData& rTo, long& rFactor ) const
{ {
FT_Activate_Size( maSizeFT ); if( maSizeFT )
pFTActivateSize( maSizeFT );
rFactor = 0x100; rFactor = 0x100;
...@@ -979,7 +998,8 @@ int FreetypeServerFont::GetGlyphIndex( sal_Unicode aChar ) const ...@@ -979,7 +998,8 @@ int FreetypeServerFont::GetGlyphIndex( sal_Unicode aChar ) const
void FreetypeServerFont::InitGlyphData( int nGlyphIndex, GlyphData& rGD ) const void FreetypeServerFont::InitGlyphData( int nGlyphIndex, GlyphData& rGD ) const
{ {
FT_Activate_Size( maSizeFT ); if( maSizeFT )
pFTActivateSize( maSizeFT );
int nGlyphFlags; int nGlyphFlags;
SplitGlyphFlags( *this, nGlyphIndex, nGlyphFlags ); SplitGlyphFlags( *this, nGlyphIndex, nGlyphFlags );
...@@ -1058,7 +1078,8 @@ bool FreetypeServerFont::GetAntialiasAdvice( void ) const ...@@ -1058,7 +1078,8 @@ bool FreetypeServerFont::GetAntialiasAdvice( void ) const
bool FreetypeServerFont::GetGlyphBitmap1( int nGlyphIndex, RawBitmap& rRawBitmap ) const bool FreetypeServerFont::GetGlyphBitmap1( int nGlyphIndex, RawBitmap& rRawBitmap ) const
{ {
FT_Activate_Size( maSizeFT ); if( maSizeFT )
pFTActivateSize( maSizeFT );
int nGlyphFlags; int nGlyphFlags;
SplitGlyphFlags( *this, nGlyphIndex, nGlyphFlags ); SplitGlyphFlags( *this, nGlyphIndex, nGlyphFlags );
...@@ -1152,7 +1173,8 @@ bool FreetypeServerFont::GetGlyphBitmap1( int nGlyphIndex, RawBitmap& rRawBitmap ...@@ -1152,7 +1173,8 @@ bool FreetypeServerFont::GetGlyphBitmap1( int nGlyphIndex, RawBitmap& rRawBitmap
bool FreetypeServerFont::GetGlyphBitmap8( int nGlyphIndex, RawBitmap& rRawBitmap ) const bool FreetypeServerFont::GetGlyphBitmap8( int nGlyphIndex, RawBitmap& rRawBitmap ) const
{ {
FT_Activate_Size( maSizeFT ); if( maSizeFT )
pFTActivateSize( maSizeFT );
int nGlyphFlags; int nGlyphFlags;
SplitGlyphFlags( *this, nGlyphIndex, nGlyphFlags ); SplitGlyphFlags( *this, nGlyphIndex, nGlyphFlags );
...@@ -1382,7 +1404,8 @@ ULONG FreetypeServerFont::GetFontCodeRanges( sal_uInt32* pCodes ) const ...@@ -1382,7 +1404,8 @@ ULONG FreetypeServerFont::GetFontCodeRanges( sal_uInt32* pCodes ) const
int FreetypeServerFont::GetGlyphKernValue( int nGlyphLeft, int nGlyphRight ) const int FreetypeServerFont::GetGlyphKernValue( int nGlyphLeft, int nGlyphRight ) const
{ {
FT_Activate_Size( maSizeFT ); if( maSizeFT )
pFTActivateSize( maSizeFT );
FT_Vector aKernVal; FT_Vector aKernVal;
FT_Error rcFT = FT_Get_Kerning( maFaceFT, nGlyphLeft, nGlyphRight, FT_Error rcFT = FT_Get_Kerning( maFaceFT, nGlyphLeft, nGlyphRight,
...@@ -1395,7 +1418,8 @@ int FreetypeServerFont::GetGlyphKernValue( int nGlyphLeft, int nGlyphRight ) con ...@@ -1395,7 +1418,8 @@ int FreetypeServerFont::GetGlyphKernValue( int nGlyphLeft, int nGlyphRight ) con
ULONG FreetypeServerFont::GetKernPairs( ImplKernPairData** ppKernPairs ) const ULONG FreetypeServerFont::GetKernPairs( ImplKernPairData** ppKernPairs ) const
{ {
FT_Activate_Size( maSizeFT ); if( maSizeFT )
pFTActivateSize( maSizeFT );
*ppKernPairs = NULL; *ppKernPairs = NULL;
if( !FT_HAS_KERNING( maFaceFT ) || !FT_IS_SFNT( maFaceFT ) ) if( !FT_HAS_KERNING( maFaceFT ) || !FT_IS_SFNT( maFaceFT ) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment