summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Jamfile5
-rw-r--r--include/mupdf.h3
-rw-r--r--include/mupdf/function.h15
-rw-r--r--include/mupdf/syntax.h1
-rw-r--r--mupdf/function.c44
-rw-r--r--mupdf/lex.c55
6 files changed, 45 insertions, 78 deletions
diff --git a/Jamfile b/Jamfile
index da99d0a1..0f567443 100644
--- a/Jamfile
+++ b/Jamfile
@@ -102,6 +102,10 @@ Library libmupdf :
mupdf/doctor.c
mupdf/nametree.c
+ mupdf/outline.c
+ mupdf/pagetree.c
+
+ mupdf/function.c
mupdf/cmap.c
mupdf/font.c
mupdf/fontfile.c
@@ -109,7 +113,6 @@ Library libmupdf :
mupdf/image.c
mupdf/resources.c
mupdf/page.c
- mupdf/pagetree.c
mupdf/build.c
mupdf/interpret.c
;
diff --git a/include/mupdf.h b/include/mupdf.h
index cc455f89..a7feec65 100644
--- a/include/mupdf.h
+++ b/include/mupdf.h
@@ -9,7 +9,8 @@
#include "mupdf/syntax.h"
#include "mupdf/xref.h"
+#include "mupdf/function.h"
#include "mupdf/rsrc.h"
#include "mupdf/content.h"
#include "mupdf/page.h"
-#include "mupdf/function.h"
+
diff --git a/include/mupdf/function.h b/include/mupdf/function.h
index 483931b5..9e2caa26 100644
--- a/include/mupdf/function.h
+++ b/include/mupdf/function.h
@@ -40,14 +40,15 @@ struct psobj_s
{
unsigned short type;
union {
- int booln; // boolean (stack only)
- int intg; // integer (stack and code)
- float real; // real (stack and code)
- int op; // operator (code only)
- int blk; // if/ifelse block pointer (code only)
+ int booln; /* boolean (stack only) */
+ int intg; /* integer (stack and code) */
+ float real; /* real (stack and code) */
+ int op; /* operator (code only) */
+ int blk; /* if/ifelse block pointer (code only) */
};
};
fz_error *pdf_loadfunction(pdf_function **func, pdf_xref *xref, fz_obj *obj);
-fz_error *pdf_execfunction(pdf_function *func, float *in, int inlen, float *out, int outlen);
-void pdf_freefunc(pdf_function *func); \ No newline at end of file
+fz_error *pdf_evalfunction(pdf_function *func, float *in, int inlen, float *out, int outlen);
+void pdf_freefunc(pdf_function *func);
+
diff --git a/include/mupdf/syntax.h b/include/mupdf/syntax.h
index 4159cc54..5d9b1ffb 100644
--- a/include/mupdf/syntax.h
+++ b/include/mupdf/syntax.h
@@ -7,6 +7,7 @@ enum
PDF_TERROR, PDF_TEOF,
PDF_TOARRAY, PDF_TCARRAY,
PDF_TODICT, PDF_TCDICT,
+ PDF_TOBRACE, PDF_TCBRACE,
PDF_TNAME, PDF_TINT, PDF_TREAL, PDF_TSTRING, PDF_TKEYWORD,
PDF_TR, PDF_TTRUE, PDF_TFALSE, PDF_TNULL,
PDF_TOBJ, PDF_TENDOBJ,
diff --git a/mupdf/function.c b/mupdf/function.c
index 8d262b00..ee2310e0 100644
--- a/mupdf/function.c
+++ b/mupdf/function.c
@@ -609,7 +609,7 @@ cleanup:
}
static fz_error *
-execsamplefunc(pdf_function *func, float *in, float *out)
+evalsamplefunc(pdf_function *func, float *in, float *out)
{
int i , j, k, idx;
int e[2][func->m];
@@ -756,7 +756,7 @@ cleanup:
}
static fz_error *
-execexponentialfunc(pdf_function *func, float in, float *out)
+evalexponentialfunc(pdf_function *func, float in, float *out)
{
fz_error *err = nil;
float x = in;
@@ -873,7 +873,7 @@ cleanup:
}
static fz_error*
-execstitchinigfunc(pdf_function *func, float in, float *out)
+evalstitchingfunc(pdf_function *func, float in, float *out)
{
fz_error *err = nil;
float low,high;
@@ -903,7 +903,7 @@ execstitchinigfunc(pdf_function *func, float in, float *out)
in = INTERPOLATE(in,low,high,
func->u.st.encode[i*2],func->u.st.encode[i*2 + 1]);
- err = pdf_execfunction(func->u.st.funcs[i],&in,1,out,func->n);
+ err = pdf_evalfunction(func->u.st.funcs[i],&in,1,out,func->n);
if(err) return err;
return nil;
@@ -939,7 +939,7 @@ parsecode(pdf_function *func, fz_file *stream, int *codeptr)
memset(buf,0,sizeof(buf));
while (1) {
- token = pdf_pslex(stream,buf,buflen,&len);
+ token = pdf_lex(stream,buf,buflen,&len);
if(token == PDF_TERROR || token == PDF_TEOF)
goto cleanup;
@@ -957,30 +957,30 @@ parsecode(pdf_function *func, fz_file *stream, int *codeptr)
func->u.p.code[*codeptr].real = atof(buf);
++*codeptr;
break;
- case PDF_TPSOPENBRACE:
+ case PDF_TOBRACE:
opPtr = *codeptr;
*codeptr += 3;
resizecode(func,opPtr + 2);
err = parsecode(func, stream, codeptr);
if(err) goto cleanup;
- token = pdf_pslex(stream,buf,buflen,&len);
+ token = pdf_lex(stream,buf,buflen,&len);
if(token == PDF_TEOF || token == PDF_TERROR)
goto cleanup;
- if(token == PDF_TPSOPENBRACE) {
+ if(token == PDF_TOBRACE) {
elsePtr = *codeptr;
err = parsecode(func, stream, codeptr);
if(err) goto cleanup;
- token = pdf_pslex(stream,buf,buflen,&len);
+ token = pdf_lex(stream,buf,buflen,&len);
if(token == PDF_TERROR || token == PDF_TEOF)
goto cleanup;
}
else
elsePtr = -1;
- if(token == PDF_TPSOPERATION) {
+ if(token == PDF_TKEYWORD) {
if(!strcmp(buf,"if")) {
if (elsePtr >= 0)
goto cleanup;
@@ -1005,13 +1005,13 @@ parsecode(pdf_function *func, fz_file *stream, int *codeptr)
else
goto cleanup;
break;
- case PDF_TPSCLOSEBRACE:
+ case PDF_TCBRACE:
resizecode(func,*codeptr);
func->u.p.code[*codeptr].type = psOperator;
func->u.p.code[*codeptr].op = psOpReturn;
++*codeptr;
return nil;
- case PDF_TPSOPERATION:
+ case PDF_TKEYWORD:
a = -1;
b = sizeof(psOpNames) / sizeof(psOpNames[0]);
// invariant: psOpNames[a] < op < psOpNames[b]
@@ -1073,7 +1073,7 @@ cleanup:
}
static fz_error *
-execpostscriptfunc(pdf_function *func, psstack *st, int codeptr)
+evalpostscriptfunc(pdf_function *func, psstack *st, int codeptr)
{
fz_error *err = nil;
int i1, i2;
@@ -1381,16 +1381,16 @@ execpostscriptfunc(pdf_function *func, psstack *st, int codeptr)
case psOpIf:
SAFE_POPBOOL(st, &b1);
if (b1) {
- execpostscriptfunc(func, st, codeptr + 2);
+ evalpostscriptfunc(func, st, codeptr + 2);
}
codeptr = func->u.p.code[codeptr + 1].blk;
break;
case psOpIfelse:
SAFE_POPBOOL(st, &b1);
if (b1) {
- execpostscriptfunc(func, st, codeptr + 2);
+ evalpostscriptfunc(func, st, codeptr + 2);
} else {
- execpostscriptfunc(func, st, func->u.p.code[codeptr].blk);
+ evalpostscriptfunc(func, st, func->u.p.code[codeptr].blk);
}
codeptr = func->u.p.code[codeptr + 1].blk;
break;
@@ -1573,7 +1573,7 @@ cleanup:
}
fz_error *
-pdf_execfunction(pdf_function *func, float *in, int inlen, float *out, int outlen)
+pdf_evalfunction(pdf_function *func, float *in, int inlen, float *out, int outlen)
{
fz_error *err = nil;
int i;
@@ -1583,13 +1583,13 @@ pdf_execfunction(pdf_function *func, float *in, int inlen, float *out, int outle
switch(func->type) {
case PDF_FUNC_SAMPLE:
- err = execsamplefunc(func, in, out);
+ err = evalsamplefunc(func, in, out);
break;
case PDF_FUNC_EXPONENTIAL:
- err = execexponentialfunc(func, *in, out);
+ err = evalexponentialfunc(func, *in, out);
break;
case PDF_FUNC_STITCHING:
- err = execstitchinigfunc(func, *in, out);
+ err = evalstitchingfunc(func, *in, out);
break;
case PDF_FUNC_POSTSCRIPT:
{
@@ -1598,7 +1598,7 @@ pdf_execfunction(pdf_function *func, float *in, int inlen, float *out, int outle
for (i = 0; i < func->m; ++i)
SAFE_PUSHREAL(&st,in[i]);
- err = execpostscriptfunc(func, &st, 0);
+ err = evalpostscriptfunc(func, &st, 0);
if(err) goto cleanup;
for (i = func->n - 1; i >= 0; --i) {
@@ -1610,4 +1610,4 @@ pdf_execfunction(pdf_function *func, float *in, int inlen, float *out, int outle
}
cleanup:
return err;
-} \ No newline at end of file
+}
diff --git a/mupdf/lex.c b/mupdf/lex.c
index 5f09c45a..7e82ba6c 100644
--- a/mupdf/lex.c
+++ b/mupdf/lex.c
@@ -319,42 +319,18 @@ pdf_lex(fz_file *f, unsigned char *buf, int n, int *sl)
return PDF_TCARRAY;
}
- else if (isnumber(c))
+ else if (c == '{')
{
- lexnumber(f, buf, n);
- *sl = strlen(buf);
- if (strchr(buf, '.'))
- return PDF_TREAL;
- return PDF_TINT;
+ fz_readbyte(f);
+ return PDF_TOBRACE;
}
- else if (isregular(c))
+ else if (c == '}')
{
- lexname(f, buf, n);
- *sl = strlen(buf);
- return tokenfromkeyword(buf);
+ fz_readbyte(f);
+ return PDF_TCBRACE;
}
- else
- return PDF_TERROR;
- }
-}
-
-int
-pdf_pslex(fz_file *f, unsigned char *buf, int n, int *sl)
-{
- int c;
-
- while (1)
- {
- c = fz_peekbyte(f);
-
- if (c == EOF)
- return PDF_TEOF;
-
- else if (iswhite(c))
- lexwhite(f);
-
else if (isnumber(c))
{
lexnumber(f, buf, n);
@@ -368,26 +344,11 @@ pdf_pslex(fz_file *f, unsigned char *buf, int n, int *sl)
{
lexname(f, buf, n);
*sl = strlen(buf);
- return PDF_TPSOPERATION;
- }
-
- else if (c == '{')
- {
- buf[0] = fz_readbyte(f);
- buf[1] = 0;
- return PDF_TPSOPENBRACE;
- }
-
- else if (c == '}')
- {
- buf[0] = fz_readbyte(f);
- buf[1] = 0;
- return PDF_TPSCLOSEBRACE;
+ return tokenfromkeyword(buf);
}
else
- {
return PDF_TERROR;
- }
}
}
+