summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/tex/texdeffont.w
blob: eab44838beb5e73e2ae8a58a3115f1938893628a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
% texdeffont.w

% Copyright 2008-2010 Taco Hoekwater <taco@@luatex.org>

% This file is part of LuaTeX.

% LuaTeX is free software; you can redistribute it and/or modify it under
% the terms of the GNU General Public License as published by the Free
% Software Foundation; either version 2 of the License, or (at your
% option) any later version.

% LuaTeX is distributed in the hope that it will be useful, but WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
% FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
% License for more details.

% You should have received a copy of the GNU General Public License along
% with LuaTeX; if not, see <http://www.gnu.org/licenses/>. 

@ @c
#include "ptexlib.h"

static const char _svn_version[] =
    "$Id: texdeffont.w 3615 2010-04-13 21:59:59Z oneiros $ $URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.66.0/source/texk/web2c/luatexdir/tex/texdeffont.w $";



@ When the user defines \.{\\font\\f}, say, \TeX\ assigns an internal number
to the user's font~\.{\\f}. Adding this number to |font_id_base| gives the
|eqtb| location of a ``frozen'' control sequence that will always select
the font.

@c
int font_bytes;

void set_cur_font(internal_font_number f)
{
    int a = 0;                  /* never global */
    define(cur_font_loc, data_cmd, f);
}

@ @c
static char *scaled_to_string(scaled s)
{                               /* prints scaled real, rounded to five digits */
    static char result[16];
    int n, k;
    scaled delta;               /* amount of allowable inaccuracy */
    k = 0;
    if (s < 0) {
        result[k++] = '-';
        s = -s;                 /* print the sign, if negative */
    }
    {
        int l = 0;
        char dig[8] = { 0 };
        n = s / unity;
        /* process the integer part */
        do {
            dig[l++] = (char) (n % 10);
            n = n / 10;;
        } while (n > 0);
        while (l > 0) {
            result[k++] = (char) (dig[--l] + '0');
        }
    }
    result[k++] = '.';
    s = 10 * (s % unity) + 5;
    delta = 10;
    do {
        if (delta > unity)
            s = s + 0100000 - 050000;   /* round the last digit */
        result[k++] = (char) ('0' + (s / unity));
        s = 10 * (s % unity);
        delta = delta * 10;
    } while (s > delta);

    result[k] = 0;
    return (char *) result;
}

@ @c
void tex_def_font(small_number a)
{
    pointer u;                  /* user's font identifier */
    internal_font_number f;     /* runs through existing fonts */
    str_number t;               /* name for the frozen font identifier */
    int old_setting;            /* holds |selector| setting */
    int offset = 0;
    scaled s = -1000;           /* stated ``at'' size, or negative of scaled magnification */
    int natural_dir = -1;       /* the natural direction of the font */
    char *fn;
    if (job_name == 0)
        open_log_file();        /* avoid confusing \.{texput} with the font name */
    get_r_token();
    u = cur_cs;
    if (u >= null_cs)
        t = cs_text(u);
    else
        t = maketexstring("FONT");
    if (a >= 4) {
        geq_define(u, set_font_cmd, null_font);
    } else {
        eq_define(u, set_font_cmd, null_font);
    }
    scan_optional_equals();
    /* Get the next non-blank non-call token; */
    do {
        get_x_token();
    } while ((cur_cmd == spacer_cmd) || (cur_cmd == relax_cmd));

    if (cur_cmd != left_brace_cmd) {
        back_input();
        scan_file_name();
        if (cur_area != get_nullstr() || cur_ext != get_nullstr()) {
            /* Have to do some rescue-ing here, fonts only have a name,
               no area nor extension */
            old_setting = selector;
            selector = new_string;
            if (cur_area != get_nullstr()) {
                print(cur_area);
            }
            if (cur_name != get_nullstr()) {
                print(cur_name);
            }
            if (cur_ext != get_nullstr()) {
                print(cur_ext);
            }
            selector = old_setting;
            cur_name = make_string();
            cur_ext = get_nullstr();
            cur_area = get_nullstr();
        }
    } else {
        back_input();
        (void) scan_toks(false, true);
        old_setting = selector;
        selector = new_string;
        token_show(def_ref);
        selector = old_setting;
        flush_list(def_ref);
        /* |str_room(1)|; *//* what did that do ? */
        cur_name = make_string();
        cur_ext = get_nullstr();
        cur_area = get_nullstr();
    }
    /* Scan the font size specification; */
    name_in_progress = true;    /* this keeps |cur_name| from being changed */
    if (scan_keyword("at")) {
        /* Put the positive `at' size into |s| */
        scan_normal_dimen();
        s = cur_val;
        if ((s <= 0) || (s >= 01000000000)) {
            char err[256];
            const char *errhelp[] =
                { "I can only handle fonts at positive sizes that are",
                "less than 2048pt, so I've changed what you said to 10pt.",
                NULL
            };
            snprintf(err, 255, "Improper `at' size (%spt), replaced by 10pt",
                     scaled_to_string(s));
            tex_error(err, errhelp);
            s = 10 * unity;
        }
    } else if (scan_keyword("scaled")) {
        scan_int();
        s = -cur_val;
        if ((cur_val <= 0) || (cur_val > 32768)) {
            char err[256];
            const char *errhelp[] =
                { "The magnification ratio must be between 1 and 32768.",
                NULL
            };
            snprintf(err, 255,
                     "Illegal magnification has been changed to 1000 (%d)",
                     (int) cur_val);
            tex_error(err, errhelp);
            s = -1000;
        }
    }
    if (scan_keyword("offset")) {
        scan_int();
        offset = cur_val;
        if (cur_val < 0) {
            char err[256];
            const char *errhelp[] =
                { "The offset must be bigger than 0.", NULL };
            snprintf(err, 255, "Illegal offset has been changed to 0 (%d)",
                     (int) cur_val);
            tex_error(err, errhelp);
            offset = 0;
        }
    }
    if (scan_keyword("naturaldir")) {
        scan_direction();
        natural_dir = cur_val;
    }
    name_in_progress = false;
    fn = makecstring(cur_name);
    f = read_font_info(u, fn, s, natural_dir);
    xfree(fn);
/*  
    The new code seems not to work.
    if (a >= 4) {
        geq_define(u, set_font_cmd, null_font);
    } else {
        eq_define(u, set_font_cmd, null_font);
    }
    Therefore the old code is used here.
*/
    equiv(u) = f;

    eqtb[font_id_base + f] = eqtb[u];
    cs_text(font_id_base + f) = t;
}