Changeset 332 for branches


Ignore:
Timestamp:
Mar 31, 2010, 12:17:51 PM (12 years ago)
Author:
dmik
Message:

branches/kmk: Poppler plugin: Substitute Zapf Dingbats with Dejavu Sans if the former is not present to make dingbats symbols (such as a check mark frequently used in forms) visible.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/kmk/poppler/fc-emulate-os2/fontconfig/fontconfig.cpp

    r296 r332  
    256256
    257257    string key = familyName;
    258     if ( stricmp( styleName.c_str(), "regular" ) != 0 ) {
     258    if ( stricmp( styleName.c_str(), "regular" ) != 0 &&
     259         stricmp( styleName.c_str(), "book" ) != 0 ) {
    259260        key += ' ';
    260261        key += styleName;
     
    449450#define DEFAULT_SANSSERIF_FONT      "helvetica"
    450451#define DEFAULT_MONOSPACED_FONT     "courier"
     452#define DEFAULT_SYMBOL_FONT         "symbol set"
    451453
    452454static bool isSansserif( const char *family )
     
    459461}
    460462
    461 static string buildFontKey( FcPattern *p, bool useDefaultFonts )
     463static string buildFontKey( FcPattern *p )
    462464{
    463465    string key = p->family;
    464466
    465     if ( useDefaultFonts )
    466     {
     467    // From http://en.wikipedia.org/wiki/Portable_Document_Format:
     468    //
     469    // There are fourteen typefaces that have a special significance to PDF
     470    // documents:
     471    //
     472    //  * Times (v3) (in regular, italic, bold, and bold italic)
     473    //  * Courier (in regular, oblique, bold and bold oblique)
     474    //  * Helvetica (v3) (in regular, oblique, bold and bold oblique)
     475    //  * Symbol
     476    //  * Zapf Dingbats
     477    //
     478    // These fonts, sometimes referred to as the "base fourteen fonts" should
     479    // always be present (actually present or a close substitute) and so need
     480    // not be embedded in a PDF.[46]  PDF viewers must know about the metrics
     481    // of these fonts. Other fonts may be substituted if they are not embedded
     482    // in a PDF.
     483    //
     484    // The following code is based on this information and guarantees that we
     485    // always return a valid font for those (except Zapf Dingbats for which we
     486    // don't have a pre-installed OS/2 font).
     487
     488    bool ignoreStyle = false;
     489
     490    if ( fontmap->find( key ) == fontmap->end() ) {
     491        // not found: try substitutions
    467492        if ( p->spacing == FC_MONO ) {
    468493            key = DEFAULT_MONOSPACED_FONT;
    469         }
    470         else
    471         {
     494        } else {
    472495            if ( isSansserif( p->family ) ) {
    473496                key = DEFAULT_SANSSERIF_FONT;
     497            } else {
     498                if ( key == "symbol" ) {
     499                    ignoreStyle = true;
     500                    key = "opensymbol";
     501                    if ( fontmap->find( key ) == fontmap->end() )
     502                        key = DEFAULT_SYMBOL_FONT;
     503                } else if ( key == "zapfdingbats" || key == "zapf dingbats" ) {
     504                    ignoreStyle = true;
     505                    key = "dejavu sans";
     506                    // last resort, quite meaningless but we must provide something
     507                    if ( fontmap->find( key ) == fontmap->end() )
     508                        key = DEFAULT_SYMBOL_FONT;
     509                } else {
     510                    key = DEFAULT_SERIF_FONT;
     511                }
    474512            }
    475             else {
    476                 key = DEFAULT_SERIF_FONT;
    477             }
    478         }
    479     }
    480     else
    481     {
    482         // use 'Symbol Set' (SYMB.PFB) instead of 'Symbol'
    483         if ( strcmp( p->family, "symbol" ) == 0 ) {
    484             key = "symbol set";
    485         }
    486     }
    487 
    488     if ( p->weight > FC_WEIGHT_NORMAL ) {
    489         key += ' ';
    490         key += "bold";
    491     }
    492 
    493     if ( (p->slant == FC_SLANT_ITALIC) || (p->slant == FC_SLANT_OBLIQUE) ) {
    494         key += ' ';
    495         key += "italic";
     513        }
     514
     515    }
     516
     517    if ( !ignoreStyle ) {
     518        if ( p->weight > FC_WEIGHT_NORMAL ) {
     519            key += ' ';
     520            key += "bold";
     521        }
     522        if ( (p->slant == FC_SLANT_ITALIC) || (p->slant == FC_SLANT_OBLIQUE) ) {
     523            key += ' ';
     524            key += "italic";
     525        }
    496526    }
    497527
     
    511541    pat->filename = NULL;
    512542
    513     string key = buildFontKey( pat, false );
    514 
    515     if ( fontmap->find( key ) == fontmap->end() ) {
    516         key = buildFontKey( pat, true );
    517         pat->filename = newstrdup( (*fontmap)[ key ].c_str() );
    518     }
    519     else {
    520         pat->filename = newstrdup( (*fontmap)[ key ].c_str() );
    521     }
     543    string key = buildFontKey( pat );
     544    pat->filename = newstrdup( (*fontmap)[ key ].c_str() );
    522545
    523546//printf( "MATCHED STYLE: %s, FILENAME: %s\n", key.c_str(), pat->filename );
Note: See TracChangeset for help on using the changeset viewer.