[poppler] poppler/poppler: CairoFontEngine.cc, 1.14,
1.15 CairoFontEngine.h, 1.4, 1.5 CairoOutputDev.cc, 1.18,
1.19 GlobalParams.cc, 1.3, 1.4 GlobalParams.h, 1.1.1.1,
1.2 SplashOutputDev.cc, 1.1.1.1, 1.2 SplashOutputDev.h, 1.1.1.1, 1.2
Albert Astals Cid
aacid at freedesktop.org
Fri Jul 29 03:34:22 EST 2005
Update of /cvs/poppler/poppler/poppler
In directory gabe:/tmp/cvs-serv4280/poppler
Modified Files:
CairoFontEngine.cc CairoFontEngine.h CairoOutputDev.cc
GlobalParams.cc GlobalParams.h SplashOutputDev.cc
SplashOutputDev.h
Log Message:
Fontconfig patch is here, rejoice
Index: CairoFontEngine.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/CairoFontEngine.cc,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- CairoFontEngine.cc 22 Jul 2005 11:01:25 -0000 1.14
+++ CairoFontEngine.cc 28 Jul 2005 17:34:19 -0000 1.15
@@ -27,36 +27,6 @@
}
//------------------------------------------------------------------------
-// Font substitutions
-//------------------------------------------------------------------------
-
-struct CairoOutFontSubst {
- char *name;
- double mWidth;
-};
-
-// index: {symbolic:12, fixed:8, serif:4, sans-serif:0} + bold*2 + italic
-static CairoOutFontSubst cairoOutSubstFonts[16] = {
- {"Helvetica", 0.833},
- {"Helvetica-Oblique", 0.833},
- {"Helvetica-Bold", 0.889},
- {"Helvetica-BoldOblique", 0.889},
- {"Times-Roman", 0.788},
- {"Times-Italic", 0.722},
- {"Times-Bold", 0.833},
- {"Times-BoldItalic", 0.778},
- {"Courier", 0.600},
- {"Courier-Oblique", 0.600},
- {"Courier-Bold", 0.600},
- {"Courier-BoldOblique", 0.600},
- {"Symbol", 0.576},
- {"Symbol", 0.576},
- {"Symbol", 0.576},
- {"Symbol", 0.576}
-};
-
-
-//------------------------------------------------------------------------
// CairoFont
//------------------------------------------------------------------------
@@ -83,7 +53,6 @@
codeToGID = NULL;
codeToGIDLen = 0;
- substIdx = -1;
cairo_font_face = NULL;
ref = *gfxFont->getID();
@@ -112,35 +81,8 @@
} else if (!(fileName = gfxFont->getExtFontFile())) {
// look for a display font mapping or a substitute font
dfp = NULL;
- if (gfxFont->isCIDFont()) {
- if (((GfxCIDFont *)gfxFont)->getCollection()) {
- dfp = globalParams->
- getDisplayCIDFont(gfxFont->getName(),
- ((GfxCIDFont *)gfxFont)->getCollection());
- }
- } else {
- if (gfxFont->getName()) {
- dfp = globalParams->getDisplayFont(gfxFont->getName());
- }
- if (!dfp) {
- // 8-bit font substitution
- if (gfxFont->isFixedWidth()) {
- substIdx = 8;
- } else if (gfxFont->isSerif()) {
- substIdx = 4;
- } else {
- substIdx = 0;
- }
- if (gfxFont->isBold()) {
- substIdx += 2;
- }
- if (gfxFont->isItalic()) {
- substIdx += 1;
- }
- substName = new GooString(cairoOutSubstFonts[substIdx].name);
- dfp = globalParams->getDisplayFont(substName);
- delete substName;
- }
+ if (gfxFont->getName()) {
+ dfp = globalParams->getDisplayFont(gfxFont);
}
if (!dfp) {
error(-1, "Couldn't find a font for '%s'",
@@ -297,39 +239,6 @@
return gid;
}
-double
-CairoFont::getSubstitutionCorrection(GfxFont *gfxFont)
-{
- double w1, w2;
- CharCode code;
- char *name;
-
- // for substituted fonts: adjust the font matrix -- compare the
- // width of 'm' in the original font and the substituted font
- if (substIdx >= 0) {
- for (code = 0; code < 256; ++code) {
- if ((name = ((Gfx8BitFont *)gfxFont)->getCharName(code)) &&
- name[0] == 'm' && name[1] == '\0') {
- break;
- }
- }
- if (code < 256) {
- w1 = ((Gfx8BitFont *)gfxFont)->getWidth(code);
- w2 = cairoOutSubstFonts[substIdx].mWidth;
- if (!gfxFont->isSymbolic()) {
- // if real font is substantially narrower than substituted
- // font, reduce the font size accordingly
- if (w1 > 0.01 && w1 < 0.9 * w2) {
- w1 /= w2;
- return w1;
- }
- }
- }
- }
- return 1.0;
-}
-
-
//------------------------------------------------------------------------
// CairoFontEngine
//------------------------------------------------------------------------
Index: CairoFontEngine.h
===================================================================
RCS file: /cvs/poppler/poppler/poppler/CairoFontEngine.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- CairoFontEngine.h 2 May 2005 05:39:11 -0000 1.4
+++ CairoFontEngine.h 28 Jul 2005 17:34:19 -0000 1.5
@@ -24,9 +24,7 @@
GBool matches(Ref &other);
cairo_font_face_t *getFontFace(void);
unsigned long getGlyph(CharCode code, Unicode *u, int uLen);
- double getSubstitutionCorrection(GfxFont *gfxFont);
private:
- int substIdx;
Ref ref;
cairo_font_face_t *cairo_font_face;
FT_Face face;
Index: CairoOutputDev.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/CairoOutputDev.cc,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- CairoOutputDev.cc 28 Jul 2005 05:52:43 -0000 1.18
+++ CairoOutputDev.cc 28 Jul 2005 17:34:19 -0000 1.19
@@ -228,10 +228,6 @@
m11 *= state->getHorizScaling();
m12 *= state->getHorizScaling();
- w = currentFont->getSubstitutionCorrection(state->getFont());
- m12 *= w;
- m22 *= w;
-
LOG(printf ("font matrix: %f %f %f %f\n", m11, m12, m21, m22));
font_face = currentFont->getFontFace();
Index: GlobalParams.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/GlobalParams.cc,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- GlobalParams.cc 28 Jul 2005 06:31:57 -0000 1.3
+++ GlobalParams.cc 28 Jul 2005 17:34:19 -0000 1.4
@@ -32,6 +32,7 @@
#include "BuiltinFontTables.h"
#include "FontEncodingTables.h"
#include "GlobalParams.h"
+#include "GfxFont.h"
#if MULTITHREADED
# define lockGlobalParams gLockMutex(&mutex)
@@ -49,6 +50,10 @@
# define unlockCMapCache
#endif
+#ifndef FC_WEIGHT_BOOK
+#define FC_WEIGHT_BOOK 75
+#endif
+
#include "NameToUnicodeTable.h"
#include "UnicodeMapTables.h"
#include "UTF8.h"
@@ -60,62 +65,6 @@
//------------------------------------------------------------------------
-static struct {
- char *name;
- char *fileName;
-} displayFontTab[] = {
- {"Courier", "n022003l.pfb"},
- {"Courier-Bold", "n022004l.pfb"},
- {"Courier-BoldOblique", "n022024l.pfb"},
- {"Courier-Oblique", "n022023l.pfb"},
- {"Helvetica", "n019003l.pfb"},
- {"Helvetica-Bold", "n019004l.pfb"},
- {"Helvetica-BoldOblique", "n019024l.pfb"},
- {"Helvetica-Oblique", "n019023l.pfb"},
- {"Symbol", "s050000l.pfb"},
- {"Times-Bold", "n021004l.pfb"},
- {"Times-BoldItalic", "n021024l.pfb"},
- {"Times-Italic", "n021023l.pfb"},
- {"Times-Roman", "n021003l.pfb"},
- {"ZapfDingbats", "d050000l.pfb"},
- {NULL}
-};
-
-static char *displayFontDirs[] = {
- "/usr/share/ghostscript/fonts",
- "/usr/local/share/ghostscript/fonts",
- "/usr/share/fonts/default/Type1",
- NULL
-};
-
-/* patterns originally from mupdf; added agfa fonts*/
-static struct {
- const char *name;
- const char *pattern;
-} displayFontTabFc[] = {
- /* FIXME Adobe fonts should be here, but that breaks down if
- fontconfig returns pcf fonts */
- {"Courier", "Nimbus Mono L,Courier New,Cumberland AMT,Cumberland:style=Regular,Roman"},
- {"Courier-Bold", "Nimbus Mono L,Courier New,Cumberland AMT,Cumberland:style=Bold"},
- {"Courier-BoldOblique", "Nimbus Mono L,Courier New,Cumberland AMT,Cumberland:style=Oblique,Italic"},
- {"Courier-Oblique", "Nimbus Mono L,Courier New,Cumberland AMT,Cumberland:style=BoldOblique,BoldItalic"},
- {"Helvetica", "Nimbus Sans L,Arial,Albany AMT,Albany:style=Regular,Roman"},
- {"Helvetica-Bold", "Nimbus Sans L,Arial,Albany AMT,Albany:style=Bold"},
- {"Helvetica-BoldOblique", "Nimbus Sans L,Arial,Albany AMT,Albany:style=Oblique,Italic"},
- {"Helvetica-Oblique", "Nimbus Sans L,Arial,Albany AMT,Albany:style=BoldOblique,BoldItalic"},
- /* FIXME Symbol should be first,
- but that matches windows ttf which gets wrong encoding */
- {"Symbol", "Standard Symbols L,Symbol"},
- {"Times-Bold", "Nimbus Roman No9 L,Times New Roman,Thorndale AMT,Thorndale:style=Bold,Medium"},
- {"Times-BoldItalic", "Nimbus Roman No9 L,Times New Roman,Thorndale AMT,Thorndale:style=BoldItalic,Medium Italic"},
- {"Times-Italic", "Nimbus Roman No9 L,Times New Roman,Thorndale AMT,Thorndale:style=Italic,Regular Italic"},
- {"Times-Roman", "Nimbus Roman No9 L,Times New Roman,Thorndale AMT,Thorndale:style=Regular,Roman"},
- {"ZapfDingbats", "Dingbats:outline=true"},
- {NULL}
-};
-
-//------------------------------------------------------------------------
-
GlobalParams *globalParams = NULL;
//------------------------------------------------------------------------
@@ -181,6 +130,9 @@
GooString *fileName;
FILE *f;
int i;
+
+ FcInit();
+ FCcfg = FcConfigGetCurrent();
#if MULTITHREADED
gInitMutex(&mutex);
@@ -207,8 +159,6 @@
cMapDirs = new GooHash(gTrue);
toUnicodeDirs = new GooList();
displayFonts = new GooHash();
- displayCIDFonts = new GooHash();
- displayNamedCIDFonts = new GooHash();
#if HAVE_PAPER_H
char *paperName;
const struct paper *paperType;
@@ -394,21 +344,17 @@
} else if (!cmd->cmp("toUnicodeDir")) {
parseToUnicodeDir(tokens, fileName, line);
} else if (!cmd->cmp("displayFontT1")) {
- parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line);
+ // deprecated
} else if (!cmd->cmp("displayFontTT")) {
- parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line);
+ // deprecated
} else if (!cmd->cmp("displayNamedCIDFontT1")) {
- parseDisplayFont(tokens, displayNamedCIDFonts,
- displayFontT1, fileName, line);
+ // deprecated
} else if (!cmd->cmp("displayCIDFontT1")) {
- parseDisplayFont(tokens, displayCIDFonts,
- displayFontT1, fileName, line);
+ // deprecated
} else if (!cmd->cmp("displayNamedCIDFontTT")) {
- parseDisplayFont(tokens, displayNamedCIDFonts,
- displayFontTT, fileName, line);
+ // deprecated
} else if (!cmd->cmp("displayCIDFontTT")) {
- parseDisplayFont(tokens, displayCIDFonts,
- displayFontTT, fileName, line);
+ // deprecated
} else if (!cmd->cmp("psFile")) {
parsePSFile(tokens, fileName, line);
} else if (!cmd->cmp("psFont")) {
@@ -617,44 +563,6 @@
toUnicodeDirs->append(((GooString *)tokens->get(1))->copy());
}
-void GlobalParams::parseDisplayFont(GooList *tokens, GooHash *fontHash,
- DisplayFontParamKind kind,
- GooString *fileName, int line) {
- DisplayFontParam *param, *old;
-
- if (tokens->getLength() < 2) {
- goto err1;
- }
- param = new DisplayFontParam(((GooString *)tokens->get(1))->copy(), kind);
-
- switch (kind) {
- case displayFontT1:
- if (tokens->getLength() != 3) {
- goto err2;
- }
- param->t1.fileName = ((GooString *)tokens->get(2))->copy();
- break;
- case displayFontTT:
- if (tokens->getLength() != 3) {
- goto err2;
- }
- param->tt.fileName = ((GooString *)tokens->get(2))->copy();
- break;
- }
-
- if ((old = (DisplayFontParam *)fontHash->remove(param->name))) {
- delete old;
- }
- fontHash->add(param->name, param);
- return;
-
- err2:
- delete param;
- err1:
- error(-1, "Bad 'display*Font*' config file command (%s:%d)",
- fileName->getCString(), line);
-}
-
void GlobalParams::parsePSPaperSize(GooList *tokens, GooString *fileName,
int line) {
GooString *tok;
@@ -880,8 +788,6 @@
deleteGooHash(unicodeMaps, GooString);
deleteGooList(toUnicodeDirs, GooString);
deleteGooHash(displayFonts, DisplayFontParam);
- deleteGooHash(displayCIDFonts, DisplayFontParam);
- deleteGooHash(displayNamedCIDFonts, DisplayFontParam);
if (psFile) {
delete psFile;
}
@@ -917,131 +823,6 @@
}
//------------------------------------------------------------------------
-
-void GlobalParams::setupBaseFonts(char *dir) {
- GooString *fontName;
- GooString *fileName;
- FILE *f;
- DisplayFontParam *dfp;
- int i, j;
-
- for (i = 0; displayFontTab[i].name; ++i) {
- fontName = new GooString(displayFontTab[i].name);
- if (getDisplayFont(fontName)) {
- delete fontName;
- continue;
- }
- fileName = NULL;
- if (dir) {
- fileName = appendToPath(new GooString(dir), displayFontTab[i].fileName);
- if ((f = fopen(fileName->getCString(), "rb"))) {
- fclose(f);
- } else {
- delete fileName;
- fileName = NULL;
- }
- }
-#ifndef WIN32
- for (j = 0; !fileName && displayFontDirs[j]; ++j) {
- fileName = appendToPath(new GooString(displayFontDirs[j]),
- displayFontTab[i].fileName);
- if ((f = fopen(fileName->getCString(), "rb"))) {
- fclose(f);
- } else {
- delete fileName;
- fileName = NULL;
- }
- }
-#endif
- if (!fileName) {
- error(-1, "No display font for '%s'", displayFontTab[i].name);
- delete fontName;
- continue;
- }
- dfp = new DisplayFontParam(fontName, displayFontT1);
- dfp->t1.fileName = fileName;
- globalParams->addDisplayFont(dfp);
- }
-}
-
-//------------------------------------------------------------------------
-
-void GlobalParams::setupBaseFontsFc(FcConfig *fcConfig) {
- GooString *fontName;
- GooString *fileName;
- DisplayFontParam *dfp;
- FcPattern *namePat, *matchPat;
- FcResult result;
- FcChar8 *fcFileName;
- int i;
- DisplayFontParamKind kind;
-
- for (i = 0; displayFontTabFc[i].name; ++i) {
- fontName = new GooString(displayFontTabFc[i].name);
- if (getDisplayFont(fontName)) {
- delete fontName;
- continue;
- }
- fileName = NULL;
- result = FcResultMatch;
- namePat = FcNameParse((const FcChar8 *)displayFontTabFc[i].pattern);
- FcConfigSubstitute(fcConfig, namePat, FcMatchPattern);
- FcDefaultSubstitute(namePat);
- matchPat = FcFontMatch(fcConfig, namePat, &result);
-
- if (result == FcResultMatch) {
- result = FcPatternGetString(matchPat, "file", 0, &fcFileName);
- if (result == FcResultMatch)
- fileName = new GooString((const char *)fcFileName);
- }
-
- FcPatternDestroy(matchPat);
- FcPatternDestroy(namePat);
-
- if (fileName) {
- char *ext;
-
- /* FIXME */
- ext = strrchr(fileName->getCString(), '.');
- if (ext) {
- if (strcasecmp (ext, ".pfb") == 0)
- kind = displayFontT1;
- else if (strcasecmp (ext, ".pfa") == 0)
- kind = displayFontT1;
- else if (strcasecmp (ext, ".ttf") == 0)
- kind = displayFontTT;
- else if (strcasecmp (ext, ".ttc") == 0)
- kind = displayFontTT;
- else {
- delete fileName;
- fileName = NULL;
- }
- } else {
- delete fileName;
- fileName = NULL;
- }
- }
-
- if (!fileName) {
- error(-1, "No display font for '%s'", displayFontTabFc[i].name);
- delete fontName;
- continue;
- }
-
- dfp = new DisplayFontParam(fontName, kind);
- switch (kind) {
- case displayFontT1:
- dfp->t1.fileName = fileName;
- break;
- case displayFontTT:
- dfp->tt.fileName = fileName;
- }
-
- globalParams->addDisplayFont(dfp);
- }
-}
-
-//------------------------------------------------------------------------
// accessors
//------------------------------------------------------------------------
@@ -1127,24 +908,217 @@
return NULL;
}
-DisplayFontParam *GlobalParams::getDisplayFont(GooString *fontName) {
- DisplayFontParam *dfp;
+GBool findModifier(const char *name, const char *modifier, const char **start)
+{
+ const char *match;
- lockGlobalParams;
- dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
- unlockGlobalParams;
- return dfp;
+ if (name == NULL)
+ return gFalse;
+
+ match = strstr(name, modifier);
+ if (match) {
+ if (*start == NULL || match < *start)
+ *start = match;
+ return gTrue;
+ }
+ else {
+ return gFalse;
+ }
}
-DisplayFontParam *GlobalParams::getDisplayCIDFont(GooString *fontName,
- GooString *collection) {
+FcPattern *buildFcPattern(GfxFont *font)
+{
+ int weight = FC_WEIGHT_NORMAL,
+ slant = FC_SLANT_ROMAN,
+ width = FC_WIDTH_NORMAL,
+ spacing = FC_PROPORTIONAL;
+ bool deleteFamily = false;
+ char *family, *name, *lang, *modifiers;
+ const char *start;
+ FcPattern *p;
+
+ // this is all heuristics will be overwritten if font had proper info
+ name = font->getName()->getCString();
+
+ modifiers = strchr (name, ',');
+ if (modifiers == NULL)
+ modifiers = strchr (name, '-');
+
+ // remove the - from the names, for some reason, Fontconfig does not
+ // understand "MS-Mincho" but does with "MS Mincho"
+ int len = strlen(name);
+ for (int i = 0; i < len; i++)
+ name[i] = (name[i] == '-' ? ' ' : name[i]);
+
+ start = NULL;
+ findModifier(modifiers, "Regular", &start);
+ findModifier(modifiers, "Roman", &start);
+
+ if (findModifier(modifiers, "Oblique", &start))
+ slant = FC_SLANT_OBLIQUE;
+ if (findModifier(modifiers, "Italic", &start))
+ slant = FC_SLANT_ITALIC;
+ if (findModifier(modifiers, "Bold", &start))
+ weight = FC_WEIGHT_BOLD;
+ if (findModifier(modifiers, "Light", &start))
+ weight = FC_WEIGHT_LIGHT;
+ if (findModifier(modifiers, "Condensed", &start))
+ width = FC_WIDTH_CONDENSED;
+
+ if (start) {
+ // There have been "modifiers" in the name, crop them to obtain
+ // the family name
+ family = new char[len+1];
+ strcpy(family, name);
+ int pos = (modifiers - name);
+ family[pos] = '\0';
+ pos--;
+ family[pos] = '\0';
+ deleteFamily = true;
+ }
+ else {
+ family = name;
+ }
+
+ // use font flags
+ if (font->isFixedWidth())
+ spacing = FC_MONO;
+ if (font->isBold())
+ weight = FC_WEIGHT_BOLD;
+ if (font->isItalic())
+ slant = FC_SLANT_ITALIC;
+
+ // if the FontDescriptor specified a family name use it
+ if (font->getFamily())
+ family = font->getFamily()->getCString();
+
+ // if the FontDescriptor specified a weight use it
+ switch (font -> getWeight())
+ {
+ case GfxFont::W100: weight = FC_WEIGHT_EXTRALIGHT; break;
+ case GfxFont::W200: weight = FC_WEIGHT_LIGHT; break;
+ case GfxFont::W300: weight = FC_WEIGHT_BOOK; break;
+ case GfxFont::W400: weight = FC_WEIGHT_NORMAL; break;
+ case GfxFont::W500: weight = FC_WEIGHT_MEDIUM; break;
+ case GfxFont::W600: weight = FC_WEIGHT_DEMIBOLD; break;
+ case GfxFont::W700: weight = FC_WEIGHT_BOLD; break;
+ case GfxFont::W800: weight = FC_WEIGHT_EXTRABOLD; break;
+ case GfxFont::W900: weight = FC_WEIGHT_BLACK; break;
+ default: break;
+ }
+
+ // if the FontDescriptor specified a width use it
+ switch (font -> getStretch())
+ {
+ case GfxFont::UltraCondensed: width = FC_WIDTH_ULTRACONDENSED; break;
+ case GfxFont::ExtraCondensed: width = FC_WIDTH_EXTRACONDENSED; break;
+ case GfxFont::Condensed: width = FC_WIDTH_CONDENSED; break;
+ case GfxFont::SemiCondensed: width = FC_WIDTH_SEMICONDENSED; break;
+ case GfxFont::Normal: width = FC_WIDTH_NORMAL; break;
+ case GfxFont::SemiExpanded: width = FC_WIDTH_SEMIEXPANDED; break;
+ case GfxFont::Expanded: width = FC_WIDTH_EXPANDED; break;
+ case GfxFont::ExtraExpanded: width = FC_WIDTH_EXTRAEXPANDED; break;
+ case GfxFont::UltraExpanded: width = FC_WIDTH_ULTRAEXPANDED; break;
+ default: break;
+ }
+
+ // find the language we want the font to support
+ if (font->isCIDFont())
+ {
+ GooString *collection = ((GfxCIDFont *)font)->getCollection();
+ if (collection)
+ {
+ if (strcmp(collection->getCString(), "Adobe-GB1") == 0)
+ lang = "zh-cn"; // Simplified Chinese
+ else if (strcmp(collection->getCString(), "Adobe-CNS1") == 0)
+ lang = "zh-tw"; // Traditional Chinese
+ else if (strcmp(collection->getCString(), "Adobe-Japan1") == 0)
+ lang = "ja"; // Japanese
+ else if (strcmp(collection->getCString(), "Adobe-Japan2") == 0)
+ lang = "ja"; // Japanese
+ else if (strcmp(collection->getCString(), "Adobe-Korea1") == 0)
+ lang = "ko"; // Korean
+ else if (strcmp(collection->getCString(), "Adobe-UCS") == 0)
+ lang = "xx";
+ else if (strcmp(collection->getCString(), "Adobe-Identity") == 0)
+ lang = "xx";
+ else
+ {
+ error(-1, "Unknown CID font collection, please report to poppler bugzilla.");
+ lang = "xx";
+ }
+ }
+ else lang = "xx";
+ }
+ else lang = "xx";
+
+ p = FcPatternBuild(NULL,
+ FC_FAMILY, FcTypeString, family,
+ FC_SLANT, FcTypeInteger, slant,
+ FC_WEIGHT, FcTypeInteger, weight,
+ FC_WIDTH, FcTypeInteger, width,
+ FC_SPACING, FcTypeInteger, spacing,
+ FC_LANG, FcTypeString, lang,
+ NULL);
+ if (deleteFamily)
+ delete family;
+ return p;
+}
+
+DisplayFontParam *GlobalParams::getDisplayFont(GfxFont *font) {
DisplayFontParam *dfp;
+ FcPattern *p=0,*m=0;
+ GooString *fontName = font->getName();
+ if (!fontName) return NULL;
+
lockGlobalParams;
- if (!fontName ||
- !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) {
- dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection);
+ dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
+ if (!dfp)
+ {
+ FcChar8* s;
+ char * ext;
+ FcResult res;
+ p = buildFcPattern(font);
+ // TODO DEBUG INFO, REMOVE
+ FcPatternPrint(p);
+
+ if (!p)
+ goto fin;
+ FcConfigSubstitute(FCcfg, p, FcMatchPattern);
+ FcDefaultSubstitute(p);
+ m = FcFontMatch(FCcfg,p,&res);
+ if (!m)
+ goto fin;
+ res = FcPatternGetString(m, FC_FILE, 0, &s);
+ // TODO DEBUG INFO, REMOVE
+ printf("Font file: %s\n", s);
+ if (res != FcResultMatch || !s)
+ goto fin;
+ ext = strrchr((char*)s,'.');
+ if (!ext)
+ goto fin;
+ if (!strncasecmp(ext,".ttf",4))
+ {
+ dfp = new DisplayFontParam(fontName->copy(), displayFontTT);
+ dfp->tt.fileName = new GooString((char*)s);
+ }
+ else if (!strncasecmp(ext,".pfa",4) || !strncasecmp(ext,".pfb",4))
+ {
+ dfp = new DisplayFontParam(fontName->copy(), displayFontT1);
+ dfp->t1.fileName = new GooString((char*)s);
+ }
+ else
+ goto fin;
+ displayFonts->add(dfp->name,dfp);
}
+fin:
+ unlockGlobalParams;
+ if (m)
+ FcPatternDestroy(m);
+ if (p)
+ FcPatternDestroy(p);
+
unlockGlobalParams;
return dfp;
}
@@ -1532,17 +1506,6 @@
// functions to set parameters
//------------------------------------------------------------------------
-void GlobalParams::addDisplayFont(DisplayFontParam *param) {
- DisplayFontParam *old;
-
- lockGlobalParams;
- if ((old = (DisplayFontParam *)displayFonts->remove(param->name))) {
- delete old;
- }
- displayFonts->add(param->name, param);
- unlockGlobalParams;
-}
-
void GlobalParams::setPSFile(char *file) {
lockGlobalParams;
if (psFile) {
Index: GlobalParams.h
===================================================================
RCS file: /cvs/poppler/poppler/poppler/GlobalParams.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- GlobalParams.h 3 Mar 2005 19:46:00 -0000 1.1.1.1
+++ GlobalParams.h 28 Jul 2005 17:34:19 -0000 1.2
@@ -34,6 +34,7 @@
class CMap;
class CMapCache;
class GlobalParams;
+class GfxFont;
//------------------------------------------------------------------------
@@ -115,9 +116,6 @@
~GlobalParams();
- void setupBaseFonts(char *dir);
- void setupBaseFontsFc(FcConfig *fcConfig);
-
//----- accessors
CharCode getMacRomanCharCode(char *charName);
@@ -127,8 +125,7 @@
FILE *getUnicodeMapFile(GooString *encodingName);
FILE *findCMapFile(GooString *collection, GooString *cMapName);
FILE *findToUnicodeFile(GooString *name);
- DisplayFontParam *getDisplayFont(GooString *fontName);
- DisplayFontParam *getDisplayCIDFont(GooString *fontName, GooString *collection);
+ DisplayFontParam *getDisplayFont(GfxFont *font);
GooString *getPSFile();
int getPSPaperWidth();
int getPSPaperHeight();
@@ -170,7 +167,6 @@
//----- functions to set parameters
- void addDisplayFont(DisplayFontParam *param);
void setPSFile(char *file);
GBool setPSPaperSize(char *size);
void setPSPaperWidth(int width);
@@ -209,9 +205,6 @@
void parseUnicodeMap(GooList *tokens, GooString *fileName, int line);
void parseCMapDir(GooList *tokens, GooString *fileName, int line);
void parseToUnicodeDir(GooList *tokens, GooString *fileName, int line);
- void parseDisplayFont(GooList *tokens, GooHash *fontHash,
- DisplayFontParamKind kind,
- GooString *fileName, int line);
void parsePSFile(GooList *tokens, GooString *fileName, int line);
void parsePSPaperSize(GooList *tokens, GooString *fileName, int line);
void parsePSImageableArea(GooList *tokens, GooString *fileName, int line);
@@ -253,10 +246,6 @@
GooList *toUnicodeDirs; // list of ToUnicode CMap dirs [GooString]
GooHash *displayFonts; // display font info, indexed by font name
// [DisplayFontParam]
- GooHash *displayCIDFonts; // display CID font info, indexed by
- // collection [DisplayFontParam]
- GooHash *displayNamedCIDFonts; // display CID font info, indexed by
- // font name [DisplayFontParam]
GooString *psFile; // PostScript file or command (for xpdf)
int psPaperWidth; // paper size, in PostScript points, for
int psPaperHeight; // PostScript output
@@ -301,6 +290,8 @@
CharCodeToUnicodeCache *unicodeToUnicodeCache;
UnicodeMapCache *unicodeMapCache;
CMapCache *cMapCache;
+
+ FcConfig *FCcfg;
#if MULTITHREADED
GooMutex mutex;
Index: SplashOutputDev.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/SplashOutputDev.cc,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- SplashOutputDev.cc 3 Mar 2005 19:46:01 -0000 1.1.1.1
+++ SplashOutputDev.cc 28 Jul 2005 17:34:19 -0000 1.2
@@ -39,35 +39,6 @@
#include "SplashOutputDev.h"
//------------------------------------------------------------------------
-// Font substitutions
-//------------------------------------------------------------------------
-
-struct SplashOutFontSubst {
- char *name;
- double mWidth;
-};
-
-// index: {symbolic:12, fixed:8, serif:4, sans-serif:0} + bold*2 + italic
-static SplashOutFontSubst splashOutSubstFonts[16] = {
- {"Helvetica", 0.833},
- {"Helvetica-Oblique", 0.833},
- {"Helvetica-Bold", 0.889},
- {"Helvetica-BoldOblique", 0.889},
- {"Times-Roman", 0.788},
- {"Times-Italic", 0.722},
- {"Times-Bold", 0.833},
- {"Times-BoldItalic", 0.778},
- {"Courier", 0.600},
- {"Courier-Oblique", 0.600},
- {"Courier-Bold", 0.600},
- {"Courier-BoldOblique", 0.600},
- {"Symbol", 0.576},
- {"Symbol", 0.576},
- {"Symbol", 0.576},
- {"Symbol", 0.576}
-};
-
-//------------------------------------------------------------------------
#define soutRound(x) ((int)(x + 0.5))
@@ -78,7 +49,7 @@
class SplashOutFontFileID: public SplashFontFileID {
public:
- SplashOutFontFileID(Ref *rA) { r = *rA; substIdx = -1; }
+ SplashOutFontFileID(Ref *rA) { r = *rA; }
~SplashOutFontFileID() {}
@@ -87,13 +58,9 @@
((SplashOutFontFileID *)id)->r.gen == r.gen;
}
- void setSubstIdx(int substIdxA) { substIdx = substIdxA; }
- int getSubstIdx() { return substIdx; }
-
private:
Ref r;
- int substIdx;
};
//------------------------------------------------------------------------
@@ -547,36 +514,8 @@
// look for a display font mapping or a substitute font
dfp = NULL;
- if (gfxFont->isCIDFont()) {
- if (((GfxCIDFont *)gfxFont)->getCollection()) {
- dfp = globalParams->
- getDisplayCIDFont(gfxFont->getName(),
- ((GfxCIDFont *)gfxFont)->getCollection());
- }
- } else {
- if (gfxFont->getName()) {
- dfp = globalParams->getDisplayFont(gfxFont->getName());
- }
- if (!dfp) {
- // 8-bit font substitution
- if (gfxFont->isFixedWidth()) {
- substIdx = 8;
- } else if (gfxFont->isSerif()) {
- substIdx = 4;
- } else {
- substIdx = 0;
- }
- if (gfxFont->isBold()) {
- substIdx += 2;
- }
- if (gfxFont->isItalic()) {
- substIdx += 1;
- }
- substName = new GooString(splashOutSubstFonts[substIdx].name);
- dfp = globalParams->getDisplayFont(substName);
- delete substName;
- id->setSubstIdx(substIdx);
- }
+ if (gfxFont->getName()) {
+ dfp = globalParams->getDisplayFont(gfxFont);
}
if (!dfp) {
error(-1, "Couldn't find a font for '%s'",
@@ -678,31 +617,6 @@
m11 *= state->getHorizScaling();
m12 *= state->getHorizScaling();
- // for substituted fonts: adjust the font matrix -- compare the
- // width of 'm' in the original font and the substituted font
- substIdx = ((SplashOutFontFileID *)fontFile->getID())->getSubstIdx();
- if (substIdx >= 0) {
- for (code = 0; code < 256; ++code) {
- if ((name = ((Gfx8BitFont *)gfxFont)->getCharName(code)) &&
- name[0] == 'm' && name[1] == '\0') {
- break;
- }
- }
- if (code < 256) {
- w1 = ((Gfx8BitFont *)gfxFont)->getWidth(code);
- w2 = splashOutSubstFonts[substIdx].mWidth;
- if (!gfxFont->isSymbolic()) {
- // if real font is substantially narrower than substituted
- // font, reduce the font size accordingly
- if (w1 > 0.01 && w1 < 0.9 * w2) {
- w1 /= w2;
- m11 *= w1;
- m21 *= w1;
- }
- }
- }
- }
-
// create the scaled font
mat[0] = m11; mat[1] = -m12;
mat[2] = m21; mat[3] = -m22;
@@ -1306,43 +1220,3 @@
gray = 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.g;
splash->setFillPattern(getColor(gray, &rgb));
}
-
-SplashFont *SplashOutputDev::getFont(GooString *name, double *mat) {
- DisplayFontParam *dfp;
- Ref ref;
- SplashOutFontFileID *id;
- SplashFontFile *fontFile;
- SplashFont *fontObj;
- int i;
-
- for (i = 0; i < 16; ++i) {
- if (!name->cmp(splashOutSubstFonts[i].name)) {
- break;
- }
- }
- if (i == 16) {
- return NULL;
- }
- ref.num = i;
- ref.gen = -1;
- id = new SplashOutFontFileID(&ref);
-
- // check the font file cache
- if ((fontFile = fontEngine->getFontFile(id))) {
- delete id;
-
- // load the font file
- } else {
- dfp = globalParams->getDisplayFont(name);
- if (dfp->kind != displayFontT1) {
- return NULL;
- }
- fontFile = fontEngine->loadType1Font(id, dfp->t1.fileName->getCString(),
- gFalse, winAnsiEncoding);
- }
-
- // create the scaled font
- fontObj = fontEngine->getFont(fontFile, (SplashCoord *)mat);
-
- return fontObj;
-}
Index: SplashOutputDev.h
===================================================================
RCS file: /cvs/poppler/poppler/poppler/SplashOutputDev.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- SplashOutputDev.h 3 Mar 2005 19:46:00 -0000 1.1.1.1
+++ SplashOutputDev.h 28 Jul 2005 17:34:19 -0000 1.2
@@ -152,9 +152,6 @@
// Set the Splash fill color.
void setFillColor(int r, int g, int b);
- // Get a font object for a Base-14 font, using the Latin-1 encoding.
- SplashFont *getFont(GooString *name, double *mat);
-
void setUnderlayCbk(void (*cbk)(void *data), void *data)
{ underlayCbk = cbk; underlayCbkData = data; }
More information about the poppler
mailing list