|
|
6423da3 |
From 4d974b37e75d1c46b9ddbf86bc6f2756014c7c46 Mon Sep 17 00:00:00 2001
|
|
|
6423da3 |
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
|
|
|
6423da3 |
Date: Tue, 19 Jul 2011 13:39:34 +0100
|
|
|
6423da3 |
Subject: [PATCH] Resolves: rhbz#715549 use fontconfig's detected format when
|
|
|
6423da3 |
available
|
|
|
6423da3 |
|
|
|
6423da3 |
---
|
|
|
6423da3 |
vcl/inc/vcl/fontmanager.hxx | 2 +-
|
|
|
6423da3 |
vcl/unx/generic/fontmanager/fontconfig.cxx | 12 +++-
|
|
|
6423da3 |
vcl/unx/generic/fontmanager/fontmanager.cxx | 81 +++++++++++++++++----------
|
|
|
6423da3 |
3 files changed, 62 insertions(+), 33 deletions(-)
|
|
|
6423da3 |
|
|
|
6423da3 |
diff --git a/vcl/inc/vcl/fontmanager.hxx b/vcl/inc/vcl/fontmanager.hxx
|
|
|
6423da3 |
index 410ecf1..816adbe 100644
|
|
|
6423da3 |
--- a/vcl/inc/vcl/fontmanager.hxx
|
|
|
6423da3 |
+++ b/vcl/inc/vcl/fontmanager.hxx
|
|
|
6423da3 |
@@ -333,7 +333,7 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
|
|
|
6423da3 |
|
|
|
6423da3 |
void getFontAttributesFromXLFD( PrintFont* pFont, const std::list< rtl::OString >& rXLFDs ) const;
|
|
|
6423da3 |
|
|
|
6423da3 |
- bool analyzeFontFile( int nDirID, const rtl::OString& rFileName, const std::list< rtl::OString >& rXLFDs, std::list< PrintFont* >& rNewFonts ) const;
|
|
|
6423da3 |
+ bool analyzeFontFile( int nDirID, const rtl::OString& rFileName, const std::list< rtl::OString >& rXLFDs, std::list< PrintFont* >& rNewFonts, const char *pFormat=NULL ) const;
|
|
|
6423da3 |
rtl::OUString convertTrueTypeName( void* pNameRecord ) const; // actually a NameRecord* formt font subsetting code
|
|
|
6423da3 |
void analyzeTrueTypeFamilyName( void* pTTFont, std::list< rtl::OUString >& rnames ) const; // actually a TrueTypeFont* from font subsetting code
|
|
|
6423da3 |
bool analyzeTrueTypeFile( PrintFont* pFont ) const;
|
|
|
da058f6 |
diff --git a/vcl/unx/source/fontmanager/fontconfig.cxx b/vcl/unx/source/fontmanager/fontconfig.cxx
|
|
|
6423da3 |
index e4b2f00..5e97bec 100644
|
|
|
da058f6 |
--- a/vcl/unx/source/fontmanager/fontconfig.cxx
|
|
|
da058f6 |
+++ b/vcl/unx/source/fontmanager/fontconfig.cxx
|
|
|
de1a1c2 |
@@ -68,6 +68,9 @@
|
|
|
de1a1c2 |
#ifndef FC_EMBOLDEN
|
|
|
de1a1c2 |
#define FC_EMBOLDEN "embolden"
|
|
|
da058f6 |
#endif
|
|
|
da058f6 |
+ #ifndef FC_FONTFORMAT
|
|
|
da058f6 |
+ #define FC_FONTFORMAT "fontformat"
|
|
|
da058f6 |
+ #endif
|
|
|
de1a1c2 |
#else
|
|
|
de1a1c2 |
typedef void FcConfig;
|
|
|
de1a1c2 |
typedef void FcObjectSet;
|
|
|
de1a1c2 |
@@ -842,6 +845,7 @@
|
|
|
6423da3 |
FcChar8* file = NULL;
|
|
|
6423da3 |
FcChar8* family = NULL;
|
|
|
6423da3 |
FcChar8* style = NULL;
|
|
|
6423da3 |
+ FcChar8* format = NULL;
|
|
|
6423da3 |
int slant = 0;
|
|
|
6423da3 |
int weight = 0;
|
|
|
6423da3 |
int spacing = 0;
|
|
|
de1a1c2 |
@@ -856,6 +860,7 @@
|
|
|
da058f6 |
FcResult eSpacRes = rWrapper.FcPatternGetInteger( pFSet->fonts[i], FC_SPACING, 0, &spacing );
|
|
|
da058f6 |
FcResult eOutRes = rWrapper.FcPatternGetBool( pFSet->fonts[i], FC_OUTLINE, 0, &outline );
|
|
|
da058f6 |
FcResult eIndexRes = rWrapper.FcPatternGetInteger( pFSet->fonts[i], FC_INDEX, 0, &nCollectionEntry );
|
|
|
da058f6 |
+ FcResult eFormatRes = rWrapper.FcPatternGetString(pFSet->fonts[i], FC_FONTFORMAT, 0, &format);
|
|
|
da058f6 |
|
|
|
6423da3 |
if( eFileRes != FcResultMatch || eFamilyRes != FcResultMatch || eOutRes != FcResultMatch )
|
|
|
6423da3 |
continue;
|
|
|
de1a1c2 |
@@ -863,13 +868,14 @@
|
|
|
6423da3 |
#if (OSL_DEBUG_LEVEL > 2)
|
|
|
6423da3 |
fprintf( stderr, "found font \"%s\" in file %s\n"
|
|
|
6423da3 |
" weight = %d, slant = %d, style = \"%s\"\n"
|
|
|
6423da3 |
- " spacing = %d, outline = %d\n"
|
|
|
6423da3 |
+ " spacing = %d, outline = %d, format %s\n"
|
|
|
6423da3 |
, family, file
|
|
|
6423da3 |
, eWeightRes == FcResultMatch ? weight : -1
|
|
|
6423da3 |
, eSpacRes == FcResultMatch ? slant : -1
|
|
|
6423da3 |
, eStyleRes == FcResultMatch ? (const char*) style : "<nil>"
|
|
|
6423da3 |
, eSpacRes == FcResultMatch ? spacing : -1
|
|
|
6423da3 |
, eOutRes == FcResultMatch ? outline : -1
|
|
|
6423da3 |
+ , eFormatRes == FcResultMatch ? (const char*)format : "<unknown>"
|
|
|
6423da3 |
);
|
|
|
6423da3 |
#endif
|
|
|
6423da3 |
|
|
|
de1a1c2 |
@@ -904,7 +910,9 @@
|
|
|
6423da3 |
// not known, analyze font file to get attributes
|
|
|
6423da3 |
// not described by fontconfig (e.g. alias names, PSName)
|
|
|
6423da3 |
std::list< OString > aDummy;
|
|
|
6423da3 |
- analyzeFontFile( nDirID, aBase, aDummy, aFonts );
|
|
|
6423da3 |
+ if (eFormatRes != FcResultMatch)
|
|
|
6423da3 |
+ format = NULL;
|
|
|
6423da3 |
+ analyzeFontFile( nDirID, aBase, aDummy, aFonts, (const char*)format );
|
|
|
6423da3 |
#if OSL_DEBUG_LEVEL > 1
|
|
|
6423da3 |
if( aFonts.empty() )
|
|
|
6423da3 |
fprintf( stderr, "Warning: file \"%s\" is unusable to psprint\n", aOrgPath.getStr() );
|
|
|
da058f6 |
diff --git a/vcl/unx/source/fontmanager/fontmanager.cxx b/vcl/unx/source/fontmanager/fontmanager.cxx
|
|
|
6423da3 |
index 2dceb35..27a2629 100644
|
|
|
da058f6 |
--- a/vcl/unx/source/fontmanager/fontmanager.cxx
|
|
|
da058f6 |
+++ b/vcl/unx/source/fontmanager/fontmanager.cxx
|
|
|
6423da3 |
@@ -1281,9 +1281,12 @@ int PrintFontManager::addFontFile( const ::rtl::OString& rFileName, int /*nFaceN
|
|
|
6423da3 |
return nFontId;
|
|
|
6423da3 |
}
|
|
|
6423da3 |
|
|
|
6423da3 |
-// -------------------------------------------------------------------------
|
|
|
6423da3 |
+enum fontFormat
|
|
|
6423da3 |
+{
|
|
|
6423da3 |
+ UNKNOWN, TRUETYPE, CFF, TYPE1, AFM
|
|
|
6423da3 |
+};
|
|
|
6423da3 |
|
|
|
6423da3 |
-bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, const ::std::list<OString>& rXLFDs, ::std::list< PrintFontManager::PrintFont* >& rNewFonts ) const
|
|
|
6423da3 |
+bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, const ::std::list<OString>& rXLFDs, ::std::list< PrintFontManager::PrintFont* >& rNewFonts, const char *pFormat ) const
|
|
|
6423da3 |
{
|
|
|
6423da3 |
rNewFonts.clear();
|
|
|
6423da3 |
|
|
|
6423da3 |
@@ -1297,8 +1300,32 @@ bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, co
|
|
|
6423da3 |
if( access( aFullPath.getStr(), R_OK ) )
|
|
|
6423da3 |
return false;
|
|
|
6423da3 |
|
|
|
6423da3 |
- ByteString aExt( rFontFile.copy( rFontFile.lastIndexOf( '.' )+1 ) );
|
|
|
6423da3 |
- if( aExt.EqualsIgnoreCaseAscii( "pfb" ) || aExt.EqualsIgnoreCaseAscii( "pfa" ) )
|
|
|
6423da3 |
+ fontFormat eFormat = UNKNOWN;
|
|
|
6423da3 |
+ if (pFormat)
|
|
|
6423da3 |
+ {
|
|
|
6423da3 |
+ if (!strcmp(pFormat, "TrueType"))
|
|
|
6423da3 |
+ eFormat = TRUETYPE;
|
|
|
6423da3 |
+ else if (!strcmp(pFormat, "CFF"))
|
|
|
6423da3 |
+ eFormat = CFF;
|
|
|
6423da3 |
+ else if (!strcmp(pFormat, "Type 1"))
|
|
|
6423da3 |
+ eFormat = TYPE1;
|
|
|
6423da3 |
+ }
|
|
|
6423da3 |
+ if (eFormat == UNKNOWN)
|
|
|
6423da3 |
+ {
|
|
|
6423da3 |
+ ByteString aExt( rFontFile.copy( rFontFile.lastIndexOf( '.' )+1 ) );
|
|
|
6423da3 |
+ if( aExt.EqualsIgnoreCaseAscii( "pfb" ) || aExt.EqualsIgnoreCaseAscii( "pfa" ) )
|
|
|
6423da3 |
+ eFormat = TYPE1;
|
|
|
6423da3 |
+ else if( aExt.EqualsIgnoreCaseAscii( "afm" ) )
|
|
|
6423da3 |
+ eFormat = AFM;
|
|
|
6423da3 |
+ else if( aExt.EqualsIgnoreCaseAscii( "ttf" )
|
|
|
6423da3 |
+ || aExt.EqualsIgnoreCaseAscii( "ttc" )
|
|
|
6423da3 |
+ || aExt.EqualsIgnoreCaseAscii( "tte" ) ) // #i33947# for Gaiji support
|
|
|
6423da3 |
+ eFormat = TRUETYPE;
|
|
|
6423da3 |
+ else if( aExt.EqualsIgnoreCaseAscii( "otf" ) ) // check for TTF- and PS-OpenType too
|
|
|
6423da3 |
+ eFormat = CFF;
|
|
|
6423da3 |
+ }
|
|
|
6423da3 |
+
|
|
|
6423da3 |
+ if (eFormat == TYPE1)
|
|
|
6423da3 |
{
|
|
|
6423da3 |
// check for corresponding afm metric
|
|
|
6423da3 |
// first look for an adjacent file
|
|
|
6423da3 |
@@ -1352,7 +1379,7 @@ bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, co
|
|
|
6423da3 |
}
|
|
|
6423da3 |
}
|
|
|
6423da3 |
}
|
|
|
6423da3 |
- else if( aExt.EqualsIgnoreCaseAscii( "afm" ) )
|
|
|
6423da3 |
+ else if (eFormat == AFM)
|
|
|
6423da3 |
{
|
|
|
6423da3 |
ByteString aFilePath( aDir );
|
|
|
6423da3 |
aFilePath.Append( '/' );
|
|
|
6423da3 |
@@ -1365,34 +1392,14 @@ bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, co
|
|
|
6423da3 |
else
|
|
|
6423da3 |
delete pFont;
|
|
|
6423da3 |
}
|
|
|
6423da3 |
- else if( aExt.EqualsIgnoreCaseAscii( "ttf" )
|
|
|
6423da3 |
- || aExt.EqualsIgnoreCaseAscii( "tte" ) // #i33947# for Gaiji support
|
|
|
6423da3 |
- || aExt.EqualsIgnoreCaseAscii( "otf" ) ) // check for TTF- and PS-OpenType too
|
|
|
6423da3 |
- {
|
|
|
6423da3 |
- TrueTypeFontFile* pFont = new TrueTypeFontFile();
|
|
|
6423da3 |
- pFont->m_nDirectory = nDirID;
|
|
|
6423da3 |
- pFont->m_aFontFile = rFontFile;
|
|
|
6423da3 |
- pFont->m_nCollectionEntry = -1;
|
|
|
6423da3 |
-
|
|
|
6423da3 |
- if( rXLFDs.size() )
|
|
|
6423da3 |
- getFontAttributesFromXLFD( pFont, rXLFDs );
|
|
|
6423da3 |
- // need to read the font anyway to get aliases inside the font file
|
|
|
6423da3 |
- if( ! analyzeTrueTypeFile( pFont ) )
|
|
|
6423da3 |
- {
|
|
|
6423da3 |
- delete pFont;
|
|
|
6423da3 |
- pFont = NULL;
|
|
|
6423da3 |
- }
|
|
|
6423da3 |
- else
|
|
|
6423da3 |
- rNewFonts.push_back( pFont );
|
|
|
6423da3 |
- }
|
|
|
6423da3 |
- else if( aExt.EqualsIgnoreCaseAscii( "ttc" ) )
|
|
|
6423da3 |
+ else if (eFormat == TRUETYPE || eFormat == CFF)
|
|
|
6423da3 |
{
|
|
|
6423da3 |
// get number of ttc entries
|
|
|
6423da3 |
int nLength = CountTTCFonts( aFullPath.getStr() );
|
|
|
6423da3 |
if( nLength )
|
|
|
6423da3 |
{
|
|
|
6423da3 |
#if OSL_DEBUG_LEVEL > 1
|
|
|
6423da3 |
- fprintf( stderr, "%s contains %d fonts\n", aFullPath.getStr(), nLength );
|
|
|
6423da3 |
+ fprintf( stderr, "ttc: %s contains %d fonts\n", aFullPath.getStr(), nLength );
|
|
|
6423da3 |
#endif
|
|
|
6423da3 |
for( int i = 0; i < nLength; i++ )
|
|
|
6423da3 |
{
|
|
|
6423da3 |
@@ -1411,10 +1418,24 @@ bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, co
|
|
|
6423da3 |
rNewFonts.push_back( pFont );
|
|
|
6423da3 |
}
|
|
|
6423da3 |
}
|
|
|
6423da3 |
-#if OSL_DEBUG_LEVEL > 1
|
|
|
6423da3 |
else
|
|
|
6423da3 |
- fprintf( stderr, "CountTTCFonts( \"%s/%s\" ) failed\n", getDirectory(nDirID).getStr(), rFontFile.getStr() );
|
|
|
6423da3 |
-#endif
|
|
|
6423da3 |
+ {
|
|
|
6423da3 |
+ TrueTypeFontFile* pFont = new TrueTypeFontFile();
|
|
|
6423da3 |
+ pFont->m_nDirectory = nDirID;
|
|
|
6423da3 |
+ pFont->m_aFontFile = rFontFile;
|
|
|
6423da3 |
+ pFont->m_nCollectionEntry = -1;
|
|
|
6423da3 |
+
|
|
|
6423da3 |
+ if( rXLFDs.size() )
|
|
|
6423da3 |
+ getFontAttributesFromXLFD( pFont, rXLFDs );
|
|
|
6423da3 |
+ // need to read the font anyway to get aliases inside the font file
|
|
|
6423da3 |
+ if( ! analyzeTrueTypeFile( pFont ) )
|
|
|
6423da3 |
+ {
|
|
|
6423da3 |
+ delete pFont;
|
|
|
6423da3 |
+ pFont = NULL;
|
|
|
6423da3 |
+ }
|
|
|
6423da3 |
+ else
|
|
|
6423da3 |
+ rNewFonts.push_back( pFont );
|
|
|
6423da3 |
+ }
|
|
|
6423da3 |
}
|
|
|
6423da3 |
return ! rNewFonts.empty();
|
|
|
6423da3 |
}
|
|
|
6423da3 |
--
|
|
|
6423da3 |
1.7.6
|
|
|
6423da3 |
|