diff options
Diffstat (limited to 'source/luametatex/source/tex')
-rw-r--r-- | source/luametatex/source/tex/texcommands.c | 1 | ||||
-rw-r--r-- | source/luametatex/source/tex/texcommands.h | 1 | ||||
-rw-r--r-- | source/luametatex/source/tex/texexpand.c | 14 | ||||
-rw-r--r-- | source/luametatex/source/tex/texfont.c | 4 | ||||
-rw-r--r-- | source/luametatex/source/tex/texnodes.c | 118 | ||||
-rw-r--r-- | source/luametatex/source/tex/texnodes.h | 6 | ||||
-rw-r--r-- | source/luametatex/source/tex/texprinting.c | 15 | ||||
-rw-r--r-- | source/luametatex/source/tex/texscanning.c | 21 | ||||
-rw-r--r-- | source/luametatex/source/tex/texscanning.h | 2 | ||||
-rw-r--r-- | source/luametatex/source/tex/textoken.c | 32 | ||||
-rw-r--r-- | source/luametatex/source/tex/textoken.h | 1 |
11 files changed, 161 insertions, 54 deletions
diff --git a/source/luametatex/source/tex/texcommands.c b/source/luametatex/source/tex/texcommands.c index 0e9bb7ac9..9425141db 100644 --- a/source/luametatex/source/tex/texcommands.c +++ b/source/luametatex/source/tex/texcommands.c @@ -657,6 +657,7 @@ void tex_initialize_commands(void) tex_primitive(luatex_command, "directlua", convert_cmd, lua_code, 0); tex_primitive(luatex_command, "csstring", convert_cmd, cs_string_code, 0); tex_primitive(luatex_command, "csactive", convert_cmd, cs_active_code, 0); + /* tex_primitive(luatex_command, "csnamestring", convert_cmd, cs_lastname_code, 0); */ tex_primitive(luatex_command, "detokenized", convert_cmd, detokenized_code, 0); tex_primitive(luatex_command, "expanded", convert_cmd, expanded_code, 0); tex_primitive(luatex_command, "semiexpanded", convert_cmd, semi_expanded_code, 0); diff --git a/source/luametatex/source/tex/texcommands.h b/source/luametatex/source/tex/texcommands.h index a5c157a44..55de1dce6 100644 --- a/source/luametatex/source/tex/texcommands.h +++ b/source/luametatex/source/tex/texcommands.h @@ -443,6 +443,7 @@ typedef enum convert_codes { string_code, /*tex command code for |\string| */ cs_string_code, /*tex command code for |\csstring| */ cs_active_code, /*tex command code for |\csactive| */ + /* cs_lastname_code, */ /*tex command code for |\cslastname| */ detokenized_code, /*tex command code for |\detokenized| */ roman_numeral_code, /*tex command code for |\romannumeral| */ meaning_code, /*tex command code for |\meaning| */ diff --git a/source/luametatex/source/tex/texexpand.c b/source/luametatex/source/tex/texexpand.c index cec254d2b..8a2fa79a0 100644 --- a/source/luametatex/source/tex/texexpand.c +++ b/source/luametatex/source/tex/texexpand.c @@ -677,6 +677,20 @@ int tex_is_valid_csname(void) tex_get_x_or_protected(); /* we skip unprotected ! */ } while (cur_cmd != end_cs_name_cmd); goto FINISH; + /* no real gain: */ + // while (1) { + // tex_get_token(); + // if (cur_cmd == end_cs_name_cmd) { + // goto FINISH; + // } else if (cur_cmd <= max_command_cmd || is_protected_cmd(cur_cmd)) { + // /* go on */ + // } else { + // tex_expand_current_token(); + // if (cur_cmd != end_cs_name_cmd) { + // goto FINISH; + // } + // } + // } } else if (n) { /*tex Look up the characters of list |n| in the hash table, and set |cur_cs|. */ int f = lmt_fileio_state.io_first; diff --git a/source/luametatex/source/tex/texfont.c b/source/luametatex/source/tex/texfont.c index ac0ea1290..0f1cf6117 100644 --- a/source/luametatex/source/tex/texfont.c +++ b/source/luametatex/source/tex/texfont.c @@ -1958,7 +1958,9 @@ scaled tex_char_depth_from_glyph(halfword g) scaled tex_char_total_from_glyph(halfword g) { charinfo *ci = tex_aux_char_info(glyph_font(g), glyph_character(g)); - return tex_aux_glyph_y_scaled(g, ci->height + ci->depth); + scaled ht = ci->height; + scaled dp = ci->depth; + return tex_aux_glyph_y_scaled(g, (ht > 0 ? ht : 0) + (dp > 0 ? dp : 0)); /* so not progression */ } scaled tex_char_italic_from_glyph(halfword g) diff --git a/source/luametatex/source/tex/texnodes.c b/source/luametatex/source/tex/texnodes.c index ab2601a43..1c4a6b896 100644 --- a/source/luametatex/source/tex/texnodes.c +++ b/source/luametatex/source/tex/texnodes.c @@ -2669,9 +2669,9 @@ void tex_show_node_list(halfword p, int threshold, int max) if (valid_direction(box_dir(p))) { tex_print_str(", direction "); switch (box_dir(p)) { - case 0 : tex_print_str("l2r"); break; - case 1 : tex_print_str("r2l"); break; - default : tex_print_str("unset"); break; + case dir_lefttoright: tex_print_str("l2r"); break; + case dir_righttoleft: tex_print_str("r2l"); break; + default : tex_print_str("unset"); break; } } if (box_geometry(p)) { @@ -3372,14 +3372,38 @@ scaled tex_glyph_depth(halfword p) /* not used */ return d < 0 ? 0 : d; } +// scaledwhd tex_glyph_dimensions(halfword p) +// { +// scaledwhd whd = { 0, 0, 0, 0 }; +// scaled x = glyph_x_offset(p); +// scaled y = glyph_y_offset(p); +// whd.ht = tex_char_height_from_glyph(p) + glyph_raise(p); +// whd.dp = tex_char_depth_from_glyph(p) - glyph_raise(p); +// whd.wd = tex_char_width_from_glyph(p) - (glyph_left(p) + glyph_right(p)); +// if (x && tex_has_glyph_option(p, glyph_option_apply_x_offset)) { +// whd.wd += x; +// } +// if (y && tex_has_glyph_option(p, glyph_option_apply_y_offset)) { +// whd.ht += y; +// whd.dp -= y; +// } +// if (whd.ht < 0) { +// whd.ht = 0; +// } +// if (whd.dp < 0) { +// whd.dp = 0; +// } +// return whd; +// } + scaledwhd tex_glyph_dimensions(halfword p) { - scaledwhd whd = { 0, 0, 0, 0 }; + scaledwhd whd = tex_char_whd_from_glyph(p); scaled x = glyph_x_offset(p); scaled y = glyph_y_offset(p); - whd.ht = tex_char_height_from_glyph(p) + glyph_raise(p); - whd.dp = tex_char_depth_from_glyph(p) - glyph_raise(p); - whd.wd = tex_char_width_from_glyph(p) - (glyph_left(p) + glyph_right(p)); + whd.ht += glyph_raise(p); + whd.dp -= glyph_raise(p); + whd.wd += (glyph_left(p) + glyph_right(p)); if (x && tex_has_glyph_option(p, glyph_option_apply_x_offset)) { whd.wd += x; } @@ -3396,14 +3420,41 @@ scaledwhd tex_glyph_dimensions(halfword p) return whd; } +// scaledwhd tex_glyph_dimensions_ex(halfword p) +// { +// scaledwhd whd = { 0, 0, 0, 0 }; +// scaled x = glyph_x_offset(p); +// scaled y = glyph_y_offset(p); +// whd.ht = tex_char_height_from_glyph(p) + glyph_raise(p); +// whd.dp = tex_char_depth_from_glyph(p) - glyph_raise(p); +// whd.wd = tex_char_width_from_glyph(p) - (glyph_left(p) + glyph_right(p)); +// if (x && tex_has_glyph_option(p, glyph_option_apply_x_offset)) { +// whd.wd += x; +// } +// if (y && tex_has_glyph_option(p, glyph_option_apply_y_offset)) { +// whd.ht += y; +// whd.dp -= y; +// } +// if (whd.ht < 0) { +// whd.ht = 0; +// } +// if (whd.dp < 0) { +// whd.dp = 0; +// } +// if (whd.wd && glyph_expansion(p)) { +// whd.wd = tex_ext_xn_over_d(whd.wd, 1000000 + glyph_expansion(p), 1000000); +// } +// return whd; +// } + scaledwhd tex_glyph_dimensions_ex(halfword p) { - scaledwhd whd = { 0, 0, 0, 0 }; + scaledwhd whd = tex_char_whd_from_glyph(p); scaled x = glyph_x_offset(p); scaled y = glyph_y_offset(p); - whd.ht = tex_char_height_from_glyph(p) + glyph_raise(p); - whd.dp = tex_char_depth_from_glyph(p) - glyph_raise(p); - whd.wd = tex_char_width_from_glyph(p) - (glyph_left(p) + glyph_right(p)); + whd.ht += glyph_raise(p); + whd.dp -= glyph_raise(p); + whd.wd -= (glyph_left(p) + glyph_right(p)); if (x && tex_has_glyph_option(p, glyph_option_apply_x_offset)) { whd.wd += x; } @@ -3423,23 +3474,43 @@ scaledwhd tex_glyph_dimensions_ex(halfword p) return whd; } + scaled tex_glyph_total(halfword p) { - scaled ht = tex_char_height_from_glyph(p); - scaled dp = tex_char_depth_from_glyph(p); - if (ht < 0) { - ht = 0; - } - if (dp < 0) { - dp = 0; - } - return ht + dp; + // scaled ht = tex_char_height_from_glyph(p); + // scaled dp = tex_char_depth_from_glyph(p); + // if (ht < 0) { + // ht = 0; + // } + // if (dp < 0) { + // dp = 0; + // } + // return ht + dp; + return tex_char_total_from_glyph(p); } +// int tex_glyph_has_dimensions(halfword p) +// { +// scaled offset = glyph_x_offset(p); +// scaled amount = tex_char_width_from_glyph(p); +// if (offset && tex_has_glyph_option(p, glyph_option_apply_x_offset)) { +// amount += offset; +// } +// amount -= (glyph_left(p) + glyph_right(p)); +// if (amount) { +// return 1; +// } else { +// amount = tex_char_total_from_glyph(p); +// /* here offset and raise just moves */ +// return amount != 0; +// } +// } + int tex_glyph_has_dimensions(halfword p) { + scaledwhd whd = tex_char_whd_from_glyph(p); scaled offset = glyph_x_offset(p); - scaled amount = tex_char_width_from_glyph(p); + scaled amount = whd.wd; if (offset && tex_has_glyph_option(p, glyph_option_apply_x_offset)) { amount += offset; } @@ -3447,9 +3518,8 @@ int tex_glyph_has_dimensions(halfword p) if (amount) { return 1; } else { - amount = tex_char_total_from_glyph(p); - /* here offset adn raise just moves */ - return amount != 0; + /* here offset and raise just moves */ + return whd.ht > 0 || whd.dp > 0; } } diff --git a/source/luametatex/source/tex/texnodes.h b/source/luametatex/source/tex/texnodes.h index 50dbeaa97..8a462ebac 100644 --- a/source/luametatex/source/tex/texnodes.h +++ b/source/luametatex/source/tex/texnodes.h @@ -867,11 +867,11 @@ typedef enum list_geometries { # define box_glue_order(a) vlink(a,6) # define box_glue_sign(a) vinfo(a,6) # define box_glue_set(a) dvalue(a,7) /* So we reserve a whole memory word! */ -# define box_dir(a) vlink00(a,8) +# define box_dir(a) vlink00(a,8) /* We could encode it as geomtry but not now. */ # define box_package_state(a) vlink01(a,8) # define box_axis(a) vlink02(a,8) # define box_geometry(a) vlink03(a,8) -# define box_orientation(a) vinfo(a,8) /* also used for size in alignments */ +# define box_orientation(a) vinfo(a,8) /* Also used for size in alignments. */ # define box_x_offset(a) vlink(a,9) # define box_y_offset(a) vinfo(a,9) # define box_pre_migrated(a) vlink(a,10) @@ -885,7 +885,7 @@ typedef enum list_geometries { # define box_input_file(a) vlink(a,14) /* aka box_synctex_tag */ # define box_input_line(a) vinfo(a,14) /* aka box_synctex_line */ -# define box_total(a) (box_height(a) + box_depth(a)) +# define box_total(a) (box_height(a) + box_depth(a)) /* Here we add, with glyphs we maximize. */ inline static void tex_set_box_geometry (halfword b, halfword g) { box_geometry(b) |= (singleword) (g); } /* static void tex_unset_box_geometry (halfword b, halfword g) { box_geometry(b) &= (singleword) ~((singleword) (g) | box_geometry(b)); } */ diff --git a/source/luametatex/source/tex/texprinting.c b/source/luametatex/source/tex/texprinting.c index 860ff6731..d18445f36 100644 --- a/source/luametatex/source/tex/texprinting.c +++ b/source/luametatex/source/tex/texprinting.c @@ -465,15 +465,22 @@ void tex_print_str_esc(const char *s) void tex_print_int(int n) { /*tex In the end a 0..9 fast path works out best; using |sprintf| is slower. */ + if (n < 0) { + tex_print_char('-'); + n = -n; + } if (n >= 0 && n <= 9) { tex_print_char('0' + n); + } else if (n >= 0 && n <= 99) { + tex_print_char('0' + n/10); + tex_print_char('0' + n%10); } else { int k = 0; unsigned char digits[24]; - if (n < 0) { - tex_print_char('-'); - n = -n; - } +// if (n < 0) { +// tex_print_char('-'); +// n = -n; +// } do { digits[k] = '0' + (unsigned char) (n % 10); n = n / 10; diff --git a/source/luametatex/source/tex/texscanning.c b/source/luametatex/source/tex/texscanning.c index 3c9859de9..15e887a71 100644 --- a/source/luametatex/source/tex/texscanning.c +++ b/source/luametatex/source/tex/texscanning.c @@ -3380,25 +3380,6 @@ halfword tex_scan_general_text(halfword *tail) /*tex - The |get_x_or_protected| procedure is like |get_x_token| except that protected macros are not - expanded. It sets |cur_cmd|, |cur_chr|, |cur_tok|, and expands non-protected macros. - -*/ - -void tex_get_x_or_protected(void) -{ - while (1) { - tex_get_token(); - if (cur_cmd <= max_command_cmd || is_protected_cmd(cur_cmd)) { - return; - } else { - tex_expand_current_token(); - } - } -} - -/*tex - |scan_toks|. This function returns a pointer to the tail of a new token list, and it also makes |def_ref| point to the reference count at the head of that list. @@ -3759,7 +3740,7 @@ halfword tex_scan_macro_normal(void) return result; } -# define optimize_grouping 0 +# define optimize_grouping 1 halfword tex_scan_macro_expand(void) { diff --git a/source/luametatex/source/tex/texscanning.h b/source/luametatex/source/tex/texscanning.h index 303143587..3415c27dd 100644 --- a/source/luametatex/source/tex/texscanning.h +++ b/source/luametatex/source/tex/texscanning.h @@ -136,8 +136,6 @@ extern halfword tex_get_font_dimen (void); extern void tex_set_scaled_font_dimen (void); extern halfword tex_get_scaled_font_dimen (void); -extern void tex_get_x_or_protected (void); - extern int tex_fract (int x, int n, int d, int max_answer); extern halfword tex_scan_lua_value (int index); diff --git a/source/luametatex/source/tex/textoken.c b/source/luametatex/source/tex/textoken.c index ba457491a..b46e6de85 100644 --- a/source/luametatex/source/tex/textoken.c +++ b/source/luametatex/source/tex/textoken.c @@ -2078,6 +2078,28 @@ halfword tex_get_token(void) return cur_tok; } +/*tex + + The |get_x_or_protected| procedure is like |get_x_token| except that protected macros are not + expanded. It sets |cur_cmd|, |cur_chr|, |cur_tok|, and expands non-protected macros. + +*/ + +void tex_get_x_or_protected(void) +{ + lmt_hash_state.no_new_cs = 0; + while (1) { + tex_get_next(); + if (cur_cmd <= max_command_cmd || is_protected_cmd(cur_cmd)) { + break; + } else { + tex_expand_current_token(); + } + } + cur_tok = cur_cs ? cs_token_flag + cur_cs : token_val(cur_cmd, cur_chr); /* needed afterwards ? */ + lmt_hash_state.no_new_cs = 1; +} + /*tex This changes the string |s| to a token list. */ halfword tex_string_to_toks(const char *ss) @@ -2765,6 +2787,16 @@ void tex_run_convert_tokens(halfword code) pop_selector; break; } + /* + case cs_lastname_code: + if (lmt_scanner_state.last_cs_name != null_cs) { + int saved_selector; + push_selector; + tex_print_cs_name(lmt_scanner_state.last_cs_name); + pop_selector; + } + break; + */ case detokenized_code: { int saved_selector; diff --git a/source/luametatex/source/tex/textoken.h b/source/luametatex/source/tex/textoken.h index 843304405..da2d01f7c 100644 --- a/source/luametatex/source/tex/textoken.h +++ b/source/luametatex/source/tex/textoken.h @@ -359,6 +359,7 @@ extern halfword tex_active_to_cs (int c, int force); extern halfword tex_string_to_toks (const char *s); extern int tex_get_char_cat_code (int c); extern halfword tex_get_token (void); +extern void tex_get_x_or_protected (void); extern halfword tex_str_toks (lstring s, halfword *tail); /* returns head */ extern halfword tex_cur_str_toks (halfword *tail); /* returns head */ extern halfword tex_str_scan_toks (int c, lstring b); /* returns head */ |