diff options
-rw-r--r-- | include/mupdf/fitz/font.h | 58 | ||||
-rw-r--r-- | platform/win32/libmupdf.vcproj | 4 | ||||
-rw-r--r-- | source/fitz/draw-glyph.c | 20 | ||||
-rw-r--r-- | source/fitz/font-impl.h | 50 | ||||
-rw-r--r-- | source/fitz/font.c | 92 | ||||
-rw-r--r-- | source/fitz/stext-device.c | 18 | ||||
-rw-r--r-- | source/fitz/stext-output.c | 23 | ||||
-rw-r--r-- | source/fitz/svg-device.c | 2 | ||||
-rw-r--r-- | source/fitz/trace-device.c | 2 | ||||
-rw-r--r-- | source/html/html-font.c | 11 | ||||
-rw-r--r-- | source/html/html-layout.c | 17 | ||||
-rw-r--r-- | source/pdf/pdf-device.c | 6 | ||||
-rw-r--r-- | source/pdf/pdf-font.c | 34 | ||||
-rw-r--r-- | source/pdf/pdf-op-run.c | 2 | ||||
-rw-r--r-- | source/pdf/pdf-type3.c | 36 | ||||
-rw-r--r-- | source/tools/murun.c | 2 | ||||
-rw-r--r-- | source/xps/xps-glyphs.c | 23 |
17 files changed, 243 insertions, 157 deletions
diff --git a/include/mupdf/fitz/font.h b/include/mupdf/fitz/font.h index 2547e7a0..69959908 100644 --- a/include/mupdf/fitz/font.h +++ b/include/mupdf/fitz/font.h @@ -6,6 +6,9 @@ #include "mupdf/fitz/math.h" #include "mupdf/fitz/buffer.h" +/* forward declaration for circular dependency */ +struct fz_device_s; + /* An abstract font handle. Currently there are no public API functions for handling these. @@ -20,16 +23,11 @@ typedef struct fz_font_s fz_font; char *ft_error_string(int err); -/* forward declaration for circular dependency */ -struct fz_device_s; -struct fz_display_list_s; +/* common CJK font collections */ +enum { FZ_ADOBE_CNS_1, FZ_ADOBE_GB_1, FZ_ADOBE_JAPAN_1, FZ_ADOBE_KOREA_1 }; -struct fz_font_s +typedef struct { - int refs; - char name[32]; - fz_buffer *buffer; - unsigned int is_mono : 1; unsigned int is_serif : 1; unsigned int is_bold : 1; @@ -43,42 +41,22 @@ struct fz_font_s unsigned int has_opentype : 1; /* has opentype shaping tables */ unsigned int invalid_bbox : 1; unsigned int use_glyph_bbox : 1; +} fz_font_flags_t; - void *ft_face; /* has an FT_Face if used */ - void *hb_font; /* hb_font for shaping */ - void (*hb_destroy)(void *); /* Destructor for hb_font */ +fz_font_flags_t *fz_font_flags(fz_font *font); - fz_matrix t3matrix; - void *t3resources; - fz_buffer **t3procs; /* has 256 entries if used */ - struct fz_display_list_s **t3lists; /* has 256 entries if used */ - float *t3widths; /* has 256 entries if used */ - unsigned short *t3flags; /* has 256 entries if used */ - void *t3doc; /* a pdf_document for the callback */ - void (*t3run)(fz_context *ctx, void *doc, void *resources, fz_buffer *contents, struct fz_device_s *dev, const fz_matrix *ctm, void *gstate, int nestedDepth); - void (*t3freeres)(fz_context *ctx, void *doc, void *resources); - - fz_rect bbox; /* font bbox is used only for t3 fonts */ - - int glyph_count; - - /* per glyph bounding box cache */ - fz_rect *bbox_table; - - /* substitute metrics */ - int width_count; - short width_default; /* in 1000 units */ - short *width_table; /* in 1000 units */ - - /* cached glyph metrics */ - float *advance_cache; +typedef struct +{ + void *font; /* hb_font for shaping */ + void (*destroy)(void *); /* Destructor for hb_font */ +} fz_hb_t; - /* cached encoding lookup */ - uint16_t *encoding_cache[256]; -}; +fz_hb_t *fz_font_hb(fz_font *font); -/* common CJK font collections */ -enum { FZ_ADOBE_CNS_1, FZ_ADOBE_GB_1, FZ_ADOBE_JAPAN_1, FZ_ADOBE_KOREA_1 }; +const char *fz_font_name(fz_font *font); +void *fz_font_ft_face(fz_font *font); +fz_buffer **fz_font_t3_procs(fz_font *font); +fz_rect *fz_font_bbox(fz_font *font); void fz_new_font_context(fz_context *ctx); fz_font_context *fz_keep_font_context(fz_context *ctx); diff --git a/platform/win32/libmupdf.vcproj b/platform/win32/libmupdf.vcproj index c3f0bc7a..08ed1469 100644 --- a/platform/win32/libmupdf.vcproj +++ b/platform/win32/libmupdf.vcproj @@ -1277,6 +1277,10 @@ > </File> <File + RelativePath="..\..\source\fitz\font-impl.h" + > + </File> + <File RelativePath="..\..\source\fitz\font.c" > </File> diff --git a/source/fitz/draw-glyph.c b/source/fitz/draw-glyph.c index dbaace9e..93bd62b3 100644 --- a/source/fitz/draw-glyph.c +++ b/source/fitz/draw-glyph.c @@ -175,7 +175,7 @@ fz_subpixel_adjust(fz_context *ctx, fz_matrix *ctm, fz_matrix *subpix_ctm, unsig fz_glyph * fz_render_stroked_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix *trm, const fz_matrix *ctm, const fz_stroke_state *stroke, const fz_irect *scissor) { - if (font->ft_face) + if (fz_font_ft_face(font)) { fz_matrix subpix_trm; unsigned char qe, qf; @@ -191,7 +191,7 @@ fz_render_stroked_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix *trm, fz_pixmap * fz_render_stroked_glyph_pixmap(fz_context *ctx, fz_font *font, int gid, fz_matrix *trm, const fz_matrix *ctm, const fz_stroke_state *stroke, const fz_irect *scissor) { - if (font->ft_face) + if (fz_font_ft_face(font)) { fz_matrix subpix_trm; unsigned char qe, qf; @@ -252,6 +252,7 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix *ctm, fz_colo int do_cache, locked, caching; fz_glyph_cache_entry *entry; unsigned hash; + int is_ft_font = !!fz_font_ft_face(font); fz_var(locked); fz_var(caching); @@ -266,7 +267,7 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix *ctm, fz_colo } else { - if (font->ft_face) + if (is_ft_font) return NULL; subpix_scissor.x0 = scissor->x0 - floorf(ctm->e); subpix_scissor.y0 = scissor->y0 - floorf(ctm->f); @@ -307,11 +308,11 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix *ctm, fz_colo fz_try(ctx) { - if (font->ft_face) + if (is_ft_font) { val = fz_render_ft_glyph(ctx, font, gid, &subpix_ctm, key.aa); } - else if (font->t3procs) + else if (fz_font_t3_procs(font)) { /* We drop the glyphcache here, and execute the t3 * glyph code. The danger here is that some other @@ -339,7 +340,7 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix *ctm, fz_colo /* If we throw an exception whilst caching, * just ignore the exception and carry on. */ caching = 1; - if (!font->ft_face) + if (!is_ft_font) { /* We had to unlock. Someone else might * have rendered in the meantime */ @@ -413,6 +414,7 @@ fz_render_glyph_pixmap(fz_context *ctx, fz_font *font, int gid, fz_matrix *ctm, unsigned char qe, qf; fz_matrix subpix_ctm; float size = fz_subpixel_adjust(ctx, ctm, &subpix_ctm, &qe, &qf); + int is_ft_font = !!fz_font_ft_face(font); if (size <= MAX_GLYPH_SIZE) { @@ -420,17 +422,17 @@ fz_render_glyph_pixmap(fz_context *ctx, fz_font *font, int gid, fz_matrix *ctm, } else { - if (font->ft_face) + if (is_ft_font) return NULL; } fz_try(ctx) { - if (font->ft_face) + if (is_ft_font) { val = fz_render_ft_glyph_pixmap(ctx, font, gid, &subpix_ctm, fz_text_aa_level(ctx)); } - else if (font->t3procs) + else if (fz_font_t3_procs(font)) { val = fz_render_t3_glyph_pixmap(ctx, font, gid, &subpix_ctm, NULL, scissor); } diff --git a/source/fitz/font-impl.h b/source/fitz/font-impl.h new file mode 100644 index 00000000..b6015172 --- /dev/null +++ b/source/fitz/font-impl.h @@ -0,0 +1,50 @@ +#ifndef MUPDF_FITZ_FONT_IMPL_H +#define MUPDF_FITZ_FONT_IMPL_H + +#include "mupdf/fitz/font.h" + +/* forward declaration for circular dependency */ +struct fz_device_s; +struct fz_display_list_s; + +struct fz_font_s +{ + int refs; + char name[32]; + fz_buffer *buffer; + + fz_font_flags_t flags; + + void *ft_face; /* has an FT_Face if used */ + fz_hb_t hb; + + fz_matrix t3matrix; + void *t3resources; + fz_buffer **t3procs; /* has 256 entries if used */ + struct fz_display_list_s **t3lists; /* has 256 entries if used */ + float *t3widths; /* has 256 entries if used */ + unsigned short *t3flags; /* has 256 entries if used */ + void *t3doc; /* a pdf_document for the callback */ + void (*t3run)(fz_context *ctx, void *doc, void *resources, fz_buffer *contents, struct fz_device_s *dev, const fz_matrix *ctm, void *gstate, int nestedDepth); + void (*t3freeres)(fz_context *ctx, void *doc, void *resources); + + fz_rect bbox; /* font bbox is used only for t3 fonts */ + + int glyph_count; + + /* per glyph bounding box cache */ + fz_rect *bbox_table; + + /* substitute metrics */ + int width_count; + short width_default; /* in 1000 units */ + short *width_table; /* in 1000 units */ + + /* cached glyph metrics */ + float *advance_cache; + + /* cached encoding lookup */ + uint16_t *encoding_cache[256]; +}; + +#endif diff --git a/source/fitz/font.c b/source/fitz/font.c index beab4c87..be0f38d7 100644 --- a/source/fitz/font.c +++ b/source/fitz/font.c @@ -1,5 +1,7 @@ #include "mupdf/fitz.h" +#include "font-impl.h" + #include <ft2build.h> #include "hb.h" #include "hb-ft.h" @@ -37,11 +39,11 @@ fz_new_font(fz_context *ctx, const char *name, int use_glyph_bbox, int glyph_cou fz_strlcpy(font->name, "(null)", sizeof font->name); font->ft_face = NULL; - font->ft_substitute = 0; - font->fake_bold = 0; - font->fake_italic = 0; - font->force_hinting = 0; - font->has_opentype = 0; + font->flags.ft_substitute = 0; + font->flags.fake_bold = 0; + font->flags.fake_italic = 0; + font->flags.force_hinting = 0; + font->flags.has_opentype = 0; font->t3matrix = fz_identity; font->t3resources = NULL; @@ -59,7 +61,7 @@ fz_new_font(fz_context *ctx, const char *name, int use_glyph_bbox, int glyph_cou font->glyph_count = glyph_count; - font->use_glyph_bbox = !!use_glyph_bbox; + font->flags.use_glyph_bbox = !!use_glyph_bbox; if (use_glyph_bbox && glyph_count <= MAX_BBOX_TABLE_SIZE) { font->bbox_table = fz_malloc_array(ctx, glyph_count, sizeof(fz_rect)); @@ -156,10 +158,10 @@ fz_drop_font(fz_context *ctx, fz_font *font) fz_free(ctx, font->bbox_table); fz_free(ctx, font->width_table); fz_free(ctx, font->advance_cache); - if (font->hb_destroy && font->hb_font) + if (font->hb.destroy && font->hb.font) { hb_lock(ctx); - font->hb_destroy(font->hb_font); + font->hb.destroy(font->hb.font); hb_unlock(ctx); } fz_free(ctx, font); @@ -176,7 +178,7 @@ fz_set_font_bbox(fz_context *ctx, fz_font *font, float xmin, float ymin, float x font->bbox.y0 = -1; font->bbox.x1 = 2; font->bbox.y1 = 2; - font->invalid_bbox = 1; + font->flags.invalid_bbox = 1; } else { @@ -475,23 +477,23 @@ fz_new_font_from_buffer(fz_context *ctx, const char *name, fz_buffer *buffer, in (float) face->bbox.xMax / face->units_per_EM, (float) face->bbox.yMax / face->units_per_EM); - font->is_mono = !!(face->face_flags & FT_FACE_FLAG_FIXED_WIDTH); - font->is_serif = 1; - font->is_bold = !!(face->style_flags & FT_STYLE_FLAG_BOLD); - font->is_italic = !!(face->style_flags & FT_STYLE_FLAG_ITALIC); + font->flags.is_mono = !!(face->face_flags & FT_FACE_FLAG_FIXED_WIDTH); + font->flags.is_serif = 1; + font->flags.is_bold = !!(face->style_flags & FT_STYLE_FLAG_BOLD); + font->flags.is_italic = !!(face->style_flags & FT_STYLE_FLAG_ITALIC); if (FT_IS_SFNT(face)) { os2 = FT_Get_Sfnt_Table(face, FT_SFNT_OS2); if (os2) - font->is_serif = !(os2->sFamilyClass & 2048); /* Class 8 is sans-serif */ + font->flags.is_serif = !(os2->sFamilyClass & 2048); /* Class 8 is sans-serif */ FT_Sfnt_Table_Info(face, 0, NULL, &n); for (i = 0; i < n; ++i) { FT_Sfnt_Table_Info(face, i, &tag, &size); if (tag == TTAG_GDEF || tag == TTAG_GPOS || tag == TTAG_GSUB) - font->has_opentype = 1; + font->flags.has_opentype = 1; } } @@ -532,7 +534,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_stretch && font->width_table /* && font->wmode == 0 */) + if (font->flags.ft_stretch && font->width_table /* && font->wmode == 0 */) { FT_Fixed adv; float subw; @@ -588,7 +590,7 @@ do_ft_render_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm fz_adjust_ft_glyph_width(ctx, font, gid, &local_trm); - if (font->fake_italic) + if (font->flags.fake_italic) fz_pre_shear(&local_trm, SHEAR, 0); /* @@ -633,7 +635,7 @@ do_ft_render_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm goto retry_unhinted; } } - else if (font->force_hinting) + else if (font->flags.force_hinting) { /* Enable hinting, but keep the huge char size so that @@ -659,7 +661,7 @@ retry_unhinted: } } - if (font->fake_bold) + if (font->flags.fake_bold) { FT_Outline_Embolden(&face->glyph->outline, strength * 64); FT_Outline_Translate(&face->glyph->outline, -strength * 32, -strength * 32); @@ -749,7 +751,7 @@ do_render_ft_stroked_glyph(fz_context *ctx, fz_font *font, int gid, const fz_mat fz_adjust_ft_glyph_width(ctx, font, gid, &local_trm); - if (font->fake_italic) + if (font->flags.fake_italic) fz_pre_shear(&local_trm, SHEAR, 0); m.xx = local_trm.a * 64; /* should be 65536 */ @@ -907,7 +909,7 @@ fz_bound_ft_glyph(fz_context *ctx, fz_font *font, int gid) fz_adjust_ft_glyph_width(ctx, font, gid, &local_trm); - if (font->fake_italic) + if (font->flags.fake_italic) fz_pre_shear(&local_trm, SHEAR, 0); m.xx = local_trm.a * 65536; @@ -917,7 +919,7 @@ fz_bound_ft_glyph(fz_context *ctx, fz_font *font, int gid) v.x = local_trm.e * 65536; v.y = local_trm.f * 65536; - if (font->force_hinting) + if (font->flags.force_hinting) { ft_flags = FT_LOAD_NO_BITMAP; } @@ -945,7 +947,7 @@ fz_bound_ft_glyph(fz_context *ctx, fz_font *font, int gid) return bounds; } - if (font->fake_bold) + if (font->flags.fake_bold) { FT_Outline_Embolden(&face->glyph->outline, strength * scale); FT_Outline_Translate(&face->glyph->outline, -strength * 0.5 * scale, -strength * 0.5 * scale); @@ -1047,12 +1049,12 @@ fz_outline_ft_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *tr fz_adjust_ft_glyph_width(ctx, font, gid, &local_trm); - if (font->fake_italic) + if (font->flags.fake_italic) fz_pre_shear(&local_trm, SHEAR, 0); fz_lock(ctx, FZ_LOCK_FREETYPE); - if (font->force_hinting) + if (font->flags.force_hinting) { ft_flags = FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM; fterr = FT_Set_Char_Size(face, scale, scale, 72, 72); @@ -1072,7 +1074,7 @@ fz_outline_ft_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *tr return NULL; } - if (font->fake_bold) + if (font->flags.fake_bold) { FT_Outline_Embolden(&face->glyph->outline, strength * scale); FT_Outline_Translate(&face->glyph->outline, -strength * 0.5 * scale, -strength * 0.5 * scale); @@ -1205,7 +1207,7 @@ fz_prepare_t3_glyph(fz_context *ctx, fz_font *font, int gid, int nested_depth) font->bbox_table[gid] = d1_rect; fz_transform_rect(&font->bbox_table[gid], &font->t3matrix); - if (font->invalid_bbox || !fz_contains_rect(&font->bbox, &d1_rect)) + if (font->flags.invalid_bbox || !fz_contains_rect(&font->bbox, &d1_rect)) { /* Either the font bbox is invalid, or the d1_rect returned is * incompatible with it. Either way, don't trust the d1 rect @@ -1352,7 +1354,7 @@ fz_print_font(fz_context *ctx, fz_output *out, fz_font *font) if (font->ft_face) { fz_printf(ctx, out, "\tfreetype face %p\n", font->ft_face); - if (font->ft_substitute) + if (font->flags.ft_substitute) fz_printf(ctx, out, "\tsubstitute font\n"); } @@ -1524,7 +1526,7 @@ fz_encode_character_with_fallback(fz_context *ctx, fz_font *user_font, int unico if (script == 0) script = ucdn_get_script(unicode); - font = fz_load_fallback_font(ctx, script, language, user_font->is_serif, user_font->is_bold, user_font->is_italic); + font = fz_load_fallback_font(ctx, script, language, user_font->flags.is_serif, user_font->flags.is_bold, user_font->flags.is_italic); if (font) { gid = fz_encode_character(ctx, font, unicode); @@ -1550,3 +1552,35 @@ fz_encode_character_with_fallback(fz_context *ctx, fz_font *user_font, int unico return *out_font = user_font, 0; } + +const char *fz_font_name(fz_font *font) +{ + if (font == NULL || font->name == NULL) + return ""; + return font->name; +} + +fz_buffer **fz_font_t3_procs(fz_font *font) +{ + return font ? font->t3procs : NULL; +} + +fz_rect *fz_font_bbox(fz_font *font) +{ + return font ? &font->bbox : NULL; +} + +void *fz_font_ft_face(fz_font *font) +{ + return font ? font->ft_face : NULL; +} + +fz_font_flags_t *fz_font_flags(fz_font *font) +{ + return font ? &font->flags : NULL; +} + +fz_hb_t *fz_font_hb(fz_font *font) +{ + return font ? &font->hb : NULL; +} diff --git a/source/fitz/stext-device.c b/source/fitz/stext-device.c index 909d0a46..88a9f669 100644 --- a/source/fitz/stext-device.c +++ b/source/fitz/stext-device.c @@ -784,7 +784,9 @@ static void fz_stext_extract(fz_context *ctx, fz_stext_device *dev, fz_text_span *span, const fz_matrix *ctm, fz_stext_style *style) { fz_font *font = span->font; - FT_Face face = font->ft_face; + FT_Face face = fz_font_ft_face(font); + fz_buffer **t3procs = fz_font_t3_procs(font); + fz_rect *bbox = fz_font_bbox(font); fz_matrix tm = span->trm; fz_matrix trm; float adv; @@ -800,26 +802,26 @@ fz_stext_extract(fz_context *ctx, fz_stext_device *dev, fz_text_span *span, cons if (style->wmode == 0) { - if (font->ft_face) + if (face) { fz_lock(ctx, FZ_LOCK_FREETYPE); - err = FT_Set_Char_Size(font->ft_face, 64, 64, 72, 72); + err = FT_Set_Char_Size(face, 64, 64, 72, 72); if (err) fz_warn(ctx, "freetype set character size: %s", ft_error_string(err)); ascender = (float)face->ascender / face->units_per_EM; descender = (float)face->descender / face->units_per_EM; fz_unlock(ctx, FZ_LOCK_FREETYPE); } - else if (font->t3procs && !fz_is_empty_rect(&font->bbox)) + else if (t3procs && !fz_is_empty_rect(bbox)) { - ascender = font->bbox.y1; - descender = font->bbox.y0; + ascender = bbox->y1; + descender = bbox->y0; } } else { - ascender = font->bbox.x1; - descender = font->bbox.x0; + ascender = bbox->x1; + descender = bbox->x0; } style->ascender = ascender; style->descender = descender; diff --git a/source/fitz/stext-output.c b/source/fitz/stext-output.c index f7ea0c24..39d97dc3 100644 --- a/source/fitz/stext-output.c +++ b/source/fitz/stext-output.c @@ -10,20 +10,22 @@ static int font_is_bold(fz_font *font) { - FT_Face face = font->ft_face; + FT_Face face = fz_font_ft_face(font); if (face && (face->style_flags & FT_STYLE_FLAG_BOLD)) return 1; - if (strstr(font->name, "Bold")) + if (strstr(fz_font_name(font), "Bold")) return 1; return 0; } static int font_is_italic(fz_font *font) { - FT_Face face = font->ft_face; + FT_Face face = fz_font_ft_face(font); + const char *name; if (face && (face->style_flags & FT_STYLE_FLAG_ITALIC)) return 1; - if (strstr(font->name, "Italic") || strstr(font->name, "Oblique")) + name = fz_font_name(font); + if (strstr(name, "Italic") || strstr(name, "Oblique")) return 1; return 0; } @@ -53,8 +55,9 @@ fz_print_style_end(fz_context *ctx, fz_output *out, fz_stext_style *style) static void fz_print_style(fz_context *ctx, fz_output *out, fz_stext_style *style) { - char *s = strchr(style->font->name, '+'); - s = s ? s + 1 : style->font->name; + const char *name = fz_font_name(style->font); + const char *s = strchr(name, '+'); + s = s ? s + 1 : name; fz_printf(ctx, out, "span.s%d{font-family:\"%s\";font-size:%gpt;", style->id, s, style->size); if (font_is_italic(style->font)) @@ -292,7 +295,7 @@ fz_print_stext_page_xml(fz_context *ctx, fz_output *out, fz_stext_page *page) { fz_stext_block *block = page->blocks[block_n].u.text; fz_stext_line *line; - char *s; + const char *s; fz_printf(ctx, out, "<block bbox=\"%g %g %g %g\">\n", block->bbox.x0, block->bbox.y0, block->bbox.x1, block->bbox.y1); @@ -304,6 +307,7 @@ fz_print_stext_page_xml(fz_context *ctx, fz_output *out, fz_stext_page *page) for (span = line->first_span; span; span = span->next) { fz_stext_style *style = NULL; + const char *name = NULL; int char_num; for (char_num = 0; char_num < span->len; char_num++) { @@ -315,8 +319,9 @@ fz_print_stext_page_xml(fz_context *ctx, fz_output *out, fz_stext_page *page) fz_printf(ctx, out, "</span>\n"); } style = ch->style; - s = strchr(style->font->name, '+'); - s = s ? s + 1 : style->font->name; + name = fz_font_name(style->font); + s = strchr(name, '+'); + s = s ? s + 1 : name; fz_printf(ctx, out, "<span bbox=\"%g %g %g %g\" font=\"%s\" size=\"%g\">\n", span->bbox.x0, span->bbox.y0, span->bbox.x1, span->bbox.y1, s, style->size); diff --git a/source/fitz/svg-device.c b/source/fitz/svg-device.c index b997653d..1484dddd 100644 --- a/source/fitz/svg-device.c +++ b/source/fitz/svg-device.c @@ -274,7 +274,7 @@ svg_dev_text_span(fz_context *ctx, svg_device *sdev, const fz_matrix *ctm, const fz_printf(ctx, out, " transform=\"matrix(%g,%g,%g,%g,%g,%g)\"", local_trm.a, local_trm.b, local_trm.c, local_trm.d, local_trm.e, local_trm.f); fz_printf(ctx, out, " font-size=\"%g\"", size); - fz_printf(ctx, out, " font-family=\"%s\"", span->font->name); + fz_printf(ctx, out, " font-family=\"%s\"", fz_font_name(span->font)); /* Leading (and repeated) whitespace presents a problem for SVG * text, so elide it here. */ diff --git a/source/fitz/trace-device.c b/source/fitz/trace-device.c index 0b77c075..86e059b5 100644 --- a/source/fitz/trace-device.c +++ b/source/fitz/trace-device.c @@ -38,7 +38,7 @@ static void fz_trace_text_span(fz_context *ctx, fz_output *out, fz_text_span *span) { int i; - fz_printf(ctx, out, "<span font=\"%s\" wmode=\"%d\"", span->font->name, span->wmode); + fz_printf(ctx, out, "<span font=\"%s\" wmode=\"%d\"", fz_font_name(span->font), span->wmode); fz_printf(ctx, out, " trm=\"%g %g %g %g\">\n", span->trm.a, span->trm.b, span->trm.c, span->trm.d); for (i = 0; i < span->len; i++) { diff --git a/source/html/html-font.c b/source/html/html-font.c index 3b8f7c72..01ec10f5 100644 --- a/source/html/html-font.c +++ b/source/html/html-font.c @@ -19,7 +19,7 @@ fz_load_html_default_font(fz_context *ctx, fz_html_font_set *set, const char *fa if (!data) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load html font: %s", real_family); set->fonts[idx] = fz_new_font_from_memory(ctx, NULL, data, size, 0, 1); - set->fonts[idx]->is_serif = !is_sans; + fz_font_flags(set->fonts[idx])->is_serif = !is_sans; } return set->fonts[idx]; } @@ -60,10 +60,11 @@ fz_load_html_font(fz_context *ctx, fz_html_font_set *set, const char *family, in if (data) { fz_font *font = fz_new_font_from_memory(ctx, NULL, data, size, 0, 0); - if (is_bold && !font->is_bold) - font->fake_bold = 1; - if (is_italic && !font->is_italic) - font->fake_italic = 1; + fz_font_flags_t *flags = fz_font_flags(font); + if (is_bold && !flags->is_bold) + flags->fake_bold = 1; + if (is_italic && !flags->is_italic) + flags->fake_italic = 1; fz_add_html_font_face(ctx, set, family, is_bold, is_italic, "<builtin>", font); fz_drop_font(ctx, font); return font; diff --git a/source/html/html-layout.c b/source/html/html-layout.c index e671c64d..2fe6de82 100644 --- a/source/html/html-layout.c +++ b/source/html/html-layout.c @@ -791,7 +791,7 @@ static int quick_ligature_mov(fz_context *ctx, string_walker *walker, unsigned i static int quick_ligature(fz_context *ctx, string_walker *walker, unsigned int i) { - if (walker->glyph_info[i].codepoint == 'f' && i + 1 < walker->glyph_count && !walker->font->is_mono) + if (walker->glyph_info[i].codepoint == 'f' && i + 1 < walker->glyph_count && !fz_font_flags(walker->font)->is_mono) { if (walker->glyph_info[i+1].codepoint == 'f') { @@ -873,13 +873,13 @@ static int walk_string(string_walker *walker) /* Disable harfbuzz shaping if script is common or LGC and there are no opentype tables. */ quickshape = 0; - if (walker->script <= 3 && !walker->rtl && !walker->font->has_opentype) + if (walker->script <= 3 && !walker->rtl && !fz_font_flags(walker->font)->has_opentype) quickshape = 1; hb_lock(ctx); fz_try(ctx) { - face = walker->font->ft_face; + face = fz_font_ft_face(walker->font); walker->scale = face->units_per_EM; fterr = FT_Set_Char_Size(face, walker->scale, walker->scale, 72, 72); if (fterr) @@ -899,11 +899,12 @@ static int walk_string(string_walker *walker) if (!quickshape) { - if (walker->font->hb_font == NULL) + fz_hb_t *hb = fz_font_hb(walker->font); + if (hb->font == NULL) { Memento_startLeaking(); /* HarfBuzz leaks harmlessly */ - walker->font->hb_destroy = (fz_hb_font_destructor_t *)hb_font_destroy; - walker->font->hb_font = hb_ft_font_create(face, NULL); + hb->destroy = (fz_hb_font_destructor_t *)hb_font_destroy; + hb->font = hb_ft_font_create(face, NULL); Memento_stopLeaking(); } @@ -911,7 +912,7 @@ static int walk_string(string_walker *walker) hb_buffer_guess_segment_properties(walker->hb_buf); Memento_stopLeaking(); - hb_shape(walker->font->hb_font, walker->hb_buf, NULL, 0); + hb_shape(hb->font, walker->hb_buf, NULL, 0); } walker->glyph_pos = hb_buffer_get_glyph_positions(walker->hb_buf, &walker->glyph_count); @@ -1978,7 +1979,7 @@ void fz_print_css_style(fz_context *ctx, fz_css_style *style, int boxtype, int n) { indent(n); printf("font_size %g%c\n", style->font_size.value, style->font_size.unit); - indent(n); printf("font %s\n", style->font ? style->font->name : "NULL"); + indent(n); printf("font %s\n", style->font ? fz_font_name(style->font) : "NULL"); indent(n); printf("width = %g%c;\n", style->width.value, style->width.unit); indent(n); printf("height = %g%c;\n", style->height.value, style->height.unit); if (boxtype == BOX_BLOCK) diff --git a/source/pdf/pdf-device.c b/source/pdf/pdf-device.c index 9644d862..30ae76b5 100644 --- a/source/pdf/pdf-device.c +++ b/source/pdf/pdf-device.c @@ -383,9 +383,9 @@ pdf_dev_font(fz_context *ctx, pdf_device *pdev, fz_font *font) if (gs->font >= 0 && pdev->cid_fonts[gs->font] == font) return; - if (font->t3procs) + if (fz_font_t3_procs(font)) fz_throw(ctx, FZ_ERROR_GENERIC, "pdf device does not support type 3 fonts"); - if (font->ft_substitute) + if (fz_font_flags(font)->ft_substitute) fz_throw(ctx, FZ_ERROR_GENERIC, "pdf device does not support substitute fonts"); if (!pdf_font_writing_supported(font)) fz_throw(ctx, FZ_ERROR_GENERIC, "pdf device does not support font types found in this file"); @@ -469,7 +469,7 @@ pdf_dev_text_span(fz_context *ctx, pdf_device *pdev, fz_text_span *span) if (fabsf(dx) > 0 || fabsf(dy) > 0) fz_buffer_printf(ctx, gs->buf, "%f %f %f %f %f %f Tm\n", tm.a, tm.b, tm.c, tm.d, tm.e, tm.f); - if (span->font->t3procs) + if (fz_font_t3_procs(span->font)) fz_buffer_printf(ctx, gs->buf, "<%02x> Tj\n", it->gid); else fz_buffer_printf(ctx, gs->buf, "<%04x> Tj\n", it->gid); diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c index b11d2240..aaab41a5 100644 --- a/source/pdf/pdf-font.c +++ b/source/pdf/pdf-font.c @@ -1,5 +1,7 @@ #include "mupdf/pdf.h" +#include "../fitz/font-impl.h" + #include <ft2build.h> #include FT_FREETYPE_H #include FT_ADVANCES_H @@ -208,7 +210,7 @@ static int ft_cid_to_gid(pdf_font_desc *fontdesc, int cid) cid = pdf_lookup_cmap(fontdesc->to_ttf_cmap, cid); /* vertical presentation forms */ - if (fontdesc->font->ft_substitute && fontdesc->wmode) + if (fontdesc->font->flags.ft_substitute && fontdesc->wmode) { switch (cid) { @@ -326,7 +328,7 @@ pdf_load_builtin_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname, fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find builtin font: '%s'", fontname); fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1); - fontdesc->font->is_serif = !!strstr(clean_name, "Times"); + fontdesc->font->flags.is_serif = !!strstr(clean_name, "Times"); } if (!strcmp(clean_name, "Symbol") || !strcmp(clean_name, "ZapfDingbats")) @@ -351,17 +353,17 @@ pdf_load_substitute_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontnam fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find substitute font"); fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1); - fontdesc->font->fake_bold = bold && !fontdesc->font->is_bold; - fontdesc->font->fake_italic = italic && !fontdesc->font->is_italic; + fontdesc->font->flags.fake_bold = bold && !fontdesc->font->flags.is_bold; + fontdesc->font->flags.fake_italic = italic && !fontdesc->font->flags.is_italic; - fontdesc->font->is_mono = mono; - fontdesc->font->is_serif = serif; - fontdesc->font->is_bold = bold; - fontdesc->font->is_italic = italic; + fontdesc->font->flags.is_mono = mono; + fontdesc->font->flags.is_serif = serif; + fontdesc->font->flags.is_bold = bold; + fontdesc->font->flags.is_italic = italic; } - fontdesc->font->ft_substitute = 1; - fontdesc->font->ft_stretch = 1; + fontdesc->font->flags.ft_substitute = 1; + fontdesc->font->flags.ft_stretch = 1; } static void @@ -382,8 +384,8 @@ pdf_load_substitute_cjk_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fon fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, index, 0); } - fontdesc->font->ft_substitute = 1; - fontdesc->font->ft_stretch = 0; + fontdesc->font->flags.ft_substitute = 1; + fontdesc->font->flags.ft_stretch = 0; } static void @@ -1050,7 +1052,7 @@ load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encodi /* if font is external, cidtogidmap should not be identity */ /* so we map from cid to unicode and then map that through the (3 1) */ /* unicode cmap to get a glyph id */ - else if (fontdesc->font->ft_substitute) + else if (fontdesc->font->flags.ft_substitute) { fterr = FT_Select_Charmap(face, ft_encoding_unicode); if (fterr) @@ -1074,7 +1076,7 @@ load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encodi * If we only have a substitute font, that won't work. * Make a last ditch attempt by using * the ToUnicode table if it exists to map via the substitute font's cmap. */ - if (strstr(fontdesc->encoding->cmap_name, "Identity-") && fontdesc->font->ft_substitute) + if (strstr(fontdesc->encoding->cmap_name, "Identity-") && fontdesc->font->flags.ft_substitute) { fz_warn(ctx, "non-embedded font using identity encoding: %s", basefont); if (fontdesc->to_unicode && !fontdesc->to_ttf_cmap) @@ -1265,7 +1267,7 @@ pdf_load_font_descriptor(fz_context *ctx, pdf_document *doc, pdf_font_desc *font if (ft_kind(face) == TRUETYPE) { if (FT_IS_TRICKY(face) || is_dynalab(fontdesc->font->name)) - fontdesc->font->force_hinting = 1; + fontdesc->font->flags.force_hinting = 1; if (fontdesc->ascent == 0.0f) fontdesc->ascent = 1000.0f * face->ascender / face->units_per_EM; @@ -1463,7 +1465,7 @@ pdf_add_font_file(fz_context *ctx, pdf_document *doc, fz_font *font) fz_var(ref); /* Check for substitute fonts */ - if (font->ft_substitute) + if (font->flags.ft_substitute) return NULL; fz_try(ctx) diff --git a/source/pdf/pdf-op-run.c b/source/pdf/pdf-op-run.c index a3dca30c..dba3e086 100644 --- a/source/pdf/pdf-op-run.c +++ b/source/pdf/pdf-op-run.c @@ -926,7 +926,7 @@ pdf_show_char(fz_context *ctx, pdf_run_processor *pr, int cid) /* If we are a type3 font within a type 3 font, or are otherwise * uncachable, then render direct. */ - render_direct = (!fontdesc->font->ft_face && pr->nested_depth > 0) || !fz_glyph_cacheable(ctx, fontdesc->font, gid); + render_direct = (!fz_font_ft_face(fontdesc->font) && pr->nested_depth > 0) || !fz_glyph_cacheable(ctx, fontdesc->font, gid); /* flush buffered text if rendermode has changed */ if (!pr->text || gstate->render != pr->text_mode || render_direct) diff --git a/source/pdf/pdf-type3.c b/source/pdf/pdf-type3.c index 57cda6df..84912772 100644 --- a/source/pdf/pdf-type3.c +++ b/source/pdf/pdf-type3.c @@ -1,5 +1,7 @@ #include "mupdf/pdf.h" +#include "../fitz/font-impl.h" + static void pdf_run_glyph_func(fz_context *ctx, void *doc, void *rdb, fz_buffer *contents, fz_device *dev, const fz_matrix *ctm, void *gstate, int nested_depth) { @@ -27,6 +29,7 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d int i, k, n; fz_rect bbox; fz_matrix matrix; + fz_font *font; fz_var(fontdesc); @@ -57,10 +60,11 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d obj = pdf_dict_get(ctx, dict, PDF_NAME_FontBBox); fz_transform_rect(pdf_to_rect(ctx, obj, &bbox), &matrix); - fontdesc->font = fz_new_type3_font(ctx, buf, &matrix); + font = fz_new_type3_font(ctx, buf, &matrix); + fontdesc->font = font; fontdesc->size += sizeof(fz_font) + 256 * (sizeof(fz_buffer*) + sizeof(float)); - fz_set_font_bbox(ctx, fontdesc->font, bbox.x0, bbox.y0, bbox.x1, bbox.y1); + fz_set_font_bbox(ctx, font, bbox.x0, bbox.y0, bbox.x1, bbox.y1); /* Encoding */ @@ -124,8 +128,8 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d for (i = first; i <= last; i++) { float w = pdf_to_real(ctx, pdf_array_get(ctx, widths, i - first)); - w = fontdesc->font->t3matrix.a * w * 1000; - fontdesc->font->t3widths[i] = w * 0.001f; + w = font->t3matrix.a * w * 1000; + font->t3widths[i] = w * 0.001f; pdf_add_hmtx(ctx, fontdesc, i, i, w); } @@ -133,17 +137,17 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d /* Resources -- inherit page resources if the font doesn't have its own */ - fontdesc->font->t3freeres = pdf_t3_free_resources; - fontdesc->font->t3resources = pdf_dict_get(ctx, dict, PDF_NAME_Resources); - if (!fontdesc->font->t3resources) - fontdesc->font->t3resources = rdb; - if (fontdesc->font->t3resources) - pdf_keep_obj(ctx, fontdesc->font->t3resources); - if (!fontdesc->font->t3resources) + font->t3freeres = pdf_t3_free_resources; + font->t3resources = pdf_dict_get(ctx, dict, PDF_NAME_Resources); + if (!font->t3resources) + font->t3resources = rdb; + if (font->t3resources) + pdf_keep_obj(ctx, font->t3resources); + if (!font->t3resources) fz_warn(ctx, "no resource dictionary for type 3 font!"); - fontdesc->font->t3doc = doc; - fontdesc->font->t3run = pdf_run_glyph_func; + font->t3doc = doc; + font->t3run = pdf_run_glyph_func; /* CharProcs */ @@ -160,8 +164,8 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d obj = pdf_dict_gets(ctx, charprocs, estrings[i]); if (pdf_is_stream(ctx, obj)) { - fontdesc->font->t3procs[i] = pdf_load_stream(ctx, obj); - fontdesc->size += fontdesc->font->t3procs[i]->cap; + font->t3procs[i] = pdf_load_stream(ctx, obj); + fontdesc->size += font->t3procs[i]->cap; fontdesc->size += 0; // TODO: display list size calculation } } @@ -174,7 +178,7 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d fz_rethrow(ctx); } - doc->type3_fonts[doc->num_type3_fonts++] = fz_keep_font(ctx, fontdesc->font); + doc->type3_fonts[doc->num_type3_fonts++] = fz_keep_font(ctx, font); return fontdesc; } diff --git a/source/tools/murun.c b/source/tools/murun.c index 3ed0228f..14e28f70 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -2073,7 +2073,7 @@ static void ffi_new_Font(js_State *J) static void ffi_Font_getName(js_State *J) { fz_font *font = js_touserdata(J, 0, "fz_font"); - js_pushstring(J, font->name); + js_pushstring(J, fz_font_name(font)); } static void ffi_Font_encodeCharacter(js_State *J) diff --git a/source/xps/xps-glyphs.c b/source/xps/xps-glyphs.c index 407953e8..1296d6f9 100644 --- a/source/xps/xps-glyphs.c +++ b/source/xps/xps-glyphs.c @@ -22,14 +22,14 @@ static inline int unhex(int a) int xps_count_font_encodings(fz_font *font) { - FT_Face face = font->ft_face; + FT_Face face = fz_font_ft_face(font); return face->num_charmaps; } void xps_identify_font_encoding(fz_font *font, int idx, int *pid, int *eid) { - FT_Face face = font->ft_face; + FT_Face face = fz_font_ft_face(font); *pid = face->charmaps[idx]->platform_id; *eid = face->charmaps[idx]->encoding_id; } @@ -37,14 +37,14 @@ xps_identify_font_encoding(fz_font *font, int idx, int *pid, int *eid) void xps_select_font_encoding(fz_font *font, int idx) { - FT_Face face = font->ft_face; + FT_Face face = fz_font_ft_face(font); FT_Set_Charmap(face, face->charmaps[idx]); } int xps_encode_font_char(fz_font *font, int code) { - FT_Face face = font->ft_face; + FT_Face face = fz_font_ft_face(font); int gid = FT_Get_Char_Index(face, code); if (gid == 0 && face->charmap && face->charmap->platform_id == 3 && face->charmap->encoding_id == 0) gid = FT_Get_Char_Index(face, 0xF000 | code); @@ -55,7 +55,7 @@ void xps_measure_font_glyph(fz_context *ctx, xps_document *doc, fz_font *font, int gid, xps_glyph_metrics *mtx) { int mask = FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_TRANSFORM; - FT_Face face = font->ft_face; + FT_Face face = fz_font_ft_face(font); FT_Fixed hadv = 0, vadv = 0; fz_lock(ctx, FZ_LOCK_FREETYPE); @@ -242,10 +242,13 @@ xps_lookup_font(fz_context *ctx, xps_document *doc, char *base_uri, char *font_u if (style_att) { - font->fake_bold = !!strstr(style_att, "Bold"); - font->is_bold = font->fake_bold; - font->fake_italic = !!strstr(style_att, "Italic"); - font->is_italic = font->fake_italic; + fz_font_flags_t *flags = fz_font_flags(font); + int bold = !!strstr(style_att, "Bold"); + int italic = !!strstr(style_att, "Italic"); + flags->fake_bold = bold; + flags->is_bold = bold; + flags->fake_italic = italic; + flags->is_italic = italic; } xps_select_best_font_encoding(ctx, doc, font); @@ -436,7 +439,7 @@ xps_parse_glyphs_imp(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, else advance = mtx.hadv * 100; - if (font->fake_bold) + if (fz_font_flags(font)->fake_bold) advance *= 1.02f; if (is && *is) |