ptr tex::vsplit(int n, scal h) { ptr p; ptr q; ptr v; v = box(n); if (split_first_mark != null) { delete_token_ref(split_first_mark); split_first_mark = null; delete_token_ref(split_bot_mark); split_bot_mark = null; } if (v == null) return null; if (type(v) != VLIST_NODE) { print_err(null_str); print_esc("vsplit"); print(" needs a "); print_esc("vbox"); help_vsplit_vbox(); error(); return null; } q = vert_break(list_ptr(v), h, split_max_depth); p = list_ptr(v); if (p == q) { list_ptr(v) = null; } else { loop { if (type(p) == MARK_NODE) { if (split_first_mark == null) { split_first_mark = mark_ptr(p); split_bot_mark = split_first_mark; token_ref_count(split_first_mark) += 2; } else { delete_token_ref(split_bot_mark); split_bot_mark = mark_ptr(p); add_token_ref(split_bot_mark); } } if (link(p) == q) { link(p) = null; break; } p = link(p); } } q = prune_page_top(q); p = list_ptr(v); free_node(v, BOX_NODE_SIZE); if (q == null) { box(n) = null; } else { box(n) = vpack(q, 0, ADDITIONAL); } return (vpackage(p, h, EXACTLY, split_max_depth)); }
static void do_extension_pdf(int immediate) { int i; if(scan_keyword("literal")){ new_whatsit(pdf_literal_node); if(scan_keyword("direct")) set_pdf_literal_mode(tail,direct_always); else if(scan_keyword("page")) set_pdf_literal_mode(tail,direct_page); else set_pdf_literal_mode(tail,set_origin); scan_toks(false,true); set_pdf_literal_type(tail,normal); set_pdf_literal_data(tail,def_ref); }else if(scan_keyword("dest")){ scan_pdfdest(static_pdf); }else if(scan_keyword("annot")){ scan_annot(static_pdf); }else if(scan_keyword("save")){ new_whatsit(pdf_save_node); }else if(scan_keyword("restore")){ new_whatsit(pdf_restore_node); }else if(scan_keyword("setmatrix")){ new_whatsit(pdf_setmatrix_node); scan_toks(false,true); set_pdf_setmatrix_data(tail,def_ref); }else if(scan_keyword("obj")){ scan_obj(static_pdf); if(immediate){ if(obj_data_ptr(static_pdf,pdf_last_obj)==0) normal_error("pdf backend","\\pdfextension obj 'reserveobjnum' cannot be used with \\immediate"); pdf_write_obj(static_pdf,pdf_last_obj); } }else if(scan_keyword("refobj")){ scan_refobj(static_pdf); }else if(scan_keyword("colorstack")){ scan_int(); if(cur_val>=colorstackused()){ print_err("Unknown color stack number "); print_int(cur_val); help3 ("Allocate and initialize a color stack with \\pdfextension colorstackinit.", "I'll use default color stack 0 here.", "Proceed, with fingers crossed."); error(); cur_val= 0; } if(cur_val<0){ print_err("Invalid negative color stack number"); help2("I'll use default color stack 0 here.", "Proceed, with fingers crossed."); error(); cur_val= 0; } if(scan_keyword("set")) i= colorstack_set; else if(scan_keyword("push")) i= colorstack_push; else if(scan_keyword("pop")) i= colorstack_pop; else if(scan_keyword("current")) i= colorstack_current; else i= -1; if(i>=0){ new_whatsit(pdf_colorstack_node); set_pdf_colorstack_stack(tail,cur_val); set_pdf_colorstack_cmd(tail,i); set_pdf_colorstack_data(tail,null); if(i<=colorstack_data){ scan_toks(false,true); set_pdf_colorstack_data(tail,def_ref); } }else{ print_err("Color stack action is missing"); help3("The expected actions for \\pdfextension colorstack:", " set, push, pop, current", "I'll ignore the color stack command."); error(); } }else if(scan_keyword("startlink")){ scan_startlink(static_pdf); }else if(scan_keyword("endlink")){ if(abs(mode)==vmode) normal_error("pdf backend","\\pdfextension endlink cannot be used in vertical mode"); new_whatsit(pdf_end_link_node); }else if(scan_keyword("startthread")){ new_annot_whatsit(pdf_start_thread_node); scan_thread_id(); }else if(scan_keyword("endthread")){ new_whatsit(pdf_end_thread_node); }else if(scan_keyword("thread")){ new_annot_whatsit(pdf_thread_node); scan_thread_id(); }else if(scan_keyword("outline")){ scan_pdfoutline(static_pdf); }else if(scan_keyword("glyphtounicode")){ glyph_to_unicode(); }else if(scan_keyword("catalog")){ scan_pdfcatalog(static_pdf); }else if(scan_keyword("fontattr")){ scan_font_ident(); i= cur_val; if(i==null_font) normal_error("pdf backend","invalid font identifier"); scan_toks(false,true); set_pdf_font_attr(i,tokens_to_string(def_ref)); if(str_length(pdf_font_attr(i))==0){ flush_str((str_ptr-1)); set_pdf_font_attr(i,0); } }else if(scan_keyword("mapfile")){ scan_toks(false,true); pdfmapfile(def_ref); delete_token_ref(def_ref); }else if(scan_keyword("mapline")){ scan_toks(false,true); pdfmapline(def_ref); delete_token_ref(def_ref); }else if(scan_keyword("includechars")){ pdf_include_chars(static_pdf); }else if(scan_keyword("info")){ scan_toks(false,true); pdf_info_toks= concat_tokens(pdf_info_toks,def_ref); }else if(scan_keyword("names")){ scan_toks(false,true); pdf_names_toks= concat_tokens(pdf_names_toks,def_ref); }else if(scan_keyword("trailer")){ scan_toks(false,true); pdf_trailer_toks= concat_tokens(pdf_trailer_toks,def_ref); }else{ tex_error("unexpected use of \\pdfextension",null); } }
void scan_pdfximage(PDF pdf) { scaled_whd alt_rule; image_dict *idict; int transform = 0, page = 1, pagebox, colorspace = 0; char *named = NULL, *attr = NULL, *file_name = NULL, *user = NULL, *owner = NULL, *visible = NULL; alt_rule = scan_alt_rule(); if (scan_keyword("attr")) { scan_toks(false, true); attr = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); } if (scan_keyword("named")) { scan_toks(false, true); if (0) { named = tokenlist_to_cstring(def_ref, true, NULL); page = 0; } else { normal_warning("pdf backend","named pages are not supported, using page 1"); page = 1; } delete_token_ref(def_ref); } else if (scan_keyword("page")) { scan_int(); page = cur_val; } if (scan_keyword("userpassword")) { scan_toks(false, true); user = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); } if (scan_keyword("ownerpassword")) { scan_toks(false, true); owner = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); } if (scan_keyword("visiblefilename")) { scan_toks(false, true); visible = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); } if (scan_keyword("colorspace")) { scan_int(); colorspace = cur_val; } pagebox = scan_pdf_box_spec(); if (pagebox == PDF_BOX_SPEC_NONE) { pagebox = pdf_pagebox; if (pagebox == PDF_BOX_SPEC_NONE) pagebox = PDF_BOX_SPEC_CROP; } scan_toks(false, true); file_name = tokenlist_to_cstring(def_ref, true, NULL); if (file_name == NULL) { normal_error("pdf backend","no image filename given"); } delete_token_ref(def_ref); idict = read_image(file_name, page, named, colorspace, pagebox, user, owner, visible); img_attr(idict) = attr; img_dimen(idict) = alt_rule; img_transform(idict) = transform; last_saved_image_index = img_objnum(idict); last_saved_image_pages = img_totalpages(idict); }
void tex::fire_up(ptr c) { int n; bool wait; ptr prev_p; scal save_vfuzz; int save_vbadness; ptr save_split_top_skip; ptr p, q, r; if (type(best_page_break) == PENALTY_NODE) { set_output_penalty(penalty(best_page_break)); penalty(best_page_break) = INF_PENALTY; } else { set_output_penalty(INF_PENALTY); } if (bot_mark != null) { if (top_mark != null) delete_token_ref(top_mark); top_mark = bot_mark; add_token_ref(top_mark); delete_token_ref(first_mark); first_mark = null; } if (c == best_page_break) { best_page_break = null; } if (box(255) != null) { print_err(null_str); print_esc("box"); print("255 is not void"); help_box_255(); box_error(255); } insert_penalties = 0; save_split_top_skip = split_top_skip; if (holding_inserts <= 0) { r = link(page_ins_head); while (r != page_ins_head) { if (best_ins_ptr(r) != null) { n = subtype(r); ensure_vbox(n); if (box(n) == null) box(n) = new_null_box(); p = node_list(box(n)); while (link(p) != null) { p = link(p); } last_ins_ptr(r) = p; } r = link(r); } } q = hold_head; link(q) = null; prev_p = page_head; p = link(prev_p); while (p != best_page_break) { if (type(p) == INS_NODE) { if (holding_inserts <= 0) { wait = insert_box(p); link(prev_p) = link(p); link(p) = null; if (wait) { q = link(q) = p; incr(insert_penalties); } else { delete_glue_ref(split_top_ptr(p)); free_node(p, INS_NODE_SIZE); } p = prev_p; } } else if (type(p) == MARK_NODE) { if (first_mark == null) { first_mark = mark_ptr(p); add_token_ref(first_mark); } if (bot_mark != null) delete_token_ref(bot_mark); bot_mark = mark_ptr(p); add_token_ref(bot_mark); } prev_p = p; p = link(prev_p); } split_top_skip = save_split_top_skip; if (p != null) { if (link(contrib_head) == null) { if (nest_ptr == nest) { tail = page_tail; } else { contrib_tail = page_tail; } } link(page_tail) = link(contrib_head); link(contrib_head) = p; link(prev_p) = null; } save_vbadness = vbadness; save_vfuzz = vfuzz; vbadness = INF_BAD; vfuzz = MAX_DIMEN; box(255) = vpackage(link(page_head), best_size, EXACTLY, page_max_depth); vbadness = save_vbadness; vfuzz = save_vfuzz; if (last_glue != null) delete_glue_ref(last_glue); start_new_page(); if (q != hold_head) { link(page_head) = link(hold_head); page_tail = q; } r = link(page_ins_head); while (r != page_ins_head) { q = link(r); free_node(r, PAGE_INS_NODE_SIZE); r = q; } link(page_ins_head) = page_ins_head; if (top_mark != null && first_mark == null) { first_mark = top_mark; add_token_ref(top_mark); } if (output_routine != null) { if (dead_cycles >= max_dead_cycles) { print_err("Output loop---"); print_int(dead_cycles); print(" consecutive dead cycles"); help_dead_cycles(); error(); } else { output_active = TRUE; incr(dead_cycles); push_nest(); mode = -VMODE; prev_depth = IGNORE_DEPTH; mode_line = -line; begin_token_list(output_routine, OUTPUT_TEXT); new_save_level(OUTPUT_GROUP); normal_paragraph(); scan_left_brace(); return; } } if (link(page_head) != null) { if (link(contrib_head) == null) { if (nest_ptr == nest) { tail = page_tail; } else { contrib_tail = page_tail; } } else { link(page_tail) = link(contrib_head); } link(contrib_head) = link(page_head); link(page_head) = null; page_tail = page_head; } ship_out(box(255)); box(255) = null; }
void tex::flush_node_list(ptr p) { ptr q; while (p != null) { q = link(p); if (is_char_node(p)) { free_avail(p); } else { switch (type(p)) { case HLIST_NODE: case VLIST_NODE: case UNSET_NODE: flush_node_list(list_ptr(p)); free_node(p, BOX_NODE_SIZE); goto done; case RULE_NODE: free_node(p, RULE_NODE_SIZE); goto done; case INS_NODE: flush_node_list(ins_ptr(p)); delete_glue_ref(split_top_ptr(p)); free_node(p, INS_NODE_SIZE); goto done; case WHATSIT_NODE: free_whatsit(p); goto done; case GLUE_NODE: fast_delete_glue_ref(glue_ptr(p)); if (leader_ptr(p) != null) flush_node_list(leader_ptr(p)); break; case KERN_NODE: case MATH_NODE: case PENALTY_NODE: break; case LIGATURE_NODE: flush_node_list(lig_ptr(p)); break; case MARK_NODE: delete_token_ref(mark_ptr(p)); break; case DISC_NODE: flush_node_list(pre_break(p)); flush_node_list(post_break(p)); break; case ADJUST_NODE: flush_node_list(adjust_ptr(p)); break; case STYLE_NODE: free_node(p, STYLE_NODE_SIZE); goto done; case CHOICE_NODE: flush_node_list(display_mlist(p)); flush_node_list(text_mlist(p)); flush_node_list(script_mlist(p)); flush_node_list(script_script_mlist(p)); free_node(p, STYLE_NODE_SIZE); goto done; case ORD_NOAD: case OP_NOAD: case BIN_NOAD: case REL_NOAD: case OPEN_NOAD: case CLOSE_NOAD: case PUNCT_NOAD: case INNER_NOAD: case RADICAL_NOAD: case OVER_NOAD: case UNDER_NOAD: case VCENTER_NOAD: case ACCENT_NOAD: if (math_type(nucleus(p)) >= SUB_BOX) flush_node_list(math_link(nucleus(p))); if (math_type(supscr(p)) >= SUB_BOX) flush_node_list(math_link(supscr(p))); if (math_type(subscr(p)) >= SUB_BOX) flush_node_list(math_link(subscr(p))); if (type(p) == RADICAL_NOAD) free_node(p, RADICAL_NOAD_SIZE); else if (type(p) == ACCENT_NOAD) free_node(p, ACCENT_NOAD_SIZE); else free_node(p, NOAD_SIZE); goto done; case LEFT_NOAD: case RIGHT_NOAD: free_node(p, NOAD_SIZE); goto done; case FRACTION_NOAD: flush_node_list(math_link(numerator(p))); flush_node_list(math_link(denominator(p))); free_node(p, FRACTION_NOAD_SIZE); goto done; default: confusion("flushing"); break; } free_node(p, SMALL_NODE_SIZE); done:; } p = q; } }