From c6959b1074f7a80a2c0d16697a3544c627d9b978 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Thu, 8 Sep 2011 00:20:26 +0200 Subject: Use rate limited fitz warnings for openjpeg warnings/errors. --- fitz/filt_jpxd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'fitz') diff --git a/fitz/filt_jpxd.c b/fitz/filt_jpxd.c index 765aad29..101f4e10 100644 --- a/fitz/filt_jpxd.c +++ b/fitz/filt_jpxd.c @@ -5,17 +5,17 @@ static void fz_opj_error_callback(const char *msg, void *client_data) { - fprintf(stderr, "openjpeg error: %s", msg); + fz_warn("openjpeg error: %s", msg); } static void fz_opj_warning_callback(const char *msg, void *client_data) { - fprintf(stderr, "openjpeg warning: %s", msg); + fz_warn("openjpeg warning: %s", msg); } static void fz_opj_info_callback(const char *msg, void *client_data) { - /* fprintf(stderr, "openjpeg info: %s", msg); */ + /* fz_warn("openjpeg info: %s", msg); */ } fz_error -- cgit v1.2.3 From 02e2e9b427345da8be8e5fd2eccd7deba96593b4 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 18 Sep 2011 14:41:57 +0200 Subject: Move array/dict growing into separate functions. --- fitz/base_object.c | 53 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'fitz') diff --git a/fitz/base_object.c b/fitz/base_object.c index 5c20767a..9c6ccfdd 100644 --- a/fitz/base_object.c +++ b/fitz/base_object.c @@ -394,6 +394,18 @@ fz_new_array(int initialcap) return obj; } +static void +fz_array_grow(fz_obj *obj) +{ + int i; + + obj->u.a.cap = (obj->u.a.cap * 3) / 2; + obj->u.a.items = fz_realloc(obj->u.a.items, obj->u.a.cap, sizeof(fz_obj*)); + + for (i = obj->u.a.len ; i < obj->u.a.cap; i++) + obj->u.a.items[i] = NULL; +} + fz_obj * fz_copy_array(fz_obj *obj) { @@ -462,13 +474,7 @@ fz_array_push(fz_obj *obj, fz_obj *item) else { if (obj->u.a.len + 1 > obj->u.a.cap) - { - int i; - obj->u.a.cap = (obj->u.a.cap * 3) / 2; - obj->u.a.items = fz_realloc(obj->u.a.items, obj->u.a.cap, sizeof(fz_obj*)); - for (i = obj->u.a.len ; i < obj->u.a.cap; i++) - obj->u.a.items[i] = NULL; - } + fz_array_grow(obj); obj->u.a.items[obj->u.a.len] = fz_keep_obj(item); obj->u.a.len++; } @@ -484,13 +490,7 @@ fz_array_insert(fz_obj *obj, fz_obj *item) else { if (obj->u.a.len + 1 > obj->u.a.cap) - { - int i; - obj->u.a.cap = (obj->u.a.cap * 3) / 2; - obj->u.a.items = fz_realloc(obj->u.a.items, obj->u.a.cap, sizeof(fz_obj*)); - for (i = obj->u.a.len ; i < obj->u.a.cap; i++) - obj->u.a.items[i] = NULL; - } + fz_array_grow(obj); memmove(obj->u.a.items + 1, obj->u.a.items, obj->u.a.len * sizeof(fz_obj*)); obj->u.a.items[0] = fz_keep_obj(item); obj->u.a.len++; @@ -530,6 +530,21 @@ fz_new_dict(int initialcap) return obj; } +static void +fz_dict_grow(fz_obj *obj) +{ + int i; + + obj->u.d.cap = (obj->u.d.cap * 3) / 2; + obj->u.d.items = fz_realloc(obj->u.d.items, obj->u.d.cap, sizeof(struct keyval)); + + for (i = obj->u.d.len; i < obj->u.d.cap; i++) + { + obj->u.d.items[i].k = NULL; + obj->u.d.items[i].v = NULL; + } +} + fz_obj * fz_copy_dict(fz_obj *obj) { @@ -686,15 +701,7 @@ fz_dict_put(fz_obj *obj, fz_obj *key, fz_obj *val) } if (obj->u.d.len + 1 > obj->u.d.cap) - { - obj->u.d.cap = (obj->u.d.cap * 3) / 2; - obj->u.d.items = fz_realloc(obj->u.d.items, obj->u.d.cap, sizeof(struct keyval)); - for (i = obj->u.d.len; i < obj->u.d.cap; i++) - { - obj->u.d.items[i].k = NULL; - obj->u.d.items[i].v = NULL; - } - } + fz_dict_grow(obj); /* borked! */ if (obj->u.d.len) -- cgit v1.2.3 From 4fd20cb9e212cde89e2cf53c6d4d121f1d600351 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 18 Sep 2011 14:44:01 +0200 Subject: Return expected location when finding keys in dicts. --- fitz/base_object.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'fitz') diff --git a/fitz/base_object.c b/fitz/base_object.c index 9c6ccfdd..41fe70a5 100644 --- a/fitz/base_object.c +++ b/fitz/base_object.c @@ -599,7 +599,7 @@ fz_dict_get_val(fz_obj *obj, int i) } static int -fz_dict_finds(fz_obj *obj, char *key) +fz_dict_finds(fz_obj *obj, char *key, int *location) { if (obj->u.d.sorted) { @@ -615,6 +615,9 @@ fz_dict_finds(fz_obj *obj, char *key) l = m + 1; else return m; + + if (location) + *location = l; } } @@ -624,6 +627,9 @@ fz_dict_finds(fz_obj *obj, char *key) for (i = 0; i < obj->u.d.len; i++) if (strcmp(fz_to_name(obj->u.d.items[i].k), key) == 0) return i; + + if (location) + *location = obj->u.d.len; } return -1; @@ -639,7 +645,7 @@ fz_dict_gets(fz_obj *obj, char *key) if (!fz_is_dict(obj)) return NULL; - i = fz_dict_finds(obj, key); + i = fz_dict_finds(obj, key, NULL); if (i >= 0) return obj->u.d.items[i].v; @@ -692,7 +698,7 @@ fz_dict_put(fz_obj *obj, fz_obj *key, fz_obj *val) return; } - i = fz_dict_finds(obj, s); + i = fz_dict_finds(obj, s, NULL); if (i >= 0) { fz_drop_obj(obj->u.d.items[i].v); @@ -730,7 +736,7 @@ fz_dict_dels(fz_obj *obj, char *key) fz_warn("assert: not a dict (%s)", fz_objkindstr(obj)); else { - int i = fz_dict_finds(obj, key); + int i = fz_dict_finds(obj, key, NULL); if (i >= 0) { fz_drop_obj(obj->u.d.items[i].k); -- cgit v1.2.3 From f788271e01f5c0ba97bc4ad561ae546ac11017c1 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 18 Sep 2011 14:53:54 +0200 Subject: Keep dicts that have more than 100 entries sorted. --- fitz/base_object.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'fitz') diff --git a/fitz/base_object.c b/fitz/base_object.c index 41fe70a5..6881fffb 100644 --- a/fitz/base_object.c +++ b/fitz/base_object.c @@ -516,7 +516,7 @@ fz_new_dict(int initialcap) obj->refs = 1; obj->kind = FZ_DICT; - obj->u.d.sorted = 1; + obj->u.d.sorted = 0; obj->u.d.len = 0; obj->u.d.cap = initialcap > 1 ? initialcap : 10; @@ -605,6 +605,14 @@ fz_dict_finds(fz_obj *obj, char *key, int *location) { int l = 0; int r = obj->u.d.len - 1; + + if (strcmp(fz_to_name(obj->u.d.items[r].k), key) < 0) + { + if (location) + *location = r + 1; + return -1; + } + while (l <= r) { int m = (l + r) >> 1; @@ -673,6 +681,7 @@ fz_dict_getsa(fz_obj *obj, char *key, char *abbrev) void fz_dict_put(fz_obj *obj, fz_obj *key, fz_obj *val) { + int location; char *s; int i; @@ -698,25 +707,30 @@ fz_dict_put(fz_obj *obj, fz_obj *key, fz_obj *val) return; } - i = fz_dict_finds(obj, s, NULL); - if (i >= 0) + if (obj->u.d.len > 100 && !obj->u.d.sorted) + fz_sort_dict(obj); + + i = fz_dict_finds(obj, s, &location); + if (i >= 0 && i < obj->u.d.len) { fz_drop_obj(obj->u.d.items[i].v); obj->u.d.items[i].v = fz_keep_obj(val); - return; } + else + { + if (obj->u.d.len + 1 > obj->u.d.cap) + fz_dict_grow(obj); - if (obj->u.d.len + 1 > obj->u.d.cap) - fz_dict_grow(obj); + i = location; + if (obj->u.d.sorted) + memmove(&obj->u.d.items[i + 1], + &obj->u.d.items[i], + (obj->u.d.len - i) * sizeof(struct keyval)); - /* borked! */ - if (obj->u.d.len) - if (strcmp(fz_to_name(obj->u.d.items[obj->u.d.len - 1].k), s) > 0) - obj->u.d.sorted = 0; - - obj->u.d.items[obj->u.d.len].k = fz_keep_obj(key); - obj->u.d.items[obj->u.d.len].v = fz_keep_obj(val); - obj->u.d.len ++; + obj->u.d.items[i].k = fz_keep_obj(key); + obj->u.d.items[i].v = fz_keep_obj(val); + obj->u.d.len ++; + } } void -- cgit v1.2.3 From 7f69791dd7e5fd047253ed337f004ab1bfc0bb5b Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 28 Sep 2011 15:01:44 +0200 Subject: Improve trace formatting of text objects. Print CTM and TRM separately. --- fitz/dev_trace.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'fitz') diff --git a/fitz/dev_trace.c b/fitz/dev_trace.c index 03e05f91..a98eb898 100644 --- a/fitz/dev_trace.c +++ b/fitz/dev_trace.c @@ -7,6 +7,13 @@ fz_trace_matrix(fz_matrix ctm) ctm.a, ctm.b, ctm.c, ctm.d, ctm.e, ctm.f); } +static void +fz_trace_trm(fz_matrix trm) +{ + printf("trm=\"%g %g %g %g\" ", + trm.a, trm.b, trm.c, trm.d); +} + static void fz_trace_color(fz_colorspace *colorspace, float *color, float alpha) { @@ -135,7 +142,8 @@ fz_trace_fill_text(void *user, fz_text *text, fz_matrix ctm, { printf("font->name, text->wmode); fz_trace_color(colorspace, color, alpha); - fz_trace_matrix(fz_concat(ctm, text->trm)); + fz_trace_matrix(ctm); + fz_trace_trm(text->trm); printf(">\n"); fz_debug_text(text, 0); printf("\n"); @@ -147,7 +155,8 @@ fz_trace_stroke_text(void *user, fz_text *text, fz_stroke_state *stroke, fz_matr { printf("font->name, text->wmode); fz_trace_color(colorspace, color, alpha); - fz_trace_matrix(fz_concat(ctm, text->trm)); + fz_trace_matrix(ctm); + fz_trace_trm(text->trm); printf(">\n"); fz_debug_text(text, 0); printf("\n"); @@ -158,7 +167,8 @@ fz_trace_clip_text(void *user, fz_text *text, fz_matrix ctm, int accumulate) { printf("font->name, text->wmode); printf("accumulate=\"%d\" ", accumulate); - fz_trace_matrix(fz_concat(ctm, text->trm)); + fz_trace_matrix(ctm); + fz_trace_trm(text->trm); printf(">\n"); fz_debug_text(text, 0); printf("\n"); @@ -168,7 +178,8 @@ static void fz_trace_clip_stroke_text(void *user, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm) { printf("font->name, text->wmode); - fz_trace_matrix(fz_concat(ctm, text->trm)); + fz_trace_matrix(ctm); + fz_trace_trm(text->trm); printf(">\n"); fz_debug_text(text, 0); printf("\n"); @@ -178,7 +189,8 @@ static void fz_trace_ignore_text(void *user, fz_text *text, fz_matrix ctm) { printf("font->name, text->wmode); - fz_trace_matrix(fz_concat(ctm, text->trm)); + fz_trace_matrix(ctm); + fz_trace_trm(text->trm); printf(">\n"); fz_debug_text(text, 0); printf("\n"); -- cgit v1.2.3 From d5bdf330a2e9b5596dd7a3f40a6cbd81bd6e0538 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 31 Oct 2011 22:40:03 +0100 Subject: Avoid pointer arithmetic in fz_seek. The pointer arithmetic could over/underflow, causing the range test to pass even when it shouldn't (due to compiler oddities). --- fitz/stm_read.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'fitz') diff --git a/fitz/stm_read.c b/fitz/stm_read.c index 59f06433..ff97340f 100644 --- a/fitz/stm_read.c +++ b/fitz/stm_read.c @@ -175,10 +175,10 @@ fz_seek(fz_stream *stm, int offset, int whence) } if (whence == 0) { - unsigned char *p = stm->wp - (stm->pos - offset); - if (p >= stm->bp && p <= stm->wp) + int dist = stm->pos - offset; + if (dist >= 0 && dist <= stm->wp - stm->bp) { - stm->rp = p; + stm->rp = stm->wp - dist; stm->eof = 0; return; } -- cgit v1.2.3 From 97d00440c043b712a2d16134e3b52850c7b36d47 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 10 Nov 2011 01:52:40 +0100 Subject: Add XPS outline parsing and move outline data struct to fz_outline. --- fitz/doc_outline.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ fitz/fitz.h | 18 ++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 fitz/doc_outline.c (limited to 'fitz') diff --git a/fitz/doc_outline.c b/fitz/doc_outline.c new file mode 100644 index 00000000..ea3906ac --- /dev/null +++ b/fitz/doc_outline.c @@ -0,0 +1,49 @@ +#include "fitz.h" + +void +fz_free_outline(fz_outline *outline) +{ + while (outline) + { + fz_outline *next = outline->next; + fz_free_outline(outline->down); + fz_free(outline->title); + fz_free(outline); + outline = next; + } +} + +void +fz_debug_outline_xml(fz_outline *outline, int level) +{ + while (outline) + { + printf("title, outline->page); + if (outline->down) + { + printf(">\n"); + fz_debug_outline_xml(outline->down, level + 1); + printf("\n"); + } + else + { + printf(" />\n"); + } + outline = outline->next; + } +} + +void +fz_debug_outline(fz_outline *outline, int level) +{ + int i; + while (outline) + { + for (i = 0; i < level; i++) + putchar('\t'); + printf("%s\t%d\n", outline->title, outline->page); + if (outline->down) + fz_debug_outline(outline->down, level + 1); + outline = outline->next; + } +} diff --git a/fitz/fitz.h b/fitz/fitz.h index dff6b8d4..5529384d 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -1063,6 +1063,24 @@ void fz_free_display_list(fz_display_list *list); fz_device *fz_new_list_device(fz_display_list *list); void fz_execute_display_list(fz_display_list *list, fz_device *dev, fz_matrix ctm, fz_bbox area); +/* + * Document interface. + */ + +typedef struct fz_outline_s fz_outline; + +struct fz_outline_s +{ + char *title; + int page; + fz_outline *next; + fz_outline *down; +}; + +void fz_debug_outline_xml(fz_outline *outline, int level); +void fz_debug_outline(fz_outline *outline, int level); +void fz_free_outline(fz_outline *outline); + /* * Plotting functions. */ -- cgit v1.2.3 From 5c4ff53fb89b5068bc901fd5909be9e5d2d0cb0b Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 8 Nov 2011 17:46:48 +0000 Subject: Grid fitting tweaks. Extract the grid fitting code from the scaling code and the affine image drawing code into it's own separate function. This reduces code duplication. It also allows us to make better allowance for rounding errors. Add a voodoo offset in the draw_affine.c code for painting interpolated images. This gives us the best possible match between all the different combinations of scaled/unscaled and interpolated/uninterpolated images. --- fitz/fitz.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'fitz') diff --git a/fitz/fitz.h b/fitz/fitz.h index 5529384d..a1235c05 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -273,6 +273,8 @@ fz_point fz_transform_vector(fz_matrix m, fz_point p); fz_rect fz_transform_rect(fz_matrix m, fz_rect r); fz_bbox fz_transform_bbox(fz_matrix m, fz_bbox b); +void fz_gridfit_matrix(fz_matrix *m); + /* * Basic crypto functions. * Independent of the rest of fitz. @@ -629,7 +631,6 @@ void fz_invert_pixmap(fz_pixmap *pix); void fz_gamma_pixmap(fz_pixmap *pix, float gamma); fz_pixmap *fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h); -fz_pixmap *fz_scale_pixmap_gridfit(fz_pixmap *src, float x, float y, float w, float h, int gridfit); fz_error fz_write_pnm(fz_pixmap *pixmap, char *filename); fz_error fz_write_pam(fz_pixmap *pixmap, char *filename, int savealpha); -- cgit v1.2.3 From fd6def85f22b598d4c278e76138ab7dccbb84c36 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 14 Nov 2011 16:31:10 +0000 Subject: Squash 3 'const' warnings. 3 functions were defined as taking a const unsigned, but declared as taking an unsigned. Fixed here. --- fitz/crypt_arc4.c | 4 ++-- fitz/crypt_md5.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'fitz') diff --git a/fitz/crypt_arc4.c b/fitz/crypt_arc4.c index 72871386..272891ce 100644 --- a/fitz/crypt_arc4.c +++ b/fitz/crypt_arc4.c @@ -24,7 +24,7 @@ #include "fitz.h" void -fz_arc4_init(fz_arc4 *arc4, const unsigned char *key, const unsigned keylen) +fz_arc4_init(fz_arc4 *arc4, const unsigned char *key, unsigned keylen) { unsigned int t, u; unsigned int keyindex; @@ -86,7 +86,7 @@ fz_arc4_next(fz_arc4 *arc4) } void -fz_arc4_encrypt(fz_arc4 *arc4, unsigned char *dest, const unsigned char *src, const unsigned len) +fz_arc4_encrypt(fz_arc4 *arc4, unsigned char *dest, const unsigned char *src, unsigned len) { unsigned int i; for (i = 0; i < len; i++) diff --git a/fitz/crypt_md5.c b/fitz/crypt_md5.c index ba2571c4..b6e06845 100644 --- a/fitz/crypt_md5.c +++ b/fitz/crypt_md5.c @@ -210,7 +210,7 @@ void fz_md5_init(fz_md5 *context) /* MD5 block update operation. Continues an MD5 message-digest operation, * processing another message block, and updating the context. */ -void fz_md5_update(fz_md5 *context, const unsigned char *input, const unsigned inlen) +void fz_md5_update(fz_md5 *context, const unsigned char *input, unsigned inlen) { unsigned i, index, partlen; -- cgit v1.2.3