[poppler] 2 commits - poppler/SplashOutputDev.cc qt4/tests splash/SplashFontFile.cc splash/SplashFontFile.h splash/SplashFont.h splash/SplashFTFont.cc splash/SplashFTFont.h
Albert Astals Cid
aacid at kemper.freedesktop.org
Tue Jan 29 14:47:12 PST 2008
poppler/SplashOutputDev.cc | 37 +++++++++++++++++++++++++++
qt4/tests/test-poppler-qt4.cpp | 2 +
splash/SplashFTFont.cc | 55 ++++++++++++++++++++++++++++++++++++++++-
splash/SplashFTFont.h | 4 ++
splash/SplashFont.h | 4 ++
splash/SplashFontFile.cc | 1
splash/SplashFontFile.h | 2 +
7 files changed, 104 insertions(+), 1 deletion(-)
New commits:
commit 4c738cc6bd51f9d9e23ba83949c490c5c8691345
Author: Albert Astals Cid <aacid at kde.org>
Date: Tue Jan 29 23:45:52 2008 +0100
Scale text to match 'm' size
Fixes bug 12304
diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc
index c810dc7..5315bfc 100644
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -965,6 +965,7 @@ void SplashOutputDev::doUpdateFont(GfxState *state) {
SplashCoord mat[4];
int substIdx, n;
int faceIndex = 0;
+ GBool recreateFont = gFalse;
needFontUpdate = gFalse;
font = NULL;
@@ -1142,6 +1143,7 @@ void SplashOutputDev::doUpdateFont(GfxState *state) {
// this shouldn't happen
goto err2;
}
+ fontFile->doAdjustMatrix = gTrue;
}
// get the font matrix
@@ -1157,6 +1159,41 @@ void SplashOutputDev::doUpdateFont(GfxState *state) {
mat[2] = m21; mat[3] = m22;
font = fontEngine->getFont(fontFile, mat, splash->getMatrix());
+ // for substituted fonts: adjust the font matrix -- compare the
+ // width of 'm' in the original font and the substituted font
+ if (fontFile->doAdjustMatrix && !gfxFont->isCIDFont()) {
+ double w1, w2;
+ CharCode code;
+ char *name;
+ 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 = font->getGlyphAdvance(code);
+ if (!gfxFont->isSymbolic() && w2 > 0) {
+ // 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;
+ recreateFont = gTrue;
+ }
+ }
+ }
+ }
+
+ if (recreateFont)
+ {
+ mat[0] = m11; mat[1] = m12;
+ mat[2] = m21; mat[3] = m22;
+ font = fontEngine->getFont(fontFile, mat, splash->getMatrix());
+ }
+
if (fontsrc && !fontsrc->isFile)
fontsrc->unref();
return;
diff --git a/splash/SplashFTFont.cc b/splash/SplashFTFont.cc
index 0241df0..28e48d7 100644
--- a/splash/SplashFTFont.cc
+++ b/splash/SplashFTFont.cc
@@ -42,7 +42,7 @@ SplashFTFont::SplashFTFont(SplashFTFontFile *fontFileA, SplashCoord *matA,
SplashFont(fontFileA, matA, textMatA, fontFileA->engine->aa)
{
FT_Face face;
- double size, div;
+ double div;
int x, y;
face = fontFileA->face;
@@ -239,6 +239,59 @@ GBool SplashFTFont::makeGlyph(int c, int xFrac, int yFrac,
return gTrue;
}
+double SplashFTFont::getGlyphAdvance(int c)
+{
+ SplashFTFontFile *ff;
+ FT_Vector offset;
+ FT_UInt gid;
+ FT_Matrix identityMatrix;
+
+ ff = (SplashFTFontFile *)fontFile;
+
+ // init the matrix
+ identityMatrix.xx = 65536; // 1 in 16.16 format
+ identityMatrix.xy = 0;
+ identityMatrix.yx = 0;
+ identityMatrix.yy = 65536; // 1 in 16.16 format
+
+ // init the offset
+ offset.x = 0;
+ offset.y = 0;
+
+ FT_Set_Transform(ff->face, &identityMatrix, &offset);
+
+ if (ff->codeToGID && c < ff->codeToGIDLen) {
+ gid = (FT_UInt)ff->codeToGID[c];
+ } else {
+ gid = (FT_UInt)c;
+ }
+ if (ff->trueType && gid == 0) {
+ // skip the TrueType notdef glyph
+ return -1;
+ }
+
+ // if we have the FT2 bytecode interpreter, autohinting won't be used
+#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
+ if (FT_Load_Glyph(ff->face, gid,
+ aa ? FT_LOAD_NO_BITMAP : FT_LOAD_DEFAULT)) {
+ return -1;
+ }
+#else
+ // FT2's autohinting doesn't always work very well (especially with
+ // font subsets), so turn it off if anti-aliasing is enabled; if
+ // anti-aliasing is disabled, this seems to be a tossup - some fonts
+ // look better with hinting, some without, so leave hinting on
+ if (FT_Load_Glyph(ff->face, gid,
+ aa ? FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP
+ : FT_LOAD_DEFAULT)) {
+ return -1;
+ }
+#endif
+
+ // 64.0 is 1 in 26.6 format
+ return ff->face->glyph->metrics.horiAdvance / 64.0 / size;
+}
+
struct SplashFTFontPath {
SplashPath *path;
SplashCoord textScale;
diff --git a/splash/SplashFTFont.h b/splash/SplashFTFont.h
index 70c01d3..4e22026 100644
--- a/splash/SplashFTFont.h
+++ b/splash/SplashFTFont.h
@@ -43,12 +43,16 @@ public:
// Return the path for a glyph.
virtual SplashPath *getGlyphPath(int c);
+ // Return the advance of a glyph. (in 0..1 range)
+ virtual double getGlyphAdvance(int c);
+
private:
FT_Size sizeObj;
FT_Matrix matrix;
FT_Matrix textMatrix;
SplashCoord textScale;
+ double size;
};
#endif // HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
diff --git a/splash/SplashFont.h b/splash/SplashFont.h
index 3af9412..f59b3a1 100644
--- a/splash/SplashFont.h
+++ b/splash/SplashFont.h
@@ -75,6 +75,10 @@ public:
// Return the path for a glyph.
virtual SplashPath *getGlyphPath(int c) = 0;
+ // Return the advance of a glyph. (in 0..1 range)
+ // < 0 means not known
+ virtual double getGlyphAdvance(int c) { return -1; }
+
// Return the font transform matrix.
SplashCoord *getMatrix() { return mat; }
diff --git a/splash/SplashFontFile.cc b/splash/SplashFontFile.cc
index 1c70d3c..80c99ae 100644
--- a/splash/SplashFontFile.cc
+++ b/splash/SplashFontFile.cc
@@ -34,6 +34,7 @@ SplashFontFile::SplashFontFile(SplashFontFileID *idA, SplashFontSrc *srcA) {
src = srcA;
src->ref();
refCnt = 0;
+ doAdjustMatrix = gFalse;
}
SplashFontFile::~SplashFontFile() {
diff --git a/splash/SplashFontFile.h b/splash/SplashFontFile.h
index 1e4639e..e04e28c 100644
--- a/splash/SplashFontFile.h
+++ b/splash/SplashFontFile.h
@@ -62,6 +62,8 @@ public:
// the SplashFontFile object.
void decRefCnt();
+ GBool doAdjustMatrix;
+
protected:
SplashFontFile(SplashFontFileID *idA, SplashFontSrc *srcA);
commit 64f16cf6ebf2870852fe8d937b25be58869ad40a
Author: Albert Astals Cid <aacid at kde.org>
Date: Tue Jan 29 23:41:15 2008 +0100
Enable antialias by default on the test tool
diff --git a/qt4/tests/test-poppler-qt4.cpp b/qt4/tests/test-poppler-qt4.cpp
index 299335d..6fba0a0 100644
--- a/qt4/tests/test-poppler-qt4.cpp
+++ b/qt4/tests/test-poppler-qt4.cpp
@@ -35,6 +35,8 @@ PDFDisplay::PDFDisplay( Poppler::Document *d, bool arthur )
backendString = "Splash";
doc->setRenderBackend(Poppler::Document::SplashBackend);
}
+ doc->setRenderHint(Poppler::Document::Antialiasing, true);
+ doc->setRenderHint(Poppler::Document::TextAntialiasing, true);
display();
}
More information about the poppler
mailing list