| 1 |
/* |
| 2 |
Copyright 1996-2014 Han The Thanh, <[email protected]> |
| 3 |
|
| 4 |
This file is part of pdfTeX. |
| 5 |
|
| 6 |
pdfTeX is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 2 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
pdfTeX is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License along |
| 17 |
with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "ptexlib.h" |
| 21 |
|
| 22 |
typedef struct { |
| 23 |
char *dataptr; |
| 24 |
integer len; |
| 25 |
} packet_entry; |
| 26 |
|
| 27 |
/* define packet_ptr, packet_array & packet_limit */ |
| 28 |
define_array(packet); |
| 29 |
|
| 30 |
typedef struct { |
| 31 |
char **data; |
| 32 |
int *len; |
| 33 |
int char_count; |
| 34 |
} vf_entry; |
| 35 |
|
| 36 |
/* define vf_ptr, vf_array & vf_limit */ |
| 37 |
define_array(vf); |
| 38 |
|
| 39 |
static char *packet_data_ptr; |
| 40 |
|
| 41 |
integer newvfpacket(internalfontnumber f) |
| 42 |
{ |
| 43 |
int i, n = fontec[f] - fontbc[f] + 1; |
| 44 |
alloc_array(vf, 1, SMALL_ARRAY_SIZE); |
| 45 |
vf_ptr->len = xtalloc(n, int); |
| 46 |
vf_ptr->data = xtalloc(n, char *); |
| 47 |
vf_ptr->char_count = n; |
| 48 |
for (i = 0; i < n; i++) { |
| 49 |
vf_ptr->data[i] = NULL; |
| 50 |
vf_ptr->len[i] = 0; |
| 51 |
} |
| 52 |
return vf_ptr++ - vf_array; |
| 53 |
} |
| 54 |
|
| 55 |
void storepacket(internalfontnumber f, integer c, strnumber s) |
| 56 |
{ |
| 57 |
int l = strstart[s + 1] - strstart[s]; |
| 58 |
vf_array[vfpacketbase[f]].len[c - fontbc[f]] = l; |
| 59 |
vf_array[vfpacketbase[f]].data[c - fontbc[f]] = xtalloc(l, char); |
| 60 |
memcpy((void *) vf_array[vfpacketbase[f]].data[c - fontbc[f]], |
| 61 |
(void *) (strpool + strstart[s]), (unsigned) l); |
| 62 |
} |
| 63 |
|
| 64 |
void startpacket(internalfontnumber f, eightbits c) |
| 65 |
{ |
| 66 |
packet_data_ptr = vf_array[vfpacketbase[f]].data[c - fontbc[f]]; |
| 67 |
vfpacketlength = vf_array[vfpacketbase[f]].len[c - fontbc[f]]; |
| 68 |
} |
| 69 |
|
| 70 |
eightbits packetbyte(void) |
| 71 |
{ |
| 72 |
vfpacketlength--; |
| 73 |
return *packet_data_ptr++; |
| 74 |
} |
| 75 |
|
| 76 |
void pushpacketstate(void) |
| 77 |
{ |
| 78 |
alloc_array(packet, 1, SMALL_ARRAY_SIZE); |
| 79 |
packet_ptr->dataptr = packet_data_ptr; |
| 80 |
packet_ptr->len = vfpacketlength; |
| 81 |
packet_ptr++; |
| 82 |
} |
| 83 |
|
| 84 |
void poppacketstate(void) |
| 85 |
{ |
| 86 |
if (packet_ptr == packet_array) |
| 87 |
pdftex_fail("packet stack empty, impossible to pop"); |
| 88 |
packet_ptr--; |
| 89 |
packet_data_ptr = packet_ptr->dataptr; |
| 90 |
vfpacketlength = packet_ptr->len; |
| 91 |
} |
| 92 |
|
| 93 |
void vf_free(void) |
| 94 |
{ |
| 95 |
vf_entry *v; |
| 96 |
char **p; |
| 97 |
if (vf_array != NULL) { |
| 98 |
for (v = vf_array; v < vf_ptr; v++) { |
| 99 |
xfree(v->len); |
| 100 |
for (p = v->data; p - v->data < v->char_count; p++) |
| 101 |
xfree(*p); |
| 102 |
xfree(v->data); |
| 103 |
} |
| 104 |
xfree(vf_array); |
| 105 |
} |
| 106 |
xfree(packet_array); |
| 107 |
} |