Back to index

tetex-bin  3.0
out_ofm.c
Go to the documentation of this file.
00001 /* out_ofm.c: Outputting to an OFM file.
00002 
00003 This file is part of Omega,
00004 which is based on the web2c distribution of TeX,
00005 
00006 Copyright (c) 1994--2001 John Plaice and Yannis Haralambous
00007 
00008 Omega is free software; you can redistribute it and/or modify
00009 it under the terms of the GNU General Public License as published by
00010 the Free Software Foundation; either version 2 of the License, or
00011 (at your option) any later version.
00012 
00013 Omega is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Omega; if not, write to the Free Software Foundation, Inc.,
00020 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00021 
00022 */
00023 
00024 #include "cpascal.h"
00025 #include "list_routines.h"
00026 #include "header_routines.h"
00027 #include "manifests.h"
00028 #include "char_routines.h"
00029 #include "ligkern_routines.h"
00030 #include "out_ofm.h"
00031 #include "extra_routines.h"
00032 #include "param_routines.h"
00033 #include "dimen_routines.h"
00034 #include "error_routines.h"
00035 #include "parse_ofm.h"
00036 
00037 void
00038 output_ofm_file(void)
00039 {
00040     check_and_correct();
00041     compute_ofm_character_info();
00042     compute_ofm_subsizes();
00043     output_ofm_subsizes();
00044     output_ofm_header();
00045     compute_ofm_extra_stuff();
00046     output_ofm_extra_stuff();
00047     output_ofm_character_info();
00048     output_ofm_dimension();
00049     output_ofm_ligkern();
00050     output_ofm_extensible();
00051     output_ofm_parameter();
00052 }
00053 
00054 extern unsigned header_ptr;
00055 extern unsigned mw,mh,md,mi;
00056 
00057 void
00058 compute_ofm_subsizes(void)
00059 {
00060     switch(ofm_level) {
00061         case OFM_TFM: {
00062             lh = header_max + 1;
00063             if (bc > ec) bc = 1;
00064             if (ec>255)
00065                 fatal_error_1(
00066                    "Char (%x) too big for TFM (max ff); use OFM file",ec);
00067             nw++; nh++; nd++; ni++;
00068             compute_ligkern_offset();
00069             lf = 6+lh+(ec-bc+1)+nw+nh+nd+ni+nl+lk_offset+nk+ne+np;
00070             /*lf = 6+lh+(ec-bc+1)+nw+nh+nd+ni+nl-1+lk_offset+nk+ne+np;*/
00071             break;
00072         }
00073         case OFM_LEVEL0: {
00074             lh = header_max + 1;
00075             if (ec>65535)
00076                 fatal_error_1(
00077                 "Char (%x) too big for OFM level-0 (max ffff); use level-2",
00078                 ec);
00079             if (bc > ec) bc = 1;
00080             nw++; nh++; nd++; ni++;
00081             compute_ligkern_offset();
00082             lf = 14+lh+2*(ec-bc+1)+nw+nh+nd+ni+2*(nl+lk_offset)+nk+2*ne+np;
00083             break;
00084         }
00085         case OFM_LEVEL1: {
00086             lh = header_max + 1;
00087             if (ec>65535)
00088                 fatal_error_1(
00089                 "Char (%x) too big for OFM level-1 (max ffff); use level-2",
00090                 ec);
00091             if (bc > ec) bc = 1;
00092             nw++; nh++; nd++; ni++;
00093             compute_ligkern_offset();
00094             lf = 29+lh+ncw+nw+nh+nd+ni+2*(nl+lk_offset)+nk+2*ne+np+
00095                  nki+nwi+nkf+nwf+nkm+nwm+nkr+nwr+nkg+nwg+nkp+nwp;
00096             nco = 29+lh+nki+nwi+nkf+nwf+nkm+nwm+nkr+nwr+nkg+nwg+nkp+nwp;
00097             break;
00098         }
00099         default: { internal_error_0("output_ofm_subfiles"); }
00100     }   
00101 }
00102 
00103 void
00104 output_ofm_subsizes(void)
00105 {
00106     switch(ofm_level) {
00107         case OFM_TFM: {
00108             out_ofm_2(lf); out_ofm_2(lh); out_ofm_2(bc); out_ofm_2(ec);
00109             out_ofm_2(nw); out_ofm_2(nh); out_ofm_2(nd); out_ofm_2(ni);
00110             out_ofm_2(nl+lk_offset); out_ofm_2(nk);
00111             out_ofm_2(ne); out_ofm_2(np);
00112             break;
00113         }
00114         case OFM_LEVEL0: {
00115             out_ofm_4(0);
00116             out_ofm_4(lf); out_ofm_4(lh); out_ofm_4(bc); out_ofm_4(ec);
00117             out_ofm_4(nw); out_ofm_4(nh); out_ofm_4(nd); out_ofm_4(ni);
00118             out_ofm_4(nl+lk_offset); out_ofm_4(nk);
00119             out_ofm_4(ne); out_ofm_4(np); out_ofm_4(font_dir);
00120             break;
00121         }
00122         case OFM_LEVEL1: {
00123             out_ofm_4(1);
00124             out_ofm_4(lf); out_ofm_4(lh); out_ofm_4(bc); out_ofm_4(ec);
00125             out_ofm_4(nw); out_ofm_4(nh); out_ofm_4(nd); out_ofm_4(ni);
00126             out_ofm_4(nl+lk_offset); out_ofm_4(nk);
00127             out_ofm_4(ne); out_ofm_4(np); out_ofm_4(font_dir);
00128             out_ofm_4(nco); out_ofm_4(ncw); out_ofm_4(npc);
00129             out_ofm_4(nki); out_ofm_4(nwi);
00130             out_ofm_4(nkf); out_ofm_4(nwf);
00131             out_ofm_4(nkm); out_ofm_4(nwm);
00132             out_ofm_4(nkr); out_ofm_4(nwr);
00133             out_ofm_4(nkg); out_ofm_4(nwg);
00134             out_ofm_4(nkp); out_ofm_4(nwp);
00135             break;
00136         }
00137         default: { internal_error_0("output_ofm_subfiles"); }
00138     }
00139 }
00140 
00141 extern FILE *file_ofm;
00142 unsigned file_ofm_count = 0;
00143 
00144 void
00145 out_ofm(unsigned i)
00146 {
00147     fputc(i,file_ofm);
00148     file_ofm_count++;
00149 }
00150 
00151 void
00152 out_ofm_2(unsigned i)
00153 {
00154  
00155     fputc((i>>8)&0xff,  file_ofm);
00156     fputc(i&0xff,       file_ofm);
00157     file_ofm_count += 2;
00158 }
00159 
00160 void
00161 out_ofm_4(unsigned i)
00162 {
00163     fputc((i>>24)&0xff, file_ofm);
00164     fputc((i>>16)&0xff, file_ofm);
00165     fputc((i>>8)&0xff,  file_ofm);
00166     fputc(i&0xff,       file_ofm);
00167     file_ofm_count += 4;
00168 }
00169 
00170 void
00171 out_ofm_char(unsigned i)
00172 {
00173     if (ofm_level == OFM_NOLEVEL) {
00174         internal_error_1("out_ofm_char.1 (ofm_level=%d)", ofm_level);
00175     }
00176     if (ofm_level == OFM_TFM) {
00177         if (i>=0x100) internal_error_1("out_ofm_char.2 (i=%x)", i);
00178         out_ofm(i);
00179     } else {
00180         if (i>=0x10000) internal_error_1("out_ofm_char.3 (i=%x)", i);
00181         out_ofm_2(i);
00182     }
00183 }
00184 
00185 #define dabs(x) ((x)>=0?(x):-(x))
00186 
00187 void
00188 out_ofm_scaled(fix fval)
00189 {
00190     if (dabs((double)fval/(double)design_units) >= 16.0) {
00191         warning_2("The relative dimension %d is too large.\n"
00192                   "Must be less than 16*designsize = %d designunits",
00193                   fval/0x100000, design_units/0x10000);
00194         fval = 0;
00195     }
00196     if (design_units != UNITY) {
00197         fval = zround(((double)fval/(double)design_units) * 1048576.0);
00198     }
00199     if (fval < 0) {
00200         out_ofm(255); fval = fval + 0x1000000;
00201         if (fval <= 0) fval = 1;
00202     } else {
00203         out_ofm(0);
00204         if (fval >= 0x1000000) fval = 0xffffff;
00205     }
00206     out_ofm((fval >> 16) & 0xff);
00207     out_ofm((fval >> 8) & 0xff);
00208     out_ofm(fval & 0xff);
00209 }