20
20
#include "ptexlib.h"
22
#include "luatex-api.h"
22
#include "lua/luatex-api.h"
24
24
static const char _svn_version[] =
25
"$Id: dofont.c 2448 2009-06-08 07:43:50Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/dofont.c $";
30
# include <sys/time.h>
25
"$Id: dofont.c 3261 2009-12-18 11:38:21Z taco $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.50.0/source/texk/web2c/luatexdir/font/dofont.c $";
34
27
/* a bit more interfacing is needed for proper error reporting */
36
29
static char *font_error_message(pointer u, char *nom, scaled s)
38
31
char *str = xmalloc(256);
39
char *c = makecstring(zget_cs_text(u));
32
char *c = makecstring(cs_text(u));
40
33
char *extra = "metric data not found or bad";
42
35
snprintf(str, 255, "Font \\%s=%s at %gpt not loadable: %s", c, nom,
48
41
snprintf(str, 255, "Font \\%s=%s not loadable: %s", c, nom, extra);
53
static int do_define_font(integer f, char *cnom, scaled s, integer natural_dir)
47
static int do_define_font(int f, char *cnom, scaled s, int natural_dir)
56
50
boolean res; /* was the callback successful? */
67
56
callback_id = callback_defined(define_font_callback);
68
57
if (callback_id > 0) {
69
58
cnam = xstrdup(cnom);
71
gettimeofday(&tva, NULL);
73
59
callback_id = run_and_save_callback(callback_id, "Sdd->", cnam, s, f);
75
gettimeofday(&tvb, NULL);
76
tvdiff = tvb.tv_sec * 1000000.0;
77
tvdiff += (double) tvb.tv_usec;
78
tvdiff -= (tva.tv_sec * 1000000.0);
79
tvdiff -= (double) tva.tv_usec;
81
fprintf(stdout, "\ncallback('define_font',%s,%i): %f seconds\n", cnam,
85
61
if (callback_id > 0) { /* success */
86
62
luaL_checkstack(Luas, 1, "out of stack space");
87
63
lua_rawgeti(Luas, LUA_REGISTRYINDEX, callback_id);
88
64
if (lua_istable(Luas, -1)) {
90
gettimeofday(&tva, NULL);
92
65
res = font_from_lua(Luas, f);
93
66
destroy_saved_callback(callback_id);
95
gettimeofday(&tvb, NULL);
96
tvdiff = tvb.tv_sec * 1000000.0;
97
tvdiff += (double) tvb.tv_usec;
98
tvdiff -= (tva.tv_sec * 1000000.0);
99
tvdiff -= (double) tva.tv_usec;
101
fprintf(stdout, "font_from_lua(%s,%i): %f seconds\n",
102
font_name(f), f, tvdiff);
104
67
/* lua_pop(Luas, 1); *//* done by font_from_lua */
105
68
} else if (lua_isnumber(Luas, -1)) {
106
69
r = lua_tonumber(Luas, -1);
117
80
} else if (callback_id == 0) {
118
81
res = read_tfm_info(f, cnom, s);
120
set_hyphen_char(f, get_default_hyphen_char());
121
set_skew_char(f, get_default_skew_char());
83
set_hyphen_char(f, int_par(default_hyphen_char_code));
84
set_skew_char(f, int_par(default_skew_char_code));
87
if (font_name(f) && strlen(font_name(f)) > 255) {
88
/* the font name has to fit in the dvi file's single byte storage */
89
/* no need to test area, as we are never using it */
125
93
if (font_type(f) != virtual_font_type) { /* implies lua */
137
int read_font_info(pointer u, str_number nom, scaled s, integer natural_dir)
105
int read_font_info(pointer u, str_number nom, scaled s, int natural_dir)
142
cnom = xstrdup(makecstring(nom));
110
cnom = makecstring(nom);
145
113
if ((f = do_define_font(f, cnom, s, natural_dir))) {
150
118
"so I will ignore the font specification.",
151
119
"[Wizards can fix TFM files using TFtoPL/PLtoTF.]",
152
120
"You might try inserting a different font spec;",
153
"e.g., type `I\font<same font id>=<substitute font name>'.",
121
"e.g., type `I\\font<same font id>=<substitute font name>'.",
156
if (!get_suppress_fontnotfound_error()) {
124
if (int_par(suppress_fontnotfound_error_code) == 0) {
157
125
msg = font_error_message(u, cnom, s);
158
126
tex_error(msg, help);