summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/fitz/font.h2
-rw-r--r--source/fitz/font.c19
2 files changed, 12 insertions, 9 deletions
diff --git a/include/mupdf/fitz/font.h b/include/mupdf/fitz/font.h
index 712a9782..b6ea3362 100644
--- a/include/mupdf/fitz/font.h
+++ b/include/mupdf/fitz/font.h
@@ -67,7 +67,7 @@ struct fz_font_s
float *advance_cache;
/* cached encoding lookup */
- uint16_t *encoding_cache;
+ uint16_t *encoding_cache[256];
};
/* common CJK font collections */
diff --git a/source/fitz/font.c b/source/fitz/font.c
index 5b29f30c..600253eb 100644
--- a/source/fitz/font.c
+++ b/source/fitz/font.c
@@ -7,7 +7,6 @@
#define MAX_BBOX_TABLE_SIZE 4096
#define MAX_ADVANCE_CACHE 4096
-#define MAX_ENCODING_CACHE 2304 /* covers latin, greek, cyrillic, hebrew and arabic */
/* 20 degrees */
#define SHEAR 0.36397f
@@ -145,12 +144,14 @@ fz_drop_font(fz_context *ctx, fz_font *font)
fz_drop_freetype(ctx);
}
+ for (i = 0; i < 256; ++i)
+ fz_free(ctx, font->encoding_cache[i]);
+
fz_drop_buffer(ctx, font->ft_buffer);
fz_free(ctx, font->ft_filepath);
fz_free(ctx, font->bbox_table);
fz_free(ctx, font->width_table);
fz_free(ctx, font->advance_cache);
- fz_free(ctx, font->encoding_cache);
fz_free(ctx, font);
}
@@ -1348,16 +1349,18 @@ fz_encode_character(fz_context *ctx, fz_font *font, int ucs)
{
if (font->ft_face)
{
- if (ucs >= 0 && ucs < MAX_ENCODING_CACHE)
+ if (ucs >= 0 && ucs < 0x10000)
{
- if (!font->encoding_cache)
+ int pg = ucs >> 8;
+ int ix = ucs & 0xFF;
+ if (!font->encoding_cache[pg])
{
int i;
- font->encoding_cache = fz_malloc_array(ctx, MAX_ENCODING_CACHE, sizeof(uint16_t));
- for (i = 0; i < MAX_ENCODING_CACHE; ++i)
- font->encoding_cache[i] = FT_Get_Char_Index(font->ft_face, i);
+ font->encoding_cache[pg] = fz_malloc_array(ctx, 256, sizeof(uint16_t));
+ for (i = 0; i < 256; ++i)
+ font->encoding_cache[pg][i] = FT_Get_Char_Index(font->ft_face, (pg << 8) + i);
}
- return font->encoding_cache[ucs];
+ return font->encoding_cache[pg][ix];
}
return FT_Get_Char_Index(font->ft_face, ucs);
}