Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS Outline #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ platform/win32/Release
platform/win32/ReleaseOpenssl
platform/win32/Memento
platform/win32/x64
platform/win32/.vs
3 changes: 3 additions & 0 deletions include/mupdf/fitz/outline.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

down: The outline items immediate children in the hierarchy.
May be NULL if no children exist.
js: javascript action associated with this entry if applicable
*/

typedef struct fz_outline
{
int refs;
Expand All @@ -38,6 +40,7 @@ typedef struct fz_outline
struct fz_outline *next;
struct fz_outline *down;
int is_open;
char* js;
} fz_outline;

/**
Expand Down
3 changes: 3 additions & 0 deletions include/mupdf/fitz/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,10 @@ static inline int fz_peek_byte(fz_context *ctx, fz_stream *stm)

stm: The stream to operate upon.
*/

static inline void fz_unread_byte(fz_context *ctx FZ_UNUSED, fz_stream *stm)
{
ctx = ctx;
stm->rp--;
}

Expand Down Expand Up @@ -525,6 +527,7 @@ static inline unsigned int fz_read_rbits(fz_context *ctx, fz_stream *stm, int n)
*/
static inline void fz_sync_bits(fz_context *ctx FZ_UNUSED, fz_stream *stm)
{
ctx = ctx;
stm->avail = 0;
}

Expand Down
14 changes: 10 additions & 4 deletions source/pdf/pdf-link.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,10 @@ pdf_load_link(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int pagenum, fz
char *uri;
fz_link *link = NULL;

obj = pdf_dict_get(ctx, dict, PDF_NAME(Subtype));
if (!pdf_name_eq(ctx, obj, PDF_NAME(Link)))
return NULL;
// obj = pdf_dict_get(ctx, dict, PDF_NAME(Subtype));
// if (!pdf_name_eq(ctx, obj, PDF_NAME(Link)))

obj = pdf_dict_get(ctx, dict, PDF_NAME(Rect));
obj = pdf_dict_get(ctx, dict, PDF_NAME(Rect));
if (!obj)
return NULL;

Expand All @@ -424,7 +423,14 @@ pdf_load_link(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int pagenum, fz
/* fall back to additional action button's down/up action */
if (!action)
action = pdf_dict_geta(ctx, pdf_dict_get(ctx, dict, PDF_NAME(AA)), PDF_NAME(U), PDF_NAME(D));

uri = pdf_parse_link_action(ctx, doc, action, pagenum);
if (!uri)
{
pdf_obj *dobj = pdf_resolve_indirect(ctx, action);
pdf_obj * js = pdf_dict_get(ctx, dobj, PDF_NAME(JS));
uri = pdf_load_stream_or_string_as_utf8(ctx, js);
}
}

if (!uri)
Expand Down
13 changes: 13 additions & 0 deletions source/pdf/pdf-outline.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ pdf_load_outline_imp(fz_context *ctx, pdf_document *doc, pdf_obj *dict)
obj = pdf_dict_get(ctx, dict, PDF_NAME(Title));
if (obj)
node->title = Memento_label(fz_strdup(ctx, pdf_to_text_string(ctx, obj)), "outline_title");
if ((obj = pdf_dict_get(ctx, dict, PDF_NAME(Next))) != NULL)
{
obj = pdf_resolve_indirect(ctx, obj);
if((obj = pdf_dict_get(ctx, obj, PDF_NAME(Title))) != NULL)
node->uri = Memento_label(fz_strdup(ctx, pdf_to_text_string(ctx, obj)), "outline_title");
}

if ((obj = pdf_dict_get(ctx, dict, PDF_NAME(Dest))) != NULL)
node->uri = Memento_label(pdf_parse_link_dest(ctx, doc, obj), "outline_uri");
else if ((obj = pdf_dict_get(ctx, dict, PDF_NAME(A))) != NULL)
{
node->uri = Memento_label(pdf_parse_link_action(ctx, doc, obj, -1), "outline_uri");
}
else
node->uri = NULL;

Expand All @@ -38,6 +46,11 @@ pdf_load_outline_imp(fz_context *ctx, pdf_document *doc, pdf_obj *dict)
else
node->page = -1;

if ((obj = pdf_dict_get(ctx, obj, PDF_NAME(Next))) != NULL) // insert javascript code if present
{
pdf_obj* js = pdf_dict_get(ctx, obj, PDF_NAME(JS));
node->js = pdf_load_stream_or_string_as_utf8(ctx, js);
}
obj = pdf_dict_get(ctx, dict, PDF_NAME(First));
if (obj)
{
Expand Down
2 changes: 1 addition & 1 deletion source/pdf/pdf-page.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ pdf_load_page_imp(fz_context *ctx, fz_document *doc_, int chapter, int number)
fz_rect page_mediabox;
fz_matrix page_ctm;
pdf_page_transform(ctx, page, &page_mediabox, &page_ctm);
page->links = pdf_load_link_annots(ctx, doc, obj, number, page_ctm);
page->links = pdf_load_link_annots(ctx, doc, obj, number, page_ctm);
pdf_load_annots(ctx, page, obj);
}
}
Expand Down
13 changes: 11 additions & 2 deletions source/tools/pdfshow.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,17 @@ print_outline(fz_outline *outline, int level)
fz_write_byte(ctx, out, '|');

for (i = 0; i < level; i++)
fz_write_byte(ctx, out, '\t');
fz_write_printf(ctx, out, "%Q\t%s\n", outline->title, outline->uri);
fz_write_printf(ctx, out, " ");
fz_write_printf(ctx, out, "%Q %s", outline->title, outline->uri);
if (outline->js)
{
fz_write_printf(ctx, out, " js: %s\n", outline->js);
}
else
{
fz_write_printf(ctx, out, "\n");
}

if (outline->down)
print_outline(outline->down, level + 1);
outline = outline->next;
Expand Down