3
Copyright 2009 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/>. */
20
/* $Id: dvigen.h 3261 2009-12-18 11:38:21Z taco $ */
25
extern int total_pages;
30
extern int dead_cycles;
31
extern boolean doing_leaders;
33
extern int oval, ocmd;
38
typedef int dvi_index; /* an index into the output buffer */
40
extern int dvi_buf_size;
41
extern eight_bits *dvi_buf; /* 0 is unused */
42
extern dvi_index half_buf;
43
extern dvi_index dvi_limit;
44
extern dvi_index dvi_ptr;
45
extern int dvi_offset;
49
To put a byte in the buffer without paying the cost of invoking a procedure
50
each time, we use the macro |dvi_out|.
53
# define dvi_out(A) do { \
54
dvi_buf[dvi_ptr++]=A; \
55
if (dvi_ptr==dvi_limit) dvi_swap(); \
58
extern void dvi_swap(void);
59
extern void dvi_four(int x);
60
extern void dvi_push(void);
61
extern void dvi_pop(int l);
62
extern void out_cmd(void);
63
extern void dvi_font_def(internal_font_number f);
65
# define dvi_set(A,B) do { \
66
oval=A; ocmd=set1; out_cmd(); dvi.h += (B); \
69
# define dvi_put(A) do { \
70
oval=A; ocmd=put1; out_cmd(); \
73
# define location(A) varmem[(A)+1].cint
75
extern halfword down_ptr, right_ptr; /* heads of the down and right stacks */
78
The |vinfo| fields in the entries of the down stack or the right stack
79
have six possible settings: |y_here| or |z_here| mean that the \.{DVI}
80
command refers to |y| or |z|, respectively (or to |w| or |x|, in the
81
case of horizontal motion); |yz_OK| means that the \.{DVI} command is
82
\\{down} (or \\{right}) but can be changed to either |y| or |z| (or
83
to either |w| or |x|); |y_OK| means that it is \\{down} and can be changed
84
to |y| but not |z|; |z_OK| is similar; and |d_fixed| means it must stay
87
The four settings |yz_OK|, |y_OK|, |z_OK|, |d_fixed| would not need to
88
be distinguished from each other if we were simply solving the
89
digit-subscripting problem mentioned above. But in \TeX's case there is
90
a complication because of the nested structure of |push| and |pop|
91
commands. Suppose we add parentheses to the digit-subscripting problem,
92
redefining hits so that $\delta_y\ldots \delta_y$ is a hit if all $y$'s between
93
the $\delta$'s are enclosed in properly nested parentheses, and if the
94
parenthesis level of the right-hand $\delta_y$ is deeper than or equal to
95
that of the left-hand one. Thus, `(' and `)' correspond to `|push|'
96
and `|pop|'. Now if we want to assign a subscript to the final 1 in the
98
$$2_y\,7_d\,1_d\,(\,8_z\,2_y\,8_z\,)\,1$$
99
we cannot change the previous $1_d$ to $1_y$, since that would invalidate
100
the $2_y\ldots2_y$ hit. But we can change it to $1_z$, scoring a hit
101
since the intervening $8_z$'s are enclosed in parentheses.
105
y_here = 1, /* |vinfo| when the movement entry points to a |y| command */
106
z_here = 2, /* |vinfo| when the movement entry points to a |z| command */
107
yz_OK = 3, /* |vinfo| corresponding to an unconstrained \\{down} command */
108
y_OK = 4, /* |vinfo| corresponding to a \\{down} that can't become a |z| */
109
z_OK = 5, /* |vinfo| corresponding to a \\{down} that can't become a |y| */
110
d_fixed = 6, /* |vinfo| corresponding to a \\{down} that can't change */
113
/* As we search through the stack, we are in one of three states,
114
|y_seen|, |z_seen|, or |none_seen|, depending on whether we have
115
encountered |y_here| or |z_here| nodes. These states are encoded as
116
multiples of 6, so that they can be added to the |info| fields for quick
119
# define none_seen 0 /* no |y_here| or |z_here| nodes have been encountered yet */
120
# define y_seen 6 /* we have seen |y_here| but not |z_here| */
121
# define z_seen 12 /* we have seen |z_here| but not |y_here| */
123
extern void movement(scaled w, eight_bits o);
124
extern void prune_movements(int l);
127
The actual distances by which we want to move might be computed as the
128
sum of several separate movements. For example, there might be several
129
glue nodes in succession, or we might want to move right by the width of
130
some box plus some amount of glue. More importantly, the baselineskip
131
distances are computed in terms of glue together with the depth and
132
height of adjacent boxes, and we want the \.{DVI} file to lump these
133
three quantities together into a single motion.
135
Therefore, \TeX\ maintains two pairs of global variables: |dvi.h| and |dvi.v|
136
are the |h| and |v| coordinates corresponding to the commands actually
137
output to the \.{DVI} file, while |cur.h| and |cur.v| are the coordinates
138
corresponding to the current state of the output routines. Coordinate
139
changes will accumulate in |cur.h| and |cur.v| without being reflected
140
in the output, until such a change becomes necessary or desirable; we
141
can call the |movement| procedure whenever we want to make |dvi.h=pos.h|
144
The current font reflected in the \.{DVI} output is called |dvi_f|;
145
there is no need for a `\\{cur\_f}' variable.
147
The depth of nesting of |hlist_out| and |vlist_out| is called |cur_s|;
148
this is essentially the depth of |push| commands in the \.{DVI} output.
151
# define synch_h(p) do { \
152
if (p.h != dvi.h) { \
153
movement(p.h - dvi.h, right1); \
158
# define synch_v(p) do { \
159
if (p.v != dvi.v) { \
160
movement(dvi.v - p.v, down1); \
165
# define synch_dvi_with_pos(p) do {synch_h(p); synch_v(p); } while (0)
167
# define billion 1000000000.0
169
# define vet_glue(A) do { glue_temp=A; \
170
if (glue_temp>billion) \
172
else if (glue_temp<-billion) \
173
glue_temp=-billion; \
176
extern scaled_whd rule;
177
extern scaledpos dvi;
178
extern scaledpos cur_page_size; /* width and height of page being shipped */
180
extern void expand_macros_in_tokenlist(halfword p);
181
extern void write_out(halfword p);
182
extern void dvi_special(PDF pdf, halfword p);
184
extern void ensure_dvi_header_written(PDF pdf);
185
extern void finish_dvi_file(PDF pdf, int version, int revision);
187
extern void dvi_place_glyph(PDF pdf, internal_font_number f, int c);
188
extern void dvi_place_rule(PDF pdf, halfword q, scaledpos size);
190
extern void dvi_begin_page(PDF pdf);
191
extern void dvi_end_page(PDF pdf);