3 % Copyright
2006-2010 Taco Hoekwater
<taco@@luatex.org
>
5 % This file is part of LuaTeX.
7 % LuaTeX is free software
; you can redistribute it and
/or modify it under
8 % the terms of the GNU General Public License as published by the Free
9 % Software Foundation
; either version
2 of the License
, or
(at your
10 % option
) any later version.
12 % LuaTeX is distributed in the hope that it will be useful
, but WITHOUT
13 % ANY WARRANTY
; without even the implied warranty of MERCHANTABILITY or
14 % FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 % License for more details.
17 % You should have received a copy of the GNU General Public License along
18 % with LuaTeX
; if not
, see
<http
://www.gnu.org
/licenses
/>.
24 #include
"lua/luatex-api.h"
26 @ a bit more interfacing is needed for proper error reporting
29 static char
*font_error_message
(pointer u
, char
*nom
, scaled s
)
31 char
*str
= xmalloc
(256);
32 char
*c
= makecstring
(cs_text
(u
));
33 const char
*extra
= "metric data not found or bad";
35 snprintf
(str
, 255, "Font \\%s=%s at %gpt not loadable: %s", c
, nom
,
36 (double
) s
/ 65536, extra
);
37 } else if
(s
!= -1000) {
38 snprintf
(str
, 255, "Font \\%s=%s scaled %d not loadable: %s", c
, nom
,
41 snprintf
(str
, 255, "Font \\%s=%s not loadable: %s", c
, nom
, extra
);
47 static int do_define_font
(int f
, const char
*cnom
, scaled s
, int natural_dir
)
50 boolean res
; /* was the callback successful?
*/
56 callback_id
= callback_defined
(define_font_callback
);
57 if
(callback_id
> 0) {
59 callback_id
= run_and_save_callback
(callback_id
, "Sdd->", cnam
, s
, f
);
61 if
(callback_id
> 0) { /* success
*/
62 luaL_checkstack
(Luas
, 1, "out of stack space");
63 lua_rawgeti
(Luas
, LUA_REGISTRYINDEX
, callback_id
);
64 t
= lua_type
(Luas
, -1);
65 if
(t
== LUA_TTABLE
) {
66 res
= font_from_lua
(Luas
, f
);
67 destroy_saved_callback
(callback_id
);
68 /* |lua_pop
(Luas
, 1);|
*//* done by |font_from_lua|
*/
69 } else if
(t
== LUA_TNUMBER
) {
70 r
= (int
) lua_tointeger
(Luas
, -1);
71 destroy_saved_callback
(callback_id
);
81 } else if
(callback_id
== 0) {
82 res
= read_tfm_info
(f
, cnom
, s
);
84 set_hyphen_char
(f
, int_par
(default_hyphen_char_code
));
85 set_skew_char
(f
, int_par
(default_skew_char_code
));
88 if
(font_name
(f
) && strlen(font_name(f)) > 255) {
89 /* the font name has to fit in the dvi file's single byte storage
*/
90 /* no need to test area
, as we are never using it
*/
94 if
(font_type
(f
) != virtual_font_type
) { /* implies lua
*/
96 set_font_natural_dir
(f
, natural_dir
);
106 int read_font_info
(pointer u
, char
*cnom
, scaled s
, int natural_dir
)
112 if
((f
= do_define_font
(f
, cnom
, s
, natural_dir
))) {
116 { "I wasn't able to read the size data for this font,",
117 "so I will ignore the font specification.",
118 "[Wizards can fix TFM files using TFtoPL/PLtoTF.]",
119 "You might try inserting a different font spec;",
120 "e.g., type `I\\font<same font id>=<substitute font name>'.",
123 if
(int_par
(suppress_fontnotfound_error_code
) == 0) {
124 msg
= font_error_message
(u
, cnom
, s
);
125 tex_error
(msg
, help
);
132 @ TODO This function is a placeholder. There can easily appears holes in
133 the |font_tables| array
, and we could attempt to reuse those
136 int find_font_id
(const char
*nom
, scaled s
)
140 if
((f
= do_define_font
(f
, nom
, s
, -1))) {