Lines 47-56
Link Here
|
47 |
typedef void FcObjectSet; |
47 |
typedef void FcObjectSet; |
48 |
typedef void FcPattern; |
48 |
typedef void FcPattern; |
49 |
typedef void FcFontSet; |
49 |
typedef void FcFontSet; |
|
|
50 |
typedef void FcCharSet; |
50 |
typedef int FcResult; |
51 |
typedef int FcResult; |
51 |
typedef int FcBool; |
52 |
typedef int FcBool; |
52 |
typedef int FcMatchKind; |
53 |
typedef int FcMatchKind; |
53 |
typedef char FcChar8; |
54 |
typedef char FcChar8; |
|
|
55 |
typedef sal_Int32 FcChar32; |
54 |
#endif |
56 |
#endif |
55 |
|
57 |
|
56 |
#include <cstdio> |
58 |
#include <cstdio> |
Lines 74-79
Link Here
|
74 |
#ifndef _RTL_USTRBUF_HXX |
76 |
#ifndef _RTL_USTRBUF_HXX |
75 |
#include <rtl/ustrbuf.hxx> |
77 |
#include <rtl/ustrbuf.hxx> |
76 |
#endif |
78 |
#endif |
|
|
79 |
#ifndef _OSL_PROCESS_H_ |
80 |
#include <osl/process.h> |
81 |
#endif |
82 |
#ifndef _RTL_LOCALE_HXX_ |
83 |
#include <rtl/locale.hxx> |
84 |
#endif |
85 |
#include <utility> |
86 |
#include <algorithm> |
87 |
|
77 |
|
88 |
|
78 |
using namespace psp; |
89 |
using namespace psp; |
79 |
using namespace osl; |
90 |
using namespace osl; |
Lines 83-88
Link Here
|
83 |
{ |
94 |
{ |
84 |
oslModule m_pLib; |
95 |
oslModule m_pLib; |
85 |
FcConfig* m_pDefConfig; |
96 |
FcConfig* m_pDefConfig; |
|
|
97 |
FcFontSet* m_pOutlineSet; |
86 |
|
98 |
|
87 |
FcBool (*m_pFcInit)(); |
99 |
FcBool (*m_pFcInit)(); |
88 |
FcConfig* (*m_pFcConfigGetCurrent)(); |
100 |
FcConfig* (*m_pFcConfigGetCurrent)(); |
Lines 91-108
Link Here
|
91 |
FcPattern* (*m_pFcPatternCreate)(); |
103 |
FcPattern* (*m_pFcPatternCreate)(); |
92 |
void (*m_pFcPatternDestroy)(FcPattern*); |
104 |
void (*m_pFcPatternDestroy)(FcPattern*); |
93 |
FcFontSet* (*m_pFcFontList)(FcConfig*,FcPattern*,FcObjectSet*); |
105 |
FcFontSet* (*m_pFcFontList)(FcConfig*,FcPattern*,FcObjectSet*); |
|
|
106 |
FcFontSet* (*m_pFcConfigGetFonts)(FcConfig*,FcSetName); |
94 |
FcFontSet* (*m_pFcFontSetCreate)(); |
107 |
FcFontSet* (*m_pFcFontSetCreate)(); |
|
|
108 |
FcCharSet* (*m_pFcCharSetCreate)(); |
109 |
FcBool (*m_pFcCharSetAddChar)(FcCharSet *, FcChar32); |
110 |
FcBool (*m_pFcCharSetHasChar)(FcCharSet *, FcChar32); |
111 |
void (*m_pFcCharSetDestroy)(FcCharSet*); |
95 |
void (*m_pFcFontSetDestroy)(FcFontSet*); |
112 |
void (*m_pFcFontSetDestroy)(FcFontSet*); |
96 |
FcBool (*m_pFcFontSetAdd)(FcFontSet*,FcPattern*); |
113 |
FcBool (*m_pFcFontSetAdd)(FcFontSet*,FcPattern*); |
|
|
114 |
void (*m_pFcPatternReference)(FcPattern*); |
115 |
FcResult (*m_pFcPatternGetCharSet)(const FcPattern*,const char*,int,FcCharSet**); |
97 |
FcResult (*m_pFcPatternGetString)(const FcPattern*,const char*,int,FcChar8**); |
116 |
FcResult (*m_pFcPatternGetString)(const FcPattern*,const char*,int,FcChar8**); |
98 |
FcResult (*m_pFcPatternGetInteger)(const FcPattern*,const char*,int,int*); |
117 |
FcResult (*m_pFcPatternGetInteger)(const FcPattern*,const char*,int,int*); |
99 |
FcResult (*m_pFcPatternGetDouble)(const FcPattern*,const char*,int,double*); |
118 |
FcResult (*m_pFcPatternGetDouble)(const FcPattern*,const char*,int,double*); |
100 |
FcResult (*m_pFcPatternGetBool)(const FcPattern*,const char*,int,FcBool*); |
119 |
FcResult (*m_pFcPatternGetBool)(const FcPattern*,const char*,int,FcBool*); |
101 |
void (*m_pFcDefaultSubstitute)(FcPattern *); |
120 |
void (*m_pFcDefaultSubstitute)(FcPattern *); |
102 |
FcPattern* (*m_pFcFontMatch)(FcConfig*,FcPattern*,FcResult*); |
|
|
103 |
FcPattern* (*m_pFcFontSetMatch)(FcConfig*,FcFontSet**, int, FcPattern*,FcResult*); |
121 |
FcPattern* (*m_pFcFontSetMatch)(FcConfig*,FcFontSet**, int, FcPattern*,FcResult*); |
104 |
FcBool (*m_pFcConfigSubstitute)(FcConfig*,FcPattern*,FcMatchKind); |
122 |
FcBool (*m_pFcConfigSubstitute)(FcConfig*,FcPattern*,FcMatchKind); |
105 |
FcBool (*m_pFcPatternAddInteger)(FcPattern*,const char*,int); |
123 |
FcBool (*m_pFcPatternAddInteger)(FcPattern*,const char*,int); |
|
|
124 |
FcBool (*m_pFcPatternAddBool)(FcPattern*,const char*,FcBool); |
125 |
FcBool (*m_pFcPatternAddCharSet)(FcPattern*,const char*,const FcCharSet*); |
106 |
FcBool (*m_pFcPatternAddString)(FcPattern*,const char*,const FcChar8*); |
126 |
FcBool (*m_pFcPatternAddString)(FcPattern*,const char*,const FcChar8*); |
107 |
|
127 |
|
108 |
oslGenericFunction loadSymbol( const char* ); |
128 |
oslGenericFunction loadSymbol( const char* ); |
Lines 118-123
Link Here
|
118 |
{ return m_pLib != NULL;} |
138 |
{ return m_pLib != NULL;} |
119 |
|
139 |
|
120 |
FcConfig* getDefConfig() { return m_pDefConfig; } |
140 |
FcConfig* getDefConfig() { return m_pDefConfig; } |
|
|
141 |
FcFontSet* getFontSet() { return m_pOutlineSet; } |
121 |
|
142 |
|
122 |
FcBool FcInit() |
143 |
FcBool FcInit() |
123 |
{ return m_pFcInit(); } |
144 |
{ return m_pFcInit(); } |
Lines 147-160
Link Here
|
147 |
|
168 |
|
148 |
FcFontSet* FcFontList( FcConfig* pConfig, FcPattern* pPattern, FcObjectSet* pSet ) |
169 |
FcFontSet* FcFontList( FcConfig* pConfig, FcPattern* pPattern, FcObjectSet* pSet ) |
149 |
{ return m_pFcFontList( pConfig, pPattern, pSet ); } |
170 |
{ return m_pFcFontList( pConfig, pPattern, pSet ); } |
150 |
|
171 |
|
|
|
172 |
FcFontSet* FcConfigGetFonts( FcConfig* pConfig, FcSetName eSet) |
173 |
{ return m_pFcConfigGetFonts( pConfig, eSet ); } |
174 |
|
151 |
FcFontSet* FcFontSetCreate() |
175 |
FcFontSet* FcFontSetCreate() |
152 |
{ return m_pFcFontSetCreate(); } |
176 |
{ return m_pFcFontSetCreate(); } |
|
|
177 |
|
178 |
FcCharSet* FcCharSetCreate() |
179 |
{ return m_pFcCharSetCreate(); } |
180 |
|
181 |
FcBool FcCharSetAddChar(FcCharSet *fcs, FcChar32 ucs4) |
182 |
{ return m_pFcCharSetAddChar(fcs, ucs4); } |
183 |
|
184 |
FcBool FcCharSetHasChar(FcCharSet *fcs, FcChar32 ucs4) |
185 |
{ return m_pFcCharSetHasChar(fcs, ucs4); } |
186 |
|
187 |
void FcCharSetDestroy( FcCharSet* pSet ) |
188 |
{ m_pFcCharSetDestroy( pSet );} |
189 |
|
153 |
void FcFontSetDestroy( FcFontSet* pSet ) |
190 |
void FcFontSetDestroy( FcFontSet* pSet ) |
154 |
{ m_pFcFontSetDestroy( pSet );} |
191 |
{ m_pFcFontSetDestroy( pSet );} |
|
|
192 |
|
155 |
FcBool FcFontSetAdd( FcFontSet* pSet, FcPattern* pPattern ) |
193 |
FcBool FcFontSetAdd( FcFontSet* pSet, FcPattern* pPattern ) |
156 |
{ return m_pFcFontSetAdd( pSet, pPattern ); } |
194 |
{ return m_pFcFontSetAdd( pSet, pPattern ); } |
157 |
|
195 |
|
|
|
196 |
void FcPatternReference( FcPattern* pPattern ) |
197 |
{ m_pFcPatternReference( pPattern ); } |
198 |
|
199 |
FcResult FcPatternGetCharSet( const FcPattern* pPattern, const char* object, int n, FcCharSet** s ) |
200 |
{ return m_pFcPatternGetCharSet( pPattern, object, n, s ); } |
201 |
|
158 |
FcResult FcPatternGetString( const FcPattern* pPattern, const char* object, int n, FcChar8** s ) |
202 |
FcResult FcPatternGetString( const FcPattern* pPattern, const char* object, int n, FcChar8** s ) |
159 |
{ return m_pFcPatternGetString( pPattern, object, n, s ); } |
203 |
{ return m_pFcPatternGetString( pPattern, object, n, s ); } |
160 |
|
204 |
|
Lines 168-175
Link Here
|
168 |
{ return m_pFcPatternGetBool( pPattern, object, n, s ); } |
212 |
{ return m_pFcPatternGetBool( pPattern, object, n, s ); } |
169 |
void FcDefaultSubstitute( FcPattern* pPattern ) |
213 |
void FcDefaultSubstitute( FcPattern* pPattern ) |
170 |
{ m_pFcDefaultSubstitute( pPattern ); } |
214 |
{ m_pFcDefaultSubstitute( pPattern ); } |
171 |
FcPattern* FcFontMatch( FcConfig* pConfig, FcPattern* pPattern, FcResult* pResult ) |
|
|
172 |
{ return m_pFcFontMatch( pConfig, pPattern, pResult ); } |
173 |
FcPattern* FcFontSetMatch( FcConfig* pConfig, FcFontSet **ppFontSet, int nset, FcPattern* pPattern, FcResult* pResult ) |
215 |
FcPattern* FcFontSetMatch( FcConfig* pConfig, FcFontSet **ppFontSet, int nset, FcPattern* pPattern, FcResult* pResult ) |
174 |
{ return m_pFcFontSetMatch ? m_pFcFontSetMatch( pConfig, ppFontSet, nset, pPattern, pResult ) : 0; } |
216 |
{ return m_pFcFontSetMatch ? m_pFcFontSetMatch( pConfig, ppFontSet, nset, pPattern, pResult ) : 0; } |
175 |
FcBool FcConfigSubstitute( FcConfig* pConfig, FcPattern* pPattern, FcMatchKind eKind ) |
217 |
FcBool FcConfigSubstitute( FcConfig* pConfig, FcPattern* pPattern, FcMatchKind eKind ) |
Lines 178-183
Link Here
|
178 |
{ return m_pFcPatternAddInteger( pPattern, pObject, nValue ); } |
220 |
{ return m_pFcPatternAddInteger( pPattern, pObject, nValue ); } |
179 |
FcBool FcPatternAddString( FcPattern* pPattern, const char* pObject, const FcChar8* pString ) |
221 |
FcBool FcPatternAddString( FcPattern* pPattern, const char* pObject, const FcChar8* pString ) |
180 |
{ return m_pFcPatternAddString( pPattern, pObject, pString ); } |
222 |
{ return m_pFcPatternAddString( pPattern, pObject, pString ); } |
|
|
223 |
FcBool FcPatternAddBool( FcPattern* pPattern, const char* pObject, bool nValue ) |
224 |
{ return m_pFcPatternAddBool( pPattern, pObject, nValue ); } |
225 |
FcBool FcPatternAddCharSet(FcPattern* pPattern,const char* pObject,const FcCharSet*pCharSet) |
226 |
{ return m_pFcPatternAddCharSet(pPattern,pObject,pCharSet); } |
181 |
}; |
227 |
}; |
182 |
|
228 |
|
183 |
oslGenericFunction FontCfgWrapper::loadSymbol( const char* pSymbol ) |
229 |
oslGenericFunction FontCfgWrapper::loadSymbol( const char* pSymbol ) |
Lines 192-198
Link Here
|
192 |
|
238 |
|
193 |
FontCfgWrapper::FontCfgWrapper() |
239 |
FontCfgWrapper::FontCfgWrapper() |
194 |
: m_pLib( NULL ), |
240 |
: m_pLib( NULL ), |
195 |
m_pDefConfig( NULL ) |
241 |
m_pDefConfig( NULL ), |
|
|
242 |
m_pOutlineSet( NULL ) |
196 |
{ |
243 |
{ |
197 |
#ifdef ENABLE_FONTCONFIG |
244 |
#ifdef ENABLE_FONTCONFIG |
198 |
OUString aLib( RTL_CONSTASCII_USTRINGPARAM( "libfontconfig.so.1" ) ); |
245 |
OUString aLib( RTL_CONSTASCII_USTRINGPARAM( "libfontconfig.so.1" ) ); |
Lines 226-237
Link Here
|
226 |
loadSymbol( "FcPatternDestroy" ); |
273 |
loadSymbol( "FcPatternDestroy" ); |
227 |
m_pFcFontList = (FcFontSet*(*)(FcConfig*,FcPattern*,FcObjectSet*)) |
274 |
m_pFcFontList = (FcFontSet*(*)(FcConfig*,FcPattern*,FcObjectSet*)) |
228 |
loadSymbol( "FcFontList" ); |
275 |
loadSymbol( "FcFontList" ); |
|
|
276 |
m_pFcConfigGetFonts = (FcFontSet*(*)(FcConfig*,FcSetName)) |
277 |
loadSymbol( "FcConfigGetFonts" ); |
229 |
m_pFcFontSetCreate = (FcFontSet*(*)()) |
278 |
m_pFcFontSetCreate = (FcFontSet*(*)()) |
230 |
loadSymbol( "FcFontSetCreate" ); |
279 |
loadSymbol( "FcFontSetCreate" ); |
|
|
280 |
m_pFcCharSetCreate = (FcCharSet*(*)()) |
281 |
loadSymbol( "FcCharSetCreate" ); |
282 |
m_pFcCharSetAddChar = (FcBool(*)(FcCharSet*, FcChar32)) |
283 |
loadSymbol( "FcCharSetAddChar" ); |
284 |
m_pFcCharSetHasChar = (FcBool(*)(FcCharSet*, FcChar32)) |
285 |
loadSymbol( "FcCharSetHasChar" ); |
286 |
m_pFcCharSetDestroy = (void(*)(FcCharSet*)) |
287 |
loadSymbol( "FcCharSetDestroy" ); |
231 |
m_pFcFontSetDestroy = (void(*)(FcFontSet*)) |
288 |
m_pFcFontSetDestroy = (void(*)(FcFontSet*)) |
232 |
loadSymbol( "FcFontSetDestroy" ); |
289 |
loadSymbol( "FcFontSetDestroy" ); |
233 |
m_pFcFontSetAdd = (FcBool(*)(FcFontSet*,FcPattern*)) |
290 |
m_pFcFontSetAdd = (FcBool(*)(FcFontSet*,FcPattern*)) |
234 |
loadSymbol( "FcFontSetAdd" ); |
291 |
loadSymbol( "FcFontSetAdd" ); |
|
|
292 |
m_pFcPatternReference = (void(*)(FcPattern*)) |
293 |
loadSymbol( "FcPatternReference" ); |
294 |
m_pFcPatternGetCharSet = (FcResult(*)(const FcPattern*,const char*,int,FcCharSet**)) |
295 |
loadSymbol( "FcPatternGetCharSet" ); |
235 |
m_pFcPatternGetString = (FcResult(*)(const FcPattern*,const char*,int,FcChar8**)) |
296 |
m_pFcPatternGetString = (FcResult(*)(const FcPattern*,const char*,int,FcChar8**)) |
236 |
loadSymbol( "FcPatternGetString" ); |
297 |
loadSymbol( "FcPatternGetString" ); |
237 |
m_pFcPatternGetInteger = (FcResult(*)(const FcPattern*,const char*,int,int*)) |
298 |
m_pFcPatternGetInteger = (FcResult(*)(const FcPattern*,const char*,int,int*)) |
Lines 242-255
Link Here
|
242 |
loadSymbol( "FcPatternGetBool" ); |
303 |
loadSymbol( "FcPatternGetBool" ); |
243 |
m_pFcDefaultSubstitute = (void(*)(FcPattern *)) |
304 |
m_pFcDefaultSubstitute = (void(*)(FcPattern *)) |
244 |
loadSymbol( "FcDefaultSubstitute" ); |
305 |
loadSymbol( "FcDefaultSubstitute" ); |
245 |
m_pFcFontMatch = (FcPattern*(*)(FcConfig*,FcPattern*,FcResult*)) |
|
|
246 |
loadSymbol( "FcFontMatch" ); |
247 |
m_pFcFontSetMatch = (FcPattern*(*)(FcConfig*,FcFontSet**,int,FcPattern*,FcResult*)) |
306 |
m_pFcFontSetMatch = (FcPattern*(*)(FcConfig*,FcFontSet**,int,FcPattern*,FcResult*)) |
248 |
loadSymbol( "FcFontSetMatch" ); |
307 |
loadSymbol( "FcFontSetMatch" ); |
249 |
m_pFcConfigSubstitute = (FcBool(*)(FcConfig*,FcPattern*,FcMatchKind)) |
308 |
m_pFcConfigSubstitute = (FcBool(*)(FcConfig*,FcPattern*,FcMatchKind)) |
250 |
loadSymbol( "FcConfigSubstitute" ); |
309 |
loadSymbol( "FcConfigSubstitute" ); |
251 |
m_pFcPatternAddInteger = (FcBool(*)(FcPattern*,const char*,int)) |
310 |
m_pFcPatternAddInteger = (FcBool(*)(FcPattern*,const char*,int)) |
252 |
loadSymbol( "FcPatternAddInteger" ); |
311 |
loadSymbol( "FcPatternAddInteger" ); |
|
|
312 |
m_pFcPatternAddBool = (FcBool(*)(FcPattern*,const char*,FcBool)) |
313 |
loadSymbol( "FcPatternAddBool" ); |
314 |
m_pFcPatternAddCharSet = (FcBool(*)(FcPattern*,const char*,const FcCharSet *)) |
315 |
loadSymbol( "FcPatternAddCharSet" ); |
253 |
m_pFcPatternAddString = (FcBool(*)(FcPattern*,const char*,const FcChar8*)) |
316 |
m_pFcPatternAddString = (FcBool(*)(FcPattern*,const char*,const FcChar8*)) |
254 |
loadSymbol( "FcPatternAddString" ); |
317 |
loadSymbol( "FcPatternAddString" ); |
255 |
|
318 |
|
Lines 261-277
Link Here
|
261 |
m_pFcPatternCreate && |
324 |
m_pFcPatternCreate && |
262 |
m_pFcPatternDestroy && |
325 |
m_pFcPatternDestroy && |
263 |
m_pFcFontList && |
326 |
m_pFcFontList && |
|
|
327 |
m_pFcConfigGetFonts && |
264 |
m_pFcFontSetCreate && |
328 |
m_pFcFontSetCreate && |
|
|
329 |
m_pFcCharSetCreate && |
330 |
m_pFcCharSetAddChar && |
331 |
m_pFcCharSetHasChar && |
332 |
m_pFcCharSetDestroy && |
265 |
m_pFcFontSetDestroy && |
333 |
m_pFcFontSetDestroy && |
266 |
m_pFcFontSetAdd && |
334 |
m_pFcFontSetAdd && |
|
|
335 |
m_pFcPatternReference && |
336 |
m_pFcPatternGetCharSet && |
267 |
m_pFcPatternGetString && |
337 |
m_pFcPatternGetString && |
268 |
m_pFcPatternGetInteger && |
338 |
m_pFcPatternGetInteger && |
269 |
m_pFcPatternGetDouble && |
339 |
m_pFcPatternGetDouble && |
270 |
m_pFcPatternGetBool && |
340 |
m_pFcPatternGetBool && |
271 |
m_pFcDefaultSubstitute && |
341 |
m_pFcDefaultSubstitute && |
272 |
m_pFcFontMatch && |
|
|
273 |
m_pFcConfigSubstitute && |
342 |
m_pFcConfigSubstitute && |
274 |
m_pFcPatternAddInteger && |
343 |
m_pFcPatternAddInteger && |
|
|
344 |
m_pFcPatternAddCharSet && |
345 |
m_pFcPatternAddBool && |
275 |
m_pFcPatternAddString |
346 |
m_pFcPatternAddString |
276 |
) ) |
347 |
) ) |
277 |
{ |
348 |
{ |
Lines 289-298
Link Here
|
289 |
osl_unloadModule( (oslModule)m_pLib ); |
360 |
osl_unloadModule( (oslModule)m_pLib ); |
290 |
m_pLib = NULL; |
361 |
m_pLib = NULL; |
291 |
} |
362 |
} |
|
|
363 |
|
364 |
m_pOutlineSet = FcFontSetCreate(); |
365 |
|
366 |
/* |
367 |
add only acceptable outlined fonts to our config, |
368 |
for future fontconfig use |
369 |
*/ |
370 |
FcFontSet *pOrig = FcConfigGetFonts(NULL, FcSetSystem); |
371 |
|
372 |
if (!pOrig) |
373 |
return; |
374 |
|
375 |
for( int i = 0; i < pOrig->nfont; ++i ) |
376 |
{ |
377 |
FcBool outline = false; |
378 |
FcPattern *pOutlinePattern = pOrig->fonts[i]; |
379 |
FcResult eOutRes = |
380 |
FcPatternGetBool( pOutlinePattern, FC_OUTLINE, 0, &outline ); |
381 |
if (eOutRes == FcResultMatch && !outline) |
382 |
continue; |
383 |
FcPatternReference(pOutlinePattern); |
384 |
FcFontSetAdd(m_pOutlineSet, pOutlinePattern); |
385 |
} |
292 |
} |
386 |
} |
293 |
|
387 |
|
294 |
FontCfgWrapper::~FontCfgWrapper() |
388 |
FontCfgWrapper::~FontCfgWrapper() |
295 |
{ |
389 |
{ |
|
|
390 |
if( m_pOutlineSet ) |
391 |
FcFontSetDestroy( m_pOutlineSet ); |
296 |
if( m_pLib ) |
392 |
if( m_pLib ) |
297 |
osl_unloadModule( (oslModule)m_pLib ); |
393 |
osl_unloadModule( (oslModule)m_pLib ); |
298 |
} |
394 |
} |
Lines 319-324
Link Here
|
319 |
#define FC_EMBEDDED_BITMAP "embeddedbitmap" |
415 |
#define FC_EMBEDDED_BITMAP "embeddedbitmap" |
320 |
#endif |
416 |
#endif |
321 |
|
417 |
|
|
|
418 |
namespace |
419 |
{ |
420 |
typedef std::pair<FcChar8*, FcChar8*> lang_and_family; |
421 |
|
422 |
class localizedsorter |
423 |
{ |
424 |
rtl::OLocale maLoc; |
425 |
public: |
426 |
localizedsorter(rtl_Locale* pLoc) : maLoc(pLoc) {} |
427 |
FcChar8* bestname(const std::vector<lang_and_family> &families); |
428 |
}; |
429 |
|
430 |
FcChar8* localizedsorter::bestname(const std::vector<lang_and_family> &families) |
431 |
{ |
432 |
FcChar8* candidate = families.begin()->second; |
433 |
rtl::OString sLangMatch(rtl::OUStringToOString(maLoc.getLanguage().toAsciiLowerCase(), RTL_TEXTENCODING_UTF8)); |
434 |
rtl::OString sFullMatch = sLangMatch; |
435 |
sFullMatch += OString('-'); |
436 |
sFullMatch += rtl::OUStringToOString(maLoc.getCountry().toAsciiLowerCase(), RTL_TEXTENCODING_UTF8); |
437 |
|
438 |
std::vector<lang_and_family>::const_iterator aEnd = families.end(); |
439 |
bool alreadyclosematch = false; |
440 |
for (std::vector<lang_and_family>::const_iterator aIter = families.begin(); aIter != aEnd; ++aIter) |
441 |
{ |
442 |
const char *pLang = (const char*)aIter->first; |
443 |
//perfect |
444 |
if (strcmp(pLang, sFullMatch.getStr()) == 0) |
445 |
{ |
446 |
candidate = aIter->second; |
447 |
break; |
448 |
} |
449 |
else if ((strcmp(pLang, sLangMatch.getStr()) == 0) && (!alreadyclosematch)) |
450 |
{ |
451 |
candidate = aIter->second; |
452 |
alreadyclosematch = true; |
453 |
} |
454 |
} |
455 |
|
456 |
return candidate; |
457 |
} |
458 |
|
459 |
|
460 |
FcResult lcl_FamilyFromPattern(FontCfgWrapper& rWrapper, FcPattern* pPattern, FcChar8 **family, |
461 |
std::hash_map< rtl::OString, rtl::OString, rtl::OStringHash > &aFontconfigNameToLocalized) |
462 |
{ |
463 |
FcChar8 *origfamily; |
464 |
FcResult eFamilyRes = rWrapper.FcPatternGetString( pPattern, FC_FAMILY, 0, &origfamily ); |
465 |
*family = origfamily; |
466 |
|
467 |
if( eFamilyRes == FcResultMatch) |
468 |
{ |
469 |
FcChar8* familylang = NULL; |
470 |
if (rWrapper.FcPatternGetString( pPattern, FC_FAMILYLANG, 0, &familylang ) == FcResultMatch) |
471 |
{ |
472 |
std::vector< lang_and_family > lang_and_families; |
473 |
lang_and_families.push_back(lang_and_family(familylang, *family)); |
474 |
int k = 1; |
475 |
while (1) |
476 |
{ |
477 |
if (rWrapper.FcPatternGetString( pPattern, FC_FAMILYLANG, k, &familylang ) != FcResultMatch) |
478 |
break; |
479 |
if (rWrapper.FcPatternGetString( pPattern, FC_FAMILY, k, family ) != FcResultMatch) |
480 |
break; |
481 |
lang_and_families.push_back(lang_and_family(familylang, *family)); |
482 |
++k; |
483 |
} |
484 |
|
485 |
//possible to-do, sort by UILocale instead of process locale |
486 |
rtl_Locale* pLoc; |
487 |
osl_getProcessLocale(&pLoc); |
488 |
localizedsorter aSorter(pLoc); |
489 |
*family = aSorter.bestname(lang_and_families); |
490 |
|
491 |
std::vector<lang_and_family>::const_iterator aEnd = lang_and_families.end(); |
492 |
for (std::vector<lang_and_family>::const_iterator aIter = lang_and_families.begin(); aIter != aEnd; ++aIter) |
493 |
{ |
494 |
const char *candidate = (const char*)(aIter->second); |
495 |
if (strcmp(candidate, (const char*)(*family)) != 0) |
496 |
aFontconfigNameToLocalized[OString(candidate)] = OString((const char*)(*family)); |
497 |
} |
498 |
} |
499 |
} |
500 |
|
501 |
return eFamilyRes; |
502 |
} |
503 |
} |
504 |
|
505 |
|
322 |
/* |
506 |
/* |
323 |
* PrintFontManager::initFontconfig |
507 |
* PrintFontManager::initFontconfig |
324 |
*/ |
508 |
*/ |
Lines 331-350
Link Here
|
331 |
if( ! rWrapper.isValid() ) |
505 |
if( ! rWrapper.isValid() ) |
332 |
return false; |
506 |
return false; |
333 |
|
507 |
|
334 |
FcConfig* pConfig = rWrapper.getDefConfig(); |
508 |
FcFontSet* pFSet = rWrapper.getFontSet(); |
335 |
FcObjectSet* pOSet = rWrapper.FcObjectSetBuild( FC_FAMILY, |
|
|
336 |
FC_STYLE, |
337 |
FC_SLANT, |
338 |
FC_WEIGHT, |
339 |
FC_SPACING, |
340 |
FC_FILE, |
341 |
FC_OUTLINE, |
342 |
FC_INDEX, |
343 |
FC_EMBEDDED_BITMAP, |
344 |
FC_ANTIALIAS, |
345 |
(void *) NULL ); |
346 |
FcPattern* pPattern = rWrapper.FcPatternCreate(); |
347 |
FcFontSet* pFSet = rWrapper.FcFontList( pConfig, pPattern, pOSet ); |
348 |
|
509 |
|
349 |
if( pFSet ) |
510 |
if( pFSet ) |
350 |
{ |
511 |
{ |
Lines 363-369
Link Here
|
363 |
FcBool outline = false, embitmap = true, antialias = true; |
524 |
FcBool outline = false, embitmap = true, antialias = true; |
364 |
|
525 |
|
365 |
FcResult eFileRes = rWrapper.FcPatternGetString( pFSet->fonts[i], FC_FILE, 0, &file ); |
526 |
FcResult eFileRes = rWrapper.FcPatternGetString( pFSet->fonts[i], FC_FILE, 0, &file ); |
366 |
FcResult eFamilyRes = rWrapper.FcPatternGetString( pFSet->fonts[i], FC_FAMILY, 0, &family ); |
527 |
FcResult eFamilyRes = lcl_FamilyFromPattern(rWrapper, pFSet->fonts[i], &family, m_aFontconfigNameToLocalized ); |
367 |
FcResult eStyleRes = rWrapper.FcPatternGetString( pFSet->fonts[i], FC_STYLE, 0, &style ); |
528 |
FcResult eStyleRes = rWrapper.FcPatternGetString( pFSet->fonts[i], FC_STYLE, 0, &style ); |
368 |
FcResult eSlantRes = rWrapper.FcPatternGetInteger( pFSet->fonts[i], FC_SLANT, 0, &slant ); |
529 |
FcResult eSlantRes = rWrapper.FcPatternGetInteger( pFSet->fonts[i], FC_SLANT, 0, &slant ); |
369 |
FcResult eWeightRes = rWrapper.FcPatternGetInteger( pFSet->fonts[i], FC_WEIGHT, 0, &weight ); |
530 |
FcResult eWeightRes = rWrapper.FcPatternGetInteger( pFSet->fonts[i], FC_WEIGHT, 0, &weight ); |
Lines 389-394
Link Here
|
389 |
); |
550 |
); |
390 |
#endif |
551 |
#endif |
391 |
|
552 |
|
|
|
553 |
OSL_ASSERT(eOutRes != FcResultMatch || outline); |
554 |
|
392 |
// only outline fonts are usable to psprint anyway |
555 |
// only outline fonts are usable to psprint anyway |
393 |
if( eOutRes == FcResultMatch && ! outline ) |
556 |
if( eOutRes == FcResultMatch && ! outline ) |
394 |
continue; |
557 |
continue; |
Lines 542-555
Link Here
|
542 |
} |
705 |
} |
543 |
} |
706 |
} |
544 |
|
707 |
|
545 |
// cleanup |
|
|
546 |
if( pPattern ) |
547 |
rWrapper.FcPatternDestroy( pPattern ); |
548 |
if( pFSet ) |
549 |
rWrapper.FcFontSetDestroy( pFSet ); |
550 |
if( pOSet ) |
551 |
rWrapper.FcObjectSetDestroy( pOSet ); |
552 |
|
553 |
// how does one get rid of the config ? |
708 |
// how does one get rid of the config ? |
554 |
#if OSL_DEBUG_LEVEL > 1 |
709 |
#if OSL_DEBUG_LEVEL > 1 |
555 |
fprintf( stderr, "inserted %d fonts from fontconfig\n", nFonts ); |
710 |
fprintf( stderr, "inserted %d fonts from fontconfig\n", nFonts ); |
Lines 563-601
Link Here
|
563 |
FontCfgWrapper::release(); |
718 |
FontCfgWrapper::release(); |
564 |
} |
719 |
} |
565 |
|
720 |
|
566 |
bool PrintFontManager::matchFont( FastPrintFontInfo& rInfo, const com::sun::star::lang::Locale& rLocale ) |
721 |
static void addtopattern(FontCfgWrapper& rWrapper, FcPattern *pPattern, |
|
|
722 |
italic::type eItalic, weight::type eWeight, width::type eWidth, pitch::type ePitch) |
567 |
{ |
723 |
{ |
568 |
#ifdef ENABLE_FONTCONFIG |
724 |
#ifdef ENABLE_FONTCONFIG |
569 |
FontCfgWrapper& rWrapper = FontCfgWrapper::get(); |
725 |
if( eItalic != italic::Unknown ) |
570 |
if( ! rWrapper.isValid() ) |
|
|
571 |
return false; |
572 |
|
573 |
FcConfig* pConfig = rWrapper.getDefConfig(); |
574 |
FcPattern* pPattern = rWrapper.FcPatternCreate(); |
575 |
|
576 |
OString aLangAttrib; |
577 |
// populate pattern with font characteristics |
578 |
if( rLocale.Language.getLength() ) |
579 |
{ |
580 |
OUStringBuffer aLang(6); |
581 |
aLang.append( rLocale.Language ); |
582 |
if( rLocale.Country.getLength() ) |
583 |
{ |
584 |
aLang.append( sal_Unicode('-') ); |
585 |
aLang.append( rLocale.Country ); |
586 |
} |
587 |
aLangAttrib = OUStringToOString( aLang.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ); |
588 |
} |
589 |
if( aLangAttrib.getLength() ) |
590 |
rWrapper.FcPatternAddString( pPattern, FC_LANG, (FcChar8*)aLangAttrib.getStr() ); |
591 |
|
592 |
OString aFamily = OUStringToOString( rInfo.m_aFamilyName, RTL_TEXTENCODING_UTF8 ); |
593 |
if( aFamily.getLength() ) |
594 |
rWrapper.FcPatternAddString( pPattern, FC_FAMILY, (FcChar8*)aFamily.getStr() ); |
595 |
if( rInfo.m_eItalic != italic::Unknown ) |
596 |
{ |
726 |
{ |
597 |
int nSlant = FC_SLANT_ROMAN; |
727 |
int nSlant = FC_SLANT_ROMAN; |
598 |
switch( rInfo.m_eItalic ) |
728 |
switch( eItalic ) |
599 |
{ |
729 |
{ |
600 |
case italic::Italic: nSlant = FC_SLANT_ITALIC;break; |
730 |
case italic::Italic: nSlant = FC_SLANT_ITALIC;break; |
601 |
case italic::Oblique: nSlant = FC_SLANT_OBLIQUE;break; |
731 |
case italic::Oblique: nSlant = FC_SLANT_OBLIQUE;break; |
Lines 604-613
Link Here
|
604 |
} |
734 |
} |
605 |
rWrapper.FcPatternAddInteger( pPattern, FC_SLANT, nSlant ); |
735 |
rWrapper.FcPatternAddInteger( pPattern, FC_SLANT, nSlant ); |
606 |
} |
736 |
} |
607 |
if( rInfo.m_eWeight != weight::Unknown ) |
737 |
if( eWeight != weight::Unknown ) |
608 |
{ |
738 |
{ |
609 |
int nWeight = FC_WEIGHT_NORMAL; |
739 |
int nWeight = FC_WEIGHT_NORMAL; |
610 |
switch( rInfo.m_eWeight ) |
740 |
switch( eWeight ) |
611 |
{ |
741 |
{ |
612 |
case weight::Thin: nWeight = FC_WEIGHT_THIN;break; |
742 |
case weight::Thin: nWeight = FC_WEIGHT_THIN;break; |
613 |
case weight::UltraLight: nWeight = FC_WEIGHT_ULTRALIGHT;break; |
743 |
case weight::UltraLight: nWeight = FC_WEIGHT_ULTRALIGHT;break; |
Lines 624-633
Link Here
|
624 |
} |
754 |
} |
625 |
rWrapper.FcPatternAddInteger( pPattern, FC_WEIGHT, nWeight ); |
755 |
rWrapper.FcPatternAddInteger( pPattern, FC_WEIGHT, nWeight ); |
626 |
} |
756 |
} |
627 |
if( rInfo.m_eWidth != width::Unknown ) |
757 |
if( eWidth != width::Unknown ) |
628 |
{ |
758 |
{ |
629 |
int nWidth = FC_WIDTH_NORMAL; |
759 |
int nWidth = FC_WIDTH_NORMAL; |
630 |
switch( rInfo.m_eWidth ) |
760 |
switch( eWidth ) |
631 |
{ |
761 |
{ |
632 |
case width::UltraCondensed: nWidth = FC_WIDTH_ULTRACONDENSED;break; |
762 |
case width::UltraCondensed: nWidth = FC_WIDTH_ULTRACONDENSED;break; |
633 |
case width::ExtraCondensed: nWidth = FC_WIDTH_EXTRACONDENSED;break; |
763 |
case width::ExtraCondensed: nWidth = FC_WIDTH_EXTRACONDENSED;break; |
Lines 643-652
Link Here
|
643 |
} |
773 |
} |
644 |
rWrapper.FcPatternAddInteger( pPattern, FC_WIDTH, nWidth ); |
774 |
rWrapper.FcPatternAddInteger( pPattern, FC_WIDTH, nWidth ); |
645 |
} |
775 |
} |
646 |
if( rInfo.m_ePitch != pitch::Unknown ) |
776 |
if( ePitch != pitch::Unknown ) |
647 |
{ |
777 |
{ |
648 |
int nSpacing = FC_PROPORTIONAL; |
778 |
int nSpacing = FC_PROPORTIONAL; |
649 |
switch( rInfo.m_ePitch ) |
779 |
switch( ePitch ) |
650 |
{ |
780 |
{ |
651 |
case pitch::Fixed: nSpacing = FC_MONO;break; |
781 |
case pitch::Fixed: nSpacing = FC_MONO;break; |
652 |
case pitch::Variable: nSpacing = FC_PROPORTIONAL;break; |
782 |
case pitch::Variable: nSpacing = FC_PROPORTIONAL;break; |
Lines 654-665
Link Here
|
654 |
break; |
784 |
break; |
655 |
} |
785 |
} |
656 |
rWrapper.FcPatternAddInteger( pPattern, FC_SPACING, nSpacing ); |
786 |
rWrapper.FcPatternAddInteger( pPattern, FC_SPACING, nSpacing ); |
|
|
787 |
if (nSpacing == FC_MONO) |
788 |
rWrapper.FcPatternAddString( pPattern, FC_FAMILY, (FcChar8*)"monospace"); |
657 |
} |
789 |
} |
|
|
790 |
#endif |
791 |
} |
792 |
|
793 |
String PrintFontManager::Substitute(const std::vector<String> &rNames, std::vector<sal_Unicode> &rGlyphs, |
794 |
const ByteString &rLangAttrib, italic::type eItalic, weight::type eWeight, |
795 |
width::type eWidth, pitch::type ePitch) const |
796 |
{ |
797 |
String aName; |
798 |
#ifdef ENABLE_FONTCONFIG |
799 |
FontCfgWrapper& rWrapper = FontCfgWrapper::get(); |
800 |
if( ! rWrapper.isValid() ) |
801 |
return aName; |
802 |
|
803 |
FcFontSet* pSet = NULL; |
804 |
FcPattern* pPattern = rWrapper.FcPatternCreate(); |
805 |
|
806 |
// Prefer scalable fonts |
807 |
rWrapper.FcPatternAddBool( pPattern, FC_SCALABLE, 1 ); |
808 |
|
809 |
std::vector<String>::const_iterator aEnd = rNames.end(); |
810 |
for (std::vector<String>::const_iterator aIter = rNames.begin(); aIter != aEnd; ++aIter) |
811 |
{ |
812 |
OString maTargetName = OUStringToOString(*aIter, RTL_TEXTENCODING_UTF8); |
813 |
rWrapper.FcPatternAddString(pPattern, FC_FAMILY, (FcChar8*)maTargetName.getStr()); |
814 |
break; |
815 |
} |
816 |
|
817 |
if( rLangAttrib.Len() ) |
818 |
rWrapper.FcPatternAddString(pPattern, FC_LANG, (FcChar8*)rLangAttrib.GetBuffer()); |
819 |
|
820 |
// Add required Unicode characters, if any |
821 |
if (! rGlyphs.empty() ) |
822 |
{ |
823 |
FcCharSet *unicodes = rWrapper.FcCharSetCreate(); |
824 |
std::vector<sal_Unicode>::const_iterator aGlyphEnd = rGlyphs.end(); |
825 |
for (std::vector<sal_Unicode>::const_iterator aGlyphIter = rGlyphs.begin(); |
826 |
aGlyphIter != aGlyphEnd; ++aGlyphIter) |
827 |
{ |
828 |
rWrapper.FcCharSetAddChar( unicodes, (FcChar32)*aGlyphIter ); |
829 |
} |
830 |
rWrapper.FcPatternAddCharSet( pPattern, FC_CHARSET, unicodes); |
831 |
rWrapper.FcCharSetDestroy( unicodes ); |
832 |
} |
833 |
|
834 |
addtopattern(rWrapper, pPattern, eItalic, eWeight, eWidth, ePitch); |
835 |
|
836 |
rWrapper.FcConfigSubstitute( NULL, pPattern, FcMatchPattern ); |
837 |
rWrapper.FcDefaultSubstitute( pPattern ); |
838 |
FcResult eResult = FcResultNoMatch; |
839 |
FcFontSet *pFontSet = rWrapper.getFontSet(); |
840 |
FcPattern* pResult = rWrapper.FcFontSetMatch( NULL, &pFontSet, 1, pPattern, &eResult ); |
841 |
rWrapper.FcPatternDestroy( pPattern ); |
842 |
|
843 |
if( pResult ) |
844 |
{ |
845 |
pSet = rWrapper.FcFontSetCreate(); |
846 |
// info: destroying the pSet destroys pResult implicitly |
847 |
// since pResult was "added" to pSet |
848 |
rWrapper.FcFontSetAdd( pSet, pResult ); |
849 |
} |
850 |
|
851 |
if( pSet ) |
852 |
{ |
853 |
if( pSet->nfont > 0 ) |
854 |
{ |
855 |
//extract the closest match |
856 |
FcChar8* family = NULL; |
857 |
FcResult eFileRes = rWrapper.FcPatternGetString( pSet->fonts[0], FC_FAMILY, 0, &family ); |
858 |
|
859 |
if( eFileRes == FcResultMatch ) |
860 |
{ |
861 |
OString sFamily((sal_Char*)family); |
862 |
std::hash_map< rtl::OString, rtl::OString, rtl::OStringHash >::const_iterator aI = m_aFontconfigNameToLocalized.find(sFamily); |
863 |
if (aI != m_aFontconfigNameToLocalized.end()) |
864 |
sFamily = aI->second; |
865 |
aName = String( sFamily.getStr(), RTL_TEXTENCODING_UTF8 ); |
866 |
} |
867 |
|
868 |
if (!rGlyphs.empty() ) |
869 |
{ |
870 |
std::vector<sal_Unicode> aGlyphs; |
871 |
FcCharSet *unicodes; |
872 |
if (rWrapper.FcPatternGetCharSet(pSet->fonts[0], FC_CHARSET, 0, &unicodes) == FcResultMatch) |
873 |
{ |
874 |
std::vector<sal_Unicode>::iterator aGlyphEnd = rGlyphs.end(); |
875 |
for (std::vector<sal_Unicode>::iterator aGlyphIter = rGlyphs.begin(); |
876 |
aGlyphIter != aGlyphEnd; ++aGlyphIter) |
877 |
{ |
878 |
if (rWrapper.FcCharSetHasChar( unicodes, (FcChar32)*aGlyphIter )) |
879 |
aGlyphs.push_back(*aGlyphIter); |
880 |
} |
881 |
} |
882 |
rGlyphs.swap(aGlyphs); |
883 |
} |
884 |
|
885 |
} |
886 |
} |
887 |
rWrapper.FcFontSetDestroy( pSet ); |
888 |
#endif |
889 |
return aName; |
890 |
} |
891 |
|
892 |
bool PrintFontManager::matchFont( FastPrintFontInfo& rInfo, const com::sun::star::lang::Locale& rLocale ) |
893 |
{ |
894 |
#ifdef ENABLE_FONTCONFIG |
895 |
FontCfgWrapper& rWrapper = FontCfgWrapper::get(); |
896 |
if( ! rWrapper.isValid() ) |
897 |
return false; |
898 |
|
899 |
FcConfig* pConfig = rWrapper.getDefConfig(); |
900 |
FcPattern* pPattern = rWrapper.FcPatternCreate(); |
901 |
|
902 |
OString aLangAttrib; |
903 |
// populate pattern with font characteristics |
904 |
if( rLocale.Language.getLength() ) |
905 |
{ |
906 |
OUStringBuffer aLang(6); |
907 |
aLang.append( rLocale.Language ); |
908 |
if( rLocale.Country.getLength() ) |
909 |
{ |
910 |
aLang.append( sal_Unicode('-') ); |
911 |
aLang.append( rLocale.Country ); |
912 |
} |
913 |
aLangAttrib = OUStringToOString( aLang.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ); |
914 |
} |
915 |
if( aLangAttrib.getLength() ) |
916 |
rWrapper.FcPatternAddString( pPattern, FC_LANG, (FcChar8*)aLangAttrib.getStr() ); |
917 |
|
918 |
OString aFamily = OUStringToOString( rInfo.m_aFamilyName, RTL_TEXTENCODING_UTF8 ); |
919 |
if( aFamily.getLength() ) |
920 |
rWrapper.FcPatternAddString( pPattern, FC_FAMILY, (FcChar8*)aFamily.getStr() ); |
921 |
|
922 |
addtopattern(rWrapper, pPattern, rInfo.m_eItalic, rInfo.m_eWeight, rInfo.m_eWidth, rInfo.m_ePitch); |
658 |
|
923 |
|
659 |
rWrapper.FcConfigSubstitute( pConfig, pPattern, FcMatchPattern ); |
924 |
rWrapper.FcConfigSubstitute( pConfig, pPattern, FcMatchPattern ); |
660 |
rWrapper.FcDefaultSubstitute( pPattern ); |
925 |
rWrapper.FcDefaultSubstitute( pPattern ); |
661 |
FcResult eResult = FcResultNoMatch; |
926 |
FcResult eResult = FcResultNoMatch; |
662 |
FcPattern* pResult = rWrapper.FcFontMatch( pConfig, pPattern, &eResult ); |
927 |
FcFontSet *pFontSet = rWrapper.getFontSet(); |
|
|
928 |
FcPattern* pResult = rWrapper.FcFontSetMatch( pConfig, &pFontSet, 1, pPattern, &eResult ); |
663 |
bool bSuccess = false; |
929 |
bool bSuccess = false; |
664 |
if( pResult ) |
930 |
if( pResult ) |
665 |
{ |
931 |
{ |