diff options
author | Herbert Duerr <hdu@openoffice.org> | 2001-03-07 12:02:11 +0000 |
---|---|---|
committer | Herbert Duerr <hdu@openoffice.org> | 2001-03-07 12:02:11 +0000 |
commit | f8a0d17b2b1b5e5eac0c7c9887bc07b1882aa827 (patch) | |
tree | 3a94f6140af7b76f03eaa19a4c526623915878a0 /vcl | |
parent | c90a189318d3598dff68bc9f037ce10efb74fe91 (diff) |
use font mapping in upper layers
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/glyphs/gcach_ftyp.cxx | 139 | ||||
-rw-r--r-- | vcl/source/glyphs/glyphcache.cxx | 32 | ||||
-rw-r--r-- | vcl/unx/source/gdi/salgdi3.cxx | 59 |
3 files changed, 94 insertions, 136 deletions
diff --git a/vcl/source/glyphs/gcach_ftyp.cxx b/vcl/source/glyphs/gcach_ftyp.cxx index 1dcbb249048c..866f6b5ddef2 100644 --- a/vcl/source/glyphs/gcach_ftyp.cxx +++ b/vcl/source/glyphs/gcach_ftyp.cxx @@ -2,8 +2,8 @@ * * $RCSfile: gcach_ftyp.cxx,v $ * - * $Revision: 1.12 $ - * last change: $Author: pl $ $Date: 2001-03-05 10:58:40 $ + * $Revision: 1.13 $ + * last change: $Author: hdu $ $Date: 2001-03-07 13:02:11 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,12 +65,10 @@ #include <bitmap.hxx> #include <bmpacc.hxx> -#include <rtl/ustring> // used only for string=>hashvalue +//#include <rtl/ustring> // used only for string=>hashvalue #include <osl/file.hxx> #include <poly.hxx> -#ifndef NO_FREETYPE_FONTS - #include "freetype/freetype.h" #include "freetype/ftglyph.h" #include "freetype/ftoutln.h" @@ -96,8 +94,7 @@ static FT_Library aLibFT = 0; size_t std::hash<FtFontInfo*>::operator()( const FtFontInfo* pFI ) const { - size_t nHash = ::rtl::OUString( pFI->aFontData.maName ).hashCode(); -//### nHash += ::rtl::OUString( pFI->aFontData.maStyleName ).hashCode(); + size_t nHash = (size_t)pFI; return nHash; } @@ -105,19 +102,7 @@ size_t std::hash<FtFontInfo*>::operator()( const FtFontInfo* pFI ) const bool std::equal_to<FtFontInfo*>::operator()( const FtFontInfo* pA, const FtFontInfo* pB ) const { - if( (pA->aFontData.maName == pB->aFontData.maName) ) - return true; - return false; -} - -// ----------------------------------------------------------------------- - -inline int CalcSimilarity( const FtFontInfo* pA, const FtFontInfo* pB ) -{ - int nSimilarity = 0; - nSimilarity += 3*(pA->aFontData.meItalic == pB->aFontData.meItalic); - nSimilarity += 2*(pA->aFontData.meWeight == pB->aFontData.meWeight); - return nSimilarity; + return (pA == pB); } // ----------------------------------------------------------------------- @@ -151,9 +136,14 @@ void FreetypeManager::AddFontFile( const String& rNormalizedName, ImplFontData& rData = pFontInfo->aFontData; rData = *pData; - rData.mpSysData = SERVERFONT_MAGIC; + rData.mpSysData = pFontInfo; rData.mpNext = NULL; + // using unicode emulation for non-symbol fonts + if( rData.meCharSet != RTL_TEXTENCODING_SYMBOL ) + rData.meCharSet = RTL_TEXTENCODING_UNICODE; + rData.meScript = SCRIPT_DONTKNOW; + maFontList.insert( pFontInfo ); } @@ -197,7 +187,7 @@ long FreetypeManager::AddFontDir( const String& rNormalizedName ) ImplFontData& rData = pFontInfo->aFontData; rData.mpNext = NULL; - rData.mpSysData = SERVERFONT_MAGIC; + rData.mpSysData = pFontInfo; // TODO: prefer unicode names if available // TODO: prefer locale specific names if available? @@ -256,8 +246,8 @@ long FreetypeManager::FetchFontList( ImplDevFontList* pToAdd ) const void FreetypeManager::ClearFontList( ) { - for( FontList::iterator it(maFontList.begin()); it != maFontList.end(); ++it ) - delete *it; + for( FontList::iterator it(maFontList.begin()); it != maFontList.end(); ) + delete *(it++); maFontList.clear(); } @@ -265,40 +255,11 @@ void FreetypeManager::ClearFontList( ) FreetypeServerFont* FreetypeManager::CreateFont( const ImplFontSelectData& rFSD ) { - FtFontInfo aFontInfo; - aFontInfo.aFontData.maStyleName = rFSD.maStyleName; - aFontInfo.aFontData.meWeight = rFSD.meWeight; - aFontInfo.aFontData.meItalic = rFSD.meItalic; - - for( xub_StrLen nBreaker1 = 0, nBreaker2 = 0; nBreaker2 != STRING_LEN; nBreaker1 = nBreaker2 + 1 ) + const FtFontInfo* pFI = (const FtFontInfo*)rFSD.mpFontData->mpSysData; + if( maFontList.find( pFI ) != maFontList.end() ) { - nBreaker2 = rFSD.maName.Search( ';', nBreaker1 ); - if( nBreaker2 == STRING_NOTFOUND ) - nBreaker2 = STRING_LEN; - aFontInfo.aFontData.maName = rFSD.maName.Copy( nBreaker1, nBreaker2-nBreaker1 ); - - // find best match (e.g. only regular available but bold requested) - typedef std::pair<FontList::const_iterator,FontList::const_iterator> CPair; - - const CPair aRange = maFontList.equal_range( &aFontInfo ); - int nBestMatch = 0; - FontList::const_iterator it_best = aRange.first; - for( FontList::const_iterator it = aRange.first; it != aRange.second; ++it ) - { - const int nMatchVal = CalcSimilarity( (*it), &aFontInfo ); - if( nBestMatch < nMatchVal ) - { - nBestMatch = nMatchVal; - it_best = it; - } - } - if( it_best != aRange.second ) - { - FreetypeServerFont* pFont = new FreetypeServerFont( rFSD, **it_best ); - if( pFont->TestFont() ) - return pFont; - delete pFont; - } + FreetypeServerFont* pFont = new FreetypeServerFont( rFSD, *pFI ); + return pFont; } return NULL; @@ -321,8 +282,11 @@ FreetypeServerFont::FreetypeServerFont( const ImplFontSelectData& rFSD, const Ft FT_Encoding eEncoding = ft_encoding_unicode; if( mrFontInfo.aFontData.meCharSet == RTL_TEXTENCODING_SYMBOL ) - // TODO: for FT>=2.0 use "eEncoding = ft_encoding_symbol"; + { + // TODO for FT>=200b8: ft_encoding_symbol + //### TODO: some PS symbol fonts don't map their symbols correctly eEncoding = ft_encoding_none; + } rc = FT_Select_Charmap( maFaceFT, eEncoding ); mnWidth = rFSD.mnWidth; @@ -339,7 +303,7 @@ FreetypeServerFont::FreetypeServerFont( const ImplFontSelectData& rFSD, const Ft if( rFSD.mnOrientation != 0 ) { - mnLoadFlags |= FT_LOAD_NO_HINTING; + mnLoadFlags |= FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; FT_Matrix aMatrix; aMatrix.xx = +nCos; @@ -373,7 +337,7 @@ void FreetypeServerFont::FetchFontMetric( ImplFontMetricData& rTo, long& rFactor rTo.mnAscent = (+rMetrics.ascender + 32) >> 6; // TODO: change +desc to -desc for FT_Version>2.0beta8 rTo.mnDescent = (+rMetrics.descender + 32) >> 6; - rTo.mnLeading = (rMetrics.height - rMetrics.ascender - rMetrics.descender + 32) >> 6; + rTo.mnLeading = ((rMetrics.height + 32) >> 6) - (rTo.mnAscent + rTo.mnDescent); rTo.mnSlant = 0; rTo.maName = mrFontInfo.aFontData.maName; @@ -414,6 +378,50 @@ void FreetypeServerFont::FetchFontMetric( ImplFontMetricData& rTo, long& rFactor // ----------------------------------------------------------------------- +/*### TODO +static int SetVerticalFlags( sal_Unicode nChar ) +{ + if ( (nChar >= 0x1100 && nChar <= 0x11f9) || // Hangul Jamo + (nChar >= 0x3000 && nChar <= 0xfaff) ) // other CJK + { + if( nChar == 0x2010 || nChar == 0x2015 || + nChar == 0x2016 || nChar == 0x2026 || + (nChar >= 0x3008 && nChar <= 0x3017) ) + { + return VCLASS_ROTATE; + } + else if( nChar == 0x3001 || nChar == 0x3002 ) + { + return VCLASS_TRANSFORM1; + } + else if( nChar == 0x3041 || nChar == 0x3043 || + nChar == 0x3045 || nChar == 0x3047 || + nChar == 0x3049 || nChar == 0x3063 || + nChar == 0x3083 || nChar == 0x3085 || + nChar == 0x3087 || nChar == 0x308e || + nChar == 0x30a1 || nChar == 0x30a3 || + nChar == 0x30a5 || nChar == 0x30a7 || + nChar == 0x30a9 || nChar == 0x30c3 || + nChar == 0x30e3 || nChar == 0x30e5 || + nChar == 0x30e7 || nChar == 0x30ee || + nChar == 0x30f5 || nChar == 0x30f6 ) + { + return VCLASS_TRANSFORM2; + } + else if ( nChar == 0x30fc ) + { + return VCLASS_ROTATE_REVERSE; + } + + return VCLASS_CJK; + } + + return VCLASS_ROTATE; +} +*/ + +// ----------------------------------------------------------------------- + int FreetypeServerFont::GetGlyphIndex( sal_Unicode aChar ) const { if( mrFontInfo.aFontData.meCharSet == RTL_TEXTENCODING_SYMBOL ) @@ -434,6 +442,15 @@ int FreetypeServerFont::GetGlyphIndex( sal_Unicode aChar ) const void FreetypeServerFont::InitGlyphData( int nGlyphIndex, GlyphData& rGD ) const { FT_Error rc = FT_Load_Glyph( maFaceFT, nGlyphIndex, mnLoadFlags ); + if( rc != FT_Err_Ok ) + { + // we get here when e.g. a PS font doesn't have a default glyph + rGD.SetCharWidth( 0 ); + rGD.SetDelta( 0, 0 ); + rGD.SetOffset( 0, 0 ); + rGD.SetSize( Size( 0, 0 ) ); + return; + } #if 0 if( GetFontSelData().mbVertical && FT_HAS_VERTICAL(maFaceFT) ) @@ -577,7 +594,6 @@ ULONG FreetypeServerFont::GetKernPairs( ImplKernPairData** ppKernPairs ) const // first figure out which glyph pairs are involved in kerning SFNT_Interface* pSFNT = (SFNT_Interface*) FT_Get_Module_Interface( aLibFT, "sfnt" ); - DBG_ASSERT( (pSFNT!=NULL), "pSFNT==NULL!" ); if( !pSFNT ) return 0; @@ -894,4 +910,3 @@ bool FreetypeServerFont::GetGlyphOutline( int nGlyphIndex, PolyPolygon& rPolyPol // ======================================================================= -#endif // NO_FREETYPE_FONTS diff --git a/vcl/source/glyphs/glyphcache.cxx b/vcl/source/glyphs/glyphcache.cxx index 1a31b90a3055..2a7f25894558 100644 --- a/vcl/source/glyphs/glyphcache.cxx +++ b/vcl/source/glyphs/glyphcache.cxx @@ -2,9 +2,9 @@ * * $RCSfile: glyphcache.cxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: hdu $ $Date: 2001-02-27 18:36:55 $ + * last change: $Author: hdu $ $Date: 2001-03-07 13:02:11 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -90,9 +90,7 @@ GlyphCache::GlyphCache( ULONG _nMaxSize ) pFtManager(NULL), pCurrentGCFont(NULL) { -#ifndef NO_FREETYPE_FONTS pFtManager = new FreetypeManager; -#endif // NO_FREETYPE_FONTS } // ----------------------------------------------------------------------- @@ -102,10 +100,8 @@ GlyphCache::~GlyphCache() // TODO: // for( FontList::iterator it = aFontList.begin(); it != aFontList.end(); ++it ) // delete const_cast<ServerFont*>( it->second ); -#ifndef NO_FREETYPE_FONTS if( pFtManager ) delete pFtManager; -#endif // NO_FREETYPE_FONTS } // ----------------------------------------------------------------------- @@ -113,8 +109,7 @@ GlyphCache::~GlyphCache() inline size_t std::hash<ImplFontSelectData>::operator()( const ImplFontSelectData& rFontSelData ) const { // TODO: does it pay much to improve this hash function? - size_t nHash = ::rtl::OUString( rFontSelData.maName ).hashCode(); - nHash += ::rtl::OUString( rFontSelData.maStyleName ).hashCode(); + size_t nHash = size_t( rFontSelData.mpFontData->mpSysData ); nHash += rFontSelData.mnHeight; nHash += rFontSelData.mnOrientation; nHash += rFontSelData.mbVertical; @@ -125,18 +120,11 @@ inline size_t std::hash<ImplFontSelectData>::operator()( const ImplFontSelectDat bool operator==( const ImplFontSelectData& rA, const ImplFontSelectData& rB ) { - if( (rA.maName == rB.maName) - && (rA.maStyleName == rB.maStyleName) + if( (rA.mpFontData->mpSysData == rB.mpFontData->mpSysData ) && (rA.mnHeight == rB.mnHeight) && ((rA.mnWidth==rB.mnWidth) || (!rA.mnWidth && (rA.mnHeight==rB.mnWidth))) && (rA.mnOrientation == rB.mnOrientation) - && (rA.mbVertical == rB.mbVertical) - && (rA.meWeight == rB.meWeight) - && (rA.meItalic == rB.meItalic) - && (rA.mePitch == rB.mePitch) - && (rA.meCharSet == rB.meCharSet) - && (rA.meFamily == rB.meFamily) - && (rA.meWidthType == rB.meWidthType) ) + && (rA.mbVertical == rB.mbVertical) ) return true; return false; } @@ -167,17 +155,14 @@ void GlyphCache::EnsureInstance( GlyphCachePeer& rPeer, bool bInitFonts ) void GlyphCache::ClearFontPath() { -#ifndef NO_FREETYPE_FONTS if( pFtManager ) pFtManager->ClearFontList(); -#endif // NO_FREETYPE_FONTS } // ----------------------------------------------------------------------- void GlyphCache::AddFontPath( const String& rFontPath ) { -#ifndef NO_FREETYPE_FONTS if( !pFtManager ) return; @@ -191,7 +176,6 @@ void GlyphCache::AddFontPath( const String& rFontPath ) osl::FileBase::normalizePath( rFontPath.Copy( nBreaker1, nBreaker2 ), aNormalizedName ); pFtManager->AddFontDir( aNormalizedName ); } -#endif // NO_FREETYPE_FONTS } // ----------------------------------------------------------------------- @@ -199,10 +183,8 @@ void GlyphCache::AddFontPath( const String& rFontPath ) void GlyphCache::AddFontFile( const String& rNormalizedName, int nFaceNum, int nFontId, const ImplFontData* pFontData ) { -#ifndef NO_FREETYPE_FONTS if( pFtManager ) pFtManager->AddFontFile( rNormalizedName, nFaceNum, nFontId, pFontData ); -#endif // NO_FREETYPE_FONTS } // ----------------------------------------------------------------------- @@ -210,10 +192,8 @@ void GlyphCache::AddFontFile( const String& rNormalizedName, int nFaceNum, long GlyphCache::FetchFontList( ImplDevFontList* pList ) const { long nCount = 0; -#ifndef NO_FREETYPE_FONTS if( pFtManager ) nCount += pFtManager->FetchFontList( pList ); -#endif // NO_FREETYPE_FONTS // nCount += VirtDevServerFont::FetchFontList( pList ); return nCount; } @@ -233,10 +213,8 @@ ServerFont* GlyphCache::CacheFont( const ImplFontSelectData& rFontSelData ) // font not cached yet => create new font item ServerFont* pNew = NULL; // TODO: pNew = VirtDevServerFont::CreateFont( rFontSelData ); -#ifndef NO_FREETYPE_FONTS if( !pNew && pFtManager) pNew = pFtManager->CreateFont( rFontSelData ); -#endif // NO_FREETYPE_FONTS if( pNew ) { diff --git a/vcl/unx/source/gdi/salgdi3.cxx b/vcl/unx/source/gdi/salgdi3.cxx index 8427804a7d36..c4dc2957e6cc 100644 --- a/vcl/unx/source/gdi/salgdi3.cxx +++ b/vcl/unx/source/gdi/salgdi3.cxx @@ -2,9 +2,9 @@ * * $RCSfile: salgdi3.cxx,v $ * - * $Revision: 1.24 $ + * $Revision: 1.25 $ * - * last change: $Author: pl $ $Date: 2001-03-05 10:58:42 $ + * last change: $Author: hdu $ $Date: 2001-03-07 12:59:08 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -543,32 +543,10 @@ SalGraphicsData::SetFont( const ImplFontSelectData *pEntry ) if( pEntry->mpFontData && pEntry->mpFontData->mpSysData ) { #ifdef USE_BUILTIN_RASTERIZER - if( pEntry->mpFontData->mpSysData == SERVERFONT_MAGIC ) - { - // requesting a font provided by builtin rasterizer - mpServerSideFont = GlyphCache::GetInstance().CacheFont( *pEntry ); -#ifdef USE_PSPRINT - if( (m_pPrinterGfx != NULL) && (mpServerSideFont != NULL) ) - { - // we need to notify printergfx of the font change - int nFontId = mpServerSideFont->GetFontId(); - if( nFontId <= 0 ) - { - if( const ::rtl::OString* pOString = mpServerSideFont->GetFontFileName() ) - { - // we have a font file the printfontmanager should know about - ::rtl::OUString aFontFileName = OStringToOUString( *pOString, RTL_TEXTENCODING_UNICODE ); - int nFaceNum = mpServerSideFont->GetFontFaceNumber(); - psp::PrintFontManager& rPSPFontManager = psp::PrintFontManager::get(); - nFontId = rPSPFontManager.addFontFile( aFontFileName, nFaceNum ); - mpServerSideFont->SetFontId( nFontId ); - } - } - m_pPrinterGfx->SetFont( nFontId, pEntry->mnHeight, pEntry->mnWidth, pEntry->mnOrientation ); - } -#endif // USE_PSPRINT + // requesting a font provided by builtin rasterizer + mpServerSideFont = GlyphCache::GetInstance().CacheFont( *pEntry ); + if( mpServerSideFont ) return; - } #endif //USE_BUILTIN_RASTERIZER ExtendedXlfd *pSysFont = (ExtendedXlfd*)pEntry->mpFontData->mpSysData; @@ -1227,34 +1205,21 @@ SalGraphicsData::DrawText( USHORT SalGraphics::SetFont( ImplFontSelectData *pEntry ) { -#if defined(USE_PSPRINT) - if( (maGraphicsData.m_pPrinterGfx != NULL) -#ifdef USE_BUILTIN_RASTERIZER - && ( !pEntry->mpFontData || (pEntry->mpFontData->mpSysData != SERVERFONT_MAGIC) ) -#endif // USE_BUILTIN_RASTERIZER - ) +#ifdef USE_PSPRINT + if( (maGraphicsData.m_pPrinterGfx != NULL) ) { sal_Bool bVertical = pEntry->mbVertical; sal_Int32 nID = pEntry->mpFontData ? (sal_Int32)pEntry->mpFontData->mpSysData : 0; - return maGraphicsData.m_pPrinterGfx->SetFont( - nID, - pEntry->mnHeight, - pEntry->mnWidth, - pEntry->mnOrientation - ); + return maGraphicsData.m_pPrinterGfx->SetFont( nID, + pEntry->mnHeight, pEntry->mnWidth, pEntry->mnOrientation); } else - { #endif - - - maGraphicsData.SetFont( pEntry ); - return _IsPrinter() ? SAL_SETFONT_USEDRAWTEXTARRAY : 0; - -#if defined(USE_PSPRINT) + { + maGraphicsData.SetFont( pEntry ); + return _IsPrinter() ? SAL_SETFONT_USEDRAWTEXTARRAY : 0; } -#endif } // ---------------------------------------------------------------------------- |