summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-04-15 11:29:02 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-04-15 11:33:53 +0200
commit68ddf2e5505b3b6295f2373fdac8a5b296bb441c (patch)
treed8890ffad8dd2cc82ac898e377af82fb052eff15
parent33a189cce63587e52d76bffadcd547a55818cf92 (diff)
downloadmupdf-68ddf2e5505b3b6295f2373fdac8a5b296bb441c.tar.xz
Use artificial italics and emboldening for substitute font.
-rw-r--r--fitz/base_geometry.c10
-rw-r--r--fitz/fitz.h1
-rw-r--r--fitz/res_font.c19
-rw-r--r--pdf/pdf_font.c16
4 files changed, 42 insertions, 4 deletions
diff --git a/fitz/base_geometry.c b/fitz/base_geometry.c
index bd333dfa..302ef966 100644
--- a/fitz/base_geometry.c
+++ b/fitz/base_geometry.c
@@ -31,6 +31,16 @@ fz_scale(float sx, float sy)
}
fz_matrix
+fz_shear(float h, float v)
+{
+ fz_matrix m;
+ m.a = 1; m.b = v;
+ m.c = h; m.d = 1;
+ m.e = 0; m.f = 0;
+ return m;
+}
+
+fz_matrix
fz_rotate(float theta)
{
fz_matrix m;
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 3e08a680..9ba9d0b1 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -252,6 +252,7 @@ extern const fz_matrix fz_identity;
fz_matrix fz_concat(fz_matrix one, fz_matrix two);
fz_matrix fz_scale(float sx, float sy);
+fz_matrix fz_shear(float sx, float sy);
fz_matrix fz_rotate(float theta);
fz_matrix fz_translate(float tx, float ty);
fz_matrix fz_invert_matrix(fz_matrix m);
diff --git a/fitz/res_font.c b/fitz/res_font.c
index b564b45b..e255c406 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -13,7 +13,11 @@ fz_new_font(char *name)
font = fz_malloc(sizeof(fz_font));
font->refs = 1;
- fz_strlcpy(font->name, name, sizeof font->name);
+
+ if (name)
+ fz_strlcpy(font->name, name, sizeof font->name);
+ else
+ fz_strlcpy(font->name, "(null)", sizeof font->name);
font->ft_face = NULL;
font->ft_substitute = 0;
@@ -316,6 +320,9 @@ fz_render_ft_glyph(fz_font *font, int gid, fz_matrix trm)
trm = fz_adjust_ft_glyph_width(font, gid, trm);
+ if (font->ft_italic)
+ trm = fz_concat(fz_shear(0.3f, 0), trm);
+
/*
Freetype mutilates complex glyphs if they are loaded
with FT_Set_Char_Size 1.0. it rounds the coordinates
@@ -378,6 +385,13 @@ fz_render_ft_glyph(fz_font *font, int gid, fz_matrix trm)
}
}
+ if (font->ft_bold)
+ {
+ float strength = fz_matrix_expansion(trm) * 0.04f;
+ FT_Outline_Embolden(&face->glyph->outline, strength * 64);
+ FT_Outline_Translate(&face->glyph->outline, -strength * 32, -strength * 32);
+ }
+
fterr = FT_Render_Glyph(face->glyph, fz_get_aa_level() > 0 ? ft_render_mode_normal : ft_render_mode_mono);
if (fterr)
{
@@ -404,6 +418,9 @@ fz_render_ft_stroked_glyph(fz_font *font, int gid, fz_matrix trm, fz_matrix ctm,
trm = fz_adjust_ft_glyph_width(font, gid, trm);
+ if (font->ft_italic)
+ trm = fz_concat(fz_shear(0.3f, 0), trm);
+
m.xx = trm.a * 64; /* should be 65536 */
m.yx = trm.b * 64;
m.xy = trm.c * 64;
diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c
index d0a67b31..36c23d0e 100644
--- a/pdf/pdf_font.c
+++ b/pdf/pdf_font.c
@@ -99,6 +99,16 @@ static int ft_kind(FT_Face face)
return UNKNOWN;
}
+static int ft_is_bold(FT_Face face)
+{
+ return face->style_flags & FT_STYLE_FLAG_BOLD;
+}
+
+static int ft_is_italic(FT_Face face)
+{
+ return face->style_flags & FT_STYLE_FLAG_ITALIC;
+}
+
static int ft_char_index(FT_Face face, int cid)
{
int gid = FT_Get_Char_Index(face, cid);
@@ -197,8 +207,8 @@ pdf_load_substitute_font(pdf_font_desc *fontdesc, int mono, int serif, int bold,
return fz_rethrow(error, "cannot load freetype font from memory");
fontdesc->font->ft_substitute = 1;
- fontdesc->font->ft_bold = bold;
- fontdesc->font->ft_italic = italic;
+ fontdesc->font->ft_bold = bold && !ft_is_bold(fontdesc->font->ft_face);
+ fontdesc->font->ft_italic = italic && !ft_is_italic(fontdesc->font->ft_face);
return fz_okay;
}
@@ -261,7 +271,7 @@ pdf_load_system_font(pdf_font_desc *fontdesc, char *fontname, char *collection)
error = pdf_load_substitute_font(fontdesc, mono, serif, bold, italic);
if (error)
- return fz_throw("cannot load substitute font");
+ return fz_rethrow(error, "cannot load substitute font");
return fz_okay;
}