Index: src/extension/internal/pdfinput/svg-builder.cpp =================================================================== --- src/extension/internal/pdfinput/svg-builder.cpp (revision 20605) +++ src/extension/internal/pdfinput/svg-builder.cpp (working copy) @@ -13,6 +13,8 @@ #ifdef HAVE_CONFIG_H # include #endif + +#include #ifdef HAVE_POPPLER @@ -850,6 +852,62 @@ } } +/* + MatchingChars + Count for how many characters s1 matches sp taking into account + that a space in sp may be removed or replaced by some other tokens + specified in the code. +*/ +static int MatchingChars(std::string s1, std::string sp) +{ + unsigned int is = 0; + unsigned int ip = 0; + + while(is < s1.length() && ip < sp.length()) { + if (s1[is] == sp[ip]) { + is++; ip++; + } else if (sp[ip] == ' ') { + ip++; + if (s1[is] == '_' || s1[is] == '-') { // Valid matches to spaces in sp. + is++; + } + } else { + break; + } + } + return(ip); +} + +/* + BestMatchingFont + Scan the available fonts to find the font name that best matches PDFname. +*/ +static std::string BestMatchingFont(std::string PDFname) +{ + FamilyToStylesMap familyStyleMap; + font_factory::Default()->GetUIFamiliesAndStyles(&familyStyleMap); + double bestMatch = 0; + std::string bestFontname; + + for (FamilyToStylesMap::iterator iter = familyStyleMap.begin(); + iter != familyStyleMap.end(); + iter++) { + std::string fontname = iter->first.c_str(); + double relMatch = (float)MatchingChars(PDFname, fontname) / fontname.length(); + if (relMatch > bestMatch) { + bestMatch = relMatch; + bestFontname = fontname; + } + } + + if (bestMatch < 0.25) { + // Some threshold ... if less the right font is probably not available. + bestFontname = "Arial"; + } + + return bestFontname; +} + /** * This array holds info about translating font weight names to more or less CSS equivalents */ @@ -917,9 +975,9 @@ // Font family if (font->getFamily()) { - sp_repr_css_set_property(_font_style, "font-family", font->getFamily()->getCString()); + sp_repr_css_set_property(_font_style, "font-family", BestMatchingFont(font->getFamily()->getCString()).c_str()); } else { - sp_repr_css_set_property(_font_style, "font-family", font_family); + sp_repr_css_set_property(_font_style, "font-family", BestMatchingFont(font_family).c_str()); } // Font style