diff options
-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | apps/mupdfextract.c | 2 | ||||
-rw-r--r-- | apps/pdfapp.c | 56 | ||||
-rw-r--r-- | apps/win_main.c | 5 | ||||
-rw-r--r-- | apps/x11_main.c | 5 | ||||
-rw-r--r-- | fitz/fitz.h | 10 | ||||
-rw-r--r-- | fitz/res_pixmap.c | 12 | ||||
-rw-r--r-- | xps/muxps-internal.h | 242 | ||||
-rw-r--r-- | xps/muxps.h | 257 | ||||
-rw-r--r-- | xps/xps_common.c | 3 | ||||
-rw-r--r-- | xps/xps_doc.c | 3 | ||||
-rw-r--r-- | xps/xps_glyphs.c | 3 | ||||
-rw-r--r-- | xps/xps_gradient.c | 11 | ||||
-rw-r--r-- | xps/xps_image.c | 3 | ||||
-rw-r--r-- | xps/xps_outline.c | 3 | ||||
-rw-r--r-- | xps/xps_path.c | 23 | ||||
-rw-r--r-- | xps/xps_resource.c | 3 | ||||
-rw-r--r-- | xps/xps_tile.c | 3 | ||||
-rw-r--r-- | xps/xps_util.c | 3 | ||||
-rw-r--r-- | xps/xps_xml.c | 3 | ||||
-rw-r--r-- | xps/xps_zip.c | 3 |
21 files changed, 348 insertions, 320 deletions
@@ -36,6 +36,11 @@ MKDIR_CMD = $(QUIET_MKDIR) mkdir -p $@ # --- Rules --- +FITZ_HDR := fitz/fitz.h fitz/fitz-internal.h +MUPDF_HDR := $(FITZ_HDR) pdf/mupdf.h pdf/mupdf-internal.h +MUXPS_HDR := $(FITZ_HDR) xps/muxps.h xps/muxps-internal.h +MUCBZ_HDR := $(FITZ_HDR) cbz/mucbz.h + $(OUT) $(GEN) : $(MKDIR_CMD) @@ -46,15 +51,15 @@ $(OUT)/%.a : $(OUT)/% : $(OUT)/%.o $(LINK_CMD) -$(OUT)/%.o : fitz/%.c fitz/fitz.h | $(OUT) +$(OUT)/%.o : fitz/%.c $(FITZ_HDR) | $(OUT) $(CC_CMD) -$(OUT)/%.o : draw/%.c fitz/fitz.h | $(OUT) +$(OUT)/%.o : draw/%.c $(FITZ_HDR) | $(OUT) $(CC_CMD) -$(OUT)/%.o : pdf/%.c fitz/fitz.h pdf/mupdf.h | $(OUT) +$(OUT)/%.o : pdf/%.c $(MUPDF_HDR) | $(OUT) $(CC_CMD) -$(OUT)/%.o : xps/%.c fitz/fitz.h xps/muxps.h | $(OUT) +$(OUT)/%.o : xps/%.c $(MUXPS_HDR) | $(OUT) $(CC_CMD) -$(OUT)/%.o : cbz/%.c fitz/fitz.h cbz/mucbz.h | $(OUT) +$(OUT)/%.o : cbz/%.c $(MUCBZ_HDR) | $(OUT) $(CC_CMD) $(OUT)/%.o : apps/%.c fitz/fitz.h pdf/mupdf.h xps/muxps.h cbz/mucbz.h | $(OUT) $(CC_CMD) diff --git a/apps/mupdfextract.c b/apps/mupdfextract.c index 398ff6d9..e86a7db1 100644 --- a/apps/mupdfextract.c +++ b/apps/mupdfextract.c @@ -61,7 +61,7 @@ static void savefont(pdf_obj *dict, int num) FILE *f; char *fontname = "font"; int n, len; - char *data; + unsigned char *data; obj = pdf_dict_gets(dict, "FontName"); if (obj) diff --git a/apps/pdfapp.c b/apps/pdfapp.c index e5742645..7c64cdbb 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -199,20 +199,23 @@ static fz_matrix pdfapp_viewctm(pdfapp_t *app) static void pdfapp_panview(pdfapp_t *app, int newx, int newy) { + int image_w = fz_pixmap_width(app->ctx, app->image); + int image_h = fz_pixmap_height(app->ctx, app->image); + if (newx > 0) newx = 0; if (newy > 0) newy = 0; - if (newx + app->image->w < app->winw) - newx = app->winw - app->image->w; - if (newy + app->image->h < app->winh) - newy = app->winh - app->image->h; + if (newx + image_w < app->winw) + newx = app->winw - image_w; + if (newy + image_h < app->winh) + newy = app->winh - image_h; - if (app->winw >= app->image->w) - newx = (app->winw - app->image->w) / 2; - if (app->winh >= app->image->h) - newy = (app->winh - app->image->h) / 2; + if (app->winw >= image_w) + newx = (app->winw - image_w) / 2; + if (app->winh >= image_h) + newy = (app->winh - image_h) / 2; if (newx != app->panx || newy != app->pany) winrepaint(app); @@ -313,8 +316,8 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage, int repai if (app->shrinkwrap) { - int w = app->image->w; - int h = app->image->h; + int w = fz_pixmap_width(app->ctx, app->image); + int h = fz_pixmap_height(app->ctx, app->image); if (app->winw == w) app->panx = 0; if (app->winh == h) @@ -711,22 +714,22 @@ void pdfapp_onkey(pdfapp_t *app, int c) break; case 'h': - app->panx += app->image->w / 10; + app->panx += fz_pixmap_width(app->ctx, app->image) / 10; pdfapp_showpage(app, 0, 0, 1); break; case 'j': - app->pany -= app->image->h / 10; + app->pany -= fz_pixmap_height(app->ctx, app->image) / 10; pdfapp_showpage(app, 0, 0, 1); break; case 'k': - app->pany += app->image->h / 10; + app->pany += fz_pixmap_height(app->ctx, app->image) / 10; pdfapp_showpage(app, 0, 0, 1); break; case 'l': - app->panx -= app->image->w / 10; + app->panx -= fz_pixmap_width(app->ctx, app->image) / 10; pdfapp_showpage(app, 0, 0, 1); break; @@ -901,12 +904,13 @@ void pdfapp_onkey(pdfapp_t *app, int c) void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int state) { + fz_bbox rect = fz_bound_pixmap(app->image); fz_link *link; fz_matrix ctm; fz_point p; - p.x = x - app->panx + app->image->x; - p.y = y - app->pany + app->image->y; + p.x = x - app->panx + rect.x0; + p.y = y - app->pany + rect.y0; ctm = pdfapp_viewctm(app); ctm = fz_invert_matrix(ctm); @@ -990,10 +994,10 @@ void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int sta if (app->iscopying) { app->iscopying = 0; - app->selr.x0 = MIN(app->selx, x) - app->panx + app->image->x; - app->selr.x1 = MAX(app->selx, x) - app->panx + app->image->x; - app->selr.y0 = MIN(app->sely, y) - app->pany + app->image->y; - app->selr.y1 = MAX(app->sely, y) - app->pany + app->image->y; + app->selr.x0 = MIN(app->selx, x) - app->panx + rect.x0; + app->selr.x1 = MAX(app->selx, x) - app->panx + rect.x0; + app->selr.y0 = MIN(app->sely, y) - app->pany + rect.y0; + app->selr.y1 = MAX(app->sely, y) - app->pany + rect.y0; winrepaint(app); if (app->selr.x0 < app->selr.x1 && app->selr.y0 < app->selr.y1) windocopy(app); @@ -1008,7 +1012,7 @@ void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int sta int newy = app->pany + y - app->sely; /* Scrolling beyond limits implies flipping pages */ /* Are we requested to scroll beyond limits? */ - if (newy + app->image->h < app->winh || newy > 0) + if (newy + fz_pixmap_height(app->ctx, app->image) < app->winh || newy > 0) { /* Yes. We can assume that deltay != 0 */ int deltay = y - app->sely; @@ -1030,7 +1034,7 @@ void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int sta { app->pageno--; pdfapp_showpage(app, 1, 1, 1); - newy = -app->image->h; + newy = -fz_pixmap_height(app->ctx, app->image); } app->beyondy = 0; } @@ -1061,10 +1065,10 @@ void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int sta else if (app->iscopying) { - app->selr.x0 = MIN(app->selx, x) - app->panx + app->image->x; - app->selr.x1 = MAX(app->selx, x) - app->panx + app->image->x; - app->selr.y0 = MIN(app->sely, y) - app->pany + app->image->y; - app->selr.y1 = MAX(app->sely, y) - app->pany + app->image->y; + app->selr.x0 = MIN(app->selx, x) - app->panx + rect.x0; + app->selr.x1 = MAX(app->selx, x) - app->panx + rect.x0; + app->selr.y0 = MIN(app->sely, y) - app->pany + rect.y0; + app->selr.y1 = MAX(app->sely, y) - app->pany + rect.y0; winrepaint(app); } diff --git a/apps/win_main.c b/apps/win_main.c index 3417a11e..b8a18535 100644 --- a/apps/win_main.c +++ b/apps/win_main.c @@ -355,9 +355,8 @@ void winblitsearch() void winblit() { - fz_bbox bb = fz_bound_pixmap(gapp.image); - int image_w = bb.x1-bb.x0; - int image_h = bb.y1-bb.y0; + int image_w = fz_pixmap_width(gapp.ctx, gapp.image); + int image_h = fz_pixmap_height(gapp.ctx, gapp.image); int image_n = fz_pixmap_components(context, gapp.image); unsigned char *samples = fz_pixmap_pixels(context, gapp.image); int x0 = gapp.panx; diff --git a/apps/x11_main.c b/apps/x11_main.c index fe0196fc..0d7d6375 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -249,9 +249,8 @@ void winhelp(pdfapp_t *app) void winresize(pdfapp_t *app, int w, int h) { - fz_bbox bb = fz_bound_pixmap(gapp.image); - int image_w = bb.x1 - bb.x0; - int image_h = bb.y1 - bb.y0; + int image_w = fz_pixmap_width(gapp.ctx, gapp.image); + int image_h = fz_pixmap_height(gapp.ctx, gapp.image); XWindowChanges values; int mask, width, height; diff --git a/fitz/fitz.h b/fitz/fitz.h index 8570f077..85e1feea 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -1126,6 +1126,16 @@ typedef struct fz_pixmap_s fz_pixmap; fz_bbox fz_bound_pixmap(fz_pixmap *pix); /* + fz_pixmap_width: Return the width of the pixmap in pixels. +*/ +int fz_pixmap_width(fz_context *ctx, fz_pixmap *pix); + +/* + fz_pixmap_height: Return the height of the pixmap in pixels. +*/ +int fz_pixmap_height(fz_context *ctx, fz_pixmap *pix); + +/* fz_new_pixmap: Create a new pixmap, with it's origin at (0,0) cs: The colorspace to use for the pixmap, or NULL for an alpha diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index fc40135e..7aaf8ce0 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -110,6 +110,18 @@ fz_bound_pixmap(fz_pixmap *pix) return bbox; } +int +fz_pixmap_width(fz_context *ctx, fz_pixmap *pix) +{ + return pix->w; +} + +int +fz_pixmap_height(fz_context *ctx, fz_pixmap *pix) +{ + return pix->h; +} + void fz_clear_pixmap(fz_context *ctx, fz_pixmap *pix) { diff --git a/xps/muxps-internal.h b/xps/muxps-internal.h new file mode 100644 index 00000000..3084bdfa --- /dev/null +++ b/xps/muxps-internal.h @@ -0,0 +1,242 @@ +#ifndef MUXPS_INTERNAL_H +#define MUXPS_INTERNAL_H + +#include "muxps.h" +#include "fitz-internal.h" + +typedef unsigned char byte; + +/* + * XPS and ZIP constants. + */ + +#define REL_START_PART \ + "http://schemas.microsoft.com/xps/2005/06/fixedrepresentation" +#define REL_DOC_STRUCTURE \ + "http://schemas.microsoft.com/xps/2005/06/documentstructure" +#define REL_REQUIRED_RESOURCE \ + "http://schemas.microsoft.com/xps/2005/06/required-resource" +#define REL_REQUIRED_RESOURCE_RECURSIVE \ + "http://schemas.microsoft.com/xps/2005/06/required-resource#recursive" + +#define ZIP_LOCAL_FILE_SIG 0x04034b50 +#define ZIP_DATA_DESC_SIG 0x08074b50 +#define ZIP_CENTRAL_DIRECTORY_SIG 0x02014b50 +#define ZIP_END_OF_CENTRAL_DIRECTORY_SIG 0x06054b50 + +/* + * Memory, and string functions. + */ + +int xps_strcasecmp(char *a, char *b); +void xps_resolve_url(char *output, char *base_uri, char *path, int output_size); +int xps_url_is_remote(char *path); +char *xps_parse_point(char *s_in, float *x, float *y); + +/* + * Container parts. + */ + +typedef struct xps_part_s xps_part; + +struct xps_part_s +{ + char *name; + int size; + int cap; + byte *data; +}; + +xps_part *xps_new_part(xps_document *doc, char *name, int size); +int xps_has_part(xps_document *doc, char *partname); +xps_part *xps_read_part(xps_document *doc, char *partname); +void xps_free_part(xps_document *doc, xps_part *part); + +/* + * Document structure. + */ + +typedef struct xps_fixdoc_s xps_fixdoc; +typedef struct xps_target_s xps_target; + +struct xps_fixdoc_s +{ + char *name; + char *outline; + xps_fixdoc *next; +}; + +struct xps_page_s +{ + char *name; + int number; + int width; + int height; + xml_element *root; + int links_resolved; + fz_link *links; + xps_page *next; +}; + +struct xps_target_s +{ + char *name; + int page; + xps_target *next; +}; + +void xps_read_page_list(xps_document *doc); +void xps_debug_page_list(xps_document *doc); +void xps_free_page_list(xps_document *doc); + +int xps_count_pages(xps_document *doc); +xps_page *xps_load_page(xps_document *doc, int number); +fz_link *xps_load_links(xps_document *doc, xps_page *page); +fz_rect xps_bound_page(xps_document *doc, xps_page *page); +void xps_free_page(xps_document *doc, xps_page *page); + +fz_outline *xps_load_outline(xps_document *doc); + +int xps_find_link_target(xps_document *doc, char *target_uri); +void xps_add_link(xps_document *doc, fz_rect area, char *base_uri, char *target_uri); +/* + * Images, fonts, and colorspaces. + */ + +typedef struct xps_font_cache_s xps_font_cache; + +struct xps_font_cache_s +{ + char *name; + fz_font *font; + xps_font_cache *next; +}; + +typedef struct xps_glyph_metrics_s xps_glyph_metrics; + +struct xps_glyph_metrics_s +{ + float hadv, vadv, vorg; +}; + +int xps_count_font_encodings(fz_font *font); +void xps_identify_font_encoding(fz_font *font, int idx, int *pid, int *eid); +void xps_select_font_encoding(fz_font *font, int idx); +int xps_encode_font_char(fz_font *font, int key); + +void xps_measure_font_glyph(xps_document *doc, fz_font *font, int gid, xps_glyph_metrics *mtx); + +void xps_debug_path(xps_document *doc); + +void xps_parse_color(xps_document *doc, char *base_uri, char *hexstring, fz_colorspace **csp, float *samples); +void xps_set_color(xps_document *doc, fz_colorspace *colorspace, float *samples); + +/* + * Resource dictionaries. + */ + +typedef struct xps_resource_s xps_resource; + +struct xps_resource_s +{ + char *name; + char *base_uri; /* only used in the head nodes */ + xml_element *base_xml; /* only used in the head nodes, to free the xml document */ + xml_element *data; + xps_resource *next; + xps_resource *parent; /* up to the previous dict in the stack */ +}; + +xps_resource * xps_parse_resource_dictionary(xps_document *doc, char *base_uri, xml_element *root); +void xps_free_resource_dictionary(xps_document *doc, xps_resource *dict); +void xps_resolve_resource_reference(xps_document *doc, xps_resource *dict, char **attp, xml_element **tagp, char **urip); + +void xps_debug_resource_dictionary(xps_resource *dict); + +/* + * Fixed page/graphics parsing. + */ + +void xps_run_page(xps_document *doc, xps_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie); + +void xps_parse_fixed_page(xps_document *doc, fz_matrix ctm, xps_page *page); +void xps_parse_canvas(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_path(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_glyphs(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_solid_color_brush(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_image_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_visual_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_linear_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_radial_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); + +void xps_parse_tiling_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root, void(*func)(xps_document*, fz_matrix, fz_rect, char*, xps_resource*, xml_element*, void*), void *user); + +void xps_parse_matrix_transform(xps_document *doc, xml_element *root, fz_matrix *matrix); +void xps_parse_render_transform(xps_document *doc, char *text, fz_matrix *matrix); +void xps_parse_rectangle(xps_document *doc, char *text, fz_rect *rect); + +void xps_begin_opacity(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, char *opacity_att, xml_element *opacity_mask_tag); +void xps_end_opacity(xps_document *doc, char *base_uri, xps_resource *dict, char *opacity_att, xml_element *opacity_mask_tag); + +void xps_parse_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); +void xps_parse_element(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); + +void xps_clip(xps_document *doc, fz_matrix ctm, xps_resource *dict, char *clip_att, xml_element *clip_tag); + +/* + * The interpreter context. + */ + +typedef struct xps_entry_s xps_entry; + +struct xps_entry_s +{ + char *name; + int offset; + int csize; + int usize; +}; + +struct xps_document_s +{ + fz_document super; + + fz_context *ctx; + char *directory; + fz_stream *file; + int zip_count; + xps_entry *zip_table; + + char *start_part; /* fixed document sequence */ + xps_fixdoc *first_fixdoc; /* first fixed document */ + xps_fixdoc *last_fixdoc; /* last fixed document */ + xps_page *first_page; /* first page of document */ + xps_page *last_page; /* last page of document */ + int page_count; + + xps_target *target; /* link targets */ + + char *base_uri; /* base uri for parsing XML and resolving relative paths */ + char *part_uri; /* part uri for parsing metadata relations */ + + /* We cache font resources */ + xps_font_cache *font_table; + + /* Opacity attribute stack */ + float opacity[64]; + int opacity_top; + + /* Current color */ + fz_colorspace *colorspace; + float color[8]; + float alpha; + + /* Current device */ + fz_cookie *cookie; + fz_device *dev; + + /* Current page we are loading */ + xps_page *current_page; +}; + +#endif diff --git a/xps/muxps.h b/xps/muxps.h index caba3322..a485adca 100644 --- a/xps/muxps.h +++ b/xps/muxps.h @@ -1,37 +1,10 @@ -#ifndef _MUXPS_H_ -#define _MUXPS_H_ +#ifndef MUXPS_H +#define MUXPS_H -#include "fitz-internal.h" - -typedef unsigned char byte; - -/* - * XPS and ZIP constants. - */ +#include "fitz.h" typedef struct xps_document_s xps_document; - -#define REL_START_PART \ - "http://schemas.microsoft.com/xps/2005/06/fixedrepresentation" -#define REL_DOC_STRUCTURE \ - "http://schemas.microsoft.com/xps/2005/06/documentstructure" -#define REL_REQUIRED_RESOURCE \ - "http://schemas.microsoft.com/xps/2005/06/required-resource" -#define REL_REQUIRED_RESOURCE_RECURSIVE \ - "http://schemas.microsoft.com/xps/2005/06/required-resource#recursive" - -#define ZIP_LOCAL_FILE_SIG 0x04034b50 -#define ZIP_DATA_DESC_SIG 0x08074b50 -#define ZIP_CENTRAL_DIRECTORY_SIG 0x02014b50 -#define ZIP_END_OF_CENTRAL_DIRECTORY_SIG 0x06054b50 - -/* - * Memory, and string functions. - */ - -int xps_strcasecmp(char *a, char *b); -void xps_resolve_url(char *output, char *base_uri, char *path, int output_size); -int xps_url_is_remote(char *path); +typedef struct xps_page_s xps_page; /* * XML document model @@ -39,7 +12,7 @@ int xps_url_is_remote(char *path); typedef struct element xml_element; -xml_element *xml_parse_document(fz_context *doc, byte *buf, int len); +xml_element *xml_parse_document(fz_context *doc, unsigned char *buf, int len); xml_element *xml_next(xml_element *item); xml_element *xml_down(xml_element *item); char *xml_tag(xml_element *item); @@ -48,213 +21,6 @@ void xml_free_element(fz_context *doc, xml_element *item); void xml_print_element(xml_element *item, int level); /* - * Container parts. - */ - -typedef struct xps_part_s xps_part; - -struct xps_part_s -{ - char *name; - int size; - int cap; - byte *data; -}; - -xps_part *xps_new_part(xps_document *doc, char *name, int size); -int xps_has_part(xps_document *doc, char *partname); -xps_part *xps_read_part(xps_document *doc, char *partname); -void xps_free_part(xps_document *doc, xps_part *part); - -/* - * Document structure. - */ - -typedef struct xps_fixdoc_s xps_fixdoc; -typedef struct xps_page_s xps_page; -typedef struct xps_target_s xps_target; - -struct xps_fixdoc_s -{ - char *name; - char *outline; - xps_fixdoc *next; -}; - -struct xps_page_s -{ - char *name; - int number; - int width; - int height; - xml_element *root; - int links_resolved; - fz_link *links; - xps_page *next; -}; - -struct xps_target_s -{ - char *name; - int page; - xps_target *next; -}; - -void xps_read_page_list(xps_document *doc); -void xps_debug_page_list(xps_document *doc); -void xps_free_page_list(xps_document *doc); - -int xps_count_pages(xps_document *doc); -xps_page *xps_load_page(xps_document *doc, int number); -fz_link *xps_load_links(xps_document *doc, xps_page *page); -fz_rect xps_bound_page(xps_document *doc, xps_page *page); -void xps_free_page(xps_document *doc, xps_page *page); - -fz_outline *xps_load_outline(xps_document *doc); - -int xps_find_link_target(xps_document *doc, char *target_uri); -void xps_add_link(xps_document *doc, fz_rect area, char *base_uri, char *target_uri); -/* - * Images, fonts, and colorspaces. - */ - -typedef struct xps_font_cache_s xps_font_cache; - -struct xps_font_cache_s -{ - char *name; - fz_font *font; - xps_font_cache *next; -}; - -typedef struct xps_glyph_metrics_s xps_glyph_metrics; - -struct xps_glyph_metrics_s -{ - float hadv, vadv, vorg; -}; - -int xps_count_font_encodings(fz_font *font); -void xps_identify_font_encoding(fz_font *font, int idx, int *pid, int *eid); -void xps_select_font_encoding(fz_font *font, int idx); -int xps_encode_font_char(fz_font *font, int key); - -void xps_measure_font_glyph(xps_document *doc, fz_font *font, int gid, xps_glyph_metrics *mtx); - -void xps_debug_path(xps_document *doc); - -void xps_parse_color(xps_document *doc, char *base_uri, char *hexstring, fz_colorspace **csp, float *samples); -void xps_set_color(xps_document *doc, fz_colorspace *colorspace, float *samples); - -/* - * Resource dictionaries. - */ - -typedef struct xps_resource_s xps_resource; - -struct xps_resource_s -{ - char *name; - char *base_uri; /* only used in the head nodes */ - xml_element *base_xml; /* only used in the head nodes, to free the xml document */ - xml_element *data; - xps_resource *next; - xps_resource *parent; /* up to the previous dict in the stack */ -}; - -xps_resource * xps_parse_resource_dictionary(xps_document *doc, char *base_uri, xml_element *root); -void xps_free_resource_dictionary(xps_document *doc, xps_resource *dict); -void xps_resolve_resource_reference(xps_document *doc, xps_resource *dict, char **attp, xml_element **tagp, char **urip); - -void xps_debug_resource_dictionary(xps_resource *dict); - -/* - * Fixed page/graphics parsing. - */ - -void xps_run_page(xps_document *doc, xps_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie); - -void xps_parse_fixed_page(xps_document *doc, fz_matrix ctm, xps_page *page); -void xps_parse_canvas(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_path(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_glyphs(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_solid_color_brush(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_image_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_visual_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_linear_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_radial_gradient_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); - -void xps_parse_tiling_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root, void(*func)(xps_document*, fz_matrix, fz_rect, char*, xps_resource*, xml_element*, void*), void *user); - -void xps_parse_matrix_transform(xps_document *doc, xml_element *root, fz_matrix *matrix); -void xps_parse_render_transform(xps_document *doc, char *text, fz_matrix *matrix); -void xps_parse_rectangle(xps_document *doc, char *text, fz_rect *rect); - -void xps_begin_opacity(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, char *opacity_att, xml_element *opacity_mask_tag); -void xps_end_opacity(xps_document *doc, char *base_uri, xps_resource *dict, char *opacity_att, xml_element *opacity_mask_tag); - -void xps_parse_brush(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); -void xps_parse_element(xps_document *doc, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *node); - -void xps_clip(xps_document *doc, fz_matrix ctm, xps_resource *dict, char *clip_att, xml_element *clip_tag); - -/* - * The interpreter context. - */ - -typedef struct xps_entry_s xps_entry; - -struct xps_entry_s -{ - char *name; - int offset; - int csize; - int usize; -}; - -struct xps_document_s -{ - fz_document super; - - fz_context *ctx; - char *directory; - fz_stream *file; - int zip_count; - xps_entry *zip_table; - - char *start_part; /* fixed document sequence */ - xps_fixdoc *first_fixdoc; /* first fixed document */ - xps_fixdoc *last_fixdoc; /* last fixed document */ - xps_page *first_page; /* first page of document */ - xps_page *last_page; /* last page of document */ - int page_count; - - xps_target *target; /* link targets */ - - char *base_uri; /* base uri for parsing XML and resolving relative paths */ - char *part_uri; /* part uri for parsing metadata relations */ - - /* We cache font resources */ - xps_font_cache *font_table; - - /* Opacity attribute stack */ - float opacity[64]; - int opacity_top; - - /* Current color */ - fz_colorspace *colorspace; - float color[8]; - float alpha; - - /* Current device */ - fz_cookie *cookie; - fz_device *dev; - - /* Current page we are loading */ - xps_page *current_page; -}; - -/* xps_open_document: Open a document. Open a document for reading so the library is able to locate @@ -290,10 +56,13 @@ xps_document *xps_open_document_with_stream(fz_stream *file); */ void xps_close_document(xps_document *doc); -/* - * Parsing helper functions - */ -char *xps_get_real_params(char *s, int num, float *x); -char *xps_get_point(char *s_in, float *x, float *y); +int xps_count_pages(xps_document *doc); +xps_page *xps_load_page(xps_document *doc, int number); +fz_rect xps_bound_page(xps_document *doc, xps_page *page); +void xps_run_page(xps_document *doc, xps_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie); +fz_link *xps_load_links(xps_document *doc, xps_page *page); +void xps_free_page(xps_document *doc, xps_page *page); + +fz_outline *xps_load_outline(xps_document *doc); #endif diff --git a/xps/xps_common.c b/xps/xps_common.c index c8464459..4829ef9c 100644 --- a/xps/xps_common.c +++ b/xps/xps_common.c @@ -1,5 +1,4 @@ -#include "fitz-internal.h" -#include "muxps.h" +#include "muxps-internal.h" static inline int unhex(int a) { diff --git a/xps/xps_doc.c b/xps/xps_doc.c index 5515b47a..9988691f 100644 --- a/xps/xps_doc.c +++ b/xps/xps_doc.c @@ -1,5 +1,4 @@ -#include "fitz-internal.h" -#include "muxps.h" +#include "muxps-internal.h" static void xps_rels_for_part(char *buf, char *name, int buflen) diff --git a/xps/xps_glyphs.c b/xps/xps_glyphs.c index 6cdf420b..94baa918 100644 --- a/xps/xps_glyphs.c +++ b/xps/xps_glyphs.c @@ -1,5 +1,4 @@ -#include "fitz-internal.h" -#include "muxps.h" +#include "muxps-internal.h" #include <ft2build.h> #include FT_FREETYPE_H diff --git a/xps/xps_gradient.c b/xps/xps_gradient.c index 580a9cb6..fe88b295 100644 --- a/xps/xps_gradient.c +++ b/xps/xps_gradient.c @@ -1,5 +1,4 @@ -#include "fitz-internal.h" -#include "muxps.h" +#include "muxps-internal.h" #define MAX_STOPS 256 @@ -318,9 +317,9 @@ xps_draw_radial_gradient(xps_document *doc, fz_matrix ctm, yrad = 1.0; if (origin_att) - xps_get_point(origin_att, &x0, &y0); + xps_parse_point(origin_att, &x0, &y0); if (center_att) - xps_get_point(center_att, &x1, &y1); + xps_parse_point(center_att, &x1, &y1); if (radius_x_att) xrad = fz_atof(radius_x_att); if (radius_y_att) @@ -362,9 +361,9 @@ xps_draw_linear_gradient(xps_document *doc, fz_matrix ctm, x1 = y1 = 1; if (start_point_att) - xps_get_point(start_point_att, &x0, &y0); + xps_parse_point(start_point_att, &x0, &y0); if (end_point_att) - xps_get_point(end_point_att, &x1, &y1); + xps_parse_point(end_point_att, &x1, &y1); xps_draw_one_linear_gradient(doc, ctm, stops, count, 1, x0, y0, x1, y1); } diff --git a/xps/xps_image.c b/xps/xps_image.c index 665b6d11..1f46a756 100644 --- a/xps/xps_image.c +++ b/xps/xps_image.c @@ -1,5 +1,4 @@ -#include "fitz-internal.h" -#include "muxps.h" +#include "muxps-internal.h" typedef struct xps_image_s xps_image; diff --git a/xps/xps_outline.c b/xps/xps_outline.c index 577cdb6b..60e2f779 100644 --- a/xps/xps_outline.c +++ b/xps/xps_outline.c @@ -1,5 +1,4 @@ -#include "fitz-internal.h" -#include "muxps.h" +#include "muxps-internal.h" /* * Parse the document structure / outline parts referenced from fixdoc relationships. diff --git a/xps/xps_path.c b/xps/xps_path.c index b3dda187..337f144d 100644 --- a/xps/xps_path.c +++ b/xps/xps_path.c @@ -1,8 +1,7 @@ -#include "fitz-internal.h" -#include "muxps.h" +#include "muxps-internal.h" -char * -xps_get_real_params(char *s, int num, float *x) +static char * +xps_parse_float_array(char *s, int num, float *x) { int k = 0; @@ -25,12 +24,12 @@ xps_get_real_params(char *s, int num, float *x) } char * -xps_get_point(char *s_in, float *x, float *y) +xps_parse_point(char *s_in, float *x, float *y) { char *s_out = s_in; float xy[2]; - s_out = xps_get_real_params(s_out, 2, &xy[0]); + s_out = xps_parse_float_array(s_out, 2, &xy[0]); *x = xy[0]; *y = xy[1]; return s_out; @@ -516,8 +515,8 @@ xps_parse_arc_segment(fz_context *doc, fz_path *path, xml_element *root, int str if (!is_stroked) *skipped_stroke = 1; - xps_get_point(point_att, &point_x, &point_y); - xps_get_point(size_att, &size_x, &size_y); + xps_parse_point(point_att, &point_x, &point_y); + xps_parse_point(size_att, &size_x, &size_y); rotation_angle = fz_atof(rotation_angle_att); is_large_arc = !strcmp(is_large_arc_att, "true"); is_clockwise = !strcmp(sweep_direction_att, "Clockwise"); @@ -559,7 +558,7 @@ xps_parse_poly_quadratic_bezier_segment(fz_context *doc, fz_path *path, xml_elem while (*s != 0) { while (*s == ' ') s++; - s = xps_get_point(s, &x[n], &y[n]); + s = xps_parse_point(s, &x[n], &y[n]); n ++; if (n == 2) { @@ -607,7 +606,7 @@ xps_parse_poly_bezier_segment(fz_context *doc, fz_path *path, xml_element *root, while (*s != 0) { while (*s == ' ') s++; - s = xps_get_point(s, &x[n], &y[n]); + s = xps_parse_point(s, &x[n], &y[n]); n ++; if (n == 3) { @@ -645,7 +644,7 @@ xps_parse_poly_line_segment(fz_context *doc, fz_path *path, xml_element *root, i while (*s != 0) { while (*s == ' ') s++; - s = xps_get_point(s, &x, &y); + s = xps_parse_point(s, &x, &y); if (stroking && !is_stroked) fz_moveto(doc, path, x, y); else @@ -678,7 +677,7 @@ xps_parse_path_figure(fz_context *doc, fz_path *path, xml_element *root, int str if (is_filled_att) is_filled = !strcmp(is_filled_att, "true"); if (start_point_att) - xps_get_point(start_point_att, &start_x, &start_y); + xps_parse_point(start_point_att, &start_x, &start_y); if (!stroking && !is_filled) /* not filled, when filling */ return; diff --git a/xps/xps_resource.c b/xps/xps_resource.c index c65893a1..099f378d 100644 --- a/xps/xps_resource.c +++ b/xps/xps_resource.c @@ -1,5 +1,4 @@ -#include "fitz-internal.h" -#include "muxps.h" +#include "muxps-internal.h" static xml_element * xps_find_resource(xps_document *doc, xps_resource *dict, char *name, char **urip) diff --git a/xps/xps_tile.c b/xps/xps_tile.c index 93783ee1..5ec0463f 100644 --- a/xps/xps_tile.c +++ b/xps/xps_tile.c @@ -1,5 +1,4 @@ -#include "fitz-internal.h" -#include "muxps.h" +#include "muxps-internal.h" #define TILE diff --git a/xps/xps_util.c b/xps/xps_util.c index aed6c19f..cb84ba71 100644 --- a/xps/xps_util.c +++ b/xps/xps_util.c @@ -1,5 +1,4 @@ -#include "fitz-internal.h" -#include "muxps.h" +#include "muxps-internal.h" static inline int xps_tolower(int c) { diff --git a/xps/xps_xml.c b/xps/xps_xml.c index aee1568e..e2e958c8 100644 --- a/xps/xps_xml.c +++ b/xps/xps_xml.c @@ -1,5 +1,4 @@ -#include "fitz-internal.h" -#include "muxps.h" +#include "muxps-internal.h" struct attribute { diff --git a/xps/xps_zip.c b/xps/xps_zip.c index a2182d5c..be7ae221 100644 --- a/xps/xps_zip.c +++ b/xps/xps_zip.c @@ -1,5 +1,4 @@ -#include "fitz-internal.h" -#include "muxps.h" +#include "muxps-internal.h" #include <zlib.h> |