summaryrefslogtreecommitdiff
path: root/pdf/pdf_parse.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-02-26 11:15:16 -0800
committerRobin Watts <robin@ghostscript.com>2012-02-26 19:36:30 +0000
commitbbfe635555dce16858403706e2031dd3bfa1a9f1 (patch)
tree6e414005f04f233a83dbeec5607c0665a6d498bc /pdf/pdf_parse.c
parentca578b08dc1243dc6cbb3235272d52d9e2336925 (diff)
downloadmupdf-bbfe635555dce16858403706e2031dd3bfa1a9f1.tar.xz
Move fz_obj to be pdf_obj.
Currently, we are in the slightly strange position of having the PDF specific object types as part of fitz. Here we pull them out into the pdf layer instead. This has been made possible by the recent changes to make the store no longer be tied to having fz_obj's as keys. Most of this work is a simple huge rename; to help customers who may have code that use such functions we have provided a sed script to do the renaming; scripts/rename2.sed. Various other small tweaks are required; the store used to have some debugging code that still required knowledge of fz_obj types - we extract that into a nicer 'type' based function pointer. Also, the type 3 font handling used to have an fz_obj pointer for type 3 resources, and therefore needed to know how to free this; this has become a void * with a function to free it.
Diffstat (limited to 'pdf/pdf_parse.c')
-rw-r--r--pdf/pdf_parse.c196
1 files changed, 98 insertions, 98 deletions
diff --git a/pdf/pdf_parse.c b/pdf/pdf_parse.c
index fb6cb7ef..e171e698 100644
--- a/pdf/pdf_parse.c
+++ b/pdf/pdf_parse.c
@@ -2,13 +2,13 @@
#include "mupdf.h"
fz_rect
-pdf_to_rect(fz_context *ctx, fz_obj *array)
+pdf_to_rect(fz_context *ctx, pdf_obj *array)
{
fz_rect r;
- float a = fz_to_real(fz_array_get(array, 0));
- float b = fz_to_real(fz_array_get(array, 1));
- float c = fz_to_real(fz_array_get(array, 2));
- float d = fz_to_real(fz_array_get(array, 3));
+ float a = pdf_to_real(pdf_array_get(array, 0));
+ float b = pdf_to_real(pdf_array_get(array, 1));
+ float c = pdf_to_real(pdf_array_get(array, 2));
+ float d = pdf_to_real(pdf_array_get(array, 3));
r.x0 = MIN(a, c);
r.y0 = MIN(b, d);
r.x1 = MAX(a, c);
@@ -17,25 +17,25 @@ pdf_to_rect(fz_context *ctx, fz_obj *array)
}
fz_matrix
-pdf_to_matrix(fz_context *ctx, fz_obj *array)
+pdf_to_matrix(fz_context *ctx, pdf_obj *array)
{
fz_matrix m;
- m.a = fz_to_real(fz_array_get(array, 0));
- m.b = fz_to_real(fz_array_get(array, 1));
- m.c = fz_to_real(fz_array_get(array, 2));
- m.d = fz_to_real(fz_array_get(array, 3));
- m.e = fz_to_real(fz_array_get(array, 4));
- m.f = fz_to_real(fz_array_get(array, 5));
+ m.a = pdf_to_real(pdf_array_get(array, 0));
+ m.b = pdf_to_real(pdf_array_get(array, 1));
+ m.c = pdf_to_real(pdf_array_get(array, 2));
+ m.d = pdf_to_real(pdf_array_get(array, 3));
+ m.e = pdf_to_real(pdf_array_get(array, 4));
+ m.f = pdf_to_real(pdf_array_get(array, 5));
return m;
}
/* Convert Unicode/PdfDocEncoding string into utf-8 */
char *
-pdf_to_utf8(fz_context *ctx, fz_obj *src)
+pdf_to_utf8(fz_context *ctx, pdf_obj *src)
{
- unsigned char *srcptr = (unsigned char *) fz_to_str_buf(src);
+ unsigned char *srcptr = (unsigned char *) pdf_to_str_buf(src);
char *dstptr, *dst;
- int srclen = fz_to_str_len(src);
+ int srclen = pdf_to_str_len(src);
int dstlen = 0;
int ucs;
int i;
@@ -92,11 +92,11 @@ pdf_to_utf8(fz_context *ctx, fz_obj *src)
/* Convert Unicode/PdfDocEncoding string into ucs-2 */
unsigned short *
-pdf_to_ucs2(fz_context *ctx, fz_obj *src)
+pdf_to_ucs2(fz_context *ctx, pdf_obj *src)
{
- unsigned char *srcptr = (unsigned char *) fz_to_str_buf(src);
+ unsigned char *srcptr = (unsigned char *) pdf_to_str_buf(src);
unsigned short *dstptr, *dst;
- int srclen = fz_to_str_len(src);
+ int srclen = pdf_to_str_len(src);
int i;
if (srclen >= 2 && srcptr[0] == 254 && srcptr[1] == 255)
@@ -161,28 +161,28 @@ pdf_from_ucs2(fz_context *ctx, unsigned short *src)
return docstr;
}
-fz_obj *
-pdf_to_utf8_name(fz_context *ctx, fz_obj *src)
+pdf_obj *
+pdf_to_utf8_name(fz_context *ctx, pdf_obj *src)
{
char *buf = pdf_to_utf8(ctx, src);
- fz_obj *dst = fz_new_name(ctx, buf);
+ pdf_obj *dst = fz_new_name(ctx, buf);
fz_free(ctx, buf);
return dst;
}
-fz_obj *
+pdf_obj *
pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
{
- fz_obj *ary = NULL;
- fz_obj *obj = NULL;
+ pdf_obj *ary = NULL;
+ pdf_obj *obj = NULL;
int a = 0, b = 0, n = 0;
int tok;
fz_context *ctx = file->ctx;
- fz_obj *op;
+ pdf_obj *op;
fz_var(obj);
- ary = fz_new_array(ctx, 4);
+ ary = pdf_new_array(ctx, 4);
fz_try(ctx)
{
@@ -194,16 +194,16 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
{
if (n > 0)
{
- obj = fz_new_int(ctx, a);
- fz_array_push(ary, obj);
- fz_drop_obj(obj);
+ obj = pdf_new_int(ctx, a);
+ pdf_array_push(ary, obj);
+ pdf_drop_obj(obj);
obj = NULL;
}
if (n > 1)
{
- obj = fz_new_int(ctx, b);
- fz_array_push(ary, obj);
- fz_drop_obj(obj);
+ obj = pdf_new_int(ctx, b);
+ pdf_array_push(ary, obj);
+ pdf_drop_obj(obj);
obj = NULL;
}
n = 0;
@@ -211,9 +211,9 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
if (tok == PDF_TOK_INT && n == 2)
{
- obj = fz_new_int(ctx, a);
- fz_array_push(ary, obj);
- fz_drop_obj(obj);
+ obj = pdf_new_int(ctx, a);
+ pdf_array_push(ary, obj);
+ pdf_drop_obj(obj);
obj = NULL;
a = b;
n --;
@@ -236,61 +236,61 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
case PDF_TOK_R:
if (n != 2)
fz_throw(ctx, "cannot parse indirect reference in array");
- obj = fz_new_indirect(ctx, a, b, xref);
- fz_array_push(ary, obj);
- fz_drop_obj(obj);
+ obj = pdf_new_indirect(ctx, a, b, xref);
+ pdf_array_push(ary, obj);
+ pdf_drop_obj(obj);
obj = NULL;
n = 0;
break;
case PDF_TOK_OPEN_ARRAY:
obj = pdf_parse_array(xref, file, buf);
- fz_array_push(ary, obj);
- fz_drop_obj(obj);
+ pdf_array_push(ary, obj);
+ pdf_drop_obj(obj);
obj = NULL;
break;
case PDF_TOK_OPEN_DICT:
obj = pdf_parse_dict(xref, file, buf);
- fz_array_push(ary, obj);
- fz_drop_obj(obj);
+ pdf_array_push(ary, obj);
+ pdf_drop_obj(obj);
obj = NULL;
break;
case PDF_TOK_NAME:
obj = fz_new_name(ctx, buf->scratch);
- fz_array_push(ary, obj);
- fz_drop_obj(obj);
+ pdf_array_push(ary, obj);
+ pdf_drop_obj(obj);
obj = NULL;
break;
case PDF_TOK_REAL:
- obj = fz_new_real(ctx, buf->f);
- fz_array_push(ary, obj);
- fz_drop_obj(obj);
+ obj = pdf_new_real(ctx, buf->f);
+ pdf_array_push(ary, obj);
+ pdf_drop_obj(obj);
obj = NULL;
break;
case PDF_TOK_STRING:
- obj = fz_new_string(ctx, buf->scratch, buf->len);
- fz_array_push(ary, obj);
- fz_drop_obj(obj);
+ obj = pdf_new_string(ctx, buf->scratch, buf->len);
+ pdf_array_push(ary, obj);
+ pdf_drop_obj(obj);
obj = NULL;
break;
case PDF_TOK_TRUE:
- obj = fz_new_bool(ctx, 1);
- fz_array_push(ary, obj);
- fz_drop_obj(obj);
+ obj = pdf_new_bool(ctx, 1);
+ pdf_array_push(ary, obj);
+ pdf_drop_obj(obj);
obj = NULL;
break;
case PDF_TOK_FALSE:
- obj = fz_new_bool(ctx, 0);
- fz_array_push(ary, obj);
- fz_drop_obj(obj);
+ obj = pdf_new_bool(ctx, 0);
+ pdf_array_push(ary, obj);
+ pdf_drop_obj(obj);
obj = NULL;
break;
case PDF_TOK_NULL:
- obj = fz_new_null(ctx);
- fz_array_push(ary, obj);
- fz_drop_obj(obj);
+ obj = pdf_new_null(ctx);
+ pdf_array_push(ary, obj);
+ pdf_drop_obj(obj);
obj = NULL;
break;
@@ -303,19 +303,19 @@ end:
}
fz_catch(ctx)
{
- fz_drop_obj(obj);
- fz_drop_obj(ary);
+ pdf_drop_obj(obj);
+ pdf_drop_obj(ary);
fz_throw(ctx, "cannot parse array");
}
return op;
}
-fz_obj *
+pdf_obj *
pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
{
- fz_obj *dict = NULL;
- fz_obj *key = NULL;
- fz_obj *val = NULL;
+ pdf_obj *dict = NULL;
+ pdf_obj *key = NULL;
+ pdf_obj *val = NULL;
int tok;
int a, b;
fz_context *ctx = file->ctx;
@@ -324,7 +324,7 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
fz_var(key);
fz_var(val);
- dict = fz_new_dict(ctx, 8);
+ dict = pdf_new_dict(ctx, 8);
fz_try(ctx)
{
@@ -357,11 +357,11 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
break;
case PDF_TOK_NAME: val = fz_new_name(ctx, buf->scratch); break;
- case PDF_TOK_REAL: val = fz_new_real(ctx, buf->f); break;
- case PDF_TOK_STRING: val = fz_new_string(ctx, buf->scratch, buf->len); break;
- case PDF_TOK_TRUE: val = fz_new_bool(ctx, 1); break;
- case PDF_TOK_FALSE: val = fz_new_bool(ctx, 0); break;
- case PDF_TOK_NULL: val = fz_new_null(ctx); break;
+ case PDF_TOK_REAL: val = pdf_new_real(ctx, buf->f); break;
+ case PDF_TOK_STRING: val = pdf_new_string(ctx, buf->scratch, buf->len); break;
+ case PDF_TOK_TRUE: val = pdf_new_bool(ctx, 1); break;
+ case PDF_TOK_FALSE: val = pdf_new_bool(ctx, 0); break;
+ case PDF_TOK_NULL: val = pdf_new_null(ctx); break;
case PDF_TOK_INT:
/* 64-bit to allow for numbers > INT_MAX and overflow */
@@ -370,11 +370,11 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
if (tok == PDF_TOK_CLOSE_DICT || tok == PDF_TOK_NAME ||
(tok == PDF_TOK_KEYWORD && !strcmp(buf->scratch, "ID")))
{
- val = fz_new_int(ctx, a);
+ val = pdf_new_int(ctx, a);
fz_dict_put(dict, key, val);
- fz_drop_obj(val);
+ pdf_drop_obj(val);
val = NULL;
- fz_drop_obj(key);
+ pdf_drop_obj(key);
key = NULL;
goto skip;
}
@@ -384,7 +384,7 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
tok = pdf_lex(file, buf);
if (tok == PDF_TOK_R)
{
- val = fz_new_indirect(ctx, a, b, xref);
+ val = pdf_new_indirect(ctx, a, b, xref);
break;
}
}
@@ -395,23 +395,23 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
}
fz_dict_put(dict, key, val);
- fz_drop_obj(val);
+ pdf_drop_obj(val);
val = NULL;
- fz_drop_obj(key);
+ pdf_drop_obj(key);
key = NULL;
}
}
fz_catch(ctx)
{
- fz_drop_obj(dict);
- fz_drop_obj(key);
- fz_drop_obj(val);
+ pdf_drop_obj(dict);
+ pdf_drop_obj(key);
+ pdf_drop_obj(val);
fz_throw(ctx, "cannot parse dict");
}
return dict;
}
-fz_obj *
+pdf_obj *
pdf_parse_stm_obj(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
{
int tok;
@@ -429,23 +429,23 @@ pdf_parse_stm_obj(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf)
return pdf_parse_dict(xref, file, buf);
/* RJW: "cannot parse object stream" */
case PDF_TOK_NAME: return fz_new_name(ctx, buf->scratch); break;
- case PDF_TOK_REAL: return fz_new_real(ctx, buf->f); break;
- case PDF_TOK_STRING: return fz_new_string(ctx, buf->scratch, buf->len); break;
- case PDF_TOK_TRUE: return fz_new_bool(ctx, 1); break;
- case PDF_TOK_FALSE: return fz_new_bool(ctx, 0); break;
- case PDF_TOK_NULL: return fz_new_null(ctx); break;
- case PDF_TOK_INT: return fz_new_int(ctx, buf->i); break;
+ case PDF_TOK_REAL: return pdf_new_real(ctx, buf->f); break;
+ case PDF_TOK_STRING: return pdf_new_string(ctx, buf->scratch, buf->len); break;
+ case PDF_TOK_TRUE: return pdf_new_bool(ctx, 1); break;
+ case PDF_TOK_FALSE: return pdf_new_bool(ctx, 0); break;
+ case PDF_TOK_NULL: return pdf_new_null(ctx); break;
+ case PDF_TOK_INT: return pdf_new_int(ctx, buf->i); break;
default: fz_throw(ctx, "unknown token in object stream");
}
return NULL; /* Stupid MSVC */
}
-fz_obj *
+pdf_obj *
pdf_parse_ind_obj(pdf_document *xref,
fz_stream *file, pdf_lexbuf *buf,
int *onum, int *ogen, int *ostmofs)
{
- fz_obj *obj = NULL;
+ pdf_obj *obj = NULL;
int num = 0, gen = 0, stm_ofs;
int tok;
int a, b;
@@ -486,11 +486,11 @@ pdf_parse_ind_obj(pdf_document *xref,
break;
case PDF_TOK_NAME: obj = fz_new_name(ctx, buf->scratch); break;
- case PDF_TOK_REAL: obj = fz_new_real(ctx, buf->f); break;
- case PDF_TOK_STRING: obj = fz_new_string(ctx, buf->scratch, buf->len); break;
- case PDF_TOK_TRUE: obj = fz_new_bool(ctx, 1); break;
- case PDF_TOK_FALSE: obj = fz_new_bool(ctx, 0); break;
- case PDF_TOK_NULL: obj = fz_new_null(ctx); break;
+ case PDF_TOK_REAL: obj = pdf_new_real(ctx, buf->f); break;
+ case PDF_TOK_STRING: obj = pdf_new_string(ctx, buf->scratch, buf->len); break;
+ case PDF_TOK_TRUE: obj = pdf_new_bool(ctx, 1); break;
+ case PDF_TOK_FALSE: obj = pdf_new_bool(ctx, 0); break;
+ case PDF_TOK_NULL: obj = pdf_new_null(ctx); break;
case PDF_TOK_INT:
a = buf->i;
@@ -498,7 +498,7 @@ pdf_parse_ind_obj(pdf_document *xref,
/* "cannot parse indirect object (%d %d R)", num, gen */
if (tok == PDF_TOK_STREAM || tok == PDF_TOK_ENDOBJ)
{
- obj = fz_new_int(ctx, a);
+ obj = pdf_new_int(ctx, a);
goto skip;
}
if (tok == PDF_TOK_INT)
@@ -508,14 +508,14 @@ pdf_parse_ind_obj(pdf_document *xref,
/* RJW: "cannot parse indirect object (%d %d R)", num, gen); */
if (tok == PDF_TOK_R)
{
- obj = fz_new_indirect(ctx, a, b, xref);
+ obj = pdf_new_indirect(ctx, a, b, xref);
break;
}
}
fz_throw(ctx, "expected 'R' keyword (%d %d R)", num, gen);
case PDF_TOK_ENDOBJ:
- obj = fz_new_null(ctx);
+ obj = pdf_new_null(ctx);
goto skip;
default:
@@ -528,7 +528,7 @@ pdf_parse_ind_obj(pdf_document *xref,
}
fz_catch(ctx)
{
- fz_drop_obj(obj);
+ pdf_drop_obj(obj);
fz_throw(ctx, "cannot parse indirect object (%d %d R)", num, gen);
}