void scr_cp( void ) { char * pa; char * p; int len; getnum_block gn; condcode cc; char cwcurr[4]; cwcurr[0] = SCR_char; cwcurr[1] = 'c'; cwcurr[2] = 'p'; cwcurr[3] = '\0'; p = scan_start; while( *p && *p != ' ' ) { // over cw p++; } while( *p && *p == ' ' ) { // next word start p++; } pa = p; while( *p && *p != ' ' ) { // end of word p++; } len = p - pa; if( len > 0 ) { // no action if no parm gn.argstart = pa; gn.argstop = scan_stop; gn.ignore_blanks = 0; cc = getnum ( &gn ); // try to get numeric value if( cc == notnum ) { xx_opt_err( cwcurr, pa ); scan_restart = scan_stop +1; } else { if( gn.result > 0 ) { // ignore values < 1 if( ((gn.result * wgml_fonts[g_curr_font].line_height) + t_page.cur_depth) > t_page.max_depth ) { last_page_out(); reset_t_page(); } } scan_restart = gn.argstart; } } else { scan_restart = scan_stop +1; } return; }
void gml_exmp( const gmltag * entry ) { tag_cb * wk; entry = entry; scr_process_break(); if( !ProcFlags.xmp_active ) { // no preceding :XMP tag g_err_tag_prec( "XMP" ); scan_start = scan_stop + 1; return; } g_curr_font = font_save; ProcFlags.xmp_active = false; ProcFlags.justify = justify_save; wk = nest_cb; nest_cb = nest_cb->prev; add_tag_cb_to_pool( wk ); /* place the accumulated xlines on the proper page */ ProcFlags.group_elements = false; if( t_doc_el_group.first != NULL ) { t_doc_el_group.depth += (t_doc_el_group.first->blank_lines + t_doc_el_group.first->subs_skip); } if( (t_doc_el_group.depth + t_page.cur_depth) > t_page.max_depth ) { /* the block won't fit on this page */ if( t_doc_el_group.depth <= t_page.max_depth ) { /* the block will be on the next page */ do_page_out(); reset_t_page(); } } while( t_doc_el_group.first != NULL ) { insert_col_main( t_doc_el_group.first ); t_doc_el_group.first = t_doc_el_group.first->next; } t_doc_el_group.depth = 0; t_doc_el_group.last = NULL; scan_start = scan_stop + 1; return; }
void start_doc_sect( void ) { bool first_section; bool header; bool page_r; doc_section ds; font_number font; spacing_line spacing_ln; page_ej page_e; su *p_sk; su *top_sk; uint32_t ind; xx_str *h_string; if( ProcFlags.start_section ) { return; // once is enough } if( !ProcFlags.fb_document_done ) { // the very first section/page do_layout_end_processing(); } first_section = (ProcFlags.doc_sect == doc_sect_none); header = false; // no header string (ABSTRACT, ... ) output page_r = false; // no page number reset page_e = ej_no; // no page eject ProcFlags.start_section = true; ProcFlags.keep_left_margin = false; ds = ProcFlags.doc_sect_nxt; // new section if( ds == doc_sect_none ) { ds = doc_sect_body; // if text without section start assume body } /***********************************************************************/ /* process special section attributes */ /***********************************************************************/ switch( ds ) { case doc_sect_body: page_r = layout_work.body.page_reset; page_e = layout_work.body.page_eject; if( layout_work.body.header ) { header = true; h_string = layout_work.body.string; top_sk = &layout_work.body.pre_top_skip; p_sk = &layout_work.body.post_skip; font = layout_work.body.font; spacing_ln = g_spacing_ln; // standard spacing } break; case doc_sect_titlep: // for preceding :BINCLUDE/:GRAPHIC page_e = ej_yes; init_nest_cb( true ); nest_cb->gtag = t_TITLEP; nest_cb->p_stack->lineno = titlep_lineno; // correct line number break; case doc_sect_abstract: page_r = layout_work.abstract.page_reset; page_e = layout_work.abstract.page_eject; if( layout_work.abstract.header ) { header = true; h_string = layout_work.abstract.string; top_sk = &layout_work.abstract.pre_top_skip; p_sk = &layout_work.abstract.post_skip; font = layout_work.abstract.font; spacing_ln = layout_work.abstract.spacing; } break; case doc_sect_preface: page_r = layout_work.preface.page_reset; page_e = layout_work.preface.page_eject; if( layout_work.preface.header ) { header = true; h_string = layout_work.preface.string; top_sk = &layout_work.preface.pre_top_skip; p_sk = &layout_work.preface.post_skip; font = layout_work.preface.font; spacing_ln = layout_work.preface.spacing; } break; case doc_sect_appendix: page_r = layout_work.appendix.page_reset; page_e = layout_work.appendix.page_eject; if( layout_work.appendix.header ) { header = true; h_string = layout_work.appendix.string; top_sk = &layout_work.appendix.pre_top_skip; p_sk = &layout_work.appendix.post_skip; font = layout_work.appendix.font; spacing_ln = layout_work.appendix.spacing; } break; case doc_sect_backm: page_r = layout_work.backm.page_reset; page_e = layout_work.backm.page_eject; if( layout_work.backm.header ) { header = true; h_string = layout_work.backm.string; top_sk = &layout_work.backm.pre_top_skip; p_sk = &layout_work.backm.post_skip; font = layout_work.backm.font; spacing_ln = g_spacing_ln; // standard spacing } break; case doc_sect_index: page_r = layout_work.index.page_reset; page_e = layout_work.index.page_eject; if( layout_work.index.header ) { header = true; h_string = layout_work.index.index_string; top_sk = &layout_work.index.pre_top_skip; p_sk = &layout_work.index.post_skip; font = layout_work.index.font; spacing_ln = layout_work.index.spacing; } break; default: new_section( ds ); break; } if( first_section ) { // nothing precedes the first section if( page_e == ej_even ) { do_page_out(); // apage of first page is odd page = 0; // restart page for first text page } new_section( ds ); reset_t_page(); document_new_position(); // first text page ready for content } else { full_page_out(); // ensure are on last page switch( page_e ) { // page eject requested case ej_yes : finish_page_section( ds, true );// emit last page in old section if( page_r ) { page = 0; } reset_t_page(); break; case ej_odd : if( !(apage & 1) ) { // first page would be even do_page_out(); // emit last page in old section reset_t_page(); } finish_page_section( ds, true );// emit last page in old section if( page_r ) { page = 0; } reset_t_page(); break; case ej_even : if( (apage & 1) ) { // first page will be odd do_page_out(); // emit last page in old section reset_t_page(); } finish_page_section( ds, true );// emit last page in old section if( page_r ) { page = 0; } reset_t_page(); break; default: // ej_no new_section( ds ); /****************************************************/ /* set page bottom banner/limit for new section */ /****************************************************/ ind = !(page & 1); t_page.bottom_banner = sect_ban_bot[ind]; if( sect_ban_bot[ind] != NULL ) { if( bin_driver->y_positive == 0 ) { g_page_bottom = g_page_bottom_org + sect_ban_bot[ind]->ban_depth; } else { g_page_bottom = g_page_bottom_org - sect_ban_bot[ind]->ban_depth; } } else { g_page_bottom = g_page_bottom_org; } break; } } g_cur_left = g_page_left_org; g_cur_h_start = g_page_left_org + g_indent; if( header ) { doc_header( p_sk, top_sk, h_string, font, spacing_ln, page_e == ej_no ); } ProcFlags.doc_sect = ds; }
static void gml_hx_common( gml_tag gtag, int hx_lvl ) { char * p; char * headp; bool idseen; bool stitleseen; int rc; int k; size_t headlen; size_t txtlen; char hnumstr[64]; ref_entry * re; ref_entry * rwk; static char hxstr[4] = ":HX"; static char htextx[8] = "$htextX"; static char headx[7] = "$headX"; gtag = gtag; *(hxstr + 2) = '0' + hx_lvl; htextx[6] = '0' + hx_lvl; hnumx[5] = '0' + hx_lvl; headx[5] = '0' + hx_lvl; switch( hx_lvl ) { case 0: if( !((ProcFlags.doc_sect == doc_sect_body) || (ProcFlags.doc_sect_nxt == doc_sect_body)) ) { g_err( err_tag_wrong_sect, hxstr, ":BODY section" ); err_count++; file_mac_info(); } break; case 1: if( !((ProcFlags.doc_sect >= doc_sect_body) || (ProcFlags.doc_sect_nxt >= doc_sect_body)) ) { g_err( err_tag_wrong_sect, hxstr, ":BODY :APPENDIX :BACKM sections" ); err_count++; file_mac_info(); } break; default: if( !((ProcFlags.doc_sect >= doc_sect_abstract) || (ProcFlags.doc_sect_nxt >= doc_sect_abstract)) ) { g_err( err_tag_wrong_sect, hxstr, ":ABSTRACT section or later" ); err_count++; file_mac_info(); } break; } if( layout_work.hx[hx_lvl].number_form != num_none ) { layout_work.hx[hx_lvl].headn++; } idseen = false; stitleseen = false; p = scan_start; re = NULL; /***********************************************************************/ /* Scan attributes for :Hx */ /* id= */ /* stitle= */ /***********************************************************************/ for( ;; ) { while( *p == ' ' ) { p++; } if( *p == '\0' || *p == '.' ) { break; // tag end found } if( !strnicmp( "stitle=", p, 7 ) ) { p += 6; stitleseen = true; /***************************************************************/ /* Although unsupported scan stitle='xxx' */ /***************************************************************/ g_warn( wng_unsupp_att, "stitle" ); wng_count++; file_mac_info(); p = get_att_value( p ); scan_start = p; if( !ProcFlags.tag_end_found ) { continue; } break; } /*******************************************************************/ /* ID='xxxxxxxx' */ /*******************************************************************/ if( !strnicmp( "id=", p, 3 ) ) { p += 2; p = get_refid_value( p ); if( val_len > 0 ) { idseen = true; // valid id attribute found *(val_start + val_len) = '\0'; if( re == NULL ) { // prepare reference entry re = mem_alloc( sizeof( ref_entry ) ); init_ref_entry( re, val_start, val_len ); } else { fill_id( re, val_start, val_len ); } } scan_start = p; if( !ProcFlags.tag_end_found ) { continue; } break; } /*******************************************************************/ /* no more valid attributes, process remaining input as header text*/ /*******************************************************************/ break; } if( *p == '.' ) { // tag end ? p++; } /************************************************************************/ /* set the global vars $headx, $headnumx, $htextx */ /* perhaps text translated to upper or lower case */ /************************************************************************/ while( *p == ' ' ) { // ignore leading blanks p++; } if( *p ) { // text exists if( layout_work.hx[hx_lvl].cases == case_lower ) { strlwr( p ); } else if( layout_work.hx[hx_lvl].cases == case_upper ) { strupr( p ); } } rc = add_symvar( &global_dict, htextx, p, no_subscript, 0 ); update_headnumx( hx_lvl, hnumstr, sizeof( hnumstr ) ); txtlen = strlen( p ); headlen = strlen( hnumstr) + txtlen + 2; headp = mem_alloc( headlen ); if( layout_work.hx[hx_lvl].number_form != num_none ) { strcpy( headp, hnumstr); // numbered header strcat( headp, " " ); } else { *headp = '\0'; } strcat( headp, p ); rc = add_symvar( &global_dict, headx, headp, no_subscript, 0 ); out_msg( " %s\n", headp ); // always verbose output ? TBD mem_free( headp ); /***********************************************************************/ /* if id specified add it to reference dict */ /***********************************************************************/ if( idseen ) { rwk = find_refid( ref_dict, re->id ); if( !rwk ) { // new entry if( txtlen > 0 ) { // text line not empty re->u.info.text_cap = mem_alloc( txtlen + 1 ); strcpy( re->u.info.text_cap, p ); } add_ref_entry( &ref_dict, re ); re = NULL; // free will be done via dictionary } else { /***************************************************************/ /* test for duplicate id */ /* it is done with comparing line no only, in the hope that */ /* two identical ids are not specified in different files on */ /* the same line no. */ /***************************************************************/ if( re->lineno != rwk->lineno ) { g_err( wng_id_xxx, re->id ); g_info( inf_id_duplicate ); file_mac_info(); err_count++; } if( re->u.info.text_cap != NULL ) { mem_free( re->u.info.text_cap ); } mem_free( re ); } } if( layout_work.hx[hx_lvl].number_reset ) { for( k = hx_lvl + 1; k < 7; k++ ) { layout_work.hx[k].headn = 0;// reset following levels if( layout_work.hx[k].headnsub != NULL ) { *(layout_work.hx[k].headnsub->value) = '\0'; } } } /***********************************************************************/ /* creation of actual heading */ /***********************************************************************/ /***********************************************************************/ /* eject page(s) if specified */ /***********************************************************************/ if( layout_work.hx[hx_lvl].page_eject != ej_no ) { if( ProcFlags.page_started ) { do_page_out(); reset_t_page(); } if( !ProcFlags.start_section ) { start_doc_sect(); } set_headx_banners( hx_lvl ); // set possible banners reset_t_page(); // and adjust page margins if( (layout_work.hx[hx_lvl].page_eject == ej_odd) && (page & 1) ) { do_page_out(); // next page would be even reset_t_page(); } else if( (layout_work.hx[hx_lvl].page_eject == ej_even) && !(page & 1) ) { do_page_out(); // next page would be odd reset_t_page(); } } if( layout_work.hx[hx_lvl].display_heading ) { hx_header( hx_lvl, hnumstr, p ); } scan_start = scan_stop; return; }
static void update_t_page( void ) { bool fig_placed; bool splittable; doc_element * cur_el; uint32_t depth; reset_t_page(); /* some section headings are placed in t_page.page_width when */ /* processed. One FIG in n_page.col_top goes into t_page.page_width */ /* if it is empty */ /* t_page.page_width can only hold one doc_element */ /* This is preliminary and may be changed as needed. */ depth = t_page.cur_depth; fig_placed = false; if( t_page.page_width == NULL ) { // skip if section full if( n_page.col_top != NULL ) { // at most one item can be placed switch( n_page.col_top->type ) { // add code for FIG when needed case el_text : // all elements should be FIGs default : internal_err( __FILE__, __LINE__ ); } } } /* one FIG in n_page.col_top goes into t_page.main->top_fig if none */ /* was placed in t_page.page_width */ /* this is preliminary and may be changed as needed */ /* Note: t_page.main is NULL at this point, initialize if needed */ if( !fig_placed ) { if( n_page.col_top != NULL ) { // at most one item can be placed switch( n_page.col_top->type ) { // add code for FIG when needed case el_text : // all elements should be FIGs default : internal_err( __FILE__, __LINE__ ); } } } /***********************************************************************/ /* The order here is not clear. */ /* That shown is based on filling the t_page.main->bot_fig and the */ /* t_page.main->footnote parts before filling t_page.main->main, thus */ /* having a firm depth for t_page.main->main to start with. */ /* However, if there is no top_fig, then the first doc_element in */ /* t_page.main->main must set its pre_skip to 0, and then what */ /* happens if there is no room for anything to be placed there? */ /* So this may need to be rethought when FN and FIG are implemented. */ /***********************************************************************/ /* one FIG in n_page.col_bot goes into t_page.main->bot_fig */ /* entrained footnotes need to be moved to n_page.col_fn */ /* this is preliminary and may be changed as needed */ /* Note: t_page.main may be NULL at this point, initialize if needed */ if( n_page.col_bot != NULL ) { // at most one item can be placed switch( n_page.col_bot->type ) { // add code for FIG & entrained footnotes when needed case el_text : // all elements should be FIGs or footnotes default : internal_err( __FILE__, __LINE__ ); } } /* all footnotes in n_page.col_fn go into t_page.main->footnote */ /* this is preliminary and may be changed as needed */ /* Note: t_page.main may be NULL at this point, initialize if needed */ if( n_page.col_fn != NULL ) { // at most one item can be placed switch( n_page.col_fn->type ) { // add code for footnotes when needed case el_text : // all elements should be footnotes default : internal_err( __FILE__, __LINE__ ); } } /* t_page.main->main is used for the bulk of the elements */ /* it is filled last because the other deferred items are believed to */ /* have priority; this may change as the situation is clarified. */ /* unless the section is ended, there must be at least on element left */ /* in n_page.col_main for the page to be full */ /* Note: when FIG/FN processing is implemented, t_page.main may not be */ /* NULL at this point */ /****************************************************************/ /* test version until things get a bit more clear */ /* the theory here is that only one processing step should be */ /* here, and then the function calling update_t_page() */ /* should be relied on to output the page */ /****************************************************************/ while( n_page.col_main != NULL ) { cur_el = n_page.col_main; n_page.col_main = n_page.col_main->next; if( n_page.col_main == NULL ) { n_page.last_col_main = NULL; } /****************************************************************/ /* this section identifies skips and blank lines that finish */ /* the current page and then exits the loop after adjusting */ /* the element field values as needed */ /****************************************************************/ if( cur_el->blank_lines > 0 ) { if( (t_page.cur_depth + cur_el->blank_lines) >= t_page.max_depth ) { cur_el->blank_lines -= (t_page.max_depth - t_page.cur_depth); break; } else if( !ProcFlags.page_started && ((t_page.cur_depth + cur_el->blank_lines + cur_el->top_skip) >= t_page.max_depth) ) { cur_el->top_skip -= (t_page.max_depth - t_page.cur_depth); cur_el->top_skip += cur_el->blank_lines; cur_el->blank_lines = 0; break; } else if( (t_page.cur_depth + cur_el->blank_lines + cur_el->subs_skip) >= t_page.max_depth ) { cur_el->blank_lines = 0; break; } } if( !ProcFlags.page_started ) { if( cur_el->blank_lines > 0 ) { depth += cur_el->blank_lines + cur_el->subs_skip; } else { depth += cur_el->top_skip; } ProcFlags.page_started = true; } else { depth += cur_el->blank_lines + cur_el->subs_skip; } if( depth >= t_page.max_depth ) { // skip fills page break; } /****************************************************************/ /* Does the first line minimum apply here? If so, it needs to */ /* be implemented. Note that cur_el->depth does not reflect it */ /* because there is no way to tell if it will apply when the */ /* cur_el->depth is computed. */ /****************************************************************/ if( (depth + cur_el->depth) > t_page.max_depth ) { // cur_el will fill the page splittable = split_element( cur_el, t_page.max_depth - t_page.cur_depth - depth ); if( splittable ) { if( cur_el->next != NULL ) { // cur_el was split n_page.col_main = cur_el->next; if( n_page.last_col_main == NULL ) { n_page.last_col_main = n_page.col_main; } cur_el->next = NULL; } if( t_page.main == NULL ) { t_page.main = alloc_doc_col(); } if( t_page.main->main == NULL ) { t_page.main->main = cur_el; t_page.last_col_main = t_page.main->main; } else { t_page.last_col_main->next = cur_el; t_page.last_col_main = t_page.last_col_main->next; } t_page.last_col_main->next = NULL; t_page.cur_depth += cur_el->depth; } else { if( (t_page.main == NULL) || (t_page.main->main == NULL) ) { // adapt when FIG/FN done xx_err( err_text_line_too_deep ); g_suicide(); // no line will fit on any page } n_page.col_main = cur_el->next; if( n_page.last_col_main == NULL ) { n_page.last_col_main = n_page.col_main; } cur_el->next = NULL; } } else { // cur_el fits as-is if( t_page.main == NULL ) { t_page.main = alloc_doc_col(); } if( t_page.main->main == NULL ) { t_page.main->main = cur_el; t_page.last_col_main = t_page.main->main; } else { t_page.last_col_main->next = cur_el; t_page.last_col_main = t_page.last_col_main->next; } t_page.last_col_main->next = NULL; t_page.cur_depth += cur_el->depth; } } return; }
void scr_pa( void ) { char * pa; char * p; int len; char cwcurr[4]; cwcurr[0] = SCR_char; cwcurr[1] = 'p'; cwcurr[2] = 'a'; cwcurr[3] = '\0'; p = scan_start; while( *p && *p != ' ' ) { // over cw p++; } while( *p && *p == ' ' ) { // next word start p++; } pa = p; while( *p && *p != ' ' ) { // end of word p++; } len = p - pa; switch( len ) { case 7 : if( strnicmp( "NOSTART", pa, 7 ) ) { xx_opt_err( cwcurr, pa ); break; } /* fallthru for NOSTART */ case 0 : last_page_out(); // default action reset_t_page(); break; case 3 : if( !strnicmp( "ODD", pa, 3 ) ) { last_page_out(); reset_t_page(); if( (page & 1) ) { // next page would be even do_page_out(); reset_t_page(); } } else { xx_opt_err( cwcurr, pa ); } break; case 4 : if( !strnicmp( "EVEN", pa, 4 ) ) { last_page_out(); reset_t_page(); if( !(page & 1) ) { // next page would be odd do_page_out(); reset_t_page(); } } else { xx_opt_err( cwcurr, pa ); } break; default: xx_opt_err( cwcurr, pa ); break; } scan_restart = scan_stop +1; return; }
void start_doc_sect( void ) { bool first_section; bool header; bool page_r; char * h_text; doc_section ds; hdsrc hds_lvl; int k; page_ej page_e; uint32_t page_c; uint32_t page_s; if( ProcFlags.start_section ) { return; // once is enough } if( !ProcFlags.fb_document_done ) { // the very first section/page do_layout_end_processing(); } scr_process_break(); // commit any prior text first_section = (ProcFlags.doc_sect == doc_sect_none); ProcFlags.start_section = true; ProcFlags.keep_left_margin = false; page_c = layout_work.defaults.columns; ds = ProcFlags.doc_sect_nxt; // new section if( ds == doc_sect_none ) { ds = doc_sect_body; // if text without section start assume body } /***********************************************************************/ /* process special section attributes */ /***********************************************************************/ switch( ds ) { case doc_sect_titlep : page_c = layout_work.titlep.columns; page_e = ej_yes; page_r = false; // no page number reset header = false; // no header string (ABSTRACT, ... ) output init_nest_cb(); nest_cb->p_stack = copy_to_nest_stack(); nest_cb->c_tag = t_TITLEP; nest_cb->p_stack->lineno = titlep_lineno; // correct line number break; case doc_sect_abstract : page_c = layout_work.abstract.columns; page_e = layout_work.abstract.page_eject; page_r = layout_work.abstract.page_reset; page_s = layout_work.hx.hx_sect[hds_abstract].spacing; header = layout_work.hx.hx_sect[hds_abstract].header; if( header ) { h_text = &layout_work.abstract.string; hds_lvl = hds_abstract; } break; case doc_sect_preface : page_c = layout_work.preface.columns; page_e = layout_work.preface.page_eject; page_r = layout_work.preface.page_reset; page_s = layout_work.hx.hx_sect[hds_preface].spacing; header = layout_work.hx.hx_sect[hds_preface].header; if( header ) { h_text = &layout_work.preface.string; hds_lvl = hds_preface; } break; case doc_sect_body : page_c = layout_work.body.columns; page_e = layout_work.body.page_eject; page_r = layout_work.body.page_reset; page_s = layout_work.hx.hx_sect[hds_body].spacing; header = layout_work.hx.hx_sect[hds_body].header; if( header ) { h_text = &layout_work.body.string; hds_lvl = hds_body; } break; case doc_sect_appendix : page_c = layout_work.appendix.columns; page_e = layout_work.appendix.section_eject; page_r = layout_work.appendix.page_reset; page_s = layout_work.hx.hx_sect[hds_appendix].spacing; header = false; // no section header string output, as such if( page_e != ej_no ) { page_e = ej_yes; // "even" and "odd" act like "yes" } for( k = 1; k < hds_appendix; k++ ) { // reset heading levels hd_nums[k].headn = 0; if( hd_nums[k].headnsub != NULL ) { *(hd_nums[k].headnsub->value) = '\0'; } } break; case doc_sect_backm : page_c = layout_work.backm.columns; page_e = layout_work.backm.page_eject; page_r = layout_work.backm.page_reset; page_s = layout_work.hx.hx_sect[hds_backm].spacing; header = layout_work.hx.hx_sect[hds_backm].header; if( header ) { h_text = &layout_work.backm.string; hds_lvl = hds_backm; } break; case doc_sect_index : page_c = layout_work.index.columns; page_e = layout_work.index.page_eject; page_r = layout_work.index.page_reset; page_s = layout_work.hx.hx_sect[hds_index].spacing; header = layout_work.hx.hx_sect[hds_index].header; if( header ) { h_text = &layout_work.index.index_string; hds_lvl = hds_index; } break; case doc_sect_gdoc : case doc_sect_etitlep : case doc_sect_frontm : page_c = layout_work.defaults.columns; page_e = ej_no; // no page eject page_r = false; // no page number reset page_s = layout_work.defaults.spacing; // default spacing header = false; // no section header break; case doc_sect_egdoc : page_c = layout_work.defaults.columns; page_e = ej_yes; page_r = false; // no page number reset page_s = layout_work.defaults.spacing; // default spacing header = false; // no section header break; default: internal_err( __FILE__, __LINE__ ); break; } if( first_section ) { // nothing precedes the first section if( page_e == ej_even ) { do_page_out(); // apage of first page is odd page = 0; // restart page for first text page ProcFlags.page_ejected = true; } set_section_banners( ds ); reset_t_page(); document_new_position(); // first text page ready for content } else if( page_e == ej_no ) { full_page_out(); // ensure are on last page ProcFlags.page_ejected = false; set_section_banners( ds ); reset_bot_ban(); } else { last_page_out(); // ensure last page output ProcFlags.page_ejected = true; // only first section has nothing to output if( page_e == ej_odd ) { if( (page & 1) ) { // first page will be odd do_page_out(); // emit blank page } } else if( page_e == ej_even ) { if( !(page & 1) ) { // first page will be even do_page_out(); // emit blank page } } else if( page_e != ej_yes ) { internal_err( __FILE__, __LINE__ ); } g_skip = 0; // ignore remaining skip value set_section_banners( ds ); reset_t_page(); } ProcFlags.doc_sect = ds; t_page.col_count = page_c; set_cols(); if( page_r ) { page = 0; } spacing = page_s; g_cur_left = g_page_left_org; if( header ) { line_position = pos_center; concat_save = ProcFlags.concat; ProcFlags.concat = true; justify_save = ProcFlags.justify; ProcFlags.justify = ju_off; gen_heading( h_text, NULL, 0, hds_lvl ); g_indent = 0; // reset for section body ProcFlags.concat = concat_save; ProcFlags.justify = justify_save; } g_curr_font = layout_work.defaults.font; g_cur_h_start = g_page_left_org + g_indent; ProcFlags.doc_sect = ds; }
static void gen_toc( void ) { bool levels[7]; // track levels char buffer[11]; char postfix[12]; ffh_entry * curr; int i; int j; uint32_t cur_level; uint32_t indent[7]; uint32_t size; if( hd_list == NULL ) return; // no hd_list, no TOC /* Insert TOC into current section */ last_page_out(); // ensure are on new page g_skip = 0; // ignore remaining skip value set_section_banners( doc_sect_toc ); reset_t_page(); /* Set TOC margins and other values */ g_page_left = g_page_left_org + 2 * conv_hor_unit( &layout_work.toc.left_adjust, g_curr_font ); // matches wgml 4.0 g_page_right = g_page_right_org - conv_hor_unit( &layout_work.toc.right_adjust, g_curr_font ); size = conv_hor_unit( &layout_work.tocpgnum.size, g_curr_font ); // space from fill to right edge figlist_toc_tabs( layout_work.toc.fill_string, size ); /* Initialize levels and indent values */ for( i = 0; i < 7; i++ ) { levels[i] = false; indent[i] = 0; } /* Get converted indent values, which are cumulative */ for( i = 0; i < 7; i++ ) { for( j = i; j < 7; j++ ) { indent[j] += conv_hor_unit( &layout_work.tochx[i].indent, g_curr_font ); } } /* Output TOC */ concat_save = ProcFlags.concat; ProcFlags.concat = true; justify_save = ProcFlags.justify; ProcFlags.justify = ju_off; ProcFlags.keep_left_margin = true; // keep all indents while outputting text curr = hd_list; while( curr != NULL ) { cur_level = curr->number; for( i = 0; i < 7; i++ ) { if( i > cur_level ) { // all lower levels are inactive levels[i] = false; } } if( cur_level < layout_work.toc.toc_levels ) { g_curr_font = layout_work.tochx[cur_level].font; if( levels[cur_level] ) { spacing = layout_work.toc.spacing; set_skip_vars( &layout_work.tochx[cur_level].skip, NULL, NULL, spacing, g_curr_font ); } else { spacing = 1; set_skip_vars( &layout_work.tochx[cur_level].pre_skip, NULL, &layout_work.tochx[cur_level].post_skip, spacing, g_curr_font ); } g_cur_left = g_page_left + indent[cur_level]; g_cur_h_start = g_cur_left; if( curr->prefix != NULL ) { process_text( curr->prefix, g_curr_font ); g_cur_left = t_line->last->x_address + t_line->last->width + wgml_fonts[g_curr_font].spc_width; g_cur_h_start = g_cur_left; ProcFlags.ct = true; // emulate CT post_space = 0; } else { t_line = alloc_text_line(); // capture spacing if no prefix } if( !levels[cur_level] ) { spacing = layout_work.toc.spacing; set_skip_vars( NULL, NULL, NULL, spacing, g_curr_font ); } if( curr->text != NULL ) { g_page_right -= size; if( ProcFlags.has_aa_block ) { // matches wgml 4.0 g_page_right -= tab_col; } else { g_page_right -= 3 * tab_col; } ProcFlags.stop_xspc = true; // suppress 2nd space after stop process_text( curr->text, g_curr_font ); if( ProcFlags.has_aa_block ) { // matches wgml 4.0 g_page_right += tab_col; } else { g_page_right += 3 * tab_col; } g_page_right += size; } ProcFlags.ct = true; // emulate CT g_curr_font = FONT0; process_text( "$", g_curr_font ); format_num( curr->pageno, &buffer, sizeof( buffer ), curr->style ); strcpy_s( postfix, 12, "$" ); // insert tab characters strcat_s( postfix, 12, buffer ); // append page number g_curr_font = layout_work.tocpgnum.font; process_text( postfix, g_curr_font ); } scr_process_break(); // ensure line break levels[cur_level] = true; // first entry of level done curr = curr->next; } ProcFlags.concat = concat_save; ProcFlags.justify = justify_save; /* Re-establish current section */ last_page_out(); // ensure all pages output set_section_banners( ProcFlags.doc_sect ); reset_t_page(); return; }
static void gen_figlist( void ) { char buffer[11]; char postfix[12]; ffh_entry * curr; uint32_t size; if( fig_list == NULL ) return; // no fig_list, no FIGLIST /* Insert FIGLIST into current section */ last_page_out(); // ensure are on new page g_skip = 0; // ignore remaining skip value set_section_banners( doc_sect_figlist ); reset_t_page(); /* Set FIGLIST margins and other values */ g_page_left = g_page_left_org + 2 * conv_hor_unit( &layout_work.figlist.left_adjust, g_curr_font ); // matches wgml 4.0 g_page_right = g_page_right_org - conv_hor_unit( &layout_work.figlist.right_adjust, g_curr_font ); size = conv_hor_unit( &layout_work.flpgnum.size, g_curr_font ); // space from fill to right edge figlist_toc_tabs( layout_work.figlist.fill_string, size ); /* Output FIGLIST */ concat_save = ProcFlags.concat; ProcFlags.concat = true; justify_save = ProcFlags.justify; ProcFlags.justify = ju_off; ProcFlags.keep_left_margin = true; // keep all indents while outputting text curr = fig_list; while( curr != NULL ) { if( curr->flags & ffh_figcap ) { // no FIGCAP used, no FIGLIST output g_curr_font = FONT0; // wgml 4.0 uses font 0 if( ProcFlags.page_started ) { // not on first entry spacing = layout_work.figlist.spacing; set_skip_vars( NULL, NULL, NULL, spacing, g_curr_font ); } g_cur_left = g_page_left; g_cur_h_start = g_cur_left; process_text( curr->prefix, g_curr_font ); // caption prefix if( curr->text != NULL ) { g_cur_left = t_line->last->x_address + t_line->last->width + wgml_fonts[g_curr_font].spc_width; g_cur_h_start = g_cur_left; ProcFlags.ct = true; // emulate CT ProcFlags.stop_xspc = true; // suppress 2nd space after stops post_space = 0; g_page_right -= size; if( ProcFlags.has_aa_block ) { // matches wgml 4.0 g_page_right -= tab_col; } else { g_page_right -= 3 * tab_col; } if( !ProcFlags.page_started ) { // first entry wrapping spacing = layout_work.figlist.spacing; } set_skip_vars( &layout_work.figlist.skip, NULL, NULL, spacing, g_curr_font ); process_text( curr->text, g_curr_font );// caption text if( ProcFlags.has_aa_block ) { // matches wgml 4.0 g_page_right += tab_col; } else { g_page_right += 3 * tab_col; } g_page_right += size; } ProcFlags.ct = true; // emulate CT g_curr_font = FONT0; process_text( "$", g_curr_font ); format_num( curr->pageno, &buffer, sizeof( buffer ), curr->style ); strcpy_s( postfix, 12, "$" ); // insert tab characters strcat_s( postfix, 12, buffer ); // append page number g_curr_font = layout_work.flpgnum.font; process_text( postfix, g_curr_font ); } scr_process_break(); // ensure line break curr = curr->next; } ProcFlags.concat = concat_save; ProcFlags.justify = justify_save; /* Re-establish current section */ last_page_out(); // ensure all pages output set_section_banners( ProcFlags.doc_sect ); reset_t_page(); return; }