w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

parse_ofm.c
Go to the documentation of this file.
1 /* parse_ofm.h: Checking an existent 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 Copyright (C) 2005, 2006 Roozbeh Pournader
8 
9 Omega is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13 
14 Omega is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Omega; if not, write to the Free Software Foundation, Inc.,
21 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22 
23 */
24 
25 #include "cpascal.h"
26 #include "list_routines.h"
27 #include "header_routines.h"
28 #include "manifests.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 "print_routines.h"
37 #include "out_routines.h"
38 #include "font_routines.h"
39 #include "parse_ofm.h"
40 #include "omfonts.h"
41 #include "manifests.h"
42 
47 
54  /* base addresses for the subfiles */
55 unsigned char_start;
56 unsigned bytes_per_entry;
57 
58 unsigned lf;
59 boolean ofm_on;
60 unsigned start_pos;
61 unsigned family_pos;
62 unsigned ofm_ptr;
63 unsigned ncw;
64 unsigned ncl;
65 unsigned nce;
66 unsigned nco;
67 unsigned npc;
68 
69 static void
70 eval_two_bytes(unsigned *pos) {
71  if (ofm[ofm_ptr]>127)
72  fatal_error_0("One of the subfile sizes (2) is negative");
73  *pos = ofm[ofm_ptr]*0x100 + ofm[ofm_ptr+1];
74  ofm_ptr += 2;
75 }
76 
77 static void
78 eval_four_bytes(unsigned *pos) {
79  if (ofm[ofm_ptr]>127)
80  fatal_error_0("One of the subfile sizes (4) is negative");
81  *pos = ofm[ofm_ptr]*0x1000000 + ofm[ofm_ptr+1]*0x10000 +
82  ofm[ofm_ptr+2]*0x100 + ofm[ofm_ptr+3];
83  ofm_ptr += 4;
84 }
85 
86 static void ofm_organize(void);
87 static void ofm_read_simple(void);
88 static void ofm_read_rest(void);
89 
90 boolean changed = FALSE;
91 
92 void
93 parse_ofm(boolean read_ovf)
94 {
95  ofm_organize();
96  if (read_ovf == TRUE) input_ovf_file();
98  if (read_ovf == TRUE) input_ovf_fonts();
99  ofm_read_rest();
100  if (read_ovf == TRUE) input_ovf_chars();
101  print_characters(read_ovf);
102  if (changed) {
103  left();
104  out("COMMENT THE OFM FILE WAS BAD, SO THE DATA HAS BEEN CHANGED!");
105  right();
106  }
107 }
108 
109 /* parse_ofm ensures that all of the header entries are consistent.
110  The file is assumed to have been read in already, with the
111  contents in the ofm array (length_ofm bytes).
112 */
113 
114 void
116 {
117  unsigned copies,i;
118 
119  ofm_on = false; ofm_level = OFM_NOLEVEL; lf = 0; lh = 0;
120  nco = 0; ncw = 0; npc = 0;
121  bc = 0; ec = 0; nw = 0; nh = 0; nd = 0; ni = 0;
122  nl = 0; nk = 0; ne = 0; np = 0;
123  nki = 0; nwi = 0; nkf = 0; nwf = 0;
124  nkm = 0; nwm = 0;
125  nkr = 0; nwr = 0; nkg = 0; nwg = 0;
126  nkp = 0; nwp = 0; font_dir = 0;
127 
128  if (length_ofm < 8)
129  fatal_error_0("File too short");
130  lf = ofm[0]*256 + ofm[1];
131  if (lf==0) { /* This is not a TFM file, it is an OFM-file */
132  ofm_on = TRUE;
133 
134  /* next line edited by Thomas Esser, based on a patch sent
135  * by Hossein Movahhedian. The old code had " + 1"
136  * instead of "+ OFM_LEVEL0" and caused lots of segfaults */
137  ofm_level = ofm[2]*0x100 + ofm[3] + OFM_LEVEL0;
138  if (ofm[4]>127)
139  fatal_error_0("File length is negative");
140  lf = ofm[4]*0x1000000 + ofm[5]*0x10000 + ofm[6]*0x100 + ofm[7];
141  } else {
142  ofm_on = FALSE;
143  ofm_level = OFM_TFM;
144  }
145  if ((lf*4)!=length_ofm)
146  fatal_error_2("Stated (%d) and actual (%d) file length do not match",
147  lf*4, length_ofm);
148 
149  switch(ofm_level) {
150  case OFM_TFM: { start_pos = 2; check_sum_pos = 24; break; }
151  case OFM_LEVEL0: { start_pos = 8; check_sum_pos = 56; break; }
152  case OFM_LEVEL1: { start_pos = 8; check_sum_pos = 116; break; }
153  default: { fatal_error_1("OFMLEVEL %d not supported", ofm_level-OFM_LEVEL0);
154  break; }
155  }
158  family_pos = scheme_pos+40;
160 
161  ofm_ptr = start_pos;
162 
163  if (ofm_on==FALSE) {
164  eval_two_bytes(&lh);
165  eval_two_bytes(&bc);
166  eval_two_bytes(&ec);
167  eval_two_bytes(&nw);
168  eval_two_bytes(&nh);
169  eval_two_bytes(&nd);
170  eval_two_bytes(&ni);
171  eval_two_bytes(&nl);
172  eval_two_bytes(&nk);
173  eval_two_bytes(&ne);
174  eval_two_bytes(&np);
175  ncw = (ec-bc+1);
176  ncl = nl;
177  nce = ne;
178  header_length = 6;
179  top_char = 255;
180  top_width = 255;
181  top_height = 15;
182  top_depth = 15;
183  top_italic = 63;
184  } else {
190  eval_four_bytes(&nd);
197  top_char = 0x10ffff;
198  top_width = 65535;
199  top_height = 255;
200  top_depth = 255;
201  top_italic = 255;
202  ncl = nl*2;
203  nce = ne*2;
204  if (ofm_level==OFM_LEVEL0) {
205  header_length = 14;
206  ncw = 2*(ec-bc+1);
207  } else {
208  header_length = 29;
212  eval_four_bytes(&nki); /* Kinds of font ivalues */
213  eval_four_bytes(&nwi); /* Words of font ivalues */
214  eval_four_bytes(&nkf); /* Kinds of font fvalues */
215  eval_four_bytes(&nwf); /* Words of font fvalues */
216  eval_four_bytes(&nkm); /* Kinds of font mvalues */
217  eval_four_bytes(&nwm); /* Words of font mvalues */
218  eval_four_bytes(&nkr); /* Kinds of font rules */
219  eval_four_bytes(&nwr); /* Words of font rules */
220  eval_four_bytes(&nkg); /* Kinds of font glues */
221  eval_four_bytes(&nwg); /* Words of font glues */
222  eval_four_bytes(&nkp); /* Kinds of font penalties */
223  eval_four_bytes(&nwp); /* Words of font penalties */
224  }
225  }
226  if (lf != (header_length+lh+ncw+nw+nh+nd+ni+ncl+nk+nce+np+
228  fatal_error_0("Subfile sizes do not add up to the stated total");
229  if (lh < 2)
230  fatal_error_1("The header length is only %d", lh);
231  if ((bc > (ec+1)) || (ec > top_char))
232  fatal_error_2("The character code range %d .. %d is illegal", bc, ec);
233  if ((nw==0) || (nh==0) || (nd==0) || (ni==0))
234  fatal_error_0("Incomplete subfiles for character dimensions");
248  bytes_per_entry = (12 + 2*npc) / 4 * 4;
249  init_planes();
250  no_labels = 0;
251  switch (ofm_level) {
252  case OFM_TFM: {
253  for(i=bc; i<=ec; i++) {
255  char_start = 4*char_base+4*(i-bc);
256  current_character->index_indices[C_WD] =
257  ofm[char_start] & 0xff;
258  current_character->index_indices[C_HT] =
259  (ofm[char_start+1] & 0xf0) >> 4;
260  current_character->index_indices[C_DP] =
261  ofm[char_start+1] & 0xf;
262  current_character->index_indices[C_IC] =
263  (ofm[char_start+2] & 0xfc) >> 2;
264  current_character->tag =
265  ofm[char_start+2] & 0x3;
266  if (current_character->tag == TAG_LIG) no_labels++;
267  current_character->remainder =
268  ofm[char_start+3] & 0xff;
269  }
270  break;
271  }
272  case OFM_LEVEL0: {
273  for(i=bc; i<=ec; i++) {
275  char_start = 4*char_base+8*(i-bc);
276  current_character->index_indices[C_WD] =
277  ((ofm[char_start] & 0xff) << 8) |
278  (ofm[char_start+1] & 0xff);
279  current_character->index_indices[C_HT] =
280  ofm[char_start+2] & 0xff;
281  current_character->index_indices[C_DP] =
282  ofm[char_start+3] & 0xff;
283  current_character->index_indices[C_IC] =
284  ofm[char_start+4] & 0xff;
285  current_character->tag =
286  ofm[char_start+5] & 0x3;
287  if (current_character->tag == TAG_LIG) no_labels++;
288  current_character->remainder =
289  ((ofm[char_start+6] & 0xff) << 8) |
290  (ofm[char_start+7] & 0xff);
291  }
292  break;
293  }
294  case OFM_LEVEL1: {
295  char_start = 4*char_base;
296  i = bc;
297  while (i<=ec) {
299  current_character->index_indices[C_WD] =
300  ((ofm[char_start] & 0xff) << 8) |
301  (ofm[char_start+1] & 0xff);
302  current_character->index_indices[C_HT] =
303  ofm[char_start+2] & 0xff;
304  current_character->index_indices[C_DP] =
305  ofm[char_start+3] & 0xff;
306  current_character->index_indices[C_IC] =
307  ofm[char_start+4] & 0xff;
308  current_character->tag =
309  ofm[char_start+5] & 0x3;
310  if (current_character->tag == TAG_LIG) no_labels++;
311  current_character->remainder =
312  ((ofm[char_start+6] & 0xff) << 8) |
313  (ofm[char_start+7] & 0xff);
314  copies = 256*ofm[char_start+8]+ofm[char_start+9];
315  /* Handle character params */
316  copy_characters(i, copies);
317  i += copies + 1;
319  }
320  if (char_start != (4*(char_base+ncw)))
321  fatal_error_0("Length of char info table does not "
322  "correspond to specification");
323  break;
324  }
325  default: {
326  fatal_error_1("Inappropriate font level (%d)", ofm_level-OFM_LEVEL0);
327  }
328  }
337 }
338 
339 void
341 {
342 
343  if (ofm_on==TRUE) {
346  }
347  header = (char *) ofm+check_sum_pos;
348  retrieve_header();
349  print_family();
350  print_face();
353  out("(COMMENT DESIGNSIZE IS IN POINTS)"); out_ln();
354  out("(COMMENT OTHER SIZES ARE MULTIPLES OF DESIGNSIZE)"); out_ln();
355  print_check_sum();
356  if ((seven_bit == TRUE) || (ofm_level != OFM_TFM))
360 }
361 
362 void
364 {
373 }
int nl
Definition: afm2tfm.c:885
int ne
Definition: afm2tfm.c:885
int nk
Definition: afm2tfm.c:885
int nd
Definition: afm2tfm.c:885
int ni
Definition: afm2tfm.c:885
int nh
Definition: afm2tfm.c:885
void copy_characters(unsigned c, unsigned copies)
void print_extens(void)
void init_character(unsigned c, char_entry *ready_made)
Definition: char_routines.c:98
char_entry * current_character
Definition: char_routines.c:78
void adjust_labels(boolean play_with_starts)
unsigned no_labels
Definition: char_routines.c:84
void init_planes(void)
Definition: char_routines.c:91
void print_characters(boolean read_ovf)
void print_labels(void)
void retrieve_exten_table(unsigned char *table)
@ FALSE
Definition: dd.h:101
@ TRUE
Definition: dd.h:102
void retrieve_dimen_tables(void)
void print_dimen_tables(void)
static int np
Definition: bifont.c:64
void fatal_error_2(const_string fmt, int item, int item2)
void fatal_error_0(const_string fmt)
void fatal_error_1(const_string fmt, int item)
unsigned nwf
unsigned nki
unsigned nkm
unsigned nwm
unsigned nwg
unsigned nkf
unsigned nwr
unsigned nkp
unsigned nkr
unsigned nwp
unsigned nwi
unsigned nkg
void input_ovf_fonts(void)
void input_ovf_chars(void)
void input_ovf_file(void)
#define lh
Definition: gsftopk.c:500
#define bc
Definition: gsftopk.c:501
#define ec
Definition: gsftopk.c:502
#define nw
Definition: gsftopk.c:503
FILE * out
Definition: hbf2gf.c:286
void retrieve_header(void)
boolean seven_bit
unsigned font_dir
unsigned ofm_level
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
@ right
Definition: annotate.c:15
void retrieve_ligkern_table(unsigned char *ofm_lig_table, unsigned char *ofm_kern_table)
void print_ligkern_table(void)
const int * pos
Definition: combiners.h:905
#define OFM_LEVEL0
Definition: manifests.h:283
#define OFM_TFM
Definition: manifests.h:282
#define C_DP
Definition: manifests.h:30
#define TAG_LIG
Definition: manifests.h:262
#define OFM_LEVEL1
Definition: manifests.h:284
#define C_HT
Definition: manifests.h:29
#define C_WD
Definition: manifests.h:28
#define C_IC
Definition: manifests.h:31
#define OFM_NOLEVEL
Definition: manifests.h:281
unsigned length_ofm
Definition: omfonts.c:74
unsigned char * ofm
Definition: omfonts.c:71
int verbose_option
Definition: omfonts.c:53
void out_ln(void)
Definition: out_routines.c:260
void print_parameters(void)
void retrieve_parameters(unsigned char *table)
unsigned ivalues_start
Definition: parse_ofm.c:48
unsigned top_italic
Definition: parse_ofm.c:43
unsigned glues_base
Definition: parse_ofm.c:51
unsigned rules_base
Definition: parse_ofm.c:51
static void ofm_read_rest(void)
Definition: parse_ofm.c:363
unsigned top_char
Definition: parse_ofm.c:43
unsigned penalties_base
Definition: parse_ofm.c:51
static void eval_two_bytes(unsigned *pos)
Definition: parse_ofm.c:70
unsigned depth_base
Definition: parse_ofm.c:52
unsigned fvalues_base
Definition: parse_ofm.c:50
unsigned nce
Definition: parse_ofm.c:65
unsigned param_base
Definition: parse_ofm.c:53
unsigned penalties_start
Definition: parse_ofm.c:49
unsigned check_sum_pos
Definition: parse_ofm.c:44
unsigned mvalues_start
Definition: parse_ofm.c:48
unsigned family_pos
Definition: parse_ofm.c:61
unsigned random_word_pos
Definition: parse_ofm.c:46
unsigned top_height
Definition: parse_ofm.c:43
void parse_ofm(boolean read_ovf)
Definition: parse_ofm.c:93
unsigned design_size_pos
Definition: parse_ofm.c:44
unsigned ncl
Definition: parse_ofm.c:64
unsigned start_pos
Definition: parse_ofm.c:60
unsigned bytes_per_entry
Definition: parse_ofm.c:56
unsigned fvalues_start
Definition: parse_ofm.c:48
boolean changed
Definition: parse_ofm.c:90
unsigned exten_base
Definition: parse_ofm.c:53
unsigned mvalues_base
Definition: parse_ofm.c:50
unsigned nco
Definition: parse_ofm.c:66
boolean ofm_on
Definition: parse_ofm.c:59
unsigned ivalues_base
Definition: parse_ofm.c:50
unsigned npc
Definition: parse_ofm.c:67
unsigned lf
Definition: parse_ofm.c:58
unsigned char_start
Definition: parse_ofm.c:55
unsigned glues_start
Definition: parse_ofm.c:49
unsigned top_width
Definition: parse_ofm.c:43
static void ofm_read_simple(void)
Definition: parse_ofm.c:340
unsigned ncw
Definition: parse_ofm.c:63
unsigned start_ptr
Definition: parse_ofm.c:44
unsigned kern_base
Definition: parse_ofm.c:53
unsigned seven_bit_flag_pos
Definition: parse_ofm.c:45
unsigned lig_kern_base
Definition: parse_ofm.c:53
unsigned width_base
Definition: parse_ofm.c:52
unsigned italic_base
Definition: parse_ofm.c:52
unsigned top_depth
Definition: parse_ofm.c:43
unsigned scheme_pos
Definition: parse_ofm.c:44
unsigned header_length
Definition: parse_ofm.c:46
static void ofm_organize(void)
Definition: parse_ofm.c:115
static void eval_four_bytes(unsigned *pos)
Definition: parse_ofm.c:78
unsigned height_base
Definition: parse_ofm.c:52
unsigned ofm_ptr
Definition: parse_ofm.c:62
unsigned rules_start
Definition: parse_ofm.c:49
unsigned char_base
Definition: parse_ofm.c:52
void print_face(void)
void print_font_dir(unsigned val)
void print_seven_bit_safe_flag(void)
void print_ofm_level(unsigned val)
void print_coding_scheme(void)
void print_check_sum(void)
void print_family(void)
void print_design_size(void)
lft_cell * left
Definition: routines.h:73