View | Details | Raw Unified | Return to issue 54603
Collapse All | Expand All

(-)openoffice.org.orig/psprint/inc/psprint/fontmanager.hxx (+2 lines)
Lines 451-456 Link Here
451
    std::hash_multimap< sal_Unicode, sal_uInt8 >	m_aUnicodeToAdobecode;
451
    std::hash_multimap< sal_Unicode, sal_uInt8 >	m_aUnicodeToAdobecode;
452
    std::hash_multimap< sal_uInt8, sal_Unicode >	m_aAdobecodeToUnicode;
452
    std::hash_multimap< sal_uInt8, sal_Unicode >	m_aAdobecodeToUnicode;
453
453
454
    std::hash_map< rtl::OString, rtl::OString, rtl::OStringHash > m_aFontconfigNameToLocalized;
455
454
    mutable FontCache*							m_pFontCache;
456
    mutable FontCache*							m_pFontCache;
455
    bool m_bFontconfigSuccess;
457
    bool m_bFontconfigSuccess;
456
        
458
        
(-)openoffice.org.orig/psprint/source/fontmanager/fontconfig.cxx (-2 / +96 lines)
Lines 75-80 Link Here
75
#ifndef _RTL_USTRBUF_HXX
75
#ifndef _RTL_USTRBUF_HXX
76
#include <rtl/ustrbuf.hxx>
76
#include <rtl/ustrbuf.hxx>
77
#endif
77
#endif
78
#ifndef _OSL_PROCESS_H_
79
#include <osl/process.h>
80
#endif
81
#ifndef _RTL_LOCALE_HXX_
82
#include <rtl/locale.hxx>
83
#endif
84
#include <utility>
85
#include <algorithm>
86
78
87
79
using namespace psp;
88
using namespace psp;
80
using namespace osl;
89
using namespace osl;
Lines 412-417 Link Here
412
#define FC_EMBEDDED_BITMAP "embeddedbitmap"
421
#define FC_EMBEDDED_BITMAP "embeddedbitmap"
413
#endif
422
#endif
414
423
424
namespace
425
{
426
    typedef std::pair<FcChar8*, FcChar8*> lang_and_family;
427
428
    class localizedsorter
429
    {
430
            rtl::OLocale maLoc;
431
        public:
432
            localizedsorter(rtl_Locale* pLoc) : maLoc(pLoc) {}
433
            FcChar8* bestname(const std::vector<lang_and_family> &families);
434
    };
435
436
    FcChar8* localizedsorter::bestname(const std::vector<lang_and_family> &families)
437
    {
438
        FcChar8* candidate = families.begin()->second;
439
        rtl::OString sLangMatch(rtl::OUStringToOString(maLoc.getLanguage().toAsciiLowerCase(), RTL_TEXTENCODING_UTF8));
440
        rtl::OString sFullMatch = sLangMatch;
441
        sFullMatch += OString('-');
442
        sFullMatch += rtl::OUStringToOString(maLoc.getCountry().toAsciiLowerCase(), RTL_TEXTENCODING_UTF8);
443
444
        std::vector<lang_and_family>::const_iterator aEnd = families.end();
445
        for (std::vector<lang_and_family>::const_iterator aIter = families.begin(); aIter != aEnd; ++aIter)
446
        {
447
            const char *pLang = (const char*)aIter->first;
448
            //perfect
449
            if (strcmp(pLang, sFullMatch.getStr()) == 0)
450
            {
451
                candidate = aIter->second;
452
                break;
453
            }
454
            else if (strcmp(pLang, sLangMatch.getStr()) == 0)
455
                candidate = aIter->second;
456
        }
457
458
        return candidate;
459
    }
460
461
462
    FcResult lcl_FamilyFromPattern(FontCfgWrapper& rWrapper, FcPattern* pPattern, FcChar8 **family, 
463
        std::hash_map< rtl::OString, rtl::OString, rtl::OStringHash > &aFontconfigNameToLocalized)
464
    {
465
	FcChar8 *origfamily;
466
        FcResult eFamilyRes	= rWrapper.FcPatternGetString( pPattern, FC_FAMILY, 0, &origfamily );
467
        *family = origfamily;
468
469
        if( eFamilyRes == FcResultMatch)
470
        {
471
            FcChar8* familylang = NULL;
472
            if (rWrapper.FcPatternGetString( pPattern, FC_FAMILYLANG, 0, &familylang ) == FcResultMatch)
473
            {
474
                std::vector< lang_and_family > lang_and_families;
475
                lang_and_families.push_back(lang_and_family(familylang, *family));
476
                int k = 1;
477
                while (1)
478
                {
479
                    if (rWrapper.FcPatternGetString( pPattern, FC_FAMILYLANG, k, &familylang ) != FcResultMatch)
480
                        break;
481
                    if (rWrapper.FcPatternGetString( pPattern, FC_FAMILY, k, family ) != FcResultMatch)
482
                        break;
483
                    lang_and_families.push_back(lang_and_family(familylang, *family));
484
                    ++k;
485
                }
486
487
                //possible to-do, sort by UILocale instead of process locale
488
                rtl_Locale* pLoc;
489
                osl_getProcessLocale(&pLoc);
490
                localizedsorter aSorter(pLoc);
491
                *family = aSorter.bestname(lang_and_families);
492
		if (strcmp((const char*)origfamily, (const char*)(*family)) != 0)
493
		    aFontconfigNameToLocalized[OString((const char*)origfamily)] = OString((const char*)(*family));
494
            }
495
        }
496
497
        return eFamilyRes;
498
    }
499
}
500
501
415
/*
502
/*
416
 * PrintFontManager::initFontconfig
503
 * PrintFontManager::initFontconfig
417
 */
