summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/fitz/font.h3
-rw-r--r--source/fitz/font.c15
-rw-r--r--source/pdf/pdf-font.c15
3 files changed, 24 insertions, 9 deletions
diff --git a/include/mupdf/fitz/font.h b/include/mupdf/fitz/font.h
index 3a4dccf0..32d76110 100644
--- a/include/mupdf/fitz/font.h
+++ b/include/mupdf/fitz/font.h
@@ -58,7 +58,8 @@ struct fz_font_s
/* substitute metrics */
int width_count;
- int *width_table; /* in 1000 units */
+ short width_default; /* in 1000 units */
+ short *width_table; /* in 1000 units */
};
/* common CJK font collections */
diff --git a/source/fitz/font.c b/source/fitz/font.c
index 6d703659..387e3617 100644
--- a/source/fitz/font.c
+++ b/source/fitz/font.c
@@ -410,7 +410,7 @@ static fz_matrix *
fz_adjust_ft_glyph_width(fz_context *ctx, fz_font *font, int gid, fz_matrix *trm)
{
/* Fudge the font matrix to stretch the glyph if we've substituted the font. */
- if (font->ft_substitute && font->width_table && gid < font->width_count /* && font->wmode == 0 */)
+ if (font->ft_substitute && font->width_table /* && font->wmode == 0 */)
{
FT_Error fterr;
int subw;
@@ -430,7 +430,10 @@ fz_adjust_ft_glyph_width(fz_context *ctx, fz_font *font, int gid, fz_matrix *trm
realw = ((FT_Face)font->ft_face)->glyph->metrics.horiAdvance;
fz_unlock(ctx, FZ_LOCK_FREETYPE);
- subw = font->width_table[gid];
+ if (gid < font->width_count)
+ subw = font->width_table[gid];
+ else
+ subw = font->width_default;
if (realw)
scale = (float) subw / realw;
else
@@ -1300,8 +1303,12 @@ fz_advance_ft_glyph(fz_context *ctx, fz_font *font, int gid)
FT_Fixed adv;
int mask;
- if (font->ft_substitute && font->width_table && gid < font->width_count)
- return font->width_table[gid];
+ if (font->width_table)
+ {
+ if (gid < font->width_count)
+ return font->width_table[gid] / 1000.0f;
+ return font->width_default / 1000.0f;
+ }
mask = FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING | FT_LOAD_IGNORE_TRANSFORM;
/* if (font->wmode)
diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c
index 35e61f93..38dd2b58 100644
--- a/source/pdf/pdf-font.c
+++ b/source/pdf/pdf-font.c
@@ -1187,13 +1187,17 @@ pdf_make_width_table(fz_context *ctx, pdf_font_desc *fontdesc)
if (gid > n)
n = gid;
}
- };
+ }
font->width_count = n + 1;
font->width_table = fz_malloc_array(ctx, font->width_count, sizeof(int));
memset(font->width_table, 0, font->width_count * sizeof(int));
fontdesc->size += font->width_count * sizeof(int);
+ font->width_default = fontdesc->dhmtx.w;
+ for (i = 0; i < font->width_count; i++)
+ font->width_table[i] = -1;
+
for (i = 0; i < fontdesc->hmtx_len; i++)
{
for (k = fontdesc->hmtx[i].lo; k <= fontdesc->hmtx[i].hi; k++)
@@ -1204,6 +1208,10 @@ pdf_make_width_table(fz_context *ctx, pdf_font_desc *fontdesc)
font->width_table[gid] = fz_maxi(fontdesc->hmtx[i].w, font->width_table[gid]);
}
}
+
+ for (i = 0; i < font->width_count; i++)
+ if (font->width_table[i] == -1)
+ font->width_table[i] = font->width_default;
}
pdf_font_desc *
@@ -1254,9 +1262,8 @@ pdf_load_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, i
fontdesc = pdf_load_simple_font(ctx, doc, dict);
}
- /* Save the widths to stretch non-CJK substitute fonts */
- if (fontdesc->font->ft_substitute && !fontdesc->to_ttf_cmap)
- pdf_make_width_table(ctx, fontdesc);
+ /* Create glyph width table for stretching substitute fonts and text extraction. */
+ pdf_make_width_table(ctx, fontdesc);
pdf_store_item(ctx, dict, fontdesc, fontdesc->size);