diff options
author | Denis Bitouzé <dbitouze@wanadoo.fr> | 2021-02-25 18:23:07 +0000 |
---|---|---|
committer | Denis Bitouzé <dbitouze@wanadoo.fr> | 2021-02-25 18:23:07 +0000 |
commit | c6101f91d071883b48b1b4b51e5eba0f36d9a78d (patch) | |
tree | 1bf7f5a881d7a4f5c5bf59d0b2821943dd822372 /Build/source/texk/web2c/luatexdir/pdf | |
parent | 07ee7222e389b0777456b427a55c22d0e6ffd267 (diff) |
French translation for tlmgr updated
git-svn-id: svn://tug.org/texlive/trunk@57912 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/pdf')
45 files changed, 0 insertions, 9823 deletions
diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfaction.c b/Build/source/texk/web2c/luatexdir/pdf/pdfaction.c deleted file mode 100644 index 2909ac6ad74..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfaction.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - -Copyright 2009-2011 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -/*tex Read an action specification. */ - -halfword scan_action(PDF pdf) -{ - int p = new_node(whatsit_node, pdf_action_node); - (void) pdf; - if (scan_keyword("user")) - set_pdf_action_type(p, pdf_action_user); - else if (scan_keyword("goto")) - set_pdf_action_type(p, pdf_action_goto); - else if (scan_keyword("thread")) - set_pdf_action_type(p, pdf_action_thread); - else - normal_error("pdf backend", "action type missing"); - if (pdf_action_type(p) == pdf_action_user) { - scan_toks(false, true); - set_pdf_action_tokens(p, def_ref); - return p; - } - if (scan_keyword("file")) { - scan_toks(false, true); - set_pdf_action_file(p, def_ref); - } - if (scan_keyword("page")) { - if (pdf_action_type(p) != pdf_action_goto) - normal_error("pdf backend", "only GoTo action can be used with 'page'"); - set_pdf_action_type(p, pdf_action_page); - scan_int(); - if (cur_val <= 0) - normal_error("pdf backend", "page number must be positive"); - set_pdf_action_id(p, cur_val); - set_pdf_action_named_id(p, 0); - scan_toks(false, true); - set_pdf_action_tokens(p, def_ref); - } else if (scan_keyword("name")) { - scan_toks(false, true); - set_pdf_action_named_id(p, 1); - set_pdf_action_id(p, def_ref); - } else if (scan_keyword("num")) { - if ((pdf_action_type(p) == pdf_action_goto) && - (pdf_action_file(p) != null)) - normal_error("pdf backend", "'goto' option cannot be used with both 'file' and 'num'"); - scan_int(); - if (cur_val <= 0) - normal_error("pdf backend", "num identifier must be positive"); - set_pdf_action_named_id(p, 0); - set_pdf_action_id(p, cur_val); - } else { - normal_error("pdf backend", "identifier type missing"); - } - if (scan_keyword("newwindow")) { - set_pdf_action_new_window(p, pdf_window_new); - /*tex Scan an optional space. */ - get_x_token(); - if (cur_cmd != spacer_cmd) - back_input(); - } else if (scan_keyword("nonewwindow")) { - set_pdf_action_new_window(p, pdf_window_nonew); - /*tex Scan an optional space. */ - get_x_token(); - if (cur_cmd != spacer_cmd) - back_input(); - } else { - set_pdf_action_new_window(p, pdf_window_notset); - } - if ((pdf_action_new_window(p) > pdf_window_notset) && - (((pdf_action_type(p) != pdf_action_goto) && - (pdf_action_type(p) != pdf_action_page)) || - (pdf_action_file(p) == null))) - normal_error("pdf backend","'newwindow' or 'nonewwindow' must be used with 'goto' and 'file' option"); - return p; -} - -/*tex Write an action specification. */ - -void write_action(PDF pdf, halfword p) -{ - char *s; - int d = 0; - if (pdf_action_type(p) == pdf_action_user) { - pdf_out(pdf, '\n'); - pdf_print_toks(pdf, pdf_action_tokens(p)); - pdf_out(pdf, '\n'); - return; - } - pdf_begin_dict(pdf); - if (pdf_action_file(p) != null) { - pdf_add_name(pdf, "F"); - pdf_out(pdf, ' '); - s = tokenlist_to_cstring(pdf_action_file(p), true, NULL); - pdf_print_str(pdf, s); - xfree(s); - pdf_out(pdf, ' '); - if (pdf_action_new_window(p) > pdf_window_notset) { - if (pdf_action_new_window(p) == pdf_window_new) - pdf_dict_add_bool(pdf, "NewWindow", 1); - else - pdf_dict_add_bool(pdf, "NewWindow", 0); - } - } - switch (pdf_action_type(p)) { - case pdf_action_page: - pdf_dict_add_name(pdf, "S", "GoTo"); - if (pdf_action_file(p) == null) { - pdf_add_name(pdf, "D"); - pdf_begin_array(pdf); - pdf_add_ref(pdf, pdf_get_obj(pdf, obj_type_page, pdf_action_id(p), false)); - } else { - pdf_add_name(pdf, "D"); - pdf_begin_array(pdf); - pdf_print_int(pdf, pdf_action_id(p) - 1); - } - { - char *tokstr = tokenlist_to_cstring(pdf_action_tokens(p), true, NULL); - pdf_printf(pdf, " %s", tokstr); - pdf_end_array(pdf); - xfree(tokstr); - } - break; - case pdf_action_goto: - if (pdf_action_file(p) == null) { - pdf_dict_add_name(pdf, "S", "GoTo"); - d = pdf_get_obj(pdf, obj_type_dest, pdf_action_id(p), pdf_action_named_id(p)); - } else - pdf_dict_add_name(pdf, "S", "GoToR"); - if (pdf_action_named_id(p) > 0) { - char *tokstr = tokenlist_to_cstring(pdf_action_id(p), true, NULL); - pdf_dict_add_string(pdf, "D", tokstr); - xfree(tokstr); - } else if (pdf_action_file(p) == null) { - pdf_dict_add_ref(pdf, "D", d); - } else { - normal_error("pdf backend","'goto' option cannot be used with both 'file' and 'num'"); - } - break; - case pdf_action_thread: - pdf_dict_add_name(pdf, "S", "Thread"); - if (pdf_action_file(p) == null) { - d = pdf_get_obj(pdf, obj_type_thread, pdf_action_id(p), pdf_action_named_id(p)); - if (pdf_action_named_id(p) > 0) { - char *tokstr = tokenlist_to_cstring(pdf_action_id(p), true, NULL); - pdf_dict_add_string(pdf, "D", tokstr); - xfree(tokstr); - } else if (pdf_action_file(p) == null) { - pdf_dict_add_ref(pdf, "D", d); - } else { - pdf_dict_add_int(pdf, "D", pdf_action_id(p)); - } - } - break; - } - pdf_end_dict(pdf); -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfaction.h b/Build/source/texk/web2c/luatexdir/pdf/pdfaction.h deleted file mode 100644 index 3d7751351df..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfaction.h +++ /dev/null @@ -1,54 +0,0 @@ -/* pdfaction.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef PDFACTION_H -# define PDFACTION_H - -/* - Increase count of references to this action. this is used to speed up - copy_node(). -*/ - -# define add_action_ref(a) pdf_action_refcount((a))++ - -/* - Decrease count of references to this action; free it if there is no reference - to this action. -*/ - -# define delete_action_ref(a) { \ - if (pdf_action_refcount(a) == null) { \ - flush_node(a); \ - } else { \ - pdf_action_refcount(a)--; \ - } \ -} - -# define set_pdf_action_type(A,B) pdf_action_type(A)=B -# define set_pdf_action_tokens(A,B) pdf_action_tokens(A)=B -# define set_pdf_action_file(A,B) pdf_action_file(A)=B -# define set_pdf_action_id(A,B) pdf_action_id(A)=B -# define set_pdf_action_named_id(A,B) pdf_action_named_id(A)=B -# define set_pdf_action_new_window(A,B) pdf_action_new_window(A)=B - -extern halfword scan_action(PDF pdf); -extern void write_action(PDF pdf, halfword p); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfannot.c b/Build/source/texk/web2c/luatexdir/pdf/pdfannot.c deleted file mode 100644 index e501947c78f..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfannot.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - -Copyright 2009-2011 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -void do_annot(PDF pdf, halfword p, halfword parent_box, scaledpos cur) -{ - scaled_whd alt_rule; - int k; - if (global_shipping_mode == SHIPPING_FORM) - normal_error("pdf backend", "annotations cannot be inside an xform"); - if (doing_leaders) - return; - if (is_obj_scheduled(pdf, pdf_annot_objnum(p))) { - k = pdf_create_obj(pdf, obj_type_annot, 0); - obj_annot_ptr(pdf, pdf_annot_objnum(p)) = p; - pdf_annot_objnum(p) = k; - } - alt_rule.wd = width(p); - alt_rule.ht = height(p); - alt_rule.dp = depth(p); - set_rect_dimens(pdf, p, parent_box, cur, alt_rule, 0); - obj_annot_ptr(pdf, pdf_annot_objnum(p)) = p; - addto_page_resources(pdf, obj_type_annot, pdf_annot_objnum(p)); -} - -/*tex Create a new whatsit node for annotation. */ - -void new_annot_whatsit(small_number w) -{ - scaled_whd alt_rule; - new_whatsit(w); - alt_rule = scan_alt_rule(); - set_width(tail_par, alt_rule.wd); - set_height(tail_par, alt_rule.ht); - set_depth(tail_par, alt_rule.dp); - if ((w == pdf_thread_node) || (w == pdf_start_thread_node)) { - if (scan_keyword("attr")) { - scan_toks(false, true); - set_pdf_thread_attr(tail_par, def_ref); - } else { - set_pdf_thread_attr(tail_par, null); - } - } -} - -/*tex Scanning at the \TEX\ end: */ - -void scan_annot(PDF pdf) -{ - int k; - if (scan_keyword("reserveobjnum")) { - k = pdf_create_obj(pdf, obj_type_annot, 0); - /*tex Scan an optional space. */ - get_x_token(); - if (cur_cmd != spacer_cmd) - back_input(); - } else { - if (scan_keyword("useobjnum")) { - scan_int(); - k = cur_val; - check_obj_type(pdf, obj_type_annot, k); - if (obj_annot_ptr(pdf, k) != 0) - normal_error("pdf backend", "annot object in use"); - } else { - k = pdf_create_obj(pdf, obj_type_annot, 0); - } - new_annot_whatsit(pdf_annot_node); - obj_annot_ptr(pdf, k) = tail_par; - set_pdf_annot_objnum(tail_par, k); - scan_toks(false, true); - set_pdf_annot_data(tail_par, def_ref); - } - pdf_last_annot = k; -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfannot.h b/Build/source/texk/web2c/luatexdir/pdf/pdfannot.h deleted file mode 100644 index 2c862975db0..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfannot.h +++ /dev/null @@ -1,37 +0,0 @@ -/* pdfannot.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - - -#ifndef PDFANNOT_H -# define PDFANNOT_H - -/* data structure of annotations; words 1..4 represent the coordinates of the annotation */ - -# define obj_annot_ptr obj_aux /* pointer to corresponding whatsit node */ - -# define set_pdf_annot_objnum(A,B) pdf_annot_objnum(A)=B -# define set_pdf_annot_data(A,B) pdf_annot_data(A)=B - -extern void do_annot(PDF pdf, halfword p, halfword parent_box, scaledpos cur); -extern void new_annot_whatsit(small_number w); - -extern void scan_annot(PDF pdf); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.c b/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.c deleted file mode 100644 index fbb88692fe9..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - -Copyright 2009-2011 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -/*tex - - This module implements color stack support. The following array and - especially stack data structures are used. - - \startitemize - \startitem - They automatically grow dynamically. - \stopitem - \startitem - The size never decreases. - \stopitem - \startitem - The variable with name ending in "size" contains the number how many - entries the data structure can hold. - \stopitem - \startitem - The variable with name ending in "used" contains the number of - actually used entries. - \stopitem - \startitem - Memory of strings in stack entries must be allocated and freed if the - stack is cleared. - \stopitem - \stopitemize - -*/ - -#define MAX_COLORSTACKS 32768 - -/* - The colorstack number is stored in two bytes (info field of the node); - condition (newcolorstack): |MAX_COLORSTACKS mod STACK_INCREMENT = 0| -*/ - -#define COLOR_DEFAULT "0 g 0 G" - -typedef struct { - char **page_stack; - char **form_stack; - char *page_current; - char *form_current; - char *form_init; - int page_size; - int form_size; - int page_used; - int form_used; - int literal_mode; - boolean page_start; -} colstack_type; - -static colstack_type *colstacks = NULL; -static int colstacks_size = 0; -static int colstacks_used = 0; - -/*tex - - Initialization is done, if the color stacks are used, |init_colorstacks()| is - defined as macro to avoid unnecessary procedure calls. - -*/ - -#define init_colorstacks() if (colstacks_size == 0) colstacks_first_init(); - -static void colstacks_first_init(void) -{ - colstacks_size = STACK_INCREMENT; - colstacks = xtalloc((unsigned) colstacks_size, colstack_type); - colstacks_used = 1; - colstacks[0].page_stack = NULL; - colstacks[0].form_stack = NULL; - colstacks[0].page_size = 0; - colstacks[0].form_size = 0; - colstacks[0].page_used = 0; - colstacks[0].form_used = 0; - colstacks[0].page_current = xstrdup(COLOR_DEFAULT); - colstacks[0].form_current = xstrdup(COLOR_DEFAULT); - colstacks[0].form_init = xstrdup(COLOR_DEFAULT); - colstacks[0].literal_mode = direct_always; - colstacks[0].page_start = true; -} - -int colorstackused(void) -{ - init_colorstacks(); - return colstacks_used; -} - -/*tex - - A new color stack is setup with the given parameters. The stack number is - returned or -1 in case of error (no room). - -*/ - -int newcolorstack(const char *str, int literal_mode, boolean page_start) -{ - colstack_type *colstack; - int colstack_num; - init_colorstacks(); - /*tex Make room: */ - if (colstacks_used == MAX_COLORSTACKS) { - return -1; - } - if (colstacks_used == colstacks_size) { - colstacks_size += STACK_INCREMENT; - /*tex - If |(MAX_COLORSTACKS mod STACK_INCREMENT = 0)| then we don't - need to check the case that size overruns |MAX_COLORSTACKS|. - */ - colstacks = xreallocarray(colstacks, colstack_type, (unsigned) colstacks_size); - } - /*tex Claim new color stack. */ - colstack_num = colstacks_used++; - colstack = &colstacks[colstack_num]; - /*tex Configure the new color stack. */ - colstack->page_stack = NULL; - colstack->form_stack = NULL; - colstack->page_size = 0; - colstack->page_used = 0; - colstack->form_size = 0; - colstack->form_used = 0; - colstack->literal_mode = literal_mode; - colstack->page_start = page_start; - colstack->page_current = NULL; - colstack->form_current = NULL; - colstack->form_init = NULL; - if (str) { - colstack->page_current = xstrdup(str); - colstack->form_current = xstrdup(str); - colstack->form_init = xstrdup(str); - } - return colstack_num; -} - -#define get_colstack(n) (&colstacks[n]) - -/*tex Put a string on top of the string pool and updates |pool_ptr|. */ - -static void put_cstring_on_str_pool(char *str) -{ - int save_selector = selector; - selector = new_string; - if (str == NULL || *str == 0) { - return; - } - tprint(str); - selector = save_selector; -} - -static int colorstackset(int colstack_no, str_number s) -{ - colstack_type *colstack = get_colstack(colstack_no); - - if (global_shipping_mode == SHIPPING_PAGE) { - xfree(colstack->page_current); - colstack->page_current = makecstring(s); - } else { - xfree(colstack->form_current); - colstack->form_current = makecstring(s); - } - return colstack->literal_mode; -} - -int colorstackcurrent(int colstack_no) -{ - colstack_type *colstack = get_colstack(colstack_no); - - if (global_shipping_mode == SHIPPING_PAGE) { - put_cstring_on_str_pool(colstack->page_current); - } else { - put_cstring_on_str_pool(colstack->form_current); - } - return colstack->literal_mode; -} - -static int colorstackpush(int colstack_no, str_number s) -{ - colstack_type *colstack = get_colstack(colstack_no); - char *str; - if (global_shipping_mode == SHIPPING_PAGE) { - if (colstack->page_used == colstack->page_size) { - colstack->page_size += STACK_INCREMENT; - xretalloc(colstack->page_stack, (unsigned) colstack->page_size, char *); - } - colstack->page_stack[colstack->page_used++] = colstack->page_current; - str = makecstring(s); - if (*str == 0) { - colstack->page_current = NULL; - } else { - colstack->page_current = xstrdup(str); - } - free(str); - } else { - if (colstack->form_used == colstack->form_size) { - colstack->form_size += STACK_INCREMENT; - xretalloc(colstack->form_stack, (unsigned) colstack->form_size, char *); - } - colstack->form_stack[colstack->form_used++] = colstack->form_current; - str = makecstring(s); - if (*str == 0) { - colstack->form_current = NULL; - } else { - colstack->form_current = xstrdup(str); - } - free(str); - } - return colstack->literal_mode; -} - -int colorstackpop(int colstack_no) -{ - colstack_type *colstack = get_colstack(colstack_no); - if (global_shipping_mode == SHIPPING_PAGE) { - if (colstack->page_used == 0) { - formatted_warning("pdf backend","pop empty color page stack %u",(unsigned int) colstack_no); - return colstack->literal_mode; - } - xfree(colstack->page_current); - colstack->page_current = colstack->page_stack[--colstack->page_used]; - put_cstring_on_str_pool(colstack->page_current); - } else { - if (colstack->form_used == 0) { - formatted_warning("pdf backend","pop empty color form stack %u",(unsigned int) colstack_no); - return colstack->literal_mode; - } - xfree(colstack->form_current); - colstack->form_current = colstack->form_stack[--colstack->form_used]; - put_cstring_on_str_pool(colstack->form_current); - } - return colstack->literal_mode; -} - -void colorstackpagestart(void) -{ - int i, j; - colstack_type *colstack; - if (global_shipping_mode == SHIPPING_PAGE) { - return; - } - for (i = 0; i < colstacks_used; i++) { - colstack = &colstacks[i]; - for (j = 0; j < colstack->form_used; j++) { - xfree(colstack->form_stack[j]); - } - colstack->form_used = 0; - xfree(colstack->form_current); - if (colstack->form_init == NULL) { - colstack->form_current = NULL; - } else { - colstack->form_current = xstrdup(colstack->form_init); - } - } -} - -int colorstackskippagestart(int colstack_no) -{ - colstack_type *colstack = get_colstack(colstack_no); - if (!colstack->page_start) { - return 1; - } - if (colstack->page_current == NULL) { - return 0; - } - if (strcmp(COLOR_DEFAULT, colstack->page_current) == 0) { - return 2; - } - return 0; -} - -void pdf_out_colorstack(PDF pdf, halfword p) -{ - int old_setting; - str_number s; - int cmd = pdf_colorstack_cmd(p); - int stack_no = pdf_colorstack_stack(p); - int literal_mode = 0; - if (stack_no >= colorstackused()) { - formatted_warning("pdf backend","color stack %u is not initialized",(unsigned int) stack_no); - return; - } - switch (cmd) { - case colorstack_set: - case colorstack_push: - old_setting = selector; - selector = new_string; - show_token_list(token_link(pdf_colorstack_data(p)), null, -1); - selector = old_setting; - s = make_string(); - if (cmd == colorstack_set) - literal_mode = colorstackset(stack_no, s); - else - literal_mode = colorstackpush(stack_no, s); - if (str_length(s) > 0) - pdf_literal(pdf, s, literal_mode, false); - flush_str(s); - return; - break; - case colorstack_pop: - literal_mode = colorstackpop(stack_no); - break; - case colorstack_current: - literal_mode = colorstackcurrent(stack_no); - break; - default: - break; - } - if (cur_length > 0) { - s = make_string(); - pdf_literal(pdf, s, literal_mode, false); - flush_str(s); - } -} - -void pdf_out_colorstack_startpage(PDF pdf) -{ - int start_status; - int literal_mode; - str_number s; - int i = 0; - int max = colorstackused(); - while (i < max) { - start_status = colorstackskippagestart(i); - if (start_status == 0) { - literal_mode = colorstackcurrent(i); - if (cur_length > 0) { - s = make_string(); - pdf_literal(pdf, s, literal_mode, false); - flush_str(s); - } - } - i++; - } -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.h b/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.h deleted file mode 100644 index dfd955c5e2c..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfcolorstack.h +++ /dev/null @@ -1,41 +0,0 @@ -/* pdfcolorstack.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - - -#ifndef PDFCOLORSTACK_H -# define PDFCOLORSTACK_H - -# define set_pdf_colorstack_stack(A,B) pdf_colorstack_stack(A)=B -# define set_pdf_colorstack_cmd(A,B) pdf_colorstack_cmd(A)=B -# define set_pdf_colorstack_data(A,B) pdf_colorstack_data(A)=B - -# define STACK_INCREMENT 8 - -int newcolorstack(const char *s, int literal_mode, boolean pagestart); -int colorstackused(void); -int colorstackpop(int colstack_no); -int colorstackcurrent(int colstack_no); -int colorstackskippagestart(int colstack_no); -void colorstackpagestart(void); - -extern void pdf_out_colorstack(PDF pdf, halfword p); -extern void pdf_out_colorstack_startpage(PDF pdf); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfdest.c b/Build/source/texk/web2c/luatexdir/pdf/pdfdest.c deleted file mode 100644 index 346cd26e031..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfdest.c +++ /dev/null @@ -1,401 +0,0 @@ -/* - -Copyright 2009-2011 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -/*tex - - Here we implement subroutines for work with objects and related things. Some - of them are used in former parts too, so we need to declare them forward. - Memory will grow dynamically. - -*/ - -void init_dest_names(PDF pdf) -{ - pdf->dest_names_size = inf_dest_names_size; - pdf->dest_names = xmallocarray(dest_name_entry, inf_dest_names_size); -} - -void append_dest_name(PDF pdf, char *s, int n) -{ - int a; - if (pdf->dest_names_ptr == sup_dest_names_size) - overflow("number of destination names (dest_names_size)",(unsigned) pdf->dest_names_size); - if (pdf->dest_names_ptr == pdf->dest_names_size) { - a = pdf->dest_names_size / 5; - if (pdf->dest_names_size < sup_dest_names_size - a) - pdf->dest_names_size = pdf->dest_names_size + a; - else - pdf->dest_names_size = sup_dest_names_size; - pdf->dest_names = xreallocarray(pdf->dest_names, dest_name_entry, (unsigned) pdf->dest_names_size); - } - pdf->dest_names[pdf->dest_names_ptr].objname = xstrdup(s); - pdf->dest_names[pdf->dest_names_ptr].objnum = n; - pdf->dest_names_ptr++; -} - -/*tex - - When a destination is created we need to check whether another destination - with the same identifier already exists and give a warning if needed. - -*/ - -static void warn_dest_dup(int id, small_number byname) -{ - if (byname > 0) { - char *ss = tokenlist_to_cstring(id, true, NULL); - formatted_warning("pdf backend", "ignoring duplicate destination with the name '%s'",ss); - } else { - formatted_warning("pdf backend", "ignoring duplicate destination with the num '%d'",id); - } -} - -void do_dest(PDF pdf, halfword p, halfword parent_box, scaledpos cur) -{ - scaledpos pos = pdf->posstruct->pos; - scaled_whd alt_rule; - int k; - if (global_shipping_mode == SHIPPING_FORM) - normal_error("pdf backend", "destinations cannot be inside an xform"); - if (doing_leaders) - return; - k = pdf_get_obj(pdf, obj_type_dest, pdf_dest_id(p), pdf_dest_named_id(p)); - if (obj_dest_ptr(pdf, k) != null) { - warn_dest_dup(pdf_dest_id(p), (small_number) pdf_dest_named_id(p)); - return; - } - obj_dest_ptr(pdf, k) = p; - addto_page_resources(pdf, obj_type_dest, k); - alt_rule.wd = width(p); - alt_rule.ht = height(p); - alt_rule.dp = depth(p); - /*tex - The different branches for matrixused is somewhat strange and should - always be used - */ - switch (pdf_dest_type(p)) { - case pdf_dest_xyz: - if (matrixused()) - set_rect_dimens(pdf, p, parent_box, cur, alt_rule, pdf_dest_margin); - else { - pdf_ann_left(p) = pos.h; - pdf_ann_top(p) = pos.v; - } - break; - case pdf_dest_fith: - case pdf_dest_fitbh: - if (matrixused()) - set_rect_dimens(pdf, p, parent_box, cur, alt_rule, pdf_dest_margin); - else - pdf_ann_top(p) = pos.v; - break; - case pdf_dest_fitv: - case pdf_dest_fitbv: - if (matrixused()) - set_rect_dimens(pdf, p, parent_box, cur, alt_rule, pdf_dest_margin); - else - pdf_ann_left(p) = pos.h; - break; - case pdf_dest_fit: - case pdf_dest_fitb: - break; - case pdf_dest_fitr: - set_rect_dimens(pdf, p, parent_box, cur, alt_rule, pdf_dest_margin); - } -} - -void write_out_pdf_mark_destinations(PDF pdf) -{ - pdf_object_list *k; - if ((k = get_page_resources_list(pdf, obj_type_dest)) != NULL) { - while (k != NULL) { - if (is_obj_written(pdf, k->info)) { - normal_error("pdf backend","destination has been already written (this shouldn't happen)"); - } else { - int i; - i = obj_dest_ptr(pdf, k->info); - pdf_begin_obj(pdf, k->info, OBJSTM_ALWAYS); - if (pdf_dest_named_id(i) > 0) { - pdf_begin_dict(pdf); - pdf_add_name(pdf, "D"); - } - pdf_begin_array(pdf); - pdf_add_ref(pdf, pdf->last_page); - switch (pdf_dest_type(i)) { - case pdf_dest_xyz: - pdf_add_name(pdf, "XYZ"); - pdf_add_bp(pdf, pdf_ann_left(i)); - pdf_add_bp(pdf, pdf_ann_top(i)); - if (pdf_dest_xyz_zoom(i) == null) { - pdf_add_null(pdf); - } else { - pdf_check_space(pdf); - pdf_print_int(pdf, pdf_dest_xyz_zoom(i) / 1000); - pdf_out(pdf, '.'); - pdf_print_int(pdf, (pdf_dest_xyz_zoom(i) % 1000)); - pdf_set_space(pdf); - } - break; - case pdf_dest_fit: - pdf_add_name(pdf, "Fit"); - break; - case pdf_dest_fith: - pdf_add_name(pdf, "FitH"); - pdf_add_bp(pdf, pdf_ann_top(i)); - break; - case pdf_dest_fitv: - pdf_add_name(pdf, "FitV"); - pdf_add_bp(pdf, pdf_ann_left(i)); - break; - case pdf_dest_fitb: - pdf_add_name(pdf, "FitB"); - break; - case pdf_dest_fitbh: - pdf_add_name(pdf, "FitBH"); - pdf_add_bp(pdf, pdf_ann_top(i)); - break; - case pdf_dest_fitbv: - pdf_add_name(pdf, "FitBV"); - pdf_add_bp(pdf, pdf_ann_left(i)); - break; - case pdf_dest_fitr: - pdf_add_name(pdf, "FitR"); - pdf_add_rect_spec(pdf, i); - break; - default: - normal_error("pdf backend", "unknown dest type"); - break; - } - pdf_end_array(pdf); - if (pdf_dest_named_id(i) > 0) - pdf_end_dict(pdf); - pdf_end_obj(pdf); - } - k = k->link; - } - } -} - -void scan_pdfdest(PDF pdf) -{ - halfword q; - int k; - str_number i; - scaled_whd alt_rule; - q = cur_list.tail_field; - new_whatsit(pdf_dest_node); - if (scan_keyword("num")) { - scan_int(); - if (cur_val <= 0) - normal_error("pdf backend", "num identifier must be positive"); - if (cur_val > max_halfword) - normal_error("pdf backend", "number too big"); - set_pdf_dest_id(cur_list.tail_field, cur_val); - set_pdf_dest_named_id(cur_list.tail_field, 0); - } else if (scan_keyword("name")) { - scan_toks(false, true); - set_pdf_dest_id(cur_list.tail_field, def_ref); - set_pdf_dest_named_id(cur_list.tail_field, 1); - } else { - normal_error("pdf backend", "identifier type missing"); - } - if (scan_keyword("xyz")) { - set_pdf_dest_type(cur_list.tail_field, pdf_dest_xyz); - if (scan_keyword("zoom")) { - scan_int(); - if (cur_val > max_halfword) - normal_error("pdf backend", "number too big"); - set_pdf_dest_xyz_zoom(cur_list.tail_field, cur_val); - } else { - set_pdf_dest_xyz_zoom(cur_list.tail_field, null); - } - } else if (scan_keyword("fitbh")) { - set_pdf_dest_type(cur_list.tail_field, pdf_dest_fitbh); - } else if (scan_keyword("fitbv")) { - set_pdf_dest_type(cur_list.tail_field, pdf_dest_fitbv); - } else if (scan_keyword("fitb")) { - set_pdf_dest_type(cur_list.tail_field, pdf_dest_fitb); - } else if (scan_keyword("fith")) { - set_pdf_dest_type(cur_list.tail_field, pdf_dest_fith); - } else if (scan_keyword("fitv")) { - set_pdf_dest_type(cur_list.tail_field, pdf_dest_fitv); - } else if (scan_keyword("fitr")) { - set_pdf_dest_type(cur_list.tail_field, pdf_dest_fitr); - } else if (scan_keyword("fit")) { - set_pdf_dest_type(cur_list.tail_field, pdf_dest_fit); - } else { - normal_error("pdf backend", "destination type missing"); - } - /*tex Scan an optional space. */ - get_x_token(); - if (cur_cmd != spacer_cmd) - back_input(); - if (pdf_dest_type(cur_list.tail_field) == pdf_dest_fitr) { - alt_rule = scan_alt_rule(); - set_width(cur_list.tail_field, alt_rule.wd); - set_height(cur_list.tail_field, alt_rule.ht); - set_depth(cur_list.tail_field, alt_rule.dp); - } - if (pdf_dest_named_id(cur_list.tail_field) != 0) { - i = tokens_to_string(pdf_dest_id(cur_list.tail_field)); - k = find_obj(pdf, obj_type_dest, i, true); - flush_str(i); - } else { - k = find_obj(pdf, obj_type_dest, pdf_dest_id(cur_list.tail_field), false); - } - if ((k != 0) && (obj_dest_ptr(pdf, k) != null)) { - warn_dest_dup(pdf_dest_id(cur_list.tail_field),(small_number) pdf_dest_named_id(cur_list.tail_field)); - flush_node_list(cur_list.tail_field); - cur_list.tail_field = q; - vlink(q) = null; - } -} - -/*tex Sort |dest_names| by names: */ - -static int dest_cmp(const void *a, const void *b) -{ - dest_name_entry aa = *(const dest_name_entry *) a; - dest_name_entry bb = *(const dest_name_entry *) b; - return strcmp(aa.objname, bb.objname); -} - -void sort_dest_names(PDF pdf) -{ - qsort(pdf->dest_names, (size_t) pdf->dest_names_ptr, sizeof(dest_name_entry), dest_cmp); -} - -/*tex - - Output the name tree. The tree nature of the destination list forces the - storing of intermediate data in |obj_info| and |obj_aux| fields, which is - further uglified by the fact that |obj_tab| entries do not accept char - pointers. - -*/ - -int output_name_tree(PDF pdf) -{ - /*tex A flag for name tree output: is it |/Names| or |/Kids|: */ - boolean is_names = true; - /*tex - The index of current child of |l|; if |k < pdf_dest_names_ptr| then this - is pointer to |dest_names| array; otherwise it is the pointer to - |obj_tab| (object number). - */ - int k = 0; - int b = 0; - int m, j, l; - int dests = 0; - int names_head = 0; - int names_tail = 0; - if (pdf->dest_names_ptr == 0) { - goto DONE; - } - sort_dest_names(pdf); - while (true) { - do { - /*tex Create a new node: */ - l = pdf_create_obj(pdf, obj_type_others, 0); - if (b == 0) { - /*tex First in this level: */ - b = l; - } - if (names_head == 0) { - names_head = l; - names_tail = l; - } else { - set_obj_link(pdf, names_tail, l); - names_tail = l; - } - set_obj_link(pdf, names_tail, 0); - /*tex Output the current node in this level. */ - pdf_begin_obj(pdf, l, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - j = 0; - if (is_names) { - set_obj_start(pdf, l, pdf->dest_names[k].objname); - pdf_add_name(pdf, "Names"); - pdf_begin_array(pdf); - do { - pdf_add_string(pdf, pdf->dest_names[k].objname); - pdf_add_ref(pdf, pdf->dest_names[k].objnum); - j++; - k++; - } while (j != name_tree_kids_max && k != pdf->dest_names_ptr); - pdf_end_array(pdf); - /*tex For later use: */ - set_obj_stop(pdf, l, pdf->dest_names[k - 1].objname); - if (k == pdf->dest_names_ptr) { - is_names = false; - k = names_head; - b = 0; - } - } else { - set_obj_start(pdf, l, obj_start(pdf, k)); - pdf_add_name(pdf, "Kids"); - pdf_begin_array(pdf); - do { - pdf_add_ref(pdf, k); - set_obj_stop(pdf, l, obj_stop(pdf, k)); - k = obj_link(pdf, k); - j++; - } while (j != name_tree_kids_max && k != b - && obj_link(pdf, k) != 0); - pdf_end_array(pdf); - if (k == b) - b = 0; - } - pdf_add_name(pdf, "Limits"); - pdf_begin_array(pdf); - pdf_add_string(pdf, obj_start(pdf, l)); - pdf_add_string(pdf, obj_stop(pdf, l)); - pdf_end_array(pdf); - pdf_end_dict(pdf); - pdf_end_obj(pdf); - } while (b != 0); - if (k == l) { - dests = l; - goto DONE; - } - } - DONE: - if ((dests != 0) || (pdf_names_toks != null)) { - m = pdf_create_obj(pdf, obj_type_others, 0); - pdf_begin_obj(pdf, m, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - if (dests != 0) - pdf_dict_add_ref(pdf, "Dests", dests); - if (pdf_names_toks != null) { - pdf_print_toks(pdf, pdf_names_toks); - delete_token_ref(pdf_names_toks); - pdf_names_toks = null; - } - print_pdf_table_string(pdf, "names"); - pdf_end_dict(pdf); - pdf_end_obj(pdf); - return m; - } else { - return 0; - } -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfdest.h b/Build/source/texk/web2c/luatexdir/pdf/pdfdest.h deleted file mode 100644 index 576baea0434..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfdest.h +++ /dev/null @@ -1,64 +0,0 @@ -/* pdfdest.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - - -#ifndef PDFDEST_H -# define PDFDEST_H - -/* types of destinations */ - -typedef enum { - pdf_dest_xyz = 0, - pdf_dest_fit = 1, - pdf_dest_fith = 2, - pdf_dest_fitv = 3, - pdf_dest_fitb = 4, - pdf_dest_fitbh = 5, - pdf_dest_fitbv = 6, - pdf_dest_fitr = 7 -} pdf_destination_types; - -/* max number of kids for balanced trees */ - -# define name_tree_kids_max 32 /* max number of kids of node of name tree for name destinations */ - -/* data structure of destinations */ - -# define obj_dest_ptr obj_aux /* pointer to |pdf_dest_node| */ -# define set_obj_dest_ptr(pdf,A,B) obj_dest_ptr(pdf,A)=B - -# define set_pdf_dest_id(A,B) pdf_dest_id(A)=B -# define set_pdf_dest_named_id(A,B) pdf_dest_named_id(A)=B -# define set_pdf_dest_type(A,B) pdf_dest_type(A)=B -# define set_pdf_dest_xyz_zoom(A,B) pdf_dest_xyz_zoom(A)=B - -# define inf_dest_names_size 1000 /* min size of the destination names table for PDF output */ -# define sup_dest_names_size 131072 /* max size of the destination names table for PDF output */ - -extern void append_dest_name(PDF, char *, int); -extern void do_dest(PDF pdf, halfword p, halfword parent_box, scaledpos cur); - -extern void write_out_pdf_mark_destinations(PDF); -extern void scan_pdfdest(PDF); -extern void init_dest_names(PDF); -extern void sort_dest_names(PDF); -extern int output_name_tree(PDF); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdffont.c b/Build/source/texk/web2c/luatexdir/pdf/pdffont.c deleted file mode 100644 index 1e1f0f8d9da..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdffont.c +++ /dev/null @@ -1,214 +0,0 @@ -/* - -Copyright 2009-2014 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -/*tex - - As \LUATEX\ should also act as a back-end driver, it needs to support virtual - fonts too. Information about virtual fonts can be found in the source of some - \DVI-related programs. - - Whenever we want to write out a character in a font to \PDF\ output, we - should check whether the used character is a virtual or real character. The - |has_packet| C macro checks for this condition. - - The following code typesets a character to \PDF\ output - -*/ - -scaled_whd output_one_char(PDF pdf, halfword p) -{ - internal_font_number f = font(p); - int c = character(p); - int ex_glyph = ex_glyph(p)/1000; - /*tex The real width, height and depth of the character: */ - scaled_whd ci = get_charinfo_whd(f, c); - if (!(char_exists(f,c))) { - lua_glyph_not_found_callback(f,c); - /*tex Not here |char_warning(f,c);| */ - return ci; - } - ci.wd = ext_xn_over_d(ci.wd, 1000000 + ex_glyph(p), 1000000); - switch (pdf->posstruct->dir) { - case dir_TLT: - break; - case dir_TRT: - pos_left(ci.wd); - break; - case dir_LTL: - pos_down(ci.ht); - pos_left(ci.wd); - break; - case dir_RTT: - pos_down(ci.ht); - pos_left(ci.wd / 2); - break; - default: - formatted_warning("pdf backend","ignoring bad dir %i when outputting a character",pdf->posstruct->dir); - } - if (has_packet(f, c)) { - do_vf_packet(pdf, f, c, ex_glyph); - } else { - backend_out[glyph_node] (pdf, f, c, ex_glyph); - } - return ci; -} - -/*tex - - Mark |f| as a used font; set |font_used(f)|, |font_size(f)| and - |pdf_font_num(f)|. - -*/ - -static void pdf_use_font(internal_font_number f, int fontnum) -{ - set_font_used(f, true); - if ((fontnum > 0) || ((fontnum < 0) && (pdf_font_num(-fontnum) > 0))) { - set_pdf_font_num(f, fontnum); - } else { - normal_error("pdf backend","bad font id"); - } -} - -/*tex - - To set PDF font we need to find out fonts with the same name, because \TeX\ - can load the same font several times for various sizes. For such fonts we - define only one font resource. The array |pdf_font_num| holds the object - number of font resource. A negative value of an entry of |pdf_font_num| - indicates that the corresponding font shares the font resource with the font. - -*/ - -#define same(n,f,k) (n(f) != NULL && n(k) != NULL && strcmp(n(f), n(k)) == 0) - -/*tex - - For some \LUA-loaded (for instance \AFM) fonts, it is normal to have a zero - cidregistry, and such fonts do not have a fontmap entry yet at this point, so - the test should use the other branch. - -*/ - -static boolean font_shareable(internal_font_number f, internal_font_number k) -{ - if (font_cidregistry(f) == NULL && font_cidregistry(k) == NULL && font_encodingbytes(f) != 2 && font_encodingbytes(k) != 2) { - if (font_map(k) != NULL && font_map(f) != NULL && (same(font_name, k, f))) { - return 1; - } - } else if ((same(font_filename, k, f) && same(font_fullname, k, f))) { - return 1; - } - return 0; -} - -/*tex - - We will create a font object. We check whether |f| can share the font object - with some |k|: we have 2 cases here: |f| and |k| have the same tfm name, so - they have been loaded at different sizes, eg 'cmr10' and 'cmr10 at 11pt'. - - We optionally take over slant and extend from map entry, if not already set; - this should also be the only place where getfontmap() may be called. - - Beware, \LUATEX\ is different from \PDFTEX\ in dealing with expanded and - slanted fonts and expansion and protrusion as it will use the same font but a - different transformation which is way more efficient and also cleaner. - -*/ - -void pdf_init_font(PDF pdf, internal_font_number f) -{ - internal_font_number k; - fm_entry *fm; - int i, l; - if (font_used(f)) { - formatted_error("pdf backend","font %i gets initialized twice",(int) f); - } - fm = getfontmap(font_name(f)); - if (font_map(f) == NULL && fm != NULL) { - font_map(f) = fm; - if (is_slantset(fm)) - font_slant(f) = fm->slant; - if (is_extendset(fm)) - font_extend(f) = fm->extend; - } - i = pdf->head_tab[obj_type_font]; - while (i != 0) { - k = obj_info(pdf, i); - if (font_shareable(f, k)) { - if (pdf_font_num(k) < 0) - pdf_use_font(f, pdf_font_num(k)); - else - pdf_use_font(f, -k); - return; - } - i = obj_link(pdf, i); - } - /*tex Create a new font object for |f|: */ - l = pdf_create_obj(pdf, obj_type_font, f); - pdf_use_font(f, l); -} - -/*tex - - Set the actual font on PDF page; sets |ff| to the tfm number of the base font - sharing the font object with |f|; |ff| is either |f| itself (then it is its - own base font), or some font with the same tfm name at different size and/or - expansion. - -*/ - -internal_font_number pdf_set_font(PDF pdf, internal_font_number f) -{ - /*tex For use with |set_ff|: */ - int ff; - if (!font_used(f)) - pdf_init_font(pdf, f); - /*tex Also known as |set_ff(f)|: */ - ff = pdf_font_num(f) < 0 ? -pdf_font_num(f) : f; - addto_page_resources(pdf, obj_type_font, pdf_font_num(ff)); - return ff; -} - -void pdf_include_chars(PDF pdf) -{ - str_number s; - unsigned char *k, *j; - internal_font_number f; - scan_font_ident(); - f = cur_val; - if (f == null_font) - normal_error("pdf backend", "invalid font identifier for 'includechars'"); - /* pdf_check_vf(c); */ - if (!font_used(f)) - pdf_init_font(pdf, f); - scan_toks(false, true); - s = tokens_to_string(def_ref); - delete_token_ref(def_ref); - j = str_string(s) + str_length(s); - for (k = str_string(s); k < j; k++) { - pdf_mark_char(f, *k); - } - flush_str(s); -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdffont.h b/Build/source/texk/web2c/luatexdir/pdf/pdffont.h deleted file mode 100644 index 47f987dd685..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdffont.h +++ /dev/null @@ -1,30 +0,0 @@ -/* pdffont.h - - Copyright 2010-2013 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - - -#ifndef PDFFONT_H -# define PDFFONT_H - -extern scaled_whd output_one_char(PDF pdf, halfword p); -extern void pdf_init_font(PDF pdf, internal_font_number f); -extern internal_font_number pdf_set_font(PDF pdf, internal_font_number f); -extern void pdf_include_chars(PDF); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfgen.c b/Build/source/texk/web2c/luatexdir/pdf/pdfgen.c deleted file mode 100644 index ce610cb4925..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfgen.c +++ /dev/null @@ -1,2569 +0,0 @@ -/* - -Copyright 2009-2013 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -#include <kpathsea/c-dir.h> -#include <kpathsea/c-ctype.h> -#include "lua/luatex-api.h" -#include "md5.h" - -#define check_nprintf(size_get, size_want) \ - if ((unsigned)(size_get) >= (unsigned)(size_want)) \ - formatted_error("pdf backend","snprintf() failed in file %s at line %d", __FILE__, __LINE__); - -PDF static_pdf = NULL; - -/*tex The commandline interface: */ - -int output_mode_used; -int output_mode_option; -int output_mode_value; -int draft_mode_option; -int draft_mode_value; - -/*tex Additional keys of the |/Info| dictionary: */ - -halfword pdf_info_toks; - -/*tex Additional keys of the |/Catalog| and its |/OpenAction| dictionary: */ - -halfword pdf_catalog_toks; - -halfword pdf_catalog_openaction; - -/*tex Additional keys of the |/Names| dictionary: */ - -halfword pdf_names_toks; - -/*tex Additional keys of the |/Trailer| dictionary" */ - -halfword pdf_trailer_toks; - -/*tex Set to |shipping_mode| when |ship_out| starts */ - -shipping_mode_e global_shipping_mode = NOT_SHIPPING; - -/*tex - - Create a new buffer |strbuf_s| of size |size| and maximum allowed size - |limit|. Initialize it and set |p| to begin of data. - -*/ - -strbuf_s *new_strbuf(size_t size, size_t limit) -{ - strbuf_s *b; - b = xtalloc(1, strbuf_s); - b->size = size; - b->limit = limit; - if (size > 0) { - b->p = b->data = xtalloc(b->size, unsigned char); - } else { - /*tex For other alloc: */ - b->p = b->data = NULL; - } - return b; -} - -/*tex Check that |n| bytes more fit into buffer; increase it if required. */ - -static void strbuf_room(strbuf_s * b, size_t n) -{ - unsigned int a; - size_t l = (size_t) (b->p - b->data); - if (n > b->limit - l) - overflow("PDF buffer", (unsigned) b->size); - if (n + l > b->size) { - a = (unsigned int) (b->size >> 2); - if (n + l > b->size + a) - b->size = n + l; - else if (b->size < b->limit - a) - b->size = b->size + a; - else - b->size = b->limit; - b->data = xreallocarray(b->data, unsigned char, (unsigned) b->size); - b->p = b->data + l; - } -} - -/*tex Seek to position |offset| within buffer. Position must be valid. */ - -void strbuf_seek(strbuf_s * b, off_t offset) -{ - b->p = b->data + offset; -} - -/*tex Get the current buffer fill level, the number of characters.*/ - -size_t strbuf_offset(strbuf_s * b) -{ - return (size_t) (b->p - b->data); -} - -/*tex Put one character into buffer. Make room before if needed. */ - -void strbuf_putchar(strbuf_s * b, unsigned char c) -{ - if ((size_t) (b->p - b->data + 1) > b->size) - strbuf_room(b, 1); - *b->p++ = c; -} - -/*tex Dump filled buffer part to the \PDF\ file. */ - -void strbuf_flush(PDF pdf, strbuf_s * b) -{ - pdf_out_block(pdf, (const char *) b->data, strbuf_offset(b)); - strbuf_seek(b, 0); -} - -/*tex We free all dynamically allocated buffer structures. */ - -void strbuf_free(strbuf_s * b) -{ - xfree(b->data); - xfree(b); -} - -/*tex This |init_pdf_struct| is called early and only once. */ - -PDF init_pdf_struct(PDF pdf) -{ - os_struct *os; - pdf = xtalloc(1, pdf_output_file); - memset(pdf, 0, sizeof(pdf_output_file)); - pdf->job_name = makecstring(job_name); - /*tex This will be set by |fix_o_mode|: */ - output_mode_used = OMODE_NONE; - /*tex Used by synctex, we need to use output_mode_used there. */ - pdf->o_mode = output_mode_used; - pdf->o_state = ST_INITIAL; - /*tex Initialize \PDF\ and object stream writing */ - pdf->os = os = xtalloc(1, os_struct); - memset(pdf->os, 0, sizeof(os_struct)); - os->buf[PDFOUT_BUF] = new_strbuf(inf_pdfout_buf_size, sup_pdfout_buf_size); - os->buf[OBJSTM_BUF] = new_strbuf(inf_objstm_buf_size, sup_objstm_buf_size); - os->obj = xtalloc(PDF_OS_MAX_OBJS, os_obj_data); - os->cur_objstm = 0; - os->curbuf = PDFOUT_BUF; - pdf->buf = os->buf[os->curbuf]; - /*tex - Later ttf_seek_outbuf(TABDIR_OFF + n * 4 * TTF_ULONG_SIZE); in - ttf_init_font we need 236 bytes, so we start with 256 bytes as in \PDFTEX. - */ - pdf->fb = new_strbuf(256, 100000000); - pdf->stream_deflate = false; - pdf->stream_writing = false; - /*tex - Sometimes it is neccesary to allocate memory for PDF output that cannot be - deallocated then, so we use |mem| for this purpose. - */ - pdf->mem_size = inf_pdf_mem_size; - pdf->mem = xtalloc(pdf->mem_size, int); - /*tex - The first word is not used so we can use zero as a value for testing - whether a pointer to |mem| is valid. - */ - pdf->mem_ptr = 1; - pdf->pstruct = NULL; - pdf->posstruct = xtalloc(1, posstructure); - pdf->posstruct->pos.h = 0; - pdf->posstruct->pos.v = 0; - pdf->posstruct->dir = dir_TLT; - /*tex Allocated size of |obj_tab| array> */ - pdf->obj_tab_size = (unsigned) inf_obj_tab_size; - pdf->obj_tab = xtalloc(pdf->obj_tab_size + 1, obj_entry); - memset(pdf->obj_tab, 0, sizeof(obj_entry)); - pdf->minor_version = -1; - pdf->major_version = -1; - pdf->decimal_digits = 4; - pdf->gamma = 65536; - pdf->image_gamma = 65536; - pdf->image_hicolor = 1; - pdf->image_apply_gamma = 0; - pdf->objcompresslevel = 0; - pdf->compress_level = 0; - pdf->force_file = 0; - pdf->recompress = 0; - pdf->draftmode = 0; - pdf->inclusion_copy_font = 1; - pdf->pk_resolution = 0; - pdf->pk_fixed_dpi = 0; - pdf->pk_scale_factor = 0; - init_dest_names(pdf); - pdf->page_resources = NULL; - init_pdf_pagecalculations(pdf); - pdf->vfstruct = new_vfstruct(); - return pdf; -} - -/*tex We use |pdf_get_mem| to allocate memory in |mem|. */ - -int pdf_get_mem(PDF pdf, int s) -{ - int a; - int ret; - if (s > sup_pdf_mem_size - pdf->mem_ptr) - overflow("pdf memory size (pdf_mem_size)", (unsigned) pdf->mem_size); - if (pdf->mem_ptr + s > pdf->mem_size) { - a = pdf->mem_size >> 2; - if (pdf->mem_ptr + s > pdf->mem_size + a) { - pdf->mem_size = pdf->mem_ptr + s; - } else if (pdf->mem_size < sup_pdf_mem_size - a) { - pdf->mem_size = pdf->mem_size + a; - } else { - pdf->mem_size = sup_pdf_mem_size; - } - pdf->mem = xreallocarray(pdf->mem, int, (unsigned) pdf->mem_size); - } - ret = pdf->mem_ptr; - pdf->mem_ptr = pdf->mem_ptr + s; - return ret; -} - -/*tex - - This ensures that |pdfmajorversion| and |pdfminorversion| are set only before - any bytes have been written to the generated \PDF\ file. Here also all - variables for \PDF\ output are initialized, the \PDF\ file is opened by - |ensure_pdf_open|, and the \PDF\ header is written. - -*/ - -void fix_pdf_version(PDF pdf) -{ - if (pdf->major_version < 0) { - /*tex It is unset. */ - if (pdf_major_version == 0) { - normal_warning("pdf backend","unset major version, using 1 instead"); - pdf->major_version = 1; - } else if ((pdf_major_version < 0) || (pdf_major_version > 2)) { - formatted_warning("pdf backend","illegal major version %d, using 1 instead",pdf_major_version); - pdf->major_version = 1; - } else { - pdf->major_version = pdf_major_version; - } - } else if (pdf->major_version != pdf_major_version) { - normal_warning("pdf backend", "the major version cannot be changed after data is written to the PDF file"); - } - if (pdf->minor_version < 0) { - /*tex It is unset. */ - if ((pdf_minor_version < 0) || (pdf_minor_version > 9)) { - formatted_warning("pdf backend","illegal minor version %d, using 4 instead",pdf_minor_version); - pdf->minor_version = 4; - } else { - pdf->minor_version = pdf_minor_version; - } - } else if (pdf->minor_version != pdf_minor_version) { - normal_warning("pdf backend", "minorversion cannot be changed after data is written to the PDF file"); - } -} - -static void fix_pdf_draftmode(PDF pdf) -{ - if (pdf->draftmode != draft_mode_par) - normal_warning("pdf backend", "draftmode cannot be changed after data is written to the PDF file"); - if (pdf->draftmode != 0) { - /*tex Fix these as they might have been changed in between. */ - pdf->compress_level = 0; - pdf->objcompresslevel = 0; - } -} - -#define ZIP_BUF_SIZE 32768 - -#define check_err(f, fn) \ - if (f != Z_OK) \ - formatted_error("pdf backend","zlib %s() failed (error code %d)", fn, f) - -static void write_zip(PDF pdf) -{ - int flush, err = Z_OK; - uInt zip_len; - strbuf_s *buf = pdf->buf; - z_stream *s = pdf->c_stream; - boolean finish = pdf->zip_write_state == ZIP_FINISH; - if (pdf->stream_length == 0) { - if (s == NULL) { - s = pdf->c_stream = xtalloc(1, z_stream); - s->zalloc = (alloc_func) 0; - s->zfree = (free_func) 0; - s->opaque = (voidpf) 0; - check_err(deflateInit(s, pdf->compress_level), "deflateInit"); - pdf->zipbuf = xtalloc(ZIP_BUF_SIZE, char); - } else - check_err(deflateReset(s), "deflateReset"); - s->next_out = (Bytef *) pdf->zipbuf; - s->avail_out = ZIP_BUF_SIZE; - } - s->next_in = buf->data; - s->avail_in = (uInt) (buf->p - buf->data); - while (true) { - if (s->avail_out == 0 || (finish && s->avail_out < ZIP_BUF_SIZE)) { - zip_len = ZIP_BUF_SIZE - s->avail_out; - pdf->gone += (off_t) xfwrite(pdf->zipbuf, 1, zip_len, pdf->file); - pdf->last_byte = pdf->zipbuf[zip_len - 1]; - s->next_out = (Bytef *) pdf->zipbuf; - s->avail_out = ZIP_BUF_SIZE; - } - if (finish) { - if (err == Z_STREAM_END) { - xfflush(pdf->file); - pdf->zip_write_state = NO_ZIP; - break; - } - flush = Z_FINISH; - } else { - if (s->avail_in == 0) - break; - flush = Z_NO_FLUSH; - } - err = deflate(s, flush); - if (err != Z_OK && err != Z_STREAM_END) - formatted_error("pdf backend","zlib deflate() failed (error code %d)", err); - } - pdf->stream_length = (off_t) s->total_out; -} - -void zip_free(PDF pdf) -{ - if (pdf->zipbuf != NULL) { - check_err(deflateEnd(pdf->c_stream), "deflateEnd"); - xfree(pdf->zipbuf); - } - xfree(pdf->c_stream); -} - -static void write_nozip(PDF pdf) -{ - strbuf_s *buf = pdf->buf; - size_t l = strbuf_offset(buf); - if (l == 0) - return; - pdf->stream_length = pdf_offset(pdf) - pdf->save_offset; - pdf->gone += (off_t) xfwrite((char *) buf->data, sizeof(char), l, pdf->file); - pdf->last_byte = *(buf->p - 1); -} - -/*tex - - The PDF buffer is flushed by calling |pdf_flush|, which checks the variable - |zip_write_state| and will compress the buffer before flushing if neccesary. - We call |pdf_begin_stream| to begin a stream and |pdf_end_stream| to finish - it. The stream contents will be compressed if compression is turn on. - -*/ - -void pdf_flush(PDF pdf) -{ - os_struct *os = pdf->os; - off_t saved_pdf_gone = pdf->gone; - switch (os->curbuf) { - case PDFOUT_BUF: - if (pdf->draftmode == 0) { - switch (pdf->zip_write_state) { - case NO_ZIP: - write_nozip(pdf); - break; - case ZIP_WRITING: - case ZIP_FINISH: - write_zip(pdf); - break; - default: - normal_error("pdf backend", "bad zip state"); - } - } else - pdf->zip_write_state = NO_ZIP; - strbuf_seek(pdf->buf, 0); - if (saved_pdf_gone > pdf->gone) - normal_error("pdf backend", "file size exceeds architectural limits (pdf_gone wraps around)"); - break; - case OBJSTM_BUF: - break; - default: - normal_error("pdf backend", "bad buffer state"); - } -} - -static void pdf_buffer_select(PDF pdf, buffer_e buf) -{ - os_struct *os = pdf->os; - if (pdf->os_enable && buf == OBJSTM_BUF) { - /*tex Switch to object stream: */ - os->curbuf = OBJSTM_BUF; - } else { - /*tex Switch to \PDF\ stream: */ - os->curbuf = PDFOUT_BUF; - } - pdf->buf = os->buf[pdf->os->curbuf]; -} - -/*tex - - We create new |/ObjStm| object if required, and set up cross reference info. - -*/ - -static void pdf_prepare_obj(PDF pdf, int k, int pdf_os_threshold) -{ - os_struct *os = pdf->os; - strbuf_s *obuf = os->buf[OBJSTM_BUF]; - if (pdf->objcompresslevel >= pdf_os_threshold) - pdf_buffer_select(pdf, OBJSTM_BUF); - else - pdf_buffer_select(pdf, PDFOUT_BUF); - switch (os->curbuf) { - case PDFOUT_BUF: - obj_offset(pdf, k) = pdf_offset(pdf); - /*tex Mark it as not included in any |ObjStm|. */ - obj_os_idx(pdf, k) = PDF_OS_MAX_OBJS; - break; - case OBJSTM_BUF: - if (os->cur_objstm == 0) { - os->cur_objstm = - (unsigned int) pdf_create_obj(pdf, obj_type_objstm, 0); - os->idx = 0; - /*tex Start a fresh object stream. */ - obuf->p = obuf->data; - /*tex Keep some statistics. */ - os->ostm_ctr++; - } - obj_os_idx(pdf, k) = (int) os->idx; - obj_os_objnum(pdf, k) = (int) os->cur_objstm; - os->obj[os->idx].num = k; - os->obj[os->idx].off = obuf->p - obuf->data; - break; - default: - normal_error("pdf backend", "bad object state"); - } -} - -/*tex - - We set the active buffer pointer and make sure that there are at least |n| - bytes free in that buffer, flushing happens if needed. - -*/ - -inline void pdf_room(PDF pdf, int n) -{ - strbuf_s *buf = pdf->buf; - if ((size_t) (n + buf->p - buf->data) <= buf->size) - return; - if (pdf->os->curbuf == PDFOUT_BUF) { - if ((size_t) n > buf->size) - overflow("PDF output buffer", (unsigned) buf->size); - if ((size_t) (n + buf->p - buf->data) < buf->limit) - strbuf_room(buf, (size_t) n); - else - pdf_flush(pdf); - } else { - strbuf_room(buf, (size_t) n); - } -} - -void pdf_out_block(PDF pdf, const char *s, size_t n) -{ - size_t l; - strbuf_s *buf = pdf->buf; - do { - l = n; - if (l > buf->size) - l = buf->size; - pdf_room(pdf, (int) l); - (void) memcpy(buf->p, s, l); - buf->p += l; - s += l; - n -= l; - } while (n > 0); -} - -__attribute__ ((format(printf, 2, 3))) -void pdf_printf(PDF pdf, const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - if (pdf->printf_buf == NULL) { - pdf->printf_buf = xtalloc(PRINTF_BUF_SIZE, char); - } - (void) vsnprintf(pdf->printf_buf, PRINTF_BUF_SIZE, fmt, args); - pdf_puts(pdf, pdf->printf_buf); - va_end(args); -} - -void pdf_print(PDF pdf, str_number s) -{ - const char *ss; - size_t l; - if (s >= STRING_OFFSET) { - ss = (const char *) str_string(s); - l = str_length(s); - pdf_out_block(pdf, ss, l); - } else { - pdf_out(pdf, s); - } -} - -void pdf_print_int(PDF pdf, longinteger n) -{ - char s[24]; - int w; - w = snprintf(s, 23, "%" LONGINTEGER_PRI "d", (LONGINTEGER_TYPE) n); - check_nprintf(w, 23); - pdf_out_block(pdf, (const char *) s, (size_t) w); -} - -void print_pdffloat(PDF pdf, pdffloat f) -{ - int64_t m = f.m; - if (m == 0) { - pdf_out(pdf, '0'); - } else { - int e = f.e; - if (e == 0) { - /*tex division by |ten_pow[0] == 1| */ - if (m == 1) { - pdf_out(pdf, '1'); - } else { - char a[24]; - snprintf(a, 23, "%" LONGINTEGER_PRI "i", (LONGINTEGER_TYPE) m); - pdf_puts(pdf, a); - } - } else { - int t = ten_pow[e] ; - if (t == m) { - pdf_out(pdf, '1'); - } else { - int i, l, w; - char a[24]; - if (m < 0) { - pdf_out(pdf, '-'); - m *= -1; - } - l = m / t; - w = snprintf(a, 23, "%i", l); - pdf_out_block(pdf, (const char *) a, (size_t) w); - l = m % t; - if (l != 0) { - pdf_out(pdf, '.'); - snprintf(a, 23, "%d", l + t); - for (i = e; i > 0; i--) { - if (a[i] != '0') - break; - a[i] = '\0'; - } - pdf_puts(pdf, (a + 1)); - } - } - } - } -} - -void pdf_print_str(PDF pdf, const char *s) -{ - const char *orig = s; - /*tex This initializes at the last string index. */ - int l = (int) strlen(s) - 1; - if (l < 0) { - pdf_puts(pdf, "()"); - return; - } - /*tex - The next might not really be safe as the string could be ``(a)xx(b)'' but - so far we never had an issue. - */ - if ((s[0] == '(') && (s[l] == ')')) { - pdf_puts(pdf, s); - return; - } - if ((s[0] != '<') || (s[l] != '>') || odd((l + 1))) { - pdf_out(pdf, '('); - pdf_puts(pdf, s); - pdf_out(pdf, ')'); - return; - } - s++; - while (isxdigit((unsigned char)*s)) - s++; - if (s != orig + l) { - pdf_out(pdf, '('); - pdf_puts(pdf, orig); - pdf_out(pdf, ')'); - return; - } - pdf_puts(pdf, orig); -} - -/*tex A stream needs to have a stream dictionary also. */ - -void pdf_begin_stream(PDF pdf) -{ - pdf_puts(pdf, "\nstream\n"); - pdf_save_offset(pdf); - pdf_flush(pdf); - if (pdf->stream_deflate) { - pdf->zip_write_state = ZIP_WRITING; - } - pdf->stream_writing = true; - pdf->stream_length = 0; - pdf->last_byte = 0; -} - -void pdf_end_stream(PDF pdf) -{ - os_struct *os = pdf->os; - switch (os->curbuf) { - case PDFOUT_BUF: - if (pdf->zip_write_state == ZIP_WRITING) - pdf->zip_write_state = ZIP_FINISH; - /*tex This sets| pdf->last_byte|. */ - pdf_flush(pdf); - break; - case OBJSTM_BUF: - normal_error("pdf backend", "bad buffer in end stream, case 1"); - break; - default: - normal_error("pdf backend", "bad buffer in end stream, case 2"); - } - pdf->stream_deflate = false; - pdf->stream_writing = false; - /*tex This doesn't really belong to the stream: */ - pdf_out(pdf, '\n'); - pdf_puts(pdf, "endstream"); - /*tex Write the stream |/Length|. */ - - if (pdf->seek_write_length && pdf->draftmode == 0) { - xfseeko(pdf->file, (off_t)pdf->stream_length_offset+12, SEEK_SET, pdf->job_name); - fprintf(pdf->file, " "); - xfseeko(pdf->file, (off_t)pdf->stream_length_offset, SEEK_SET, pdf->job_name); - fprintf(pdf->file, "%" LONGINTEGER_PRI "i >>", (LONGINTEGER_TYPE) pdf->stream_length); - xfseeko(pdf->file, 0, SEEK_END, pdf->job_name); - } - pdf->seek_write_length = false; -} - -/*tex - - To print |scaled| value to \PDF\ output we need some subroutines to ensure - accurary. - -*/ - - -/*tex We max out at $2^{31}-1$. */ - -#define max_integer 0x7FFFFFFF - -/*tex scaled value corresponds to 100in, exact, 473628672 */ - -scaled one_hundred_inch = 7227 * 65536; - -/*tex scaled value corresponds to 1in (rounded to 4736287) */ - -scaled one_inch = (7227 * 65536 + 50) / 100; - -/*tex scaled value corresponds to 1truein (rounded!) */ - -scaled one_true_inch = (7227 * 65536 + 50) / 100; - -/*tex scaled value corresponds to 100bp */ - -scaled one_hundred_bp = (7227 * 65536) / 72; - -/*tex scaled value corresponds to 1bp (rounded to 65782) */ - -scaled one_bp = 65781; - -/*tex - - One basepoint is set to exactly 65781, as in \TEX\ itself, because this value - is also used for |\pdfpxdimen|. - -*/ - -int ten_pow[10] = { - 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 /* $10^0..10^9$ */ -}; - -/*tex - - The function |divide_scaled| divides |s| by |m| using |dd| decimal digits of - precision. - -*/ - -scaled round_xn_over_d(scaled x, int n, unsigned int d) -{ - boolean positive = true; - unsigned t, u, v; - if (x < 0) { - positive = !positive; - x = -(x); - } - if (n < 0) { - positive = !positive; - n = -(n); - } - t = (unsigned) ((x % 0100000) * n); - u = (unsigned) (((unsigned) (x) / 0100000) * (unsigned) n + (t / 0100000)); - v = (u % d) * 0100000 + (t % 0100000); - if (u / d >= 0100000) - arith_error = true; - else - u = 0100000 * (u / d) + (v / d); - v = v % d; - if (2 * v >= d) - u++; - if (positive) - return (scaled) u; - else - return (-(scaled) u); -} - -void pdf_add_bp(PDF pdf, scaled s) -{ - pdffloat a; - pdfstructure *p = pdf->pstruct; - a.m = i64round(s * p->k1); - a.e = pdf->decimal_digits; - pdf_check_space(pdf); - print_pdffloat(pdf, a); - pdf_set_space(pdf); -} - -typedef struct { - int obj_type; - pdf_object_list *list; -} pr_entry; - -static int comp_page_resources(const void *pa, const void *pb, void *p) -{ - int a = ((const pr_entry *) pa)->obj_type; - int b = ((const pr_entry *) pb)->obj_type; - (void) p; - if (a > b) - return 1; - if (a < b) - return -1; - return 0; -} - -void addto_page_resources(PDF pdf, pdf_obj_type t, int k) -{ - pdf_resource_struct *re; - pr_entry *pr, tmp; - void **pp; - pdf_object_list *p, *item = NULL; - re = pdf->page_resources; - if (re->resources_tree == NULL) { - re->resources_tree = avl_create(comp_page_resources, NULL, &avl_xallocator); - if (re->resources_tree == NULL) - formatted_error("pdf backend","addto_page_resources(): avl_create() page_resource_tree failed"); - } - tmp.obj_type = t; - pr = (pr_entry *) avl_find(re->resources_tree, &tmp); - if (pr == NULL) { - pr = xtalloc(1, pr_entry); - pr->obj_type = t; - pr->list = NULL; - pp = avl_probe(re->resources_tree, pr); - if (pp == NULL) - formatted_error("pdf backend","addto_page_resources(): avl_probe() out of memory in insertion"); - } - if (pr->list == NULL) { - item = xtalloc(1, pdf_object_list); - item->link = NULL; - item->info = k; - pr->list = item; - if (obj_type(pdf, k) == (int)t) { - /*tex |k| is an object number. */ - set_obj_scheduled(pdf, k); - } - } else { - for (p = pr->list; p->info != k && p->link != NULL; p = p->link); - if (p->info != k) { - item = xtalloc(1, pdf_object_list); - item->link = NULL; - item->info = k; - p->link = item; - if (obj_type(pdf, k) == (int)t) - set_obj_scheduled(pdf, k); - } - } -} - -pdf_object_list *get_page_resources_list(PDF pdf, pdf_obj_type t) -{ - pdf_resource_struct *re = pdf->page_resources; - pr_entry *pr, tmp; - if (re == NULL || re->resources_tree == NULL) - return NULL; - tmp.obj_type = t; - pr = (pr_entry *) avl_find(re->resources_tree, &tmp); - if (pr == NULL) - return NULL; - return pr->list; -} - -static void reset_page_resources(PDF pdf) -{ - pdf_resource_struct *re = pdf->page_resources; - pr_entry *p; - struct avl_traverser t; - pdf_object_list *l1, *l2; - if (re == NULL || re->resources_tree == NULL) - return; - avl_t_init(&t, re->resources_tree); - for (p = avl_t_first(&t, re->resources_tree); p != NULL; p = avl_t_next(&t)) { - if (p->list != NULL) { - for (l1 = p->list; l1 != NULL; l1 = l2) { - l2 = l1->link; - free(l1); - } - /*tex We reset but the AVL tree remains! */ - p->list = NULL; - } - } -} - -static void destroy_pg_res_tree(void *pa, void *param) -{ - (void) param; - xfree(pa); -} - -static void destroy_page_resources_tree(PDF pdf) -{ - pdf_resource_struct *re = pdf->page_resources; - reset_page_resources(pdf); - if (re->resources_tree != NULL) - avl_destroy(re->resources_tree, destroy_pg_res_tree); - re->resources_tree = NULL; -} - -static void pdf_print_fw_int(PDF pdf, longinteger n) -{ - unsigned char digits[11]; - - int k = 10; - do { - k--; - digits[k] = (unsigned char) ('0' + (n % 10)); - n /= 10; - } while (k != 0); - if (n!=0) { - /*tex The absolute value of $n$ is greater than 9999999999. */ - normal_error("pdf backend", "offset exceeds 10 bytes, try enabling object compression."); - } - digits[10]='\0'; - pdf_puts(pdf, (const char *) digits); -} - -/*tex - - We print out an integer |n| as a fixed number |w| of bytes,. This is used in - the |XRef| cross-reference stream creator. - -*/ - -static void pdf_out_bytes(PDF pdf, longinteger n, size_t w) -{ - /*tex The number of digits in a number being output. */ - unsigned char bytes[8]; - int k = (int) w; - do { - k--; - bytes[k] = (unsigned char) (n % 256); - n /= 256; - } while (k != 0); - pdf_out_block(pdf, (const char *) bytes, w); -} - -void pdf_print_str_ln(PDF pdf, const char *s) -{ - pdf_print_str(pdf, s); - pdf_out(pdf, '\n'); -} - -void pdf_print_toks(PDF pdf, halfword p) -{ - int len = 0; - char *s = tokenlist_to_cstring(p, true, &len); - if (len > 0) { - pdf_check_space(pdf); - pdf_puts(pdf, s); - pdf_set_space(pdf); - } - xfree(s); -} - -/* -void pdf_add_rect_spec(PDF pdf, halfword r) -{ - pdf_add_bp(pdf, pdf_ann_left(r)); - pdf_add_bp(pdf, pdf_ann_bottom(r)); - pdf_add_bp(pdf, pdf_ann_right(r)); - pdf_add_bp(pdf, pdf_ann_top(r)); -} -*/ - -void pdf_add_rect_spec(PDF pdf, halfword r) -{ - /* the check is now here */ - pdf_add_bp(pdf, pdf_ann_left(r) < pdf_ann_right(r) ? pdf_ann_left(r) : pdf_ann_right(r)); - pdf_add_bp(pdf, pdf_ann_bottom(r) < pdf_ann_top(r) ? pdf_ann_bottom(r) : pdf_ann_top(r)); - pdf_add_bp(pdf, pdf_ann_left(r) < pdf_ann_right(r) ? pdf_ann_right(r) : pdf_ann_left(r)); - pdf_add_bp(pdf, pdf_ann_bottom(r) < pdf_ann_top(r) ? pdf_ann_top(r) : pdf_ann_bottom(r)); -} - -void pdf_rectangle(PDF pdf, halfword r) -{ - pdf_add_name(pdf, "Rect"); - pdf_begin_array(pdf); - pdf_add_rect_spec(pdf, r); - pdf_end_array(pdf); -} - -static void init_pdf_outputparameters(PDF pdf) -{ - int pk_mode; - pdf->draftmode = fix_int(draft_mode_par, 0, 1); - pdf->compress_level = fix_int(pdf_compress_level, 0, 9); - pdf->decimal_digits = fix_int(pdf_decimal_digits, 3, 5); - pdf->gamma = fix_int(pdf_gamma, 0, 1000000); - pdf->image_gamma = fix_int(pdf_image_gamma, 0, 1000000); - pdf->image_hicolor = fix_int(pdf_image_hicolor, 0, 1); - pdf->image_apply_gamma = fix_int(pdf_image_apply_gamma, 0, 1); - pdf->objcompresslevel = fix_int(pdf_obj_compress_level, 0, MAX_OBJ_COMPRESS_LEVEL); - pdf->recompress = fix_int(pdf_recompress, 0, 1); - pdf->inclusion_copy_font = fix_int(pdf_inclusion_copy_font, 0, 1); - pdf->pk_resolution = fix_int(pdf_pk_resolution, 72, 8000); - pdf->pk_fixed_dpi = fix_int(pdf_pk_fixed_dpi, 0, 1); - if (((pdf->major_version > 1) || (pdf->minor_version >= 5)) && (pdf->objcompresslevel > 0)) { - pdf->os_enable = true; - } else { - if (pdf->objcompresslevel > 0) { - normal_warning("pdf backend","objcompresslevel > 0 requires minorversion > 4"); - pdf->objcompresslevel = 0; - } - pdf->os_enable = false; - } - if (pdf->pk_resolution == 0) { - /*tex If not set from format file or by user take it from \.{texmf.cnf}. */ - pdf->pk_resolution = pk_dpi; - } - pdf->pk_scale_factor = divide_scaled(72, pdf->pk_resolution, pk_decimal_digits(pdf,5)); - if (!callback_defined(read_pk_file_callback)) { - pk_mode = pdf_pk_mode; - if (pk_mode != null) { - char *s = tokenlist_to_cstring(pk_mode, true, NULL); - kpse_init_prog("LUATEX", (unsigned) pdf->pk_resolution, s, nil); - xfree(s); - } else { - kpse_init_prog("LUATEX", (unsigned) pdf->pk_resolution, nil, nil); - } - if (!kpse_var_value("MKTEXPK")) - kpse_set_program_enabled(kpse_pk_format, 1, kpse_src_cmdline); - } - set_job_id(pdf, year_par, month_par, day_par, time_par); - if ((pdf_unique_resname > 0) && (pdf->resname_prefix == NULL)) - pdf->resname_prefix = get_resname_prefix(pdf); -} - -/*tex - - This checks that we have a name for the generated PDF file and that it's - open. - -*/ - -void pdf_write_header(PDF pdf) -{ - /*tex Initialize variables for \PDF\ output. */ - fix_pdf_version(pdf); - init_pdf_outputparameters(pdf); - fix_pdf_draftmode(pdf); - /*tex Write \PDF\ header */ - pdf_printf(pdf, "%%PDF-%d.%d\n", pdf->major_version, pdf->minor_version); - /* Some binary crap. */ - pdf_out(pdf, '%'); - pdf_out(pdf, 'L' + 128); - pdf_out(pdf, 'U' + 128); - pdf_out(pdf, 'A' + 128); - pdf_out(pdf, 'T' + 128); - pdf_out(pdf, 'E' + 128); - pdf_out(pdf, 'X' + 128); - pdf_out(pdf, 'P' + 128); - pdf_out(pdf, 'D' + 128); - pdf_out(pdf, 'F' + 128); - pdf_out(pdf, '\n'); -} - -void pdf_open_file(PDF pdf) { - ensure_output_file_open(pdf, ".pdf"); -} - -void ensure_output_state(PDF pdf, output_state s) -{ - if (pdf->o_state < s) { - if (s > ST_INITIAL) { - ensure_output_state(pdf, s - 1); - } - switch (s - 1) { - case ST_INITIAL: - fix_o_mode(); - break; - case ST_OMODE_FIX: - backend_out_control[backend_control_open_file](pdf); - break; - case ST_FILE_OPEN: - backend_out_control[backend_control_write_header](pdf); - break; - case ST_HEADER_WRITTEN: - break; - case ST_FILE_CLOSED: - break; - default: - normal_error("pdf backend","weird output state"); - } - pdf->o_state++; - } -} - -/*tex - - Write out an accumulated object stream. The object number and byte offset - pairs are generated and appended to the ready buffered object stream. By this - the value of \.{/First} can be calculated. Then a new \.{/ObjStm} object is - generated, and everything is copied to the PDF output buffer, where also - compression is done. When calling this procedure, |pdf_os_mode| must be - |true|. - -*/ - -static void pdf_os_write_objstream(PDF pdf) -{ - os_struct *os = pdf->os; - /*tex |n1|, |n2|: |ObjStm| buffer may be reallocated! */ - unsigned int i, j, n1, n2; - strbuf_s *obuf = os->buf[OBJSTM_BUF]; - if (os->cur_objstm == 0) { - /*tex No object stream started. */ - return; - } - /*tex Remember end of collected object stream contents. */ - n1 = (unsigned int) strbuf_offset(obuf); - /*tex This is needed here to calculate |/First| for the |ObjStm| dict */ - for (i = 0, j = 0; i < os->idx; i++) { - /*tex Add object-number/byte-offset list to buffer. */ - pdf_print_int(pdf, (int) os->obj[i].num); - pdf_out(pdf, ' '); - pdf_print_int(pdf, (int) os->obj[i].off); - if (j == 9 || i == os->idx - 1) { - /*tex Print out in groups of ten for better readability. */ - pdf_out(pdf, '\n'); - j = 0; - } else { - pdf_out(pdf, ' '); - j++; - } - } - /*tex Remember current buffer end. */ - n2 = (unsigned int) strbuf_offset(obuf); - /*tex Switch to \PDF\ stream writing. */ - pdf_begin_obj(pdf, (int) os->cur_objstm, OBJSTM_NEVER); - pdf_begin_dict(pdf); - pdf_dict_add_name(pdf, "Type", "ObjStm"); - /*tex The number of objects in |ObjStm|. */ - pdf_dict_add_int(pdf, "N", (int) os->idx); - pdf_dict_add_int(pdf, "First", (int) (n2 - n1)); - pdf_dict_add_streaminfo(pdf); - pdf_end_dict(pdf); - pdf_begin_stream(pdf); - /*tex Write object-number/byte-offset list. */ - pdf_out_block(pdf, (const char *) (obuf->data + n1), (size_t) (n2 - n1)); - /*tex Write collected object stream contents. */ - pdf_out_block(pdf, (const char *) obuf->data, (size_t) n1); - pdf_end_stream(pdf); - pdf_end_obj(pdf); - /*tex We force object stream generation next time. */ - os->cur_objstm = 0; -} - -/*tex Here comes a bunch of flushers: */ - -void pdf_begin_dict(PDF pdf) -{ - pdf_check_space(pdf); - pdf_puts(pdf, "<<"); - pdf_set_space(pdf); -} - -void pdf_end_dict(PDF pdf) -{ - pdf_check_space(pdf); - pdf_puts(pdf, ">>"); - pdf_set_space(pdf); -} - -void pdf_dict_add_bool(PDF pdf, const char *key, int i) -{ - pdf_add_name(pdf, key); - pdf_add_bool(pdf, i); -} - -void pdf_dict_add_int(PDF pdf, const char *key, int i) -{ - pdf_add_name(pdf, key); - pdf_add_int(pdf, i); -} - -void pdf_dict_add_name(PDF pdf, const char *key, const char *val) -{ - pdf_add_name(pdf, key); - pdf_add_name(pdf, val); -} - -void pdf_dict_add_string(PDF pdf, const char *key, const char *val) -{ - if (val == NULL) - return; - pdf_add_name(pdf, key); - pdf_check_space(pdf); - pdf_print_str(pdf, val); - pdf_set_space(pdf); -} - -void pdf_dict_add_ref(PDF pdf, const char *key, int num) -{ - pdf_add_name(pdf, key); - pdf_add_ref(pdf, num); -} - -void pdf_add_null(PDF pdf) -{ - pdf_check_space(pdf); - pdf_puts(pdf, "null"); - pdf_set_space(pdf); -} - -void pdf_add_bool(PDF pdf, int i) -{ - pdf_check_space(pdf); - if (i == 0) - pdf_puts(pdf, "false"); - else - pdf_puts(pdf, "true"); - pdf_set_space(pdf); -} - -void pdf_add_int(PDF pdf, int i) -{ - pdf_check_space(pdf); - pdf_print_int(pdf, i); - pdf_set_space(pdf); -} - -void pdf_add_longint(PDF pdf, longinteger n) -{ - pdf_check_space(pdf); - pdf_print_int(pdf, n); - pdf_set_space(pdf); -} - -void pdf_add_string(PDF pdf, const char *s) -{ - pdf_check_space(pdf); - pdf_print_str(pdf, s); - pdf_set_space(pdf); -} - -void pdf_add_name(PDF pdf, const char *name) -{ - pdf_check_space(pdf); - pdf_out(pdf, '/'); - pdf_puts(pdf, name); - pdf_set_space(pdf); -} - -void pdf_add_ref(PDF pdf, int num) -{ - pdf_check_space(pdf); - pdf_print_int(pdf, num); - pdf_puts(pdf, " 0 R"); - pdf_set_space(pdf); -} - -/*tex - - When we add the stream length and filter entries to a stream dictionary, - remember file position for seek. - -*/ - -void pdf_dict_add_streaminfo(PDF pdf) -{ - if (pdf->compress_level > 0) { - pdf_dict_add_name(pdf, "Filter", "FlateDecode"); - pdf->stream_deflate = true; - } - pdf_add_name(pdf, "Length"); - pdf->stream_length_offset = pdf_offset(pdf) + 1; - /*tex Fill in length at |pdf_end_stream| call. */ - pdf->seek_write_length = true; - /*tex We reserve space for 10 decimal digits plus space. */ - pdf_puts(pdf, " x "); - pdf_set_space(pdf); -} - -void pdf_begin_array(PDF pdf) -{ - pdf_check_space(pdf); - pdf_out(pdf, '['); - pdf_set_space(pdf); -} - -void pdf_end_array(PDF pdf) -{ - pdf_check_space(pdf); - pdf_out(pdf, ']'); - pdf_set_space(pdf); -} - -void pdf_begin_obj(PDF pdf, int i, int pdf_os_threshold) -{ - os_struct *os = pdf->os; - ensure_output_state(pdf, ST_HEADER_WRITTEN); - pdf_prepare_obj(pdf, i, pdf_os_threshold); - switch (os->curbuf) { - case PDFOUT_BUF: - pdf_printf(pdf, "%d 0 obj\n", (int) i); - break; - case OBJSTM_BUF: - if (pdf->compress_level == 0) { - /*tex Some debugging help. */ - pdf_printf(pdf, "%% %d 0 obj\n", (int) i); - } - break; - default: - normal_error("pdf backend","weird begin object"); - } - pdf_reset_space(pdf); -} - -void pdf_end_obj(PDF pdf) -{ - os_struct *os = pdf->os; - switch (os->curbuf) { - case PDFOUT_BUF: - /*tex End a \PDF\ object. */ - pdf_puts(pdf, "\nendobj\n"); - break; - case OBJSTM_BUF: - /*tex Tthe number of objects collected so far in ObjStm: */ - os->idx++; - /*tex Only for statistics: */ - os->o_ctr++; - if (os->idx == PDF_OS_MAX_OBJS) { - pdf_os_write_objstream(pdf); - } else { - /*tex Adobe Reader seems to need this. */ - pdf_out(pdf, '\n'); - } - break; - default: - normal_error("pdf backend","weird end object"); - } -} - -/* - Needed for embedding fonts. - -*/ - -pdf_obj *pdf_new_stream(void) -{ - pdf_obj *stream = xmalloc(sizeof(pdf_obj)); - stream->length = 0; - stream->data = NULL; - return stream; -} - -void pdf_add_stream(pdf_obj * stream, unsigned char *buf, long len) -{ - int i; - assert(stream != NULL); - if (stream->data == NULL) { - stream->data = xmalloc((unsigned) len); - } else { - stream->data = - xrealloc(stream->data, (unsigned) len + (unsigned) stream->length); - } - for (i = 0; i < len; i++) { - *(stream->data + stream->length + i) = *(buf + i); - } - stream->length += (unsigned) len; -} - -void pdf_release_obj(pdf_obj * stream) -{ - if (stream != NULL) { - if (stream->data != NULL) { - xfree(stream->data); - } - xfree(stream); - } -} - -/* - - This one converts any string given in in in an allowed PDF string which can - be handled by printf et.al.: \.{\\} is escaped to \.{\\\\}, parenthesis are - escaped and control characters are octal encoded. This assumes that the - string does not contain any already escaped characters! - -*/ - -char *convertStringToPDFString(const char *in, int len) -{ - static char pstrbuf[MAX_PSTRING_LEN]; - char *out = pstrbuf; - int i, j, k; - char buf[5]; - j = 0; - for (i = 0; i < len; i++) { - check_buf((unsigned) j + sizeof(buf), MAX_PSTRING_LEN); - if (((unsigned char) in[i] < '!') || ((unsigned char) in[i] > '~')) { - /*tex Convert control characters into octal. */ - k = snprintf(buf, sizeof(buf), "\\%03o", (unsigned int) (unsigned char) in[i]); - check_nprintf(k, sizeof(buf)); - out[j++] = buf[0]; - out[j++] = buf[1]; - out[j++] = buf[2]; - out[j++] = buf[3]; - } else if ((in[i] == '(') || (in[i] == ')')) { - /*tex Escape parenthesis: */ - out[j++] = '\\'; - out[j++] = in[i]; - } else if (in[i] == '\\') { - /*tex Escape backslash: */ - out[j++] = '\\'; - out[j++] = '\\'; - } else { - /* Copy char : */ - out[j++] = in[i]; - } - } - out[j] = '\0'; - return pstrbuf; -} - -/*tex - - This one converts any string given in in in an allowed PDF string which is - hexadecimal encoded; |sizeof(out)| should be at least $|lin|*2+1$. - -*/ - -static void convertStringToHexString(const char *in, char *out, int lin) -{ - int i, k; - char buf[3]; - int j = 0; - for (i = 0; i < lin; i++) { - k = snprintf(buf, sizeof(buf), "%02X", (unsigned int) (unsigned char) in[i]); - check_nprintf(k, sizeof(buf)); - out[j++] = buf[0]; - out[j++] = buf[1]; - } - out[j] = '\0'; -} - -/*tex - - We compute the ID string as per PDF specification 1.4 9.3 that stipulates - only that the two IDs must be identical when the file is created and that - they should be reasonably unique. Since it's difficult to get the file size - at this point in the execution of pdfTeX and scanning the info dict is also - difficult, we start with a simpler implementation using just the first two - items. - - A user supplied trailerid had better be an array! So maybe we need to check - for |[]| and error otherwise. - -*/ - -static void print_ID(PDF pdf) -{ - if ((pdf_suppress_optional_info & 512) == 0) { - const char *p = NULL; - pdf_add_name(pdf, "ID"); - p = get_pdf_table_string("trailerid"); - if (p && strlen(p) > 0) { - pdf_puts(pdf,p); - } else if (pdf_trailer_id != 0) { - /*tex The user provided one: */ - pdf_print_toks(pdf, pdf_trailer_id); - } else { - /*tex The system provided one: */ - time_t t; - size_t size; - char time_str[32]; - md5_state_t state; - md5_byte_t digest[16]; - char id[64]; - char pwd[4096]; - md5_init(&state); - t = pdf->start_time; - size = strftime(time_str, sizeof(time_str), "%Y%m%dT%H%M%SZ", gmtime(&t)); - md5_append(&state, (const md5_byte_t *) time_str, (int) size); - if (getcwd(pwd, sizeof(pwd)) == NULL) { - formatted_error("pdf backend","getcwd() failed (%s), (path too long?)", strerror(errno)); - } -#ifdef WIN32 - { - char *p; - for (p = pwd; *p; p++) { - if (*p == '\\') - *p = '/'; - else if (IS_KANJI(p)) - p++; - } - } -#endif - md5_append(&state, (const md5_byte_t *) pwd, (int) strlen(pwd)); - md5_append(&state, (const md5_byte_t *) "/", 1); - md5_append(&state, (const md5_byte_t *) pdf->file_name, (int) strlen(pdf->file_name)); - md5_finish(&state, digest); - convertStringToHexString((char *) digest, id, 16); - pdf_begin_array(pdf); - pdf_check_space(pdf); - pdf_printf(pdf, "<%s> <%s>", id, id); - pdf_set_space(pdf); - pdf_end_array(pdf); - } - } -} - -/*tex - - Here we print the |/CreationDate| entry in the form - |(D:YYYYMMDDHHmmSSOHH'mm')|. The main difficulty is get the time zone offset. - |strftime()| does this in ISO C99 (e.g. newer glibc) with \%z, but we have to - work with other systems (e.g. Solaris 2.5). - -*/ - -#define TIME_STR_SIZE 30 - -static void makepdftime(PDF pdf) -{ - struct tm lt, gmt; - size_t size; - int i, off, off_hours, off_mins; - time_t t = pdf->start_time; - char *time_str = pdf->start_time_str; - /*tex Get the time. */ - if (utc_option) { - lt = *gmtime(&t); - } else { - lt = *localtime(&t); - } - size = strftime(time_str, TIME_STR_SIZE, "D:%Y%m%d%H%M%S", <); - /*tex Expected format: |YYYYmmddHHMMSS|. */ - if (size == 0) { - /*tex Unexpected, contents of |time_str| is undefined .*/ - time_str[0] = '\0'; - return; - } - /*tex - A correction for seconds. the PDF reference expects 00..59, therefore we - map 60 and 61 to 59. - */ - if (time_str[14] == '6') { - time_str[14] = '5'; - time_str[15] = '9'; - /*tex For safety: */ - time_str[16] = '\0'; - } - /*tex Get the time zone offset. */ - gmt = *gmtime(&t); - off = 60 * (lt.tm_hour - gmt.tm_hour) + lt.tm_min - gmt.tm_min; - if (lt.tm_year != gmt.tm_year) { - off += (lt.tm_year > gmt.tm_year) ? 1440 : -1440; - } else if (lt.tm_yday != gmt.tm_yday) { - off += (lt.tm_yday > gmt.tm_yday) ? 1440 : -1440; - } - if (off == 0) { - time_str[size++] = 'Z'; - time_str[size] = 0; - } else { - off_hours = off / 60; - off_mins = abs(off - off_hours * 60); - i = snprintf(&time_str[size], 9, "%+03d'%02d'", off_hours, off_mins); - check_nprintf(i, 9); - } - pdf->start_time = t; -} - -void initialize_start_time(PDF pdf) -{ - if (pdf->start_time == 0) { - pdf->start_time = get_start_time(); - pdf->start_time_str = xtalloc(TIME_STR_SIZE, char); - makepdftime(pdf); - } -} - -char *getcreationdate(PDF pdf) -{ - initialize_start_time(pdf); - return pdf->start_time_str; -} - -void remove_pdffile(PDF pdf) -{ - if (pdf != NULL) { - if (!kpathsea_debug && pdf->file_name && (pdf->draftmode == 0)) { - xfclose(pdf->file, pdf->file_name); - remove(pdf->file_name); - } - } -} - -/*tex We use this checker in other modules. It is not pdf specific. */ - -void check_o_mode(PDF pdf, const char *s, int o_mode_bitpattern, boolean strict) -{ - - output_mode o_mode; - const char *m = NULL; - if (lua_only) { - normal_error("lua only","no backend present, needed for what you asked for"); - return ; - } - if (output_mode_used == OMODE_NONE) - o_mode = get_o_mode(); - else - o_mode = output_mode_used; - /*tex This is used by synctex, we need to use output_mode_used there. */ - pdf->o_mode = output_mode_used; - if (!((1 << o_mode) & o_mode_bitpattern)) { - switch (o_mode) { - case OMODE_DVI: - m = "DVI"; - break; - case OMODE_PDF: - m = "PDF"; - break; - default: - normal_error("pdf backend","weird output state"); - } - if (strict) - formatted_error("pdf backend", "%s not allowed in %s mode (outputmode = %d)",s, m, (int) output_mode_par); - else - formatted_warning("pdf backend", "%s not allowed in %s mode (outputmode = %d)",s, m, (int) output_mode_par); - } else if (strict) - ensure_output_state(pdf, ST_HEADER_WRITTEN); -} - -void ensure_output_file_open(PDF pdf, const char *ext) -{ - char *fn; - if (pdf->file_name != NULL) - return; - if (job_name == 0) - open_log_file(); - fn = pack_job_name(ext); - if (pdf->draftmode == 0 || output_mode_used == OMODE_DVI) { - while (!lua_b_open_out(&pdf->file, fn)) - fn = prompt_file_name("file name for output", ext); - } - pdf->file_name = fn; -} - -/*tex till here */ - -void set_job_id(PDF pdf, int year, int month, int day, int time) -{ - char *name_string, *format_string, *s; - size_t slen; - int i; - if (pdf->job_id_string != NULL) - return; - name_string = makecstring(job_name); - format_string = makecstring(format_ident); - slen = SMALL_BUF_SIZE + strlen(name_string) + strlen(format_string) + strlen(luatex_banner); - s = xtalloc(slen, char); - /*tex The \WEBC\ version string starts with a space. (Really?) */ - i = snprintf(s, slen, "%.4d/%.2d/%.2d %.2d:%.2d %s %s %s", year, month, day, time / 60, time % 60, name_string, format_string, luatex_banner); - check_nprintf(i, slen); - pdf->job_id_string = xstrdup(s); - xfree(s); - xfree(name_string); - xfree(format_string); -} - -char *get_resname_prefix(PDF pdf) -{ - static char name_str[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - /*tex We make a tag of 6 characters long. */ - static char prefix[7]; - short i; - size_t base = strlen(name_str); - unsigned long crc = crc32(0L, Z_NULL, 0); - crc = crc32(crc, (Bytef *) pdf->job_id_string, (uInt) strlen(pdf->job_id_string)); - for (i = 0; i < 6; i++) { - prefix[i] = name_str[crc % base]; - crc /= base; - } - prefix[6] = '\0'; - return prefix; -} - -void pdf_begin_page(PDF pdf) -{ - int xform_attributes; - int xform_type = 0; - scaled form_margin = pdf_xform_margin; - ensure_output_state(pdf, ST_HEADER_WRITTEN); - init_pdf_pagecalculations(pdf); - if (pdf->page_resources == NULL) { - pdf->page_resources = xtalloc(1, pdf_resource_struct); - pdf->page_resources->resources_tree = NULL; - } - pdf->page_resources->last_resources = pdf_create_obj(pdf, obj_type_others, 0); - reset_page_resources(pdf); - - if (global_shipping_mode == SHIPPING_PAGE) { - pdf->last_page = pdf_get_obj(pdf, obj_type_page, total_pages + 1, 0); - /*tex Mark that this page has been created. */ - set_obj_aux(pdf, pdf->last_page, 1); - pdf->last_stream = pdf_create_obj(pdf, obj_type_pagestream, 0); - pdf_begin_obj(pdf, pdf->last_stream, OBJSTM_NEVER); - pdf->last_thread = null; - pdf_begin_dict(pdf); - } else { - xform_type = obj_xform_type(pdf, pdf_cur_form) ; - pdf_begin_obj(pdf, pdf_cur_form, OBJSTM_NEVER); - pdf->last_stream = pdf_cur_form; - /*tex Write out the |Form| stream header */ - pdf_begin_dict(pdf); - if (xform_type == 0) { - pdf_dict_add_name(pdf, "Type", "XObject"); - pdf_dict_add_name(pdf, "Subtype", "Form"); - pdf_dict_add_int(pdf, "FormType", 1); - } - xform_attributes = pdf_xform_attr; - /*tex Now stored in the object: */ - form_margin = obj_xform_margin(pdf, pdf_cur_form); - if (xform_attributes != null) - pdf_print_toks(pdf, xform_attributes); - if (obj_xform_attr(pdf, pdf_cur_form) != null) { - pdf_print_toks(pdf, obj_xform_attr(pdf, pdf_cur_form)); - delete_token_ref(obj_xform_attr(pdf, pdf_cur_form)); - set_obj_xform_attr(pdf, pdf_cur_form, null); - } - if (obj_xform_attr_str(pdf, pdf_cur_form) != null) { - lua_pdf_literal(pdf, obj_xform_attr_str(pdf, pdf_cur_form),1); - luaL_unref(Luas, LUA_REGISTRYINDEX, obj_xform_attr_str(pdf, pdf_cur_form)); - set_obj_xform_attr_str(pdf, pdf_cur_form, null); - } - if (xform_type == 0 || xform_type == 1 || xform_type == 3) { - pdf_add_name(pdf, "BBox"); - pdf_begin_array(pdf); - pdf_add_bp(pdf, -form_margin); - pdf_add_bp(pdf, -form_margin); - pdf_add_bp(pdf, pdf->page_size.h + form_margin); - pdf_add_bp(pdf, pdf->page_size.v + form_margin); - pdf_end_array(pdf); - } - if (xform_type == 0 || xform_type == 2 || xform_type == 3) { - pdf_add_name(pdf, "Matrix"); - pdf_begin_array(pdf); - pdf_add_int(pdf, 1); - pdf_add_int(pdf, 0); - pdf_add_int(pdf, 0); - pdf_add_int(pdf, 1); - pdf_add_int(pdf, 0); - pdf_add_int(pdf, 0); - pdf_end_array(pdf); - } - pdf_dict_add_ref(pdf, "Resources", pdf->page_resources->last_resources); - } - /*tex Start a stream of page or form contents: */ - pdf_dict_add_streaminfo(pdf); - pdf_end_dict(pdf); - pdf_begin_stream(pdf); - /*tex Start with an empty stack: */ - pos_stack_used = 0; - if (global_shipping_mode == SHIPPING_PAGE) { - colorstackpagestart(); - } - if (global_shipping_mode == SHIPPING_PAGE) - pdf_out_colorstack_startpage(pdf); -} - -void print_pdf_table_string(PDF pdf, const char *s) -{ - size_t len; - const char *ls; - lua_rawgeti(Luas, LUA_REGISTRYINDEX, lua_key_index(pdf_data)); - lua_rawget(Luas, LUA_REGISTRYINDEX); - lua_pushstring(Luas, s); - lua_rawget(Luas, -2); - if (lua_type(Luas, -1) == LUA_TSTRING) { - ls = lua_tolstring(Luas, -1, &len); - if (len > 0) { - pdf_check_space(pdf); - pdf_out_block(pdf, ls, len); - pdf_set_space(pdf); - } - } - lua_pop(Luas, 2); -} - -const char *get_pdf_table_string(const char *s) -{ - const_lstring ls; - lua_rawgeti(Luas, LUA_REGISTRYINDEX, lua_key_index(pdf_data)); - lua_rawget(Luas, LUA_REGISTRYINDEX); - lua_pushstring(Luas, s); - lua_rawget(Luas, -2); - if (lua_type(Luas, -1) == LUA_TSTRING) { - ls.s = lua_tolstring(Luas, -1, &ls.l); - /*tex - Here |s| is supposed to be anchored (e.g.\ in the registry) so it's - not garbage collected. - */ - lua_pop(Luas, 2); - return ls.s; - } - lua_pop(Luas, 2); - return NULL ; -} - -void pdf_end_page(PDF pdf) -{ - char s[64], *p; - int j, annots = 0, beads = 0, callback_id; - pdf_resource_struct *res_p = pdf->page_resources; - pdf_resource_struct local_page_resources; - pdf_object_list *annot_list, *bead_list, *link_list, *ol, *ol1; - /*tex We save |pdf->page_size| during flushing pending forms: */ - scaledpos save_cur_page_size; - shipping_mode_e save_shipping_mode; - int save_pdf_cur_form; - int xform_resources; - int page_resources, page_attributes; - int procset = PROCSET_PDF; - /*tex Finish the stream of page or form contents: */ - pdf_goto_pagemode(pdf); - if (pos_stack_used > 0) { - formatted_error("pdf backend","%u unmatched 'save' after %s shipout", (unsigned int) pos_stack_used, - ((global_shipping_mode == SHIPPING_PAGE) ? "page" : "form")); - } - pdf_end_stream(pdf); - pdf_end_obj(pdf); - callback_id = callback_defined(finish_pdfpage_callback); - if (callback_id > 0) - run_callback(callback_id, "b->",(global_shipping_mode == SHIPPING_PAGE)); - if (global_shipping_mode == SHIPPING_PAGE) { - int location = 0; - int callback_id = callback_defined(page_order_index_callback); - if (callback_id) { - run_callback(callback_id, "d->d", total_pages, &location); - } - pdf->last_pages = pdf_do_page_divert(pdf, pdf->last_page, location); - /*tex Write out the |/Page| object. */ - pdf_begin_obj(pdf, pdf->last_page, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - pdf_dict_add_name(pdf, "Type", "Page"); - pdf_dict_add_ref(pdf, "Contents", pdf->last_stream); - pdf_dict_add_ref(pdf, "Resources", res_p->last_resources); - pdf_add_name(pdf, "MediaBox"); - pdf_begin_array(pdf); - pdf_add_int(pdf, 0); - pdf_add_int(pdf, 0); - pdf_add_bp(pdf, pdf->page_size.h); - pdf_add_bp(pdf, pdf->page_size.v); - pdf_end_array(pdf); - page_attributes = pdf_page_attr ; - if (page_attributes != null) - pdf_print_toks(pdf, page_attributes); - print_pdf_table_string(pdf, "pageattributes"); - pdf_dict_add_ref(pdf, "Parent", pdf->last_pages); - if (pdf->img_page_group_val != 0) { - pdf_dict_add_ref(pdf, "Group", pdf->img_page_group_val); - } - annot_list = get_page_resources_list(pdf, obj_type_annot); - link_list = get_page_resources_list(pdf, obj_type_link); - if (annot_list != NULL || link_list != NULL) { - annots = pdf_create_obj(pdf, obj_type_annots, 0); - pdf_dict_add_ref(pdf, "Annots", annots); - } - bead_list = get_page_resources_list(pdf, obj_type_bead); - if (bead_list != NULL) { - beads = pdf_create_obj(pdf, obj_type_beads, 0); - pdf_dict_add_ref(pdf, "B", beads); - } - pdf_end_dict(pdf); - pdf_end_obj(pdf); - pdf->img_page_group_val = 0; - /*tex Generate an array of annotations or beads in page. */ - if (annot_list != NULL || link_list != NULL) { - pdf_begin_obj(pdf, annots, OBJSTM_ALWAYS); - pdf_begin_array(pdf); - while (annot_list != NULL) { - pdf_add_ref(pdf, annot_list->info); - annot_list = annot_list->link; - } - while (link_list != NULL) { - pdf_add_ref(pdf, link_list->info); - link_list = link_list->link; - } - pdf_end_array(pdf); - pdf_end_obj(pdf); - } - if (bead_list != NULL) { - pdf_begin_obj(pdf, beads, OBJSTM_ALWAYS); - pdf_begin_array(pdf); - while (bead_list != NULL) { - pdf_add_ref(pdf, bead_list->info); - bead_list = bead_list->link; - } - pdf_end_array(pdf); - pdf_end_obj(pdf); - } - } - /*tex Write out the resource lists and pending raw objects. */ - ol = get_page_resources_list(pdf, obj_type_obj); - while (ol != NULL) { - if (!is_obj_written(pdf, ol->info)) - pdf_write_obj(pdf, ol->info); - ol = ol->link; - } - /*tex - When flushing pending forms we need to save and restore resource lists - which are also used by page shipping. Saving and restoring - |pdf->page_size| is needed for proper writing out pending \PDF\ marks. - */ - ol = get_page_resources_list(pdf, obj_type_xform); - while (ol != NULL) { - if (!is_obj_written(pdf, ol->info)) { - save_pdf_cur_form = pdf_cur_form; - pdf_cur_form = ol->info; - save_cur_page_size = pdf->page_size; - save_shipping_mode = global_shipping_mode; - pdf->page_resources = &local_page_resources; - local_page_resources.resources_tree = NULL; - ship_out(pdf, obj_xform_box(pdf, pdf_cur_form), SHIPPING_FORM); - /*tex Restore the page size and page resources. */ - pdf->page_size = save_cur_page_size; - global_shipping_mode = save_shipping_mode; - destroy_page_resources_tree(pdf); - pdf->page_resources = res_p; - pdf_cur_form = save_pdf_cur_form; - } - ol = ol->link; - } - /*tex Write out pending images. */ - ol = get_page_resources_list(pdf, obj_type_ximage); - while (ol != NULL) { - if (!is_obj_written(pdf, ol->info)) - pdf_write_image(pdf, ol->info); - ol = ol->link; - } - if (global_shipping_mode == SHIPPING_PAGE) { - /*tex Write out pending \PDF\ marks and annotations. */ - ol = get_page_resources_list(pdf, obj_type_annot); - while (ol != NULL) { - if (ol->info > 0 && obj_type(pdf, ol->info) == obj_type_annot) { - /*tex Here |j| points to |pdf_annot_node|: */ - j = obj_annot_ptr(pdf, ol->info); - pdf_begin_obj(pdf, ol->info, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - pdf_dict_add_name(pdf, "Type", "Annot"); - pdf_print_toks(pdf, pdf_annot_data(j)); - pdf_rectangle(pdf, j); - pdf_end_dict(pdf); - pdf_end_obj(pdf); - } - ol = ol->link; - } - /*tex Write out PDF link annotations. */ - if ((ol = get_page_resources_list(pdf, obj_type_link)) != NULL) { - while (ol != NULL) { - j = obj_annot_ptr(pdf, ol->info); - pdf_begin_obj(pdf, ol->info, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - pdf_dict_add_name(pdf, "Type", "Annot"); - if (pdf_action_type(pdf_link_action(j)) != pdf_action_user) - pdf_dict_add_name(pdf, "Subtype", "Link"); - if (pdf_link_attr(j) != null) - pdf_print_toks(pdf, pdf_link_attr(j)); - pdf_rectangle(pdf, j); - if (pdf_action_type(pdf_link_action(j)) != pdf_action_user) - pdf_puts(pdf, "/A "); - write_action(pdf, pdf_link_action(j)); - pdf_end_dict(pdf); - pdf_end_obj(pdf); - ol = ol->link; - } - /*tex Flush |pdf_start_link_node|'s created by |append_link|. */ - ol = get_page_resources_list(pdf, obj_type_link); - while (ol != NULL) { - j = obj_annot_ptr(pdf, ol->info); - /*tex - Nodes with |subtype = pdf_link_data_node| were created by - |append_link| and must be flushed here, as they are not - linked in any list. - */ - if (subtype(j) == pdf_link_data_node) - flush_node(j); - ol = ol->link; - } - } - /*tex Write out \PDF\ mark destinations. */ - write_out_pdf_mark_destinations(pdf); - /*tex Write out \PDF\ bead rectangle specifications. */ - print_bead_rectangles(pdf); - } - /*tex Write out resources dictionary. */ - pdf_begin_obj(pdf, res_p->last_resources, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - /*tex Print additional resources. */ - if (global_shipping_mode == SHIPPING_PAGE) { - page_resources = pdf_page_resources; - if (page_resources != null) { - pdf_print_toks(pdf, page_resources); - } - print_pdf_table_string(pdf, "pageresources"); - } else { - xform_resources = pdf_xform_resources; - if (xform_resources != null) { - pdf_print_toks(pdf, xform_resources); - } - if (obj_xform_resources(pdf, pdf_cur_form) != null) { - pdf_print_toks(pdf, obj_xform_resources(pdf, pdf_cur_form)); - delete_token_ref(obj_xform_resources(pdf, pdf_cur_form)); - set_obj_xform_resources(pdf, pdf_cur_form, null); - } - if (obj_xform_resources_str(pdf, pdf_cur_form) != null) { - lua_pdf_literal(pdf, obj_xform_resources_str(pdf, pdf_cur_form),1); - luaL_unref(Luas, LUA_REGISTRYINDEX, obj_xform_resources_str(pdf, pdf_cur_form)); - set_obj_xform_resources_str(pdf, pdf_cur_form, null); - } - } - /*tex Generate font resources. */ - if ((ol = get_page_resources_list(pdf, obj_type_font)) != NULL) { - pdf_add_name(pdf, "Font"); - pdf_begin_dict(pdf); - while (ol != NULL) { - p = s; - p += snprintf(p, 20, "F%i", obj_info(pdf, ol->info)); - if (pdf->resname_prefix != NULL) - p += snprintf(p, 20, "%s", pdf->resname_prefix); - pdf_dict_add_ref(pdf, s, ol->info); - ol = ol->link; - } - pdf_end_dict(pdf); - procset |= PROCSET_TEXT; - } - /*tex Generate |XObject| resources. */ - ol = get_page_resources_list(pdf, obj_type_xform); - ol1 = get_page_resources_list(pdf, obj_type_ximage); - if (ol != NULL || ol1 != NULL) { - pdf_add_name(pdf, "XObject"); - pdf_begin_dict(pdf); - while (ol != NULL) { - p = s; - p += snprintf(p, 20, "Fm%i", obj_info(pdf, ol->info)); - if (pdf->resname_prefix != NULL) - p += snprintf(p, 20, "%s", pdf->resname_prefix); - pdf_dict_add_ref(pdf, s, ol->info); - ol = ol->link; - } - while (ol1 != null) { - p = s; - p += snprintf(p, 20, "Im%i", obj_info(pdf, ol1->info)); - if (pdf->resname_prefix != NULL) - p += snprintf(p, 20, "%s", pdf->resname_prefix); - pdf_dict_add_ref(pdf, s, ol1->info); - procset |= img_procset(idict_array[obj_data_ptr(pdf, ol1->info)]); - ol1 = ol1->link; - } - pdf_end_dict(pdf); - } - /*tex Generate |ProcSet| in version 1.*/ - if (pdf->major_version == 1) { - pdf_add_name(pdf, "ProcSet"); - pdf_begin_array(pdf); - if ((procset & PROCSET_PDF) != 0) - pdf_add_name(pdf, "PDF"); - if ((procset & PROCSET_TEXT) != 0) - pdf_add_name(pdf, "Text"); - if ((procset & PROCSET_IMAGE_B) != 0) - pdf_add_name(pdf, "ImageB"); - if ((procset & PROCSET_IMAGE_C) != 0) - pdf_add_name(pdf, "ImageC"); - if ((procset & PROCSET_IMAGE_I) != 0) - pdf_add_name(pdf, "ImageI"); - pdf_end_array(pdf); - } - pdf_end_dict(pdf); - pdf_end_obj(pdf); -} - -/*tex - - We're now ready to wrap up the output file. Destinations that have been - referenced but don't exists have |obj_dest_ptr=null|. Leaving them undefined - might cause troubles for PDF browsers, so we need to fix them; they point to - the last page. - -*/ - -static void check_nonexisting_destinations(PDF pdf) -{ - int k; - for (k = pdf->head_tab[obj_type_dest]; k != 0; k = obj_link(pdf, k)) { - if (obj_dest_ptr(pdf, k) == null) { - if (obj_info(pdf, k) < 0) { - char *ss = makecstring(-obj_info(pdf, k)); - formatted_warning("pdf backend", "unreferenced destination with name '%s'",ss); - } else { - formatted_warning("pdf backend", "unreferenced destination with num '%d'",obj_info(pdf,k)); - } - - pdf_begin_obj(pdf, k, OBJSTM_ALWAYS); - pdf_begin_array(pdf); - pdf_add_ref(pdf, pdf->last_page); - pdf_add_name(pdf, "Fit"); - pdf_end_array(pdf); - pdf_end_obj(pdf); - } - } -} - -static void check_nonexisting_pages(PDF pdf) -{ - struct avl_traverser t; - oentry *p; - struct avl_table *page_tree = pdf->obj_tree[obj_type_page]; - avl_t_init(&t, page_tree); - /*tex Search from the end backward until the last real page is found. */ - for (p = avl_t_last(&t, page_tree); p != NULL && obj_aux(pdf, p->objptr) == 0; p = avl_t_prev(&t)) { - formatted_warning("pdf backend", "page %d has been referenced but does not exist",obj_info(pdf, p->objptr)); - } -} - -/*tex - - If the same keys in a dictionary are given several times, then it is not - defined which value is choosen by an application. Therefore the keys - |/Producer| and |/Creator| are only set if the token list |pdf_info_toks| - converted to a string does not contain these key strings. - -*/ - -static boolean substr_of_str(const char *s, const char *t) -{ - if (strstr(t, s) == NULL) - return false; - return true; -} - -static int pdf_print_info(PDF pdf, int luatexversion, str_number luatexrevision) -{ - boolean creator_given = false; - boolean producer_given = false; - boolean creationdate_given = false; - boolean moddate_given = false; - boolean trapped_given = false; - char *s = NULL; - const char *p = NULL; - int k, len = 0; - k = pdf_create_obj(pdf, obj_type_info, 0); - pdf_begin_obj(pdf, k, 3); - pdf_begin_dict(pdf); - if (pdf_info_toks != 0) { - s = tokenlist_to_cstring(pdf_info_toks, true, &len); - creator_given = substr_of_str("/Creator", s); - producer_given = substr_of_str("/Producer", s); - creationdate_given = substr_of_str("/CreationDate", s); - moddate_given = substr_of_str("/ModDate", s); - trapped_given = substr_of_str("/Trapped", s); - } - p = get_pdf_table_string("info"); - if (p && strlen(p) > 0) { - creator_given = creator_given || substr_of_str("/Creator", p); - producer_given = producer_given || substr_of_str("/Producer", p); - creationdate_given = creationdate_given || substr_of_str("/CreationDate", p); - moddate_given = moddate_given || substr_of_str("/ModDate", p); - trapped_given = trapped_given || substr_of_str("/Trapped", p); - } - if (pdf_info_toks != null) { - if (len > 0) { - pdf_check_space(pdf); - pdf_puts(pdf, s); - pdf_set_space(pdf); - xfree(s); - } - delete_token_ref(pdf_info_toks); - pdf_info_toks = null; - } - if (p && strlen(p) > 0) { - pdf_check_space(pdf); - pdf_puts(pdf, p); - pdf_set_space(pdf); - } - if ((pdf_suppress_optional_info & 128) == 0 && !producer_given) { - pdf_add_name(pdf, "Producer"); - pdf_puts(pdf, " (LuaTeX-"); - pdf_puts(pdf, luatex_version_string); - pdf_out(pdf, ')'); - } - if ((pdf_suppress_optional_info & 16) == 0 && !creator_given) { - pdf_dict_add_string(pdf, "Creator", "TeX"); - } - if ((pdf_suppress_optional_info & 32) == 0 && !creationdate_given) { - initialize_start_time(pdf); - pdf_dict_add_string(pdf, "CreationDate", pdf->start_time_str); - } - if ((pdf_suppress_optional_info & 64) == 0 && !moddate_given) { - initialize_start_time(pdf); - pdf_dict_add_string(pdf, "ModDate", pdf->start_time_str); - } - if ((pdf_suppress_optional_info & 256) == 0 && !trapped_given) { - pdf_dict_add_name(pdf, "Trapped", "False"); - } - if ((pdf_suppress_optional_info & 1) == 0) { - pdf_dict_add_string(pdf, "PTEX.FullBanner", luatex_banner); - } - pdf_end_dict(pdf); - pdf_end_obj(pdf); - return k; -} - -static void build_free_object_list(PDF pdf) -{ - int k; - int l = 0; - /*tex A |null| object at the begin of a list of free objects. */ - set_obj_fresh(pdf, l); - for (k = 1; k <= pdf->obj_ptr; k++) { - if (!is_obj_written(pdf, k)) { - set_obj_link(pdf, l, k); - l = k; - } - } - set_obj_link(pdf, l, 0); -} - -/*tex - - Now we can the finish of \PDF\ output file. At this moment all |/Page| - objects are already written completely to \PDF\ output file. - -*/ - -void pdf_finish_file(PDF pdf, int fatal_error) { - if (fatal_error) { - remove_pdffile(static_pdf); /* will become remove_output_file */ - print_err(" ==> Fatal error occurred, no output PDF file produced!"); - } else { - int i, j, k; - int root, info; - int xref_stm = 0; - int outlines = 0; - int threads = 0; - int names_tree = 0; - int prerolled = 0; - size_t xref_offset_width; - int luatexversion = luatex_version; - str_number luatexrevision = get_luatexrevision(); - int callback_id = callback_defined(stop_run_callback); - int callback_id1 = callback_defined(finish_pdffile_callback); - if (total_pages == 0 && !pdf->force_file) { - if (callback_id == 0) { - normal_warning("pdf backend","no pages of output."); - } else if (callback_id > 0) { - run_callback(callback_id, "->"); - } - if (pdf->gone > 0) { - /* number of bytes gone */ - normal_error("pdf backend","already written content discarded, no output file produced."); - } - } else { - if (pdf->draftmode == 0) { - /*tex We make sure that the output file name has been already created. */ - pdf_flush(pdf); - /*tex Flush page 0 objects from JBIG2 images, if any. */ - flush_jbig2_page0_objects(pdf); - if (callback_id1 > 0) { - run_callback(callback_id1, "->"); - } - if (total_pages > 0) { - check_nonexisting_pages(pdf); - check_nonexisting_destinations(pdf); - } - /*tex - Output fonts definition. - */ - pdf->gen_tounicode = pdf_gen_tounicode; - pdf->omit_cidset = pdf_omit_cidset; - pdf->omit_charset = pdf_omit_charset; - /*tex - The first pass over the list will flag the slots that are - used so that we can do a preroll for type 3 fonts. - */ - for (k = 1; k <= max_font_id(); k++) { - if (font_used(k) && (pdf_font_num(k) < 0)) { - i = -pdf_font_num(k); - for (j = font_bc(k); j <= font_ec(k); j++) - if (quick_char_exists(k, j) && pdf_char_marked(k, j)) - pdf_mark_char(i, j); - } - } - k = pdf->head_tab[obj_type_font]; - while (k != 0) { - int f = obj_info(pdf, k); - if (do_pdf_preroll_font(pdf, f)) { - prerolled = 1; - } - k = obj_link(pdf, k); - } - /*tex - Just in case the user type 3 font has used fonts, we need to - do a second pass. We also collect some additional data here. - */ - for (k = 1; k <= max_font_id(); k++) { - if (font_used(k) && (pdf_font_num(k) < 0)) { - i = -pdf_font_num(k); - if (prerolled) { - for (j = font_bc(k); j <= font_ec(k); j++) - if (quick_char_exists(k, j) && pdf_char_marked(k, j)) - pdf_mark_char(i, j); - } else { - /*tex No need to waste time on checking again. */ - } - if ((pdf_font_attr(i) == 0) && (pdf_font_attr(k) != 0)) { - set_pdf_font_attr(i, pdf_font_attr(k)); - } else if ((pdf_font_attr(k) == 0) && (pdf_font_attr(i) != 0)) { - set_pdf_font_attr(k, pdf_font_attr(i)); - } else if ((pdf_font_attr(i) != 0) && (pdf_font_attr(k) != 0) && (!str_eq_str(pdf_font_attr(i), pdf_font_attr(k)))) { - formatted_warning("pdf backend","fontattr of font %d and %d are conflicting, %k is used",i,k,i); - } - } - } - k = pdf->head_tab[obj_type_font]; - while (k != 0) { - int f = obj_info(pdf, k); - do_pdf_font(pdf, f); - k = obj_link(pdf, k); - } - write_fontstuff(pdf); - /*tex - We're done with the fonts. - */ - if (total_pages > 0) { - pdf->last_pages = output_pages_tree(pdf); - /*tex Output outlines. */ - outlines = print_outlines(pdf); - /*tex - The name tree is very similiar to Pages tree so its construction - should be certain from Pages tree construction. For intermediate - node |obj_info| will be the first name and |obj_link| will be the - last name in \.{\\Limits} array. Note that |pdf_dest_names_ptr| - will be less than |obj_ptr|, so we test if |k < - pdf_dest_names_ptr| then |k| is index of leaf in |dest_names|; - else |k| will be index in |obj_tab| of some intermediate node. - */ - names_tree = output_name_tree(pdf); - /*tex Output article threads. */ - if (pdf->head_tab[obj_type_thread] != 0) { - threads = pdf_create_obj(pdf, obj_type_others, 0); - pdf_begin_obj(pdf, threads, OBJSTM_ALWAYS); - pdf_begin_array(pdf); - k = pdf->head_tab[obj_type_thread]; - while (k != 0) { - pdf_add_ref(pdf, k); - k = obj_link(pdf, k); - } - pdf_end_array(pdf); - pdf_end_obj(pdf); - k = pdf->head_tab[obj_type_thread]; - while (k != 0) { - out_thread(pdf, k); - k = obj_link(pdf, k); - } - } else { - threads = 0; - } - } - /*tex Output the |/Catalog| object. */ - root = pdf_create_obj(pdf, obj_type_catalog, 0); - pdf_begin_obj(pdf, root, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - pdf_dict_add_name(pdf, "Type", "Catalog"); - if (total_pages > 0) { - pdf_dict_add_ref(pdf, "Pages", pdf->last_pages); - if (threads != 0) { - pdf_dict_add_ref(pdf, "Threads", threads); - } - if (outlines != 0) { - pdf_dict_add_ref(pdf, "Outlines", outlines); - } - if (names_tree != 0) { - pdf_dict_add_ref(pdf, "Names", names_tree); - } - if (pdf_catalog_toks != null) { - pdf_print_toks(pdf, pdf_catalog_toks); - delete_token_ref(pdf_catalog_toks); - pdf_catalog_toks = null; - } - } - if (pdf_catalog_openaction != 0) { - pdf_dict_add_ref(pdf, "OpenAction", pdf_catalog_openaction); - } - print_pdf_table_string(pdf, "catalog"); - pdf_end_dict(pdf); - pdf_end_obj(pdf); - info = pdf_print_info(pdf, luatexversion, luatexrevision); - if (pdf->os_enable) { - pdf_buffer_select(pdf, OBJSTM_BUF); - pdf_os_write_objstream(pdf); - pdf_flush(pdf); - pdf_buffer_select(pdf, PDFOUT_BUF); - /*tex Output the cross-reference stream dictionary. */ - xref_stm = pdf_create_obj(pdf, obj_type_others, 0); - pdf_begin_obj(pdf, xref_stm, OBJSTM_NEVER); - if ((obj_offset(pdf, pdf->obj_ptr) / 256) > 16777215) - xref_offset_width = 5; - else if (obj_offset(pdf, pdf->obj_ptr) > 16777215) - xref_offset_width = 4; - else if (obj_offset(pdf, pdf->obj_ptr) > 65535) - xref_offset_width = 3; - else - xref_offset_width = 2; - /*tex Build a linked list of free objects. */ - build_free_object_list(pdf); - pdf_begin_dict(pdf); - pdf_dict_add_name(pdf, "Type", "XRef"); - pdf_add_name(pdf, "Index"); - pdf_begin_array(pdf); - pdf_add_int(pdf, 0); - pdf_add_int(pdf, pdf->obj_ptr + 1); - pdf_end_array(pdf); - pdf_dict_add_int(pdf, "Size", pdf->obj_ptr + 1); - pdf_add_name(pdf, "W"); - pdf_begin_array(pdf); - pdf_add_int(pdf, 1); - pdf_add_int(pdf, (int) xref_offset_width); - pdf_add_int(pdf, 1); - pdf_end_array(pdf); - pdf_dict_add_ref(pdf, "Root", root); - pdf_dict_add_ref(pdf, "Info", info); - if (pdf_trailer_toks != null) { - pdf_print_toks(pdf, pdf_trailer_toks); - delete_token_ref(pdf_trailer_toks); - pdf_trailer_toks = null; - } - print_pdf_table_string(pdf, "trailer"); - print_ID(pdf); - pdf_dict_add_streaminfo(pdf); - pdf_end_dict(pdf); - pdf_begin_stream(pdf); - for (k = 0; k <= pdf->obj_ptr; k++) { - if (!is_obj_written(pdf, k)) { - /*tex A free object: */ - pdf_out(pdf, 0); - pdf_out_bytes(pdf, obj_link(pdf, k), xref_offset_width); - pdf_out(pdf, 255); - } else if (obj_os_idx(pdf, k) == PDF_OS_MAX_OBJS) { - /*tex An object not in object stream: */ - pdf_out(pdf, 1); - pdf_out_bytes(pdf, obj_offset(pdf, k), xref_offset_width); - pdf_out(pdf, 0); - } else { - /*tex An object in object stream: */ - pdf_out(pdf, 2); - pdf_out_bytes(pdf, obj_offset(pdf, k), xref_offset_width); - pdf_out(pdf, obj_os_idx(pdf, k)); - } - } - pdf_end_stream(pdf); - pdf_end_obj(pdf); - pdf_flush(pdf); - } else { - /*tex Output the |obj_tab| and build a linked list of free objects. */ - build_free_object_list(pdf); - pdf_save_offset(pdf); - pdf_puts(pdf, "xref\n"); - pdf_puts(pdf, "0 "); - pdf_print_int_ln(pdf, pdf->obj_ptr + 1); - pdf_print_fw_int(pdf, obj_link(pdf, 0)); - pdf_puts(pdf, " 65535 f \n"); - for (k = 1; k <= pdf->obj_ptr; k++) { - if (!is_obj_written(pdf, k)) { - pdf_print_fw_int(pdf, obj_link(pdf, k)); - pdf_puts(pdf, " 00000 f \n"); - } else { - pdf_print_fw_int(pdf, obj_offset(pdf, k)); - pdf_puts(pdf, " 00000 n \n"); - } - } - } - /*tex Output the trailer. */ - if (!pdf->os_enable) { - pdf_puts(pdf, "trailer\n"); - pdf_reset_space(pdf); - pdf_begin_dict(pdf); - pdf_dict_add_int(pdf, "Size", pdf->obj_ptr + 1); - pdf_dict_add_ref(pdf, "Root", root); - pdf_dict_add_ref(pdf, "Info", info); - if (pdf_trailer_toks != null) { - pdf_print_toks(pdf, pdf_trailer_toks); - delete_token_ref(pdf_trailer_toks); - pdf_trailer_toks = null; - } - print_ID(pdf); - pdf_end_dict(pdf); - pdf_out(pdf, '\n'); - } - pdf_puts(pdf, "startxref\n"); - pdf_reset_space(pdf); - if (pdf->os_enable) - pdf_add_longint(pdf, (longinteger) obj_offset(pdf, xref_stm)); - else - pdf_add_longint(pdf, (longinteger) pdf->save_offset); - pdf_puts(pdf, "\n%%EOF\n"); - pdf_flush(pdf); - if (callback_id == 0) { - tprint_nl("Output written on "); - tprint(pdf->file_name); - tprint(" ("); - print_int(total_pages); - tprint(" page"); - if (total_pages != 1) - print_char('s'); - tprint(", "); - print_int(pdf_offset(pdf)); - tprint(" bytes)."); - print_ln(); - } else if (callback_id > 0) { - run_callback(callback_id, "->"); - } - libpdffinish(pdf); - close_file(pdf->file); - } else { - if (callback_id > 0) { - run_callback(callback_id, "->"); - } - libpdffinish(pdf); - normal_warning("pdf backend","draftmode enabled, not changing output pdf"); - } - } - if (callback_id == 0) { - if (log_opened_global) { - fprintf(log_file, "\nPDF statistics: %d PDF objects out of %d (max. %d)\n", - (int) pdf->obj_ptr, (int) pdf->obj_tab_size, - (int) sup_obj_tab_size); - if (pdf->os->ostm_ctr > 0) { - fprintf(log_file, " %d compressed objects within %d object stream%s\n", - (int) pdf->os->o_ctr, (int) pdf->os->ostm_ctr, - (pdf->os->ostm_ctr > 1 ? "s" : "")); - } - fprintf(log_file, " %d named destinations out of %d (max. %d)\n", - (int) pdf->dest_names_ptr, (int) pdf->dest_names_size, - (int) sup_dest_names_size); - fprintf(log_file, " %d words of extra memory for PDF output out of %d (max. %d)\n", - (int) pdf->mem_ptr, (int) pdf->mem_size, - (int) sup_pdf_mem_size); - } - } - } -} - -void scan_pdfcatalog(PDF pdf) -{ - halfword p; - scan_toks(false, true); - pdf_catalog_toks = concat_tokens(pdf_catalog_toks, def_ref); - if (scan_keyword("openaction")) { - if (pdf_catalog_openaction != 0) { - normal_error("pdf backend", "duplicate of openaction"); - } else { - check_o_mode(pdf, "catalog", 1 << OMODE_PDF, true); - p = scan_action(pdf); - pdf_catalog_openaction = pdf_create_obj(pdf, obj_type_others, 0); - pdf_begin_obj(pdf, pdf_catalog_openaction, OBJSTM_ALWAYS); - write_action(pdf, p); - pdf_end_obj(pdf); - delete_action_ref(p); - } - } -} - -/*tex - - This function converts double to pdffloat; very small and very large numbers - are {\em not} converted to scientific notation. Here n must be a number or - real conforming to the implementation limits of \PDF\ as specified in - appendix C.1 of the \PDF\ standard. The maximum value of ints is |+2^32|, the - maximum value of reals is |+2^15| and the smallest values of reals is - |1/(2^16)|. We are quite large on precision, because it could happen that a - pdf file imported as figure has real numbers with an unusual (and possibly useless) - high precision. Later the formatter will write the numbers in the correct format. - -*/ - -static pdffloat conv_double_to_pdffloat(double n) -{ - pdffloat a; -/* was a.e = 6; */ - a.e = 9 ; - a.m = i64round(n * ten_pow[a.e]); - return a; -} - -void pdf_add_real(PDF pdf, double d) -{ - pdf_check_space(pdf); - print_pdffloat(pdf, conv_double_to_pdffloat(d)); - pdf_set_space(pdf); -} - -void pdf_push_list(PDF pdf, scaledpos *saved_pos, int *saved_loc) { - /* nothing */ -} - -void pdf_pop_list(PDF pdf, scaledpos *saved_pos, int *saved_loc) { - /* nothing */ -} - -extern void pdf_set_reference_point(PDF pdf, posstructure *refpoint) -{ - refpoint->pos.h = pdf_h_origin; - refpoint->pos.v = pdf->page_size.v - pdf_v_origin; -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfgen.h b/Build/source/texk/web2c/luatexdir/pdf/pdfgen.h deleted file mode 100644 index 00df7f36ed3..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfgen.h +++ /dev/null @@ -1,255 +0,0 @@ -/* pdfgen.h - - Copyright 2009-2013 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef PDFGEN_H -# define PDFGEN_H - -# define PROCSET_PDF (1 << 0) -# define PROCSET_TEXT (1 << 1) -# define PROCSET_IMAGE_B (1 << 2) -# define PROCSET_IMAGE_C (1 << 3) -# define PROCSET_IMAGE_I (1 << 4) - -# define inf_pdf_mem_size 10000 /* min size of the |mem| array */ -# define sup_pdf_mem_size 100000000 /* max size of the |mem| array */ - -extern PDF static_pdf; - -extern int pdf_get_mem(PDF pdf, int s); - -/* - -We use the similiar subroutines to handle the output buffer for PDF output. When -compress is used, the state of writing to buffer is held in |zip_write_state|. We -must write the header of PDF output file in initialization to ensure that it will -be the first written bytes. - -*/ - -# define inf_pdfout_buf_size 16384 /* initial value of |pdf->buf| size */ -# define sup_pdfout_buf_size 8*16384 /* arbitrary upper hard limit of |pdf->buf| size */ -# define inf_objstm_buf_size 1 /* initial value of |os->buf[OBJSTM_BUF]| size */ -# define sup_objstm_buf_size 5000000 /* arbitrary upper hard limit of |os->buf[OBJSTM_BUF]| size */ - -# define PDF_OS_MAX_OBJS 100 /* maximum number of objects in object stream */ - -# define inf_obj_tab_size 1000 /* min size of the cross-reference table for PDF output */ -# define sup_obj_tab_size 8388607 /* max size of the cross-reference table for PDF output */ - -/* The following macros are similar as for \.{DVI} buffer handling */ - -# define pdf_offset(pdf) (pdf->gone + (off_t)(pdf->buf->p - pdf->buf->data)) -# define pdf_save_offset(pdf) pdf->save_offset = (pdf->gone + (off_t)(pdf->buf->p - pdf->buf->data)) - -# define set_ff(A) do { \ - if (pdf_font_num(A) < 0) \ - ff = -pdf_font_num(A); \ - else \ - ff = A; \ -} while (0) - -typedef enum { /* needs pdf_prefix */ - NOT_SHIPPING, - SHIPPING_PAGE, - SHIPPING_FORM -} shipping_mode_e; - -extern scaled one_hundred_inch; -extern scaled one_inch; -extern scaled one_true_inch; -extern scaled one_hundred_bp; -extern scaled one_bp; -extern int ten_pow[10]; - -extern void pdf_flush(PDF); -extern void pdf_room(PDF, int); - -extern void fix_pdf_version(PDF); - -/* output a byte to PDF buffer without checking of overflow */ - -# define pdf_quick_out(pdf,A) * (pdf->buf->p++) = (unsigned char) (A) - -/* do the same as |pdf_quick_out| and flush the PDF buffer if necessary */ - -# define pdf_out(pdf,A) do { \ - pdf_room(pdf, 1); \ - pdf_quick_out(pdf, A); \ -} while (0) - -/* - -Basic printing procedures for PDF output are very similiar to \TeX\ basic -printing ones but the output is going to PDF buffer. Subroutines with suffix -|_ln| append a new-line character to the PDF output. - -*/ - -# define pdf_print_ln(pdf,A) do { \ - pdf_print(pdf,A); \ - pdf_out(pdf, '\n'); \ -} while (0) - -/* print out an integer to PDF buffer followed by a new-line character */ - -# define pdf_print_int_ln(pdf,A) do { \ - pdf_print_int(pdf,A); \ - pdf_out(pdf, '\n'); \ -} while (0) - -#define pdf_check_space(pdf) do { \ - if (pdf->cave > 0) { \ - pdf_out(pdf, ' '); \ - pdf->cave = 0; \ - } \ -} while (0) - -#define pdf_set_space(pdf) \ - pdf->cave = 1; - -#define pdf_reset_space(pdf) \ - pdf->cave = 0; - -extern __attribute__ ((format(printf, 2, 3))) -void pdf_printf(PDF, const char *, ...); - -extern void pdf_print(PDF, str_number); -extern void pdf_print_int(PDF, longinteger); -extern void print_pdffloat(PDF pdf, pdffloat f); -extern void pdf_print_str(PDF, const char *); - -extern void pdf_add_null(PDF); -extern void pdf_add_bool(PDF, int i); -extern void pdf_add_int(PDF, int i); -extern void pdf_add_real(PDF, double d); -extern void pdf_add_longint(PDF, longinteger n); -extern void pdf_add_ref(PDF, int num); -extern void pdf_add_string(PDF, const char *s); -extern void pdf_add_name(PDF, const char *name); - -extern void pdf_dict_add_bool(PDF, const char *key, int i); -extern void pdf_dict_add_int(PDF, const char *key, int i); -extern void pdf_dict_add_ref(PDF, const char *key, int num); -extern void pdf_dict_add_name(PDF, const char *key, const char *val); -extern void pdf_dict_add_string(PDF pdf, const char *key, const char *val); -extern void pdf_dict_add_streaminfo(PDF); - -extern void pdf_begin_stream(PDF); -extern void pdf_end_stream(PDF); - -typedef unsigned char BYTE; -typedef unsigned long ULONG; - -typedef struct { - ULONG length; - BYTE *data; -} pdf_obj; - -extern pdf_obj *pdf_new_stream(void); -extern void pdf_add_stream(pdf_obj * stream, unsigned char *buf, long len); -extern void pdf_release_obj(pdf_obj * stream); - -extern void pdf_add_bp(PDF, scaled); - -extern strbuf_s *new_strbuf(size_t size, size_t limit); -extern void strbuf_seek(strbuf_s * b, off_t offset); -extern size_t strbuf_offset(strbuf_s * b); -extern void strbuf_putchar(strbuf_s * b, unsigned char c); -extern void strbuf_flush(PDF pdf, strbuf_s * b); -extern void strbuf_free(strbuf_s * b); - -/* This is for the resource lists */ - -extern void addto_page_resources(PDF pdf, pdf_obj_type t, int k); -extern pdf_object_list *get_page_resources_list(PDF pdf, pdf_obj_type t); - -extern void pdf_out_block(PDF pdf, const char *s, size_t n); - -# define pdf_puts(pdf, s) pdf_out_block((pdf), (s), strlen(s)) - -# define pdf_print_resname_prefix(pdf) do { \ - if (pdf->resname_prefix != NULL) \ - pdf_puts(pdf, pdf->resname_prefix); \ -} while (0) - -extern void pdf_print_str_ln(PDF, const char *); - -extern void pdf_print_toks(PDF, halfword); - -extern void pdf_add_rect_spec(PDF, halfword); -extern void pdf_rectangle(PDF, halfword); - -extern void pdf_begin_obj(PDF, int, int); -extern void pdf_end_obj(PDF); - -extern void pdf_begin_dict(PDF); -extern void pdf_end_dict(PDF); -extern void pdf_begin_array(PDF); -extern void pdf_end_array(PDF); - -extern void remove_pdffile(PDF); - -extern void zip_free(PDF); - -/* functions that do not output stuff */ - -extern scaled round_xn_over_d(scaled x, int n, unsigned int d); - -extern char *convertStringToPDFString(const char *in, int len); - -extern void initialize_start_time(PDF); -extern char *getcreationdate(PDF); - -extern void set_job_id(PDF, int, int, int, int); -extern char *get_resname_prefix(PDF); -extern void pdf_begin_page(PDF pdf); -extern void pdf_end_page(PDF pdf); -extern void print_pdf_table_string(PDF pdf, const char *s); -extern const char *get_pdf_table_string(const char *s); -extern int get_pdf_table_bool(PDF, const char *, int); - -extern void pdf_open_file(PDF pdf); -extern void pdf_write_header(PDF pdf); -extern void pdf_finish_file(PDF pdf, int fatal_error); - -extern void ensure_output_state(PDF pdf, output_state s); -extern PDF init_pdf_struct(PDF pdf); - -extern halfword pdf_info_toks; /* additional keys of Info dictionary */ -extern halfword pdf_catalog_toks; /* additional keys of Catalog dictionary */ -extern halfword pdf_catalog_openaction; -extern halfword pdf_names_toks; /* additional keys of Names dictionary */ -extern halfword pdf_trailer_toks; /* additional keys of Trailer dictionary */ -extern void scan_pdfcatalog(PDF pdf); - -extern shipping_mode_e global_shipping_mode; - -extern void pdf_push_list(PDF pdf, scaledpos *saved_pos, int *saved_loc); -extern void pdf_pop_list(PDF pdf, scaledpos *saved_pos, int *saved_loc); - -extern void pdf_set_reference_point(PDF pdf, posstructure *refpoint); - -/* not pdf specific */ - -extern void check_o_mode(PDF pdf, const char *s, int o_mode, boolean errorflag); -extern void ensure_output_file_open(PDF pdf, const char *ext); - - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.c b/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.c deleted file mode 100644 index c7cf0439212..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.c +++ /dev/null @@ -1,289 +0,0 @@ -/* - -Copyright 2009-2011 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" -#include "pdf/pdfpage.h" - -/*tex - - The |e_tj| step must be 3 because movements in |[]TJ| are in fontsize/$10^3$ - units. - -*/ - -#define e_tj 3 - -/*tex - - Use exactly this formula also for calculating the |/Width| array values. - -*/ - -static int64_t pdf_char_width(pdfstructure * p, internal_font_number f, int i) -{ - return i64round((double) char_width(f, i) / font_size(f) * ten_pow[e_tj + p->cw.e]); -} - -void pdf_print_charwidth(PDF pdf, internal_font_number f, int i) -{ - pdffloat cw; - pdfstructure *p = pdf->pstruct; - cw.m = pdf_char_width(p, f, i); - cw.e = p->cw.e; - print_pdffloat(pdf, cw); -} - -static void setup_fontparameters(PDF pdf, internal_font_number f, int ex_glyph) -{ - float slant, extend, squeeze, expand, scale = 1.0; - float u = 1.0; - pdfstructure *p = pdf->pstruct; - if ((font_format(f) == opentype_format || (font_format(f) == type1_format && font_encodingbytes(f) == 2)) && font_units_per_em(f) > 0) - u = font_units_per_em(f) / 1000.0; - pdf->f_cur = f; - p->f_pdf = pdf_set_font(pdf, f); - p->fs.m = i64round(font_size(f) / u / by_one_bp * ten_pow[p->fs.e]); - slant = font_slant(f) / 1000.0; - extend = font_extend(f) / 1000.0; - squeeze = font_squeeze(f) / 1000.0; - expand = 1.0 + (ex_glyph/1) / 1000.0; - /*tex The |-1| makes less corrections inside |[]TJ|: */ - p->tj_delta.e = p->cw.e - 1; - /*tex There is no need to be more precise than \TEX\ (1sp). */ - while (p->tj_delta.e > 0 && (double) font_size(f) / ten_pow[p->tj_delta.e + e_tj] < 0.5) { - /*tex This happens for very tiny fonts. */ - p->tj_delta.e--; - } - p->tm[0].m = i64round(scale * expand * extend * ten_pow[p->tm[0].e]); - p->tm[2].m = i64round(slant * ten_pow[p->tm[2].e]); - p->tm[3].m = i64round(scale * squeeze * ten_pow[p->tm[3].e]); - p->k2 = ten_pow[e_tj + p->cw.e] * scale / (ten_pow[p->pdf.h.e] * pdf2double(p->fs) * pdf2double(p->tm[0])); - /*tex We keep track of the state of ex. */ - p->cur_ex = ex_glyph ; - p->need_width = font_width(f); - p->need_mode = font_mode(f); -} - -static void set_font(PDF pdf) -{ - pdfstructure *p = pdf->pstruct; - - if (p->need_width != 0) { - pdf_printf(pdf, "%0.3f w\n",((7227.0/7200.0)/1000.0) * p->need_width ); - p->done_width = 1; - } else if (p->done_width) { - pdf_puts(pdf, "0 w\n"); - p->done_width = 0; - } - if (p->need_mode != 0) { - pdf_printf(pdf, "%d Tr\n", (int) p->need_mode); - p->done_mode = 1; - } else if (p->done_mode) { - pdf_puts(pdf, "0 Tr\n"); - p->done_mode = 0; - } - pdf_printf(pdf, "/F%d", (int) p->f_pdf); - pdf_print_resname_prefix(pdf); - pdf_out(pdf, ' '); - print_pdffloat(pdf, p->fs); - pdf_puts(pdf, " Tf\n"); - p->f_pdf_cur = p->f_pdf; - p->fs_cur.m = p->fs.m; - p->need_tf = false; - /*tex Always follow |Tf| by |Tm|: */ - p->need_tm = true; -} - -static void set_textmatrix(PDF pdf, scaledpos pos) -{ - boolean move; - pdfstructure *p = pdf->pstruct; - if (!is_textmode(p)) - normal_error("pdf backend","text mode expected in set_textmatrix"); - move = calc_pdfpos(p, pos); - if (p->need_tm || move) { - print_pdf_matrix(pdf, p->tm); - pdf_puts(pdf, " Tm "); - /*tex |Tm| replaces */ - p->pdf.h.m = p->pdf_bt_pos.h.m + p->tm[4].m; - p->pdf.v.m = p->pdf_bt_pos.v.m + p->tm[5].m; - p->need_tm = false; - } - p->tm0_cur.m = p->tm[0].m; -} - -/*tex - - Print out a character to PDF buffer; the character will be printed in octal - form in the following cases: chars <= 32, backslash (92), left parenthesis - (40), and right parenthesis (41). - -*/ - -static void pdf_print_char(PDF pdf, int c) -{ - if (c > 255) { - return; - } else if (c <= 32 || c == '\\' || c == '(' || c == ')' || c > 127) { - pdf_room(pdf, 4); - pdf_quick_out(pdf, '\\'); - pdf_quick_out(pdf, (unsigned char) ('0' + ((c >> 6) & 0x3))); - pdf_quick_out(pdf, (unsigned char) ('0' + ((c >> 3) & 0x7))); - pdf_quick_out(pdf, (unsigned char) ('0' + (c & 0x7))); - } else - pdf_out(pdf, c); -} - -static void pdf_print_wide_char(PDF pdf, int c) -{ - char hex[5]; - snprintf(hex, 5, "%04X", c); - pdf_out_block(pdf, (const char *) hex, 4); -} - -static void begin_charmode(PDF pdf, internal_font_number f, pdfstructure * p) -{ - if (!is_chararraymode(p)) - normal_error("pdf backend","char array mode expected in begin_char_mode"); - if (font_encodingbytes(f) == 2) { - p->ishex = 1; - pdf_out(pdf, '<'); - } else { - p->ishex = 0; - pdf_out(pdf, '('); - } - p->mode = PMODE_CHAR; -} - -void end_charmode(PDF pdf) -{ - pdfstructure *p = pdf->pstruct; - if (!is_charmode(p)) - normal_error("pdf backend","char mode expected in end_char_mode"); - if (p->ishex == 1) { - p->ishex = 0; - pdf_out(pdf, '>'); - } else { - pdf_out(pdf, ')'); - } - p->mode = PMODE_CHARARRAY; -} - -static void begin_chararray(PDF pdf) -{ - pdfstructure *p = pdf->pstruct; - if (!is_textmode(p)) - normal_error("pdf backend","text mode expected in begin_char_array"); - p->pdf_tj_pos = p->pdf; - p->cw.m = 0; - pdf_out(pdf, '['); - p->mode = PMODE_CHARARRAY; -} - -void end_chararray(PDF pdf) -{ - pdfstructure *p = pdf->pstruct; - if (!is_chararraymode(p)) - normal_error("pdf backend","char array mode expected in end_char_array"); - pdf_puts(pdf, "]TJ\n"); - p->pdf = p->pdf_tj_pos; - p->mode = PMODE_TEXT; -} - -/*tex - - We need to adapt the tm when a font changes. A change can be a change in id - (frontend) or pdf reference (backend, as we share font resources). At such a - change we also need to adapt to the slant and extend. Initially we also need - to take the exfactor of a glyph into account. When the font is unchanged, we - still need to check each glyph for a change in exfactor. We store the current - one on the state record so that we can minimize testing. - -*/ - -void pdf_place_glyph(PDF pdf, internal_font_number f, int c, int ex) -{ - boolean move; - pdfstructure *p = pdf->pstruct; - scaledpos pos = pdf->posstruct->pos; - /*tex - - This is already done: - - \startyping - if (!char_exists(f, c)) { - return; - } - \stoptyping - - */ - if (font_writingmode(f) == vertical_writingmode) { - if (p->wmode != WMODE_V) { - p->wmode = WMODE_V; - p->need_tm = true; - } - } else { - if (p->wmode != WMODE_H) { - p->wmode = WMODE_H; - p->need_tm = true; - } - } - if (p->need_tf || f != pdf->f_cur || p->f_pdf != p->f_pdf_cur || p->fs.m != p->fs_cur.m || is_pagemode(p)) { - pdf_goto_textmode(pdf); - setup_fontparameters(pdf, f, ex); - set_font(pdf); - } else if (p->tm0_cur.m != p->tm[0].m || p->cur_ex != ex) { - setup_fontparameters(pdf, f, ex); - p->need_tm = true; - } - /*tex All movements within text or chararray or char mode: */ - move = calc_pdfpos(p, pos); - if (move || p->need_tm) { - if (p->need_tm - || (p->wmode == WMODE_H && (p->pdf_bt_pos.v.m + p->tm[5].m) != p->pdf.v.m) - || (p->wmode == WMODE_V && (p->pdf_bt_pos.h.m + p->tm[4].m) != p->pdf.h.m) - || abs(p->tj_delta.m) >= 1000000) { - pdf_goto_textmode(pdf); - set_textmatrix(pdf, pos); - begin_chararray(pdf); - /*tex For fine adjustment: */ - move = calc_pdfpos(p, pos); - } - if (move) { - if (is_charmode(p)) - end_charmode(pdf); - print_pdffloat(pdf, p->tj_delta); - p->cw.m -= p->tj_delta.m * ten_pow[p->cw.e - p->tj_delta.e]; - } - } - /*tex Glyph output: */ - if (is_chararraymode(p)) - begin_charmode(pdf, f, p); - else if (!is_charmode(p)) - normal_error("pdf backend","char (array) mode expected in place_glyph"); - pdf_mark_char(f, c); - if (font_encodingbytes(f) == 2) - pdf_print_wide_char(pdf, char_index(f, c)); - else - pdf_print_char(pdf, c); - /*tex Also known as |adv_char_width()|: */ - p->cw.m += pdf_char_width(p, p->f_pdf, c); -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.h b/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.h deleted file mode 100644 index 2d04e944c6e..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.h +++ /dev/null @@ -1,29 +0,0 @@ -/* pdfglyph.h - - Copyright 2009-2013 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef PDFGLYPH_H -# define PDFGLYPH_H - -void end_chararray(PDF pdf); -void end_charmode(PDF pdf); -void pdf_place_glyph(PDF pdf, internal_font_number f, int c, int ex); -void pdf_print_charwidth(PDF pdf, internal_font_number f, int i); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfimage.c b/Build/source/texk/web2c/luatexdir/pdf/pdfimage.c deleted file mode 100644 index 02e4237c820..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfimage.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - -Copyright 2009-2010 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -void place_img(PDF pdf, image_dict * idict, scaled_whd dim, int transform) -{ - /*tex A transformation matrix: */ - double a[6]; - double xoff, yoff, tmp; - pdfstructure *p = pdf->pstruct; - scaledpos pos = pdf->posstruct->pos; - /*tex The number of digits after the decimal point: */ - int r; - int k; - scaledpos tmppos; - pdffloat cm[6]; - int groupref; - a[0] = a[3] = 1.0e6; - a[1] = a[2] = 0; - if (img_type(idict) == IMG_TYPE_PDF || img_type(idict) == IMG_TYPE_PDFMEMSTREAM - || img_type(idict) == IMG_TYPE_PDFSTREAM) { - a[0] /= (double) img_xsize(idict); - a[3] /= (double) img_ysize(idict); - xoff = (double) img_xorig(idict) / (double) img_xsize(idict); - yoff = (double) img_yorig(idict) / (double) img_ysize(idict); - r = 6; - } else { - if (img_type(idict) == IMG_TYPE_PNG) { - groupref = img_group_ref(idict); - if ((groupref > 0) && (pdf->img_page_group_val == 0)) - pdf->img_page_group_val = groupref; - } - a[0] /= (double) one_hundred_bp; - a[3] = a[0]; - xoff = yoff = 0; - r = 4; - } - if ((transform & 7) > 3) { - /*tex Mirror cases: */ - a[0] *= -1; - xoff *= -1; - } - switch ((transform + img_rotation(idict)) & 3) { - case 0: - /*tex No transform. */ - break; - case 1: - /*tex rotation over 90 degrees (counterclockwise) */ - a[1] = a[0]; - a[2] = -a[3]; - a[3] = a[0] = 0; - tmp = yoff; - yoff = xoff; - xoff = -tmp; - break; - case 2: - /*tex rotation over 180 degrees (counterclockwise) */ - a[0] *= -1; - a[3] *= -1; - xoff *= -1; - yoff *= -1; - break; - case 3: - /*tex rotation over 270 degrees (counterclockwise) */ - a[1] = -a[0]; - a[2] = a[3]; - a[3] = a[0] = 0; - tmp = yoff; - yoff = -xoff; - xoff = tmp; - break; - default:; - } - xoff *= (double) dim.wd; - yoff *= (double) (dim.ht + dim.dp); - a[0] *= (double) dim.wd; - a[1] *= (double) (dim.ht + dim.dp); - a[2] *= (double) dim.wd; - a[3] *= (double) (dim.ht + dim.dp); - a[4] = (double) pos.h - xoff; - a[5] = (double) pos.v - yoff; - k = transform + img_rotation(idict); - if ((transform & 7) > 3) - k++; - switch (k & 3) { - case 0: - /*tex No transform */ - break; - case 1: - /*tex rotation over 90 degrees (counterclockwise) */ - a[4] += (double) dim.wd; - break; - case 2: - /*tex rotation over 180 degrees (counterclockwise) */ - a[4] += (double) dim.wd; - a[5] += (double) (dim.ht + dim.dp); - break; - case 3: - /*tex rotation over 270 degrees (counterclockwise) */ - a[5] += (double) (dim.ht + dim.dp); - break; - default:; - } - setpdffloat(cm[0], i64round(a[0]), r); - setpdffloat(cm[1], i64round(a[1]), r); - setpdffloat(cm[2], i64round(a[2]), r); - setpdffloat(cm[3], i64round(a[3]), r); - tmppos.h = round(a[4]); - tmppos.v = round(a[5]); - pdf_goto_pagemode(pdf); - (void) calc_pdfpos(p, tmppos); - cm[4] = p->cm[4]; - cm[5] = p->cm[5]; - if (pdf->img_page_group_val == 0) - pdf->img_page_group_val = img_group_ref(idict); - pdf_puts(pdf, "q\n"); - pdf_print_cm(pdf, cm); - pdf_puts(pdf, "/Im"); - pdf_print_int(pdf, img_index(idict)); - pdf_print_resname_prefix(pdf); - pdf_puts(pdf, " Do\nQ\n"); - addto_page_resources(pdf, obj_type_ximage, img_objnum(idict)); - if (img_state(idict) < DICT_OUTIMG) - img_state(idict) = DICT_OUTIMG; -} - -/*tex For normal output see |pdflistout.c|: */ - -void pdf_place_image(PDF pdf, halfword p) -{ - scaled_whd dim; - image_dict *idict = idict_array[rule_index(p)]; - dim.wd = width(p); - dim.ht = height(p); - dim.dp = depth(p); - place_img(pdf, idict, dim, rule_transform(p)); -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfimage.h b/Build/source/texk/web2c/luatexdir/pdf/pdfimage.h deleted file mode 100644 index b5b8718393e..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfimage.h +++ /dev/null @@ -1,28 +0,0 @@ -/* pdfimage.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#ifndef PDFIMAGE_H -# define PDFIMAGE_H - -void place_img(PDF pdf, image_dict * idict, scaled_whd dim, int transform); -void pdf_place_image(PDF pdf, halfword p); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdflink.c b/Build/source/texk/web2c/luatexdir/pdf/pdflink.c deleted file mode 100644 index 77b950adf25..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdflink.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - -Copyright 2009-2012 Taco Hoekwater <taco@@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -/*tex - - To implement nested link annotations, we need a stack to hold copy of - |pdf_start_link_node|'s that are being written out, together with their box - nesting level. - -*/ - -void pdf_out_link_state(PDF pdf, halfword p) -{ - if (pdf_link_state(p) >= 0 && pdf_link_state(p) <= 1) { - pdf->link_state = pdf_link_state(p); - } else { - /* ignores so one can use them for whatever purpose */ - } -} - - -void push_link_level(PDF pdf, halfword p) -{ - if (pdf->link_stack_ptr >= pdf_max_link_level) - overflow("pdf link stack size", pdf_max_link_level); - pdf->link_stack_ptr++; - pdf->link_stack[pdf->link_stack_ptr].nesting_level = cur_s; - pdf->link_stack[pdf->link_stack_ptr].link_node = copy_node_list(p); - pdf->link_stack[pdf->link_stack_ptr].ref_link_node = p; -} - -void pop_link_level(PDF pdf) -{ - flush_node_list(pdf->link_stack[pdf->link_stack_ptr].link_node); - pdf->link_stack_ptr--; -} - -void do_link(PDF pdf, halfword p, halfword parent_box, scaledpos cur) -{ - scaled_whd alt_rule; - int k; - if (type(p) == vlist_node) - normal_error("pdf backend", "'startlink' ended up in vlist"); - if (global_shipping_mode == SHIPPING_FORM) - normal_error("pdf backend", "link annotations cannot be inside an xform"); - if (is_obj_scheduled(pdf, pdf_link_objnum(p))) - pdf_link_objnum(p) = pdf_create_obj(pdf, obj_type_others, 0); - push_link_level(pdf, p); - alt_rule.wd = width(p); - alt_rule.ht = height(p); - alt_rule.dp = depth(p); - set_rect_dimens(pdf, p, parent_box, cur, alt_rule, pdf_link_margin); - /*tex The reference for the annot object must be set here. */ - obj_annot_ptr(pdf, pdf_link_objnum(p)) = p; - k = pdf_link_objnum(p); - set_obj_scheduled(pdf, pdf_link_objnum(p)); - addto_page_resources(pdf, obj_type_link, k); -} - -void end_link(PDF pdf, halfword p) -{ - halfword q; - scaledpos pos = pdf->posstruct->pos; - if (type(p) == vlist_node) - normal_error("pdf backend","'endlink' ended up in vlist"); - if (pdf->link_stack_ptr < 1) - normal_error("pdf backend","pdf link_stack empty, 'endlink' used without 'startlink'"); - if (pdf->link_stack[pdf->link_stack_ptr].nesting_level != cur_s) - normal_error("pdf backend","'endlink' ended up in different nesting level than 'startlink'"); - /*tex - The test for running link must be done on |link_node| and not - |ref_link_node|, as |ref_link_node| can be set by |do_link| or - |append_link| already. - */ - if (is_running(width(pdf->link_stack[pdf->link_stack_ptr].link_node))) { - q = pdf->link_stack[pdf->link_stack_ptr].ref_link_node; - if (global_shipping_mode == SHIPPING_PAGE && matrixused()) { - matrixrecalculate(pos.h + pdf_link_margin); - pdf_ann_left(q) = getllx() - pdf_link_margin; - pdf_ann_top(q) = getlly() - pdf_link_margin; - pdf_ann_right(q) = geturx() + pdf_link_margin; - pdf_ann_bottom(q) = getury() + pdf_link_margin; - } else { - switch (pdf->posstruct->dir) { - case dir_TLT: - pdf_ann_right(q) = pos.h + pdf_link_margin; - break; - case dir_TRT: - pdf_ann_left(q) = pos.h - pdf_link_margin; - break; - case dir_LTL: - case dir_RTT: - pdf_ann_bottom(q) = pos.v - pdf_link_margin; - break; - default: - pdf_ann_right(q) = pos.h + pdf_link_margin; - formatted_warning("pdf backend","forcing bad dir %i to TLT in link",pdf->posstruct->dir); - } - } - } - pop_link_level(pdf); -} - -/*tex - - For ``running'' annotations we must append a new node when the end of - annotation is in other box than its start. The new created node is identical - to corresponding whatsit node representing the start of annotation, but its - |info| field is |max_halfword|. We set |info| field just before destroying - the node, in order to use |flush_node_list| to do the job. - -*/ - -void append_link(PDF pdf, halfword parent_box, scaledpos cur, small_number i) -{ - halfword p; - int k; - scaled_whd alt_rule; - p = copy_node(pdf->link_stack[(int) i].link_node); - pdf->link_stack[(int) i].ref_link_node = p; - /*tex This node is not a normal link node. */ - subtype(p) = pdf_link_data_node; - alt_rule.wd = width(p); - alt_rule.ht = height(p); - alt_rule.dp = depth(p); - set_rect_dimens(pdf, p, parent_box, cur, alt_rule, pdf_link_margin); - k = pdf_create_obj(pdf, obj_type_others, 0); - obj_annot_ptr(pdf, k) = p; - set_obj_scheduled(pdf, pdf_link_objnum(p)); - addto_page_resources(pdf, obj_type_link, k); -} - -void scan_startlink(PDF pdf) -{ - int k; - halfword r; - if (abs(cur_list.mode_field) == vmode) - normal_error("pdf backend", "startlink cannot be used in vertical mode"); - k = pdf_create_obj(pdf, obj_type_others, 0); - new_annot_whatsit(pdf_start_link_node); - set_pdf_link_attr(cur_list.tail_field, null); - if (scan_keyword("attr")) { - scan_toks(false, true); - set_pdf_link_attr(cur_list.tail_field, def_ref); - } - r = scan_action(pdf); - set_pdf_link_action(cur_list.tail_field, r); - set_pdf_link_objnum(cur_list.tail_field, k); - pdf_last_link = k; - /*tex - Although it is possible to set |obj_annot_ptr(k) := tail| here, it is not - safe if nodes are later copied/destroyed/moved; a better place to do this - is inside |do_link|, when the whatsit node is written out. - */ -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdflink.h b/Build/source/texk/web2c/luatexdir/pdf/pdflink.h deleted file mode 100644 index ed96beab3dc..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdflink.h +++ /dev/null @@ -1,37 +0,0 @@ -/* pdflink.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef PDFLINK_H -# define PDFLINK_H - -# define set_pdf_link_attr(A,B) pdf_link_attr(A)=B -# define set_pdf_link_action(A,B) pdf_link_action(A)=B -# define set_pdf_link_objnum(A,B) pdf_link_objnum(A)=B - -extern void push_link_level(PDF pdf, halfword p); -extern void pop_link_level(PDF pdf); -extern void do_link(PDF pdf, halfword p, halfword parent_box, scaledpos cur); -extern void pdf_out_link_state(PDF pdf, halfword p); -extern void end_link(PDF pdf, halfword p); -extern void append_link(PDF pdf, halfword parent_box, scaledpos cur, small_number i); -extern void scan_startlink(PDF pdf); - - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdflistout.c b/Build/source/texk/web2c/luatexdir/pdf/pdflistout.c deleted file mode 100644 index 02c7025c330..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdflistout.c +++ /dev/null @@ -1,1090 +0,0 @@ -/* - -Copyright 2009-2010 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -#define kern_width(q) width(q) + ex_kern(q) - -#define billion 1000000000.0 - -#define vet_glue(A) do { \ - glue_temp=A; \ - if (glue_temp>billion) \ - glue_temp=billion; \ - else if (glue_temp<-billion) \ - glue_temp=-billion; \ - } while (0) - -/*tex - - This code scans forward to the ending |dir_node| while keeping track of the - needed width in |w|. When it finds the node that will end this segment, it - stores the accumulated with in the |dir_dvi_h| field of that end node, so - that when that node is found later in the processing, the correct glue - correction can be applied (obsolete). - -*/ - -static scaled simple_advance_width(halfword p) -{ - halfword q = p; - scaled w = 0; - while ((q != null) && (vlink(q) != null)) { - q = vlink(q); - switch (type(q)) { - case glyph_node: - w += glyph_width(q); - break; - case hlist_node: - case vlist_node: - case rule_node: - case margin_kern_node: - w += width(q); - break; - case kern_node: - /*tex Officially we should check the subtype. */ - w += kern_width(q); - break; - case disc_node: - /* (HH): The frontend should append already. */ - if (vlink(no_break(q)) != null) - w += simple_advance_width(no_break(q)); - default: - break; - } - } - return w; -} - -static halfword calculate_width_to_enddir(halfword p, real cur_glue, scaled cur_g, halfword this_box) -{ - int dir_nest = 1; - halfword q = p, enddir_ptr = p; - scaled w = 0; - /*tex The glue value before rounding: */ - real glue_temp; - int g_sign = glue_sign(this_box); - int g_order = glue_order(this_box); - while ((q != null) && (vlink(q) != null)) { - q = vlink(q); - if (is_char_node(q)) - w += pack_width(box_dir(this_box), dir_TRT, q, true); - else { - switch (type(q)) { - case hlist_node: - case vlist_node: - w += pack_width(box_dir(this_box), box_dir(q), q, false); - break; - case rule_node: - case margin_kern_node: - w += width(q); - break; - case kern_node: - /*tex Officially we should check the subtype. */ - w += kern_width(q); - break; - case math_node: - /*tex Begin of |mathskip| code. */ - if (glue_is_zero(q)) { - w += surround(q); - break; - } else { - /*tex Fall through |mathskip|. */ - } - /*tex End of |mathskip| code. */ - case glue_node: - w += width(q) - cur_g; - if (g_sign != normal) { - if (g_sign == stretching) { - if (stretch_order(q) == g_order) { - cur_glue = cur_glue + stretch(q); - vet_glue(float_cast(glue_set(this_box)) * cur_glue); - cur_g = float_round(glue_temp); - } - } else if (shrink_order(q) == g_order) { - cur_glue = cur_glue - shrink(q); - vet_glue(float_cast(glue_set(this_box)) * cur_glue); - cur_g = float_round(glue_temp); - } - } - w += cur_g; - break; - case disc_node: - /* (HH): The frontend should append already. */ - if (vlink(no_break(q)) != null) - w += simple_advance_width(no_break(q)); - break; - case dir_node: - if (subtype(q) == normal_dir) - dir_nest++; - else - dir_nest--; - if (dir_nest == 0) { - enddir_ptr = q; - dir_cur_h(enddir_ptr) = w; - q = null; - } - break; - default: - break; - } - } - } - if (enddir_ptr == p) - /*tex No enddir found, just transport |w| by |begindir|. */ - dir_cur_h(enddir_ptr) = w; - return enddir_ptr; -} - -/*tex - - The |out_what| procedure takes care of outputting the whatsit nodes for - |vlist_out| and |hlist_out|, which are similar for either case. - - We don't implement \.{\\write} inside of leaders. (The reason is that the - number of times a leader box appears might be different in different - implementations, due to machine-dependent rounding in the glue calculations.) - -*/ - -static void handle_backend_whatsit(PDF pdf, halfword p, halfword parent_box, scaledpos cur) -{ - if (output_mode_used == OMODE_PDF) { - switch (subtype(p)) { - case pdf_literal_node: - case pdf_save_node: - case pdf_restore_node: - case pdf_setmatrix_node: - case pdf_colorstack_node: - case pdf_refobj_node: - case pdf_end_link_node: - case pdf_end_thread_node: - case pdf_link_state_node: - backend_out_whatsit[subtype(p)](pdf, p); - break; - case pdf_annot_node: - case pdf_start_link_node: - case pdf_dest_node: - case pdf_start_thread_node: - case pdf_thread_node: - backend_out_whatsit[subtype(p)](pdf, p, parent_box, cur); - break; - default: - /*tex We ignore bad ones. */ - break; - } - } -} - -void hlist_out(PDF pdf, halfword this_box, int rule_callback_id) -{ - /*tex the position structure local within this function */ - posstructure localpos; - /*tex the list origin pos. on the page, provided by the caller */ - posstructure *refpos; - /*tex A few status variables. */ - scaledpos cur = { 0, 0 }, tmpcur, basepoint; - /*tex rule dimensions */ - scaledpos size = { 0, 0 }; - scaled effective_horizontal; - /*tex what |cur.h| should pop to */ - scaled save_h; - /*tex right edge of sub-box or leader space */ - scaled edge; - /*tex temporary pointer to enddir node */ - halfword enddir_ptr; - /*tex applicable order of infinity for glue */ - int g_order; - /*tex selects type of glue */ - int g_sign; - /*tex glue variables */ - int lq, lr; - /*tex current position in the hlist */ - halfword p, q; - /*tex the leader box being replicated */ - halfword leader_box; - /*tex width of leader box being replicated */ - scaled leader_wd; - /*tex extra space between leader boxes */ - scaled lx; - /*tex were we doing leaders? */ - boolean outer_doing_leaders; - /*tex glue value before rounding */ - real glue_temp; - /*tex glue seen so far */ - real cur_glue = 0.0; - /*tex rounded equivalent of |cur_glue| times the glue ratio */ - scaled cur_g = 0; - scaled_whd rule, ci; - /*tex index to scan |pdf_link_stack| */ - int i; - /*tex DVI! \.{DVI} byte location upon entry */ - int saved_loc = 0; - /*tex safeguard */ - int dir_done = 0; - /*tex DVI! what |dvi| should pop to */ - scaledpos saved_pos = { 0, 0 }; - int synctex = synctex_par ; - scaled rleft, rright; - g_order = glue_order(this_box); - g_sign = glue_sign(this_box); - p = list_ptr(this_box); - refpos = pdf->posstruct; - /*tex use local structure for recursion */ - pdf->posstruct = &localpos; - localpos.pos = refpos->pos; - localpos.dir = box_dir(this_box); - cur_s++; - backend_out_control[backend_control_push_list](pdf,&saved_pos,&saved_loc); - for (i = 1; i <= pdf->link_stack_ptr; i++) { - if (pdf->link_state == 1) { - /* - We ignore this link. This is a compatibility-with-pdftex feature needed for latex. It - is suboptimal in the sense that when the whatsit is set, the next box is influenced, - so there there can be side effects when used in the middle of a line, when using - vadjust, etc. But we can assume that tha macro package knows when and where this - mechanism is triggered, so a more sophisticated solution is not needed (and would be - confusing in its own anyway.) - - I would not be surprised of we have some leak here but it's harmless. - */ - } else if (pdf->link_stack[i].nesting_level == cur_s) { - append_link(pdf, this_box, cur, (small_number) i); - } - } - if (synctex) { - synctexhlist(this_box); - } - while (p != null) { - if (is_char_node(p)) { - do { - if (x_displace(p) != 0 || y_displace(p) != 0) { - tmpcur.h = cur.h + x_displace(p); - tmpcur.v = cur.v - y_displace(p); - synch_pos_with_cur(pdf->posstruct, refpos, tmpcur); - } - ci = output_one_char(pdf, p); - if (textdir_parallel(localpos.dir, dir_TLT)) { - cur.h += ci.wd; - } else { - cur.h += ci.ht + ci.dp; - } - synch_pos_with_cur(pdf->posstruct, refpos, cur); - p = vlink(p); - } while (is_char_node(p)); - if (synctex) - synctexcurrent(); - } else { - /*tex - Output the non-|char_node| |p| for |hlist_out| and move to the - next node. - */ - switch (type(p)) { - case hlist_node: - case vlist_node: - if (textdir_parallel(box_dir(p), localpos.dir)) { - effective_horizontal = width(p); - basepoint.v = 0; - if (textdir_opposite(box_dir(p), localpos.dir)) - basepoint.h = width(p); - else - basepoint.h = 0; - } else { - effective_horizontal = height(p) + depth(p); - if (!is_mirrored(box_dir(p))) { - if (partextdir_eq(box_dir(p), localpos.dir)) - basepoint.h = height(p); - else - basepoint.h = depth(p); - } else { - if (partextdir_eq(box_dir(p), localpos.dir)) - basepoint.h = depth(p); - else - basepoint.h = height(p); - } - if (is_rotated(localpos.dir)) { - if (partextdir_eq(localpos.dir, box_dir(p))) { - /*tex up */ - basepoint.v = -width(p) / 2; - } else { - /*tex down */ - basepoint.v = width(p) / 2; - } - } else if (is_mirrored(localpos.dir)) { - if (partextdir_eq(localpos.dir, box_dir(p))) { - basepoint.v = 0; - } else { - /*tex down */ - basepoint.v = width(p); - } - } else { - if (partextdir_eq(localpos.dir, box_dir(p))) { - /*tex up */ - basepoint.v = -width(p); - } else { - basepoint.v = 0; - } - } - } - if (!is_mirrored(localpos.dir)) { - /*tex Shift the box down. */ - basepoint.v = basepoint.v + shift_amount(p); - } else { - /*tex Shift the box up. */ - basepoint.v = basepoint.v - shift_amount(p); - } - if (list_ptr(p) == null) { - if (synctex) { - if (type(p) == vlist_node) - synctexvoidvlist(p, this_box); - else - synctexvoidhlist(p, this_box); - } - } else { - tmpcur.h = cur.h + basepoint.h; - tmpcur.v = basepoint.v; - synch_pos_with_cur(pdf->posstruct, refpos, tmpcur); - if (type(p) == vlist_node) - vlist_out(pdf, p, rule_callback_id); - else - hlist_out(pdf, p, rule_callback_id); - } - cur.h += effective_horizontal; - break; - case disc_node: - /*tex (HH): the frontend should append already */ - if (vlink(no_break(p)) != null) { - if (subtype(p) != select_disc) { - /*tex This could be a |tlink|. */ - q = tail_of_list(vlink(no_break(p))); - vlink(q) = vlink(p); - q = vlink(no_break(p)); - vlink(no_break(p)) = null; - vlink(p) = q; - } - } - break; - case math_node: - if (synctex) { - synctexmath(p, this_box); - } - /*tex Begin |mathskip| code. */ - if (glue_is_zero(p)) { - cur.h += surround(p); - break; - } else { - /*tex Fall through |mathskip|. */ - } - /*tex End |mathskip| code. */ - case glue_node: - { - /*tex - Move right or output leaders, we use real - multiplication. - */ - rule.wd = width(p) - cur_g; - if (g_sign != normal) { - if (g_sign == stretching) { - if (stretch_order(p) == g_order) { - cur_glue = cur_glue + stretch(p); - vet_glue(float_cast(glue_set(this_box)) * cur_glue); - cur_g = float_round(glue_temp); - } - } else if (shrink_order(p) == g_order) { - cur_glue = cur_glue - shrink(p); - vet_glue(float_cast(glue_set(this_box)) * cur_glue); - cur_g = float_round(glue_temp); - } - } - rule.wd = rule.wd + cur_g; - if (subtype(p) >= a_leaders) { - /*tex - Output leaders in an hlist, |goto fin_rule| if a rule - or to |next_p| if done. - */ - leader_box = leader_ptr(p); - if (type(leader_box) == rule_node) { - rule.ht = height(leader_box); - rule.dp = depth(leader_box); - rleft = 0; - rright = 0; - goto FIN_RULE; - } - if (textdir_parallel(box_dir(leader_box), localpos.dir)) - leader_wd = width(leader_box); - else - leader_wd = height(leader_box) + depth(leader_box); - if ((leader_wd > 0) && (rule.wd > 0)) { - /*tex Compensate for floating-point rounding. */ - rule.wd = rule.wd + 10; - edge = cur.h + rule.wd; - lx = 0; - /*tex - Let |cur.h| be the position of the first box, and - set |leader_wd+lx| to the spacing between - corresponding parts of boxes. - */ - if (subtype(p) == g_leaders) { - save_h = cur.h; - switch (localpos.dir) { - case dir_TLT: - cur.h += refpos->pos.h - shipbox_refpos.h; - cur.h = leader_wd * (cur.h / leader_wd); - cur.h -= refpos->pos.h - shipbox_refpos.h; - break; - case dir_TRT: - cur.h = refpos->pos.h - shipbox_refpos.h - cur.h; - cur.h = leader_wd * (cur.h / leader_wd); - cur.h = refpos->pos.h - shipbox_refpos.h - cur.h; - break; - case dir_LTL: - case dir_RTT: - cur.h = refpos->pos.v - shipbox_refpos.v - cur.h; - cur.h = leader_wd * (cur.h / leader_wd); - cur.h = refpos->pos.v - shipbox_refpos.v - cur.h; - break; - default: - formatted_warning("pdf backend","forcing bad dir %i to TLT in hlist case 1",localpos.dir); - localpos.dir = dir_TLT; - cur.h += refpos->pos.h - shipbox_refpos.h; - cur.h = leader_wd * (cur.h / leader_wd); - cur.h -= refpos->pos.h - shipbox_refpos.h; - break; - } - if (cur.h < save_h) - cur.h += leader_wd; - } else if (subtype(p) == a_leaders) { - save_h = cur.h; - cur.h = leader_wd * (cur.h / leader_wd); - if (cur.h < save_h) - cur.h += leader_wd; - } else { - /*tex The number of box copies: */ - lq = rule.wd / leader_wd; - /*tex The remaining space: */ - lr = rule.wd % leader_wd; - if (subtype(p) == c_leaders) { - cur.h += lr / 2; - } else { - lx = lr / (lq + 1); - cur.h += (lr - (lq - 1) * lx) / 2; - } - } - while (cur.h + leader_wd <= edge) { - /*tex - Output a leader box at |cur.h|, then advance - |cur.h| by |leader_wd+lx|. - */ - if (pardir_parallel(box_dir(leader_box), localpos.dir)) { - basepoint.v = 0; - if (textdir_opposite(box_dir(leader_box), localpos.dir)) - basepoint.h = width(leader_box); - else - basepoint.h = 0; - } else { - if (!is_mirrored(box_dir(leader_box))) { - if (partextdir_eq(box_dir(leader_box), localpos.dir)) - basepoint.h = height(leader_box); - else - basepoint.h = depth(leader_box); - } else { - if (partextdir_eq(box_dir(leader_box), localpos.dir)) - basepoint.h = depth(leader_box); - else - basepoint.h = height(leader_box); - } - if (partextdir_eq(localpos.dir, box_dir(leader_box))) - basepoint.v = -(width(leader_box) / 2); - else - basepoint.v = (width(leader_box) / 2); - } - if (!is_mirrored(localpos.dir)) - basepoint.v = basepoint.v + shift_amount(leader_box); /* shift the box down */ - else - basepoint.v = basepoint.v - shift_amount(leader_box); /* shift the box up */ - tmpcur.h = cur.h + basepoint.h; - tmpcur.v = basepoint.v; - synch_pos_with_cur(pdf->posstruct, refpos, tmpcur); - outer_doing_leaders = doing_leaders; - doing_leaders = true; - if (type(leader_box) == vlist_node) - vlist_out(pdf, leader_box, rule_callback_id); - else - hlist_out(pdf, leader_box, rule_callback_id); - doing_leaders = outer_doing_leaders; - cur.h += leader_wd + lx; - } - cur.h = edge - 10; - goto NEXTP; - } - } - } - goto MOVE_PAST; - break; - case kern_node: - if (synctex) - synctexkern(p, this_box); - /*tex officially we should check the subtype */ - cur.h += kern_width(p); - break; - case rule_node: - if (rule_dir(p) < 0) - rule_dir(p) = localpos.dir; - if (pardir_parallel(rule_dir(p), localpos.dir)) { - rule.ht = height(p); - rule.dp = depth(p); - rule.wd = width(p); - } else { - rule.ht = width(p) / 2; - rule.dp = width(p) / 2; - rule.wd = height(p) + depth(p); - } - rleft = rule_left(p); - rright = rule_right(p); - goto FIN_RULE; - break; - case dir_node: - /*tex - Output a reflection instruction if the direction has changed. - */ - if (subtype(p) == normal_dir) { - /*tex - Calculate the needed width to the matching |enddir|, return the - |enddir| node, with width info. - */ - enddir_ptr = calculate_width_to_enddir(p, cur_glue, cur_g, this_box); - if (textdir_parallel(dir_dir(p), localpos.dir)) { - dir_cur_h(enddir_ptr) += cur.h; - if (textdir_opposite(dir_dir(p), localpos.dir)) - cur.h = dir_cur_h(enddir_ptr); - } else - dir_cur_h(enddir_ptr) = cur.h; - if (enddir_ptr != p) { - /*tex Only if it is an |enddir|. */ - dir_cur_v(enddir_ptr) = cur.v; - dir_refpos_h(enddir_ptr) = refpos->pos.h; - dir_refpos_v(enddir_ptr) = refpos->pos.v; - /*tex Negative: mark it as |enddir|. */ - dir_dir(enddir_ptr) = localpos.dir; - } - /*tex fake a nested |hlist_out|. */ - synch_pos_with_cur(pdf->posstruct, refpos, cur); - refpos->pos = pdf->posstruct->pos; - localpos.dir = dir_dir(p); - cur.h = 0; - cur.v = 0; - dir_done = 1; - } else if (dir_done) { - refpos->pos.h = dir_refpos_h(p); - refpos->pos.v = dir_refpos_v(p); - localpos.dir = dir_dir(p); - cur.h = dir_cur_h(p); - cur.v = dir_cur_v(p); - } else { - /*tex maybe issue a warning */ - } - break; - case whatsit_node: - /*tex Output the whatsit node |p| in |hlist_out|. */ - if (subtype(p) <= last_common_whatsit) { - switch (subtype(p)) { - case save_pos_node: - last_position = pdf->posstruct->pos; - /* - pos_info.curpos = pdf->posstruct->pos; - pos_info.boxpos.pos = refpos->pos; - pos_info.boxpos.dir = localpos.dir; - pos_info.boxdim.wd = width(this_box); - pos_info.boxdim.ht = height(this_box); - pos_info.boxdim.dp = depth(this_box); - */ - break; - case user_defined_node: - break; - case open_node: - case write_node: - case close_node: - wrapup_leader(p); - break; - case special_node: - /*tex |pdf_special(pdf, p)| */ - case late_lua_node: - /*tex |late_lua(pdf, p)| */ - backend_out_whatsit[subtype(p)] (pdf, p); - break; - default: - break; - } - } else { - handle_backend_whatsit(pdf, p, this_box, cur); - } - break; - case margin_kern_node: - cur.h += width(p); - break; - default: - break; - } - goto NEXTP; - FIN_RULE: - /*tex Output a rule in an hlist. */ - if (is_running(rule.ht)) { - rule.ht = height(this_box); - } - if (rleft != 0) { - rule.ht -= rleft; - pos_down(-rleft); - } - if (is_running(rule.dp)) { - rule.dp = depth(this_box); - } - if (rright != 0) { - rule.dp -= rright; - } - /*tex We don't output empty rules. */ - if ((rule.ht + rule.dp) > 0 && rule.wd > 0) { - switch (localpos.dir) { - case dir_TLT: - size.h = rule.wd; - size.v = rule.ht + rule.dp; - pos_down(rule.dp); - break; - case dir_TRT: - size.h = rule.wd; - size.v = rule.ht + rule.dp; - pos_left(size.h); - pos_down(rule.dp); - break; - case dir_LTL: - size.h = rule.ht + rule.dp; - size.v = rule.wd; - pos_left(rule.ht); - pos_down(size.v); - break; - case dir_RTT: - size.h = rule.ht + rule.dp; - size.v = rule.wd; - pos_left(rule.dp); - pos_down(size.v); - break; - default: - formatted_warning("pdf backend","forcing bad dir %i to TLT in hlist case 2",localpos.dir); - localpos.dir = dir_TLT; - size.h = rule.wd; - size.v = rule.ht + rule.dp; - pos_down(rule.dp); - break; - } - if (type(p) == glue_node) { - q = leader_ptr(p); - if ((q) && (type(q) == rule_node)) { - backend_out[rule_node] (pdf, q, size, rule_callback_id); - } - } else { - backend_out[rule_node] (pdf, p, size, rule_callback_id); - } - } - MOVE_PAST: - cur.h += rule.wd; - if (synctex) { - synch_pos_with_cur(pdf->posstruct, refpos, cur); - synctexhorizontalruleorglue(p, this_box); - } - NEXTP: - p = vlink(p); - synch_pos_with_cur(pdf->posstruct, refpos, cur); - } - } - if (synctex) { - synctextsilh(this_box); - } - backend_out_control[backend_control_pop_list](pdf,&saved_pos,&saved_loc); - cur_s--; - pdf->posstruct = refpos; -} - -void vlist_out(PDF pdf, halfword this_box, int rule_callback_id) -{ - /*tex The position structure local within this function: */ - posstructure localpos; - /*tex The list origin pos. on the page, provided by the caller: */ - posstructure *refpos; - /*tex a few status variables */ - scaledpos cur, tmpcur, basepoint; - /*tex rule dimensions */ - scaledpos size = { 0, 0 }; - scaled effective_vertical; - /*tex what |cur.v| should pop to */ - scaled save_v; - /*tex the top coordinate for this box */ - scaled top_edge; - /*tex bottom boundary of leader space */ - scaled edge; - /*tex applicable order of infinity for glue */ - glue_ord g_order; - /*tex selects type of glue */ - int g_sign; - /*tex glue variables */ - int lq, lr; - /*tex current position in the vlist */ - halfword p; - /*tex temp */ - halfword q; - /*tex the leader box being replicated */ - halfword leader_box; - /*tex height of leader box being replicated */ - scaled leader_ht; - /*tex extra space between leader boxes */ - scaled lx; - /*tex were we doing leaders? */ - boolean outer_doing_leaders; - /*tex glue value before rounding */ - real glue_temp; - /*tex glue seen so far */ - real cur_glue = 0.0; - /*tex rounded equivalent of |cur_glue| times the glue ratio */ - scaled cur_g = 0; - scaled_whd rule; - /*tex \DVI\ byte location upon entry */ - int saved_loc = 0; - /*tex \DVI\ what |dvi| should pop to */ - scaledpos saved_pos = { 0, 0 }; - int synctex = synctex_par ; - int rleft, rright; - g_order = (glue_ord) glue_order(this_box); - g_sign = glue_sign(this_box); - p = list_ptr(this_box); - cur.h = 0; - cur.v = -height(this_box); - top_edge = cur.v; - refpos = pdf->posstruct; - /*tex Use local structure for recursion. */ - pdf->posstruct = &localpos; - localpos.dir = box_dir(this_box); - synch_pos_with_cur(pdf->posstruct, refpos, cur); - cur_s++; - backend_out_control[backend_control_push_list](pdf,&saved_pos,&saved_loc); - if (synctex) { - synctexvlist(this_box); - } - /*tex Create thread for the current vbox if needed. */ - check_running_thread(pdf, this_box, cur); - while (p != null) { - switch (type(p)) { - case hlist_node: - case vlist_node: - /*tex Output a box in a vlist. */ - if (pardir_parallel(box_dir(p), localpos.dir)) { - effective_vertical = height(p) + depth(p); - if ((type(p) == hlist_node) && is_mirrored(box_dir(p))) - basepoint.v = depth(p); - else - basepoint.v = height(p); - if (textdir_opposite(box_dir(p), localpos.dir)) - basepoint.h = width(p); - else - basepoint.h = 0; - } else { - effective_vertical = width(p); - if (!is_mirrored(box_dir(p))) { - if (partextdir_eq(box_dir(p), localpos.dir)) - basepoint.h = height(p); - else - basepoint.h = depth(p); - } else { - if (partextdir_eq(box_dir(p), localpos.dir)) - basepoint.h = depth(p); - else - basepoint.h = height(p); - } - if (partextdir_eq(localpos.dir, box_dir(p))) - basepoint.v = 0; - else - basepoint.v = width(p); - } - /*tex Shift the box right. */ - basepoint.h = basepoint.h + shift_amount(p); - if (list_ptr(p) == null) { - cur.v += effective_vertical; - if (synctex) { - synch_pos_with_cur(pdf->posstruct, refpos, cur); - if (type(p) == vlist_node) - synctexvoidvlist(p, this_box); - else - synctexvoidhlist(p, this_box); - } - } else { - tmpcur.h = basepoint.h; - tmpcur.v = cur.v + basepoint.v; - synch_pos_with_cur(pdf->posstruct, refpos, tmpcur); - if (type(p) == vlist_node) - vlist_out(pdf, p, rule_callback_id); - else - hlist_out(pdf, p, rule_callback_id); - cur.v += effective_vertical; - } - break; - case rule_node: - if (rule_dir(p) < 0) - rule_dir(p) = localpos.dir; - if (pardir_parallel(rule_dir(p), localpos.dir)) { - rule.ht = height(p); - rule.dp = depth(p); - rule.wd = width(p); - } else { - rule.ht = width(p) / 2; - rule.dp = width(p) / 2; - rule.wd = height(p) + depth(p); - } - rleft = rule_left(p); - rright = rule_right(p); - goto FIN_RULE; - break; - case glue_node: - { - /*tex - Move down or output leaders, we use real multiplication. - */ - rule.ht = width(p) - cur_g; - if (g_sign != normal) { - if (g_sign == stretching) { - if (stretch_order(p) == g_order) { - cur_glue = cur_glue + stretch(p); - vet_glue(float_cast(glue_set(this_box)) * cur_glue); - cur_g = float_round(glue_temp); - } - } else if (shrink_order(p) == g_order) { - cur_glue = cur_glue - shrink(p); - vet_glue(float_cast(glue_set(this_box)) * cur_glue); - cur_g = float_round(glue_temp); - } - } - rule.ht = rule.ht + cur_g; - if (subtype(p) >= a_leaders) { - /*tex - Output leaders in a vlist, |goto fin_rulefin_rule| if a - rule or to |next_p| if done. - */ - leader_box = leader_ptr(p); - if (type(leader_box) == rule_node) { - rule.wd = width(leader_box); - rule.dp = 0; - rleft = 0; - rright = 0; - goto FIN_RULE; - } - leader_ht = height(leader_box) + depth(leader_box); - if ((leader_ht > 0) && (rule.ht > 0)) { - /*tex Compensate for floating-point rounding: */ - rule.ht = rule.ht + 10; - edge = cur.v + rule.ht; - lx = 0; - /*tex - Let |cur.v| be the position of the first box, and set - |leader_ht+lx| to the spacing between corresponding - parts of boxes. - */ - if (subtype(p) == g_leaders) { - save_v = cur.v; - switch (localpos.dir) { - case dir_TLT: - case dir_TRT: - cur.v = refpos->pos.v - shipbox_refpos.v - cur.v; - cur.v = leader_ht * (cur.v / leader_ht); - cur.v = refpos->pos.v - shipbox_refpos.v - cur.v; - break; - case dir_LTL: - cur.v += refpos->pos.h - shipbox_refpos.h; - cur.v = leader_ht * (cur.v / leader_ht); - cur.v -= refpos->pos.h - shipbox_refpos.h; - break; - case dir_RTT: - cur.v = refpos->pos.h - shipbox_refpos.h - cur.v; - cur.v = leader_ht * (cur.v / leader_ht); - cur.v = refpos->pos.h - shipbox_refpos.h - cur.v; - break; - default: - formatted_warning("pdf backend","forcing bad dir %i to TLT in vlist case 1",localpos.dir); - localpos.dir = dir_TLT; - cur.v += refpos->pos.h - shipbox_refpos.h; - cur.v = leader_ht * (cur.v / leader_ht); - cur.v -= refpos->pos.h - shipbox_refpos.h; - break; - } - if (cur.v < save_v) - cur.v += leader_ht; - } else if (subtype(p) == a_leaders) { - save_v = cur.v; - cur.v = top_edge + leader_ht * ((cur.v - top_edge) / leader_ht); - if (cur.v < save_v) - cur.v += leader_ht; - } else { - /*tex The number of box copies. */ - lq = rule.ht / leader_ht; - /*tex The remaining space. */ - lr = rule.ht % leader_ht; - if (subtype(p) == c_leaders) { - cur.v += lr / 2; - } else { - lx = lr / (lq + 1); - cur.v += (lr - (lq - 1) * lx) / 2; - } - } - while (cur.v + leader_ht <= edge) { - /*tex - Output a leader box at |cur.v|, then advance - |cur.v| by |leader_ht+lx|. - */ - tmpcur.h = shift_amount(leader_box); - tmpcur.v = cur.v + height(leader_box); - synch_pos_with_cur(pdf->posstruct, refpos, tmpcur); - outer_doing_leaders = doing_leaders; - doing_leaders = true; - if (type(leader_box) == vlist_node) - vlist_out(pdf, leader_box, rule_callback_id); - else - hlist_out(pdf, leader_box, rule_callback_id); - doing_leaders = outer_doing_leaders; - cur.v += leader_ht + lx; - } - cur.v = edge - 10; - goto NEXTP; - } - } - } - goto MOVE_PAST; - break; - case kern_node: - cur.v += width(p); - break; - case whatsit_node: - /*tex Output the whatsit node |p| in |vlist_out|. */ - if (subtype(p) <= last_common_whatsit) { - switch (subtype(p)) { - case save_pos_node: - last_position = pdf->posstruct->pos; - /* - pos_info.curpos = pdf->posstruct->pos; - pos_info.boxpos.pos = refpos->pos; - pos_info.boxpos.dir = localpos.dir; - pos_info.boxdim.wd = width(this_box); - pos_info.boxdim.ht = height(this_box); - pos_info.boxdim.dp = depth(this_box); - */ - break; - case user_defined_node: - break; - case open_node: - case write_node: - case close_node: - wrapup_leader(p); - break; - case special_node: - /*tex |pdf_special(pdf, p)|; */ - case late_lua_node: - /*tex |late_lua(pdf, p)|; */ - backend_out_whatsit[subtype(p)] (pdf, p); - break; - default: - break; - } - } else { - handle_backend_whatsit(pdf, p, this_box, cur); - } - break; - case glyph_node: - case disc_node: - /*tex This can't happen unless one messes up in \LUA. */ - confusion("vlistout"); - break; - default: - break; - } - goto NEXTP; - FIN_RULE: - /*tex Output a rule in a vlist and |goto next_p|. */ - if (is_running(rule.wd)) { - rule.wd = width(this_box); - } - if (rleft != 0) { - rule.wd -= rleft; - pos_left(-rleft); - } - if (rright != 0) { - rule.wd -= rright; - } - /*tex We don't output empty rules. */ - if ((rule.ht + rule.dp) > 0 && rule.wd > 0) { - switch (localpos.dir) { - case dir_TLT: - size.h = rule.wd; - size.v = rule.ht + rule.dp; - pos_down(size.v); - break; - case dir_TRT: - size.h = rule.wd; - size.v = rule.ht + rule.dp; - pos_left(size.h); - pos_down(size.v); - break; - case dir_LTL: - size.h = rule.ht + rule.dp; - size.v = rule.wd; - pos_down(size.v); - break; - case dir_RTT: - size.h = rule.ht + rule.dp; - size.v = rule.wd; - pos_left(size.h); - pos_down(size.v); - break; - default: - formatted_warning("pdf backend","forcing bad dir %i to TLT in vlist case 2",localpos.dir); - localpos.dir = dir_TLT; - size.h = rule.wd; - size.v = rule.ht + rule.dp; - pos_down(size.v); - break; - } - if (type(p) == glue_node) { - q = leader_ptr(p); - if ((q) && (type(q) == rule_node)) { - backend_out[rule_node] (pdf, q, size, rule_callback_id); - } - } else { - backend_out[rule_node] (pdf, p, size, rule_callback_id); - } - } - cur.v += rule.ht + rule.dp; - goto NEXTP; - MOVE_PAST: - cur.v += rule.ht; - NEXTP: - p = vlink(p); - synch_pos_with_cur(pdf->posstruct, refpos, cur); - } - if (synctex) { - synctextsilv(this_box); - } - backend_out_control[backend_control_pop_list](pdf,&saved_pos,&saved_loc); - cur_s--; - pdf->posstruct = refpos; -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdflistout.h b/Build/source/texk/web2c/luatexdir/pdf/pdflistout.h deleted file mode 100644 index dd3775816a3..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdflistout.h +++ /dev/null @@ -1,32 +0,0 @@ -/* pdflistout.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef PDFLISTOUT_H -# define PDFLISTOUT_H - -#define pos_right(A) pdf->posstruct->pos.h = pdf->posstruct->pos.h + (A) -#define pos_left(A) pdf->posstruct->pos.h = pdf->posstruct->pos.h - (A) -#define pos_up(A) pdf->posstruct->pos.v = pdf->posstruct->pos.v + (A) -#define pos_down(A) pdf->posstruct->pos.v = pdf->posstruct->pos.v - (A) - -extern void hlist_out(PDF pdf, halfword this_box, int rule_callback_id); -extern void vlist_out(PDF pdf, halfword this_box, int rule_callback_id); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.c b/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.c deleted file mode 100644 index e8b00a64ef5..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - -Copyright 2009-2010 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -void pdf_special(PDF pdf, halfword p) -{ - int old_setting = selector; - str_number s; - selector = new_string; - show_token_list(token_link(write_tokens(p)), null, -1); - selector = old_setting; - s = make_string(); - pdf_literal(pdf, s, scan_special, true); - flush_str(s); -} - -/*tex - - To ship out a \TeX\ box to PDF page description we need to implement - |hlist_out|, |vlist_out| and |ship_out|, which are equivalent to the \TeX' - original |hlist_out|, |vlist_out| and |ship_out| resp. But first we need to - declare some procedures needed in |hlist_out| and |vlist_out|. - -*/ - -void pdf_out_literal(PDF pdf, halfword p) -{ - int old_setting; - str_number s; - int t = pdf_literal_type(p); - pdfstructure *ps = pdf->pstruct; - if (t == normal) { - old_setting = selector; - selector = new_string; - show_token_list(token_link(pdf_literal_data(p)), null, -1); - selector = old_setting; - s = make_string(); - pdf_literal(pdf, s, pdf_literal_mode(p), false); - flush_str(s); - } else if (t == lua_refid_literal) { - switch (pdf_literal_mode(p)) { - case set_origin: - pdf_goto_pagemode(pdf); - pdf_set_pos(pdf, pdf->posstruct->pos); - break; - case direct_page: - pdf_goto_pagemode(pdf); - break; - case direct_text: - pdf_goto_textmode(pdf); - break; - case direct_font: - pdf_goto_fontmode(pdf); - break; - case direct_always: - pdf_end_string_nl(pdf); - ps->need_tm = true; - break; - case direct_raw: - pdf_end_string_nl(pdf); - break; - default: - normal_error("pdf backend","bad literal mode"); - break; - } - lua_pdf_literal(pdf, pdf_literal_data(p), 0); - } -} - -/*tex Test equality of start of strings: */ - -static boolean str_in_cstr(str_number s, const char *r, unsigned i) -{ - const unsigned char *k, *l; - if ((unsigned) str_length(s) < i + strlen(r)) - return false; - k = (const unsigned char *) r; - l = str_string(s) + i; - while ((*l) && (*k)) { - if (*l++ != *k++) - return false; - } - return true; -} - -void pdf_literal(PDF pdf, str_number s, int literal_mode, boolean warn) -{ - unsigned char *ss; - size_t l; - /*tex - The current character code position, initialized to make the compiler - happy: - */ - pool_pointer j = 0; - pdfstructure *p = pdf->pstruct; - if (s >= STRING_OFFSET) { - /*tex Needed for |out_save|: */ - j = 0; - /*tex - Unfortunately we always go through this when we have vf specials (and - also via temp strings): - */ - if (literal_mode == scan_special) { - if (!(str_in_cstr(s, "pdf:", 0) || str_in_cstr(s, "PDF:", 0))) { - if (warn && ((!(str_in_cstr(s, "src:", 0) || str_in_cstr(s, "SRC:", 0))) || (str_length(s) == 0))) - tprint_nl("Non-PDF special ignored!"); - return; - } - /*tex |strlen("PDF:")| */ - j = j + (pool_pointer) 4; - if (str_in_cstr(s, "direct:", 4)) { - /*tex |strlen("direct:")| */ - j = j + (pool_pointer) 7; - literal_mode = direct_always; - } else if (str_in_cstr(s, "page:", 4)) { - /*tex |strlen("page:")| */ - j = j + (pool_pointer) 5; - literal_mode = direct_page; - } else if (str_in_cstr(s, "text:", 4)) { - /*tex |strlen("text:")| */ - j = j + (pool_pointer) 5; - literal_mode = direct_text; - } else if (str_in_cstr(s, "raw:", 4)) { - /*tex |strlen("raw:")| */ - j = j + (pool_pointer) 4; - literal_mode = direct_raw; - } else if (str_in_cstr(s, "origin:", 4)) { - /*tex |strlen("origin:")| */ - j = j + (pool_pointer) 7; - literal_mode = set_origin; - } else { - literal_mode = set_origin; - } - } - } - switch (literal_mode) { - case set_origin: - pdf_goto_pagemode(pdf); - pdf_set_pos(pdf, pdf->posstruct->pos); - break; - case direct_page: - pdf_goto_pagemode(pdf); - break; - case direct_text: - pdf_goto_fontmode(pdf); - /*tex not: |pdf_goto_textmode(pdf);| */ - break; - case direct_always: - pdf_end_string_nl(pdf); - p->need_tm = true; - break; - case direct_raw: - pdf_end_string_nl(pdf); - break; - default: - normal_error("pdf backend","bad literal mode"); - break; - } - if (s >= STRING_OFFSET) { - ss = str_string(s); - l = str_length(s) - (size_t) j; - pdf_out_block(pdf, (const char *) (ss + j), l); - } else { - pdf_out(pdf, s); - } - pdf_out(pdf, '\n'); -} - -void pdf_literal_set_mode(PDF pdf, int literal_mode) -{ - pdfstructure *p = pdf->pstruct; - switch (literal_mode) { - case set_origin: - pdf_goto_pagemode(pdf); - pdf_set_pos(pdf, pdf->posstruct->pos); - break; - case direct_page: - pdf_goto_pagemode(pdf); - break; - case direct_text: - pdf_goto_textmode(pdf); - break; - case direct_font: - pdf_goto_fontmode(pdf); - break; - case direct_always: - pdf_end_string_nl(pdf); - p->need_tm = true; - break; - case direct_raw: - pdf_end_string_nl(pdf); - break; - default: - normal_error("pdf backend","bad literal mode"); - break; - } -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.h b/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.h deleted file mode 100644 index 388742732aa..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfliteral.h +++ /dev/null @@ -1,34 +0,0 @@ -/* pdfliteral.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - - -#ifndef PDFLITERAL_H -# define PDFLITERAL_H - -# define set_pdf_literal_mode(A,B) pdf_literal_mode(A)=B -# define set_pdf_literal_type(A,B) pdf_literal_type(A)=B -# define set_pdf_literal_data(A,B) pdf_literal_data(A)=B - -extern void pdf_literal(PDF pdf, str_number s, int literal_mode, boolean warn); -extern void pdf_literal_set_mode(PDF pdf, int literal_mode); -extern void pdf_special(PDF pdf, halfword p); -extern void pdf_out_literal(PDF pdf, halfword p); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfobj.c b/Build/source/texk/web2c/luatexdir/pdf/pdfobj.c deleted file mode 100644 index 71d6a943f57..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfobj.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - -Copyright 2009-2011 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" -#include "lua/luatex-api.h" - -/*tex Write a raw \PDF\ object: */ - -void pdf_write_obj(PDF pdf, int k) -{ - lstring data; - const_lstring st; - /*tex The index into |data.s|: */ - size_t li; - int saved_compress_level ; - /*tex Gives compressed objects for |\pdfvariable objcompresslevel| >= |OBJSTM_ALWAYS|: */ - int os_threshold = OBJSTM_ALWAYS; - /*tex Possibly a \LUA\ registry reference: */ - int l = 0; - int ll = 0; - data.s = NULL; - /*tex We can have an immediate object before we are initialized. */ - ensure_output_state(pdf, ST_HEADER_WRITTEN); - saved_compress_level = pdf->compress_level; - /*tex End of a ugly hack. */ - if (obj_obj_pdfcompresslevel(pdf, k) > -1) { - /*tex A value of |-1| means ``unset''. */ - pdf->compress_level = obj_obj_pdfcompresslevel(pdf, k); - if (pdf->compress_level == 0) { - pdf->objcompresslevel = 0; - } - } - if (obj_obj_objstm_threshold(pdf, k) != OBJSTM_UNSET) - os_threshold = obj_obj_objstm_threshold(pdf, k); - if (obj_obj_is_stream(pdf, k)) { - pdf_begin_obj(pdf, k, OBJSTM_NEVER); - pdf_begin_dict(pdf); - l = obj_obj_stream_attr(pdf, k); - if (l != LUA_NOREF) { - lua_rawgeti(Luas, LUA_REGISTRYINDEX, l); - if (lua_type(Luas,-1) != LUA_TSTRING) - normal_error("pdf backend","invalid object"); - st.s = lua_tolstring(Luas, -1, &li); - st.l = li; - lua_pop(Luas,1); - pdf_check_space(pdf); - pdf_out_block(pdf, st.s, st.l); - pdf_set_space(pdf); - luaL_unref(Luas, LUA_REGISTRYINDEX, l); - obj_obj_stream_attr(pdf, k) = LUA_NOREF; - } - pdf_dict_add_streaminfo(pdf); - pdf_end_dict(pdf); - pdf_begin_stream(pdf); - } else - pdf_begin_obj(pdf, k, os_threshold); - l = obj_obj_data(pdf, k); - lua_rawgeti(Luas, LUA_REGISTRYINDEX, l); - if (lua_type(Luas,-1) != LUA_TSTRING) - normal_error("pdf backend","invalid object"); - st.s = lua_tolstring(Luas, -1, &li); - st.l = li; - lua_pop(Luas, 1); - if (obj_obj_is_file(pdf, k)) { - /*tex The callback status value: */ - boolean res = false; - /*tex The callback found filename: */ - const char *fnam = NULL; - int callback_id; - /*tex |st.s| is also |\0|-terminated, even as |lstring| */ - fnam = luatex_find_file(st.s, find_data_file_callback); - callback_id = callback_defined(read_data_file_callback); - if (fnam && callback_id > 0) { - boolean file_opened = false; - res = run_callback(callback_id, "S->bSd", fnam, &file_opened, &data.s, &ll); - data.l = (size_t) ll; - if (!file_opened) - normal_error("pdf backend", "cannot open file for embedding"); - } else { - /*tex The data file's |FILE*|: */ - byte_file f; - if (!fnam) - fnam = st.s; - if (!luatex_open_input(&f, fnam, kpse_tex_format, FOPEN_RBIN_MODE, true)) - normal_error("pdf backend", "cannot open file for embedding"); - res = read_data_file(f, &data.s, &ll); - data.l = (size_t) ll; - close_file(f); - } - if (data.l == 0L) - normal_error("pdf backend", "empty file for embedding"); - if (!res) - normal_error("pdf backend", "error reading file for embedding"); - tprint("<<"); - tprint(st.s); - pdf_out_block(pdf, (const char *) data.s, data.l); - xfree(data.s); - tprint(">>"); - } else { - pdf_out_block(pdf, st.s, st.l); - } - if (obj_obj_is_stream(pdf, k)) { - pdf_end_stream(pdf); - pdf_end_obj(pdf); - } else { - /*tex Here we do the |\n|. */ - pdf_end_obj(pdf); - } - luaL_unref(Luas, LUA_REGISTRYINDEX, l); - obj_obj_data(pdf, k) = LUA_NOREF; - pdf->compress_level = saved_compress_level; -} - -void init_obj_obj(PDF pdf, int k) -{ - obj_obj_stream_attr(pdf, k) = LUA_NOREF; - obj_obj_data(pdf, k) = LUA_NOREF; - unset_obj_obj_is_stream(pdf, k); - unset_obj_obj_is_file(pdf, k); - unset_obj_obj_no_length(pdf, k); - obj_obj_pdfcompresslevel(pdf, k) = -1; /* unset */ - obj_obj_objstm_threshold(pdf, k) = OBJSTM_UNSET; /* unset */ -} - -/*tex - - The |\pdfextension obj| primitive is used to create a ``raw'' object in - the PDF output file. The object contents will be hold in memory and will be - written out only when the object is referenced by |\pdfextension refobj|. - When |\pdfextension obj| is used with |\immediate|, the object contents - will be written out immediately. Objects referenced in the current page are - appended into |pdf_obj_list|. - -*/ - -void scan_obj(PDF pdf) -{ - int k; - lstring *st = NULL; - if (scan_keyword("reserveobjnum")) { - get_x_token(); - if (cur_cmd != spacer_cmd) - back_input(); - pdf->obj_count++; - k = pdf_create_obj(pdf, obj_type_obj, 0); - } else { - if (scan_keyword("useobjnum")) { - scan_int(); - k = cur_val; - check_obj_type(pdf, obj_type_obj, k); - if (is_obj_scheduled(pdf, k) || obj_data_ptr(pdf, k) != 0) - normal_error("pdf backend", "scheduled object is already used"); - } else { - pdf->obj_count++; - k = pdf_create_obj(pdf, obj_type_obj, 0); - } - obj_data_ptr(pdf, k) = pdf_get_mem(pdf, pdfmem_obj_size); - init_obj_obj(pdf, k); - if (scan_keyword("uncompressed")) { - obj_obj_pdfcompresslevel(pdf, k) = 0; - obj_obj_objstm_threshold(pdf, k) = OBJSTM_NEVER; - } - if (scan_keyword("stream")) { - set_obj_obj_is_stream(pdf, k); - if (scan_keyword("attr")) { - scan_toks(false, true); - st = tokenlist_to_lstring(def_ref, true); - flush_list(def_ref); - lua_pushlstring(Luas, (char *) st->s, st->l); - obj_obj_stream_attr(pdf, k) = luaL_ref(Luas, LUA_REGISTRYINDEX); - free_lstring(st); - st = NULL; - } - } - if (scan_keyword("file")) - set_obj_obj_is_file(pdf, k); - scan_toks(false, true); - st = tokenlist_to_lstring(def_ref, true); - flush_list(def_ref); - lua_pushlstring(Luas, (char *) st->s, st->l); - obj_obj_data(pdf, k) = luaL_ref(Luas, LUA_REGISTRYINDEX); - free_lstring(st); - st = NULL; - } - pdf_last_obj = k; -} - -void scan_refobj(PDF pdf) -{ - scan_int(); - check_obj_type(pdf, obj_type_obj, cur_val); - new_whatsit(pdf_refobj_node); - pdf_obj_objnum(tail_par) = cur_val; -} - -void scan_refobj_lua(PDF pdf, int k) -{ - check_obj_type(pdf, obj_type_obj, k); - new_whatsit(pdf_refobj_node); - pdf_obj_objnum(tail_par) = k; -} - -void pdf_ref_obj(PDF pdf, halfword p) -{ - if (!is_obj_scheduled(pdf, pdf_obj_objnum(p))) - addto_page_resources(pdf, obj_type_obj, pdf_obj_objnum(p)); -} - -void pdf_ref_obj_lua(PDF pdf, int k) -{ - if (!is_obj_scheduled(pdf, k)) - addto_page_resources(pdf, obj_type_obj, k); -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfobj.h b/Build/source/texk/web2c/luatexdir/pdf/pdfobj.h deleted file mode 100644 index f6e49450be9..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfobj.h +++ /dev/null @@ -1,60 +0,0 @@ -/* pdfobj.h - - Copyright 2009-2011 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef PDFOBJ_H -# define PDFOBJ_H - -/* data structure for \.{\\pdfextension obj} and \.{\\pdfextension refobj} */ - -# define set_pdf_obj_objnum(A, B) pdf_obj_objnum(A) = (B) - -# define pdfmem_obj_size 5 /* size of memory in |mem| which |obj_data_ptr| holds */ - -# define obj_obj_data(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 0] /* object data */ -# define obj_obj_stream_attr(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 1] /* additional attributes into stream dict */ -# define obj_obj_flags(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 2] /* stream/file flags */ -# define obj_obj_pdfcompresslevel(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 3] /* overrides \pdfcompresslevel */ -# define obj_obj_objstm_threshold(pdf, A) pdf->mem[obj_data_ptr((pdf), (A)) + 4] /* for object stream compression */ - -# define OBJ_FLAG_ISSTREAM (1 << 0) -# define OBJ_FLAG_ISFILE (1 << 1) -# define OBJ_FLAG_NOLENGTH (1 << 2) - -# define obj_obj_is_stream(pdf,A) ((obj_obj_flags((pdf), (A)) & OBJ_FLAG_ISSTREAM) != 0) -# define set_obj_obj_is_stream(pdf,A) ((obj_obj_flags((pdf), (A)) |= OBJ_FLAG_ISSTREAM)) -# define unset_obj_obj_is_stream(pdf,A) ((obj_obj_flags((pdf), (A)) &= ~OBJ_FLAG_ISSTREAM)) - -# define obj_obj_is_file(pdf,A) ((obj_obj_flags((pdf), (A)) & OBJ_FLAG_ISFILE) != 0) -# define set_obj_obj_is_file(pdf,A) ((obj_obj_flags((pdf), (A)) |= OBJ_FLAG_ISFILE)) -# define unset_obj_obj_is_file(pdf,A) ((obj_obj_flags((pdf), (A)) &= ~OBJ_FLAG_ISFILE)) - -# define obj_obj_no_length(pdf,A) ((obj_obj_flags((pdf), (A)) & OBJ_FLAG_NOLENGTH) != 0) -# define set_obj_obj_no_length(pdf,A) ((obj_obj_flags((pdf), (A)) |= OBJ_FLAG_NOLENGTH)) -# define unset_obj_obj_no_length(pdf,A) ((obj_obj_flags((pdf), (A)) &= ~OBJ_FLAG_NOLENGTH)) - -extern void init_obj_obj(PDF pdf, int k); -extern void pdf_write_obj(PDF pdf, int n); -extern void scan_obj(PDF pdf); -extern void scan_refobj(PDF pdf); -extern void scan_refobj_lua(PDF pdf, int k); -extern void pdf_ref_obj(PDF pdf, halfword p); -extern void pdf_ref_obj_lua(PDF pdf, int k); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.c b/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.c deleted file mode 100644 index ae17e29dac3..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - -Copyright 2009-2011 Taco Hoekwater <taco@@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -/*tex - - Data structure of outlines; it's not able to write out outline entries before - all outline entries are defined, so memory allocated for outline entries - can't not be deallocated and will stay in memory. For this reason we will - store data of outline entries in |pdf->mem| instead of |mem|. - -*/ - -/*tex The size of memory in |pdf->mem| which |obj_outline_ptr| points to: */ - -#define pdfmem_outline_size 8 - -/*tex The count of all opened children: */ - -#define obj_outline_count obj_info - -/*tex The pointer to |pdf->mem|: */ - -#define obj_outline_ptr obj_aux - -#define obj_outline_title(pdf,A) pdf->mem[obj_outline_ptr(pdf,A)] -#define obj_outline_parent(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 1] -#define obj_outline_prev(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 2] -#define obj_outline_next(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 3] -#define obj_outline_first(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 4] -#define obj_outline_last(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 5] -#define obj_outline_action_objnum(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 6] -#define obj_outline_attr(pdf,A) pdf->mem[obj_outline_ptr(pdf,A) + 7] - -#define set_obj_outline_count(pdf,A,B) obj_outline_count(pdf,A)=B -#define set_obj_outline_ptr(pdf,A,B) obj_outline_ptr(pdf,A)=B -#define set_obj_outline_action_objnum(pdf,A,B) obj_outline_action_objnum(pdf,A)=B -#define set_obj_outline_title(pdf,A,B) obj_outline_title(pdf,A)=B -#define set_obj_outline_prev(pdf,A,B) obj_outline_prev(pdf,A)=B -#define set_obj_outline_next(pdf,A,B) obj_outline_next(pdf,A)=B -#define set_obj_outline_first(pdf,A,B) obj_outline_first(pdf,A)=B -#define set_obj_outline_last(pdf,A,B) obj_outline_last(pdf,A)=B -#define set_obj_outline_parent(pdf,A,B) obj_outline_parent(pdf,A)=B -#define set_obj_outline_attr(pdf,A,B) obj_outline_attr(pdf,A)=B - -static int open_subentries(PDF pdf, halfword p) -{ - int c, l, r; - int k = 0; - if (obj_outline_first(pdf, p) != 0) { - l = obj_outline_first(pdf, p); - do { - k++; - c = open_subentries(pdf, l); - if (obj_outline_count(pdf, l) > 0) - k = k + c; - obj_outline_parent(pdf, l) = p; - r = obj_outline_next(pdf, l); - if (r == 0) - obj_outline_last(pdf, p) = l; - l = r; - } while (l != 0); - } - if (obj_outline_count(pdf, p) > 0) - obj_outline_count(pdf, p) = k; - else - obj_outline_count(pdf, p) = -k; - return k; -} - -/*tex Return the number of outline entries in the same level with |p|: */ - -static int outline_list_count(PDF pdf, pointer p) -{ - int k = 1; - while (obj_outline_prev(pdf, p) != 0) { - k++; - p = obj_outline_prev(pdf, p); - } - return k; -} - -void scan_pdfoutline(PDF pdf) -{ - halfword q, r; - int i, k, l; - int j = 0; - halfword p = null; - if (scan_keyword("attr")) { - scan_toks(false, true); - r = def_ref; - } else { - r = 0; - } - if (scan_keyword("useobjnum")) { - scan_int(); - j = cur_val; - } else { - p = scan_action(pdf); - } - if (scan_keyword("count")) { - scan_int(); - i = cur_val; - } else { - i = 0; - } - scan_toks(false, true); - q = def_ref; - if (j == 0) { - j = pdf_create_obj(pdf, obj_type_others, 0); - pdf_begin_obj(pdf, j, OBJSTM_ALWAYS); - write_action(pdf, p); - pdf_end_obj(pdf); - delete_action_ref(p); - } - k = pdf_create_obj(pdf, obj_type_outline, 0); - set_obj_outline_ptr(pdf, k, pdf_get_mem(pdf, pdfmem_outline_size)); - set_obj_outline_action_objnum(pdf, k, j); - set_obj_outline_count(pdf, k, i); - l = pdf_create_obj(pdf, obj_type_others, 0); - pdf_begin_obj(pdf, l, OBJSTM_ALWAYS); - { - char *s = tokenlist_to_cstring(q, true, NULL); - pdf_print_str_ln(pdf, s); - xfree(s); - } - delete_token_ref(q); - pdf_end_obj(pdf); - set_obj_outline_title(pdf, k, l); - set_obj_outline_prev(pdf, k, 0); - set_obj_outline_next(pdf, k, 0); - set_obj_outline_first(pdf, k, 0); - set_obj_outline_last(pdf, k, 0); - set_obj_outline_parent(pdf, k, pdf->parent_outline); - set_obj_outline_attr(pdf, k, r); - if (pdf->first_outline == 0) - pdf->first_outline = k; - if (pdf->last_outline == 0) { - if (pdf->parent_outline != 0) - set_obj_outline_first(pdf, pdf->parent_outline, k); - } else { - set_obj_outline_next(pdf, pdf->last_outline, k); - set_obj_outline_prev(pdf, k, pdf->last_outline); - } - pdf->last_outline = k; - if (obj_outline_count(pdf, k) != 0) { - pdf->parent_outline = k; - pdf->last_outline = 0; - } else if ((pdf->parent_outline != 0) && - (outline_list_count(pdf, k) == - abs(obj_outline_count(pdf, pdf->parent_outline)))) { - j = pdf->last_outline; - do { - set_obj_outline_last(pdf, pdf->parent_outline, j); - j = pdf->parent_outline; - pdf->parent_outline = obj_outline_parent(pdf, pdf->parent_outline); - } while (!((pdf->parent_outline == 0) || - (outline_list_count(pdf, j) < - abs(obj_outline_count(pdf, pdf->parent_outline))))); - if (pdf->parent_outline == 0) - pdf->last_outline = pdf->first_outline; - else - pdf->last_outline = obj_outline_first(pdf, pdf->parent_outline); - while (obj_outline_next(pdf, pdf->last_outline) != 0) - pdf->last_outline = obj_outline_next(pdf, pdf->last_outline); - } -} - -/*tex - - In the end we must flush \PDF\F objects that cannot be written out - immediately after shipping out pages. - -*/ - -int print_outlines(PDF pdf) -{ - int k, l, a; - int outlines; - if (pdf->first_outline != 0) { - outlines = pdf_create_obj(pdf, obj_type_others, 0); - l = pdf->first_outline; - k = 0; - do { - k++; - a = open_subentries(pdf, l); - if (obj_outline_count(pdf, l) > 0) - k = k + a; - set_obj_outline_parent(pdf, l, pdf->obj_ptr); - l = obj_outline_next(pdf, l); - } while (l != 0); - pdf_begin_obj(pdf, outlines, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - pdf_dict_add_name(pdf, "Type", "Outlines"); - pdf_dict_add_ref(pdf, "First", pdf->first_outline); - pdf_dict_add_ref(pdf, "Last", pdf->last_outline); - pdf_dict_add_int(pdf, "Count", k); - pdf_end_dict(pdf); - pdf_end_obj(pdf); - /*tex Output \PDF\ outline entries. */ - k = pdf->head_tab[obj_type_outline]; - while (k != 0) { - if (obj_outline_parent(pdf, k) == pdf->parent_outline) { - if (obj_outline_prev(pdf, k) == 0) - pdf->first_outline = k; - if (obj_outline_next(pdf, k) == 0) - pdf->last_outline = k; - } - pdf_begin_obj(pdf, k, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - pdf_dict_add_ref(pdf, "Title", obj_outline_title(pdf, k)); - pdf_dict_add_ref(pdf, "A", obj_outline_action_objnum(pdf, k)); - if (obj_outline_parent(pdf, k) != 0) - pdf_dict_add_ref(pdf, "Parent", obj_outline_parent(pdf, k)); - if (obj_outline_prev(pdf, k) != 0) - pdf_dict_add_ref(pdf, "Prev", obj_outline_prev(pdf, k)); - if (obj_outline_next(pdf, k) != 0) - pdf_dict_add_ref(pdf, "Next", obj_outline_next(pdf, k)); - if (obj_outline_first(pdf, k) != 0) - pdf_dict_add_ref(pdf, "First", obj_outline_first(pdf, k)); - if (obj_outline_last(pdf, k) != 0) - pdf_dict_add_ref(pdf, "Last", obj_outline_last(pdf, k)); - if (obj_outline_count(pdf, k) != 0) - pdf_dict_add_int(pdf, "Count", obj_outline_count(pdf, k)); - if (obj_outline_attr(pdf, k) != 0) { - pdf_out(pdf, '\n'); - pdf_print_toks(pdf, obj_outline_attr(pdf, k)); - pdf_out(pdf, '\n'); - delete_token_ref(obj_outline_attr(pdf, k)); - set_obj_outline_attr(pdf, k, null); - } - pdf_end_dict(pdf); - pdf_end_obj(pdf); - k = obj_link(pdf, k); - } - } else { - outlines = 0; - } - return outlines; -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.h b/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.h deleted file mode 100644 index a1c42df936e..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfoutline.h +++ /dev/null @@ -1,28 +0,0 @@ -/* pdfoutline.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - - -#ifndef PDFOUTLINE_H -# define PDFOUTLINE_H - -extern void scan_pdfoutline(PDF pdf); -extern int print_outlines(PDF pdf); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfpage.c b/Build/source/texk/web2c/luatexdir/pdf/pdfpage.c deleted file mode 100644 index 211248a02d3..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfpage.c +++ /dev/null @@ -1,290 +0,0 @@ -/* - -Copyright 2006-2012 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -#include <stdlib.h> -#include <stdio.h> -#include <assert.h> -#include <math.h> - -void init_pdf_pagecalculations(PDF pdf) -{ - pdfstructure *p; - int decimal_digits = pdf->decimal_digits; - if (pdf->pstruct == NULL) - pdf->pstruct = xmalloc(sizeof(pdfstructure)); - p = pdf->pstruct; - setpdffloat(p->pdf.h, 0, decimal_digits); - setpdffloat(p->pdf.v, 0, decimal_digits); - p->cw.e = 1; - /*tex |+ 2| makes less corrections inside []TJ */ - p->fs_cur.e = p->fs.e = (decimal_digits < 4 ? 5 : 6); - /*tex for placement outside BT...ET */ - setpdffloat(p->cm[0], 1, 0); - setpdffloat(p->cm[1], 0, 0); - setpdffloat(p->cm[2], 0, 0); - setpdffloat(p->cm[3], 1, 0); - /*tex horizontal movement on page */ - setpdffloat(p->cm[4], 0, decimal_digits); - /*tex vertical movement on page */ - setpdffloat(p->cm[5], 0, decimal_digits); - /*tex for placement inside BT...ET */ - /*tex mantissa holds HZ expand * ExtendFont */ - setpdffloat(p->tm0_cur, 0, 6); - /*tex mantissa holds HZ expand * ExtendFont */ - setpdffloat(p->tm[0], ten_pow[6], 6); - setpdffloat(p->tm[1], 0, 0); - /*tex mantissa holds SlantFont, 0 = default */ - setpdffloat(p->tm[2], 0, 3); - setpdffloat(p->tm[3], ten_pow[6], 6); - /*tex mantissa holds delta from |pdf_bt_pos.h| */ - setpdffloat(p->tm[4], 0, decimal_digits); - /*tex mantissa holds delta from |pdf_bt_pos.v| */ - setpdffloat(p->tm[5], 0, decimal_digits); - p->f_pdf_cur = p->f_pdf = null_font; - p->fs_cur.m = p->fs.m = 0; - p->wmode = WMODE_H; - p->mode = PMODE_PAGE; - p->ishex = 0; - p->need_tf = false; - p->need_tm = false; - p->done_width = false; - p->done_mode = false; - p->k1 = ten_pow[p->pdf.h.e] / by_one_bp; -} - -void synch_pos_with_cur(posstructure * pos, posstructure * refpos, scaledpos cur) -{ - switch (pos->dir) { - case dir_TLT: - pos->pos.h = refpos->pos.h + cur.h; - pos->pos.v = refpos->pos.v - cur.v; - break; - case dir_TRT: - pos->pos.h = refpos->pos.h - cur.h; - pos->pos.v = refpos->pos.v - cur.v; - break; - case dir_LTL: - pos->pos.h = refpos->pos.h + cur.v; - pos->pos.v = refpos->pos.v - cur.h; - break; - case dir_RTT: - pos->pos.h = refpos->pos.h - cur.v; - pos->pos.v = refpos->pos.v - cur.h; - break; - default: - formatted_warning("pdf backend","forcing bad dir %i to TLT in synch_pos_with_cur",pos->dir); - pos->dir = dir_TLT; - pos->pos.h = refpos->pos.h + cur.h; - pos->pos.v = refpos->pos.v - cur.v; - break; - } -} - -boolean calc_pdfpos(pdfstructure * p, scaledpos pos) -{ - scaledpos new; - boolean move_pdfpos = false; - switch (p->mode) { - case PMODE_PAGE: - new.h = i64round(pos.h * p->k1); - new.v = i64round(pos.v * p->k1); - /*tex cm is concatenated */ - p->cm[4].m = new.h - p->pdf.h.m; - p->cm[5].m = new.v - p->pdf.v.m; - if (new.h != p->pdf.h.m || new.v != p->pdf.v.m) - move_pdfpos = true; - break; - case PMODE_TEXT: - new.h = i64round(pos.h * p->k1); - new.v = i64round(pos.v * p->k1); - /*tex Tm replaces */ - p->tm[4].m = new.h - p->pdf_bt_pos.h.m; - p->tm[5].m = new.v - p->pdf_bt_pos.v.m; - if (new.h != p->pdf.h.m || new.v != p->pdf.v.m) - move_pdfpos = true; - break; - case PMODE_CHAR: - case PMODE_CHARARRAY: - switch (p->wmode) { - case WMODE_H: - new.h = i64round((pos.h * p->k1 - (double) p->pdf_tj_pos.h.m) * p->k2); - new.v = i64round(pos.v * p->k1); - p->tj_delta.m = -i64round((double) ((new.h - p->cw.m) / ten_pow[p->cw.e - p->tj_delta.e])); - /*tex p->tm[4] is meaningless */ - p->tm[5].m = new.v - p->pdf_bt_pos.v.m; - if (p->tj_delta.m != 0 || new.v != p->pdf.v.m) - move_pdfpos = true; - break; - case WMODE_V: - new.h = i64round(pos.h * p->k1); - new.v = i64round(((double) p->pdf_tj_pos.v.m - pos.v * p->k1) * p->k2); - /*tex p->tm[5] is meaningless */ - p->tm[4].m = new.h - p->pdf_bt_pos.h.m; - p->tj_delta.m = -i64round((double) ((new.v - p->cw.m) / ten_pow[p->cw.e - p->tj_delta.e])); - if (p->tj_delta.m != 0 || new.h != p->pdf.h.m) - move_pdfpos = true; - break; - default: - normal_error("pdf backend","unknown mode in char array in calc_pos"); - break; - } - break; - default: - normal_error("pdf backend","unknown mode in calc_pos"); - } - return move_pdfpos; -} - -void print_pdf_matrix(PDF pdf, pdffloat * tm) -{ - int i; - for (i = 0; i < 5; i++) { - print_pdffloat(pdf, tm[i]); - pdf_out(pdf, ' '); - } - print_pdffloat(pdf, tm[i]); -} - -void pdf_print_cm(PDF pdf, pdffloat * cm) -{ - print_pdf_matrix(pdf, cm); - pdf_puts(pdf, " cm\n"); -} - -void pdf_set_pos(PDF pdf, scaledpos pos) -{ - boolean move; - pdfstructure *p = pdf->pstruct; - if (!is_pagemode(p)) - normal_error("pdf backend","page mode expected in set_pos"); - move = calc_pdfpos(p, pos); - if (move) { - pdf_print_cm(pdf, p->cm); - p->pdf.h.m += p->cm[4].m; - p->pdf.v.m += p->cm[5].m; - } -} - -void pdf_set_pos_temp(PDF pdf, scaledpos pos) -{ - boolean move; - pdfstructure *p = pdf->pstruct; - if (!is_pagemode(p)) - normal_error("pdf backend","page mode expected in set_pos_temp"); - move = calc_pdfpos(p, pos); - if (move) { - pdf_print_cm(pdf, p->cm); - } -} - -static void begin_text(PDF pdf) -{ - pdfstructure *p = pdf->pstruct; - if (!is_pagemode(p)) - normal_error("pdf backend","page mode expected in begin_text"); - p->pdf_bt_pos = p->pdf; - pdf_puts(pdf, "BT\n"); - p->mode = PMODE_TEXT; - p->need_tf = true; - p->need_width = 0; - p->need_mode = 0; -} - -static void end_text(PDF pdf) -{ - pdfstructure *p = pdf->pstruct; - if (!is_textmode(p)) - normal_error("pdf backend","text mode expected in end_text"); - - if (p->done_width != 0) { - pdf_puts(pdf, "0 w\n"); - p->done_width = 0; - } - if (p->done_mode != 0) { - pdf_puts(pdf, "0 Tr\n"); - p->done_mode = 0; - } - - pdf_puts(pdf, "ET\n"); - p->pdf = p->pdf_bt_pos; - p->mode = PMODE_PAGE; -} - -void pdf_end_string_nl(PDF pdf) -{ - pdfstructure *p = pdf->pstruct; - if (is_charmode(p)) - end_charmode(pdf); - if (is_chararraymode(p)) - end_chararray(pdf); -} - -void pdf_goto_pagemode(PDF pdf) -{ - pdfstructure *p = pdf->pstruct; - if (!is_pagemode(p)) { - if (is_charmode(p)) - end_charmode(pdf); - if (is_chararraymode(p)) - end_chararray(pdf); - if (is_textmode(p)) - end_text(pdf); - if (!is_pagemode(p)) - normal_error("pdf backend","page mode expected in goto_page_mode"); - } -} - -void pdf_goto_textmode(PDF pdf) -{ - pdfstructure *p = pdf->pstruct; - const scaledpos origin = { - 0, 0 - }; - if (is_pagemode(p)) { - /*tex Reset to the page origin: */ - pdf_set_pos(pdf, origin); - begin_text(pdf); - } else if (!is_textmode(p)) { - if (is_charmode(p)) - end_charmode(pdf); - if (is_chararraymode(p)) - end_chararray(pdf); - if (!is_textmode(p)) - normal_error("pdf backend","text mode expected in goto_text_mode"); - } -} - -void pdf_goto_fontmode(PDF pdf){ - pdfstructure *p = pdf->pstruct; - const scaledpos origin = { - 0, 0 - }; - if (is_charmode(p)) - end_charmode(pdf); - if (is_chararraymode(p)) - end_chararray(pdf); - if (is_textmode(p)) - end_text(pdf); - pdf_set_pos(pdf, origin); - p->mode = PMODE_PAGE; -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfpage.h b/Build/source/texk/web2c/luatexdir/pdf/pdfpage.h deleted file mode 100644 index c7a5f8a7076..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfpage.h +++ /dev/null @@ -1,48 +0,0 @@ -/* pdfpage.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef PDFPAGE_H -# define PDFPAGE_H - -# define is_pagemode(p) ((p)->mode == PMODE_PAGE) -# define is_textmode(p) ((p)->mode == PMODE_TEXT) -# define is_chararraymode(p) ((p)->mode == PMODE_CHARARRAY) -# define is_charmode(p) ((p)->mode == PMODE_CHAR) - -# define setpdffloat(a,b,c) do {(a).m = (b); (a).e = (c);} while (0) - -# ifdef hz -/* AIX 4.3 defines hz as 100 in system headers */ -# undef hz -# endif - -void synch_pos_with_cur(posstructure * pos, posstructure * refpos, scaledpos cur); -boolean calc_pdfpos(pdfstructure * p, scaledpos pos); -void pdf_end_string_nl(PDF pdf); -void pdf_goto_pagemode(PDF pdf); -void pdf_goto_textmode(PDF pdf); -void pdf_goto_fontmode(PDF pdf); -void init_pdf_pagecalculations(PDF pdf); -void pdf_print_cm(PDF pdf, pdffloat * cm); -void pdf_set_pos(PDF pdf, scaledpos pos); -void pdf_set_pos_temp(PDF pdf, scaledpos pos); -void print_pdf_matrix(PDF pdf, pdffloat * tm); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.c b/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.c deleted file mode 100644 index f21412f9a98..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - -Copyright 2006-2011 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -#define PAGES_TREE_KIDSMAX 10 - -static struct avl_table *divert_list_tree = NULL; - -typedef struct pages_entry_ { - /*tex The object number of this |/Pages| object. */ - int objnum; - /*tex The total number of all pages below. */ - int number_of_pages; - /*tex The number of direct kid objects. */ - int number_of_kids; - /*tex The array of kid object numbers. */ - int kids[PAGES_TREE_KIDSMAX]; - struct pages_entry_ *next; -} pages_entry; - -typedef struct divert_list_entry_ { - int divnum; - pages_entry *first; - pages_entry *last; -} divert_list_entry; - -static int comp_divert_list_entry(const void *pa, const void *pb, void *p) -{ - (void) p; - if (((const divert_list_entry *) pa)->divnum > ((const divert_list_entry *) pb)->divnum) - return 1; - if (((const divert_list_entry *) pa)->divnum < ((const divert_list_entry *) pb)->divnum) - return -1; - return 0; -} - -static pages_entry *new_pages_entry(PDF pdf) -{ - int i; - pages_entry *p = xtalloc(1, pages_entry); - p->number_of_pages = p->number_of_kids = 0; - for (i = 0; i < PAGES_TREE_KIDSMAX; i++) - p->kids[i] = 0; - p->next = NULL; - p->objnum = pdf_create_obj(pdf, obj_type_pages, 0); - return p; -} - -static divert_list_entry *new_divert_list_entry(void) -{ - divert_list_entry *d; - d = xtalloc(1, divert_list_entry); - d->first = d->last = NULL; - return d; -} - -static void ensure_list_tree(void) -{ - if (divert_list_tree == NULL) { - divert_list_tree = avl_create(comp_divert_list_entry, NULL, &avl_xallocator); - } -} - -static divert_list_entry *get_divert_list(int divnum) -{ - divert_list_entry *d, tmp; - void **aa; - tmp.divnum = divnum; - d = (divert_list_entry *) avl_find(divert_list_tree, &tmp); - if (d == NULL) { - d = new_divert_list_entry(); - d->divnum = divnum; - /*tex The next bit of code can actually be removed. */ - aa = avl_probe(divert_list_tree, d); - if (aa==NULL) { - normal_error("pdf backend","page list lookup error"); - } - } - return d; -} - -/*tex |pdf_do_page_divert| returns the current |/Parent| object number. */ - -int pdf_do_page_divert(PDF pdf, int objnum, int divnum) -{ - divert_list_entry *d; - pages_entry *p; - /*tex Initialize the tree. */ - ensure_list_tree(); - /*tex Make sure we have a list for this diversion. */ - d = get_divert_list(divnum); - if (d->first == NULL || d->last->number_of_kids == PAGES_TREE_KIDSMAX) { - /*tex Append a new |pages_entry|. */ - p = new_pages_entry(pdf); - if (d->first == NULL) - d->first = p; - else - d->last->next = p; - d->last = p; - } - p = d->last; - p->kids[p->number_of_kids++] = objnum; - p->number_of_pages++; - return p->objnum; -} - -static void movelist(divert_list_entry * d, divert_list_entry * dto) -{ - if (d != NULL && d->first != NULL && d->divnum != dto->divnum) { - /*tex No undivert of empty list or into self. */ - if (dto->first == NULL) - dto->first = d->first; - else - dto->last->next = d->first; - dto->last = d->last; - /*tex One could as well remove this |divert_list_entry|. */ - d->first = d->last = NULL; - } -} - -/*tex Undivert from diversion |divnum| into diversion |curdivnum|. */ - -void pdf_do_page_undivert(int divnum, int curdivnum) -{ - divert_list_entry *d, *dto, tmp; - struct avl_traverser t; - /*tex Initialize the tree. */ - ensure_list_tree(); - /*tex Find the diversion |curdivnum| list where diversion |divnum| should go. */ - dto = get_divert_list(curdivnum); - if (divnum == 0) { - /*tex Zero is a special case: undivert {\em all} lists. */ - avl_t_init(&t, divert_list_tree); - for (d = avl_t_first(&t, divert_list_tree); d != NULL; - d = avl_t_next(&t)) - movelist(d, dto); - } else { - tmp.divnum = divnum; - d = (divert_list_entry *) avl_find(divert_list_tree, &tmp); - movelist(d, dto); - } -} - -/*tex Write a |/Pages| object. */ - -static void write_pages(PDF pdf, pages_entry * p, int parent) -{ - int i; - int pages_attributes ; - pdf_begin_obj(pdf, p->objnum, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - pdf_dict_add_name(pdf, "Type", "Pages"); - if (parent == 0) { - /*tex It's root. Lookup the attributes once. */ - pages_attributes = pdf_pages_attr; - if (pages_attributes != null) { - pdf_print_toks(pdf, pages_attributes); - pdf_out(pdf, ' '); - } - print_pdf_table_string(pdf, "pagesattributes"); - pdf_out(pdf, ' '); - } else { - pdf_dict_add_ref(pdf, "Parent", parent); - } - pdf_dict_add_int(pdf, "Count", (int) p->number_of_pages); - pdf_add_name(pdf, "Kids"); - pdf_begin_array(pdf); - for (i = 0; i < p->number_of_kids; i++) { - pdf_add_ref(pdf, (int) p->kids[i]); - } - pdf_end_array(pdf); - pdf_end_dict(pdf); - pdf_end_obj(pdf); -} - -/*tex - - Loop over all |/Pages| objects, output them, create their parents, recursing - bottom up, return the |/Pages| root object number. - -*/ - -static int output_pages_list(PDF pdf, pages_entry * pe) -{ - pages_entry *p, *q, *r; - if (pe->next == NULL) { - /*tex Everything fits into one |pages_entry|. */ - write_pages(pdf, pe, 0); - return pe->objnum; - } - /*tex One level higher needed. */ - q = r = new_pages_entry(pdf); - for (p = pe; p != NULL; p = p->next) { - if (q->number_of_kids == PAGES_TREE_KIDSMAX) { - q->next = new_pages_entry(pdf); - q = q->next; - } - q->kids[q->number_of_kids++] = p->objnum; - q->number_of_pages += p->number_of_pages; - write_pages(pdf, p, q->objnum); - } - /*tex Recurse through next higher level. */ - return output_pages_list(pdf, r); -} - -int output_pages_tree(PDF pdf) -{ - divert_list_entry *d; - /*tex Concatenate all diversions into diversion 0. */ - pdf_do_page_undivert(0, 0); - /*tex Get diversion 0. */ - d = get_divert_list(0); - return output_pages_list(pdf, d->first); -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.h b/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.h deleted file mode 100644 index 9fdb0ac83d3..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfpagetree.h +++ /dev/null @@ -1,28 +0,0 @@ -/* pdfpagetree.h - - Copyright 2009--2011 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef PAGETREE_H -# define PAGETREE_H - -int output_pages_tree(PDF); -int pdf_do_page_divert(PDF, int, int); -void pdf_do_page_undivert(int, int); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfrule.c b/Build/source/texk/web2c/luatexdir/pdf/pdfrule.c deleted file mode 100644 index de689a1471f..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfrule.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - -Copyright 2010-2011 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" -#include "pdf/pdfpage.h" - -void pdf_place_rule(PDF pdf, halfword q, scaledpos size, int callback_id) -{ - pdfpos dim; - pdfstructure *p = pdf->pstruct; - scaledpos pos = pdf->posstruct->pos; - halfword s = subtype(q); - if (s >= math_over_rule && s <= math_radical_rule) { - if (callback_id == 0) { - s = normal_rule; - } else { - s = user_rule; - } - } - if (s == box_rule) { - pdf_place_form(pdf,q); - } else if (s == image_rule) { - pdf_place_image(pdf,q); - } else if (s == empty_rule) { - /*tex Place nothing, only take space. */ - } else if (s == user_rule) { - if (callback_id != 0) { - pdf_goto_pagemode(pdf); - pdf_puts(pdf, "q\n"); - pdf_set_pos_temp(pdf, pos); - run_callback(callback_id, "Ndd->",q,size.h,size.v); - pdf_puts(pdf, "\nQ\n"); - } - } else { - /*tex |normal_rule| or >= 100 being a leader rule */ - pdf_goto_pagemode(pdf); - dim.h.m = i64round(size.h * p->k1); - dim.h.e = p->pdf.h.e; - dim.v.m = i64round(size.v * p->k1); - dim.v.e = p->pdf.v.e; - pdf_puts(pdf, "q\n"); - if (size.v <= one_bp) { - pos.v += i64round(0.5 * size.v); - pdf_set_pos_temp(pdf, pos); - pdf_puts(pdf, "[] 0 d 0 J "); - print_pdffloat(pdf, dim.v); - pdf_puts(pdf, " w 0 0 m "); - print_pdffloat(pdf, dim.h); - pdf_puts(pdf, " 0 l S\n"); - } else if (size.h <= one_bp) { - pos.h += i64round(0.5 * size.h); - pdf_set_pos_temp(pdf, pos); - pdf_puts(pdf, "[] 0 d 0 J "); - print_pdffloat(pdf, dim.h); - pdf_puts(pdf, " w 0 0 m 0 "); - print_pdffloat(pdf, dim.v); - pdf_puts(pdf, " l S\n"); - } else { - pdf_set_pos_temp(pdf, pos); - if (s == outline_rule) { - pdf_puts(pdf, "[] 0 d 0 J "); - if (rule_transform(q) > 0) { - pdfpos temp ; - temp.h.m = i64round(rule_transform(q) * p->k1); - temp.h.e = p->pdf.h.e; - print_pdffloat(pdf, temp.h); - pdf_puts(pdf, " w "); - } - } - pdf_puts(pdf, "0 0 "); - print_pdffloat(pdf, dim.h); - pdf_out(pdf, ' '); - print_pdffloat(pdf, dim.v); - if (s == outline_rule) { - pdf_puts(pdf, " re S\n"); - } else { - pdf_puts(pdf, " re f\n"); - } - } - pdf_puts(pdf, "Q\n"); - } -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfrule.h b/Build/source/texk/web2c/luatexdir/pdf/pdfrule.h deleted file mode 100644 index c0d68fd44b0..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfrule.h +++ /dev/null @@ -1,27 +0,0 @@ -/* pdfrule.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - - -#ifndef PDFRULE_H -# define PDFRULE_H - -void pdf_place_rule(PDF pdf, halfword p, scaledpos size, int callback_id); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.c b/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.c deleted file mode 100644 index abfb4814201..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - -Copyright 2010 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -pos_entry *pos_stack = 0; -int pos_stack_size = 0; -int pos_stack_used = 0; - -static void checkpdfsave(scaledpos pos) -{ - pos_entry *new_stack; - if (pos_stack_used >= pos_stack_size) { - pos_stack_size += STACK_INCREMENT; - new_stack = xtalloc((unsigned) pos_stack_size, pos_entry); - memcpy((void *) new_stack, (void *) pos_stack, (unsigned) pos_stack_used * sizeof(pos_entry)); - xfree(pos_stack); - pos_stack = new_stack; - } - pos_stack[pos_stack_used].pos.h = pos.h; - pos_stack[pos_stack_used].pos.v = pos.v; - if (global_shipping_mode == SHIPPING_PAGE) { - pos_stack[pos_stack_used].matrix_stack = matrix_stack_used; - } - pos_stack_used++; -} - -static void checkpdfrestore(scaledpos pos) -{ - scaledpos diff; - if (pos_stack_used == 0) { - normal_warning("pdf backend", "'restore' is missing a 'save'"); - return; - } - pos_stack_used--; - diff.h = pos.h - pos_stack[pos_stack_used].pos.h; - diff.v = pos.v - pos_stack[pos_stack_used].pos.v; - if (diff.h != 0 || diff.v != 0) { - formatted_warning("pdf backend","misplaced 'restore' by (%dsp, %dsp)", (int) diff.h, (int) diff.v); - } - if (global_shipping_mode == SHIPPING_PAGE) { - matrix_stack_used = pos_stack[pos_stack_used].matrix_stack; - } -} - -void pdf_out_save(PDF pdf, halfword p) -{ - (void) p; - checkpdfsave(pdf->posstruct->pos); - pdf_literal(pdf, 'q', set_origin, false); -} - -void pdf_out_restore(PDF pdf, halfword p) -{ - (void) p; - checkpdfrestore(pdf->posstruct->pos); - pdf_literal(pdf, 'Q', set_origin, false); -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.h b/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.h deleted file mode 100644 index 3e1e1ef061e..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfsaverestore.h +++ /dev/null @@ -1,38 +0,0 @@ -/* pdfsaverestore.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef PDFSAVERESTORE_H -# define PDFSAVERESTORE_H - -/* stack for positions of \pdfsave */ - -typedef struct { - scaledpos pos; - int matrix_stack; -} pos_entry; - -extern pos_entry *pos_stack; /* the stack */ -extern int pos_stack_size; /* initially empty */ -extern int pos_stack_used; /* used entries */ - -extern void pdf_out_save(PDF pdf, halfword p); -extern void pdf_out_restore(PDF pdf, halfword p); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.c b/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.c deleted file mode 100644 index f19c1721d5d..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - -Copyright 2009 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -/*tex - - We keep a stack for |pdfextension setmatrix|: - -*/ - -matrix_entry *matrix_stack = NULL; -int matrix_stack_size = 0; -int matrix_stack_used = 0; - -boolean matrixused(void) -{ - return matrix_stack_used > 0; -} - -static void matrix_stack_room(void) -{ - matrix_entry *new_stack; - if (matrix_stack_used >= matrix_stack_size) { - matrix_stack_size += STACK_INCREMENT; - new_stack = xtalloc((unsigned) matrix_stack_size, matrix_entry); - memcpy((void *) new_stack, (void *) matrix_stack, (unsigned) matrix_stack_used * sizeof(matrix_entry)); - xfree(matrix_stack); - matrix_stack = new_stack; - } -} - -/*tex - - The matrix specification has four entries and gets translated to |e| being - |pos.h and |f| being pos.v. The current active matrix at the top of the - matrix stack is kept in |M_top|. - - The origin of \.{\\pdfextension setmatrix} is the current point. The - annotation coordinate system is the original page coordinate system. When - pdfTeX calculates annotation rectangles it does not take into account this - transformations, it uses the original coordinate system. To get the corrected - values, first we go back to the origin, perform the transformation and go - back: - - \starttyping - ( 1 0 0 ) ( a b 0 ) ( 1 0 0 ) - ( 0 1 0 ) x ( c d 0 ) x ( 0 1 0 ) x M\_top - ( -e -f 1 ) ( 0 0 1 ) ( e f 1 ) - - ( 1 0 0 ) ( a b 0 ) - = ( 0 1 0 ) x ( c d 0 ) x M\_top - ( e f 1 ) ( -e -f 1 ) - - ( a b 0 ) - = ( c d 0 ) x M\_top - ( e(1-a)-fc f(1-d)-eb 1 ) - \stoptyping - -*/ - -static void pdfsetmatrix(const char *in, scaledpos pos) -{ - /*tex - The argument of |pdfextension setmatrix| starts with |str_pool[in]| - and ends before |str_pool[pool_ptr]|. - */ - matrix_entry x, *y, *z; - if (global_shipping_mode == SHIPPING_PAGE) { - if (sscanf((const char *) in, " %lf %lf %lf %lf ", &x.a, &x.b, &x.c, &x.d) != 4) { - formatted_warning("pdf backend","unrecognized format of setmatrix: %s", in); - return; - } - /*tex Calculate this transformation matrix. */ - x.e = (double) pos.h * (1.0 - x.a) - (double) pos.v * x.c; - x.f = (double) pos.v * (1.0 - x.d) - (double) pos.h * x.b; - matrix_stack_room(); - z = &matrix_stack[matrix_stack_used]; - if (matrix_stack_used > 0) { - y = &matrix_stack[matrix_stack_used - 1]; - z->a = x.a * y->a + x.b * y->c; - z->b = x.a * y->b + x.b * y->d; - z->c = x.c * y->a + x.d * y->c; - z->d = x.c * y->b + x.d * y->d; - z->e = x.e * y->a + x.f * y->c + y->e; - z->f = x.e * y->b + x.f * y->d + y->f; - } else { - z->a = x.a; - z->b = x.b; - z->c = x.c; - z->d = x.d; - z->e = x.e; - z->f = x.f; - } - matrix_stack_used++; - } -} - -/*tex - - Apply matrix to point (x,y) - - \starttyping - ( a b 0 ) - ( x y 1 ) x ( c d 0 ) = ( xa+yc+e xb+yd+f 1 ) - ( e f 1 ) - \stoptyping - - If \.{\\pdfextension setmatrix} wasn't used, then return the value unchanged. - The return values for matrix tranform functions are: - -*/ - -static scaled ret_llx; -static scaled ret_lly; -static scaled ret_urx; -static scaled ret_ury; - -scaled getllx(void) -{ - return ret_llx; -} - -scaled getlly(void) -{ - return ret_lly; -} - -scaled geturx(void) -{ - return ret_urx; -} - -scaled getury(void) -{ - return ret_ury; -} - -static int last_llx; -static int last_lly; -static int last_urx; -static int last_ury; - -#define DO_ROUND(x) ((x > 0) ? (x + .5) : (x - .5)) -#define DO_MIN(a, b) ((a < b) ? a : b) -#define DO_MAX(a, b) ((a > b) ? a : b) - -static void do_matrixtransform(scaled x, scaled y, scaled * retx, scaled * rety) -{ - matrix_entry *m = &matrix_stack[matrix_stack_used - 1]; - double x_old = x; - double y_old = y; - double x_new = x_old * m->a + y_old * m->c + m->e; - double y_new = x_old * m->b + y_old * m->d + m->f; - *retx = (scaled) DO_ROUND(x_new); - *rety = (scaled) DO_ROUND(y_new); -} - -void matrixtransformrect(scaled llx, scaled lly, scaled urx, scaled ury) -{ - scaled x1, x2, x3, x4, y1, y2, y3, y4; - if (global_shipping_mode == SHIPPING_PAGE && matrix_stack_used > 0) { - last_llx = llx; - last_lly = lly; - last_urx = urx; - last_ury = ury; - do_matrixtransform(llx, lly, &x1, &y1); - do_matrixtransform(llx, ury, &x2, &y2); - do_matrixtransform(urx, lly, &x3, &y3); - do_matrixtransform(urx, ury, &x4, &y4); - ret_llx = DO_MIN(DO_MIN(x1, x2), DO_MIN(x3, x4)); - ret_lly = DO_MIN(DO_MIN(y1, y2), DO_MIN(y3, y4)); - ret_urx = DO_MAX(DO_MAX(x1, x2), DO_MAX(x3, x4)); - ret_ury = DO_MAX(DO_MAX(y1, y2), DO_MAX(y3, y4)); - } else { - ret_llx = llx; - ret_lly = lly; - ret_urx = urx; - ret_ury = ury; - } -} - -void matrixtransformpoint(scaled x, scaled y) -{ - if (global_shipping_mode == SHIPPING_PAGE && matrix_stack_used > 0) { - do_matrixtransform(x, y, &ret_llx, &ret_lly); - } else { - ret_llx = x; - ret_lly = y; - } -} - -void matrixrecalculate(scaled urx) -{ - matrixtransformrect(last_llx, last_lly, urx, last_ury); -} - -void pdf_out_setmatrix(PDF pdf, halfword p) -{ - scaledpos pos = pdf->posstruct->pos; - int old_setting; - str_number s; - old_setting = selector; - selector = new_string; - show_token_list(token_link(pdf_setmatrix_data(p)), null, -1); - pdfsetmatrix((char *) cur_string, pos); - tprint(" 0 0 cm"); - selector = old_setting; - s = make_string(); - pdf_literal(pdf, s, set_origin, false); - flush_str(s); -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.h b/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.h deleted file mode 100644 index 59fd1f69cdc..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfsetmatrix.h +++ /dev/null @@ -1,50 +0,0 @@ -/* pdfsetmatrix.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef PDFSETMATRIX_H -# define PDFSETMATRIX_H - -# define set_pdf_setmatrix_data(A,B) pdf_setmatrix_data(A)=B - -typedef struct { - double a; - double b; - double c; - double d; - double e; - double f; -} matrix_entry; - -extern matrix_entry *matrix_stack; -extern int matrix_stack_size; -extern int matrix_stack_used; - -scaled getllx(void); -scaled getlly(void); -scaled geturx(void); -scaled getury(void); -void matrixtransformpoint(scaled x, scaled y); -void matrixtransformrect(scaled llx, scaled lly, scaled urx, scaled ury); -boolean matrixused(void); -void matrixrecalculate(scaled urx); - -extern void pdf_out_setmatrix(PDF pdf, halfword p); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.c b/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.c deleted file mode 100644 index 084efc08626..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.c +++ /dev/null @@ -1,290 +0,0 @@ -/* - -Copyright 2010-2012 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -scaledpos shipbox_refpos; - -/*tex - - |ship_out| is used to shipout a box to PDF or DVI mode. If |shipping_mode| is - set to |SHIPPING_FORM| then the output will be a |Form| object (only PDF), and - if it is set to |SHIPPING_PAGE| it will be a |Page| object. - -*/ - -void ship_out(PDF pdf, halfword p, shipping_mode_e shipping_mode) -{ - /*tex Indices to first ten count registers: */ - int j, k; - int post_callback_id; - int pre_callback_id; - /*tex The origin position on the page: */ - posstructure refpoint; - int rule_callback_id = 0; - scaledpos cur = { 0, 0 }; - refpoint.pos.h = 0; - refpoint.pos.v = 0; - ensure_output_state(pdf, ST_HEADER_WRITTEN); - /*tex This is only for complaining if \.{\\outputmode} has changed: */ - fix_o_mode(); - pdf->f_cur = null_font; - /*tex - Start sheet {\sl Sync\TeX} information record. We assume that - |pdf_output| is properly set up. - */ - if (synctex_par) { - if (output_mode_used == OMODE_DVI) { - synctexsheet(mag_par); - } else { - synctexsheet(1000); - } - } - pre_callback_id = callback_defined(start_page_number_callback); - post_callback_id = callback_defined(stop_page_number_callback); - if ((tracing_output_par > 0) && (pre_callback_id == 0)) { - tprint_nl(""); - print_ln(); - tprint("Completed box being shipped out"); - } - global_shipping_mode = shipping_mode; - if (shipping_mode == SHIPPING_PAGE) { - if (pre_callback_id > 0) - (void) run_callback(pre_callback_id, "->"); - else if (pre_callback_id == 0) { - if (term_offset > max_print_line - 9) - print_ln(); - else if ((term_offset > 0) || (file_offset > 0)) - print_char(' '); - print_char('['); - j = 9; - while ((count(j) == 0) && (j > 0)) - j--; - for (k = 0; k <= j; k++) { - print_int(count(k)); - if (k < j) - print_char('.'); - } - } - } - if ((tracing_output_par > 0) && shipping_mode == SHIPPING_PAGE) { - if (pre_callback_id == 0) { - print_char(']'); - } - update_terminal(); - begin_diagnostic(); - show_box(p); - end_diagnostic(true); - } - /*tex Ship out box |p|:*/ - if (shipping_mode == SHIPPING_PAGE && box_dir(p) != page_direction_par) - normal_warning("backend","pagedir differs from bodydir, the output may be placed wrongly on the page"); - /*tex - Update the values of |max_h| and |max_v|; but if the page is too large, - |goto done|. Sometimes the user will generate a huge page because other - error messages are being ignored. Such pages are not output to the - \.{dvi} file, since they may confuse the printing software. - */ - if ((height(p) > max_dimen) || (depth(p) > max_dimen) || (height(p) + depth(p) + v_offset_par > max_dimen) || (width(p) + h_offset_par > max_dimen)) { - const char *hlp[] = { - "The page just created is more than 18 feet tall or", - "more than 18 feet wide, so I suspect something went wrong.", - NULL - }; - tex_error("Huge page cannot be shipped out", hlp); - if (tracing_output_par <= 0) { - begin_diagnostic(); - tprint_nl("The following box has been deleted:"); - show_box(p); - end_diagnostic(true); - } - goto DONE; - } - if (height(p) + depth(p) + v_offset_par > max_v) - max_v = height(p) + depth(p) + v_offset_par; - if (width(p) + h_offset_par > max_h) - max_h = width(p) + h_offset_par; - /*tex Calculate page dimensions and margins. */ - if (global_shipping_mode == SHIPPING_PAGE) { - if (page_width_par > 0) - pdf->page_size.h = page_width_par; - else { - switch (page_direction_par) { - case dir_TLT: - pdf->page_size.h = width(p) + 2 * page_left_offset_par; - break; - case dir_TRT: - pdf->page_size.h = width(p) + 2 * page_right_offset_par; - break; - case dir_LTL: - pdf->page_size.h = height(p) + depth(p) + 2 * page_left_offset_par; - break; - case dir_RTT: - pdf->page_size.h = height(p) + depth(p) + 2 * page_right_offset_par; - break; - default: - pdf->page_size.h = width(p) + 2 * page_left_offset_par; - normal_warning("pdf backend","bad page direction, assuming TLT, case 1"); - } - } - if (page_height_par > 0) - pdf->page_size.v = page_height_par; - else { - switch (page_direction_par) { - case dir_TLT: - case dir_TRT: - pdf->page_size.v = height(p) + depth(p) + 2 * page_top_offset_par; - break; - case dir_LTL: - case dir_RTT: - pdf->page_size.v = width(p) + 2 * page_top_offset_par; - break; - default: - pdf->page_size.v = height(p) + depth(p) + 2 * page_top_offset_par; - normal_warning("pdf backend","bad page direction, assuming TLT, case 2"); - } - } - /*tex - Think in upright page/paper coordinates (page origin = lower left edge). - First preset |refpoint.pos| to the DVI origin (near upper left page edge). - */ - backend_out_control[backend_control_set_reference_point](pdf,&refpoint); - /*tex - Then shift |refpoint.pos| of the DVI origin depending on the - |page_direction| within the upright (TLT) page coordinate system. - */ - switch (page_direction_par) { - case dir_TLT: - case dir_LTL: - refpoint.pos.h += h_offset_par; - refpoint.pos.v -= v_offset_par; - break; - case dir_TRT: - case dir_RTT: - refpoint.pos.h += pdf->page_size.h - page_right_offset_par - one_true_inch; - refpoint.pos.v -= v_offset_par; - break; - default: - refpoint.pos.h += h_offset_par; - refpoint.pos.v -= v_offset_par; - normal_warning("pdf backend","bad page direction, assuming TLT, case 3"); - } - /*tex - Then switch to page box coordinate system; do |height(p)| movement, - to get the location of the box origin. - */ - pdf->posstruct->dir = page_direction_par; - cur.h = 0; - cur.v = height(p); - synch_pos_with_cur(pdf->posstruct, &refpoint, cur); - } else { - /*tex We're shipping out a |/Form|. */ - pdf->posstruct->dir = box_dir(p); - switch (pdf->posstruct->dir) { - case dir_TLT: - case dir_TRT: - pdf->page_size.h = width(p); - pdf->page_size.v = height(p) + depth(p); - break; - case dir_LTL: - case dir_RTT: - pdf->page_size.h = height(p) + depth(p); - pdf->page_size.v = width(p); - break; - default: - pdf->page_size.h = width(p); - pdf->page_size.v = height(p) + depth(p); - normal_warning("pdf backend","bad page direction, assuming TLT, case 4"); - } - switch (pdf->posstruct->dir) { - case dir_TLT: - pdf->posstruct->pos.h = 0; - pdf->posstruct->pos.v = depth(p); - break; - case dir_TRT: - pdf->posstruct->pos.h = width(p); - pdf->posstruct->pos.v = depth(p); - break; - case dir_LTL: - pdf->posstruct->pos.h = height(p); - pdf->posstruct->pos.v = width(p); - break; - case dir_RTT: - pdf->posstruct->pos.h = depth(p); - pdf->posstruct->pos.v = width(p); - break; - default: - pdf->posstruct->pos.h = 0; - pdf->posstruct->pos.v = depth(p); - normal_warning("pdf backend","bad page direction, assuming TLT, case 5"); - } - } - /*tex - Now we are at the point on the page where the origin of the page box - should go. First we register the poisition for \.{\\gleaders}. - */ - shipbox_refpos = pdf->posstruct->pos; - backend_out_control[backend_control_begin_page](pdf); - rule_callback_id = callback_defined(process_rule_callback); - switch (type(p)) { - case vlist_node: - vlist_out(pdf, p, rule_callback_id); - break; - case hlist_node: - hlist_out(pdf, p, rule_callback_id); - break; - default: - normal_error("pdf backend", "no vlist or hlist in (xform) shipout"); - } - if (shipping_mode == SHIPPING_PAGE) - total_pages++; - cur_s = -1; - /*tex Finish shipping */ - backend_out_control[backend_control_end_page](pdf); - DONE: - if ((tracing_output_par <= 0) && (post_callback_id == 0) && shipping_mode == SHIPPING_PAGE) { - print_char(']'); - update_terminal(); - } - dead_cycles = 0; - /*tex Flush the box from memory, showing statistics if requested. */ - if ((tracing_stats_par > 1) && (pre_callback_id == 0)) { - tprint_nl("Memory usage before: "); - print_int(var_used); - print_char('&'); - print_int(dyn_used); - print_char(';'); - } - flush_node_list(p); - if ((tracing_stats_par > 1) && (post_callback_id == 0)) { - tprint(" after: "); - print_int(var_used); - print_char('&'); - print_int(dyn_used); - print_ln(); - } - if (shipping_mode == SHIPPING_PAGE && (post_callback_id > 0)) - (void) run_callback(post_callback_id, "->"); - /*tex Finish sheet {\sl Sync\TeX} information record. */ - if (synctex_par) - synctexteehs(); - global_shipping_mode = NOT_SHIPPING; -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.h b/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.h deleted file mode 100644 index 8fb073da4c2..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfshipout.h +++ /dev/null @@ -1,30 +0,0 @@ -/* pdfshipout.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - - -#ifndef PDFSHIPOUT_H -# define PDFSHIPOUT_H - -extern shipping_mode_e global_shipping_mode; /* set to |shipping_mode| when |ship_out| starts */ -extern scaledpos shipbox_refpos; /* for \gleaders */ - -extern void ship_out(PDF pdf, halfword p, shipping_mode_e shipping_mode); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdftables.c b/Build/source/texk/web2c/luatexdir/pdf/pdftables.c deleted file mode 100644 index 2a02dcd98ec..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdftables.c +++ /dev/null @@ -1,277 +0,0 @@ -/* - -Copyright 2009-2010 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -const char *pdf_obj_typenames[PDF_OBJ_TYPE_MAX + 1] = { - "font", "outline", "dest", "obj", "xform", "ximage", "thread", - "pagestream", "page", "pages", "catalog", "info", "link", "annot", "annots", - "bead", "beads", "objstm", "others" -}; - -int pdf_last_annot; -int pdf_last_link; -int pdf_last_obj; -int pdf_retval; - -/*tex - - AVL sort entry into |avl_table[]|. -*/ - -static int compare_info(const void *pa, const void *pb, void *param) -{ - const oentry *a = (const oentry *) pa; - const oentry *b = (const oentry *) pb; - (void) param; - if (a->u_type == b->u_type) { - if (a->u_type == union_type_int) { - return ((a->u.int0 < b->u.int0 ? -1 : (a->u.int0 > b->u.int0 ? 1 : 0))); - } else { - /*tex String type: */ - return strcmp(a->u.str0, b->u.str0); - } - } else if (a->u_type == union_type_int) { - return -1; - } else { - return 1; - } -} - -static void avl_put_obj(PDF pdf, int t, oentry * oe) -{ - void **pp; - if (pdf->obj_tree[t] == NULL) { - pdf->obj_tree[t] = avl_create(compare_info, NULL, &avl_xallocator); - if (pdf->obj_tree[t] == NULL) - formatted_error("pdf backend","avl_create() pdf->obj_tree failed"); - } - pp = avl_probe(pdf->obj_tree[t], oe); - if (pp == NULL) - formatted_error("pdf backend","avl_probe() out of memory in insertion"); -} - -static void avl_put_int_obj(PDF pdf, int int0, int objptr, int t) -{ - oentry *oe = xtalloc(1, oentry); - oe->u.int0 = int0; - oe->u_type = union_type_int; - oe->objptr = objptr; - avl_put_obj(pdf, t, oe); -} - -static void avl_put_str_obj(PDF pdf, char *str0, int objptr, int t) -{ - oentry *oe = xtalloc(1, oentry); - /*tex No |xstrdup| here! */ - oe->u.str0 = str0; - oe->u_type = union_type_cstring; - oe->objptr = objptr; - avl_put_obj(pdf, t, oe); -} - -static int avl_find_int_obj(PDF pdf, int t, int i) -{ - oentry *p; - oentry tmp; - tmp.u.int0 = i; - tmp.u_type = union_type_int; - if (pdf->obj_tree[t] == NULL) - return 0; - p = (oentry *) avl_find(pdf->obj_tree[t], &tmp); - if (p == NULL) - return 0; - return p->objptr; -} - -static int avl_find_str_obj(PDF pdf, int t, char *s) -{ - oentry *p; - oentry tmp; - tmp.u.str0 = s; - tmp.u_type = union_type_cstring; - if (pdf->obj_tree[t] == NULL) - return 0; - p = (oentry *) avl_find(pdf->obj_tree[t], &tmp); - if (p == NULL) - return 0; - return p->objptr; -} - -/*tex Create an object with type |t| and identifier |i|: */ - -int pdf_create_obj(PDF pdf, int t, int i) -{ - int a; - char *ss = NULL; - if (pdf->obj_ptr == sup_obj_tab_size) - overflow("indirect objects table size", (unsigned) pdf->obj_tab_size); - if (pdf->obj_ptr == pdf->obj_tab_size) { - a = pdf->obj_tab_size / 5; - if (pdf->obj_tab_size < sup_obj_tab_size - a) - pdf->obj_tab_size = pdf->obj_tab_size + a; - else - pdf->obj_tab_size = sup_obj_tab_size; - pdf->obj_tab = xreallocarray(pdf->obj_tab, obj_entry, (unsigned) pdf->obj_tab_size); - } - pdf->obj_ptr++; - obj_info(pdf, pdf->obj_ptr) = i; - obj_type(pdf, pdf->obj_ptr) = t; - set_obj_fresh(pdf, pdf->obj_ptr); - obj_aux(pdf, pdf->obj_ptr) = 0; - if (i < 0) { - ss = makecstring(-i); - avl_put_str_obj(pdf, ss, pdf->obj_ptr, t); - } else if (i > 0) - avl_put_int_obj(pdf, i, pdf->obj_ptr, t); - if (t <= HEAD_TAB_MAX) { - obj_link(pdf, pdf->obj_ptr) = pdf->head_tab[t]; - pdf->head_tab[t] = pdf->obj_ptr; - if ((t == obj_type_dest) && (i < 0)) - append_dest_name(pdf, makecstring(-obj_info(pdf, pdf->obj_ptr)), pdf->obj_ptr); /* why not just -i */ - } - return pdf->obj_ptr; -} - -int find_obj(PDF pdf, int t, int i, boolean byname) -{ - char *ss = NULL; - int ret; - if (byname) { - ss = makecstring(i); - ret = avl_find_str_obj(pdf, t, ss); - free(ss); - } else { - ret = avl_find_int_obj(pdf, t, i); - } - return ret; -} - -/*tex - - The following function finds an object with identifier |i| and type |t|. - Identifier |i| is either an integer or a token list index. If no such object - exists then it will be created. This function is used mainly to find - destination for link annotations and outlines; however it is also used in - |ship_out| (to check whether a Page object already exists) so we need to - declare it together with subroutines needed in |hlist_out| and |vlist_out|. - -*/ - -int pdf_get_obj(PDF pdf, int t, int i, boolean byname) -{ - int r; - str_number s; - if (byname > 0) { - s = tokens_to_string(i); - r = find_obj(pdf, t, s, true); - } else { - s = 0; - r = find_obj(pdf, t, i, false); - } - if (r == 0) { - if (byname > 0) { - r = pdf_create_obj(pdf, t, -s); - s = 0; - } else { - r = pdf_create_obj(pdf, t, i); - } - if (t == obj_type_dest) - set_obj_dest_ptr(pdf, r, null); - } - if (s != 0) - flush_str(s); - return r; -} - -/*tex Some object checking: */ - -void check_obj_exists(PDF pdf, int objnum) -{ - if (objnum < 0 || objnum > pdf->obj_ptr) - normal_error("pdf backend", "cannot find referenced object"); -} - -void check_obj_type(PDF pdf, int t, int objnum) -{ - int u; - check_obj_exists(pdf, objnum); - u = obj_type(pdf, objnum); - if (t != u) { - formatted_error("pdf backend", "referenced object has wrong type %s; should be %s", - pdf_obj_typenames[u], pdf_obj_typenames[t]); - } -} - -void set_rect_dimens(PDF pdf, halfword p, halfword parent_box, scaledpos cur, scaled_whd alt_rule, scaled margin) -{ - /*tex The positions relative to cur: */ - scaledpos ll, ur, pos_ll, pos_ur; - posstructure localpos; - localpos.dir = pdf->posstruct->dir; - /*tex |pdf| contains current point on page: */ - ll.h = 0; - if (is_running(alt_rule.dp)) - ll.v = depth(parent_box) - cur.v; - else - ll.v = alt_rule.dp; - if (is_running(alt_rule.wd)) - ur.h = width(parent_box) - cur.h; - else - ur.h = alt_rule.wd; - if (is_running(alt_rule.ht)) - ur.v = -height(parent_box) - cur.v; - else - ur.v = -alt_rule.ht; - synch_pos_with_cur(&localpos, pdf->posstruct, ll); - pos_ll = localpos.pos; - synch_pos_with_cur(&localpos, pdf->posstruct, ur); - pos_ur = localpos.pos; - /* - The test for swapping has been moved to the moment we write the rectangle. This has to - do with the fact that we have code dealing with directions and that the |pdf_ann_*| - horizontal edges get recalculated in some places. - */ - if (global_shipping_mode == SHIPPING_PAGE && matrixused()) { - matrixtransformrect(pos_ll.h, pos_ll.v, pos_ur.h, pos_ur.v); - pos_ll.h = getllx(); - pos_ll.v = getlly(); - pos_ur.h = geturx(); - pos_ur.v = getury(); - } - pdf_ann_left(p) = pos_ll.h - margin; - pdf_ann_bottom(p) = pos_ll.v - margin; - pdf_ann_right(p) = pos_ur.h + margin; - pdf_ann_top(p) = pos_ur.v + margin; -} - -void libpdffinish(PDF pdf) -{ - strbuf_free(pdf->fb); - xfree(pdf->job_id_string); - fm_free(); - t1_free(); - enc_free(); - epdf_free(); - ttf_free(); - glyph_unicode_free(); - zip_free(pdf); -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdftables.h b/Build/source/texk/web2c/luatexdir/pdf/pdftables.h deleted file mode 100644 index 5eb9eb86d09..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdftables.h +++ /dev/null @@ -1,225 +0,0 @@ -/* pdftables.h - - Copyright 2009-2013 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef PDFTABLES_H -# define PDFTABLES_H - -extern const char *pdf_obj_typenames[PDF_OBJ_TYPE_MAX + 1]; - -typedef enum { - union_type_int, - union_type_cstring, -} union_type; - -typedef struct { - union { - int int0; - char *str0; - } u; - union_type u_type; /* integer or char * in union above */ - int objptr; -} oentry; - -/* - -The cross-reference table |obj_tab| is an array of |obj_tab_size| of |obj_entry|. -Each entry contains five integer fields and represents an object in PDF file -whose object number is the index of this entry in |obj_tab|. Objects in |obj_tab| -maybe linked into list; objects in such a linked list have the same type. - -The first field contains information representing identifier of this object. It -is usally a number for most of object types, but it may be a string number for -named destination or named thread. - -The second field of |obj_entry| contains link to the next object in |obj_tab| if -this object is linked in a list. - -The third field holds the byte offset of the object in the output PDF file, or -its byte offset within an object stream. As long as the object is not written, -this field is used for flags about the write status of the object; then it has a -negative value. - -The fourth field holds the object number of the object stream, into which the -object is included. - -The last field usually represents the pointer to some auxiliary data structure -depending on the object type; however it may be used as a counter as well. - -*/ - -# define obj_info(pdf,A) pdf->obj_tab[(A)].u.int0 /* information representing identifier of this object */ -# define obj_start(pdf,A) pdf->obj_tab[(A)].u.str0 -# define obj_link(pdf,A) pdf->obj_tab[(A)].int1 /* link to the next entry in linked list */ - -# define obj_offset(pdf,A) pdf->obj_tab[(A)].int2 /* negative (flags), or byte offset for this object in PDF output file, or ... */ -# define obj_os_objnum(pdf,A) pdf->obj_tab[(A)].int2 /* ... object stream number for this object */ -# define obj_os_idx(pdf,A) pdf->obj_tab[(A)].int3 /* index of this object in object stream */ -# define obj_aux(pdf,A) pdf->obj_tab[(A)].v.int4 /* auxiliary pointer */ -# define obj_stop(pdf,A) pdf->obj_tab[(A)].v.str4 -# define obj_type(pdf,A) pdf->obj_tab[(A)].objtype - -# define obj_data_ptr obj_aux /* pointer to |pdf->mem| */ - -# define set_obj_link(pdf,A,B) obj_link(pdf,A)=(B) -# define set_obj_start(pdf,A,B) obj_start(pdf,A)=(B) -# define set_obj_info(pdf,A,B) obj_info(pdf,A)=(B) -# define set_obj_offset(pdf,A,B) obj_offset(pdf,A)=(B) -# define set_obj_os_objnum(pdf,A,B) obj_offset(pdf,A)=(B) -# define set_obj_aux(pdf,A,B) obj_aux(pdf,A)=(B) -# define set_obj_stop(pdf,A,B) obj_stop(pdf,A)=(B) -# define set_obj_data_ptr(pdf,A,B) obj_data_ptr(pdf,A)=(B) - -# define set_obj_fresh(pdf,A) obj_offset(pdf,(A))=(off_t)-2 -# define set_obj_scheduled(pdf,A) if (obj_offset(pdf,A)==(off_t)-2) obj_offset(pdf,A)=(off_t)-1 -# define is_obj_scheduled(pdf,A) ((obj_offset(pdf,A))>(off_t)-2) -# define is_obj_written(pdf,A) ((obj_offset(pdf,A))>(off_t)-1) - -/* - NOTE: The data structure definitions for the nodes on the typesetting side are - inside |nodes.h| -*/ - -# define inf_pk_dpi 72 /* min PK pixel density value from \.{texmf.cnf} */ -# define sup_pk_dpi 8000 /* max PK pixel density value from \.{texmf.cnf} */ - -# define pdf2double(a) ((double) (a).m / ten_pow[(a).e]) - -# define by_one_bp ((double) 65536 * (double) 72.27 / 72) /* number of sp per 1bp */ - -extern int find_obj(PDF pdf, int t, int i, boolean byname); -extern void check_obj_exists(PDF pdf, int objnum); -extern void check_obj_type(PDF pdf, int t, int objnum); -extern int pdf_get_obj(PDF pdf, int t, int i, boolean byname); -extern int pdf_create_obj(PDF pdf, int t, int i); -extern void set_rect_dimens(PDF pdf, halfword p, halfword parent_box, scaledpos cur, scaled_whd alt_rule, scaled margin); -extern void libpdffinish(PDF); - -# define set_width(A,B) width(A)=(B) -# define set_height(A,B) height(A)=(B) -# define set_depth(A,B) depth(A)=(B) - -/* pdf backend definitions */ - -typedef enum { - c_pdf_compress_level = 0, - c_pdf_decimal_digits, - c_pdf_image_resolution, - c_pdf_pk_resolution, - c_pdf_unique_resname, - c_pdf_major_version, - c_pdf_minor_version, - c_pdf_pagebox, - c_pdf_inclusion_errorlevel, - c_pdf_ignore_unknown_images, - c_pdf_gamma, - c_pdf_image_apply_gamma, - c_pdf_image_gamma, - c_pdf_image_hicolor, - c_pdf_image_addfilename, - c_pdf_obj_compress_level, - c_pdf_inclusion_copy_font, - c_pdf_gen_tounicode, - c_pdf_pk_fixed_dpi, - c_pdf_suppress_optional_info, - c_pdf_omit_cidset, - c_pdf_recompress, - c_pdf_omit_charset, -} pdf_backend_counters ; - -typedef enum { - d_pdf_h_origin = 0, - d_pdf_v_origin, - d_pdf_thread_margin, - d_pdf_dest_margin, - d_pdf_link_margin, - d_pdf_xform_margin, -} pdf_backend_dimensions ; - -typedef enum { - t_pdf_page_attr = 0, - t_pdf_page_resources, - t_pdf_pages_attr, - t_pdf_xform_attr, - t_pdf_xform_resources, - t_pdf_pk_mode, - t_pdf_trailer_id, -} pdf_backend_tokenlists ; - -extern int pdf_last_annot; -extern int pdf_last_link; -extern int pdf_last_obj; -extern int pdf_retval; -extern int pdf_cur_form; - -# define pdf_compress_level get_tex_extension_count_register(c_pdf_compress_level) -# define pdf_obj_compress_level get_tex_extension_count_register(c_pdf_obj_compress_level) -# define pdf_decimal_digits get_tex_extension_count_register(c_pdf_decimal_digits) -# define pdf_image_resolution get_tex_extension_count_register(c_pdf_image_resolution) -# define pdf_pk_resolution get_tex_extension_count_register(c_pdf_pk_resolution) -# define pdf_unique_resname get_tex_extension_count_register(c_pdf_unique_resname) -# define pdf_major_version get_tex_extension_count_register(c_pdf_major_version) -# define pdf_minor_version get_tex_extension_count_register(c_pdf_minor_version) -# define pdf_pagebox get_tex_extension_count_register(c_pdf_pagebox) -# define pdf_inclusion_errorlevel get_tex_extension_count_register(c_pdf_inclusion_errorlevel) -# define pdf_ignore_unknown_images get_tex_extension_count_register(c_pdf_ignore_unknown_images) -# define pdf_gamma get_tex_extension_count_register(c_pdf_gamma) -# define pdf_image_apply_gamma get_tex_extension_count_register(c_pdf_image_apply_gamma) -# define pdf_image_gamma get_tex_extension_count_register(c_pdf_image_gamma) -# define pdf_image_hicolor get_tex_extension_count_register(c_pdf_image_hicolor) -# define pdf_image_addfilename get_tex_extension_count_register(c_pdf_image_addfilename) -# define pdf_inclusion_copy_font get_tex_extension_count_register(c_pdf_inclusion_copy_font) -# define pdf_gen_tounicode get_tex_extension_count_register(c_pdf_gen_tounicode) -# define pdf_pk_fixed_dpi get_tex_extension_count_register(c_pdf_pk_fixed_dpi) -# define pdf_suppress_optional_info get_tex_extension_count_register(c_pdf_suppress_optional_info) -# define pdf_omit_cidset get_tex_extension_count_register(c_pdf_omit_cidset) -# define pdf_omit_charset get_tex_extension_count_register(c_pdf_omit_charset) -# define pdf_recompress get_tex_extension_count_register(c_pdf_recompress) - -# define pdf_h_origin get_tex_extension_dimen_register(d_pdf_h_origin) -# define pdf_v_origin get_tex_extension_dimen_register(d_pdf_v_origin) -# define pdf_thread_margin get_tex_extension_dimen_register(d_pdf_thread_margin) -# define pdf_dest_margin get_tex_extension_dimen_register(d_pdf_dest_margin) -# define pdf_link_margin get_tex_extension_dimen_register(d_pdf_link_margin) -# define pdf_xform_margin get_tex_extension_dimen_register(d_pdf_xform_margin) - -# define pdf_page_attr get_tex_extension_toks_register(t_pdf_page_attr) -# define pdf_page_resources get_tex_extension_toks_register(t_pdf_page_resources) -# define pdf_pages_attr get_tex_extension_toks_register(t_pdf_pages_attr) -# define pdf_xform_attr get_tex_extension_toks_register(t_pdf_xform_attr) -# define pdf_xform_resources get_tex_extension_toks_register(t_pdf_xform_resources) -# define pdf_pk_mode get_tex_extension_toks_register(t_pdf_pk_mode) -# define pdf_trailer_id get_tex_extension_toks_register(t_pdf_trailer_id) - -# define set_pdf_major_version(i) set_tex_extension_count_register(c_pdf_major_version,i) -# define set_pdf_minor_version(i) set_tex_extension_count_register(c_pdf_minor_version,i) -# define set_pdf_compress_level(i) set_tex_extension_count_register(c_pdf_compress_level,i) -# define set_pdf_obj_compress_level(i) set_tex_extension_count_register(c_pdf_obj_compress_level,i) -# define set_pdf_omit_cidset(i) set_tex_extension_count_register(c_pdf_omit_cidset,i) -# define set_pdf_omit_charset(i) set_tex_extension_count_register(c_pdf_omit_charset,i) -# define set_pdf_gen_tounicode(i) set_tex_extension_count_register(c_pdf_gen_tounicode,i) -# define set_pdf_recompress(i) set_tex_extension_count_register(c_pdf_recompress,i) - -# define set_pdf_decimal_digits(i) set_tex_extension_count_register(c_pdf_decimal_digits,i) -# define set_pdf_pk_resolution(i) set_tex_extension_count_register(c_pdf_pk_resolution,i) -# define set_pdf_pk_fixed_dpi(i) set_tex_extension_count_register(c_pdf_pk_fixed_dpi,i) - -# define pk_decimal_digits(pdf,delta) ((pdf->decimal_digits > 4 ? 4 : 3) + delta) - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfthread.c b/Build/source/texk/web2c/luatexdir/pdf/pdfthread.c deleted file mode 100644 index 20cc7bf0a45..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfthread.c +++ /dev/null @@ -1,276 +0,0 @@ -/* - -Copyright 2009-2012 Taco Hoekwater <taco@@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" - -/*tex - - Threads are handled in similar way as link annotations. - -*/ - -void append_bead(PDF pdf, halfword p) -{ - int a, b, c, t; - if (global_shipping_mode == SHIPPING_FORM) - normal_error("pdf backend", "threads cannot be inside an xform"); - t = pdf_get_obj(pdf, obj_type_thread, pdf_thread_id(p), pdf_thread_named_id(p)); - b = pdf_create_obj(pdf, obj_type_others, 0); - obj_bead_ptr(pdf, b) = pdf_get_mem(pdf, pdfmem_bead_size); - set_obj_bead_page(pdf, b, pdf->last_page); - set_obj_bead_data(pdf, b, p); - if (pdf_thread_attr(p) != null) - set_obj_bead_attr(pdf, b, tokens_to_string(pdf_thread_attr(p))); - else - set_obj_bead_attr(pdf, b, 0); - if (obj_thread_first(pdf, t) == 0) { - obj_thread_first(pdf, t) = b; - set_obj_bead_next(pdf, b, b); - set_obj_bead_prev(pdf, b, b); - } else { - a = obj_thread_first(pdf, t); - c = obj_bead_prev(pdf, a); - set_obj_bead_prev(pdf, b, c); - set_obj_bead_next(pdf, b, a); - set_obj_bead_prev(pdf, a, b); - set_obj_bead_next(pdf, c, b); - } - addto_page_resources(pdf, obj_type_bead, b); -} - -void do_thread(PDF pdf, halfword p, halfword parent_box, scaledpos cur) -{ - scaled_whd alt_rule; - if ((type(p) == hlist_node) && (subtype(p) == pdf_start_thread_node)) - normal_error("pdf backend", "'startthread' ended up in hlist"); - if (doing_leaders) - return; - if (subtype(p) == pdf_start_thread_node) { - pdf->thread.wd = width(p); - pdf->thread.ht = height(p); - pdf->thread.dp = depth(p); - pdf->last_thread_id = pdf_thread_id(p); - pdf->last_thread_named_id = (pdf_thread_named_id(p) > 0); - if (pdf->last_thread_named_id) - add_token_ref(pdf_thread_id(p)); - pdf->thread_level = cur_s; - } - alt_rule.wd = width(p); - alt_rule.ht = height(p); - alt_rule.dp = depth(p); - set_rect_dimens(pdf, p, parent_box, cur, alt_rule, pdf_thread_margin); - append_bead(pdf, p); - pdf->last_thread = p; -} - -void append_thread(PDF pdf, halfword parent_box, scaledpos cur) -{ - scaled_whd alt_rule; - halfword p = new_node(whatsit_node, pdf_thread_data_node); - width(p) = pdf->thread.wd; - height(p) = pdf->thread.ht; - depth(p) = pdf->thread.dp; - pdf_thread_attr(p) = null; - pdf_thread_id(p) = pdf->last_thread_id; - if (pdf->last_thread_named_id) { - add_token_ref(pdf_thread_id(p)); - pdf_thread_named_id(p) = 1; - } else { - pdf_thread_named_id(p) = 0; - } - alt_rule.wd = width(p); - alt_rule.ht = height(p); - alt_rule.dp = depth(p); - set_rect_dimens(pdf, p, parent_box, cur, alt_rule, pdf_thread_margin); - append_bead(pdf, p); - pdf->last_thread = p; -} - -void end_thread(PDF pdf, halfword p) -{ - scaledpos pos = pdf->posstruct->pos; - if (type(p) == hlist_node) - normal_error("pdf backend", "'endthread' ended up in hlist"); - if (pdf->thread_level != cur_s) - normal_error("pdf backend", "'endthread' ended up in different nesting level than 'startthread'"); - if (is_running(pdf->thread.dp) && (pdf->last_thread != null)) { - switch (pdf->posstruct->dir) { - case dir_TLT: - case dir_TRT: - pdf_ann_bottom(pdf->last_thread) = pos.v - pdf_thread_margin; - break; - case dir_LTL: - pdf_ann_right(pdf->last_thread) = pos.h + pdf_thread_margin; - break; - case dir_RTT: - pdf_ann_left(pdf->last_thread) = pos.h - pdf_thread_margin; - break; - default: - formatted_warning("pdf backend","forcing bad dir %i to TLT in end tread",pdf->posstruct->dir); - } - } - if (pdf->last_thread_named_id) - delete_token_ref(pdf->last_thread_id); - pdf->last_thread = null; -} - -/*tex The following function are needed for outputing article thread. */ - -void thread_title(PDF pdf, int t) -{ - pdf_add_name(pdf, "Title"); - pdf_out(pdf, '('); - if (obj_info(pdf, t) < 0) - pdf_print(pdf, -obj_info(pdf, t)); - else - pdf_print_int(pdf, obj_info(pdf, t)); - pdf_out(pdf, ')'); -} - -void pdf_fix_thread(PDF pdf, int t) -{ - halfword a; - if (obj_info(pdf, t) < 0) { - char *ss = makecstring(-obj_info(pdf, t)); - formatted_warning("pdf backend", "unknown thread destination name '%s'",ss); - } else { - formatted_warning("pdf backend", "unknown thread destination num '%d'",obj_info(pdf, t)); - } - a = pdf_create_obj(pdf, obj_type_others, 0); - pdf_begin_obj(pdf, a, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - pdf_dict_add_ref(pdf, "T", t); - pdf_dict_add_ref(pdf, "V", a); - pdf_dict_add_ref(pdf, "N", a); - pdf_dict_add_ref(pdf, "P", pdf->last_page); - pdf_add_name(pdf, "R"); - pdf_begin_array(pdf); - pdf_add_int(pdf, 0); - pdf_add_int(pdf, 0); - pdf_add_bp(pdf, page_width_par); - pdf_add_bp(pdf, page_height_par); - pdf_end_array(pdf); - pdf_end_dict(pdf); - pdf_end_obj(pdf); - pdf_begin_obj(pdf, t, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - pdf_add_name(pdf, "I"); - pdf_begin_dict(pdf); - thread_title(pdf, t); - pdf_end_dict(pdf); - pdf_dict_add_ref(pdf, "F", a); - pdf_end_dict(pdf); - pdf_end_obj(pdf); -} - -void out_thread(PDF pdf, int t) -{ - halfword a, b; - int last_attr; - if (obj_thread_first(pdf, t) == 0) { - pdf_fix_thread(pdf, t); - return; - } - pdf_begin_obj(pdf, t, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - a = obj_thread_first(pdf, t); - b = a; - last_attr = 0; - do { - if (obj_bead_attr(pdf, a) != 0) - last_attr = obj_bead_attr(pdf, a); - a = obj_bead_next(pdf, a); - } while (a != b); - if (last_attr != 0) { - pdf_print_ln(pdf, last_attr); - } else { - pdf_add_name(pdf, "I"); - pdf_begin_dict(pdf); - thread_title(pdf, t); - pdf_end_dict(pdf); - } - pdf_dict_add_ref(pdf, "F", a); - pdf_end_dict(pdf); - pdf_end_obj(pdf); - do { - pdf_begin_obj(pdf, a, OBJSTM_ALWAYS); - pdf_begin_dict(pdf); - if (a == b) - pdf_dict_add_ref(pdf, "T", t); - pdf_dict_add_ref(pdf, "V", obj_bead_prev(pdf, a)); - pdf_dict_add_ref(pdf, "N", obj_bead_next(pdf, a)); - pdf_dict_add_ref(pdf, "P", obj_bead_page(pdf, a)); - pdf_dict_add_ref(pdf, "R", obj_bead_rect(pdf, a)); - pdf_end_dict(pdf); - pdf_end_obj(pdf); - a = obj_bead_next(pdf, a); - } while (a != b); -} - -void scan_thread_id(void) -{ - if (scan_keyword("num")) { - scan_int(); - if (cur_val <= 0) - normal_error("pdf backend", "num identifier must be positive"); - if (cur_val > max_halfword) - normal_error("pdf backend", "number too big"); - set_pdf_thread_id(cur_list.tail_field, cur_val); - set_pdf_thread_named_id(cur_list.tail_field, 0); - } else if (scan_keyword("name")) { - scan_toks(false, true); - set_pdf_thread_id(cur_list.tail_field, def_ref); - set_pdf_thread_named_id(cur_list.tail_field, 1); - } else { - normal_error("pdf backend", "identifier type missing"); - } -} - -void check_running_thread(PDF pdf, halfword this_box, scaledpos cur) -{ - if ((pdf->last_thread != null) && is_running(pdf->thread.dp) - && (pdf->thread_level == cur_s)) - append_thread(pdf, this_box, cur); -} - -void print_bead_rectangles(PDF pdf) -{ - halfword i; - pdf_object_list *k; - int l; - if ((k = get_page_resources_list(pdf, obj_type_bead)) != NULL) { - while (k != NULL) { - l = pdf_create_obj(pdf, obj_type_others, 0); - pdf_begin_obj(pdf, l, OBJSTM_ALWAYS); - pdf_begin_array(pdf); - /*tex A pointer to a whatsit or whatsit-like node: */ - i = obj_bead_data(pdf, k->info); - pdf_add_rect_spec(pdf, i); - if (subtype(i) == pdf_thread_data_node) - flush_node(i); - pdf_end_array(pdf); - pdf_end_obj(pdf); - /*tex Rewrite |obj_bead_data|: */ - set_obj_bead_rect(pdf, k->info, l); - k = k->link; - } - } -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfthread.h b/Build/source/texk/web2c/luatexdir/pdf/pdfthread.h deleted file mode 100644 index dd9078444fc..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfthread.h +++ /dev/null @@ -1,72 +0,0 @@ -/* pdfthread.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. -*/ - - -#ifndef PDFTHREAD_H -# define PDFTHREAD_H - -/* data structure of threads; words 1..4 represent the coordinates of the corners */ - -# define obj_thread_first obj_aux /* pointer to the first bead */ - -/* data structure of beads */ -# define pdfmem_bead_size 5 /* size of memory in |pdf->mem| which |obj_bead_ptr| points to */ - -# define set_pdf_thread_attr(A,B) pdf_thread_attr(A)=B -# define set_pdf_thread_id(A,B) pdf_thread_id(A)=B -# define set_pdf_thread_named_id(A,B) pdf_thread_named_id(A)=B - -# define obj_bead_ptr obj_aux /* pointer to |pdf->mem| */ -# define obj_bead_rect(pdf,A) pdf->mem[obj_bead_ptr(pdf,A)] -# define obj_bead_page(pdf,A) pdf->mem[obj_bead_ptr(pdf,A) + 1] -# define obj_bead_next(pdf,A) pdf->mem[obj_bead_ptr(pdf,A) + 2] -# define obj_bead_prev(pdf,A) pdf->mem[obj_bead_ptr(pdf,A) + 3] -# define obj_bead_attr(pdf,A) pdf->mem[obj_bead_ptr(pdf,A) + 4] -# define obj_bead_data obj_bead_rect -# define set_obj_bead_data set_obj_bead_rect - -# define set_obj_bead_rect(pdf,A,B) obj_bead_rect(pdf,A)=B -# define set_obj_bead_page(pdf,A,B) obj_bead_page(pdf,A)=B -# define set_obj_bead_next(pdf,A,B) obj_bead_next(pdf,A)=B -# define set_obj_bead_prev(pdf,A,B) obj_bead_prev(pdf,A)=B -# define set_obj_bead_attr(pdf,A,B) obj_bead_attr(pdf,A)=B - - -/* - pointer to the corresponding whatsit node; |obj_bead_rect| is needed only when the bead - rectangle has been written out and after that |obj_bead_data| is not needed any more - so we can use this field for both -*/ - -extern void append_bead(PDF pdf, halfword p); -extern void do_thread(PDF pdf, halfword parent_box, halfword p, scaledpos cur); -extern void append_thread(PDF pdf, halfword parent_box, scaledpos cur); -extern void end_thread(PDF pdf, halfword p); -extern void scan_thread_id(void); - -extern void thread_title(PDF pdf, int t); -extern void pdf_fix_thread(PDF pdf, int t); -extern void out_thread(PDF pdf, int t); - -extern void check_running_thread(PDF pdf, halfword this_box, scaledpos cur); -extern void print_bead_rectangles(PDF pdf); -extern void flush_beads_list(void); - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdftypes.h b/Build/source/texk/web2c/luatexdir/pdf/pdftypes.h deleted file mode 100644 index ad2465f5283..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdftypes.h +++ /dev/null @@ -1,390 +0,0 @@ -/* pdftypes.h - - Copyright 2009-2013 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#ifndef PDFTYPES_H -# define PDFTYPES_H - -#ifdef HAVE_CONFIG_H -#include <w2c/config.h> -#endif -# include <zlib.h> -# include "lua/luatex-api.h" - -/* - The prefix "PTEX" for the PDF keys is special to pdfTeX and has been registered with - Adobe by Hans Hagen. -*/ - -# define pdfkeyprefix "PTEX" - -# define i32round(a) (int) floor((a) + 0.5) -/*# define i64round(a) (int64_t) floor((a) + 0.5)*/ -/*# define i64round(a) (int64_t) ( (double)(a+0.5) - ((int64_t)(a+0.5))%1 ) */ -#ifdef _WIN32 -# define i64round(a) (int64_t) win32_floor((a) + 0.5) -#else -# define i64round(a) (int64_t) llround((a)) -#endif - - -# define MAX_OBJ_COMPRESS_LEVEL 3 /* maximum/clipping value for \pdfobjcompresslevel */ -# define OBJSTM_UNSET -1 /* initial value */ -# define OBJSTM_ALWAYS 1 /* \pdfobjcompresslevel >= OBJSTM_ALWAYS: put object into object stream */ -# define OBJSTM_NEVER (MAX_OBJ_COMPRESS_LEVEL + 1) /* above maximum/clipping value for \pdfobjcompresslevel */ - -typedef int internal_font_number; /* |font| in a |char_node| */ - -typedef enum { - NO_ZIP, /* no \.{ZIP} compression */ - ZIP_WRITING, /* \.{ZIP} compression being used */ - ZIP_FINISH /* finish \.{ZIP} compression */ -} zip_write_state_e; - -typedef enum { - PDFOUT_BUF, - OBJSTM_BUF, -} buffer_e; - -/* - This stucture holds everything that is needed for the actual pdf generation. - - Because this structure interfaces with C++, it is not wise to use |boolean| - here (C++ has a boolean type built-in that is not compatible). Also, I have - plans to convert the backend code into a C library for use with e.g. standalone - lua. Together, this means that it is best only to use the standard C types and - the types explicitly defined in this header, and stay away from types like - |integer| and |eight_bits| that are used elsewhere in the \LUATEX\ sources. - -*/ - -typedef struct { - int64_t m; /* mantissa (significand) */ - int e; /* exponent * -1 */ -} pdffloat; - -typedef struct { - pdffloat h; - pdffloat v; -} pdfpos; - -# define scaled int - -typedef struct scaledpos_ { - int64_t h; - int64_t v; -} scaledpos; - -typedef struct scaled_whd_ { - scaled wd; /* TeX width */ - scaled ht; /* TeX height */ - scaled dp; /* TeX depth */ -} scaled_whd; - -typedef struct posstructure_ { - scaledpos pos; /* position on the page */ - int dir; /* direction of stuff to be put onto the page */ -} posstructure; - -/* typedef struct { */ -/* scaledpos curpos; */ /* \pdflastpos position */ -/* posstructure boxpos; */ /* box dir and position of the box origin on the page */ -/* scaled_whd boxdim; */ /* box dimensions (in hlist/vlist coordinate system) */ -/* } pos_info_structure; */ - -typedef enum { - PMODE_NONE, - PMODE_PAGE, - PMODE_TEXT, - PMODE_CHARARRAY, - PMODE_CHAR -} pos_mode; - -typedef enum { - ST_INITIAL, - ST_OMODE_FIX, - ST_FILE_OPEN, - ST_HEADER_WRITTEN, - ST_FILE_CLOSED -} output_state; - -typedef struct pdf_object_list_ { - int info; - struct pdf_object_list_ *link; -} pdf_object_list; - -typedef enum { /* []TJ runs horizontal or vertical */ - WMODE_H, - WMODE_V -} writing_mode; - -typedef struct { - pdfpos pdf; /* pos. on page (PDF page raster) */ - pdfpos pdf_bt_pos; /* pos. at begin of BT-ET group (PDF page raster) */ - pdfpos pdf_tj_pos; /* pos. at begin of TJ array (PDF page raster) */ - pdffloat cw; /* pos. within [(..)..]TJ array (glyph raster); cw.e = fractional digits in /Widths array */ - pdffloat tj_delta; /* rel. movement in [(..)..]TJ array (glyph raster) */ - pdffloat fs; /* font size in PDF units */ - pdffloat fs_cur; /* to check if fs.m has changed and Tf needed */ - pdffloat tm0_cur; /* to check if tm[0] has changed and Tm needed */ - pdffloat cm[6]; /* cm array */ - pdffloat tm[6]; /* Tm array */ - double k1; /* conv. factor from TeX sp to PDF page raster */ - double k2; /* conv. factor from PDF page raster to TJ array raster */ - int f_pdf; /* /F* font number, of unexpanded base font! */ - int f_pdf_cur; /* to check if f_pdf has changed and Tf needed */ - writing_mode wmode; /* PDF writing mode WMode (horizontal/vertical) */ - pos_mode mode; /* current positioning mode */ - int ishex; /* Whether the current char string is <> or () */ - int need_tf; /* flag whether Tf needs to be set */ - int need_tm; /* flag whether Tm needs to be set */ - int cur_ex; /* the current glyph ex factor */ - int need_width; - int need_mode; - int done_width; - int done_mode; -} pdfstructure; - -typedef struct obj_entry_ { - union { - int int0; - char *str0; - } u; - int int1; - off_t int2; - int int3; - union { - int int4; - char *str4; - } v; - int objtype; /* integer int5 */ -} obj_entry; - -typedef struct dest_name_entry_ { - char *objname; /* destination name */ - int objnum; /* destination object number */ -} dest_name_entry; - -# define pdf_max_link_level 10 /* maximum depth of link nesting */ - -typedef struct pdf_link_stack_record { - int nesting_level; - int link_node; /* holds a copy of the corresponding |pdf_start_link_node| */ - int ref_link_node; /* points to original |pdf_start_link_node|, or a - copy of |link_node| created by |append_link| in - case of multi-line link */ -} pdf_link_stack_record; - -/* types of objects */ - -/* - NB: |obj_type_thread| is the highest entry in |head_tab|, but there are a few - more linked lists that are handy. -*/ - -typedef enum { - obj_type_font = 0, /* index of linked list of Fonts objects */ - obj_type_outline = 1, /* index of linked list of outline objects */ - obj_type_dest = 2, /* index of linked list of destination objects */ - obj_type_obj = 3, /* index of linked list of raw objects */ - obj_type_xform = 4, /* index of linked list of XObject forms */ - obj_type_ximage = 5, /* index of linked list of XObject images */ - obj_type_thread = 6, /* index of linked list of num article threads */ - obj_type_pagestream = 7, /* Page stream objects */ - obj_type_page = 8, /* /Page objects */ - obj_type_pages = 9, /* /Pages objects */ - obj_type_catalog = 10, /* /Catalog object */ - obj_type_info = 11, /* /Info object */ - obj_type_link = 12, /* link objects */ - obj_type_annot = 13, /* annotation objects */ - obj_type_annots = 14, /* /Annots objects */ - obj_type_bead = 15, /* thread bead objects */ - obj_type_beads = 16, /* /B objects (array of bead objects) */ - obj_type_objstm = 17, /* /ObjStm objects */ - obj_type_others = 18 /* any other objects (also not linked in any list) */ -} pdf_obj_type; - -# define HEAD_TAB_MAX 6 /* obj_type_thread */ -# define PDF_OBJ_TYPE_MAX 18 /* obj_type_others */ - -typedef struct pdf_resource_struct_ { - struct avl_table *resources_tree; - int last_resources; /* halfword to most recently generated Resources object. */ -} pdf_resource_struct; - - -typedef struct os_obj_data_ { - int num; - int off; -} os_obj_data; - -typedef struct strbuf_s_ { - unsigned char *data; /* a PDF stream buffer */ - unsigned char *p; /* pointer to the next character in the PDF stream buffer */ - size_t size; /* currently allocated size of the PDF stream buffer, grows dynamically */ - size_t limit; /* maximum allowed PDF stream buffer size */ -} strbuf_s; - -typedef struct os_struct_ { - os_obj_data *obj; /* array of object stream objects */ - strbuf_s *buf[3]; - buffer_e curbuf; /* select into which buffer to output */ - unsigned int cur_objstm; /* number of current object stream object */ - unsigned int idx; /* index of object within object stream [1...PDF_OS_MAX_OBJS - 1] */ - unsigned int ostm_ctr; /* statistics: counter for object stream objects */ - unsigned int o_ctr; /* statistics: counter for objects within object streams */ -} os_struct; - - -# define packet_max_recursion 100 /* see |packet_cur_s| */ -# define packet_stack_size 100 - -typedef struct packet_stack_record_ { - float c0; - float c1; - float c2; - float c3; - scaledpos pos; /* c4, c5 */ -} packet_stack_record; - -typedef struct vf_struct_ { - packet_stack_record *packet_stack; /* for "push" and "pop" */ - int packet_stack_level; - int packet_stack_minlevel; /* to check stack underflow */ - internal_font_number lf; /* local font number, resolved */ - int fs_f; /* local font size */ - int ex_glyph; /* expansion value; ex_glyph = 0 means unexpanded */ - int packet_cur_s; /* do_vf_packet() nesting level */ - posstructure *refpos; - int vflua; /* flag, whether vf.*() functions are allowed */ -} vf_struct; - -typedef struct pdf_output_file_ { - FILE *file; /* the PDF output file handle */ - char *file_name; /* the PDF output file name */ - char *job_name; - output_mode o_mode; /* output mode (DVI/PDF/...) */ - output_state o_state; - /* generation parameters */ - int gamma; - int image_gamma; - int image_hicolor; /* boolean */ - int image_apply_gamma; - int draftmode; - int pk_resolution; - int pk_fixed_dpi; - int decimal_digits; - int gen_tounicode; - int omit_cidset; - int omit_charset; - int inclusion_copy_font; - int major_version; /* fixed major part of the PDF version */ - int minor_version; /* fixed minor part of the PDF version */ - int recompress; - int compress_level; /* level for zlib object stream compression */ - int objcompresslevel; /* fixed level for activating PDF object streams */ - char *job_id_string; /* the full job string */ - - int os_enable; /* true if object streams are globally enabled */ - os_struct *os; /* object stream structure pointer */ - - strbuf_s *buf; /* pointer to the current stream buffer (PDF stream, ObjStm, or Lua) */ - - off_t save_offset; /* to save |pdf_offset| */ - off_t gone; /* number of bytes that were flushed to output */ - - char *printf_buf; /* a scratch buffer for |pdf_printf| */ - - time_t start_time; /* when this job started */ - char *start_time_str; /* minimum size for time_str is 24: "D:YYYYmmddHHMMSS+HH'MM'" */ - - strbuf_s *fb; /* pointer to auxiliary buffer for font stuff */ - - char *zipbuf; - z_stream *c_stream; /* compression stream pointer */ - zip_write_state_e zip_write_state; /* which state of compression we are in */ - int stream_deflate; /* true, if stream dict has /Filter/FlateDecode */ - int stream_writing; /* true while writing stream */ - - int pk_scale_factor; /* this is just a preprocessed value that depends on |pk_resolution| and |decimal_digits| */ - - int img_page_group_val; /* page group information pointer from included pdf or png images */ - char *resname_prefix; /* global prefix of resources name */ - - int mem_size; /* allocated size of |mem| array */ - int *mem; - int mem_ptr; - - pdfstructure *pstruct; /* utity structure keeping position status in PDF page stream */ - posstructure *posstruct; /* structure for positioning within page */ - - int obj_tab_size; /* allocated size of |obj_tab| array */ - obj_entry *obj_tab; - int head_tab[HEAD_TAB_MAX + 1]; /* heads of the object lists in |obj_tab| */ - struct avl_table *obj_tree[PDF_OBJ_TYPE_MAX + 1]; /* this is useful for finding the objects back */ - - int pages_tail; - int obj_ptr; /* objects counter */ - int last_pages; /* pointer to most recently generated pages object */ - int last_page; /* pointer to most recently generated page object */ - int last_stream; /* pointer to most recently generated stream */ - off_t stream_length; /* length of most recently generated stream */ - off_t stream_length_offset; /* file offset of the last stream length */ - int seek_write_length; /* flag whether to seek back and write \.{/Length} */ - int last_byte; /* byte most recently written to PDF file; for \.{endstream} in new line */ - - int obj_count; - int xform_count; - int ximage_count; - - int force_file; - - pdf_resource_struct *page_resources; - - scaledpos page_size; /* width and height of page being shipped */ - - /* the variables from pdfdest */ - int dest_names_size; - int dest_names_ptr; - dest_name_entry *dest_names; - /* the (static) variables from pdfoutline */ - int first_outline; - int last_outline; - int parent_outline; - /* the pdf link stack */ - pdf_link_stack_record link_stack[(pdf_max_link_level + 1)]; - int link_stack_ptr; - int link_state; - /* the thread data */ - int last_thread; /* pointer to the last thread */ - scaled_whd thread; - int last_thread_id; /* identifier of the last thread */ - int last_thread_named_id; /* is identifier of the last thread named */ - int thread_level; /* depth of nesting of box containing the last thread */ - - int f_cur; /* TeX font number */ - int cave; /* stay away from previous PDF object */ - - vf_struct *vfstruct; -} pdf_output_file; - -typedef pdf_output_file *PDF; - -#endif diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfxform.c b/Build/source/texk/web2c/luatexdir/pdf/pdfxform.c deleted file mode 100644 index 7fd4eef1d82..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfxform.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - -Copyright 2009-2011 Taco Hoekwater <taco@luatex.org> - -This file is part of LuaTeX. - -LuaTeX is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your -option) any later version. - -LuaTeX is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -License for more details. - -You should have received a copy of the GNU General Public License along -with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "ptexlib.h" -#include "pdf/pdfpage.h" - -/*tex The form being output: */ - -int pdf_cur_form; - -void pdf_place_form(PDF pdf, halfword p) -{ - scaled_whd nat, tex; - scaled x, y; - pdffloat cm[6]; - pdfstructure *q = pdf->pstruct; - int r = 6; - int objnum = rule_index(p); - nat.wd = obj_xform_width(pdf, objnum); - nat.ht = obj_xform_height(pdf, objnum); - nat.dp = obj_xform_depth(pdf, objnum); - /*tex No transform yet: */ - tex.wd = width(p); - tex.ht = height(p); - tex.dp = depth(p); - if (nat.wd != tex.wd || nat.ht != tex.ht || nat.dp != tex.dp) { - x = ext_xn_over_d(ten_pow[r], tex.wd, nat.wd); - y = ext_xn_over_d(ten_pow[r], tex.dp + tex.ht, nat.dp + nat.ht); - } else - x = y = ten_pow[r]; - setpdffloat(cm[0], x, r); - setpdffloat(cm[1], 0, r); - setpdffloat(cm[2], 0, r); - setpdffloat(cm[3], y, r); - pdf_goto_pagemode(pdf); - (void) calc_pdfpos(q, pdf->posstruct->pos); - cm[4] = q->cm[4]; - cm[5] = q->cm[5]; - pdf_puts(pdf, "q\n"); - pdf_print_cm(pdf, cm); - pdf_printf(pdf, "/Fm%d", (int) obj_info(pdf, objnum)); - pdf_print_resname_prefix(pdf); - pdf_puts(pdf, " Do\nQ\n"); - addto_page_resources(pdf, obj_type_xform, objnum); -} - -/*tex We will store token lists as strings too. */ - -void scan_pdfxform(PDF pdf) -{ - int k; - halfword p; - pdf->xform_count++; - k = pdf_create_obj(pdf, obj_type_xform, pdf->xform_count); - set_obj_data_ptr(pdf, k, pdf_get_mem(pdf, pdfmem_xform_size)); - if (scan_keyword("type")) { - scan_int(); - set_obj_xform_type(pdf, k, cur_val); - } else { - set_obj_xform_type(pdf, k, 0); - } - if (scan_keyword("attr")) { - scan_toks(false, true); - set_obj_xform_attr(pdf, k, def_ref); - } else { - set_obj_xform_attr(pdf, k, null); - } - set_obj_xform_attr_str(pdf, k, null); - if (scan_keyword("resources")) { - scan_toks(false, true); - set_obj_xform_resources(pdf, k, def_ref); - } else { - set_obj_xform_resources(pdf, k, null); - } - if (scan_keyword("margin")) { - scan_int(); - set_obj_xform_margin(pdf, k, cur_val); - } else { - set_obj_xform_margin(pdf, k, pdf_xform_margin); - } - set_obj_xform_resources_str(pdf, k, null); - scan_int(); - p = box(cur_val); - if (p == null) - normal_error("pdf backend", "xforms cannot be used with a void box"); - /*tex Save the pointer to the box: */ - set_obj_xform_box(pdf, k, p); - set_obj_xform_width(pdf, k, width(p)); - set_obj_xform_height(pdf, k, height(p)); - set_obj_xform_depth(pdf, k, depth(p)); - box(cur_val) = null; - last_saved_box_index = k; -} - -void scan_pdfrefxform(PDF pdf) -{ - scaled_whd alt_rule, dim, nat; - alt_rule = scan_alt_rule(); - scan_int(); - check_obj_type(pdf, obj_type_xform, cur_val); - tail_append(new_rule(box_rule)); - nat.wd = obj_xform_width(pdf, cur_val); - nat.ht = obj_xform_height(pdf, cur_val); - nat.dp = obj_xform_depth(pdf, cur_val); - if (alt_rule.wd != null_flag || alt_rule.ht != null_flag || alt_rule.dp != null_flag) { - dim = tex_scale(nat, alt_rule); - } else { - dim = nat; - } - width(tail_par) = dim.wd; - height(tail_par) = dim.ht; - depth(tail_par) = dim.dp; - rule_index(tail_par) = cur_val; -} diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfxform.h b/Build/source/texk/web2c/luatexdir/pdf/pdfxform.h deleted file mode 100644 index 2d6441ff496..00000000000 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfxform.h +++ /dev/null @@ -1,56 +0,0 @@ -/* pdfxform.h - - Copyright 2009 Taco Hoekwater <taco@luatex.org> - - This file is part of LuaTeX. - - LuaTeX is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your - option) any later version. - - LuaTeX is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU General Public License along - with LuaTeX; if not, see <http://www.gnu.org/licenses/>. - -*/ - -#ifndef PDFXFORM_H -# define PDFXFORM_H - -# define pdfmem_xform_size 10 /* size of memory in |pdf->mem| which |obj_data_ptr| holds */ - -# define obj_xform_width(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 0] -# define obj_xform_height(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 1] -# define obj_xform_depth(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 2] -# define obj_xform_box(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 3] /* this field holds pointer to the corresponding box */ -# define obj_xform_attr(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 4] /* additional xform attributes */ -# define obj_xform_resources(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 5] /* additional xform Resources */ -# define obj_xform_attr_str(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 6] -# define obj_xform_resources_str(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 7] -# define obj_xform_type(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 8] -# define obj_xform_margin(pdf,A) pdf->mem[obj_data_ptr(pdf,A) + 9] - -# define set_pdf_xform_objnum(A,B) pdf_xform_objnum(A)=B -# define set_obj_xform_width(pdf,A,B) obj_xform_width(pdf,A)=B -# define set_obj_xform_height(pdf,A,B) obj_xform_height(pdf,A)=B -# define set_obj_xform_depth(pdf,A,B) obj_xform_depth(pdf,A)=B -# define set_obj_xform_box(pdf,A,B) obj_xform_box(pdf,A)=B -# define set_obj_xform_attr(pdf,A,B) obj_xform_attr(pdf,A)=B -# define set_obj_xform_resources(pdf,A,B) obj_xform_resources(pdf,A)=B -# define set_obj_xform_attr_str(pdf,A,B) obj_xform_attr_str(pdf,A)=B -# define set_obj_xform_resources_str(pdf,A,B) obj_xform_resources_str(pdf,A)=B -# define set_obj_xform_type(pdf,A,B) obj_xform_type(pdf,A)=B -# define set_obj_xform_margin(pdf,A,B) obj_xform_margin(pdf,A)=B - -extern int pdf_cur_form; /* the form being output */ - -void pdf_place_form(PDF pdf, halfword p); -void scan_pdfxform(PDF pdf); -void scan_pdfrefxform(PDF pdf); - -#endif |