Commit 82638bab authored by Albert Astals Cid's avatar Albert Astals Cid

Fontconfig patch is here, rejoice

parent e9015531
2005-07-28 Albert Astals Cid <aacid@kde.org>
* glib/poppler-document.cc:
* poppler/CairoFontEngine.[cc|h]:
* poppler/CairoOutputDev.cc:
* poppler/GlobalParams.[cc|h]:
* poppler/SplashOutputDev.[cc|h]:
* qt/poppler-document.cc:
* qt4/src/poppler-document.cc:
* test/gtk-cairo-test.cc:
* test/gtk-splash-test.cc:
Use fontconfig for finding which font use for not embeded fonts
2005-07-28 Kristian Høgsberg <krh@redhat.com>
* poppler/poppler-config.h.in: Add GCC_PRINTF_FORMAT macro to
......@@ -9,7 +22,7 @@
PSOutputDev::writePSFmt().
* poppler/PSOutputDev.cc, poppler/GlobalParams.cc: Quiet new
printf warnings.
printf warnings.
* poppler/TextOutputDev.cc (TextBlock::visitSelection): Assign
start and stop coordinates in one place so we don't assign the
......
......@@ -75,7 +75,6 @@ poppler_document_new_from_file (const char *uri,
if (!globalParams) {
globalParams = new GlobalParams("/etc/xpdfrc");
globalParams->setupBaseFontsFc(NULL);
}
filename = g_filename_from_uri (uri, NULL, error);
......
......@@ -26,36 +26,6 @@ static void fileWrite(void *stream, char *data, int len) {
fwrite(data, 1, len, (FILE *)stream);
}
//------------------------------------------------------------------------
// 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 @@ CairoFont::CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib) {
codeToGID = NULL;
codeToGIDLen = 0;
substIdx = -1;
cairo_font_face = NULL;
ref = *gfxFont->getID();
......@@ -112,35 +81,8 @@ CairoFont::CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib) {
} 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 @@ CairoFont::getGlyph(CharCode code,
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
//------------------------------------------------------------------------
......
......@@ -24,9 +24,7 @@ public:
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;
......
......@@ -228,10 +228,6 @@ void CairoOutputDev::updateFont(GfxState *state) {
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();
......
This diff is collapsed.
......@@ -34,6 +34,7 @@ class UnicodeMapCache;
class CMap;
class CMapCache;
class GlobalParams;
class GfxFont;
//------------------------------------------------------------------------
......@@ -115,9 +116,6 @@ public:
~GlobalParams();
void setupBaseFonts(char *dir);
void setupBaseFontsFc(FcConfig *fcConfig);
//----- accessors
CharCode getMacRomanCharCode(char *charName);
......@@ -127,8 +125,7 @@ public:
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 @@ public:
//----- functions to set parameters
void addDisplayFont(DisplayFontParam *param);
void setPSFile(char *file);
GBool setPSPaperSize(char *size);
void setPSPaperWidth(int width);
......@@ -209,9 +205,6 @@ private:
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 @@ private:
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 @@ private:
CharCodeToUnicodeCache *unicodeToUnicodeCache;
UnicodeMapCache *unicodeMapCache;
CMapCache *cMapCache;
FcConfig *FCcfg;
#if MULTITHREADED
GooMutex mutex;
......
......@@ -38,35 +38,6 @@
#include "splash/Splash.h"
#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 @@ static SplashOutFontSubst splashOutSubstFonts[16] = {
class SplashOutFontFileID: public SplashFontFileID {
public:
SplashOutFontFileID(Ref *rA) { r = *rA; substIdx = -1; }
SplashOutFontFileID(Ref *rA) { r = *rA; }
~SplashOutFontFileID() {}
......@@ -87,13 +58,9 @@ public:
((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 @@ void SplashOutputDev::updateFont(GfxState *state) {
// 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 @@ void SplashOutputDev::updateFont(GfxState *state) {
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 @@ void SplashOutputDev::setFillColor(int r, int g, int b) {
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;
}
......@@ -152,9 +152,6 @@ public:
// 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; }
......
......@@ -33,7 +33,6 @@ Document *Document::load(const QString &filePath)
{
if (!globalParams) {
globalParams = new GlobalParams("/etc/xpdfrc");
globalParams->setupBaseFontsFc(NULL);
}
DocumentData *doc = new DocumentData(new GooString(QFile::encodeName(filePath)), NULL);
......
......@@ -35,7 +35,6 @@ namespace Poppler {
{
if (!globalParams) {
globalParams = new GlobalParams("/etc/xpdfrc");
globalParams->setupBaseFontsFc(NULL);
}
DocumentData *doc = new DocumentData(new GooString(QFile::encodeName(filePath)), NULL, NULL);
......
......@@ -268,7 +268,6 @@ main (int argc, char *argv [])
gtk_init (&argc, &argv);
globalParams = new GlobalParams("/etc/xpdfrc");
globalParams->setupBaseFonts(NULL);
if (argc == 1)
{
......
......@@ -279,7 +279,6 @@ main (int argc, char *argv [])
gtk_init (&argc, &argv);
globalParams = new GlobalParams("/etc/xpdfrc");
globalParams->setupBaseFonts(NULL);
if (argc == 1)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment