Debian Codegraph @

texk/web2c/omegafonts/out_ofm.c

raw
1 /* out_ofm.c: Outputting to an OFM file.
2
3 This file is part of Omega,
4 which is based on the web2c distribution of TeX,
5
6 Copyright (c) 1994--2001 John Plaice and Yannis Haralambous
7
8 Omega is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 Omega is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Omega; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21
22 */
23
24 #include "cpascal.h"
25 #include "list_routines.h"
26 #include "header_routines.h"
27 #include "manifests.h"
28 #include "omfonts.h"
29 #include "char_routines.h"
30 #include "ligkern_routines.h"
31 #include "out_ofm.h"
32 #include "extra_routines.h"
33 #include "param_routines.h"
34 #include "dimen_routines.h"
35 #include "error_routines.h"
36 #include "parse_ofm.h"
37
38 static void compute_ofm_subsizes(void);
39 static void output_ofm_subsizes(void);
40
41 void
42 output_ofm_file(void)
43 {
44 check_and_correct();
45 if (omit_ofm) return;
46 compute_ofm_extra_stuff();
47 compute_ofm_character_info();
48 compute_ofm_subsizes();
49 output_ofm_subsizes();
50 output_ofm_header();
51 output_ofm_extra_stuff();
52 output_ofm_character_info();
53 output_ofm_dimension();
54 output_ofm_ligkern();
55 output_ofm_extensible();
56 output_ofm_parameter();
57 }
58
59 static void
60 compute_ofm_subsizes(void)
61 {
62 switch(ofm_level) {
63 case OFM_TFM: {
64 lh = header_max + 1;
65 nw++; nh++; nd++; ni++;
66 compute_ligkern_offset();
67 lf = 6+lh+(ec-bc+1)+nw+nh+nd+ni+nl+lk_offset+nk+ne+np;
68 break;
69 }
70 case OFM_LEVEL0: {
71 lh = header_max + 1;
72 nw++; nh++; nd++; ni++;
73 compute_ligkern_offset();
74 lf = 14+lh+2*(ec-bc+1)+nw+nh+nd+ni+2*(nl+lk_offset)+nk+2*ne+np;
75 break;
76 }
77 case OFM_LEVEL1: {
78 lh = header_max + 1;
79 nw++; nh++; nd++; ni++;
80 compute_ligkern_offset();
81 words_per_entry = (12 + 2*npc) / 4;
82 ncw = num_char_info * words_per_entry;
83 lf = 29+lh+ncw+nw+nh+nd+ni+2*(nl+lk_offset)+nk+2*ne+np+
84 nki+nwi+nkf+nwf+nkm+nwm+nkr+nwr+nkg+nwg+nkp+nwp;
85 nco = 29+lh+nki+nwi+nkf+nwf+nkm+nwm+nkr+nwr+nkg+nwg+nkp+nwp;
86 break;
87 }
88 default: { internal_error_0("output_ofm_subfiles"); }
89 }
90 }
91
92 static void
93 output_ofm_subsizes(void)
94 {
95 switch(ofm_level) {
96 case OFM_TFM: {
97 out_ofm_2(lf); out_ofm_2(lh); out_ofm_2(bc); out_ofm_2(ec);
98 out_ofm_2(nw); out_ofm_2(nh); out_ofm_2(nd); out_ofm_2(ni);
99 out_ofm_2(nl+lk_offset); out_ofm_2(nk);
100 out_ofm_2(ne); out_ofm_2(np);
101 break;
102 }
103 case OFM_LEVEL0: {
104 out_ofm_4(0);
105 out_ofm_4(lf); out_ofm_4(lh); out_ofm_4(bc); out_ofm_4(ec);
106 out_ofm_4(nw); out_ofm_4(nh); out_ofm_4(nd); out_ofm_4(ni);
107 out_ofm_4(nl+lk_offset); out_ofm_4(nk);
108 out_ofm_4(ne); out_ofm_4(np); out_ofm_4(font_dir);
109 break;
110 }
111 case OFM_LEVEL1: {
112 out_ofm_4(1);
113 out_ofm_4(lf); out_ofm_4(lh); out_ofm_4(bc); out_ofm_4(ec);
114 out_ofm_4(nw); out_ofm_4(nh); out_ofm_4(nd); out_ofm_4(ni);
115 out_ofm_4(nl+lk_offset); out_ofm_4(nk);
116 out_ofm_4(ne); out_ofm_4(np); out_ofm_4(font_dir);
117 out_ofm_4(nco); out_ofm_4(ncw); out_ofm_4(npc);
118 out_ofm_4(nki); out_ofm_4(nwi);
119 out_ofm_4(nkf); out_ofm_4(nwf);
120 out_ofm_4(nkm); out_ofm_4(nwm);
121 out_ofm_4(nkr); out_ofm_4(nwr);
122 out_ofm_4(nkg); out_ofm_4(nwg);
123 out_ofm_4(nkp); out_ofm_4(nwp);
124 break;
125 }
126 default: { internal_error_0("output_ofm_subfiles"); }
127 }
128 }
129
130 unsigned file_ofm_count = 0;
131
132 void
133 out_ofm(unsigned i)
134 {
135 fputc(i,file_ofm);
136 file_ofm_count++;
137 }
138
139 void
140 out_ofm_2(unsigned i)
141 {
142
143 fputc((i>>8)&0xff, file_ofm);
144 fputc(i&0xff, file_ofm);
145 file_ofm_count += 2;
146 }
147
148 void
149 out_ofm_4(unsigned i)
150 {
151 fputc((i>>24)&0xff, file_ofm);
152 fputc((i>>16)&0xff, file_ofm);
153 fputc((i>>8)&0xff, file_ofm);
154 fputc(i&0xff, file_ofm);
155 file_ofm_count += 4;
156 }
157
158 void
159 out_ofm_char(unsigned i)
160 {
161 if (ofm_level == OFM_NOLEVEL) {
162 internal_error_1("out_ofm_char.1 (ofm_level=%d)", ofm_level);
163 }
164 if (ofm_level == OFM_TFM) {
165 if (i>=0x100) internal_error_1("out_ofm_char.2 (i=%x)", i);
166 out_ofm(i);
167 } else {
168 if (i>=0x10000) internal_error_1("out_ofm_char.3 (i=%x)", i);
169 out_ofm_2(i);
170 }
171 }
172
173 #define dabs(x) ((x)>=0?(x):-(x))
174
175 void
176 out_ofm_scaled(fix fval)
177 {
178 if (dabs((double)fval/(double)design_units) >= 16.0) {
179 warning_2("The relative dimension %d is too large.\n"
180 "Must be less than 16*designsize = %d designunits",
181 fval/0x100000, design_units/0x10000);
182 fval = 0;
183 }
184 if (design_units != UNITY) {
185 fval = zround(((double)fval/(double)design_units) * 1048576.0);
186 }
187 if (fval < 0) {
188 out_ofm(255); fval = fval + 0x1000000;
189 if (fval <= 0) fval = 1;
190 } else {
191 out_ofm(0);
192 if (fval >= 0x1000000) fval = 0xffffff;
193 }
194 out_ofm((fval >> 16) & 0xff);
195 out_ofm((fval >> 8) & 0xff);
196 out_ofm(fval & 0xff);
197 }