summaryrefslogtreecommitdiff
path: root/pdf/pdf_type3.c
diff options
context:
space:
mode:
Diffstat (limited to 'pdf/pdf_type3.c')
-rw-r--r--pdf/pdf_type3.c92
1 files changed, 51 insertions, 41 deletions
diff --git a/pdf/pdf_type3.c b/pdf/pdf_type3.c
index 777ff756..6603fc8b 100644
--- a/pdf/pdf_type3.c
+++ b/pdf/pdf_type3.c
@@ -1,22 +1,31 @@
-#include "fitz.h"
-#include "mupdf.h"
+#include "fitz-internal.h"
+#include "mupdf-internal.h"
static void
-pdf_run_glyph_func(void *doc, fz_obj *rdb, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate)
+pdf_run_glyph_func(void *doc, void *rdb_, fz_buffer *contents, fz_device *dev, fz_matrix ctm, void *gstate)
{
+ pdf_obj *rdb = (pdf_obj *)rdb_;
pdf_run_glyph(doc, rdb, contents, dev, ctm, gstate);
}
+static void
+pdf_t3_free_resources(void *doc, void *rdb_)
+{
+ pdf_obj *rdb = (pdf_obj *)rdb_;
+ pdf_drop_obj(rdb);
+}
+
+
pdf_font_desc *
-pdf_load_type3_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict)
+pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict)
{
char buf[256];
char *estrings[256];
pdf_font_desc *fontdesc = NULL;
- fz_obj *encoding;
- fz_obj *widths;
- fz_obj *charprocs;
- fz_obj *obj;
+ pdf_obj *encoding;
+ pdf_obj *widths;
+ pdf_obj *charprocs;
+ pdf_obj *obj;
int first, last;
int i, k, n;
fz_rect bbox;
@@ -27,18 +36,18 @@ pdf_load_type3_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict)
fz_try(ctx)
{
- obj = fz_dict_gets(dict, "Name");
- if (fz_is_name(obj))
- fz_strlcpy(buf, fz_to_name(obj), sizeof buf);
+ obj = pdf_dict_gets(dict, "Name");
+ if (pdf_is_name(obj))
+ fz_strlcpy(buf, pdf_to_name(obj), sizeof buf);
else
sprintf(buf, "Unnamed-T3");
fontdesc = pdf_new_font_desc(ctx);
- obj = fz_dict_gets(dict, "FontMatrix");
+ obj = pdf_dict_gets(dict, "FontMatrix");
matrix = pdf_to_matrix(ctx, obj);
- obj = fz_dict_gets(dict, "FontBBox");
+ obj = pdf_dict_gets(dict, "FontBBox");
bbox = pdf_to_rect(ctx, obj);
bbox = fz_transform_rect(matrix, bbox);
@@ -52,35 +61,35 @@ pdf_load_type3_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict)
for (i = 0; i < 256; i++)
estrings[i] = NULL;
- encoding = fz_dict_gets(dict, "Encoding");
+ encoding = pdf_dict_gets(dict, "Encoding");
if (!encoding)
{
fz_throw(ctx, "syntaxerror: Type3 font missing Encoding");
}
- if (fz_is_name(encoding))
- pdf_load_encoding(estrings, fz_to_name(encoding));
+ if (pdf_is_name(encoding))
+ pdf_load_encoding(estrings, pdf_to_name(encoding));
- if (fz_is_dict(encoding))
+ if (pdf_is_dict(encoding))
{
- fz_obj *base, *diff, *item;
+ pdf_obj *base, *diff, *item;
- base = fz_dict_gets(encoding, "BaseEncoding");
- if (fz_is_name(base))
- pdf_load_encoding(estrings, fz_to_name(base));
+ base = pdf_dict_gets(encoding, "BaseEncoding");
+ if (pdf_is_name(base))
+ pdf_load_encoding(estrings, pdf_to_name(base));
- diff = fz_dict_gets(encoding, "Differences");
- if (fz_is_array(diff))
+ diff = pdf_dict_gets(encoding, "Differences");
+ if (pdf_is_array(diff))
{
- n = fz_array_len(diff);
+ n = pdf_array_len(diff);
k = 0;
for (i = 0; i < n; i++)
{
- item = fz_array_get(diff, i);
- if (fz_is_int(item))
- k = fz_to_int(item);
- if (fz_is_name(item))
- estrings[k++] = fz_to_name(item);
+ item = pdf_array_get(diff, i);
+ if (pdf_is_int(item))
+ k = pdf_to_int(item);
+ if (pdf_is_name(item))
+ estrings[k++] = pdf_to_name(item);
if (k < 0) k = 0;
if (k > 255) k = 255;
}
@@ -90,16 +99,16 @@ pdf_load_type3_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict)
fontdesc->encoding = pdf_new_identity_cmap(ctx, 0, 1);
fontdesc->size += pdf_cmap_size(ctx, fontdesc->encoding);
- pdf_load_to_unicode(xref, fontdesc, estrings, NULL, fz_dict_gets(dict, "ToUnicode"));
+ pdf_load_to_unicode(xref, fontdesc, estrings, NULL, pdf_dict_gets(dict, "ToUnicode"));
/* Widths */
pdf_set_default_hmtx(ctx, fontdesc, 0);
- first = fz_to_int(fz_dict_gets(dict, "FirstChar"));
- last = fz_to_int(fz_dict_gets(dict, "LastChar"));
+ first = pdf_to_int(pdf_dict_gets(dict, "FirstChar"));
+ last = pdf_to_int(pdf_dict_gets(dict, "LastChar"));
- widths = fz_dict_gets(dict, "Widths");
+ widths = pdf_dict_gets(dict, "Widths");
if (!widths)
{
fz_throw(ctx, "syntaxerror: Type3 font missing Widths");
@@ -107,7 +116,7 @@ pdf_load_type3_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict)
for (i = first; i <= last; i++)
{
- float w = fz_to_real(fz_array_get(widths, i - first));
+ float w = pdf_to_real(pdf_array_get(widths, i - first));
w = fontdesc->font->t3matrix.a * w * 1000;
fontdesc->font->t3widths[i] = w * 0.001f;
pdf_add_hmtx(ctx, fontdesc, i, i, w);
@@ -117,11 +126,12 @@ pdf_load_type3_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict)
/* Resources -- inherit page resources if the font doesn't have its own */
- fontdesc->font->t3resources = fz_dict_gets(dict, "Resources");
+ fontdesc->font->t3freeres = pdf_t3_free_resources;
+ fontdesc->font->t3resources = pdf_dict_gets(dict, "Resources");
if (!fontdesc->font->t3resources)
fontdesc->font->t3resources = rdb;
if (fontdesc->font->t3resources)
- fz_keep_obj(fontdesc->font->t3resources);
+ pdf_keep_obj(fontdesc->font->t3resources);
if (!fontdesc->font->t3resources)
fz_warn(ctx, "no resource dictionary for type 3 font!");
@@ -130,7 +140,7 @@ pdf_load_type3_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict)
/* CharProcs */
- charprocs = fz_dict_gets(dict, "CharProcs");
+ charprocs = pdf_dict_gets(dict, "CharProcs");
if (!charprocs)
{
fz_throw(ctx, "syntaxerror: Type3 font missing CharProcs");
@@ -140,10 +150,10 @@ pdf_load_type3_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict)
{
if (estrings[i])
{
- obj = fz_dict_gets(charprocs, estrings[i]);
- if (pdf_is_stream(xref, fz_to_num(obj), fz_to_gen(obj)))
+ obj = pdf_dict_gets(charprocs, estrings[i]);
+ if (pdf_is_stream(xref, pdf_to_num(obj), pdf_to_gen(obj)))
{
- fontdesc->font->t3procs[i] = pdf_load_stream(xref, fz_to_num(obj), fz_to_gen(obj));
+ fontdesc->font->t3procs[i] = pdf_load_stream(xref, pdf_to_num(obj), pdf_to_gen(obj));
fontdesc->size += fontdesc->font->t3procs[i]->cap;
}
}
@@ -154,7 +164,7 @@ pdf_load_type3_font(pdf_document *xref, fz_obj *rdb, fz_obj *dict)
if (fontdesc)
fz_drop_font(ctx, fontdesc->font);
fz_free(ctx, fontdesc);
- fz_throw(ctx, "cannot load type3 font (%d %d R)", fz_to_num(dict), fz_to_gen(dict));
+ fz_throw(ctx, "cannot load type3 font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
}
return fontdesc;
}