summaryrefslogtreecommitdiff
path: root/splash
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2008-01-29 23:45:52 +0100
committerAlbert Astals Cid <aacid@kde.org>2008-01-29 23:45:52 +0100
commit4c738cc6bd51f9d9e23ba83949c490c5c8691345 (patch)
treee6d5cfe82d87100b301c3bae0efda86b2e5926b4 /splash
parent64f16cf6ebf2870852fe8d937b25be58869ad40a (diff)
Scale text to match 'm' size
Fixes bug 12304
Diffstat (limited to 'splash')
-rw-r--r--splash/SplashFTFont.cc55
-rw-r--r--splash/SplashFTFont.h4
-rw-r--r--splash/SplashFont.h4
-rw-r--r--splash/SplashFontFile.cc1
-rw-r--r--splash/SplashFontFile.h2
5 files changed, 65 insertions, 1 deletions
diff --git a/splash/SplashFTFont.cc b/splash/SplashFTFont.cc
index 0241df01..28e48d79 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 70c01d38..4e220263 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 3af9412a..f59b3a1e 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 1c70d3c8..80c99ae0 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 1e4639eb..e04e28cd 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);