1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
// Utility to generate standard font set.
#include "plplotP.h"
extern short int *hersh[];
extern short int *findex[];
extern short int *buffer[];
int
compare( const void *si1, const void *si2 );
int
compare( const void *si1, const void *si2 )
{
const short *a = (const short *) si1;
const short *b = (const short *) si2;
return ( *a == *b ? 0 : ( *a > *b ? 1 : -1 ) );
}
int
main( void )
{
size_t i, j, k, ib, nstd;
U_SHORT nchars, nleng, htab, nindx, zero;
U_SHORT *hrshlst, *hrshidx;
int ix, iy;
long fpos;
PDFstrm *pdfs;
hrshlst = (U_SHORT *) malloc( 176 * sizeof ( U_SHORT ) );
hrshidx = (U_SHORT *) malloc( 176 * sizeof ( U_SHORT ) );
ib = 0;
for ( k = 0; k < 176; k++ )
hrshlst[ib++] = (U_SHORT) *( hersh[0] + k );
// Sort list
qsort( (char *) hrshlst, ib, sizeof ( U_SHORT ), compare );
// Remove duplicates
k = 0;
j = 0;
do
{
if ( hrshlst[k] == hrshlst[j] )
j++;
else
hrshlst[++k] = hrshlst[j];
} while ( j < ib );
nstd = k + 1;
// Now reindex the fonts
for ( k = 0; k < 176; k++ )
for ( i = 0; i < nstd; i++ )
if ( *( hersh[0] + k ) == hrshlst[i] )
{
hrshidx[k] = (U_SHORT) ( i + 1 );
break;
}
pdfs = pdf_fopen( PL_SFONT, "wb+" );
if ( !pdfs )
{
printf( "Error opening standard font file.\n" );
exit( 1 );
}
htab = 1 * 256 + 176;
pdf_wr_2bytes( pdfs, htab );
pdf_wr_2nbytes( pdfs, hrshidx, 176 );
zero = 0;
nindx = 0;
nleng = 1;
fpos = ftell( pdfs->file );
pdf_wr_2bytes( pdfs, nindx );
for ( j = 0; j < nstd; j++ )
{
ib = (size_t) *( findex[( hrshlst[j] - 1 ) / 100] + ( hrshlst[j] - 1 ) % 100 );
if ( ib == 0 )
{
pdf_wr_2bytes( pdfs, zero );
nindx++;
}
else
{
pdf_wr_2bytes( pdfs, nleng );
nindx++;
for (;; )
{
ix = *( buffer[ib / 100] + ib % 100 ) / 128 - 64;
iy = *( buffer[ib / 100] + ib % 100 ) % 128 - 64;
ib++;
if ( ix == -64 )
ix = 64;
if ( iy == -64 )
iy = 64;
nleng++;
if ( ix == 64 && iy == 64 )
break;
}
}
}
fseek( pdfs->file, fpos, 0 );
pdf_wr_2bytes( pdfs, nindx );
nchars = 0;
nleng = 1;
fseek( pdfs->file, 0, 2 ); // Go to end of file
fpos = ftell( pdfs->file ); // Save current position
pdf_wr_2bytes( pdfs, nleng );
for ( j = 0; j < nstd; j++ )
{
ib = (size_t) *( findex[( hrshlst[j] - 1 ) / 100] + ( hrshlst[j] - 1 ) % 100 );
if ( ib != 0 )
{
for (;; )
{
ix = *( buffer[ib / 100] + ib % 100 ) / 128 - 64;
iy = *( buffer[ib / 100] + ib % 100 ) % 128 - 64;
ib++;
if ( ix == -64 )
ix = 64;
if ( iy == -64 )
iy = 64;
fputc( ix, pdfs->file );
fputc( iy, pdfs->file );
nleng++;
if ( ix == 64 && iy == 64 )
break;
}
nchars++;
}
}
nleng--;
fseek( pdfs->file, fpos, 0 );
pdf_wr_2bytes( pdfs, nleng );
pdf_close( pdfs );
free( hrshlst );
free( hrshidx );
printf( "There are %d characters in standard font set.\n", nchars - 1 );
exit( 0 );
}
|