3
Copyright 2006-2008 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/>. */
22
#include "lua/luatex-api.h"
24
static const char _svn_version[] =
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 $";
27
/* 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
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, 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
if (lua_istable(Luas, -1)) {
65
res = font_from_lua(Luas, f);
66
destroy_saved_callback(callback_id);
67
/* lua_pop(Luas, 1); *//* done by font_from_lua */
68
} else if (lua_isnumber(Luas, -1)) {
69
r = lua_tonumber(Luas, -1);
70
destroy_saved_callback(callback_id);
80
} else if (callback_id == 0) {
81
res = read_tfm_info(f, cnom, s);
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 */
93
if (font_type(f) != virtual_font_type) { /* implies lua */
95
set_font_natural_dir(f, natural_dir);
105
int read_font_info(pointer u, str_number nom, scaled s, int natural_dir)
110
cnom = makecstring(nom);
113
if ((f = do_define_font(f, cnom, s, natural_dir))) {
117
char *help[] = { "I wasn't able to read the size data for this font,",
118
"so I will ignore the font specification.",
119
"[Wizards can fix TFM files using TFtoPL/PLtoTF.]",
120
"You might try inserting a different font spec;",
121
"e.g., type `I\\font<same font id>=<substitute font name>'.",
124
if (int_par(suppress_fontnotfound_error_code) == 0) {
125
msg = font_error_message(u, cnom, s);
126
tex_error(msg, help);
134
/* TODO This function is a placeholder. There can easily appears holes in
135
the |font_tables| array, and we could attempt to reuse those
138
int find_font_id(char *nom, scaled s)
142
if ((f = do_define_font(f, nom, s, -1))) {