summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2016-09-28 16:46:10 +0100
committerRobin Watts <robin.watts@artifex.com>2016-10-05 19:37:11 +0100
commit9e88b088ea2ddcb6f85584750eb3c989af101905 (patch)
tree19db41ec596cc347fd1b77389821135f8e934e84 /source/pdf
parent14109acf198d9371a4e2cb09ea4a125af67d441d (diff)
downloadmupdf-9e88b088ea2ddcb6f85584750eb3c989af101905.tar.xz
Move fz_font definition to be private.
Move the definition of fz_font to be in a private header file rather than in the public API. Add accessors for specific parts of the structure and use them as appropriate. The font flags, and the harfbuzz records remain public. This means that only 3 files now need access to the font implementation (font.c, pdf-font.c and pdf-type3.c). This may be able to be improved further in future.
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-device.c6
-rw-r--r--source/pdf/pdf-font.c34
-rw-r--r--source/pdf/pdf-op-run.c2
-rw-r--r--source/pdf/pdf-type3.c36
4 files changed, 42 insertions, 36 deletions
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;
}