17
17
You should have received a copy of the GNU General Public License along
18
18
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
20
#include "luatex-api.h"
20
static const char _svn_version[] =
21
"$Id: lnodelib.c 3265 2009-12-18 16:21:40Z taco $ "
22
"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.50.0/source/texk/web2c/luatexdir/lua/lnodelib.c $";
24
#include "lua/luatex-api.h"
21
25
#include <ptexlib.h>
27
static const char _svn_version[] =
28
"$Id: lnodelib.c 2476 2009-06-12 19:39:05Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/lua/lnodelib.c $";
30
27
#define init_luaS_index(a) do { \
31
28
lua_pushliteral(L,#a); \
32
29
luaS_##a##_ptr = (char *)lua_tostring(L,-1); \
46
43
make_luaS_index(luatex_node);
45
static int nodelib_getdir(lua_State * L, int n); /* forward */
48
47
halfword *check_isnode(lua_State * L, int ud)
50
49
register halfword *p = lua_touserdata(L, ud);
194
193
static int lua_nodelib_type(lua_State * L)
196
integer i = get_node_type_id(L, 1);
195
int i = get_node_type_id(L, 1);
198
197
lua_pushstring(L, node_data[i].name);
494
494
"3rd argument should be either additional or exactly");
499
else if (lua_type(L, 3) == LUA_TNUMBER) {
497
} else if (lua_type(L, 3) == LUA_TNUMBER) {
500
498
m = lua_tonumber(L, 3);
502
500
lua_pushstring(L, "incorrect 3rd argument");
502
if (lua_gettop(L) > 3) {
503
if (lua_type(L, 4) == LUA_TSTRING) {
504
d = nodelib_getdir(L, 4);
506
lua_pushstring(L, "incorrect 4th argument");
511
p = hpack(n, w, m, d);
507
512
lua_nodelib_push_fast(L, p);
517
static int lua_nodelib_dimensions(lua_State * L)
523
glue_ratio g_mult = 1.0;
525
int g_order = normal;
528
halfword n = null, p = null;
529
if (lua_isnumber(L, 1)) {
535
g_mult = (glue_ratio) lua_tonumber(L, 1);
536
g_sign = lua_tonumber(L, 2);
537
g_order = lua_tonumber(L, 3);
539
n = *(check_isnode(L, i));
540
if (lua_gettop(L) > i && !lua_isnil(L, (i + 1))) {
541
if (lua_type(L, (i + 1)) == LUA_TSTRING) {
542
d = nodelib_getdir(L, (i + 1));
544
p = *(check_isnode(L, (i + 1)));
547
if (lua_gettop(L) > (i + 1) && lua_type(L, (i + 2)) == LUA_TSTRING) {
548
d = nodelib_getdir(L, (i + 2));
550
siz = natural_sizes(n, p, g_mult, g_sign, g_order, d);
551
lua_pushnumber(L, siz.wd);
552
lua_pushnumber(L, siz.ht);
553
lua_pushnumber(L, siz.dp);
557
"missing argument to 'dimensions' (luatex_node expected)");
560
return 0; /* not reached */
512
564
/* build a vbox */
513
565
static int lua_nodelib_vpack(lua_State * L)
519
572
n = *(check_isnode(L, 1));
520
573
if (lua_gettop(L) > 1) {
521
574
w = lua_tointeger(L, 2);
531
584
"3rd argument should be either additional or exactly");
587
if (lua_gettop(L) > 3) {
588
if (lua_type(L, 4) == LUA_TSTRING) {
589
d = nodelib_getdir(L, 4);
591
lua_pushstring(L, "incorrect 4th argument");
536
596
else if (lua_type(L, 3) == LUA_TNUMBER) {
543
p = vpackage(n, w, m, max_dimen);
603
p = vpackage(n, w, m, max_dimen, d);
544
604
lua_nodelib_push_fast(L, p);
557
617
w = luaL_checkoption(L, 2, "text", math_style_names);
558
618
luaL_checkany(L, 3);
559
619
m = lua_toboolean(L, 3);
620
mlist_to_hlist_args(n, w, m);
564
621
lua_nodelib_push_fast(L, vlink(temp_head));
837
static int lua_nodelib_tail_only(lua_State * L)
842
return 1; /* the nil itself */
843
n = check_isnode(L, 1);
846
return 1; /* the old userdata */
847
while (vlink(t) != null) {
850
lua_nodelib_push_fast(L, t);
780
855
/* a few utility functions for attribute stuff */
782
857
static int lua_nodelib_has_attribute(lua_State * L)
971
1046
#define nodelib_pushattr(L,n) { lua_pushnumber(L,n); lua_nodelib_push(L); }
972
1047
#define nodelib_pushspec(L,n) { lua_pushnumber(L,n); lua_nodelib_push(L); }
973
1048
#define nodelib_pushaction(L,n) { lua_pushnumber(L,n); lua_nodelib_push(L); }
974
#define nodelib_pushstring(L,n) { lua_pushstring(L,makecstring(n)); }
1049
#define nodelib_pushstring(L,n) { char *ss=makecstring(n); lua_pushstring(L,ss); free(ss); }
976
1051
static void nodelib_pushdir(lua_State * L, int n, boolean dirnode)
979
char dirstring[5] = { 0 };
981
dirstring[f++] = (n < 0 ? '-' : '+');
1055
s[0] = (n < 0 ? '-' : '+');
985
dirstring[f++] = dir_names[(int) dir_primary[n]];
986
dirstring[f++] = dir_names[(int) dir_secondary[n]];
987
dirstring[f++] = dir_names[(int) dir_tertiary[n]];
988
lua_pushstring(L, dirstring);
1063
lua_pushfstring(L, "%sTLT", s);
1064
} else if (n == dir_TRT) {
1065
lua_pushfstring(L, "%sTRT", s);
1066
} else if (n == dir_LTL) {
1067
lua_pushfstring(L, "%sLTL", s);
1068
} else if (n == dir_RTT) {
1069
lua_pushfstring(L, "%sRTT", s);
1071
lua_pushstring(L, "???");
991
1075
static void lua_nodelib_getfield_whatsit(lua_State * L, int n, int field)
1115
1199
case pdf_refxform_node:
1116
1200
switch (field) {
1118
lua_pushnumber(L, pdf_width(n));
1202
lua_pushnumber(L, width(n));
1121
lua_pushnumber(L, pdf_height(n));
1205
lua_pushnumber(L, depth(n));
1124
lua_pushnumber(L, pdf_depth(n));
1208
lua_pushnumber(L, height(n));
1127
1211
lua_pushnumber(L, pdf_xform_objnum(n));
1133
1217
case pdf_refximage_node:
1134
1218
switch (field) {
1136
lua_pushnumber(L, pdf_width(n));
1220
lua_pushnumber(L, width(n));
1139
lua_pushnumber(L, pdf_height(n));
1223
lua_pushnumber(L, depth(n));
1142
lua_pushnumber(L, pdf_depth(n));
1226
lua_pushnumber(L, height(n));
1145
lua_pushnumber(L, pdf_ximage_objnum(n));
1229
lua_pushnumber(L, pdf_ximage_transform(n));
1232
lua_pushnumber(L, pdf_ximage_index(n));
1148
1235
lua_pushnil(L);
1151
1238
case pdf_annot_node:
1152
1239
switch (field) {
1154
lua_pushnumber(L, pdf_width(n));
1241
lua_pushnumber(L, width(n));
1157
lua_pushnumber(L, pdf_height(n));
1244
lua_pushnumber(L, depth(n));
1160
lua_pushnumber(L, pdf_depth(n));
1247
lua_pushnumber(L, height(n));
1163
1250
lua_pushnumber(L, pdf_annot_objnum(n));
1172
1259
case pdf_start_link_node:
1173
1260
switch (field) {
1175
lua_pushnumber(L, pdf_width(n));
1262
lua_pushnumber(L, width(n));
1178
lua_pushnumber(L, pdf_height(n));
1265
lua_pushnumber(L, depth(n));
1181
lua_pushnumber(L, pdf_depth(n));
1268
lua_pushnumber(L, height(n));
1184
1271
lua_pushnumber(L, pdf_link_objnum(n));
1196
1283
case pdf_dest_node:
1197
1284
switch (field) {
1199
lua_pushnumber(L, pdf_width(n));
1286
lua_pushnumber(L, width(n));
1202
lua_pushnumber(L, pdf_height(n));
1289
lua_pushnumber(L, depth(n));
1205
lua_pushnumber(L, pdf_depth(n));
1292
lua_pushnumber(L, height(n));
1208
1295
lua_pushnumber(L, pdf_dest_named_id(n));
1230
1317
case pdf_start_thread_node:
1231
1318
switch (field) {
1233
lua_pushnumber(L, pdf_width(n));
1320
lua_pushnumber(L, width(n));
1236
lua_pushnumber(L, pdf_height(n));
1323
lua_pushnumber(L, depth(n));
1239
lua_pushnumber(L, pdf_depth(n));
1326
lua_pushnumber(L, height(n));
1242
1329
lua_pushnumber(L, pdf_thread_named_id(n));
1974
2061
char *s = NULL;
1975
2062
int d = 32; /* invalid number */
1976
int a = -1, b = -1, c = -1;
1977
2063
if (lua_type(L, n) == LUA_TSTRING) {
1978
2064
s = (char *) lua_tostring(L, n);
1979
2065
if (strlen(s) == 3) {
1989
2075
if (strlen(s) == 3) {
1992
case 'T': a=0; break;
1993
case 'L': a=1; break;
1994
case 'B': a=2; break;
1995
case 'R': a=3; break;
2000
case 'T': b=0; break;
2001
case 'L': b=1; break;
2002
case 'B': b=2; break;
2003
case 'R': b=3; break;
2008
case 'T': c=0; break;
2009
case 'L': c=1; break;
2010
case 'B': c=2; break;
2011
case 'R': c=3; break;
2015
if (a != -1 && b != -1 && c != -1 && !dir_parallel(a, b)) {
2016
d += (a * 8 + dir_rearrange[b] * 4 + c);
2018
} else if (lua_isnumber(L, n)) {
2019
d = lua_tonumber(L, n);
2076
if (strcmp(s, "TLT") == 0) {
2078
} else if (strcmp(s, "TRT") == 0) {
2080
} else if (strcmp(s, "LTL") == 0) {
2082
} else if (strcmp(s, "RTT") == 0) {
2087
lua_pushstring(L, "Direction specifiers have to be strings");
2021
2090
if ((d > 31) || (d < -64) || (d < 0 && (d + 64) > 31)) {
2187
2256
case pdf_refxform_node:
2188
2257
switch (field) {
2190
pdf_width(n) = lua_tointeger(L, 3);
2259
width(n) = lua_tointeger(L, 3);
2193
pdf_height(n) = lua_tointeger(L, 3);
2262
depth(n) = lua_tointeger(L, 3);
2196
pdf_depth(n) = lua_tointeger(L, 3);
2265
height(n) = lua_tointeger(L, 3);
2199
2268
pdf_xform_objnum(n) = lua_tointeger(L, 3);
2205
2274
case pdf_refximage_node:
2206
2275
switch (field) {
2208
pdf_width(n) = lua_tointeger(L, 3);
2277
width(n) = lua_tointeger(L, 3);
2211
pdf_height(n) = lua_tointeger(L, 3);
2280
depth(n) = lua_tointeger(L, 3);
2214
pdf_depth(n) = lua_tointeger(L, 3);
2283
height(n) = lua_tointeger(L, 3);
2217
pdf_ximage_objnum(n) = lua_tointeger(L, 3);
2286
pdf_ximage_transform(n) = lua_tointeger(L, 3);
2289
pdf_ximage_index(n) = lua_tointeger(L, 3);
2220
2292
return nodelib_cantset(L, field, n);
2223
2295
case pdf_annot_node:
2224
2296
switch (field) {
2226
pdf_width(n) = lua_tointeger(L, 3);
2298
width(n) = lua_tointeger(L, 3);
2229
pdf_height(n) = lua_tointeger(L, 3);
2301
depth(n) = lua_tointeger(L, 3);
2232
pdf_depth(n) = lua_tointeger(L, 3);
2304
height(n) = lua_tointeger(L, 3);
2235
2307
pdf_annot_objnum(n) = lua_tointeger(L, 3);
2244
2316
case pdf_start_link_node:
2245
2317
switch (field) {
2247
pdf_width(n) = lua_tointeger(L, 3);
2319
width(n) = lua_tointeger(L, 3);
2250
pdf_height(n) = lua_tointeger(L, 3);
2322
depth(n) = lua_tointeger(L, 3);
2253
pdf_depth(n) = lua_tointeger(L, 3);
2325
height(n) = lua_tointeger(L, 3);
2256
2328
pdf_link_objnum(n) = lua_tointeger(L, 3);
2274
2346
case pdf_dest_node:
2275
2347
switch (field) {
2277
pdf_width(n) = lua_tointeger(L, 3);
2349
width(n) = lua_tointeger(L, 3);
2280
pdf_height(n) = lua_tointeger(L, 3);
2352
depth(n) = lua_tointeger(L, 3);
2283
pdf_depth(n) = lua_tointeger(L, 3);
2355
height(n) = lua_tointeger(L, 3);
2286
2358
pdf_dest_named_id(n) = lua_tointeger(L, 3);
2308
2380
case pdf_start_thread_node:
2309
2381
switch (field) {
2311
pdf_width(n) = lua_tointeger(L, 3);
2383
width(n) = lua_tointeger(L, 3);
2314
pdf_height(n) = lua_tointeger(L, 3);
2386
depth(n) = lua_tointeger(L, 3);
2317
pdf_depth(n) = lua_tointeger(L, 3);
2389
height(n) = lua_tointeger(L, 3);
2320
2392
pdf_thread_named_id(n) = lua_tointeger(L, 3);
3227
3299
{"count", lua_nodelib_count},
3228
3300
{"traverse", lua_nodelib_traverse},
3229
3301
{"traverse_id", lua_nodelib_traverse_filtered},
3302
{"tail", lua_nodelib_tail_only},
3230
3303
{"slide", lua_nodelib_tail},
3231
3304
{"types", lua_nodelib_types},
3232
3305
{"whatsits", lua_nodelib_whatsits},
3241
3314
{"last_node", lua_nodelib_last_node},
3242
3315
{"copy", lua_nodelib_copy},
3243
3316
{"copy_list", lua_nodelib_copy_list},
3317
{"dimensions", lua_nodelib_dimensions},
3244
3318
{"hpack", lua_nodelib_hpack},
3245
3319
{"vpack", lua_nodelib_vpack},
3246
3320
{"mlist_to_hlist", lua_nodelib_mlist_to_hlist},