504
 */
Lines 443-449 Link Here
443
            FcBool outline = false;
530
            FcBool outline = false;
444
            
531
            
445
            FcResult eFileRes	      = rWrapper.FcPatternGetString( pFSet->fonts[i], FC_FILE, 0, &file );
532
            FcResult eFileRes	      = rWrapper.FcPatternGetString( pFSet->fonts[i], FC_FILE, 0, &file );
446
            FcResult eFamilyRes	      = rWrapper.FcPatternGetString( pFSet->fonts[i], FC_FAMILY, 0, &family );
533
            FcResult eFamilyRes       = lcl_FamilyFromPattern(rWrapper, pFSet->fonts[i], &family, m_aFontconfigNameToLocalized );
447
            FcResult eStyleRes	      = rWrapper.FcPatternGetString( pFSet->fonts[i], FC_STYLE, 0, &style );
534
            FcResult eStyleRes	      = rWrapper.FcPatternGetString( pFSet->fonts[i], FC_STYLE, 0, &style );
448
            FcResult eSlantRes	      = rWrapper.FcPatternGetInteger( pFSet->fonts[i], FC_SLANT, 0, &slant );
535
            FcResult eSlantRes	      = rWrapper.FcPatternGetInteger( pFSet->fonts[i], FC_SLANT, 0, &slant );
449
            FcResult eWeightRes	      = rWrapper.FcPatternGetInteger( pFSet->fonts[i], FC_WEIGHT, 0, &weight );
536
            FcResult eWeightRes	      = rWrapper.FcPatternGetInteger( pFSet->fonts[i], FC_WEIGHT, 0, &weight );
Lines 763-770 Link Here
763
            //extract the closest match
850
            //extract the closest match
764
            FcChar8* family = NULL;
851
            FcChar8* family = NULL;
765
            FcResult eFileRes = rWrapper.FcPatternGetString( pSet->fonts[0], FC_FAMILY, 0, &family );
852
            FcResult eFileRes = rWrapper.FcPatternGetString( pSet->fonts[0], FC_FAMILY, 0, &family );
853
766
            if( eFileRes == FcResultMatch )
854
            if( eFileRes == FcResultMatch )
767
                aName = String( (sal_Char*)family, RTL_TEXTENCODING_UTF8 );
855
            {
856
                OString sFamily((sal_Char*)family);
857
                std::hash_map< rtl::OString, rtl::OString, rtl::OStringHash >::const_iterator aI = m_aFontconfigNameToLocalized.find(sFamily);
858
                if (aI != m_aFontconfigNameToLocalized.end())
859
                    sFamily = aI->second;
860
                aName = String( sFamily.getStr(), RTL_TEXTENCODING_UTF8 );
861
            }
768
862
769
            if (!rGlyphs.empty() )
863
            if (!rGlyphs.empty() )
770
            {
864
            {

Return to issue 54603