~ubuntu-branches/ubuntu/natty/luatex/natty

« 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: 2009-12-25 09:47:05 UTC
  • mfrom: (1.1.9 upstream) (4.2.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091225094705-y33rpflo8t4u9nag
Tags: 0.50.0-1
* new upstream release
* disable fix-hurd-ftbfs patch, included upstream
* disable upstram-fixes, included upstream
* disable ubuntu_libpoppler-0.11, not needed anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include "ptexlib.h"
21
21
 
22
 
#include "luatex-api.h"
 
22
#include "lua/luatex-api.h"
23
23
 
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 $";
26
 
 
27
 
#define TIMERS 0
28
 
 
29
 
#if TIMERS
30
 
#  include <sys/time.h>
31
 
#endif
32
 
 
 
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 $";
33
26
 
34
27
/* a bit more interfacing is needed for proper error reporting */
35
28
 
36
29
static char *font_error_message(pointer u, char *nom, scaled s)
37
30
{
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";
41
34
    if (s >= 0) {
42
35
        snprintf(str, 255, "Font \\%s=%s at %gpt not loadable: %s", c, nom,
47
40
    } else {
48
41
        snprintf(str, 255, "Font \\%s=%s not loadable: %s", c, nom, extra);
49
42
    }
 
43
    free(c);
50
44
    return str;
51
45
}
52
46
 
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)
54
48
{
55
49
 
56
50
    boolean res;                /* was the callback successful? */
57
 
    integer callback_id;
 
51
    int callback_id;
58
52
    char *cnam;
59
 
#if TIMERS
60
 
    struct timeval tva;
61
 
    struct timeval tvb;
62
 
    double tvdiff;
63
 
#endif
64
53
    int r;
65
54
    res = 0;
66
55
 
67
56
    callback_id = callback_defined(define_font_callback);
68
57
    if (callback_id > 0) {
69
58
        cnam = xstrdup(cnom);
70
 
#if TIMERS
71
 
        gettimeofday(&tva, NULL);
72
 
#endif
73
59
        callback_id = run_and_save_callback(callback_id, "Sdd->", cnam, s, f);
74
 
#if TIMERS
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;
80
 
        tvdiff /= 1000000;
81
 
        fprintf(stdout, "\ncallback('define_font',%s,%i): %f seconds\n", cnam,
82
 
                f, tvdiff);
83
 
#endif
84
60
        free(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)) {
89
 
#if TIMERS
90
 
                gettimeofday(&tva, NULL);
91
 
#endif
92
65
                res = font_from_lua(Luas, f);
93
66
                destroy_saved_callback(callback_id);
94
 
#if TIMERS
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;
100
 
                tvdiff /= 1000000;
101
 
                fprintf(stdout, "font_from_lua(%s,%i): %f seconds\n",
102
 
                        font_name(f), f, tvdiff);
103
 
#endif
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);
119
82
        if (res) {
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));
122
85
        }
123
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
    }
124
92
    if (res) {
125
93
        if (font_type(f) != virtual_font_type) {        /* implies lua */
126
94
            do_vf(f);
134
102
 
135
103
}
136
104
 
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)
138
106
{
139
 
    integer f;
 
107
    int f;
140
108
    char *cnom;
141
109
    char *msg;
142
 
    cnom = xstrdup(makecstring(nom));
 
110
    cnom = makecstring(nom);
143
111
 
144
112
    f = new_font();
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>'.",
154
122
            NULL
155
123
        };
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);
159
127
            free(msg);
169
137
 
170
138
int find_font_id(char *nom, scaled s)
171
139
{
172
 
    integer f;
 
140
    int f;
173
141
    f = new_font();
174
142
    if ((f = do_define_font(f, nom, s, -1))) {
175
143
        return f;