summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-interpret.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2014-01-24 12:38:31 +0000
committerRobin Watts <robin.watts@artifex.com>2014-02-10 15:04:52 +0000
commit7eddc1c63affc10e9e19b5f0de0a62556c36860e (patch)
tree28e6ead46d9725db2559c790dacbdbfd9a522823 /source/pdf/pdf-interpret.c
parent08c632046474e72f2e08e54f31e31a343808f6cb (diff)
downloadmupdf-7eddc1c63affc10e9e19b5f0de0a62556c36860e.tar.xz
Move rdb and file entries into pdf_csi.
This makes every pdf_run_XX operator function have the same function type. This paves the way for future changes in this area.
Diffstat (limited to 'source/pdf/pdf-interpret.c')
-rw-r--r--source/pdf/pdf-interpret.c97
1 files changed, 59 insertions, 38 deletions
diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c
index 35de1815..19f855f0 100644
--- a/source/pdf/pdf-interpret.c
+++ b/source/pdf/pdf-interpret.c
@@ -71,6 +71,11 @@ struct pdf_csi_s
/* usage mode for optional content groups */
char *event; /* "View", "Print", "Export" */
+ /* Current resource dict and file. These are in here to reduce param
+ * passing. */
+ pdf_obj *rdb;
+ fz_stream *file;
+
/* interpreter stack */
pdf_obj *obj;
char name[256];
@@ -1822,9 +1827,10 @@ pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate)
* Operators
*/
-static void pdf_run_BDC(pdf_csi *csi, pdf_obj *rdb)
+static void pdf_run_BDC(pdf_csi *csi)
{
pdf_obj *ocg;
+ pdf_obj *rdb = csi->rdb;
/* If we are already in a hidden OCG, then we'll still be hidden -
* just increment the depth so we pop back to visibility when we've
@@ -1851,9 +1857,11 @@ static void pdf_run_BDC(pdf_csi *csi, pdf_obj *rdb)
csi->in_hidden_ocg++;
}
-static void pdf_run_BI(pdf_csi *csi, pdf_obj *rdb, fz_stream *file)
+static void pdf_run_BI(pdf_csi *csi)
{
fz_context *ctx = csi->dev->ctx;
+ pdf_obj *rdb = csi->rdb;
+ fz_stream *file = csi->file;
int ch;
fz_image *img;
pdf_obj *obj;
@@ -1925,11 +1933,12 @@ static void pdf_run_Bstar(pdf_csi *csi)
pdf_show_path(csi, 0, 1, 1, 1);
}
-static void pdf_run_cs_imp(pdf_csi *csi, pdf_obj *rdb, int what)
+static void pdf_run_cs_imp(pdf_csi *csi, int what)
{
fz_context *ctx = csi->dev->ctx;
fz_colorspace *colorspace;
pdf_obj *obj, *dict;
+ pdf_obj *rdb = csi->rdb;
if (!strcmp(csi->name, "Pattern"))
{
@@ -1960,30 +1969,31 @@ static void pdf_run_cs_imp(pdf_csi *csi, pdf_obj *rdb, int what)
}
}
-static void pdf_run_CS(pdf_csi *csi, pdf_obj *rdb)
+static void pdf_run_CS(pdf_csi *csi)
{
csi->dev->flags &= ~FZ_DEVFLAG_STROKECOLOR_UNDEFINED;
- pdf_run_cs_imp(csi, rdb, PDF_STROKE);
+ pdf_run_cs_imp(csi, PDF_STROKE);
}
-static void pdf_run_cs(pdf_csi *csi, pdf_obj *rdb)
+static void pdf_run_cs(pdf_csi *csi)
{
csi->dev->flags &= ~FZ_DEVFLAG_FILLCOLOR_UNDEFINED;
- pdf_run_cs_imp(csi, rdb, PDF_FILL);
+ pdf_run_cs_imp(csi, PDF_FILL);
}
static void pdf_run_DP(pdf_csi *csi)
{
}
-static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb)
+static void pdf_run_Do(pdf_csi *csi)
{
fz_context *ctx = csi->dev->ctx;
pdf_obj *dict;
pdf_obj *obj;
pdf_obj *subtype;
+ pdf_obj *rdb = csi->rdb;
dict = pdf_dict_gets(rdb, "XObject");
if (!dict)
@@ -2135,13 +2145,14 @@ static void pdf_run_S(pdf_csi *csi)
pdf_show_path(csi, 0, 0, 1, 0);
}
-static void pdf_run_SC_imp(pdf_csi *csi, pdf_obj *rdb, int what, pdf_material *mat)
+static void pdf_run_SC_imp(pdf_csi *csi, int what, pdf_material *mat)
{
fz_context *ctx = csi->dev->ctx;
pdf_obj *patterntype;
pdf_obj *dict;
pdf_obj *obj;
int kind;
+ pdf_obj *rdb = csi->rdb;
kind = mat->kind;
if (csi->name[0])
@@ -2193,18 +2204,20 @@ static void pdf_run_SC_imp(pdf_csi *csi, pdf_obj *rdb, int what, pdf_material *m
mat->gstate_num = csi->gparent;
}
-static void pdf_run_SC(pdf_csi *csi, pdf_obj *rdb)
+static void pdf_run_SC(pdf_csi *csi)
{
pdf_gstate *gstate = csi->gstate + csi->gtop;
+
csi->dev->flags &= ~FZ_DEVFLAG_STROKECOLOR_UNDEFINED;
- pdf_run_SC_imp(csi, rdb, PDF_STROKE, &gstate->stroke);
+ pdf_run_SC_imp(csi, PDF_STROKE, &gstate->stroke);
}
-static void pdf_run_sc(pdf_csi *csi, pdf_obj *rdb)
+static void pdf_run_sc(pdf_csi *csi)
{
pdf_gstate *gstate = csi->gstate + csi->gtop;
+
csi->dev->flags &= ~FZ_DEVFLAG_FILLCOLOR_UNDEFINED;
- pdf_run_SC_imp(csi, rdb, PDF_FILL, &gstate->fill);
+ pdf_run_SC_imp(csi, PDF_FILL, &gstate->fill);
}
static void pdf_run_Tc(pdf_csi *csi)
@@ -2233,9 +2246,10 @@ static void pdf_run_TL(pdf_csi *csi)
gstate->leading = csi->stack[0];
}
-static void pdf_run_Tf(pdf_csi *csi, pdf_obj *rdb)
+static void pdf_run_Tf(pdf_csi *csi)
{
fz_context *ctx = csi->dev->ctx;
+ pdf_obj *rdb = csi->rdb;
pdf_gstate *gstate = csi->gstate + csi->gtop;
pdf_obj *dict;
pdf_obj *obj;
@@ -2421,11 +2435,12 @@ static void pdf_run_g(pdf_csi *csi)
pdf_set_color(csi, PDF_FILL, csi->stack);
}
-static void pdf_run_gs(pdf_csi *csi, pdf_obj *rdb)
+static void pdf_run_gs(pdf_csi *csi)
{
pdf_obj *dict;
pdf_obj *obj;
fz_context *ctx = csi->dev->ctx;
+ pdf_obj *rdb = csi->rdb;
dict = pdf_dict_gets(rdb, "ExtGState");
if (!dict)
@@ -2516,14 +2531,15 @@ static void pdf_run_ri(pdf_csi *csi)
{
}
-static void pdf_run(pdf_csi *csi)
+static void pdf_run_s(pdf_csi *csi)
{
pdf_show_path(csi, 1, 0, 1, 0);
}
-static void pdf_run_sh(pdf_csi *csi, pdf_obj *rdb)
+static void pdf_run_sh(pdf_csi *csi)
{
fz_context *ctx = csi->dev->ctx;
+ pdf_obj *rdb = csi->rdb;
pdf_obj *dict;
pdf_obj *obj;
fz_shade *shd;
@@ -2618,7 +2634,7 @@ static void pdf_run_dquote(pdf_csi *csi)
#define C(a,b,c) (a | b << 8 | c << 16)
static int
-pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf)
+pdf_run_keyword(pdf_csi *csi, char *buf)
{
fz_context *ctx = csi->dev->ctx;
int key;
@@ -2641,19 +2657,17 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf)
case A('\''): pdf_run_squote(csi); break;
case A('B'): pdf_run_B(csi); break;
case B('B','*'): pdf_run_Bstar(csi); break;
- case C('B','D','C'): pdf_run_BDC(csi, rdb); break;
- case B('B','I'):
- pdf_run_BI(csi, rdb, file);
- break;
+ case C('B','D','C'): pdf_run_BDC(csi); break;
+ case B('B','I'): pdf_run_BI(csi); break;
case C('B','M','C'): pdf_run_BMC(csi); break;
case B('B','T'): pdf_run_BT(csi); break;
case B('B','X'): pdf_run_BX(csi); break;
- case B('C','S'): pdf_run_CS(csi, rdb); break;
+ case B('C','S'): pdf_run_CS(csi); break;
case B('D','P'): pdf_run_DP(csi); break;
case B('D','o'):
fz_try(ctx)
{
- pdf_run_Do(csi, rdb);
+ pdf_run_Do(csi);
}
fz_catch(ctx)
{
@@ -2672,8 +2686,8 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf)
case A('Q'): pdf_run_Q(csi); break;
case B('R','G'): pdf_run_RG(csi); break;
case A('S'): pdf_run_S(csi); break;
- case B('S','C'): pdf_run_SC(csi, rdb); break;
- case C('S','C','N'): pdf_run_SC(csi, rdb); break;
+ case B('S','C'): pdf_run_SC(csi); break;
+ case C('S','C','N'): pdf_run_SC(csi); break;
case B('T','*'): pdf_run_Tstar(csi); break;
case B('T','D'): pdf_run_TD(csi); break;
case B('T','J'): pdf_run_TJ(csi); break;
@@ -2683,7 +2697,7 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf)
case B('T','f'):
fz_try(ctx)
{
- pdf_run_Tf(csi, rdb);
+ pdf_run_Tf(csi);
}
fz_catch(ctx)
{
@@ -2702,7 +2716,7 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf)
case B('b','*'): pdf_run_bstar(csi); break;
case A('c'): pdf_run_c(csi); break;
case B('c','m'): pdf_run_cm(csi); break;
- case B('c','s'): pdf_run_cs(csi, rdb); break;
+ case B('c','s'): pdf_run_cs(csi); break;
case A('d'): pdf_run_d(csi); break;
case B('d','0'): pdf_run_d0(csi); break;
case B('d','1'): pdf_run_d1(csi); break;
@@ -2712,7 +2726,7 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf)
case B('g','s'):
fz_try(ctx)
{
- pdf_run_gs(csi, rdb);
+ pdf_run_gs(csi);
}
fz_catch(ctx)
{
@@ -2730,13 +2744,13 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf)
case B('r','e'): pdf_run_re(csi); break;
case B('r','g'): pdf_run_rg(csi); break;
case B('r','i'): pdf_run_ri(csi); break;
- case A('s'): pdf_run(csi); break;
- case B('s','c'): pdf_run_sc(csi, rdb); break;
- case C('s','c','n'): pdf_run_sc(csi, rdb); break;
+ case A('s'): pdf_run_s(csi); break;
+ case B('s','c'): pdf_run_sc(csi); break;
+ case C('s','c','n'): pdf_run_sc(csi); break;
case B('s','h'):
fz_try(ctx)
{
- pdf_run_sh(csi, rdb);
+ pdf_run_sh(csi);
}
fz_catch(ctx)
{
@@ -2758,9 +2772,10 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf)
}
static void
-pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf)
+pdf_run_stream(pdf_csi *csi, pdf_lexbuf *buf)
{
fz_context *ctx = csi->dev->ctx;
+ fz_stream *file = csi->file;
pdf_token tok = PDF_TOK_ERROR;
int in_text_array = 0;
int ignoring_errors = 0;
@@ -2908,7 +2923,7 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf)
break;
case PDF_TOK_KEYWORD:
- if (pdf_run_keyword(csi, rdb, file, buf->scratch))
+ if (pdf_run_keyword(csi, buf->scratch))
{
tok = PDF_TOK_EOF;
}
@@ -2963,6 +2978,8 @@ pdf_run_contents_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file)
int save_in_text;
int save_gbot;
pdf_obj *save_obj;
+ pdf_obj *save_rdb = csi->rdb;
+ fz_stream *save_file = csi->file;
fz_var(buf);
@@ -2977,14 +2994,20 @@ pdf_run_contents_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file)
csi->gbot = csi->gtop;
save_obj = csi->obj;
csi->obj = NULL;
+ csi->rdb = rdb;
+ csi->file = file;
fz_try(ctx)
{
- pdf_run_stream(csi, rdb, file, buf);
+ pdf_run_stream(csi, buf);
}
fz_always(ctx)
{
pdf_drop_obj(csi->obj);
csi->obj = save_obj;
+ csi->rdb = save_rdb;
+ csi->file = save_file;
+ pdf_lexbuf_fin(buf);
+ fz_free(ctx, buf);
}
fz_catch(ctx)
{
@@ -2995,8 +3018,6 @@ pdf_run_contents_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file)
pdf_grestore(csi);
csi->gbot = save_gbot;
csi->in_text = save_in_text;
- pdf_lexbuf_fin(buf);
- fz_free(ctx, buf);
}
static void