diff options
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/data_encodings.h | 6 | ||||
-rw-r--r-- | pdf/mupdf.h | 14 | ||||
-rw-r--r-- | pdf/pdf_interpret.c | 28 | ||||
-rw-r--r-- | pdf/pdf_outline.c | 67 | ||||
-rw-r--r-- | pdf/pdf_page.c | 32 | ||||
-rw-r--r-- | pdf/pdf_shade.c | 3 | ||||
-rw-r--r-- | pdf/pdf_xobject.c | 3 |
7 files changed, 53 insertions, 100 deletions
diff --git a/pdf/data_encodings.h b/pdf/data_encodings.h index 4a86e514..96b06769 100644 --- a/pdf/data_encodings.h +++ b/pdf/data_encodings.h @@ -2,9 +2,9 @@ const unsigned short pdf_doc_encoding[256] = { - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0009, 0x000A, 0x0000, 0x0000, 0x000D, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0, ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', 0x9, 0xA, ' ', ' ', 0xD, ' ', ' ', + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0x02d8, 0x02c7, 0x02c6, 0x02d9, 0x02dd, 0x02db, 0x02da, 0x02dc, 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, diff --git a/pdf/mupdf.h b/pdf/mupdf.h index 727d28e2..d3eb72e6 100644 --- a/pdf/mupdf.h +++ b/pdf/mupdf.h @@ -410,7 +410,6 @@ void pdf_debug_font(pdf_font_desc *fontdesc); typedef struct pdf_link_s pdf_link; typedef struct pdf_annot_s pdf_annot; -typedef struct pdf_outline_s pdf_outline; typedef enum pdf_link_kind_e { @@ -438,22 +437,11 @@ struct pdf_annot_s pdf_annot *next; }; -struct pdf_outline_s -{ - char *title; - pdf_link *link; - int count; - pdf_outline *child; - pdf_outline *next; -}; - fz_obj *pdf_lookup_dest(pdf_xref *xref, fz_obj *needle); fz_obj *pdf_lookup_name(pdf_xref *xref, char *which, fz_obj *needle); fz_obj *pdf_load_name_tree(pdf_xref *xref, char *which); -pdf_outline *pdf_load_outline(pdf_xref *xref); -void pdf_debug_outline(fz_context *ctx, pdf_outline *outline, int level); -void pdf_free_outline(fz_context *ctx, pdf_outline *outline); +fz_outline *pdf_load_outline(pdf_xref *xref); pdf_link *pdf_load_link(pdf_xref *xref, fz_obj *dict); void pdf_load_links(pdf_link **, pdf_xref *, fz_obj *annots); diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index e7555e24..21039f8c 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -82,6 +82,8 @@ struct pdf_csi_s /* path object state */ fz_path *path; + int clip; + int clip_even_odd; /* text object state */ fz_text *text; @@ -241,14 +243,6 @@ pdf_show_image(pdf_csi *csi, fz_pixmap *image) pdf_end_group(csi); } -static void pdf_show_clip(pdf_csi *csi, int even_odd) -{ - pdf_gstate *gstate = csi->gstate + csi->gtop; - - gstate->clip_depth++; - fz_clip_path(csi->dev, csi->path, NULL, even_odd, gstate->ctm); -} - static void pdf_show_path(pdf_csi *csi, int doclose, int dofill, int dostroke, int even_odd) { @@ -271,6 +265,12 @@ pdf_show_path(pdf_csi *csi, int doclose, int dofill, int dostroke, int even_odd) if (dofill || dostroke) pdf_begin_group(csi, bbox); + if (csi->clip) + { + gstate->clip_depth++; + fz_clip_path(csi->dev, path, NULL, csi->clip_even_odd, gstate->ctm); + } + if (dofill) { switch (gstate->fill.kind) @@ -674,7 +674,9 @@ pdf_new_csi(pdf_xref *xref, fz_device *dev, fz_matrix ctm, char *target) csi->xbalance = 0; csi->in_text = 0; - csi->path = fz_new_path(dev->ctx); + csi->path = fz_new_path(xref->ctx); + csi->clip = 0; + csi->clip_even_odd = 0; csi->text = NULL; csi->tlm = fz_identity; @@ -1090,7 +1092,7 @@ pdf_run_xobject(pdf_csi *csi, fz_obj *resources, pdf_xobject *xobj, fz_matrix tr fz_lineto(ctx, csi->path, xobj->bbox.x1, xobj->bbox.y1); fz_lineto(ctx, csi->path, xobj->bbox.x0, xobj->bbox.y1); fz_closepath(ctx, csi->path); - pdf_show_clip(csi, 0); + csi->clip = 1; pdf_show_path(csi, 0, 0, 0, 0); /* run contents */ @@ -1702,12 +1704,14 @@ static void pdf_run_TJ(pdf_csi *csi) static void pdf_run_W(pdf_csi *csi) { - pdf_show_clip(csi, 0); + csi->clip = 1; + csi->clip_even_odd = 0; } static void pdf_run_Wstar(pdf_csi *csi) { - pdf_show_clip(csi, 1); + csi->clip = 1; + csi->clip_even_odd = 1; } static void pdf_run_b(pdf_csi *csi) diff --git a/pdf/pdf_outline.c b/pdf/pdf_outline.c index 677a701f..9353d892 100644 --- a/pdf/pdf_outline.c +++ b/pdf/pdf_outline.c @@ -1,37 +1,39 @@ #include "fitz.h" #include "mupdf.h" -static pdf_outline * +static fz_outline * pdf_load_outline_imp(pdf_xref *xref, fz_obj *dict) { fz_context *ctx = xref->ctx; - pdf_outline *node; + pdf_link *link; + fz_outline *node; fz_obj *obj; if (fz_is_null(dict)) return NULL; - node = fz_malloc(ctx, sizeof(pdf_outline)); + node = fz_malloc(ctx, sizeof(fz_outline)); + node->ctx = ctx; node->title = NULL; - node->link = NULL; - node->child = NULL; + node->page = 0; + node->down = NULL; node->next = NULL; - node->count = 0; obj = fz_dict_gets(dict, "Title"); if (obj) node->title = pdf_to_utf8(ctx, obj); - obj = fz_dict_gets(dict, "Count"); - if (obj) - node->count = fz_to_int(obj); - if (fz_dict_gets(dict, "Dest") || fz_dict_gets(dict, "A")) - node->link = pdf_load_link(xref, dict); + { + link = pdf_load_link(xref, dict); + if (link->kind == PDF_LINK_GOTO) + node->page = pdf_find_page_number(xref, fz_array_get(link->dest, 0)); + pdf_free_link(xref->ctx, link); + } obj = fz_dict_gets(dict, "First"); if (obj) - node->child = pdf_load_outline_imp(xref, obj); + node->down = pdf_load_outline_imp(xref, obj); obj = fz_dict_gets(dict, "Next"); if (obj) @@ -40,7 +42,7 @@ pdf_load_outline_imp(pdf_xref *xref, fz_obj *dict) return node; } -pdf_outline * +fz_outline * pdf_load_outline(pdf_xref *xref) { fz_obj *root, *obj, *first; @@ -53,42 +55,3 @@ pdf_load_outline(pdf_xref *xref) return NULL; } - -void -pdf_free_outline(fz_context *ctx, pdf_outline *outline) -{ - if (outline->child) - pdf_free_outline(ctx, outline->child); - if (outline->next) - pdf_free_outline(ctx, outline->next); - if (outline->link) - pdf_free_link(ctx, outline->link); - fz_free(ctx, outline->title); - fz_free(ctx, outline); -} - -void -pdf_debug_outline(fz_context *ctx, pdf_outline *outline, int level) -{ - int i; - while (outline) - { - for (i = 0; i < level; i++) - putchar(' '); - - if (outline->title) - printf("%s ", outline->title); - else - printf("<NULL> "); - - if (outline->link) - fz_debug_obj(outline->link->dest); - else - printf("<NULL>\n"); - - if (outline->child) - pdf_debug_outline(ctx, outline->child, level + 2); - - outline = outline->next; - } -} diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c index c97eb9b4..fdc48ff3 100644 --- a/pdf/pdf_page.c +++ b/pdf/pdf_page.c @@ -269,7 +269,7 @@ pdf_load_page(pdf_xref *xref, int number) pdf_annot *annot; fz_obj *pageobj, *pageref; fz_obj *obj; - fz_bbox bbox; + fz_rect mediabox, cropbox; fz_context *ctx = xref->ctx; if (number < 0 || number >= xref->page_len) @@ -289,28 +289,24 @@ pdf_load_page(pdf_xref *xref, int number) page->links = NULL; page->annots = NULL; - obj = fz_dict_gets(pageobj, "MediaBox"); - bbox = fz_round_rect(pdf_to_rect(ctx, obj)); - if (fz_is_empty_rect(pdf_to_rect(ctx, obj))) + mediabox = pdf_to_rect(ctx, fz_dict_gets(pageobj, "MediaBox")); + if (fz_is_empty_rect(mediabox)) { fz_warn(ctx, "cannot find page size for page %d", number + 1); - bbox.x0 = 0; - bbox.y0 = 0; - bbox.x1 = 612; - bbox.y1 = 792; + mediabox.x0 = 0; + mediabox.y0 = 0; + mediabox.x1 = 612; + mediabox.y1 = 792; } - obj = fz_dict_gets(pageobj, "CropBox"); - if (fz_is_array(obj)) - { - fz_bbox cropbox = fz_round_rect(pdf_to_rect(ctx, obj)); - bbox = fz_intersect_bbox(bbox, cropbox); - } + cropbox = pdf_to_rect(ctx, fz_dict_gets(pageobj, "CropBox")); + if (!fz_is_empty_rect(cropbox)) + mediabox = fz_intersect_rect(mediabox, cropbox); - page->mediabox.x0 = MIN(bbox.x0, bbox.x1); - page->mediabox.y0 = MIN(bbox.y0, bbox.y1); - page->mediabox.x1 = MAX(bbox.x0, bbox.x1); - page->mediabox.y1 = MAX(bbox.y0, bbox.y1); + page->mediabox.x0 = MIN(mediabox.x0, mediabox.x1); + page->mediabox.y0 = MIN(mediabox.y0, mediabox.y1); + page->mediabox.x1 = MAX(mediabox.x0, mediabox.x1); + page->mediabox.y1 = MAX(mediabox.y0, mediabox.y1); if (page->mediabox.x1 - page->mediabox.x0 < 1 || page->mediabox.y1 - page->mediabox.y0 < 1) { diff --git a/pdf/pdf_shade.c b/pdf/pdf_shade.c index ca39e1f8..b281542b 100644 --- a/pdf/pdf_shade.c +++ b/pdf/pdf_shade.c @@ -1029,7 +1029,8 @@ pdf_load_shading_dict(pdf_xref *xref, fz_obj *dict, fz_matrix transform) for (i = 0; i < funcs; i++) { func[i] = pdf_load_function(xref, fz_array_get(obj, i)); - fz_throw(ctx, "cannot load shading function (%d %d R)", fz_to_num(obj), fz_to_gen(obj)); + if (func[i] == NULL) + fz_throw(ctx, "cannot load shading function (%d %d R)", fz_to_num(obj), fz_to_gen(obj)); } } diff --git a/pdf/pdf_xobject.c b/pdf/pdf_xobject.c index ceec02d0..81ef52fa 100644 --- a/pdf/pdf_xobject.c +++ b/pdf/pdf_xobject.c @@ -51,7 +51,8 @@ pdf_load_xobject(pdf_xref *xref, fz_obj *dict) if (obj) { form->colorspace = pdf_load_colorspace(xref, obj); - fz_throw(ctx, "cannot load xobject colorspace"); + if (form->colorspace == NULL) + fz_throw(ctx, "cannot load xobject colorspace"); } } |