~ubuntu-branches/ubuntu/wily/luatex/wily

« back to all changes in this revision

Viewing changes to source/texk/web2c/luatexdir/font/dofont.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2010-04-29 00:47:19 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100429004719-o42etkqe90n97b9e
Tags: 0.60.1-1
* new upstream release, adapt build-script patch
* disable patch: upstream-epstopdf_cc_no_xpdf_patching, included upstream
* disable patch: libpoppler-0.12, not needed anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* dofont.c
2
 
   
3
 
   Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
4
 
 
5
 
   This file is part of LuaTeX.
6
 
 
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.
11
 
 
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.
16
 
 
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/>. */
19
 
 
20
 
#include "ptexlib.h"
21
 
 
22
 
#include "lua/luatex-api.h"
23
 
 
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 $";
26
 
 
27
 
/* a bit more interfacing is needed for proper error reporting */
28
 
 
29
 
static char *font_error_message(pointer u, char *nom, scaled s)
30
 
{
31
 
    char *str = xmalloc(256);
32
 
    char *c = makecstring(cs_text(u));
33
 
    char *extra = "metric data not found or bad";
34
 
    if (s >= 0) {
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,
39
 
                 (int) (-s), extra);
40
 
    } else {
41
 
        snprintf(str, 255, "Font \\%s=%s not loadable: %s", c, nom, extra);
42
 
    }
43
 
    free(c);
44
 
    return str;
45
 
}
46
 
 
47
 
static int do_define_font(int f, char *cnom, scaled s, int natural_dir)
48
 
{
49
 
 
50
 
    boolean res;                /* was the callback successful? */
51
 
    int callback_id;
52
 
    char *cnam;
53
 
    int r;
54
 
    res = 0;
55
 
 
56
 
    callback_id = callback_defined(define_font_callback);
57
 
    if (callback_id > 0) {
58
 
        cnam = xstrdup(cnom);
59
 
        callback_id = run_and_save_callback(callback_id, "Sdd->", cnam, s, f);
60
 
        free(cnam);
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);
71
 
                delete_font(f);
72
 
                lua_pop(Luas, 1);
73
 
                return r;
74
 
            } else {
75
 
                lua_pop(Luas, 1);
76
 
                delete_font(f);
77
 
                return 0;
78
 
            }
79
 
        }
80
 
    } else if (callback_id == 0) {
81
 
        res = read_tfm_info(f, cnom, s);
82
 
        if (res) {
83
 
            set_hyphen_char(f, int_par(default_hyphen_char_code));
84
 
            set_skew_char(f, int_par(default_skew_char_code));
85
 
        }
86
 
    }
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 */
90
 
        res = 0;
91
 
    }
92
 
    if (res) {
93
 
        if (font_type(f) != virtual_font_type) {        /* implies lua */
94
 
            do_vf(f);
95
 
            set_font_natural_dir(f, natural_dir);
96
 
        }
97
 
        return f;
98
 
    } else {
99
 
        delete_font(f);
100
 
        return 0;
101
 
    }
102
 
 
103
 
}
104
 
 
105
 
int read_font_info(pointer u, str_number nom, scaled s, int natural_dir)
106
 
{
107
 
    int f;
108
 
    char *cnom;
109
 
    char *msg;
110
 
    cnom = makecstring(nom);
111
 
 
112
 
    f = new_font();
113
 
    if ((f = do_define_font(f, cnom, s, natural_dir))) {
114
 
        free(cnom);
115
 
        return f;
116
 
    } else {
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>'.",
122
 
            NULL
123
 
        };
124
 
        if (int_par(suppress_fontnotfound_error_code) == 0) {
125
 
            msg = font_error_message(u, cnom, s);
126
 
            tex_error(msg, help);
127
 
            free(msg);
128
 
        }
129
 
        free(cnom);
130
 
        return 0;
131
 
    }
132
 
}
133
 
 
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
136
 
*/
137
 
 
138
 
int find_font_id(char *nom, scaled s)
139
 
{
140
 
    int f;
141
 
    f = new_font();
142
 
    if ((f = do_define_font(f, nom, s, -1))) {
143
 
        return f;
144
 
    } else {
145
 
        return 0;
146
 
    }
147
 
}