diff options
author | Tor Andersson <tor@ghostscript.com> | 2004-11-18 08:59:46 +0100 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2004-11-18 08:59:46 +0100 |
commit | ff0bcfe322c6ba8910105780544f498bff23bcd4 (patch) | |
tree | 63d846b0b660064533ede43e2cd42b9b9c46e0b0 | |
parent | 88074516976927dbb436888c47ff25ef53578a0d (diff) | |
download | mupdf-ff0bcfe322c6ba8910105780544f498bff23bcd4.tar.xz |
workaround freetype rounding behavior
-rw-r--r-- | base/matrix.c | 6 | ||||
-rw-r--r-- | include/fitz/geometry.h | 1 | ||||
-rw-r--r-- | mupdf/font.c | 47 | ||||
-rw-r--r-- | mupdf/stream.c | 7 |
4 files changed, 48 insertions, 13 deletions
diff --git a/base/matrix.c b/base/matrix.c index 43c3f4e1..09a2de0f 100644 --- a/base/matrix.c +++ b/base/matrix.c @@ -76,6 +76,12 @@ fz_isrectilinear(fz_matrix m) (fabs(m.a) < FLT_EPSILON && fabs(m.d) < FLT_EPSILON); } +float +fz_matrixexpansion(fz_matrix m) +{ + return sqrt(fabs(m.a * m.d - m.b * m.c)); +} + fz_point fz_transformpoint(fz_matrix m, fz_point p) { diff --git a/include/fitz/geometry.h b/include/fitz/geometry.h index 8909b229..af734f72 100644 --- a/include/fitz/geometry.h +++ b/include/fitz/geometry.h @@ -45,6 +45,7 @@ fz_matrix fz_rotate(float theta); fz_matrix fz_translate(float tx, float ty); fz_matrix fz_invertmatrix(fz_matrix m); int fz_isrectilinear(fz_matrix m); +float fz_matrixexpansion(fz_matrix m); fz_rect fz_intersectrects(fz_rect a, fz_rect b); fz_rect fz_mergerects(fz_rect a, fz_rect b); diff --git a/mupdf/font.c b/mupdf/font.c index 7c2346e3..b3fb6fc7 100644 --- a/mupdf/font.c +++ b/mupdf/font.c @@ -1,6 +1,8 @@ #include <fitz.h> #include <mupdf.h> +#define noHINT + #include <ft2build.h> #include FT_FREETYPE_H #include <freetype/internal/ftobjs.h> @@ -76,6 +78,7 @@ ftrender(fz_glyph *glyph, fz_font *fzfont, int cid, fz_matrix trm) FT_Matrix m; FT_Vector v; FT_Error fterr; + float scale; int gid; if (font->cidtogid) @@ -87,7 +90,6 @@ ftrender(fz_glyph *glyph, fz_font *fzfont, int cid, fz_matrix trm) { fz_hmtx subw; int realw; - float scale; FT_Set_Char_Size(face, 1000, 1000, 72, 72); @@ -104,8 +106,6 @@ ftrender(fz_glyph *glyph, fz_font *fzfont, int cid, fz_matrix trm) scale = 1.0; trm = fz_concat(fz_scale(scale, 1.0), trm); - - FT_Set_Char_Size(face, 64, 64, 72, 72); } glyph->w = 0; @@ -114,20 +114,47 @@ ftrender(fz_glyph *glyph, fz_font *fzfont, int cid, fz_matrix trm) glyph->top = 0; glyph->bitmap = nil; - m.xx = trm.a * 65536; - m.yx = trm.b * 65536; - m.xy = trm.c * 65536; - m.yy = trm.d * 65536; + /* freetype mutilates complex glyphs if they are loaded + * with FT_Set_Char_Size 1.0. it rounds the coordinates + * before applying transformation. to get more precision in + * freetype, we shift part of the scale in the matrix + * into FT_Set_Char_Size instead + */ + +#ifdef HINT + scale = fz_matrixexpansion(trm); + m.xx = trm.a * 65536 / scale; + m.yx = trm.b * 65536 / scale; + m.xy = trm.c * 65536 / scale; + m.yy = trm.d * 65536 / scale; + v.x = 0; + v.y = 0; + + FT_Set_Char_Size(face, 64 * scale, 64 * scale, 72, 72); + FT_Set_Transform(face, &m, &v); + + fterr = FT_Load_Glyph(face, gid, FT_LOAD_NO_BITMAP); + if (fterr) + return fz_throw("freetype failed to load glyph: 0x%x", fterr); + +#else + + m.xx = trm.a * 64; /* should be 65536 */ + m.yx = trm.b * 64; + m.xy = trm.c * 64; + m.yy = trm.d * 64; v.x = trm.e * 64; v.y = trm.f * 64; - FT_Set_Char_Size(face, 64, 64, 72, 72); + FT_Set_Char_Size(face, 65536, 65536, 72, 72); /* should be 64, 64 */ FT_Set_Transform(face, &m, &v); fterr = FT_Load_Glyph(face, gid, FT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING); if (fterr) return fz_throw("freetype failed to load glyph: 0x%x", fterr); +#endif + fterr = FT_Render_Glyph(face->glyph, ft_render_mode_normal); if (fterr) return fz_throw("freetype failed to render glyph: 0x%x", fterr); @@ -489,8 +516,6 @@ printf(" builtin widths\n"); if (error) goto cleanup; - FT_Set_Char_Size(face, 64, 64, 72, 72); - printf("\n"); return nil; @@ -772,8 +797,6 @@ printf(" cidtogidmap %d\n", len / 2); goto cleanup; } - FT_Set_Char_Size(face, 64, 64, 72, 72); - printf("\n"); return nil; diff --git a/mupdf/stream.c b/mupdf/stream.c index 3ccb61b3..8d2cf5a1 100644 --- a/mupdf/stream.c +++ b/mupdf/stream.c @@ -299,9 +299,14 @@ makedecodefilter(fz_filter **filterp, pdf_xref *xref, fz_obj *stmobj, int oid, i fz_dropobj(params); fz_dropobj(filters); + + *filterp = pipe; + } + else + { + *filterp = base; } - *filterp = pipe; return nil; cleanup2: |