1 |
From 4d974b37e75d1c46b9ddbf86bc6f2756014c7c46 Mon Sep 17 00:00:00 2001 |
2 |
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com> |
3 |
Date: Tue, 19 Jul 2011 13:39:34 +0100 |
4 |
Subject: [PATCH] Resolves: rhbz#715549 use fontconfig's detected format when |
5 |
available |
6 |
|
7 |
--- |
8 |
vcl/inc/vcl/fontmanager.hxx | 2 +- |
9 |
vcl/unx/generic/fontmanager/fontconfig.cxx | 12 +++- |
10 |
vcl/unx/generic/fontmanager/fontmanager.cxx | 81 +++++++++++++++++---------- |
11 |
3 files changed, 62 insertions(+), 33 deletions(-) |
12 |
|
13 |
diff --git a/vcl/inc/vcl/fontmanager.hxx b/vcl/inc/vcl/fontmanager.hxx |
14 |
index 410ecf1..816adbe 100644 |
15 |
--- a/vcl/inc/vcl/fontmanager.hxx |
16 |
+++ b/vcl/inc/vcl/fontmanager.hxx |
17 |
@@ -333,7 +333,7 @@ class VCL_PLUGIN_PUBLIC PrintFontManager |
18 |
|
19 |
void getFontAttributesFromXLFD( PrintFont* pFont, const std::list< rtl::OString >& rXLFDs ) const; |
20 |
|
21 |
- bool analyzeFontFile( int nDirID, const rtl::OString& rFileName, const std::list< rtl::OString >& rXLFDs, std::list< PrintFont* >& rNewFonts ) const; |
22 |
+ bool analyzeFontFile( int nDirID, const rtl::OString& rFileName, const std::list< rtl::OString >& rXLFDs, std::list< PrintFont* >& rNewFonts, const char *pFormat=NULL ) const; |
23 |
rtl::OUString convertTrueTypeName( void* pNameRecord ) const; // actually a NameRecord* formt font subsetting code |
24 |
void analyzeTrueTypeFamilyName( void* pTTFont, std::list< rtl::OUString >& rnames ) const; // actually a TrueTypeFont* from font subsetting code |
25 |
bool analyzeTrueTypeFile( PrintFont* pFont ) const; |
26 |
diff --git a/vcl/unx/source/fontmanager/fontconfig.cxx b/vcl/unx/source/fontmanager/fontconfig.cxx |
27 |
index e4b2f00..5e97bec 100644 |
28 |
--- a/vcl/unx/source/fontmanager/fontconfig.cxx |
29 |
+++ b/vcl/unx/source/fontmanager/fontconfig.cxx |
30 |
@@ -59,6 +59,9 @@ |
31 |
#ifndef FC_FT_FACE |
32 |
#define FC_FT_FACE "ftface" |
33 |
#endif |
34 |
+ #ifndef FC_FONTFORMAT |
35 |
+ #define FC_FONTFORMAT "fontformat" |
36 |
+ #endif |
37 |
#ifndef FC_EMBOLDEN |
38 |
#define FC_EMBOLDEN "embolden" |
39 |
#endif |
40 |
@@ -697,6 +700,7 @@ |
41 |
FcChar8* file = NULL; |
42 |
FcChar8* family = NULL; |
43 |
FcChar8* style = NULL; |
44 |
+ FcChar8* format = NULL; |
45 |
int slant = 0; |
46 |
int weight = 0; |
47 |
int spacing = 0; |
48 |
@@ -711,6 +715,7 @@ |
49 |
FcResult eSpacRes = rWrapper.FcPatternGetInteger( pFSet->fonts[i], FC_SPACING, 0, &spacing ); |
50 |
FcResult eOutRes = rWrapper.FcPatternGetBool( pFSet->fonts[i], FC_OUTLINE, 0, &outline ); |
51 |
FcResult eIndexRes = rWrapper.FcPatternGetInteger( pFSet->fonts[i], FC_INDEX, 0, &nCollectionEntry ); |
52 |
+ FcResult eFormatRes = rWrapper.FcPatternGetString(pFSet->fonts[i], FC_FONTFORMAT, 0, &format); |
53 |
|
54 |
if( eFileRes != FcResultMatch || eFamilyRes != FcResultMatch || eOutRes != FcResultMatch ) |
55 |
continue; |
56 |
@@ -718,13 +723,14 @@ |
57 |
#if (OSL_DEBUG_LEVEL > 2) |
58 |
fprintf( stderr, "found font \"%s\" in file %s\n" |
59 |
" weight = %d, slant = %d, style = \"%s\"\n" |
60 |
- " spacing = %d, outline = %d\n" |
61 |
+ " spacing = %d, outline = %d, format %s\n" |
62 |
, family, file |
63 |
, eWeightRes == FcResultMatch ? weight : -1 |
64 |
, eSpacRes == FcResultMatch ? slant : -1 |
65 |
, eStyleRes == FcResultMatch ? (const char*) style : "<nil>" |
66 |
, eSpacRes == FcResultMatch ? spacing : -1 |
67 |
, eOutRes == FcResultMatch ? outline : -1 |
68 |
+ , eFormatRes == FcResultMatch ? (const char*)format : "<unknown>" |
69 |
); |
70 |
#endif |
71 |
|
72 |
@@ -751,7 +757,9 @@ |
73 |
// not known, analyze font file to get attributes |
74 |
// not described by fontconfig (e.g. alias names, PSName) |
75 |
std::list< OString > aDummy; |
76 |
- analyzeFontFile( nDirID, aBase, aDummy, aFonts ); |
77 |
+ if (eFormatRes != FcResultMatch) |
78 |
+ format = NULL; |
79 |
+ analyzeFontFile( nDirID, aBase, aDummy, aFonts, (const char*)format ); |
80 |
#if OSL_DEBUG_LEVEL > 1 |
81 |
if( aFonts.empty() ) |
82 |
fprintf( stderr, "Warning: file \"%s\" is unusable to psprint\n", aOrgPath.getStr() ); |
83 |
diff --git a/vcl/unx/source/fontmanager/fontmanager.cxx b/vcl/unx/source/fontmanager/fontmanager.cxx |
84 |
index 2dceb35..27a2629 100644 |
85 |
--- a/vcl/unx/source/fontmanager/fontmanager.cxx |
86 |
+++ b/vcl/unx/source/fontmanager/fontmanager.cxx |
87 |
@@ -1281,9 +1281,12 @@ int PrintFontManager::addFontFile( const ::rtl::OString& rFileName, int /*nFaceN |
88 |
return nFontId; |
89 |
} |
90 |
|
91 |
-// ------------------------------------------------------------------------- |
92 |
+enum fontFormat |
93 |
+{ |
94 |
+ UNKNOWN, TRUETYPE, CFF, TYPE1, AFM |
95 |
+}; |
96 |
|
97 |
-bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, const ::std::list<OString>& rXLFDs, ::std::list< PrintFontManager::PrintFont* >& rNewFonts ) const |
98 |
+bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, const ::std::list<OString>& rXLFDs, ::std::list< PrintFontManager::PrintFont* >& rNewFonts, const char *pFormat ) const |
99 |
{ |
100 |
rNewFonts.clear(); |
101 |
|
102 |
@@ -1297,8 +1300,32 @@ bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, co |
103 |
if( access( aFullPath.getStr(), R_OK ) ) |
104 |
return false; |
105 |
|
106 |
- ByteString aExt( rFontFile.copy( rFontFile.lastIndexOf( '.' )+1 ) ); |
107 |
- if( aExt.EqualsIgnoreCaseAscii( "pfb" ) || aExt.EqualsIgnoreCaseAscii( "pfa" ) ) |
108 |
+ fontFormat eFormat = UNKNOWN; |
109 |
+ if (pFormat) |
110 |
+ { |
111 |
+ if (!strcmp(pFormat, "TrueType")) |
112 |
+ eFormat = TRUETYPE; |
113 |
+ else if (!strcmp(pFormat, "CFF")) |
114 |
+ eFormat = CFF; |
115 |
+ else if (!strcmp(pFormat, "Type 1")) |
116 |
+ eFormat = TYPE1; |
117 |
+ } |
118 |
+ if (eFormat == UNKNOWN) |
119 |
+ { |
120 |
+ ByteString aExt( rFontFile.copy( rFontFile.lastIndexOf( '.' )+1 ) ); |
121 |
+ if( aExt.EqualsIgnoreCaseAscii( "pfb" ) || aExt.EqualsIgnoreCaseAscii( "pfa" ) ) |
122 |
+ eFormat = TYPE1; |
123 |
+ else if( aExt.EqualsIgnoreCaseAscii( "afm" ) ) |
124 |
+ eFormat = AFM; |
125 |
+ else if( aExt.EqualsIgnoreCaseAscii( "ttf" ) |
126 |
+ || aExt.EqualsIgnoreCaseAscii( "ttc" ) |
127 |
+ || aExt.EqualsIgnoreCaseAscii( "tte" ) ) // #i33947# for Gaiji support |
128 |
+ eFormat = TRUETYPE; |
129 |
+ else if( aExt.EqualsIgnoreCaseAscii( "otf" ) ) // check for TTF- and PS-OpenType too |
130 |
+ eFormat = CFF; |
131 |
+ } |
132 |
+ |
133 |
+ if (eFormat == TYPE1) |
134 |
{ |
135 |
// check for corresponding afm metric |
136 |
// first look for an adjacent file |
137 |
@@ -1352,7 +1379,7 @@ bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, co |
138 |
} |
139 |
} |
140 |
} |
141 |
- else if( aExt.EqualsIgnoreCaseAscii( "afm" ) ) |
142 |
+ else if (eFormat == AFM) |
143 |
{ |
144 |
ByteString aFilePath( aDir ); |
145 |
aFilePath.Append( '/' ); |
146 |
@@ -1365,34 +1392,14 @@ bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, co |
147 |
else |
148 |
delete pFont; |
149 |
} |
150 |
- else if( aExt.EqualsIgnoreCaseAscii( "ttf" ) |
151 |
- || aExt.EqualsIgnoreCaseAscii( "tte" ) // #i33947# for Gaiji support |
152 |
- || aExt.EqualsIgnoreCaseAscii( "otf" ) ) // check for TTF- and PS-OpenType too |
153 |
- { |
154 |
- TrueTypeFontFile* pFont = new TrueTypeFontFile(); |
155 |
- pFont->m_nDirectory = nDirID; |
156 |
- pFont->m_aFontFile = rFontFile; |
157 |
- pFont->m_nCollectionEntry = -1; |
158 |
- |
159 |
- if( rXLFDs.size() ) |
160 |
- getFontAttributesFromXLFD( pFont, rXLFDs ); |
161 |
- // need to read the font anyway to get aliases inside the font file |
162 |
- if( ! analyzeTrueTypeFile( pFont ) ) |
163 |
- { |
164 |
- delete pFont; |
165 |
- pFont = NULL; |
166 |
- } |
167 |
- else |
168 |
- rNewFonts.push_back( pFont ); |
169 |
- } |
170 |
- else if( aExt.EqualsIgnoreCaseAscii( "ttc" ) ) |
171 |
+ else if (eFormat == TRUETYPE || eFormat == CFF) |
172 |
{ |
173 |
// get number of ttc entries |
174 |
int nLength = CountTTCFonts( aFullPath.getStr() ); |
175 |
if( nLength ) |
176 |
{ |
177 |
#if OSL_DEBUG_LEVEL > 1 |
178 |
- fprintf( stderr, "%s contains %d fonts\n", aFullPath.getStr(), nLength ); |
179 |
+ fprintf( stderr, "ttc: %s contains %d fonts\n", aFullPath.getStr(), nLength ); |
180 |
#endif |
181 |
for( int i = 0; i < nLength; i++ ) |
182 |
{ |
183 |
@@ -1411,10 +1418,24 @@ bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, co |
184 |
rNewFonts.push_back( pFont ); |
185 |
} |
186 |
} |
187 |
-#if OSL_DEBUG_LEVEL > 1 |
188 |
else |
189 |
- fprintf( stderr, "CountTTCFonts( \"%s/%s\" ) failed\n", getDirectory(nDirID).getStr(), rFontFile.getStr() ); |
190 |
-#endif |
191 |
+ { |
192 |
+ TrueTypeFontFile* pFont = new TrueTypeFontFile(); |
193 |
+ pFont->m_nDirectory = nDirID; |
194 |
+ pFont->m_aFontFile = rFontFile; |
195 |
+ pFont->m_nCollectionEntry = -1; |
196 |
+ |
197 |
+ if( rXLFDs.size() ) |
198 |
+ getFontAttributesFromXLFD( pFont, rXLFDs ); |
199 |
+ // need to read the font anyway to get aliases inside the font file |
200 |
+ if( ! analyzeTrueTypeFile( pFont ) ) |
201 |
+ { |
202 |
+ delete pFont; |
203 |
+ pFont = NULL; |
204 |
+ } |
205 |
+ else |
206 |
+ rNewFonts.push_back( pFont ); |
207 |
+ } |
208 |
} |
209 |
return ! rNewFonts.empty(); |
210 |
} |
211 |
-- |
212 |
1.7.6 |
213 |
|