X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2FSWFOutputDev.cc;h=75d19e6bcf619dd99504ccd70e024488d42344cd;hb=6d22f1376c2fcad7c872db608630468d3abcca23;hp=5186af38a9964f6f3894fc8cfb0515ff33e8a659;hpb=efbba601c7536de1aa75f2b429989797da7e2c5d;p=swftools.git diff --git a/pdf2swf/SWFOutputDev.cc b/pdf2swf/SWFOutputDev.cc index 5186af3..75d19e6 100644 --- a/pdf2swf/SWFOutputDev.cc +++ b/pdf2swf/SWFOutputDev.cc @@ -77,6 +77,8 @@ typedef struct _fontfile static fontfile_t fonts[2048]; static int fontnum = 0; +static int config_use_fontconfig = 1; + // swf <-> pdf pages // TODO: move into pdf_doc_t static int*pages = 0; @@ -1308,6 +1310,9 @@ char* searchForSuitableFont(GfxFont*gfxFont) char*name = getFontName(gfxFont); char*fontname = 0; char*filename = 0; + + if(!config_use_fontconfig) + return 0; #ifdef HAVE_FONTCONFIG FcPattern *pattern, *match; @@ -1315,25 +1320,38 @@ char* searchForSuitableFont(GfxFont*gfxFont) FcChar8 *v; static int fcinitcalled = false; + + msg(" searchForSuitableFont(%s)", name); // call init ony once if (!fcinitcalled) { + msg(" Initializing FontConfig..."); fcinitcalled = true; - FcInit(); //leaks + if(FcInit()) { + msg(" FontConfig Initialization failed. Disabling."); + config_use_fontconfig = 0; + return 0; + } + msg(" ...initialized FontConfig"); } + msg(" FontConfig: Create \"%s\" Family Pattern", name); pattern = FcPatternBuild(NULL, FC_FAMILY, FcTypeString, name, NULL); if (gfxFont->isItalic()) // check for italic + msg(" FontConfig: Adding Italic Slant"); FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC); if (gfxFont->isBold()) // check for bold + msg(" FontConfig: Adding Bold Weight"); FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD); + msg(" FontConfig: Try to match..."); // configure and match using the original font name FcConfigSubstitute(0, pattern, FcMatchPattern); FcDefaultSubstitute(pattern); match = FcFontMatch(0, pattern, &result); if (FcPatternGetString(match, "family", 0, &v) == FcResultMatch) { + msg(" FontConfig: family=%s", (char*)v); // if we get an exact match if (strcmp((char *)v, name) == 0) { if (FcPatternGetString(match, "file", 0, &v) == FcResultMatch) { @@ -1342,6 +1360,7 @@ char* searchForSuitableFont(GfxFont*gfxFont) if(nfn) fontname = strdup(nfn+1); else fontname = filename; } + msg(" FontConfig: Returning \"%s\"", fontname); } else { // initialize patterns FcPatternDestroy(pattern); @@ -1349,22 +1368,28 @@ char* searchForSuitableFont(GfxFont*gfxFont) // now match against serif etc. if (gfxFont->isSerif()) { + msg(" FontConfig: Create Serif Family Pattern"); pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "serif", NULL); } else if (gfxFont->isFixedWidth()) { + msg(" FontConfig: Create Monospace Family Pattern"); pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "monospace", NULL); } else { + msg(" FontConfig: Create Sans Family Pattern"); pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "sans", NULL); } // check for italic if (gfxFont->isItalic()) { + msg(" FontConfig: Adding Italic Slant"); int bb = FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC); } // check for bold if (gfxFont->isBold()) { + msg(" FontConfig: Adding Bold Weight"); int bb = FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD); } + msg(" FontConfig: Try to match... (2)"); // configure and match using serif etc FcConfigSubstitute (0, pattern, FcMatchPattern); FcDefaultSubstitute (pattern); @@ -1376,6 +1401,7 @@ char* searchForSuitableFont(GfxFont*gfxFont) if(nfn) fontname = strdup(nfn+1); else fontname = filename; } + msg(" FontConfig: Returning \"%s\"", fontname); } } @@ -1918,6 +1944,8 @@ void pdfswf_setparameter(char*name, char*value) pdfswf_addfontdir(value); } else if(!strcmp(name, "languagedir")) { pdfswf_addlanguagedir(value); + } else if(!strcmp(name, "fontconfig")) { + config_use_fontconfig = atoi(value); } else { swfoutput_setparameter(name, value); } @@ -1952,14 +1980,14 @@ void pdfswf_addlanguagedir(char*dir) int l; FILE*fi = 0; - char* config_file = (char*)malloc(strlen(dir)+256); + char* config_file = (char*)malloc(strlen(dir) + 1 + sizeof("add-to-xpdfrc")); strcpy(config_file, dir); strcat(config_file, dirseparator()); strcat(config_file, "add-to-xpdfrc"); fi = fopen(config_file, "rb"); if(!fi) { - msg(" Could not open %s"); + msg(" Could not open %s", config_file); return; } globalParams->parseFile(new GString(config_file), fi); @@ -2005,7 +2033,7 @@ void pdfswf_addfontdir(char*dirname) } closedir(dir); #else - msg(" No dirent.h- unable to add font dir %s"); + msg(" No dirent.h- unable to add font dir %s", dir); #endif }