diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-10-17 17:13:32 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-10-28 16:18:38 +0200 |
commit | 8a07b7fb14f11204a0d840792ab9f4bd54b066e5 (patch) | |
tree | e617a898c17aeb353f35d7b362ca2de290cf2b82 /include | |
parent | 4029b45e494634361a4205f8896ec429d11e990a (diff) | |
download | mupdf-8a07b7fb14f11204a0d840792ab9f4bd54b066e5.tar.xz |
Clean up link destination handling.
All link destinations should be URIs, and a document specific function
can be called to resolve them to actual page numbers.
Outlines have cached page numbers as well as string URIs.
Diffstat (limited to 'include')
-rw-r--r-- | include/mupdf/fitz/document.h | 9 | ||||
-rw-r--r-- | include/mupdf/fitz/link.h | 145 | ||||
-rw-r--r-- | include/mupdf/fitz/outline.h | 12 | ||||
-rw-r--r-- | include/mupdf/pdf/annot.h | 7 |
4 files changed, 33 insertions, 140 deletions
diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h index 7f3c8ece..d8123a00 100644 --- a/include/mupdf/fitz/document.h +++ b/include/mupdf/fitz/document.h @@ -32,6 +32,7 @@ typedef int (fz_document_authenticate_password_fn)(fz_context *ctx, fz_document typedef int (fz_document_has_permission_fn)(fz_context *ctx, fz_document *doc, fz_permission permission); typedef fz_outline *(fz_document_load_outline_fn)(fz_context *ctx, fz_document *doc); typedef void (fz_document_layout_fn)(fz_context *ctx, fz_document *doc, float w, float h, float em); +typedef int (fz_document_resolve_link_fn)(fz_context *ctx, fz_document *doc, const char *uri); typedef int (fz_document_count_pages_fn)(fz_context *ctx, fz_document *doc); typedef fz_page *(fz_document_load_page_fn)(fz_context *ctx, fz_document *doc, int number); typedef int (fz_document_lookup_metadata_fn)(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size); @@ -87,6 +88,7 @@ struct fz_document_s fz_document_has_permission_fn *has_permission; fz_document_load_outline_fn *load_outline; fz_document_layout_fn *layout; + fz_document_resolve_link_fn *resolve_link; fz_document_count_pages_fn *count_pages; fz_document_load_page_fn *load_page; fz_document_lookup_metadata_fn *lookup_metadata; @@ -210,6 +212,13 @@ void fz_layout_document(fz_context *ctx, fz_document *doc, float w, float h, flo int fz_count_pages(fz_context *ctx, fz_document *doc); /* + fz_resolve_link: Resolve an internal link to a page number. + + Returns -1 if the URI cannot be resolved. +*/ +int fz_resolve_link(fz_context *ctx, fz_document *doc, const char *uri); + +/* fz_load_page: Load a page. After fz_load_page is it possible to retrieve the size of the diff --git a/include/mupdf/fitz/link.h b/include/mupdf/fitz/link.h index 47abe1b4..e00d66d4 100644 --- a/include/mupdf/fitz/link.h +++ b/include/mupdf/fitz/link.h @@ -7,135 +7,10 @@ /* Links - - NOTE: The link destination struct is scheduled for imminent change! - Use at your own peril. */ typedef struct fz_link_s fz_link; -typedef struct fz_link_dest_s fz_link_dest; - -typedef enum fz_link_kind_e -{ - FZ_LINK_NONE = 0, - FZ_LINK_GOTO, - FZ_LINK_URI, - FZ_LINK_LAUNCH, - FZ_LINK_NAMED, - FZ_LINK_GOTOR -} fz_link_kind; - -enum { - fz_link_flag_l_valid = 1, /* lt.x is valid */ - fz_link_flag_t_valid = 2, /* lt.y is valid */ - fz_link_flag_r_valid = 4, /* rb.x is valid */ - fz_link_flag_b_valid = 8, /* rb.y is valid */ - fz_link_flag_fit_h = 16, /* Fit horizontally */ - fz_link_flag_fit_v = 32, /* Fit vertically */ - fz_link_flag_r_is_zoom = 64 /* rb.x is actually a zoom figure */ -}; - -/* - fz_link_dest: This structure represents the destination of - an fz_link; this may be a page to display, a new file to open, - a javascript action to perform, etc. - - kind: This identifies the kind of link destination. Different - kinds use different sections of the union. - - For FZ_LINK_GOTO or FZ_LINK_GOTOR: - - gotor.page: The target page number to move to (0 being the - first page in the document). In the FZ_LINK_GOTOR case, the - page number either refers to to the file specified by - gotor.file_spec, or the page number is -1 suggesting that - the destination is given by gotor.dest. - - gotor.dest: If set, the target destination name to be - resolved in the file specified by gotor.file_spec. Always - NULL in the FZ_LINK_GOTO case. - - gotor.flags: A bitfield consisting of fz_link_flag_* - describing the validity and meaning of the different parts - of gotor.lt and gotor.rb. Link destinations are constructed - (as far as possible) so that lt and rb can be treated as a - bounding box, though the validity flags indicate which of the - values was actually specified in the file. - - gotor.lt: The top left corner of the destination bounding box. - - gotor.rb: The bottom right corner of the destination bounding - box. If fz_link_flag_r_is_zoom is set, then the r figure - should actually be interpreted as a zoom ratio. - - gotor.file_spec: If set, this destination should cause a new - file to be opened; this field holds a pointer to a remote - file specification (UTF-8). Always NULL in the FZ_LINK_GOTO - case. - - gotor.new_window: If true, the destination should open in a - new window. Always false in the FZ_LINK_GOTO case. - - For FZ_LINK_URI: - - uri.uri: A UTF-8 encoded URI to launch. - - uri.is_map: If true, the x and y coords (as ints, in user - space) should be appended to the URI before launch. - - For FZ_LINK_LAUNCH: - - launch.file_spec: A UTF-8 file specification to launch. - - launch.new_window: If true, the destination should be launched - in a new window. - - launch.is_uri: If true, launch.file_spec is a URI to launch. - - For FZ_LINK_NAMED: - - named.named: The named action to perform. Likely to be - client specific. -*/ -struct fz_link_dest_s -{ - fz_link_kind kind; - union - { - struct - { - int page; - char *dest; - int flags; - fz_point lt; - fz_point rb; - char *file_spec; - int new_window; - } - gotor; - struct - { - char *uri; - int is_map; - } - uri; - struct - { - char *file_spec; - int new_window; - int is_uri; - } - launch; - struct - { - char *named; - } - named; - } - ld; -}; - /* fz_link is a list of interactive links on a page. @@ -149,30 +24,34 @@ struct fz_link_dest_s rect: The hot zone. The area that can be clicked in untransformed coordinates. - dest: Link destinations come in two forms: Page and area that - an application should display when this link is activated. Or - as an URI that can be given to a browser. + uri: Link destinations come in two forms: internal and external. + Internal links refer to other pages in the same document. + External links are URLs to other documents. next: A pointer to the next link on the same page. */ struct fz_link_s { int refs; - fz_rect rect; - fz_link_dest dest; fz_link *next; + fz_rect rect; + void *doc; + char *uri; }; -fz_link *fz_new_link(fz_context *ctx, const fz_rect *bbox, fz_link_dest dest); +fz_link *fz_new_link(fz_context *ctx, const fz_rect *bbox, void *doc, const char *uri); fz_link *fz_keep_link(fz_context *ctx, fz_link *link); /* + Checks if a link destination is external or internal. +*/ +int fz_is_external_link(fz_context *ctx, const char *uri); + +/* fz_drop_link: Drop and free a list of links. Does not throw exceptions. */ void fz_drop_link(fz_context *ctx, fz_link *link); -void fz_drop_link_dest(fz_context *ctx, fz_link_dest *dest); - #endif diff --git a/include/mupdf/fitz/outline.h b/include/mupdf/fitz/outline.h index c3f724bc..0223ecfa 100644 --- a/include/mupdf/fitz/outline.h +++ b/include/mupdf/fitz/outline.h @@ -15,9 +15,12 @@ title: Title of outline item using UTF-8 encoding. May be NULL if the outline item has no text string. - dest: Destination in the document to be displayed when this - outline item is activated. May be FZ_LINK_NONE if the outline - item does not have a destination. + uri: Destination in the document to be displayed when this + outline item is activated. May be an internal or external + link, or NULL if the outline item does not have a destination. + + page: The page number of an internal link, or -1 for external + links or links with no destination. next: The next outline item at the same level as this outline item. May be NULL if no more outline items exist at this level. @@ -32,7 +35,8 @@ struct fz_outline_s { int refs; char *title; - fz_link_dest dest; + char *uri; + int page; fz_outline *next; fz_outline *down; int is_open; diff --git a/include/mupdf/pdf/annot.h b/include/mupdf/pdf/annot.h index 9cd80e06..caaa9047 100644 --- a/include/mupdf/pdf/annot.h +++ b/include/mupdf/pdf/annot.h @@ -101,13 +101,14 @@ struct pdf_annot_s pdf_annot *next; }; -fz_link_dest pdf_parse_link_dest(fz_context *ctx, pdf_document *doc, fz_link_kind kind, pdf_obj *dest); -char *pdf_parse_file_spec(fz_context *ctx, pdf_document *doc, pdf_obj *file_spec); -fz_link_dest pdf_parse_action(fz_context *ctx, pdf_document *doc, pdf_obj *action); +char *pdf_parse_file_spec(fz_context *ctx, pdf_document *doc, pdf_obj *file_spec, pdf_obj *dest); +char *pdf_parse_link_dest(fz_context *ctx, pdf_document *doc, pdf_obj *obj); +char *pdf_parse_link_action(fz_context *ctx, pdf_document *doc, pdf_obj *obj); pdf_obj *pdf_lookup_dest(fz_context *ctx, pdf_document *doc, pdf_obj *needle); pdf_obj *pdf_lookup_name(fz_context *ctx, pdf_document *doc, pdf_obj *which, pdf_obj *needle); pdf_obj *pdf_load_name_tree(fz_context *ctx, pdf_document *doc, pdf_obj *which); +int pdf_resolve_link(fz_context *ctx, pdf_document *doc, const char *uri); fz_link *pdf_load_link_annots(fz_context *ctx, pdf_document *, pdf_obj *annots, const fz_matrix *page_ctm); void pdf_annot_transform(fz_context *ctx, pdf_annot *annot, fz_matrix *annot_ctm); |