summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2004-11-16 08:58:17 +0100
committerTor Andersson <tor@ghostscript.com>2004-11-16 08:58:17 +0100
commit3b425b8bf0c58e25da576ed86496171ea19240f9 (patch)
tree37d6feb715dd929392fb16fdde6cf994dfbc1397
parent49132f70ac40b2dc7b9a0e22b33a3964af687874 (diff)
downloadmupdf-3b425b8bf0c58e25da576ed86496171ea19240f9.tar.xz
removed c99-isms. improved bbox handling.
-rw-r--r--Jamfile3
-rw-r--r--TODO2
-rw-r--r--base/md5.c2
-rw-r--r--base/rect.c26
-rw-r--r--filter/faxd.c49
-rw-r--r--filter/faxd.h4
-rw-r--r--filter/faxe.c129
-rw-r--r--filter/filer.c2
-rw-r--r--filter/filew.c2
-rw-r--r--filter/jbig2d.c2
-rw-r--r--filter/lzwd.c79
-rw-r--r--filter/lzwe.c57
-rw-r--r--include/fitz/base.h5
-rw-r--r--include/fitz/cmap.h2
-rw-r--r--include/fitz/file.h4
-rw-r--r--include/fitz/geometry.h1
-rw-r--r--include/fitz/math.h18
-rw-r--r--include/fitz/object.h12
-rw-r--r--include/fitz/path.h20
-rw-r--r--include/fitz/render.h4
-rw-r--r--include/fitz/scanconv.h1
-rw-r--r--include/fitz/sysdep.h15
-rw-r--r--include/fitz/tree.h15
-rw-r--r--include/mupdf/syntax.h8
-rw-r--r--include/mupdf/xref.h4
-rw-r--r--mupdf/build.c13
-rw-r--r--mupdf/cmap.c22
-rw-r--r--mupdf/colorspace.c27
-rw-r--r--mupdf/crypt.c2
-rw-r--r--mupdf/font.c16
-rw-r--r--mupdf/function.c22
-rw-r--r--mupdf/image.c47
-rw-r--r--mupdf/interpret.c17
-rw-r--r--mupdf/lex.c2
-rw-r--r--mupdf/nametree.c38
-rw-r--r--mupdf/open.c20
-rw-r--r--mupdf/outline.c20
-rw-r--r--mupdf/pagetree.c2
-rw-r--r--mupdf/parse.c8
-rw-r--r--mupdf/repair.c4
-rw-r--r--mupdf/resources.c8
-rw-r--r--mupdf/type3.c17
-rw-r--r--mupdf/xobject.c3
-rw-r--r--mupdf/xref.c5
-rw-r--r--object/print.c11
-rw-r--r--object/simple.c4
-rw-r--r--render/edgelist.c20
-rw-r--r--render/glyphcache.c2
-rw-r--r--render/pixmap.c11
-rw-r--r--render/render.c82
-rw-r--r--render/renderimage.c34
-rw-r--r--render/renderpath.c14
-rw-r--r--render/rendertext.c8
-rw-r--r--render/scale.c3
-rw-r--r--render/scanconv.c2
-rw-r--r--test/pdfclean.c1
-rw-r--r--test/pdfrip.c2
-rw-r--r--test/x11pdf.c2
-rw-r--r--tree/cmap.c2
-rw-r--r--tree/colorspace.c4
-rw-r--r--tree/debug.c1
-rw-r--r--tree/node1.c5
-rw-r--r--tree/node2.c22
-rw-r--r--tree/text.c31
64 files changed, 428 insertions, 592 deletions
diff --git a/Jamfile b/Jamfile
index d7790384..f39fda5a 100644
--- a/Jamfile
+++ b/Jamfile
@@ -1,6 +1,9 @@
#
# Jamfile for Fitz
#
+# mpage -s4 -f -2 -c -H -W110 include/*/*.h */*.c > listing.ps
+# ps2pdf -sPAPERSIZE'='a4 listing.ps
+#
include $(HOME)/.jamrules ;
diff --git a/TODO b/TODO
index 9677b8ff..5be19c71 100644
--- a/TODO
+++ b/TODO
@@ -14,7 +14,6 @@ shadings
- ... jeong ...
rendering
- - aabb-bounded temp buffers
- save non-transformed bbox in nodes
- explicit mask field in fz_renderer .. general cleanup
- merge gka optims
@@ -28,6 +27,7 @@ parser
- tounicode
clean up
+ - make source ansi c89 / pedantic
- reference count everything
- standard cleanup mechanism
- naming conventions (fz_new/renew)
diff --git a/base/md5.c b/base/md5.c
index 648532a5..03601e5b 100644
--- a/base/md5.c
+++ b/base/md5.c
@@ -31,7 +31,7 @@ enum
S11 = 7, S12 = 12, S13 = 17, S14 = 22,
S21 = 5, S22 = 9, S23 = 14, S24 = 20,
S31 = 4, S32 = 11, S33 = 16, S34 = 23,
- S41 = 6, S42 = 10, S43 = 15, S44 = 21,
+ S41 = 6, S42 = 10, S43 = 15, S44 = 21
};
static void encode(unsigned char *, unsigned long *, unsigned);
diff --git a/base/rect.c b/base/rect.c
index cc8d0a76..a40701cc 100644
--- a/base/rect.c
+++ b/base/rect.c
@@ -1,5 +1,8 @@
#include <fitz.h>
+static fz_rect none = { { 0, 0}, {0, 0} };
+static fz_irect inone = { { 0, 0}, {0, 0} };
+
fz_rect
fz_infiniterect(void)
{
@@ -15,17 +18,21 @@ fz_rect
fz_intersectrects(fz_rect a, fz_rect b)
{
fz_rect r;
+ if (a.max.x < a.min.x)
+ return (b.max.x < b.min.x) ? none : b;
r.min.x = MAX(a.min.x, b.min.x);
r.min.y = MAX(a.min.y, b.min.y);
r.max.x = MIN(a.max.x, b.max.x);
r.max.y = MIN(a.max.y, b.max.y);
- return r;
+ return (r.max.x < r.min.x || r.max.y < r.min.y) ? none : r;
}
fz_rect
fz_mergerects(fz_rect a, fz_rect b)
{
fz_rect r;
+ if (a.max.x < a.min.x)
+ return (b.max.x < b.min.x) ? none : b;
r.min.x = MIN(a.min.x, b.min.x);
r.min.y = MIN(a.min.y, b.min.y);
r.max.x = MAX(a.max.x, b.max.x);
@@ -34,20 +41,35 @@ fz_mergerects(fz_rect a, fz_rect b)
}
fz_irect
+fz_roundrect(fz_rect f)
+{
+ fz_irect i;
+ i.min.x = fz_floor(f.min.x);// - 1;
+ i.min.y = fz_floor(f.min.y);// - 1;
+ i.max.x = fz_ceil(f.max.x);// + 1;
+ i.max.y = fz_ceil(f.max.y);// + 1;
+ return i;
+}
+
+fz_irect
fz_intersectirects(fz_irect a, fz_irect b)
{
fz_irect r;
+ if (a.max.x < a.min.x)
+ return (b.max.x < b.min.x) ? inone : b;
r.min.x = MAX(a.min.x, b.min.x);
r.min.y = MAX(a.min.y, b.min.y);
r.max.x = MIN(a.max.x, b.max.x);
r.max.y = MIN(a.max.y, b.max.y);
- return r;
+ return (r.max.x < r.min.x || r.max.y < r.min.y) ? inone : r;
}
fz_irect
fz_mergeirects(fz_irect a, fz_irect b)
{
fz_irect r;
+ if (a.max.x < a.min.x)
+ return (b.max.x < b.min.x) ? inone : b;
r.min.x = MIN(a.min.x, b.min.x);
r.min.y = MIN(a.min.y, b.min.y);
r.max.x = MAX(a.max.x, b.max.x);
diff --git a/filter/faxd.c b/filter/faxd.c
index 5f750588..62793dab 100644
--- a/filter/faxd.c
+++ b/filter/faxd.c
@@ -11,14 +11,6 @@ enum
SH1, SH2 /* in H part 1 and 2 (both makeup and terminating codes) */
};
-#define DEBUG 1
-
-#ifdef noDEBUG
-#define DPRINT(...) fprintf(stderr, __VA_ARGS__)
-#else
-#define DPRINT(...)
-#endif
-
/* TODO: uncompressed */
typedef struct fz_faxd_s fz_faxd;
@@ -105,11 +97,6 @@ fz_newfaxd(fz_filter **fp, fz_obj *params)
memset(fax->ref, 0, fax->stride);
memset(fax->dst, 0, fax->stride);
- DPRINT("FAXD k=%d eol=%d eba=%d cols=%d rows=%d eob=%d black1=%d stride=%d\n",
- fax->k, fax->endofline, fax->encodedbytealign,
- fax->columns, fax->rows, fax->endofblock, fax->blackis1,
- fax->stride);
-
return nil;
}
@@ -175,8 +162,6 @@ dec1d(fz_faxd *fax)
else
code = getcode(fax, cf_white_decode, cfd_white_initial_bits);
- DPRINT("%c %d\n", fax->c?'b':'w', code);
-
if (code == UNCOMPRESSED)
return fz_throw("ioerror: uncompressed data in faxd");
@@ -218,8 +203,6 @@ dec2d(fz_faxd *fax)
else
code = getcode(fax, cf_white_decode, cfd_white_initial_bits);
- DPRINT("%c %d\n", fax->c ? 'b' : 'w', code);
-
if (code == UNCOMPRESSED)
return fz_throw("ioerror: uncompressed data in faxd");
@@ -252,20 +235,17 @@ dec2d(fz_faxd *fax)
{
case H:
fax->stage = SH1;
- DPRINT("H\n");
break;
case P:
b1 = findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c);
b2 = findchanging(fax->ref, b1, fax->columns);
- DPRINT("P\n");
if (fax->c) setbits(fax->dst, fax->a, b2);
fax->a = b2;
break;
case V0:
b1 = findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c);
- DPRINT("V0\n");
if (fax->c) setbits(fax->dst, fax->a, b1);
fax->a = b1;
fax->c = !fax->c;
@@ -273,7 +253,6 @@ dec2d(fz_faxd *fax)
case VR1:
b1 = findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c);
- DPRINT("VR1\n");
if (fax->c) setbits(fax->dst, fax->a, b1 + 1);
fax->a = b1 + 1;
fax->c = !fax->c;
@@ -281,7 +260,6 @@ dec2d(fz_faxd *fax)
case VR2:
b1 = findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c);
- DPRINT("VR2\n");
if (fax->c) setbits(fax->dst, fax->a, b1 + 2);
fax->a = b1 + 2;
fax->c = !fax->c;
@@ -289,7 +267,6 @@ dec2d(fz_faxd *fax)
case VR3:
b1 = findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c);
- DPRINT("VR3\n");
if (fax->c) setbits(fax->dst, fax->a, b1 + 3);
fax->a = b1 + 3;
fax->c = !fax->c;
@@ -297,7 +274,6 @@ dec2d(fz_faxd *fax)
case VL1:
b1 = findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c);
- DPRINT("VL1\n");
if (fax->c) setbits(fax->dst, fax->a, b1 - 1);
fax->a = b1 - 1;
fax->c = !fax->c;
@@ -305,7 +281,6 @@ dec2d(fz_faxd *fax)
case VL2:
b1 = findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c);
- DPRINT("VL2\n");
if (fax->c) setbits(fax->dst, fax->a, b1 - 2);
fax->a = b1 - 2;
fax->c = !fax->c;
@@ -313,7 +288,6 @@ dec2d(fz_faxd *fax)
case VL3:
b1 = findchangingcolor(fax->ref, fax->a, fax->columns, !fax->c);
- DPRINT("VL3\n");
if (fax->c) setbits(fax->dst, fax->a, b1 - 3);
fax->a = b1 - 3;
fax->c = !fax->c;
@@ -346,14 +320,17 @@ loop:
if (fillbits(fax, in))
{
- if (in->eof) {
- if (fax->bidx > 31) {
+ if (in->eof)
+ {
+ if (fax->bidx > 31)
+ {
if (fax->a > 0)
goto eol;
goto rtc;
}
}
- else {
+ else
+ {
return fz_ioneedin;
}
}
@@ -366,17 +343,16 @@ loop:
if ((fax->word >> (32 - 12)) == 1)
{
- DPRINT("EOL\n");
eatbits(fax, 12);
fax->eolc ++;
- if (fax->k > 0) {
+ if (fax->k > 0)
+ {
if ((fax->word >> (32 - 1)) == 1)
fax->dim = 1;
else
fax->dim = 2;
eatbits(fax, 1);
- DPRINT("DIM %d\n", fax->dim);
}
}
else if (fax->dim == 1)
@@ -428,7 +404,8 @@ eol:
fax->a = -1;
fax->ridx ++;
- if (!fax->endofblock && fax->rows) {
+ if (!fax->endofblock && fax->rows)
+ {
if (fax->ridx >= fax->rows)
goto rtc;
}
@@ -442,10 +419,9 @@ eol:
fax->dim = 2;
}
- DPRINT("%dd scanline %d\n", fax->dim, fax->ridx + 1);
-
/* if endofline & encodedbytealign, EOLs are *not* optional */
- if (fax->encodedbytealign) {
+ if (fax->encodedbytealign)
+ {
if (fax->endofline)
eatbits(fax, (12 - fax->bidx) & 7);
else
@@ -455,7 +431,6 @@ eol:
goto loop;
rtc:
- DPRINT("RTC\n");
out->eof = 1;
return fz_iodone;
}
diff --git a/filter/faxd.h b/filter/faxd.h
index 886514f5..9f3fb470 100644
--- a/filter/faxd.h
+++ b/filter/faxd.h
@@ -35,7 +35,7 @@ enum
{
ERROR = -1,
ZEROS = -2, /* EOL follows, possibly with more padding first */
- UNCOMPRESSED = -3,
+ UNCOMPRESSED = -3
};
/* semantic codes for cf_2d_decode */
@@ -49,7 +49,7 @@ enum
V0 = 3,
VL1 = 4,
VL2 = 5,
- VL3 = 6,
+ VL3 = 6
};
/* Decoding tables */
diff --git a/filter/faxe.c b/filter/faxe.c
index a3f10915..e96c5ace 100644
--- a/filter/faxe.c
+++ b/filter/faxe.c
@@ -5,15 +5,6 @@
/* TODO: honor Rows param */
-#define noDEBUGBITS 1
-#define noDEBUG 1
-
-#ifdef DEBUG
-#define DPRINT(...) fprintf(stderr, __VA_ARGS__)
-#else
-#define DPRINT(...)
-#endif
-
typedef struct fz_faxe_s fz_faxe;
struct fz_faxe_s
@@ -104,8 +95,7 @@ fz_dropfaxe(fz_filter *p)
enum { codebytes = 2 };
-static inline int
-runbytes(int run)
+static inline int runbytes(int run)
{
int m = (run / 64) / 40 + 1; /* number of makeup codes */
return codebytes * (m + 1); /* bytes for makeup + term codes */
@@ -114,20 +104,14 @@ runbytes(int run)
static void
putbits(fz_faxe *fax, fz_buffer *out, int code, int nbits)
{
-#ifdef DEBUGBITS
- fprintf(stderr, "BITS ");
- printbits(stderr, code, nbits);
- fprintf(stderr, "\n");
-#endif
-
while (nbits > 0)
{
- if (fax->bidx == 0) {
+ if (fax->bidx == 0)
*out->wp = 0;
- }
/* code does not fit: shift right */
- if (nbits > (8 - fax->bidx)) {
+ if (nbits > (8 - fax->bidx))
+ {
*out->wp |= code >> (nbits - (8 - fax->bidx));
nbits = nbits - (8 - fax->bidx);
fax->bidx = 0;
@@ -135,10 +119,12 @@ putbits(fz_faxe *fax, fz_buffer *out, int code, int nbits)
}
/* shift left */
- else {
+ else
+ {
*out->wp |= code << ((8 - fax->bidx) - nbits);
fax->bidx += nbits;
- if (fax->bidx == 8) {
+ if (fax->bidx == 8)
+ {
fax->bidx = 0;
out->wp ++;
}
@@ -160,22 +146,22 @@ putrun(fz_faxe *fax, fz_buffer *out, int run, int c)
const cf_runs *codetable = c ? &cf_black_runs : &cf_white_runs;
- if (run > 63) {
+ if (run > 63)
+ {
m = run / 64;
- while (m > 40) {
- DPRINT("%c %d\n", c?'b':'w', 40 * 64);
+ while (m > 40)
+ {
putcode(fax, out, &codetable->makeup[40]);
m -= 40;
}
- if (m > 0) {
- DPRINT("%c %d\n", c?'b':'w', m * 64);
+ if (m > 0)
+ {
putcode(fax, out, &codetable->makeup[m]);
}
- DPRINT("%c %d\n", c?'b':'w', run % 64);
putcode(fax, out, &codetable->termination[run % 64]);
}
- else {
- DPRINT("%c %d\n", c?'b':'w', run);
+ else
+ {
putcode(fax, out, &codetable->termination[run]);
}
}
@@ -185,13 +171,6 @@ enc1d(fz_faxe *fax, unsigned char *line, fz_buffer *out)
{
int run;
-#ifdef DEBUG
-if (fax->a0 < 0) {
- DPRINT("1d scanline %d\n", fax->ridx + 1);
- DPRINT("color = %d\n", fax->c);
-}
-#endif
-
if (fax->a0 < 0)
fax->a0 = 0;
@@ -217,34 +196,18 @@ enc2d(fz_faxe *fax, unsigned char *ref, unsigned char *src, fz_buffer *out)
int a1, a2, b1, b2;
int run1, run2, n;
-
-#ifdef DEBUG
-if (fax->a0 < 0)
-{
- DPRINT("2d scanline %d\n", fax->ridx + 1);
-}
-#endif
-
- DPRINT("color = %d\n", fax->c);
-
while (fax->a0 < fax->columns)
{
a1 = findchanging(src, fax->a0, fax->columns);
b1 = findchangingcolor(ref, fax->a0, fax->columns, !fax->c);
b2 = findchanging(ref, b1, fax->columns);
-#ifdef DEBUGBITS
- DPRINT("twod a0=%d a1=%d b1=%d b2=%d\n", fax->a0, a1, b1, b2);
-#endif
-
/* pass */
if (b2 < a1)
{
if (out->wp + 1 + codebytes > out->ep)
return fz_ioneedout;
- DPRINT("P\n");
-
putcode(fax, out, &cf2_run_pass);
fax->a0 = b2;
@@ -256,15 +219,6 @@ if (fax->a0 < 0)
if (out->wp + 1 + codebytes > out->ep)
return fz_ioneedout;
-#ifdef DEBUG
- if (b1 - a1 == 0)
- DPRINT("V0\n");
- else if (b1 - a1 < 0)
- DPRINT("VR%d\n", a1 - b1);
- else
- DPRINT("VL%d\n", b1 - a1);
-#endif
-
putcode(fax, out, &cf2_run_vertical[b1 - a1 + 3]);
fax->a0 = a1;
@@ -282,8 +236,6 @@ if (fax->a0 < 0)
if (out->wp + 1 + n > out->ep)
return fz_ioneedout;
- DPRINT("H\n");
-
putcode(fax, out, &cf2_run_horizontal);
putrun(fax, out, run1, fax->c);
putrun(fax, out, run2, !fax->c);
@@ -311,15 +263,18 @@ process(fz_faxe *fax, fz_buffer *in, fz_buffer *out)
case 0:
if (fax->encodedbytealign)
{
- if (fax->endofline) {
+ if (fax->endofline)
+ {
if (out->wp + 1 + 1 > out->ep)
return fz_ioneedout;
/* make sure that EOL ends on a byte border */
putbits(fax, out, 0, (12 - fax->bidx) & 7);
}
- else {
- if (fax->bidx) {
+ else
+ {
+ if (fax->bidx)
+ {
if (out->wp + 1 > out->ep)
return fz_ioneedout;
fax->bidx = 0;
@@ -336,14 +291,15 @@ process(fz_faxe *fax, fz_buffer *in, fz_buffer *out)
if (out->wp + 1 + codebytes + 1 > out->ep)
return fz_ioneedout;
- DPRINT("EOL\n");
- if (fax->k > 0) {
+ if (fax->k > 0)
+ {
if (fax->ridx % fax->k == 0)
putcode(fax, out, &cf2_run_eol_1d);
else
putcode(fax, out, &cf2_run_eol_2d);
}
- else {
+ else
+ {
putcode(fax, out, &cf_run_eol);
}
}
@@ -351,7 +307,8 @@ process(fz_faxe *fax, fz_buffer *in, fz_buffer *out)
fax->stage ++;
case 2:
- if (in->rp + fax->stride > in->wp) {
+ if (in->rp + fax->stride > in->wp)
+ {
if (in->eof) /* XXX barf here? */
goto rtc;
return fz_ioneedin;
@@ -371,33 +328,27 @@ process(fz_faxe *fax, fz_buffer *in, fz_buffer *out)
fax->c = 0;
fax->a0 = -1;
-#ifdef DEBUGBITS
- DPRINT("LINE %d\n", fax->ridx);
- printline(stderr, fax->ref, fax->columns);
- printline(stderr, fax->src, fax->columns);
-#endif
-
fax->stage ++;
case 3:
error = 0; /* to silence compiler */
- if (fax->k < 0) {
+ if (fax->k < 0)
error = enc2d(fax, fax->ref, fax->src, out);
- }
- else if (fax->k == 0) {
+
+ else if (fax->k == 0)
error = enc1d(fax, fax->src, out);
- }
- else if (fax->k > 0) {
- if (fax->ridx % fax->k == 0) {
+
+ else if (fax->k > 0)
+ {
+ if (fax->ridx % fax->k == 0)
error = enc1d(fax, fax->src, out);
- }
- else {
+ else
error = enc2d(fax, fax->ref, fax->src, out);
- }
}
- if (error) return error;
+ if (error)
+ return error;
fax->ridx ++;
@@ -413,12 +364,12 @@ rtc:
if (out->wp + 1 + codebytes * n > out->ep)
return fz_ioneedout;
- for (i = 0; i < n; i++) {
+ for (i = 0; i < n; i++)
+ {
putcode(fax, out, &cf_run_eol);
if (fax->k > 0)
putbits(fax, out, 1, 1);
}
- DPRINT("RTC\n");
}
if (fax->bidx)
diff --git a/filter/filer.c b/filter/filer.c
index 30f4453f..92237778 100644
--- a/filter/filer.c
+++ b/filter/filer.c
@@ -124,7 +124,7 @@ fz_readbyte(fz_file *f)
}
int
-fz_read(fz_file *f, char *buf, int n)
+fz_read(fz_file *f, unsigned char *buf, int n)
{
int i = 0;
diff --git a/filter/filew.c b/filter/filew.c
index 53e3c120..1ac446fe 100644
--- a/filter/filew.c
+++ b/filter/filew.c
@@ -75,7 +75,7 @@ static int dowrite(fz_buffer *b, int fd)
}
int
-fz_write(fz_file *f, char *buf, int n)
+fz_write(fz_file *f, unsigned char *buf, int n)
{
fz_error *reason;
int i = 0;
diff --git a/filter/jbig2d.c b/filter/jbig2d.c
index d5922804..f0022bda 100644
--- a/filter/jbig2d.c
+++ b/filter/jbig2d.c
@@ -92,7 +92,7 @@ fz_processjbig2d(fz_filter *filter, fz_buffer *in, fz_buffer *out)
if (d->idx + len > d->page->height * d->page->stride)
len = d->page->height * d->page->stride - d->idx;
- // memcpy(out->wp, d->page->data + d->idx, len);
+ /* XXX memcpy(out->wp, d->page->data + d->idx, len); */
for (i = 0; i < len; i++)
out->wp[i] = ~ d->page->data[d->idx + i];
diff --git a/filter/lzwd.c b/filter/lzwd.c
index b3a0dcfa..74ddd9ce 100644
--- a/filter/lzwd.c
+++ b/filter/lzwd.c
@@ -2,14 +2,6 @@
/* TODO: error checking */
-#define noDEBUG 1
-
-#ifdef DEBUG
-#define DPRINT(...) fprintf(stderr, __VA_ARGS__)
-#else
-#define DPRINT(...)
-#endif
-
enum
{
MINBITS = 9,
@@ -17,14 +9,14 @@ enum
NUMCODES = (1 << MAXBITS),
LZW_CLEAR = 256,
LZW_EOD = 257,
- LZW_FIRST = 258,
+ LZW_FIRST = 258
};
typedef struct lzw_code_s lzw_code;
struct lzw_code_s
{
- int prev; /* prev code (in string) */
+ int prev; /* prev code (in string) */
unsigned short length; /* string len, including this token */
unsigned char value; /* data value */
unsigned char firstchar; /* first token of string */
@@ -41,9 +33,9 @@ struct fz_lzwd_s
unsigned int word; /* bits loaded from data */
int bidx;
- int resume; /* resume output of code from needout */
+ int resume; /* resume output of code from needout */
int codebits; /* num bits/code */
- int code; /* current code */
+ int code; /* current code */
int oldcode; /* previously recognized code */
int nextcode; /* next free entry */
lzw_code table[NUMCODES];
@@ -58,7 +50,8 @@ fz_newlzwd(fz_filter **fp, fz_obj *params)
lzw->earlychange = 0;
- if (params) {
+ if (params)
+ {
fz_obj *obj;
obj = fz_dictgets(params, "EarlyChange");
if (obj) lzw->earlychange = fz_toint(obj) != 0;
@@ -67,14 +60,16 @@ fz_newlzwd(fz_filter **fp, fz_obj *params)
lzw->bidx = 32;
lzw->word = 0;
- for (i = 0; i < 256; i++) {
+ for (i = 0; i < 256; i++)
+ {
lzw->table[i].value = i;
lzw->table[i].firstchar = i;
lzw->table[i].length = 1;
lzw->table[i].prev = -1;
}
- for (i = LZW_FIRST; i < NUMCODES; i++) {
+ for (i = LZW_FIRST; i < NUMCODES; i++)
+ {
lzw->table[i].value = 0;
lzw->table[i].firstchar = 0;
lzw->table[i].length = 0;
@@ -121,34 +116,34 @@ fz_processlzwd(fz_filter *filter, fz_buffer *in, fz_buffer *out)
unsigned char *s;
int len;
- if (lzw->resume) {
+ if (lzw->resume)
+ {
lzw->resume = 0;
goto output;
}
while (1)
{
- if (fillbits(lzw, in)) {
- DPRINT("FILL[eof=%d] bidx=%d word=%08x\n", in->eof, lzw->bidx, lzw->word);
- if (in->eof) {
- if (lzw->bidx > 32 - lzw->codebits) {
+ if (fillbits(lzw, in))
+ {
+ if (in->eof)
+ {
+ if (lzw->bidx > 32 - lzw->codebits)
+ {
out->eof = 1;
return fz_iodone;
}
}
- else {
+ else
+ {
return fz_ioneedin;
}
}
lzw->code = lzw->word >> (32 - lzw->codebits);
- DPRINT("CODE[%d]: %03x (%d)\n", lzw->codebits, lzw->code, lzw->code);
-
if (lzw->code == LZW_EOD)
{
- DPRINT("-> LZW_EOD\n");
-
eatbits(lzw, lzw->codebits);
out->eof = 1;
return fz_iodone;
@@ -156,8 +151,6 @@ fz_processlzwd(fz_filter *filter, fz_buffer *in, fz_buffer *out)
if (lzw->code == LZW_CLEAR)
{
- DPRINT("-> LZW_CLEAR\n");
-
int oldcodebits = lzw->codebits;
lzw->codebits = MINBITS;
@@ -165,18 +158,13 @@ fz_processlzwd(fz_filter *filter, fz_buffer *in, fz_buffer *out)
lzw->code = lzw->word >> (32 - oldcodebits - MINBITS) & ((1 << MINBITS) - 1);
- DPRINT("CODE[%d]: %03x (%d) [after CLEAR]\n", lzw->codebits, lzw->code, lzw->code);
-
- if (lzw->code == LZW_EOD) {
- DPRINT("-> LZW_EOD\n");
-
+ if (lzw->code == LZW_EOD)
+ {
eatbits(lzw, oldcodebits + MINBITS);
out->eof = 1;
return fz_iodone;
}
- DPRINT("-> %d\n", lzw->code);
-
if (out->wp + 1 > out->ep)
return fz_ioneedout;
@@ -192,7 +180,8 @@ fz_processlzwd(fz_filter *filter, fz_buffer *in, fz_buffer *out)
eatbits(lzw, lzw->codebits);
/* if stream starts without a clear code, oldcode is undefined... */
- if (lzw->oldcode == -1) {
+ if (lzw->oldcode == -1)
+ {
lzw->oldcode = lzw->code;
goto output;
}
@@ -206,13 +195,6 @@ fz_processlzwd(fz_filter *filter, fz_buffer *in, fz_buffer *out)
else
lzw->table[lzw->nextcode].value = lzw->table[lzw->nextcode].firstchar;
- DPRINT("NEW[%d] prev=%d, f=%d, l=%d, v=%d\n",
- lzw->nextcode,
- lzw->table[lzw->nextcode].prev,
- lzw->table[lzw->nextcode].firstchar,
- lzw->table[lzw->nextcode].length,
- lzw->table[lzw->nextcode].value);
-
lzw->nextcode ++;
if (lzw->nextcode >= (1 << lzw->codebits) - lzw->earlychange - 1)
@@ -228,7 +210,8 @@ output:
/* code maps to a string, copy to output (in reverse...) */
if (lzw->code > 255)
{
- if (out->wp + lzw->table[lzw->code].length > out->ep) {
+ if (out->wp + lzw->table[lzw->code].length > out->ep)
+ {
lzw->resume = 1;
return fz_ioneedout;
}
@@ -236,9 +219,8 @@ output:
len = lzw->table[lzw->code].length;
s = out->wp + len;
- DPRINT("OUT code=%d len=%d\n", lzw->code, len);
- do {
- DPRINT("-> %d\n", lzw->table[lzw->code].value);
+ do
+ {
*(--s) = lzw->table[lzw->code].value;
lzw->code = lzw->table[lzw->code].prev;
} while (lzw->code >= 0 && s > out->wp);
@@ -248,13 +230,12 @@ output:
/* ... or just a single character */
else
{
- if (out->wp + 1 > out->ep) {
+ if (out->wp + 1 > out->ep)
+ {
lzw->resume = 1;
return fz_ioneedout;
}
- DPRINT("OUT code=%d\n-> %d\n", lzw->code, lzw->code);
-
*out->wp++ = lzw->code;
}
}
diff --git a/filter/lzwe.c b/filter/lzwe.c
index f36afd0d..f2c3c7a4 100644
--- a/filter/lzwe.c
+++ b/filter/lzwe.c
@@ -2,12 +2,6 @@
#define noDEBUG 1
-#ifdef DEBUG
-#define DPRINT(...) fprintf(stderr, __VA_ARGS__)
-#else
-#define DPRINT(...)
-#endif
-
enum
{
MINBITS = 9,
@@ -18,7 +12,7 @@ enum
LZW_EOD = 257,
LZW_FIRST = 258,
HSIZE = 9001, /* 91% occupancy (???) */
- HSHIFT = (13 - 8),
+ HSHIFT = (13 - 8)
};
typedef struct lzw_hash_s lzw_hash;
@@ -67,7 +61,8 @@ fz_newlzwe(fz_filter **fp, fz_obj *params)
lzw->earlychange = 0;
- if (params) {
+ if (params)
+ {
fz_obj *obj;
obj = fz_dictgets(params, "EarlyChange");
if (obj) lzw->earlychange = fz_toint(obj) != 0;
@@ -100,16 +95,16 @@ putcode(fz_lzwe *lzw, fz_buffer *out, int code)
{
int nbits = lzw->codebits;
- DPRINT("CODE[%d] %d\n", nbits, code);
-
while (nbits > 0)
{
- if (lzw->bidx == 0) {
+ if (lzw->bidx == 0)
+ {
*out->wp = 0;
}
/* code does not fit: shift right */
- if (nbits > (8 - lzw->bidx)) {
+ if (nbits > (8 - lzw->bidx))
+ {
*out->wp |= code >> (nbits - (8 - lzw->bidx));
nbits = nbits - (8 - lzw->bidx);
lzw->bidx = 0;
@@ -117,10 +112,12 @@ putcode(fz_lzwe *lzw, fz_buffer *out, int code)
}
/* shift left */
- else {
+ else
+ {
*out->wp |= code << ((8 - lzw->bidx) - nbits);
lzw->bidx += nbits;
- if (lzw->bidx == 8) {
+ if (lzw->bidx == 8)
+ {
lzw->bidx = 0;
out->wp ++;
}
@@ -133,7 +130,8 @@ putcode(fz_lzwe *lzw, fz_buffer *out, int code)
static fz_error *
compress(fz_lzwe *lzw, fz_buffer *in, fz_buffer *out)
{
- if (lzw->resume) {
+ if (lzw->resume)
+ {
lzw->resume = 0;
goto resume;
}
@@ -144,7 +142,8 @@ compress(fz_lzwe *lzw, fz_buffer *in, fz_buffer *out)
if (out->wp + 3 > out->ep)
return fz_ioneedout;
- if (in->rp + 1 > in->wp) {
+ if (in->rp + 1 > in->wp)
+ {
if (in->eof)
goto eof;
return fz_ioneedin;
@@ -158,7 +157,8 @@ compress(fz_lzwe *lzw, fz_buffer *in, fz_buffer *out)
begin:
while (1)
{
- if (in->rp + 1 > in->wp) {
+ if (in->rp + 1 > in->wp)
+ {
if (in->eof)
goto eof;
return fz_ioneedin;
@@ -167,28 +167,30 @@ begin:
/* read character */
lzw->code = *in->rp++;
- DPRINT("READ %d\n", lzw->code);
-
/* hash string + character */
lzw->fcode = (lzw->code << MAXBITS) + lzw->oldcode;
lzw->hcode = (lzw->code << HSHIFT) ^ lzw->oldcode;
/* primary hash */
- if (lzw->table[lzw->hcode].hash == lzw->fcode) {
+ if (lzw->table[lzw->hcode].hash == lzw->fcode)
+ {
lzw->oldcode = lzw->table[lzw->hcode].code;
continue;
}
/* secondary hash */
- if (lzw->table[lzw->hcode].hash != -1) {
+ if (lzw->table[lzw->hcode].hash != -1)
+ {
int disp = HSIZE - lzw->hcode;
if (lzw->hcode == 0)
disp = 1;
- do {
+ do
+ {
lzw->hcode = lzw->hcode - disp;
if (lzw->hcode < 0)
lzw->hcode += HSIZE;
- if (lzw->table[lzw->hcode].hash == lzw->fcode) {
+ if (lzw->table[lzw->hcode].hash == lzw->fcode)
+ {
lzw->oldcode = lzw->table[lzw->hcode].code;
goto begin;
}
@@ -199,7 +201,8 @@ resume:
/* new entry: emit code and add to table */
/* reserve space for this code and an eventual CLEAR code */
- if (out->wp + 5 > out->ep) {
+ if (out->wp + 5 > out->ep)
+ {
lzw->resume = 1;
return fz_ioneedout;
}
@@ -213,7 +216,8 @@ resume:
lzw->nextcode ++;
/* table is full: emit clear code and reset */
- if (lzw->nextcode == NUMCODES - 1) {
+ if (lzw->nextcode == NUMCODES - 1)
+ {
putcode(lzw, out, LZW_CLEAR);
clearhash(lzw);
lzw->nextcode = LZW_FIRST;
@@ -221,7 +225,8 @@ resume:
}
/* check if next entry will be too big for the code size */
- else if (lzw->nextcode >= (1 << lzw->codebits) - lzw->earlychange) {
+ else if (lzw->nextcode >= (1 << lzw->codebits) - lzw->earlychange)
+ {
lzw->codebits ++;
}
}
diff --git a/include/fitz/base.h b/include/fitz/base.h
index d1c5343a..4741f297 100644
--- a/include/fitz/base.h
+++ b/include/fitz/base.h
@@ -37,10 +37,13 @@ extern fz_error fz_koutofmem;
#ifdef WIN32
#define fz_throw(...) fz_throw0(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
+#elif _ISOC99_SOURCE
+#define fz_throw(...) fz_throw0(__func__, __FILE__, __LINE__, __VA_ARGS__)
#else
-#define fz_throw(fmt, ...) fz_throw0(__func__, __FILE__, __LINE__, fmt, ## __VA_ARGS__)
+#define fz_throw fz_throw1
#endif
fz_error *fz_throw0(const char *func, const char *file, int line, char *fmt, ...);
+fz_error *fz_throw1(char *fmt, ...);
void fz_warn(char *fmt, ...);
void fz_abort(fz_error *eo);
diff --git a/include/fitz/cmap.h b/include/fitz/cmap.h
index 768d896a..c5a4ad6f 100644
--- a/include/fitz/cmap.h
+++ b/include/fitz/cmap.h
@@ -22,5 +22,5 @@ fz_error *fz_addcidrange(fz_cmap *cmap, int srclo, int srchi, int dstlo);
fz_error *fz_endcidrange(fz_cmap *cmap);
int fz_lookupcid(fz_cmap *cmap, int cpt);
-char *fz_decodecpt(fz_cmap *cmap, unsigned char *s, int *cpt);
+unsigned char *fz_decodecpt(fz_cmap *cmap, unsigned char *s, int *cpt);
diff --git a/include/fitz/file.h b/include/fitz/file.h
index 6179085a..c87ccf5d 100644
--- a/include/fitz/file.h
+++ b/include/fitz/file.h
@@ -26,13 +26,13 @@ int fz_tell(fz_file *f);
int fz_readbyte(fz_file *f);
int fz_peekbyte(fz_file *f);
int fz_readline(fz_file *f, char *buf, int n);
-int fz_read(fz_file *f, char *buf, int n);
+int fz_read(fz_file *f, unsigned char *buf, int n);
fz_error *fz_readfile(fz_buffer **bufp, fz_file *file);
int fz_printstring(fz_file *f, char *s);
int fz_printobj(fz_file *f, fz_obj *o, int tight);
int fz_print(fz_file *f, char *fmt, ...);
-int fz_write(fz_file *f, char *buf, int n);
+int fz_write(fz_file *f, unsigned char *buf, int n);
int fz_flush(fz_file *f);
diff --git a/include/fitz/geometry.h b/include/fitz/geometry.h
index 78e9e637..8909b229 100644
--- a/include/fitz/geometry.h
+++ b/include/fitz/geometry.h
@@ -49,6 +49,7 @@ int fz_isrectilinear(fz_matrix m);
fz_rect fz_intersectrects(fz_rect a, fz_rect b);
fz_rect fz_mergerects(fz_rect a, fz_rect b);
+fz_irect fz_roundrect(fz_rect r);
fz_irect fz_intersectirects(fz_irect a, fz_irect b);
fz_irect fz_mergeirects(fz_irect a, fz_irect b);
diff --git a/include/fitz/math.h b/include/fitz/math.h
index b2f1bf24..4dee81fc 100644
--- a/include/fitz/math.h
+++ b/include/fitz/math.h
@@ -1,19 +1,7 @@
/* multiply 8-bit fixpoint (0..1) so that 0*0==0 and 255*255==255 */
-static inline unsigned char fz_mul255(unsigned char a, unsigned char b)
-{
- return (a * ((unsigned int)b + 1)) >> 8;
-}
-
-/* floor / ceil towards/from +/- inf */
-static inline float fz_floor(float x)
-{
- return floor(x);
-}
-
-static inline float fz_ceil(float x)
-{
- return ceil(x);
-}
+#define fz_mul255(a,b) (((a) * ((b) + 1)) >> 8)
+#define fz_floor(x) floor(x)
+#define fz_ceil(x) ceil(x)
/* divide and floor towards -inf */
static inline int fz_idiv(int a, int b)
diff --git a/include/fitz/object.h b/include/fitz/object.h
index 41025b8b..777e889f 100644
--- a/include/fitz/object.h
+++ b/include/fitz/object.h
@@ -1,8 +1,6 @@
typedef struct fz_obj_s fz_obj;
-typedef enum fz_objkind_e fz_objkind;
-
-enum fz_objkind_e
+typedef enum fz_objkind_e
{
FZ_NULL,
FZ_BOOL,
@@ -13,8 +11,8 @@ enum fz_objkind_e
FZ_ARRAY,
FZ_DICT,
FZ_INDIRECT,
- FZ_POINTER,
-};
+ FZ_POINTER
+} fz_objkind;
struct fz_keyval_s
{
@@ -33,9 +31,9 @@ struct fz_obj_s
float f;
struct {
unsigned short len;
- unsigned char buf[];
+ char buf[1];
} s;
- unsigned char n[1];
+ char n[1];
struct {
int len;
int cap;
diff --git a/include/fitz/path.h b/include/fitz/path.h
index f128d86e..f0a3d573 100644
--- a/include/fitz/path.h
+++ b/include/fitz/path.h
@@ -1,11 +1,21 @@
-typedef enum fz_pathkind_e fz_pathkind;
-typedef enum fz_pathelkind_e fz_pathelkind;
typedef struct fz_stroke_s fz_stroke;
typedef struct fz_dash_s fz_dash;
typedef union fz_pathel_s fz_pathel;
-enum fz_pathkind_e { FZ_STROKE, FZ_FILL, FZ_EOFILL };
-enum fz_pathelkind_e { FZ_MOVETO, FZ_LINETO, FZ_CURVETO, FZ_CLOSEPATH };
+typedef enum fz_pathkind_e
+{
+ FZ_STROKE,
+ FZ_FILL,
+ FZ_EOFILL
+} fz_pathkind;
+
+typedef enum fz_pathelkind_e
+{
+ FZ_MOVETO,
+ FZ_LINETO,
+ FZ_CURVETO,
+ FZ_CLOSEPATH
+} fz_pathelkind;
struct fz_stroke_s
{
@@ -19,7 +29,7 @@ struct fz_dash_s
{
int len;
float phase;
- float array[];
+ float array[FZ_FLEX];
};
union fz_pathel_s
diff --git a/include/fitz/render.h b/include/fitz/render.h
index ac25a09d..53030a9c 100644
--- a/include/fitz/render.h
+++ b/include/fitz/render.h
@@ -9,7 +9,7 @@ struct fz_renderer_s
fz_gel *gel;
fz_ael *ael;
int mode;
- int x, y, w, h;
+ fz_irect clip;
fz_pixmap *tmp;
fz_pixmap *acc;
unsigned char r, g, b;
@@ -23,5 +23,5 @@ fz_error *fz_rendermask(fz_renderer *gc, fz_masknode *mask, fz_matrix ctm);
fz_error *fz_rendertransform(fz_renderer *gc, fz_transformnode *xform, fz_matrix ctm);
fz_error *fz_rendertext(fz_renderer *gc, fz_textnode *text, fz_matrix ctm);
fz_error *fz_rendernode(fz_renderer *gc, fz_node *node, fz_matrix ctm);
-fz_error *fz_rendertree(fz_pixmap **out, fz_renderer *gc, fz_tree *tree, fz_matrix ctm, fz_rect bbox);
+fz_error *fz_rendertree(fz_pixmap **out, fz_renderer *gc, fz_tree *tree, fz_matrix ctm, fz_irect bbox);
diff --git a/include/fitz/scanconv.h b/include/fitz/scanconv.h
index 8fefe271..675d6806 100644
--- a/include/fitz/scanconv.h
+++ b/include/fitz/scanconv.h
@@ -29,6 +29,7 @@ struct fz_ael_s
fz_error *fz_newgel(fz_gel **gelp);
fz_error *fz_insertgel(fz_gel *gel, float x0, float y0, float x1, float y1);
+fz_irect fz_boundgel(fz_gel *gel);
void fz_resetgel(fz_gel *gel, int hs, int vs);
void fz_sortgel(fz_gel *gel);
void fz_dropgel(fz_gel *gel);
diff --git a/include/fitz/sysdep.h b/include/fitz/sysdep.h
index 3e0f3232..dd4b8fd3 100644
--- a/include/fitz/sysdep.h
+++ b/include/fitz/sysdep.h
@@ -14,11 +14,17 @@
#include <errno.h>
#include <fcntl.h> /* O_RDONLY & co */
-#ifdef _ISOC99_SOURCE
-#elif __GNUC__
-#define restrict __restrict__
+#ifdef HAVE_C99
+
+#define FZ_FLEX
+
#else
+
+#define FZ_FLEX 0
#define restrict
+#define inline __inline__
+#define va_copy(a,b) (a) = (b)
+
#endif
#ifdef WIN32
@@ -50,7 +56,10 @@
#else
+#ifndef O_BINARY
#define O_BINARY 0
+#endif
+
#include <unistd.h>
#endif
diff --git a/include/fitz/tree.h b/include/fitz/tree.h
index b5cd8c8e..eebf2c38 100644
--- a/include/fitz/tree.h
+++ b/include/fitz/tree.h
@@ -19,9 +19,6 @@ void fz_insertnode(fz_node *parent, fz_node *child);
/* node types */
-typedef enum fz_nodekind_e fz_nodekind;
-typedef enum fz_blendkind_e fz_blendkind;
-
typedef struct fz_transformnode_s fz_transformnode;
typedef struct fz_overnode_s fz_overnode;
typedef struct fz_masknode_s fz_masknode;
@@ -34,7 +31,7 @@ typedef struct fz_shadenode_s fz_shadenode;
typedef struct fz_linknode_s fz_linknode;
typedef struct fz_metanode_s fz_metanode;
-enum fz_nodekind_e
+typedef enum fz_nodekind_e
{
FZ_NTRANSFORM,
FZ_NOVER,
@@ -47,9 +44,9 @@ enum fz_nodekind_e
FZ_NSHADE,
FZ_NLINK,
FZ_NMETA
-};
+} fz_nodekind;
-enum fz_blendkind_e
+typedef enum fz_blendkind_e
{
/* PDF 1.4 -- standard separable */
FZ_BNORMAL,
@@ -72,8 +69,8 @@ enum fz_blendkind_e
FZ_BLUMINOSITY,
FZ_BOVERPRINT,
- FZ_BRASTEROP,
-};
+ FZ_BRASTEROP
+} fz_blendkind;
struct fz_node_s
{
@@ -113,7 +110,7 @@ struct fz_colornode_s
fz_node super;
fz_colorspace *cs;
int n;
- float samples[];
+ float samples[FZ_FLEX];
};
struct fz_linknode_s
diff --git a/include/mupdf/syntax.h b/include/mupdf/syntax.h
index ce9d9c80..a56c5f18 100644
--- a/include/mupdf/syntax.h
+++ b/include/mupdf/syntax.h
@@ -20,10 +20,10 @@ enum
int pdf_lex(fz_file *f, unsigned char *buf, int n, int *len);
/* parse.c */
-fz_error *pdf_parsearray(fz_obj **op, fz_file *f, unsigned char *buf, int cap);
-fz_error *pdf_parsedict(fz_obj **op, fz_file *f, unsigned char *buf, int cap);
-fz_error *pdf_parsestmobj(fz_obj **op, fz_file *f, unsigned char *buf, int cap);
-fz_error *pdf_parseindobj(fz_obj **op, fz_file *f, unsigned char *buf, int cap, int *oid, int *gid, int *stmofs);
+fz_error *pdf_parsearray(fz_obj **op, fz_file *f, char *buf, int cap);
+fz_error *pdf_parsedict(fz_obj **op, fz_file *f, char *buf, int cap);
+fz_error *pdf_parsestmobj(fz_obj **op, fz_file *f, char *buf, int cap);
+fz_error *pdf_parseindobj(fz_obj **op, fz_file *f, char *buf, int cap, int *oid, int *gid, int *stmofs);
/*
* Encryption
diff --git a/include/mupdf/xref.h b/include/mupdf/xref.h
index 2ccd3710..e189ba6a 100644
--- a/include/mupdf/xref.h
+++ b/include/mupdf/xref.h
@@ -34,7 +34,7 @@ struct pdf_xrefentry_s
char type; /* 0=unset (f)ree i(n)use (o)bjstm (d)elete (a)dd */
char mark; /* for garbage collection etc */
fz_buffer *stmbuf; /* in-memory stream */
- unsigned int stmofs; /* on-disk stream */
+ int stmofs; /* on-disk stream */
fz_obj *obj; /* stored/cached object */
};
@@ -70,6 +70,6 @@ fz_error *pdf_garbagecollect(pdf_xref *xref);
fz_error *pdf_transplant(pdf_xref *dst, pdf_xref *src, fz_obj **newp, fz_obj *old);
/* private */
-fz_error *pdf_loadobjstm(pdf_xref *xref, int oid, int gen, unsigned char *buf, int cap);
+fz_error *pdf_loadobjstm(pdf_xref *xref, int oid, int gen, char *buf, int cap);
fz_error *pdf_decryptpdf(pdf_xref *xref);
diff --git a/mupdf/build.c b/mupdf/build.c
index 01a7c653..3b602e89 100644
--- a/mupdf/build.c
+++ b/mupdf/build.c
@@ -48,10 +48,10 @@ pdf_setcolorspace(pdf_csi *csi, int what, fz_colorspace *cs)
mat->kind = PDF_MCOLOR;
mat->cs = cs;
- mat->v[0] = 0; // FIXME: default color
- mat->v[1] = 0; // FIXME: default color
- mat->v[2] = 0; // FIXME: default color
- mat->v[3] = 1; // FIXME: default color
+ mat->v[0] = 0; /* FIXME: default color */
+ mat->v[1] = 0; /* FIXME: default color */
+ mat->v[2] = 0; /* FIXME: default color */
+ mat->v[3] = 1; /* FIXME: default color */
if (!strcmp(cs->name, "Indexed"))
{
@@ -661,11 +661,6 @@ pdf_showtext(pdf_csi *csi, fz_obj *text)
cid = fz_lookupcid(font->encoding, cpt);
-//printf("gl %s %g [%g %g %g %g %g %g] cpt<%02x> cid %d h %d\n",
-// font->super.name, size,
-// csi->tm.a, csi->tm.b, csi->tm.c, csi->tm.d, csi->tm.e, csi->tm.f,
-// cpt, cid, font->super.hadv[gid]);
-
error = showglyph(csi, cid);
if (error)
return error;
diff --git a/mupdf/cmap.c b/mupdf/cmap.c
index 7914bf68..dff96b43 100644
--- a/mupdf/cmap.c
+++ b/mupdf/cmap.c
@@ -16,7 +16,7 @@ enum
TENDCIDRANGE,
};
-static int tokenfromkeyword(unsigned char *key)
+static int tokenfromkeyword(char *key)
{
if (!strcmp(key, "usecmap")) return TUSECMAP;
if (!strcmp(key, "begincodespacerange")) return TBEGINCODESPACERANGE;
@@ -40,7 +40,7 @@ static int codefromstring(unsigned char *buf, int len)
return a;
}
-static int mylex(fz_file *file, unsigned char *buf, int n, int *sl)
+static int mylex(fz_file *file, char *buf, int n, int *sl)
{
int token = pdf_lex(file, buf, n, sl);
if (token == PDF_TKEYWORD)
@@ -50,7 +50,7 @@ static int mylex(fz_file *file, unsigned char *buf, int n, int *sl)
static fz_error *parsecmapname(fz_cmap *cmap, fz_file *file)
{
- unsigned char buf[256];
+ char buf[256];
int token;
int len;
@@ -65,7 +65,7 @@ static fz_error *parsecmapname(fz_cmap *cmap, fz_file *file)
static fz_error *parsewmode(fz_cmap *cmap, fz_file *file)
{
- unsigned char buf[256];
+ char buf[256];
int token;
int len;
@@ -80,7 +80,7 @@ static fz_error *parsewmode(fz_cmap *cmap, fz_file *file)
static fz_error *parsecodespacerange(fz_cmap *cmap, fz_file *file)
{
- unsigned char buf[256];
+ char buf[256];
int token;
int len;
fz_error *error;
@@ -115,7 +115,7 @@ static fz_error *parsecodespacerange(fz_cmap *cmap, fz_file *file)
static fz_error *parsecidrange(fz_cmap *cmap, fz_file *file)
{
- unsigned char buf[256];
+ char buf[256];
int token;
int len;
fz_error *error;
@@ -156,7 +156,7 @@ cleanup:
static fz_error *parsecidchar(fz_cmap *cmap, fz_file *file)
{
- unsigned char buf[256];
+ char buf[256];
int token;
int len;
fz_error *error;
@@ -191,7 +191,7 @@ cleanup:
static fz_error *parsebfrange(fz_cmap *cmap, fz_file *file)
{
- unsigned char buf[256];
+ char buf[256];
int token;
int len;
fz_error *error;
@@ -233,7 +233,7 @@ cleanup:
static fz_error *parsebfchar(fz_cmap *cmap, fz_file *file)
{
- unsigned char buf[256];
+ char buf[256];
int token;
int len;
fz_error *error;
@@ -272,8 +272,8 @@ pdf_parsecmap(fz_cmap **cmapp, fz_file *file)
{
fz_error *error;
fz_cmap *cmap;
- unsigned char key[64];
- unsigned char buf[256];
+ char key[64];
+ char buf[256];
int token;
int len;
diff --git a/mupdf/colorspace.c b/mupdf/colorspace.c
index a52f3ed0..000de777 100644
--- a/mupdf/colorspace.c
+++ b/mupdf/colorspace.c
@@ -313,11 +313,12 @@ static void devicecmyktoxyz(fz_colorspace *cs, float *cmyk, float *xyz)
static void xyztodevicecmyk(fz_colorspace *cs, float *xyz, float *cmyk)
{
float rgb[3];
+ float c, m, y, k;
xyztorgb(pdf_devicergb, xyz, rgb);
- float c = 1.0 - rgb[0];
- float m = 1.0 - rgb[0];
- float y = 1.0 - rgb[0];
- float k = MIN(c, MIN(y, k));
+ c = 1.0 - rgb[0];
+ m = 1.0 - rgb[0];
+ y = 1.0 - rgb[0];
+ k = MIN(c, MIN(m, y));
cmyk[0] = c - k;
cmyk[1] = m - k;
cmyk[2] = y - k;
@@ -360,16 +361,17 @@ static inline float cielabinvg(float x)
static void labtoxyz(fz_colorspace *fzcs, float *lab, float *xyz)
{
struct cielab *cs = (struct cielab *) fzcs;
+ float lstar, astar, bstar, l, m, n;
float tmp[3];
tmp[0] = lab[0] * 100;
tmp[1] = lab[1] * 200 - 100;
tmp[2] = lab[2] * 200 - 100;
- float lstar = tmp[0];
- float astar = MAX(MIN(tmp[1], cs->range[1]), cs->range[0]);
- float bstar = MAX(MIN(tmp[2], cs->range[3]), cs->range[2]);
- float l = ((lstar * 16.0) / 116.0) + (astar / 500.0);
- float m = (lstar * 16.0) / 116.0;
- float n = ((lstar * 16.0) / 116.0) - (bstar / 200.0);
+ lstar = tmp[0];
+ astar = MAX(MIN(tmp[1], cs->range[1]), cs->range[0]);
+ bstar = MAX(MIN(tmp[2], cs->range[3]), cs->range[2]);
+ l = ((lstar * 16.0) / 116.0) + (astar / 500.0);
+ m = (lstar * 16.0) / 116.0;
+ n = ((lstar * 16.0) / 116.0) - (bstar / 200.0);
xyz[0] = cs->white[0] * cielabg(l);
xyz[1] = cs->white[1] * cielabg(m);
xyz[2] = cs->white[2] * cielabg(n);
@@ -688,10 +690,6 @@ loadindexed(fz_colorspace **csp, pdf_xref *xref, fz_obj *array)
fz_error *
pdf_loadcolorspace(fz_colorspace **csp, pdf_xref *xref, fz_obj *obj)
{
-printf("loading colorspace: ");
-fz_debugobj(obj);
-printf("\n");
-
if (fz_isname(obj))
{
if (!strcmp(fz_toname(obj), "DeviceGray"))
@@ -778,7 +776,6 @@ printf("\n");
/* pretend this never happened... */
if (!strcmp(fz_toname(name), "Pattern"))
{
-printf("oopsie, got a pattern colorspace\n");
return pdf_loadcolorspace(csp, xref, fz_arrayget(obj, 1));
}
}
diff --git a/mupdf/crypt.c b/mupdf/crypt.c
index 302f4588..93ff8959 100644
--- a/mupdf/crypt.c
+++ b/mupdf/crypt.c
@@ -152,7 +152,7 @@ createobjkey(pdf_crypt *crypt, unsigned oid, unsigned gid, unsigned char *key)
* Algorithm 3.2 Computing an encryption key
*/
static void
-createkey(pdf_crypt *crypt, unsigned char *userpw)
+createkey(pdf_crypt *crypt, char *userpw)
{
unsigned char buf[32];
fz_md5 md5;
diff --git a/mupdf/font.c b/mupdf/font.c
index 0e216ea4..7ad43cfc 100644
--- a/mupdf/font.c
+++ b/mupdf/font.c
@@ -133,7 +133,6 @@ ftrender(fz_glyph *glyph, fz_font *fzfont, int cid, fz_matrix trm)
FT_Set_Transform(face, &m, &v);
fterr = FT_Load_Glyph(face, gid, FT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING);
- //fterr = FT_Load_Glyph(face, gid, FT_LOAD_NO_BITMAP);
if (fterr)
return fz_throw("freetype failed to load glyph: 0x%x", fterr);
@@ -225,7 +224,14 @@ static void ftdropfont(fz_font *font)
pdf_font *pfont = (pdf_font*)font;
if (pfont->encoding)
fz_dropcmap(pfont->encoding);
- // XXX free freetype face
+ if (pfont->tounicode)
+ fz_dropcmap(pfont->tounicode);
+ fz_free(pfont->cidtogid);
+ fz_free(pfont->cidtoucs);
+ if (pfont->ftface)
+ FT_Done_Face((FT_Face)pfont->ftface);
+ if (pfont->fontdata)
+ fz_dropbuffer(pfont->fontdata);
}
pdf_font *
@@ -795,10 +801,6 @@ printf(" cidtogidmap %d\n", len / 2);
if (error)
goto cleanup;
-//printf(" W2 ");
-//fz_debugobj(widths);
-//printf("\n");
-
for (i = 0; i < fz_arraylen(widths); )
{
c0 = fz_toint(fz_arrayget(widths, i));
@@ -841,8 +843,6 @@ printf(" cidtogidmap %d\n", len / 2);
printf("\n");
-//fz_debugfont((fz_font*)font);
-
return nil;
cleanup:
diff --git a/mupdf/function.c b/mupdf/function.c
index 0331607d..643d2fef 100644
--- a/mupdf/function.c
+++ b/mupdf/function.c
@@ -151,9 +151,9 @@ enum psop_e {
psOpReturn
};
-// Note: 'if' and 'ifelse' are parsed separately.
-// The rest are listed here in alphabetical order.
-// The index in this table is equivalent to the entry in PSOp.
+/* Note: 'if' and 'ifelse' are parsed separately.
+ * The rest are listed here in alphabetical order.
+ * The index in this table is equivalent to the entry in PSOp. */
char *psOpNames[] = {
"abs",
"add",
@@ -608,7 +608,7 @@ evalsamplefunc(pdf_function *func, float *in, float *out)
switch(func->u.sa.order) {
case 3:
- //cubic spline interpolation
+ /* cubic spline interpolation */
case 1:
for (i = 0; i < func->m; ++i) {
x = in[i];
@@ -625,9 +625,9 @@ evalsamplefunc(pdf_function *func, float *in, float *out)
efrac[i] = x - e[0][i];
}
- // for each output, do m-linear interpolation
+ /* for each output, do m-linear interpolation */
for (i = 0; i < func->n; ++i) {
- // pull 2^m values out of the sample array
+ /* pull 2^m values out of the sample array */
for (j = 0; j < (1 << func->m); ++j) {
idx = 0;
for (k = func->m - 1; k >= 0; --k) {
@@ -637,7 +637,7 @@ evalsamplefunc(pdf_function *func, float *in, float *out)
s0[j] = func->u.sa.samples[idx];
}
- // do m sets of interpolations
+ /* do m sets of interpolations */
for (j = 0; j < func->m; ++j) {
for (k = 0; k < (1 << (func->m - j)); k += 2) {
s1[k >> 1] = (1 - efrac[j]) * s0[k] + efrac[j] * s0[k+1];
@@ -645,8 +645,8 @@ evalsamplefunc(pdf_function *func, float *in, float *out)
memcpy(s0, s1, (1 << (func->m - j - 1)) * sizeof(float));
}
- // map output value to range
- //out[i] = s0[0] * (decode[i*2+1] - decode[i*2]) + decode[i*2];
+ /* map output value to range */
+ /*out[i] = s0[0] * (decode[i*2+1] - decode[i*2]) + decode[i*2]; */
out[i] = INTERPOLATE(s0[0],0,byterange,decode[i*2],decode[i*2+1]);
MIN_MAX(out[i],range[i*2],range[i*2+1]);
}
@@ -994,7 +994,7 @@ parsecode(pdf_function *func, fz_file *stream, int *codeptr)
case PDF_TKEYWORD:
a = -1;
b = sizeof(psOpNames) / sizeof(psOpNames[0]);
- // invariant: psOpNames[a] < op < psOpNames[b]
+ /* invariant: psOpNames[a] < op < psOpNames[b] */
while (b - a > 1) {
mid = (a + b) / 2;
cmp = strcmp(buf,psOpNames[mid]);
@@ -1251,7 +1251,7 @@ evalpostscriptfunc(pdf_function *func, psstack *st, int codeptr)
if (toptwoareints(st)) {
SAFE_POPINT(st,&i2);
SAFE_POPINT(st,&i1);
- //~ should check for out-of-range, and push a real instead
+ /*~ should check for out-of-range, and push a real instead */
SAFE_PUSHINT(st,i1 * i2);
} else {
SAFE_POPNUM(st, &r2);
diff --git a/mupdf/image.c b/mupdf/image.c
index 0c70a6df..8d8f60a8 100644
--- a/mupdf/image.c
+++ b/mupdf/image.c
@@ -81,15 +81,6 @@ decodetile(fz_pixmap *pix, int bpc, int skip, float *decode)
float invtwon = 1.0 / ((1 << bpc) - 1);
int x, y, k, i;
-printf(" decode bpc=%d skip=%d n=%d invtwon=%g\n", bpc, skip, pix->n, invtwon);
-
- for (k = skip; k < pix->n; k++)
- {
- float min = decode[(k - skip) * 2 + 0];
- float max = decode[(k - skip) * 2 + 1];
- printf(" k=%d min=%g max=%g\n", k, min, max);
- }
-
for (i = 0; i < (1 << bpc); i++)
{
if (skip)
@@ -140,8 +131,8 @@ loadtile(fz_image *img, fz_pixmap *tile)
switch (src->bpc)
{
case 1: loadtile1(src, tmp, 1); break;
- // case 2: loadtile2(src, tmp, 1); break;
- // case 4: loadtile4(src, tmp, 1); break;
+ /* case 2: loadtile2(src, tmp, 1); break; */
+ /* case 4: loadtile4(src, tmp, 1); break; */
case 8: loadtile8(src, tmp, 1); break;
default:
return fz_throw("rangecheck: unsupported bit depth: %d", src->bpc);
@@ -173,8 +164,8 @@ printf(" unpack n=%d\n", tile->n);
switch (src->bpc)
{
case 1: loadtile1(src, tile, img->n + img->a); break;
- // case 2: loadtile2(src, tile, img->n + img->a); break;
- // case 4: loadtile4(src, tile, img->n + img->a); break;
+ /* case 2: loadtile2(src, tile, img->n + img->a); break; */
+ /* case 4: loadtile4(src, tile, img->n + img->a); break; */
case 8: loadtile8(src, tile, img->n + img->a); break;
default:
return fz_throw("rangecheck: unsupported bit depth: %d", src->bpc);
@@ -185,8 +176,8 @@ printf(" unpack n=%d\n", tile->n);
switch (src->bpc)
{
case 1: loadtile1a(src, tile, img->n); break;
- // case 2: loadtile2a(src, tile, img->n); break;
- // case 4: loadtile4a(src, tile, img->n); break;
+ /* case 2: loadtile2a(src, tile, img->n); break; */
+ /* case 4: loadtile4a(src, tile, img->n); break; */
case 8: loadtile8a(src, tile, img->n); break;
default:
return fz_throw("rangecheck: unsupported bit depth: %d", src->bpc);
@@ -215,8 +206,6 @@ pdf_loadinlineimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_file *fil
if (!img)
return fz_outofmem;
-printf("inline image ");fz_debugobj(dict);printf("\n");
-
img->super.loadtile = loadtile;
img->super.drop = pdf_dropimage;
img->super.n = 0;
@@ -247,7 +236,6 @@ printf("inline image ");fz_debugobj(dict);printf("\n");
img->super.a = 0;
if (!strcmp(img->super.cs->name, "Indexed"))
{
-printf(" indexed!\n");
img->indexed = (pdf_indexed*)img->super.cs;
img->super.cs = img->indexed->base;
}
@@ -255,7 +243,6 @@ printf(" indexed!\n");
if (fz_isarray(d))
{
-printf(" decode array!\n");
if (img->indexed)
for (i = 0; i < 2; i++)
img->decode[i] = fz_toreal(fz_arrayget(d, i));
@@ -303,15 +290,11 @@ printf(" decode array!\n");
if (error)
return error;
-printf(" nullfilter %d\n", img->super.h * img->stride);
-
i = fz_read(file, img->samples->bp, img->super.h * img->stride);
error = fz_ferror(file);
if (error)
return error;
-printf(" read %d\n", i);
-
img->samples->wp += img->super.h * img->stride;
}
@@ -345,8 +328,6 @@ pdf_loadimage(pdf_image **imgp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
pdf_indexed *indexed = nil;
int stride;
-printf("loading image "); fz_debugobj(dict); printf("\n");
-
img = fz_malloc(sizeof(pdf_image));
if (!img)
return fz_outofmem;
@@ -359,8 +340,6 @@ printf("loading image "); fz_debugobj(dict); printf("\n");
h = fz_toint(fz_dictgets(dict, "Height"));
bpc = fz_toint(fz_dictgets(dict, "BitsPerComponent"));
-printf(" geometry %d x %d @ %d\n", w, h, bpc);
-
cs = nil;
obj = fz_dictgets(dict, "ColorSpace");
if (obj)
@@ -375,7 +354,6 @@ printf(" geometry %d x %d @ %d\n", w, h, bpc);
if (!strcmp(cs->name, "Indexed"))
{
-printf(" indexed!\n");
indexed = (pdf_indexed*)cs;
cs = indexed->base;
}
@@ -394,7 +372,6 @@ printf(" indexed!\n");
ismask = fz_tobool(fz_dictgets(dict, "ImageMask"));
if (ismask)
{
-printf(" image mask!\n");
bpc = 1;
n = 0;
a = 1;
@@ -453,7 +430,6 @@ printf(" image mask!\n");
obj = fz_dictgets(dict, "Decode");
if (fz_isarray(obj))
{
-printf(" decode array!\n");
if (indexed)
for (i = 0; i < 2; i++)
img->decode[i] = fz_toreal(fz_arrayget(obj, i));
@@ -504,17 +480,6 @@ printf(" decode array!\n");
*p = ~*p;
}
-if (indexed)
-printf(" decode [ %g %g ]\n", img->decode[0], img->decode[1]);
-else
-{
-printf(" decode [ ");
-for (i = 0; i < (n + a) * 2; i++)
-printf("%g ", img->decode[i]);
-printf("]\n");
-printf("\n");
-}
-
/*
* Create image object
*/
diff --git a/mupdf/interpret.c b/mupdf/interpret.c
index 786e15fe..5146bb2b 100644
--- a/mupdf/interpret.c
+++ b/mupdf/interpret.c
@@ -273,8 +273,6 @@ runkeyword(pdf_csi *csi, pdf_xref *xref, fz_obj *rdb, char *buf)
goto syntaxerror;
error = fz_newmetanode(&meta, csi->stack[0], nil);
if (error) return error;
- // error = pdf_beginmarkedcontent(gstate, meta);
- // if (error) { fz_dropnode(meta); return error; };
fz_insertnode(gstate->head, meta);
}
@@ -285,15 +283,11 @@ runkeyword(pdf_csi *csi, pdf_xref *xref, fz_obj *rdb, char *buf)
goto syntaxerror;
error = fz_newmetanode(&meta, csi->stack[0], csi->stack[1]);
if (error) return error;
- // error = pdf_beginmarkedcontent(gstate, meta);
- // if (error) { fz_dropnode(meta); return error; };
fz_insertnode(gstate->head, meta);
}
else if (!strcmp(buf, "EMC"))
{
- // error = pdf_endmarkedcontent(gstate);
- // if (error) return error;
}
else if (!strcmp(buf, "cm"))
@@ -743,13 +737,10 @@ fz_debugobj(rdb);
else if (!strcmp(buf, "d1"))
{
-printf("%g %g d0\n", fz_toreal(csi->stack[0]), fz_toreal(csi->stack[1]));
}
else
-fprintf(stderr, "syntaxerror: unknown keyword '%s'\n", buf);
- //return fz_throw("syntaxerror: unknown keyword '%s'", buf);
- //if (!csi->xbalance) goto syntaxerror;
+ if (!csi->xbalance) goto syntaxerror;
}
else switch (buf[0])
@@ -999,9 +990,7 @@ fprintf(stderr, "syntaxerror: unknown keyword '%s'\n", buf);
break;
default:
-fprintf(stderr, "syntaxerror: unknown keyword '%s'\n", buf);
- //return fz_throw("syntaxerror: unknown keyword '%s'", buf);
- //if (!csi->xbalance) goto syntaxerror;
+ if (!csi->xbalance) goto syntaxerror;
}
return nil;
@@ -1014,7 +1003,7 @@ fz_error *
pdf_runcsi(pdf_csi *csi, pdf_xref *xref, fz_obj *rdb, fz_file *file)
{
fz_error *error;
- unsigned char buf[65536];
+ char buf[65536];
int token, len;
while (1)
diff --git a/mupdf/lex.c b/mupdf/lex.c
index 7e82ba6c..f7d6292b 100644
--- a/mupdf/lex.c
+++ b/mupdf/lex.c
@@ -229,7 +229,7 @@ lexhexstring(fz_file *f, unsigned char *buf, int n)
}
static int
-tokenfromkeyword(unsigned char *key)
+tokenfromkeyword(char *key)
{
if (!strcmp(key, "R")) return PDF_TR;
if (!strcmp(key, "true")) return PDF_TTRUE;
diff --git a/mupdf/nametree.c b/mupdf/nametree.c
index 081d4387..b338cbbb 100644
--- a/mupdf/nametree.c
+++ b/mupdf/nametree.c
@@ -48,7 +48,7 @@ loadnametree(pdf_nametree *nt, pdf_xref *xref, fz_obj *root)
fz_obj *names = nil;
fz_obj *kids = nil;
fz_obj *key = nil;
-// please dont use _ in variable names:
+/*XXX please dont use _ in variable names: */
fz_obj *ref_val = nil;
fz_obj *ref = nil;
int i, len;
@@ -72,7 +72,7 @@ loadnametree(pdf_nametree *nt, pdf_xref *xref, fz_obj *root)
len = fz_arraylen(names);
if (len % 2)
-// with null error object?
+/*XXX with null error object? */
goto cleanup;
len /= 2;
@@ -90,12 +90,12 @@ loadnametree(pdf_nametree *nt, pdf_xref *xref, fz_obj *root)
}
nametreepush(nt, key, ref_val);
-// check error!
+/*XXX check error! */
fz_dropobj(key);
key = nil;
}
-// you leak names
+/*XXX you leak names */
}
/* Intermediate node */
@@ -116,7 +116,7 @@ loadnametree(pdf_nametree *nt, pdf_xref *xref, fz_obj *root)
for (i = 0; i < len; ++i) {
ref = fz_arrayget(kids, i);
loadnametree(nt, xref, ref);
-// check error!
+/*XXX check error! */
}
}
else {
@@ -124,13 +124,13 @@ loadnametree(pdf_nametree *nt, pdf_xref *xref, fz_obj *root)
error = fz_throw("invalid nametree node: there's no Names and Kids key");
goto cleanup;
}
-// you leak kids
+/*XXX you leak kids */
}
return nil;
cleanup:
-// i dont like BIG_FAT_MACROS, use: if (obj) fz_dropobj(obj)
+/*XXX i dont like BIG_FAT_MACROS, use: if (obj) fz_dropobj(obj) */
SAFE_FREE_OBJ(localroot);
SAFE_FREE_OBJ(names);
SAFE_FREE_OBJ(kids);
@@ -178,14 +178,14 @@ pdf_loadnametree(pdf_nametree **pnt, pdf_xref *xref, char* key)
error = pdf_loadindirect(&catalog, xref, ref);
if (error) goto cleanup;
-// create empty nametree instead of failing
+/*XXX create empty nametree instead of failing */
names = fz_dictgets(catalog, "Names");
-// never resolve something that can be null
+/*XXX never resolve something that can be null */
error = pdf_resolve(&names, xref);
if (error) goto cleanup;
root = fz_dictgets(names, key);
-// never resolve something that can be null
+/*XXX never resolve something that can be null */
error = pdf_resolve(&root, xref);
if (error) goto cleanup;
@@ -205,14 +205,14 @@ pdf_loadnametree(pdf_nametree **pnt, pdf_xref *xref, char* key)
error = loadnametree(nt, xref, root);
if (error) goto cleanup;
-// not necessary. tree is sorted when you load it.
+/*XXX not necessary. tree is sorted when you load it. */
sortnametree(nt);
-// please have separate cleanup and okay cases...
-// return nil; here
+/*XXX please have separate cleanup and okay cases... */
+/*XXX return nil; here */
cleanup:
-// no BIG_FAT_MACROS, please :)
+/*XXX no BIG_FAT_MACROS, please :) */
SAFE_FREE_OBJ(root);
SAFE_FREE_OBJ(names);
if (catalog) fz_dropobj(catalog);
@@ -255,7 +255,7 @@ pdf_lookupname(pdf_nametree *nt, fz_obj *name)
if (fz_isstring(name)) {
item.k = name;
item.v = nil;
-// bsearch is non-standard. please dont use it.
+/*XXX bsearch is non-standard. please dont use it. */
found = bsearch(&item, nt->items, nt->len, sizeof(nt->items[0]), compare);
return found->v;
}
@@ -268,10 +268,10 @@ pdf_lookupnames(pdf_nametree *nt, char *name)
fz_obj *key;
fz_obj *ref;
int len = strlen(name);
-// please dont create a new string just to do a lookup.
-// change this to be the "standard" function and call it from
-// pdf_lookupname instead. compare name with the fz_tostringbuf() & co
-// return values.
+/*XXX please dont create a new string just to do a lookup. */
+/*XXX change this to be the "standard" function and call it from */
+/*XXX pdf_lookupname instead. compare name with the fz_tostringbuf() & co */
+/*XXX return values. */
fz_newstring(&key, name, len);
ref = pdf_lookupname(nt, key);
fz_dropobj(key);
diff --git a/mupdf/open.c b/mupdf/open.c
index 19320d43..2705cd98 100644
--- a/mupdf/open.c
+++ b/mupdf/open.c
@@ -33,7 +33,7 @@ loadversion(pdf_xref *xref)
static fz_error *
readstartxref(pdf_xref *xref)
{
- unsigned char buf[1024];
+ char buf[1024];
int t, n;
int i;
@@ -69,7 +69,7 @@ readstartxref(pdf_xref *xref)
*/
static fz_error *
-readoldtrailer(pdf_xref *xref, unsigned char *buf, int cap)
+readoldtrailer(pdf_xref *xref, char *buf, int cap)
{
int ofs, len;
char *s;
@@ -113,13 +113,13 @@ readoldtrailer(pdf_xref *xref, unsigned char *buf, int cap)
}
static fz_error *
-readnewtrailer(pdf_xref *xref, unsigned char *buf, int cap)
+readnewtrailer(pdf_xref *xref, char *buf, int cap)
{
return pdf_parseindobj(&xref->trailer, xref->file, buf, cap, nil, nil, nil);
}
static fz_error *
-readtrailer(pdf_xref *xref, unsigned char *buf, int cap)
+readtrailer(pdf_xref *xref, char *buf, int cap)
{
int n;
int c;
@@ -142,7 +142,7 @@ readtrailer(pdf_xref *xref, unsigned char *buf, int cap)
*/
static fz_error *
-readoldxref(fz_obj **trailerp, pdf_xref *xref, unsigned char *buf, int cap)
+readoldxref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap)
{
int ofs, len;
char *s;
@@ -194,7 +194,7 @@ readoldxref(fz_obj **trailerp, pdf_xref *xref, unsigned char *buf, int cap)
}
static fz_error *
-readnewxref(fz_obj **trailerp, pdf_xref *xref, unsigned char *buf, int cap)
+readnewxref(fz_obj **trailerp, pdf_xref *xref, char *buf, int cap)
{
fz_error *error;
fz_obj *trailer;
@@ -295,7 +295,7 @@ cleanup:
}
static fz_error *
-readxref(fz_obj **trailerp, pdf_xref *xref, int ofs, unsigned char *buf, int cap)
+readxref(fz_obj **trailerp, pdf_xref *xref, int ofs, char *buf, int cap)
{
int n;
int c;
@@ -314,7 +314,7 @@ readxref(fz_obj **trailerp, pdf_xref *xref, int ofs, unsigned char *buf, int cap
}
static fz_error *
-readxrefsections(pdf_xref *xref, int ofs, unsigned char *buf, int cap)
+readxrefsections(pdf_xref *xref, int ofs, char *buf, int cap)
{
fz_error *error;
fz_obj *trailer;
@@ -355,7 +355,7 @@ cleanup:
*/
fz_error *
-pdf_loadobjstm(pdf_xref *xref, int oid, int gen, unsigned char *buf, int cap)
+pdf_loadobjstm(pdf_xref *xref, int oid, int gen, char *buf, int cap)
{
fz_error *error;
fz_obj *objstm;
@@ -458,7 +458,7 @@ pdf_openpdf(pdf_xref **xrefp, char *filename)
fz_obj *size;
int i;
- unsigned char buf[65536]; /* yeowch! */
+ char buf[65536]; /* yeowch! */
xref = fz_malloc(sizeof(pdf_xref));
if (!xref)
diff --git a/mupdf/outline.c b/mupdf/outline.c
index afccbf4a..fa8fffed 100644
--- a/mupdf/outline.c
+++ b/mupdf/outline.c
@@ -4,7 +4,7 @@
static fz_error *
loadoutlinetree(pdf_xref *xref, pdf_outline *outline, fz_obj *obj)
{
-// please call this 'error'
+/*XXX please call this 'error' */
fz_error *err;
fz_obj *first;
fz_obj *next;
@@ -14,9 +14,9 @@ loadoutlinetree(pdf_xref *xref, pdf_outline *outline, fz_obj *obj)
int i;
t = fz_dictgets(obj, "Title");
-// check for failure after each malloc
+/*XXX check for failure after each malloc */
outline->title = fz_malloc(sizeof(char) * fz_tostringlen(t) + 1);
-// use strlcpy instead. strncpy does not null terminate.
+/*XXX use strlcpy instead. strncpy does not null terminate. */
strncpy(outline->title, fz_tostringbuf(t), fz_tostringlen(t));
outline->title[fz_tostringlen(t)] = 0;
@@ -49,11 +49,11 @@ loadoutlinetree(pdf_xref *xref, pdf_outline *outline, fz_obj *obj)
if (err) return err;
o = fz_malloc(sizeof(pdf_outline));
-// you leak ref
+/*XXX you leak ref */
if (!o) { err = fz_outofmem; return err; }
loadoutlinetree(xref, o, ref);
-// check error return
+/*XXX check error return */
outline->first = o;
@@ -68,11 +68,11 @@ loadoutlinetree(pdf_xref *xref, pdf_outline *outline, fz_obj *obj)
if (err) return err;
o = fz_malloc(sizeof(pdf_outline));
-// you leak ref
+/*XXX you leak ref */
if (!o) { err = fz_outofmem; return err; }
loadoutlinetree(xref, o, ref);
-// check error return?
+/*XXX check error return? */
outline->next = o;
@@ -87,7 +87,7 @@ loadoutlinetree(pdf_xref *xref, pdf_outline *outline, fz_obj *obj)
fz_error *
pdf_loadoutlinetree(pdf_outlinetree **oo, pdf_xref *xref)
{
-// please rename to 'error'
+/*XXX please rename to 'error' */
fz_error *err;
pdf_outlinetree *o = nil;
fz_obj *outline = nil;
@@ -103,7 +103,7 @@ pdf_loadoutlinetree(pdf_outlinetree **oo, pdf_xref *xref)
err = pdf_loadindirect(&catalog, xref, ref);
if (err) goto error;
-// create empty tree if no outlines exist instead of failing?
+/*XXX create empty tree if no outlines exist instead of failing? */
ref = fz_dictgets(catalog, "Outlines");
if (!ref) goto error;
err = pdf_loadindirect(&outlines, xref, ref);
@@ -121,7 +121,7 @@ pdf_loadoutlinetree(pdf_outlinetree **oo, pdf_xref *xref)
ref = fz_dictgets(outlines, "First");
err = pdf_loadindirect(&outline, xref, ref);
-// check error
+/*XXX check error */
err = loadoutlinetree(xref, o->first, outline);
if (err) goto error;
diff --git a/mupdf/pagetree.c b/mupdf/pagetree.c
index 3a75b373..fbfca585 100644
--- a/mupdf/pagetree.c
+++ b/mupdf/pagetree.c
@@ -89,8 +89,6 @@ pdf_debugpagetree(pdf_pagetree *pages)
printf(" ");
fz_debugobj(pages->pref[i]);
printf("\t%% page %d\n", i + 1);
- //fz_debugobj(stdout, pages->pobj[i]);
- //printf("\n");
}
printf(" ]\n>>\n");
}
diff --git a/mupdf/parse.c b/mupdf/parse.c
index 3bf1e00f..2eb3d234 100644
--- a/mupdf/parse.c
+++ b/mupdf/parse.c
@@ -2,7 +2,7 @@
#include <mupdf.h>
fz_error *
-pdf_parsearray(fz_obj **op, fz_file *file, unsigned char *buf, int cap)
+pdf_parsearray(fz_obj **op, fz_file *file, char *buf, int cap)
{
fz_error *error = nil;
fz_obj *ary = nil;
@@ -101,7 +101,7 @@ cleanup:
}
fz_error *
-pdf_parsedict(fz_obj **op, fz_file *file, unsigned char *buf, int cap)
+pdf_parsedict(fz_obj **op, fz_file *file, char *buf, int cap)
{
fz_error *error = nil;
fz_obj *dict = nil;
@@ -192,7 +192,7 @@ cleanup:
}
fz_error *
-pdf_parsestmobj(fz_obj **op, fz_file *file, unsigned char *buf, int cap)
+pdf_parsestmobj(fz_obj **op, fz_file *file, char *buf, int cap)
{
int tok, len;
@@ -215,7 +215,7 @@ pdf_parsestmobj(fz_obj **op, fz_file *file, unsigned char *buf, int cap)
}
fz_error *
-pdf_parseindobj(fz_obj **op, fz_file *file, unsigned char *buf, int cap,
+pdf_parseindobj(fz_obj **op, fz_file *file, char *buf, int cap,
int *ooid, int *ogid, int *ostmofs)
{
fz_error *error = nil;
diff --git a/mupdf/repair.c b/mupdf/repair.c
index b50e08f2..cf9917ea 100644
--- a/mupdf/repair.c
+++ b/mupdf/repair.c
@@ -11,7 +11,7 @@ struct entry
};
static fz_error *
-parseobj(fz_file *file, unsigned char *buf, int cap, int *stmofs, int *stmlen,
+parseobj(fz_file *file, char *buf, int cap, int *stmofs, int *stmlen,
int *isroot, int *isinfo)
{
fz_error *error;
@@ -112,7 +112,7 @@ pdf_repairpdf(pdf_xref **xrefp, char *filename)
int listcap;
int maxoid = 0;
- unsigned char buf[65536];
+ char buf[65536];
int oid = 0;
int gen = 0;
diff --git a/mupdf/resources.c b/mupdf/resources.c
index b1be53ba..08434c0b 100644
--- a/mupdf/resources.c
+++ b/mupdf/resources.c
@@ -96,8 +96,10 @@ preloadpattern(pdf_xref *xref, fz_obj *ref)
if (pdf_findresource(xref->rpattern, ref))
return nil;
-// if (pdf_findresource(xref->rshading, ref))
-// return nil;
+/*
+ if (pdf_findresource(xref->rshading, ref))
+ return nil;
+*/
rsrc = fz_malloc(sizeof(pdf_rsrc));
if (!rsrc)
@@ -126,7 +128,7 @@ preloadpattern(pdf_xref *xref, fz_obj *ref)
else if (fz_toint(type) == 2)
{
- // load shading
+ /* load shading */
fz_dropobj(obj);
fz_free(rsrc);
return fz_throw("jeong was not here...");
diff --git a/mupdf/type3.c b/mupdf/type3.c
index 4e1a9287..eb403db4 100644
--- a/mupdf/type3.c
+++ b/mupdf/type3.c
@@ -47,7 +47,7 @@ t3render(fz_glyph *glyph, fz_font *fzfont, int cid, fz_matrix trm)
fz_tree *tree;
fz_pixmap *pixmap;
fz_matrix ctm;
- fz_rect bbox;
+ fz_irect bbox;
int i;
if (cid < 0 || cid > 255)
@@ -62,12 +62,7 @@ t3render(fz_glyph *glyph, fz_font *fzfont, int cid, fz_matrix trm)
}
ctm = fz_concat(font->matrix, trm);
- bbox = fz_boundtree(tree, ctm);
-
- bbox.min.x = fz_floor(bbox.min.x - 0.5);
- bbox.min.y = fz_floor(bbox.min.y - 0.5);
- bbox.max.x = fz_ceil(bbox.max.x + 0.5);
- bbox.max.y = fz_ceil(bbox.max.y + 0.5);
+ bbox = fz_roundrect(fz_boundtree(tree, ctm));
error = fz_newrenderer(&gc, nil, GCMEM);
if (error)
@@ -95,7 +90,7 @@ t3render(fz_glyph *glyph, fz_font *fzfont, int cid, fz_matrix trm)
pixmap->w );
}
- // XXX flip bitmap in ftrender instead; free pixmap
+ /* XXX flip bitmap in ftrender instead; free pixmap */
return nil;
}
@@ -106,9 +101,6 @@ loadcharproc(fz_tree **treep, pdf_xref *xref, fz_obj *rdb, fz_obj *stmref)
fz_error *error;
pdf_csi *csi;
- printf(" loading charproc %d %d obj\n",
- fz_tonum(stmref), fz_togen(stmref));
-
error = pdf_newcsi(&csi, 1);
error = pdf_openstream(xref, fz_tonum(stmref), fz_togen(stmref));
@@ -119,9 +111,6 @@ loadcharproc(fz_tree **treep, pdf_xref *xref, fz_obj *rdb, fz_obj *stmref)
pdf_closestream(xref);
- if (csi->tree)
- fz_debugtree(csi->tree);
-
*treep = csi->tree;
csi->tree = nil;
diff --git a/mupdf/xobject.c b/mupdf/xobject.c
index 1340bc5c..cc05502f 100644
--- a/mupdf/xobject.c
+++ b/mupdf/xobject.c
@@ -12,8 +12,6 @@ pdf_loadxobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict, fz_obj *ref)
if (!form)
return fz_outofmem;
-printf("loading xobject ");fz_debugobj(dict);printf("\n");
-
obj = fz_dictgets(dict, "BBox");
form->bbox.min.x = fz_toreal(fz_arrayget(obj, 0));
form->bbox.min.y = fz_toreal(fz_arrayget(obj, 1));
@@ -62,4 +60,3 @@ printf("loading xobject ");fz_debugobj(dict);printf("\n");
return nil;
}
-
diff --git a/mupdf/xref.c b/mupdf/xref.c
index c4e9a813..fa75b955 100644
--- a/mupdf/xref.c
+++ b/mupdf/xref.c
@@ -293,7 +293,7 @@ pdf_updatestream(pdf_xref *xref, int oid, int gen, fz_buffer *stm)
fz_error *
pdf_cacheobject(pdf_xref *xref, int oid, int gen)
{
- unsigned char buf[65536]; /* yeowch! */
+ char buf[65536]; /* yeowch! */
fz_error *error;
pdf_xrefentry *x;
@@ -317,8 +317,7 @@ pdf_cacheobject(pdf_xref *xref, int oid, int gen)
if (n < 0)
return fz_ferror(xref->file);
- error = pdf_parseindobj(&x->obj, xref->file, buf, sizeof buf,
- &roid, &rgen, &x->stmofs);
+ error = pdf_parseindobj(&x->obj, xref->file, buf, sizeof buf, &roid, &rgen, &x->stmofs);
if (error)
return error;
diff --git a/object/print.c b/object/print.c
index 520e53b9..8c756f30 100644
--- a/object/print.c
+++ b/object/print.c
@@ -73,7 +73,7 @@ static void fmtstr(struct fmt *fmt, fz_obj *obj)
fmtputc(fmt, '(');
for (i = 0; i < obj->u.s.len; i++)
{
- c = obj->u.s.buf[i];
+ c = (unsigned char) obj->u.s.buf[i];
if (c == '\n')
fmtputs(fmt, "\\n");
else if (c == '\r')
@@ -93,9 +93,6 @@ static void fmtstr(struct fmt *fmt, fz_obj *obj)
fmtputc(fmt, '\\');
sprintf(buf, "%o", c);
fmtputs(fmt, buf);
- //fmtputc(fmt, ((c >> 6) & 7) + '0');
- //fmtputc(fmt, ((c >> 3) & 7) + '0');
- //fmtputc(fmt, ((c) & 7) + '0');
}
else
fmtputc(fmt, c);
@@ -106,13 +103,15 @@ static void fmtstr(struct fmt *fmt, fz_obj *obj)
static void fmthex(struct fmt *fmt, fz_obj *obj)
{
int i;
+ int b;
int c;
fmtputc(fmt, '<');
for (i = 0; i < obj->u.s.len; i++) {
- c = (obj->u.s.buf[i] >> 4) & 0x0f;
+ b = (unsigned char) obj->u.s.buf[i];
+ c = (b >> 4) & 0x0f;
fmtputc(fmt, c < 0xA ? c + '0' : c + 'A' - 0xA);
- c = (obj->u.s.buf[i]) & 0x0f;
+ c = (b) & 0x0f;
fmtputc(fmt, c < 0xA ? c + '0' : c + 'A' - 0xA);
}
fmtputc(fmt, '>');
diff --git a/object/simple.c b/object/simple.c
index 629fdf85..aa736b8e 100644
--- a/object/simple.c
+++ b/object/simple.c
@@ -189,7 +189,7 @@ fz_toname(fz_obj *obj)
{
if (fz_isname(obj))
return obj->u.n;
- return "";
+ return nil;
}
char *
@@ -197,7 +197,7 @@ fz_tostringbuf(fz_obj *obj)
{
if (fz_isstring(obj))
return obj->u.s.buf;
- return "";
+ return nil;
}
int
diff --git a/render/edgelist.c b/render/edgelist.c
index 9bcc92b1..7b39ae70 100644
--- a/render/edgelist.c
+++ b/render/edgelist.c
@@ -52,10 +52,22 @@ fz_dropgel(fz_gel *gel)
fz_free(gel);
}
+fz_irect
+fz_boundgel(fz_gel *gel)
+{
+ fz_irect bbox;
+ bbox.min.x = fz_idiv(gel->xmin, gel->hs);
+ bbox.min.y = fz_idiv(gel->ymin, gel->vs);
+ bbox.max.x = fz_idiv(gel->xmax, gel->hs) + 1;
+ bbox.max.y = fz_idiv(gel->ymax, gel->vs) + 1;
+ return bbox;
+}
+
fz_error *
fz_insertgel(fz_gel *gel, float fx0, float fy0, float fx1, float fy1)
{
fz_edge *edge;
+ int x0, y0, x1, y1;
int dx, dy;
int winding;
int width;
@@ -67,10 +79,10 @@ fz_insertgel(fz_gel *gel, float fx0, float fy0, float fx1, float fy1)
fy1 *= gel->vs;
/* TODO: should we round or truncate? */
- int x0 = fx0 < 0 ? fx0 - 0.5 : fx0 + 0.5;
- int y0 = fy0 < 0 ? fy0 - 0.5 : fy0 + 0.5;
- int x1 = fx1 < 0 ? fx1 - 0.5 : fx1 + 0.5;
- int y1 = fy1 < 0 ? fy1 - 0.5 : fy1 + 0.5;
+ x0 = fx0 < 0 ? fx0 - 0.5 : fx0 + 0.5;
+ y0 = fy0 < 0 ? fy0 - 0.5 : fy0 + 0.5;
+ x1 = fx1 < 0 ? fx1 - 0.5 : fx1 + 0.5;
+ y1 = fy1 < 0 ? fy1 - 0.5 : fy1 + 0.5;
if (y0 == y1)
return nil;
diff --git a/render/glyphcache.c b/render/glyphcache.c
index 41ef0f08..1d3b8117 100644
--- a/render/glyphcache.c
+++ b/render/glyphcache.c
@@ -43,7 +43,7 @@ struct fz_val_s
static unsigned int hashkey(fz_key *key)
{
- unsigned char *s = (char*)key;
+ unsigned char *s = (unsigned char*)key;
unsigned int hash = 0;
unsigned int i;
for (i = 0; i < sizeof(fz_key); i++)
diff --git a/render/pixmap.c b/render/pixmap.c
index 9bbe297b..396b8784 100644
--- a/render/pixmap.c
+++ b/render/pixmap.c
@@ -146,16 +146,14 @@ fz_blendmask(fz_pixmap *dst, fz_pixmap *src, fz_pixmap *msk)
void
fz_gammapixmap(fz_pixmap *pix, float gamma)
{
- int i;
unsigned char table[255];
- for (i = 0; i < 256; i++)
- table[i] = CLAMP(pow(i / 255.0, gamma) * 255.0, 0, 255);
int n = pix->w * pix->h * pix->n;
unsigned char *p = pix->samples;
+ int i;
+ for (i = 0; i < 256; i++)
+ table[i] = CLAMP(pow(i / 255.0, gamma) * 255.0, 0, 255);
while (n--)
- {
*p = table[*p]; p++;
- }
}
void
@@ -180,9 +178,6 @@ fz_debugpixmap(fz_pixmap *pix)
putc(r, ppm);
putc(g, ppm);
putc(b, ppm);
- // putc(((r * a) / 255) + (255 - a), ppm);
- // putc(((g * a) / 255) + (255 - a), ppm);
- // putc(((b * a) / 255) + (255 - a), ppm);
}
fclose(ppm);
fclose(pgm);
diff --git a/render/render.c b/render/render.c
index 1798e011..9c28e689 100644
--- a/render/render.c
+++ b/render/render.c
@@ -72,8 +72,9 @@ fz_error *
fz_rendercolor(fz_renderer *gc, fz_colornode *color, fz_matrix ctm)
{
fz_error *error;
- int x, y;
+ int x, y, w, h;
float rgb[3];
+ unsigned char *p;
printf("render color\n");
@@ -84,11 +85,16 @@ printf("render color\n");
gc->g = rgb[1] * 255;
gc->b = rgb[2] * 255;
- error = fz_newpixmap(&gc->tmp, gc->x, gc->y, gc->w, gc->h, 4);
+ x = gc->clip.min.x;
+ y = gc->clip.min.y;
+ w = gc->clip.max.x - gc->clip.min.x;
+ h = gc->clip.max.y - gc->clip.min.y;
+
+ error = fz_newpixmap(&gc->tmp, x, y, w, h, 4);
if (error)
return error;
- unsigned char *p = gc->tmp->samples;
+ p = gc->tmp->samples;
for (y = 0; y < gc->tmp->h; y++)
{
@@ -123,10 +129,7 @@ fz_renderoverchild(fz_renderer *gc, fz_node *node, fz_matrix ctm)
if (gc->tmp)
{
-//printf("over src ");fz_debugpixmap(gc->tmp);getchar();
-//printf("over dst ");fz_debugpixmap(gc->acc);getchar();
fz_blendover(gc->tmp, gc->acc);
-//printf("over res ");fz_debugpixmap(gc->acc);getchar();
fz_droppixmap(gc->tmp);
gc->tmp = nil;
}
@@ -141,14 +144,17 @@ fz_renderover(fz_renderer *gc, fz_overnode *over, fz_matrix ctm)
fz_pixmap *oldacc = nil;
int oldmode;
-//printf("begin over\n");
+ int x = gc->clip.min.x;
+ int y = gc->clip.min.y;
+ int w = gc->clip.max.x - gc->clip.min.x;
+ int h = gc->clip.max.y - gc->clip.min.y;
/* uh-oh! we have a new over cluster */
if (gc->mode != FZ_ROVER)
{
printf("begin over accumulator\n");
oldacc = gc->acc;
- error = fz_newpixmap(&gc->acc, gc->x, gc->y, gc->w, gc->h, gc->model ? 4 : 1);
+ error = fz_newpixmap(&gc->acc, x, y, w, h, gc->model ? 4 : 1);
if (error)
return error;
fz_clearpixmap(gc->acc);
@@ -176,8 +182,6 @@ printf("end over accumulator\n");
gc->acc = oldacc;
}
-//printf("end over\n");
-
return nil;
}
@@ -191,8 +195,9 @@ fz_rendermask(fz_renderer *gc, fz_masknode *mask, fz_matrix ctm)
fz_node *color;
fz_node *shape;
int oldmode;
- fz_rect bbox;
- int ox, oy, ow, oh;
+ fz_irect newclip;
+ fz_irect oldclip;
+ int x, y, w, h;
color = mask->super.child;
shape = color->next;
@@ -211,25 +216,15 @@ printf("begin mask\n");
oldacc = gc->acc;
oldmode = gc->mode;
- gc->acc = nil;
- gc->mode = FZ_RMASK;
-
- // TODO: set clip bbox to that of shape
+ oldclip = gc->clip;
- bbox = fz_boundnode(shape, ctm);
- bbox = fz_intersectrects(bbox, (fz_rect){{gc->x,gc->y},{gc->x+gc->w,gc->y+gc->h}});
- printf("mask bbox [%g %g %g %g]\n", bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y);
- ox = gc->x;
- oy = gc->y;
- ow = gc->w;
- oh = gc->h;
+ newclip = fz_roundrect(fz_boundnode(shape, ctm));
+ newclip = fz_intersectirects(newclip, gc->clip);
+ printf("mask bbox [%d %d %d %d]\n", newclip.min.x, newclip.min.y, newclip.max.x, newclip.max.y);
- gc->x = fz_floor(bbox.min.x) - 1;
- gc->y = fz_floor(bbox.min.y) - 1;
- gc->w = fz_ceil(bbox.max.x) - fz_floor(bbox.min.x) + 1;
- gc->h = fz_ceil(bbox.max.y) - fz_floor(bbox.min.y) + 1;
- ctm.e -= bbox.min.x - fz_floor(bbox.min.x);
- ctm.f -= bbox.min.y - fz_floor(bbox.min.y);
+ gc->acc = nil;
+ gc->mode = FZ_RMASK;
+ gc->clip = newclip;
gc->tmp = nil;
error = fz_rendernode(gc, color, ctm);
@@ -245,26 +240,23 @@ printf("begin mask\n");
if (!shapepix) return nil;
- error = fz_newpixmap(&gc->tmp, gc->x, gc->y, gc->w, gc->h, colorpix->n);
+ x = gc->clip.min.x;
+ y = gc->clip.min.y;
+ w = gc->clip.max.x - gc->clip.min.x;
+ h = gc->clip.max.y - gc->clip.min.y;
+
+ error = fz_newpixmap(&gc->tmp, x, y, w, h, colorpix->n);
if (error)
return error;
fz_blendmask(gc->tmp, colorpix, shapepix);
-//printf("mask color");fz_debugpixmap(colorpix);getchar();
-//printf("mask shape");fz_debugpixmap(shapepix);getchar();
-//printf("mask blend");fz_debugpixmap(gc->tmp);getchar();
-
fz_droppixmap(shapepix);
fz_droppixmap(colorpix);
gc->acc = oldacc;
gc->mode = oldmode;
-
- gc->x = ox;
- gc->y = oy;
- gc->w = ow;
- gc->h = oh;
+ gc->clip = oldclip;
printf("end mask\n");
@@ -274,7 +266,6 @@ printf("end mask\n");
fz_error *
fz_rendertransform(fz_renderer *gc, fz_transformnode *transform, fz_matrix ctm)
{
-//printf("render transform\n");
ctm = fz_concat(transform->m, ctm);
return fz_rendernode(gc, transform->super.child, ctm);
}
@@ -311,18 +302,11 @@ fz_rendernode(fz_renderer *gc, fz_node *node, fz_matrix ctm)
}
fz_error *
-fz_rendertree(fz_pixmap **outp, fz_renderer *gc, fz_tree *tree, fz_matrix ctm, fz_rect bbox)
+fz_rendertree(fz_pixmap **outp, fz_renderer *gc, fz_tree *tree, fz_matrix ctm, fz_irect bbox)
{
fz_error *error;
- gc->x = fz_floor(bbox.min.x);
- gc->y = fz_floor(bbox.min.y);
- gc->w = fz_ceil(bbox.max.x) - fz_floor(bbox.min.x);
- gc->h = fz_ceil(bbox.max.y) - fz_floor(bbox.min.y);
-
- /* compensate for rounding */
- ctm.e -= bbox.min.x - gc->x;
- ctm.f -= bbox.min.y - gc->y;
+ gc->clip = bbox;
printf("render tree\n");
diff --git a/render/renderimage.c b/render/renderimage.c
index 3741ab73..0d86bee8 100644
--- a/render/renderimage.c
+++ b/render/renderimage.c
@@ -149,15 +149,18 @@ fz_renderimage(fz_renderer *gc, fz_imagenode *node, fz_matrix ctm)
int h = image->h;
int n = image->n;
int a = image->a;
+ int dx, dy;
+ fz_rect bbox;
+ fz_irect r;
float sx = sqrt(ctm.a * ctm.a + ctm.b * ctm.b);
float sy = sqrt(ctm.c * ctm.c + ctm.d * ctm.d);
- int dx = 1;
+ dx = 1;
while ( ( (w + dx - 1) / dx ) / sx > 2.0 && (w+dx-1)/dx > 1)
dx++;
- int dy = 1;
+ dy = 1;
while ( ( (h + dy - 1) / dy ) / sy > 2.0 && (h+dy-1)/dy > 1)
dy++;
@@ -167,24 +170,30 @@ printf("renderimage s=%gx%g/%dx%d d=%d,%d\n", sx, sy, w, h, dx, dy);
printf(" load tile %d x %d\n", w, h);
error = image->loadtile(image, tile1);
-//fz_debugpixmap(tile1);getchar();
if (dx != 1 || dy != 1)
{
printf(" scale tile 1/%d x 1/%d\n", dx, dy);
-// fz_gammapixmap(tile1, 1.0 / GAMMA);
+/* fz_gammapixmap(tile1, 1.0 / GAMMA); */
error = fz_scalepixmap(&tile2, tile1, dx, dy);
-// fz_gammapixmap(tile2, GAMMA);
+/* fz_gammapixmap(tile2, GAMMA); */
fz_droppixmap(tile1);
}
else
tile2 = tile1;
+ bbox.min.x = 0;
+ bbox.min.y = 0;
+ bbox.max.x = 1;
+ bbox.max.y = 1;
+ bbox = fz_transformaabb(ctm, bbox);
+ r = fz_intersectirects(fz_roundrect(bbox), gc->clip);
+
/* render image mask */
if (n == 0 && a == 1)
{
printf(" draw image mask\n");
- error = fz_newpixmap(&gc->tmp, gc->x, gc->y, gc->w, gc->h, 1);
+ error = fz_newpixmap(&gc->tmp, r.min.x, r.min.y, r.max.x - r.min.x, r.max.y - r.min.y, 1);
fz_clearpixmap(gc->tmp);
error = drawtile(gc, gc->tmp, tile2, ctm, 0);
}
@@ -215,17 +224,8 @@ printf(" draw image rgb over after cs transform\n");
printf(" draw image after cs transform\n");
error = fz_newpixmap(&tile3, tile2->x, tile2->y, tile2->w, tile2->h, gc->model->n + 1);
fz_convertpixmap(cs, tile2, gc->model, tile3);
- fz_rect bbox = fz_boundnode((fz_node*)node, ctm);
- fz_irect aabb;
- aabb.min.x = fz_floor(bbox.min.x) - 1;
- aabb.min.y = fz_floor(bbox.min.y) - 1;
- aabb.max.x = fz_ceil(bbox.max.x) + 1;
- aabb.max.y = fz_ceil(bbox.max.y) + 1;
- aabb = fz_intersectirects(aabb, (fz_irect){{gc->x,gc->y},{gc->x+gc->w,gc->y+gc->h}});
- error = fz_newpixmap(&gc->tmp,
- aabb.min.x, aabb.min.y,
- aabb.max.x - aabb.min.x, aabb.max.y - aabb.min.y,
- gc->model->n + 1);
+ error = fz_newpixmap(&gc->tmp, r.min.x, r.min.y,
+ r.max.x - r.min.x, r.max.y - r.min.y, gc->model->n + 1);
fz_clearpixmap(gc->tmp);
error = drawtile(gc, gc->tmp, tile3, ctm, 0);
fz_droppixmap(tile3);
diff --git a/render/renderpath.c b/render/renderpath.c
index 498c3a63..05c39c8b 100644
--- a/render/renderpath.c
+++ b/render/renderpath.c
@@ -1,6 +1,5 @@
#include <fitz.h>
-// enum { HS = 1, VS = 1, SF = 255 };
enum { HS = 17, VS = 15, SF = 1 };
static fz_error *pathtogel(fz_gel *gel, fz_pathnode *path, fz_matrix ctm)
@@ -101,7 +100,7 @@ fz_rendercolorpath(fz_renderer *gc, fz_pathnode *path, fz_colornode *color, fz_m
fz_scanconvert(gc->gel, gc->ael,
path->paint == FZ_EOFILL,
- gc->y, gc->y + gc->h,
+ gc->clip.min.y, gc->clip.max.y,
blitcolorspan, gc);
return nil;
@@ -111,6 +110,7 @@ fz_error *
fz_renderpath(fz_renderer *gc, fz_pathnode *path, fz_matrix ctm)
{
fz_error *error;
+ fz_irect bbox;
fz_resetgel(gc->gel, HS, VS);
@@ -120,7 +120,13 @@ fz_renderpath(fz_renderer *gc, fz_pathnode *path, fz_matrix ctm)
fz_sortgel(gc->gel);
- error = fz_newpixmap(&gc->tmp, gc->x, gc->y, gc->w, gc->h, 1);
+ bbox = fz_boundgel(gc->gel);
+ bbox = fz_intersectirects(bbox, gc->clip);
+
+ error = fz_newpixmap(&gc->tmp,
+ bbox.min.x, bbox.min.y,
+ bbox.max.x - bbox.min.x,
+ bbox.max.y - bbox.min.y, 1);
if (error)
return error;
@@ -128,7 +134,7 @@ fz_renderpath(fz_renderer *gc, fz_pathnode *path, fz_matrix ctm)
fz_scanconvert(gc->gel, gc->ael,
path->paint == FZ_EOFILL,
- gc->y, gc->y + gc->h,
+ gc->clip.min.y, gc->clip.max.y,
blitalphaspan, gc->tmp);
return nil;
diff --git a/render/rendertext.c b/render/rendertext.c
index 6819ccd8..98985f4d 100644
--- a/render/rendertext.c
+++ b/render/rendertext.c
@@ -61,8 +61,14 @@ fz_rendertext(fz_renderer *gc, fz_textnode *text, fz_matrix ctm)
float x, y;
int g, i, ix, iy;
fz_matrix tm, trm;
+ fz_irect bbox;
- error = fz_newpixmap(&gc->tmp, gc->x, gc->y, gc->w, gc->h, 1);
+ bbox = fz_roundrect(fz_boundnode((fz_node*)text, ctm));
+ bbox = fz_intersectirects(gc->clip, bbox);
+
+ error = fz_newpixmap(&gc->tmp,
+ bbox.min.x, bbox.min.y,
+ bbox.max.x - bbox.min.x, bbox.max.y - bbox.min.y, 1);
if (error)
return error;
diff --git a/render/scale.c b/render/scale.c
index 00203cfc..47345387 100644
--- a/render/scale.c
+++ b/render/scale.c
@@ -96,9 +96,6 @@ fz_scalepixmap(fz_pixmap **dstp, fz_pixmap *src, int xdenom, int ydenom)
scalecols(buf, dst->samples + oy * dst->w * n, dst->w, n, ydenom);
}
-//printf("unscaled image ");fz_debugpixmap(src);getchar();
-//printf("scaled image ");fz_debugpixmap(dst);getchar();
-
fz_free(buf);
*dstp = dst;
return nil;
diff --git a/render/scanconv.c b/render/scanconv.c
index db859d1f..662a4cdb 100644
--- a/render/scanconv.c
+++ b/render/scanconv.c
@@ -86,8 +86,6 @@ fz_scanconvert(fz_gel *gel, fz_ael *ael, int eofill, int y0, int y1,
int xmin = fz_idiv(gel->xmin, gel->hs);
int xmax = fz_idiv(gel->xmax, gel->hs) + 1;
- // int ymin = fz_idiv(gel->ymin, gel->vs);
- // int ymax = fz_idiv(gel->ymax, gel->vs) + 1;
int xofs = xmin * gel->hs;
int hs = gel->hs;
diff --git a/test/pdfclean.c b/test/pdfclean.c
index b8102d2c..32acacd9 100644
--- a/test/pdfclean.c
+++ b/test/pdfclean.c
@@ -158,7 +158,6 @@ int main(int argc, char **argv)
}
error = pdf_savepdf(xref, outfile, encrypt);
-// error = pdf_saveincrementalpdf(xref, infile);
if (error)
fz_abort(error);
diff --git a/test/pdfrip.c b/test/pdfrip.c
index a4bce202..b04ccf3e 100644
--- a/test/pdfrip.c
+++ b/test/pdfrip.c
@@ -167,7 +167,7 @@ printf("rendering!\n");
bbox.min.y = bbox.min.y * zoom;
bbox.max.x = bbox.max.x * zoom;
bbox.max.y = bbox.max.y * zoom;
- error = fz_rendertree(&pix, gc, page->tree, ctm, bbox);
+ error = fz_rendertree(&pix, gc, page->tree, ctm, fz_roundrect(bbox));
if (error) fz_abort(error);
printf("done!\n");
diff --git a/test/x11pdf.c b/test/x11pdf.c
index 83b340b1..58655f8a 100644
--- a/test/x11pdf.c
+++ b/test/x11pdf.c
@@ -164,7 +164,7 @@ static void showpage(void)
bbox = fz_transformaabb(ctm, page->mediabox);
- error = fz_rendertree(&image, rast, page->tree, ctm, bbox);
+ error = fz_rendertree(&image, rast, page->tree, ctm, fz_roundrect(bbox));
if (error)
fz_abort(error);
diff --git a/tree/cmap.c b/tree/cmap.c
index 1d1b3e6d..577ba7c0 100644
--- a/tree/cmap.c
+++ b/tree/cmap.c
@@ -389,7 +389,7 @@ fz_lookupcid(fz_cmap *cmap, int cpt)
return -1;
}
-char *
+unsigned char *
fz_decodecpt(fz_cmap *cmap, unsigned char *buf, int *cpt)
{
int i, k;
diff --git a/tree/colorspace.c b/tree/colorspace.c
index af0239f5..2a3e8e87 100644
--- a/tree/colorspace.c
+++ b/tree/colorspace.c
@@ -39,14 +39,10 @@ fz_stdconvcolor(fz_colorspace *srcs, float *srcv, fz_colorspace *dsts, float *ds
int i;
if (srcs != dsts)
{
-//printf("convert color from %s to %s\n ", srcs->name, dsts->name);
-//for(i=0;i<srcs->n;i++)printf("%g ", srcv[i]);printf("\n");
srcs->toxyz(srcs, srcv, xyz);
-//printf(" %g %g %g\n ", xyz[0], xyz[1], xyz[2]);
dsts->fromxyz(dsts, xyz, dstv);
for (i = 0; i < dsts->n; i++)
dstv[i] = CLAMP(dstv[i], 0.0, 1.0);
-//for(i=0;i<dsts->n;i++)printf("%g ", dstv[i]);printf("\n");
}
else
{
diff --git a/tree/debug.c b/tree/debug.c
index e55d56e7..58cb35a1 100644
--- a/tree/debug.c
+++ b/tree/debug.c
@@ -165,7 +165,6 @@ static void lispnode(fz_node *node, int level)
case FZ_NPATH: lisppath((fz_pathnode*)node, level); break;
case FZ_NTEXT: lisptext((fz_textnode*)node, level); break;
case FZ_NIMAGE: lispimage((fz_imagenode*)node, level); break;
- case FZ_NSHADE: break;//lispshade((fz_shadenode*)node, level); break;
case FZ_NLINK: lisplink((fz_linknode*)node, level); break;
}
}
diff --git a/tree/node1.c b/tree/node1.c
index 2d98d63d..eb29391f 100644
--- a/tree/node1.c
+++ b/tree/node1.c
@@ -52,9 +52,6 @@ fz_dropnode(fz_node *node)
case FZ_NIMAGE:
fz_dropimagenode((fz_imagenode *) node);
break;
- case FZ_NSHADE:
- // XXX fz_dropshadenode((fz_shadenode *) node);
- break;
case FZ_NLINK:
fz_droplinknode((fz_linknode *) node);
break;
@@ -87,8 +84,6 @@ fz_boundnode(fz_node *node, fz_matrix ctm)
return fz_boundtextnode((fz_textnode *) node, ctm);
case FZ_NIMAGE:
return fz_boundimagenode((fz_imagenode *) node, ctm);
- case FZ_NSHADE:
- // XXX return fz_boundshadenode((fz_shadenode *) node, ctm);
case FZ_NLINK:
return fz_boundlinknode((fz_linknode *) node, ctm);
case FZ_NMETA:
diff --git a/tree/node2.c b/tree/node2.c
index 0af3ab7d..542b1590 100644
--- a/tree/node2.c
+++ b/tree/node2.c
@@ -287,25 +287,17 @@ fz_newimagenode(fz_node **nodep, fz_image *image)
void
fz_dropimagenode(fz_imagenode *node)
{
- // XXX fz_dropimage(node->image);
+ fz_dropimage(node->image);
}
fz_rect
fz_boundimagenode(fz_imagenode *node, fz_matrix ctm)
{
- fz_point ll, lr, ul, ur;
- fz_rect r;
-
- ll = fz_transformpoint(ctm, (fz_point){0,0});
- lr = fz_transformpoint(ctm, (fz_point){1,0});
- ul = fz_transformpoint(ctm, (fz_point){0,1});
- ur = fz_transformpoint(ctm, (fz_point){1,1});
-
- r.min.x = MIN4(ll.x, lr.x, ul.x, ur.x);
- r.min.y = MIN4(ll.y, lr.y, ul.y, ur.y);
- r.max.x = MAX4(ll.x, lr.x, ul.x, ur.x);
- r.max.y = MAX4(ll.y, lr.y, ul.y, ur.y);
-
- return r;
+ fz_rect bbox;
+ bbox.min.x = 0;
+ bbox.min.y = 0;
+ bbox.max.x = 1;
+ bbox.max.y = 1;
+ return fz_transformaabb(ctm, bbox);
}
diff --git a/tree/text.c b/tree/text.c
index 951fdada..a7581cf9 100644
--- a/tree/text.c
+++ b/tree/text.c
@@ -30,7 +30,6 @@ fz_rect
fz_boundtextnode(fz_textnode *text, fz_matrix ctm)
{
fz_matrix trm;
- fz_point ul, ur, ll, lr;
fz_rect bbox;
fz_rect fbox;
int i;
@@ -51,15 +50,7 @@ fz_boundtextnode(fz_textnode *text, fz_matrix ctm)
bbox.max.y = MAX(bbox.max.y, text->els[i].y);
}
- ll.x = bbox.min.x; ll.y = bbox.min.y; ll = fz_transformpoint(ctm, ll);
- ul.x = bbox.min.x; ul.y = bbox.max.y; ul = fz_transformpoint(ctm, ul);
- ur.x = bbox.max.x; ur.y = bbox.max.y; ur = fz_transformpoint(ctm, ur);
- lr.x = bbox.max.x; lr.y = bbox.min.y; lr = fz_transformpoint(ctm, lr);
-
- bbox.min.x = MIN4(ll.x, ul.x, ur.x, lr.x);
- bbox.min.y = MIN4(ll.y, ul.y, ur.y, lr.y);
- bbox.max.x = MAX4(ll.x, ul.x, ur.x, lr.x);
- bbox.max.y = MAX4(ll.y, ul.y, ur.y, lr.y);
+ bbox = fz_transformaabb(ctm, bbox);
/* find bbox of font in trm * ctm space */
@@ -72,22 +63,14 @@ fz_boundtextnode(fz_textnode *text, fz_matrix ctm)
fbox.max.x = text->font->bbox.max.x * 0.001;
fbox.max.y = text->font->bbox.max.y * 0.001;
- ll.x = fbox.min.x; ll.y = fbox.min.y; ll = fz_transformpoint(trm, ll);
- ul.x = fbox.min.x; ul.y = fbox.max.y; ul = fz_transformpoint(trm, ul);
- ur.x = fbox.max.x; ur.y = fbox.max.y; ur = fz_transformpoint(trm, ur);
- lr.x = fbox.max.x; lr.y = fbox.min.y; lr = fz_transformpoint(trm, lr);
-
- fbox.min.x = MIN4(ll.x, ul.x, ur.x, lr.x);
- fbox.min.y = MIN4(ll.y, ul.y, ur.y, lr.y);
- fbox.max.x = MAX4(ll.x, ul.x, ur.x, lr.x);
- fbox.max.y = MAX4(ll.y, ul.y, ur.y, lr.y);
+ fbox = fz_transformaabb(trm, fbox);
- bbox.min.x += MIN4(ll.x, ul.x, ur.x, lr.x);
- bbox.min.y += MIN4(ll.y, ul.y, ur.y, lr.y);
- bbox.max.x += MAX4(ll.x, ul.x, ur.x, lr.x);
- bbox.max.y += MAX4(ll.y, ul.y, ur.y, lr.y);
+ /* expand glyph origin bbox by font bbox */
-// printf("text [ %g %g %g %g ]\n", bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y);
+ bbox.min.x += fbox.min.x;
+ bbox.min.y += fbox.min.y;
+ bbox.max.x += fbox.max.x;
+ bbox.max.y += fbox.max.y;
return bbox;
}