Back to index

tetex-bin  3.0
vfpacket.c
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 1996-2002 Han The Thanh, <thanh@pdftex.org>
00003 
00004 This file is part of pdfTeX.
00005 
00006 pdfTeX is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
00010 
00011 pdfTeX is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with pdfTeX; if not, write to the Free Software
00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 $Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/vfpacket.c#7 $
00021 */
00022 
00023 #include "ptexlib.h"
00024 
00025 typedef struct {
00026     internalfontnumber font;
00027     char *dataptr;
00028     int  len;
00029 } packet_entry;
00030 
00031 /* define packet_ptr, packet_array & packet_limit */
00032 define_array(packet);   
00033 
00034 typedef struct {
00035     char **data;
00036     int *len;
00037     internalfontnumber font;
00038 }  vf_entry;
00039 
00040 /* define vf_ptr, vf_array & vf_limit */
00041 define_array(vf);   
00042 
00043 static char *packet_data_ptr;
00044 
00045 integer newvfpacket(internalfontnumber f)
00046 {
00047     int i,
00048         n = fontec[f] - fontbc[f] + 1;
00049     alloc_array(vf, 1, SMALL_ARRAY_SIZE);
00050     vf_ptr->len = xtalloc(n, int);
00051     vf_ptr->data = xtalloc(n, char *);
00052     for (i = 0; i < n; i++) {
00053         vf_ptr->data[i] = NULL;
00054         vf_ptr->len[i] = 0;
00055     }
00056     vf_ptr->font = f;
00057     return vf_ptr++ - vf_array;
00058 }
00059 
00060 void storepacket(integer f, integer c, integer s)
00061 {
00062     int l = strstart[s + 1] - strstart[s];
00063     vf_array[vfpacketbase[f]].len[c - fontbc[f]] = l;
00064     vf_array[vfpacketbase[f]].data[c - fontbc[f]] = xtalloc(l, char);
00065     memcpy((void *)vf_array[vfpacketbase[f]].data[c - fontbc[f]], 
00066            (void *)(strpool + strstart[s]), (unsigned)l);
00067 }
00068 
00069 void pushpacketstate()
00070 {
00071     alloc_array(packet, 1, SMALL_ARRAY_SIZE);
00072     packet_ptr->font = f;
00073     packet_ptr->dataptr = packet_data_ptr;
00074     packet_ptr->len = vfpacketlength;
00075     packet_ptr++;
00076 }
00077 
00078 void poppacketstate()
00079 {
00080     if (packet_ptr == packet_array)
00081         pdftex_fail("packet stack empty, impossible to pop");
00082     packet_ptr--;
00083     f = packet_ptr->font;
00084     packet_data_ptr = packet_ptr->dataptr;
00085     vfpacketlength = packet_ptr->len;
00086 }
00087 
00088 void startpacket(internalfontnumber f, integer c)
00089 {
00090     packet_data_ptr = vf_array[vfpacketbase[f]].data[c - fontbc[f]];
00091     vfpacketlength = vf_array[vfpacketbase[f]].len[c - fontbc[f]];
00092 }
00093 
00094 eightbits packetbyte()
00095 {
00096     vfpacketlength--;
00097     return *packet_data_ptr++;
00098 }
00099 
00100 void vf_free(void)
00101 {
00102     vf_entry *v;
00103     int n;
00104     char **p;
00105     if (vf_array != NULL) {
00106         for (v = vf_array; v < vf_ptr; v++) {
00107             xfree(v->len);
00108             n = fontec[v->font] - fontec[v->font] + 1;
00109             for (p = v->data; p - v->data < n ; p++)
00110                 xfree(*p);
00111             xfree(v->data);
00112         }
00113         xfree(vf_array);
00114     }
00115     xfree(packet_array);
00116 }