summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2011-11-14 18:22:13 +0000
committerRobin Watts <robin.watts@artifex.com>2011-11-15 15:20:54 +0000
commit9c0a49060475b2dea1e4c2668bebd1d566113a7b (patch)
tree49e45a691cf105f4266d5c6b7242a4a3256c1200 /fitz
parent60c0544742931da63db623ad7a79ba3758704cc1 (diff)
parentfd6def85f22b598d4c278e76138ab7dccbb84c36 (diff)
downloadmupdf-9c0a49060475b2dea1e4c2668bebd1d566113a7b.tar.xz
Merge branch 'master' into context
Mostly redoing the xps_context to xps_document change and adding contexts to newly written code. Conflicts: apps/pdfapp.c apps/pdfapp.h apps/x11_main.c apps/xpsdraw.c draw/draw_device.c draw/draw_scale.c fitz/base_object.c fitz/fitz.h pdf/mupdf.h pdf/pdf_interpret.c pdf/pdf_outline.c pdf/pdf_page.c xps/muxps.h xps/xps_doc.c xps/xps_xml.c
Diffstat (limited to 'fitz')
-rw-r--r--fitz/base_object.c103
-rw-r--r--fitz/dev_trace.c22
-rw-r--r--fitz/doc_outline.c49
-rw-r--r--fitz/filt_jpxd.c9
-rw-r--r--fitz/fitz.h22
-rw-r--r--fitz/stm_read.c6
6 files changed, 161 insertions, 50 deletions
diff --git a/fitz/base_object.c b/fitz/base_object.c
index 6307e5e0..b1feeb2c 100644
--- a/fitz/base_object.c
+++ b/fitz/base_object.c
@@ -396,6 +396,18 @@ fz_new_array(fz_context *ctx, 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_resize_array(obj->ctx, 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_context *ctx, fz_obj *obj)
{
@@ -466,13 +478,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_resize_array(obj->ctx, 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++;
}
@@ -488,13 +494,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_resize_array(obj->ctx, 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++;
@@ -521,7 +521,7 @@ fz_new_dict(fz_context *ctx, 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;
@@ -535,6 +535,21 @@ fz_new_dict(fz_context *ctx, 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_resize_array(obj->ctx, 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_context *ctx, fz_obj *obj)
{
@@ -590,12 +605,20 @@ 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)
{
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;
@@ -606,6 +629,9 @@ fz_dict_finds(fz_obj *obj, char *key)
l = m + 1;
else
return m;
+
+ if (location)
+ *location = l;
}
}
@@ -615,6 +641,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;
@@ -630,7 +659,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;
@@ -658,6 +687,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;
@@ -683,33 +713,30 @@ fz_dict_put(fz_obj *obj, fz_obj *key, fz_obj *val)
return;
}
- i = fz_dict_finds(obj, s);
- 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;
}
-
- if (obj->u.d.len + 1 > obj->u.d.cap)
+ else
{
- obj->u.d.cap = (obj->u.d.cap * 3) / 2;
- obj->u.d.items = fz_resize_array(obj->ctx, 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;
- }
- }
+ if (obj->u.d.len + 1 > obj->u.d.cap)
+ fz_dict_grow(obj);
- /* 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;
+ 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));
- 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
@@ -729,7 +756,7 @@ fz_dict_dels(fz_obj *obj, char *key)
fz_warn(obj->ctx, "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);
diff --git a/fitz/dev_trace.c b/fitz/dev_trace.c
index 4db215a0..62661a3d 100644
--- a/fitz/dev_trace.c
+++ b/fitz/dev_trace.c
@@ -8,6 +8,13 @@ fz_trace_matrix(fz_matrix ctm)
}
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)
{
int i;
@@ -135,7 +142,8 @@ fz_trace_fill_text(fz_device *dev, fz_text *text, fz_matrix ctm,
{
printf("<fill_text font=\"%s\" wmode=\"%d\" ", text->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("</fill_text>\n");
@@ -147,7 +155,8 @@ fz_trace_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_
{
printf("<stroke_text font=\"%s\" wmode=\"%d\" ", text->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("</stroke_text>\n");
@@ -158,7 +167,8 @@ fz_trace_clip_text(fz_device *dev, fz_text *text, fz_matrix ctm, int accumulate)
{
printf("<clip_text font=\"%s\" wmode=\"%d\" ", text->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("</clip_text>\n");
@@ -168,7 +178,8 @@ static void
fz_trace_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm)
{
printf("<clip_stroke_text font=\"%s\" wmode=\"%d\" ", text->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("</clip_stroke_text>\n");
@@ -178,7 +189,8 @@ static void
fz_trace_ignore_text(fz_device *dev, fz_text *text, fz_matrix ctm)
{
printf("<ignore_text font=\"%s\" wmode=\"%d\" ", text->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("</ignore_text>\n");
diff --git a/fitz/doc_outline.c b/fitz/doc_outline.c
new file mode 100644
index 00000000..f6d07405
--- /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->ctx, outline->title);
+ fz_free(outline->ctx, outline);
+ outline = next;
+ }
+}
+
+void
+fz_debug_outline_xml(fz_outline *outline, int level)
+{
+ while (outline)
+ {
+ printf("<outline title=\"%s\" page=\"%d\"", outline->title, outline->page);
+ if (outline->down)
+ {
+ printf(">\n");
+ fz_debug_outline_xml(outline->down, level + 1);
+ printf("</outline>\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/filt_jpxd.c b/fitz/filt_jpxd.c
index 5700a664..64197a08 100644
--- a/fitz/filt_jpxd.c
+++ b/fitz/filt_jpxd.c
@@ -5,17 +5,19 @@
static void fz_opj_error_callback(const char *msg, void *client_data)
{
- fprintf(stderr, "openjpeg error: %s", msg);
+ fz_context *ctx = (fz_context *)client_data;
+ fz_warn(ctx, "openjpeg error: %s", msg);
}
static void fz_opj_warning_callback(const char *msg, void *client_data)
{
- fprintf(stderr, "openjpeg warning: %s", msg);
+ fz_context *ctx = (fz_context *)client_data;
+ fz_warn(ctx, "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_pixmap *
@@ -50,6 +52,7 @@ fz_load_jpx_image(fz_context *ctx, unsigned char *data, int size, fz_colorspace
opj_set_default_decoder_parameters(&params);
info = opj_create_decompress(format);
+ info->client_data = (void *)ctx;
opj_set_event_mgr((opj_common_ptr)info, &evtmgr, stderr);
opj_setup_decoder(info, &params);
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 44d976cb..0a3875c7 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -348,6 +348,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.
@@ -705,7 +707,6 @@ void fz_invert_pixmap(fz_pixmap *pix);
void fz_gamma_pixmap(fz_pixmap *pix, float gamma);
fz_pixmap *fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h);
-fz_pixmap *fz_scale_pixmap_gridfit(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h, int gridfit);
void fz_write_pnm(fz_context *ctx, fz_pixmap *pixmap, char *filename);
void fz_write_pam(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha);
@@ -1141,6 +1142,25 @@ fz_device *fz_new_list_device(fz_context *ctx, 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
+{
+ fz_context *ctx;
+ 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.
*/
diff --git a/fitz/stm_read.c b/fitz/stm_read.c
index 58379887..5622a24f 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;
}