diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/luametatex/source/lua/lmtinterface.h | 36 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmtmplib.c | 9 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmtnodelib.c | 62 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmttexiolib.c | 3 | ||||
-rw-r--r-- | source/luametatex/source/lua/lmttexlib.c | 4 | ||||
-rw-r--r-- | source/luametatex/source/luametatex.h | 6 | ||||
-rw-r--r-- | source/luametatex/source/luarest/lmtpdfelib.c | 50 | ||||
-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 |
18 files changed, 292 insertions, 93 deletions
diff --git a/source/luametatex/source/lua/lmtinterface.h b/source/luametatex/source/lua/lmtinterface.h index 707d3aefb..756a25331 100644 --- a/source/luametatex/source/lua/lmtinterface.h +++ b/source/luametatex/source/lua/lmtinterface.h @@ -234,8 +234,8 @@ extern int luaextend_xcomplex (lua_State *L); /*tex Used in |lmttokenlib|. */ -# define TOKEN_METATABLE_INSTANCE "token.instance" -# define TOKEN_METATABLE_PACKAGE "token.package" +# define TOKEN_METATABLE_INSTANCE "token.instance" +# define TOKEN_METATABLE_PACKAGE "token.package" /*tex Used in |lmtepdflib|. */ @@ -255,6 +255,28 @@ extern int luaextend_xcomplex (lua_State *L); # define SPARSE_METATABLE_INSTANCE "sparse.instance" +/*tex + There are some more but for now we have no reason to alias them for performance reasons, so + that got postponed. We then also need to move the defines here: +*/ + +/* +# define DIR_METATABLE "file.directory" + +# define LUA_BYTECODES_INDIRECT + +# define TEX_METATABLE_TEX "tex.tex" +# define TEX_NEST_INSTANCE "tex.nest.instance" +# define TEX_* "tex.*" + +# define LUA_FUNCTIONS "lua.functions" +# define LUA_BYTECODES "lua.bytecodes" +# define LUA_BYTECODES_INDIRECT "lua.bytecodes.indirect" + +# define LANGUAGE_METATABLE "luatex.language" +# define LANGUAGE_FUNCTIONS "luatex.language.wordhandlers" +*/ + /*tex Currently we sometimes use numbers and sometimes strings in node properties. We can make that @@ -1458,10 +1480,12 @@ make_lua_key_alias(L, token_package, TOKEN_METATABLE_PACKAGE);\ make_lua_key_alias(L, sparse_instance, SPARSE_METATABLE_INSTANCE);\ /* */ \ make_lua_key_alias(L, pdfe_instance, PDFE_METATABLE_INSTANCE);\ -make_lua_key_alias(L, pdfe_dictionary, PDFE_METATABLE_DICTIONARY);\ -make_lua_key_alias(L, pdfe_array, PDFE_METATABLE_ARRAY);\ -make_lua_key_alias(L, pdfe_stream, PDFE_METATABLE_STREAM);\ -make_lua_key_alias(L, pdfe_reference, PDFE_METATABLE_REFERENCE);\ +make_lua_key_alias(L, pdfe_dictionary_instance, PDFE_METATABLE_DICTIONARY);\ +make_lua_key_alias(L, pdfe_array_instance, PDFE_METATABLE_ARRAY);\ +make_lua_key_alias(L, pdfe_stream_instance, PDFE_METATABLE_STREAM);\ +make_lua_key_alias(L, pdfe_reference_instance, PDFE_METATABLE_REFERENCE);\ +/* */ \ +make_lua_key_alias(L, file_handle_instance, LUA_FILEHANDLE);\ /* done */ # define declare_metapost_lua_keys(L) \ diff --git a/source/luametatex/source/lua/lmtmplib.c b/source/luametatex/source/lua/lmtmplib.c index ecbfd46b6..83fe3efd4 100644 --- a/source/luametatex/source/lua/lmtmplib.c +++ b/source/luametatex/source/lua/lmtmplib.c @@ -1703,7 +1703,8 @@ static int mplib_new(lua_State *L) *mpud = mp; mplib_aux_set_bend_tolerance(L, bendtolerance); mplib_aux_set_move_tolerance(L, movetolerance); - luaL_getmetatable(L, MP_METATABLE_INSTANCE); + // luaL_getmetatable(L, MP_METATABLE_INSTANCE); + lua_get_metatablelua(mplib_instance); lua_setmetatable(L, -2); return 1; } @@ -1763,7 +1764,8 @@ static int mplib_aux_wrapresults(lua_State *L, mp_run_data *res, int status, lua *v = p; mplib_aux_set_bend_tolerance(L, bendtolerance); mplib_aux_set_move_tolerance(L, movetolerance); - luaL_getmetatable(L, MP_METATABLE_FIGURE); + // luaL_getmetatable(L, MP_METATABLE_FIGURE); + lua_get_metatablelua(mplib_figure); lua_setmetatable(L, -2); lua_rawseti(L, -2, i); i++; @@ -2341,7 +2343,8 @@ static int mplib_figure_objects(lua_State *L) *v = p; mplib_aux_set_bend_tolerance(L, bendtolerance); mplib_aux_set_move_tolerance(L, movetolerance); - luaL_getmetatable(L, MP_METATABLE_OBJECT); + // luaL_getmetatable(L, MP_METATABLE_OBJECT); + lua_get_metatablelua(mplib_object); lua_setmetatable(L, -2); lua_rawseti(L, -2, i); i++; diff --git a/source/luametatex/source/lua/lmtnodelib.c b/source/luametatex/source/lua/lmtnodelib.c index 2a02fbd11..58a98f7e3 100644 --- a/source/luametatex/source/lua/lmtnodelib.c +++ b/source/luametatex/source/lua/lmtnodelib.c @@ -2489,10 +2489,18 @@ static int nodelib_direct_getgeometry(lua_State* L) lua_pushboolean(L, tex_has_box_geometry(n, offset_geometry)); lua_pushboolean(L, tex_has_box_geometry(n, orientation_geometry)); lua_pushboolean(L, tex_has_box_geometry(n, anchor_geometry)); - return 4; + lua_pushinteger(L, checked_direction_value(box_dir(n))); + return 5; } else { return 1; } + } else if (lua_toboolean(L, 2)) { + lua_pushboolean(L, 0); + lua_pushboolean(L, 0); + lua_pushboolean(L, 0); + lua_pushboolean(L, 0); + lua_pushinteger(L, checked_direction_value(box_dir(n))); + return 5; } break; } @@ -2870,6 +2878,25 @@ static int nodelib_direct_getkerndimension(lua_State *L) } } +static int nodelib_direct_getlistdimensions(lua_State *L) +{ + halfword n = nodelib_valid_direct_from_index(L, 1); + if (n) { + switch (node_type(n)) { + /* when we need it more node types will be handled */ + case hlist_node: + case vlist_node: + lua_pushinteger(L, box_width(n)); + lua_pushinteger(L, box_height(n)); + lua_pushinteger(L, box_depth(n)); + lua_pushinteger(L, box_shift_amount(n)); + nodelib_push_direct_or_nil_node_prev(L, box_list(n)); + return 5; + } + } + return 0; +} + /* node.direct.getlist */ static int nodelib_direct_getlist(lua_State *L) @@ -3874,7 +3901,7 @@ static int nodelib_direct_remove(lua_State *L) return 3; } } else { - lua_pushinteger(L, head); + nodelib_push_direct_or_nil(L, head); lua_pushnil(L); } } else { @@ -3884,6 +3911,34 @@ static int nodelib_direct_remove(lua_State *L) return 2; } +static int nodelib_direct_remove_from_list(lua_State *L) +{ + halfword head = nodelib_valid_direct_from_index(L, 1); + int count = 0; + if (head) { + halfword id = lmt_tohalfword(L, 2); + halfword subtype = lmt_opthalfword(L, 3, -1); + halfword current = head; + while (current) { + halfword next = node_next(current); + if (node_type(current) == id && (subtype < 0 || node_subtype(current) == subtype)) { + if (current == head) { + head = next; + node_prev(next) = null; + } else { + tex_try_couple_nodes(node_prev(current), next); + } + tex_flush_node(current); + ++count; + } + current = next; + } + } + nodelib_push_direct_or_nil(L, head); + lua_push_integer(L, count); + return 2; +} + /* node.insertbefore (insert a node in a list) */ static int nodelib_userdata_insertbefore(lua_State *L) @@ -8436,7 +8491,6 @@ static int nodelib_direct_isprevglyph(lua_State *L) } } - /* direct.usesfont */ inline static int nodelib_aux_uses_font_disc(lua_State *L, halfword n, halfword font) @@ -9700,8 +9754,10 @@ static const struct luaL_Reg nodelib_direct_function_list[] = { { "rangedimensions", nodelib_direct_rangedimensions }, /* maybe get... */ { "getglyphdimensions", nodelib_direct_getglyphdimensions }, { "getkerndimension", nodelib_direct_getkerndimension }, + { "getlistdimensions", nodelib_direct_getlistdimensions }, { "patchattributes", nodelib_direct_patchattributes }, { "remove", nodelib_direct_remove }, + { "removefromlist", nodelib_direct_remove_from_list }, { "repack", nodelib_direct_repack }, { "freeze", nodelib_direct_freeze }, { "setattribute", nodelib_direct_setattribute }, diff --git a/source/luametatex/source/lua/lmttexiolib.c b/source/luametatex/source/lua/lmttexiolib.c index f7f7751d8..416293164 100644 --- a/source/luametatex/source/lua/lmttexiolib.c +++ b/source/luametatex/source/lua/lmttexiolib.c @@ -19,7 +19,8 @@ FILE *lmt_valid_file(lua_State *L) { luaL_Stream *p = (luaL_Stream *) lua_touserdata(L, 1); if (p && lua_getmetatable(L, 1)) { - luaL_getmetatable(L, LUA_FILEHANDLE); + // luaL_getmetatable(L, LUA_FILEHANDLE); + lua_get_metatablelua(file_handle_instance); if (! lua_rawequal(L, -1, -2)) { p = NULL; } diff --git a/source/luametatex/source/lua/lmttexlib.c b/source/luametatex/source/lua/lmttexlib.c index 7d1f3c32f..d3f4c0ab9 100644 --- a/source/luametatex/source/lua/lmttexlib.c +++ b/source/luametatex/source/lua/lmttexlib.c @@ -27,7 +27,8 @@ /*tex Due to the nature of the accessors, this is the module with most metatables. However, we - provide getters and setters too. Users can choose what they like most. + provide getters and setters too. Users can choose what they like most. If needed we can use + fast metatable resolvers but there is no real need. */ # define TEX_METATABLE_ATTRIBUTE "tex.attribute" @@ -2604,6 +2605,7 @@ static int texlib_aux_convert(lua_State *L, int cur_code) case string_code: /* arg token */ case cs_string_code: /* arg token */ case cs_active_code: /* arg token */ + /* case cs_lastname_code: */ /* arg token */ case detokenized_code: /* arg token */ case meaning_code: /* arg token */ case to_mathstyle_code: diff --git a/source/luametatex/source/luametatex.h b/source/luametatex/source/luametatex.h index 6bb728234..a9f739cec 100644 --- a/source/luametatex/source/luametatex.h +++ b/source/luametatex/source/luametatex.h @@ -87,9 +87,9 @@ # include "tex/textypes.h" # define luametatex_version 210 -# define luametatex_revision 02 -# define luametatex_version_string "2.10.02" -# define luametatex_development_id 20221118 +# define luametatex_revision 04 +# define luametatex_version_string "2.10.04" +# define luametatex_development_id 20221202 # define luametatex_name_camelcase "LuaMetaTeX" # define luametatex_name_lowercase "luametatex" diff --git a/source/luametatex/source/luarest/lmtpdfelib.c b/source/luametatex/source/luarest/lmtpdfelib.c index b22626749..74000d756 100644 --- a/source/luametatex/source/luarest/lmtpdfelib.c +++ b/source/luametatex/source/luarest/lmtpdfelib.c @@ -90,7 +90,7 @@ static pdfe_dictionary *pdfelib_aux_check_isdictionary(lua_State *L, int n) { pdfe_dictionary *p = (pdfe_dictionary *) lua_touserdata(L, n); if (p && lua_getmetatable(L, n)) { - lua_get_metatablelua(pdfe_dictionary); + lua_get_metatablelua(pdfe_dictionary_instance); if (! lua_rawequal(L, -1, -2)) { p = NULL; } @@ -107,7 +107,7 @@ static pdfe_array *pdfelib_aux_check_isarray(lua_State *L, int n) { pdfe_array *p = (pdfe_array *) lua_touserdata(L, n); if (p && lua_getmetatable(L, n)) { - lua_get_metatablelua(pdfe_array); + lua_get_metatablelua(pdfe_array_instance); if (! lua_rawequal(L, -1, -2)) { p = NULL; } @@ -124,7 +124,7 @@ static pdfe_stream *pdfelib_aux_check_isstream(lua_State *L, int n) { pdfe_stream *p = (pdfe_stream *) lua_touserdata(L, n); if (p && lua_getmetatable(L, n)) { - lua_get_metatablelua(pdfe_stream); + lua_get_metatablelua(pdfe_stream_instance); if (! lua_rawequal(L, -1, -2)) { p = NULL; } @@ -141,7 +141,7 @@ static pdfe_reference *pdfelib_aux_check_isreference(lua_State *L, int n) { pdfe_reference *p = (pdfe_reference *) lua_touserdata(L, n); if (p && lua_getmetatable(L, n)) { - lua_get_metatablelua(pdfe_reference); + lua_get_metatablelua(pdfe_reference_instance); if (! lua_rawequal(L, -1, -2)) { p = NULL; } @@ -203,10 +203,10 @@ static int pdfelib_type(lua_State *L) void *p = lua_touserdata(L, 1); if (p && lua_getmetatable(L, 1)) { check_type(document, pdfe_instance); - check_type(dictionary, pdfe_dictionary); - check_type(array, pdfe_array); - check_type(reference, pdfe_reference); - check_type(stream, pdfe_stream); + check_type(dictionary, pdfe_dictionary_instance); + check_type(array, pdfe_array_instance); + check_type(reference, pdfe_reference_instance); + check_type(stream, pdfe_stream_instance); } return 0; } @@ -278,7 +278,8 @@ static int pdfelib_reference_tostring(lua_State *L) { inline static void pdfe_push_dictionary(lua_State *L, ppdict *dictionary) { pdfe_dictionary *d = (pdfe_dictionary *) lua_newuserdatauv(L, sizeof(pdfe_dictionary), 0); - luaL_getmetatable(L, PDFE_METATABLE_DICTIONARY); + // luaL_getmetatable(L, PDFE_METATABLE_DICTIONARY); + lua_get_metatablelua(pdfe_dictionary_instance); lua_setmetatable(L, -2); d->dictionary = dictionary; } @@ -307,7 +308,8 @@ static int pdfelib_aux_pushdictionaryonly(lua_State *L, ppdict *dictionary) inline static void pdfe_push_array(lua_State *L, pparray *array) { pdfe_array *a = (pdfe_array *) lua_newuserdatauv(L, sizeof(pdfe_array), 0); - luaL_getmetatable(L, PDFE_METATABLE_ARRAY); + // luaL_getmetatable(L, PDFE_METATABLE_ARRAY); + lua_get_metatablelua(pdfe_array_instance); lua_setmetatable(L, -2); a->array = array; } @@ -336,7 +338,8 @@ static int pdfelib_aux_pusharrayonly(lua_State *L, pparray *array) inline static void pdfe_push_stream(lua_State *L, ppstream *stream) { pdfe_stream *s = (pdfe_stream *) lua_newuserdatauv(L, sizeof(pdfe_stream), 0); - luaL_getmetatable(L, PDFE_METATABLE_STREAM); + // luaL_getmetatable(L, PDFE_METATABLE_STREAM); + lua_get_metatablelua(pdfe_stream_instance); lua_setmetatable(L, -2); s->stream = stream; s->open = 0; @@ -374,7 +377,8 @@ static int pdfelib_aux_pushstreamonly(lua_State *L, ppstream *stream) inline static void pdfe_push_reference(lua_State *L, ppref *reference) { pdfe_reference *r = (pdfe_reference *) lua_newuserdatauv(L, sizeof(pdfe_reference), 0); - luaL_getmetatable(L, PDFE_METATABLE_REFERENCE); + // luaL_getmetatable(L, PDFE_METATABLE_REFERENCE); + lua_get_metatablelua(pdfe_reference_instance); lua_setmetatable(L, -2); r->xref = reference->xref; r->onum = (int) reference->number; @@ -861,7 +865,8 @@ static void aux_pdfelib_open(lua_State *L, FILE *f) { pdfe_document *p = (pdfe_document *) lua_newuserdatauv(L, sizeof(pdfe_document), 0); ppdoc *d = ppdoc_filehandle(f, 1); - luaL_getmetatable(L, PDFE_METATABLE_INSTANCE); + // luaL_getmetatable(L, PDFE_METATABLE_INSTANCE); + lua_get_metatablelua(pdfe_instance); lua_setmetatable(L, -2); p->document = d; p->open = 1; @@ -936,7 +941,8 @@ static int pdfelib_new(lua_State *L) d = ppdoc_mem(memstream, streamsize); if (d) { pdfe_document *p = (pdfe_document *) lua_newuserdatauv(L, sizeof(pdfe_document), 0); - luaL_getmetatable(L, PDFE_METATABLE_INSTANCE); + // luaL_getmetatable(L, PDFE_METATABLE_INSTANCE); + lua_get_metatablelua(pdfe_instance); lua_setmetatable(L, -2); p->document = d; p->open = 1; @@ -1321,12 +1327,12 @@ static int pdfelib_get_value_direct(lua_State *L, void **value, pp_d_direct get_ case LUA_TSTRING: { const char *key = lua_tostring(L, 2); - lua_get_metatablelua(pdfe_dictionary); + lua_get_metatablelua(pdfe_dictionary_instance); if (lua_rawequal(L, -1, -2)) { *value = get_d(((pdfe_dictionary *) p)->dictionary, key); return 1; } else { - lua_get_metatablelua(pdfe_reference); + lua_get_metatablelua(pdfe_reference_instance); if (lua_rawequal(L, -1, -3)) { ppref *r = (((pdfe_reference *) p)->xref) ? ppxref_find(((pdfe_reference *) p)->xref, (ppuint) (((pdfe_reference *) p)->onum)) : NULL; \ ppobj *o = (r) ? ppref_obj(r) : NULL; @@ -1341,12 +1347,12 @@ static int pdfelib_get_value_direct(lua_State *L, void **value, pp_d_direct get_ case LUA_TNUMBER: { size_t index = lua_tointeger(L, 2); - lua_get_metatablelua(pdfe_array); + lua_get_metatablelua(pdfe_array_instance); if (lua_rawequal(L, -1, -2)) { *value = get_a(((pdfe_array *) p)->array, index); return 2; } else { - lua_get_metatablelua(pdfe_reference); + lua_get_metatablelua(pdfe_reference_instance); if (lua_rawequal(L, -1, -3)) { ppref *r = (((pdfe_reference *) p)->xref) ? ppxref_find(((pdfe_reference *) p)->xref, (ppuint) (((pdfe_reference *) p)->onum)) : NULL; \ ppobj *o = (r) ? ppref_obj(r) : NULL; @@ -1375,11 +1381,11 @@ static int pdfelib_get_value_indirect(lua_State *L, void **value, pp_d_indirect case LUA_TSTRING: { const char *key = lua_tostring(L, 2); - lua_get_metatablelua(pdfe_dictionary); + lua_get_metatablelua(pdfe_dictionary_instance); if (lua_rawequal(L, -1, -2)) { return get_d(((pdfe_dictionary *) p)->dictionary, key, value); } else { - lua_get_metatablelua(pdfe_reference); + lua_get_metatablelua(pdfe_reference_instance); if (lua_rawequal(L, -1, -3)) { ppref *r = (((pdfe_reference *) p)->xref) ? ppxref_find(((pdfe_reference *) p)->xref, (ppuint) (((pdfe_reference *) p)->onum)) : NULL; ppobj *o = (r) ? ppref_obj(r) : NULL; @@ -1392,11 +1398,11 @@ static int pdfelib_get_value_indirect(lua_State *L, void **value, pp_d_indirect case LUA_TNUMBER: { size_t index = lua_tointeger(L, 2); - lua_get_metatablelua(pdfe_array); + lua_get_metatablelua(pdfe_array_instance); if (lua_rawequal(L, -1, -2)) { return get_a(((pdfe_array *) p)->array, index, value); } else { - lua_get_metatablelua(pdfe_reference); + lua_get_metatablelua(pdfe_reference_instance); if (lua_rawequal(L, -1, -3)) { ppref *r = (((pdfe_reference *) p)->xref) ? ppxref_find(((pdfe_reference *) p)->xref, (ppuint) (((pdfe_reference *) p)->onum)) : NULL; ppobj *o = (r) ? ppref_obj(r) : NULL; 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 */ |