1 //	xtndfont.c
2 //
3 //      Utility to generate extended font set.
4 //
5 
6 #include "plplotP.h"
7 
8 extern short int *hersh[];
9 extern short int *findex[];
10 extern short int *buffer[];
11 
12 int
main(void)13 main( void )
14 {
15     size_t  j, k, ib;
16     U_SHORT nchars, nleng, htab, nindx, zero;
17     U_SHORT *hrshlst;
18     int     ix, iy;
19     long    fpos;
20     PDFstrm *pdfs;
21 
22     hrshlst = (U_SHORT *) malloc( 4 * 176 * sizeof ( U_SHORT ) );
23 
24     ib = 0;
25     for ( j = 0; j < 4; j++ )
26         for ( k = 0; k < 176; k++ )
27             hrshlst[ib++] = (U_SHORT) *( hersh[j] + k );
28 
29     pdfs = pdf_fopen( PL_XFONT, "wb+" );
30     if ( !pdfs )
31     {
32         printf( "Error opening extended font file.\n" );
33         exit( 1 );
34     }
35 
36     htab = 4 * 256 + 176;
37 
38     pdf_wr_2bytes( pdfs, htab );
39     pdf_wr_2nbytes( pdfs, hrshlst, 4 * 176 );
40 
41     nleng = 1;
42     zero  = 0;
43     nindx = 0;
44     fpos  = ftell( pdfs->file );
45     pdf_wr_2bytes( pdfs, nindx );
46     for ( j = 0; j < 30; j++ )
47     {
48         for ( k = 0; k < 100; k++ )
49         {
50             ib = (size_t) *( findex[j] + k );
51             if ( ib == 0 )
52             {
53                 pdf_wr_2bytes( pdfs, zero );
54                 nindx++;
55             }
56             else
57             {
58                 pdf_wr_2bytes( pdfs, nleng );
59                 nindx++;
60                 for (;; )
61                 {
62                     ix = *( buffer[ib / 100] + ib % 100 ) / 128 - 64;
63                     iy = *( buffer[ib / 100] + ib % 100 ) % 128 - 64;
64                     ib++;
65                     if ( ix == -64 )
66                         ix = 64;
67                     if ( iy == -64 )
68                         iy = 64;
69                     nleng++;
70                     if ( ix == 64 && iy == 64 )
71                         break;
72                 }
73             }
74         }
75     }
76     fseek( pdfs->file, fpos, 0 );
77     pdf_wr_2bytes( pdfs, nindx );
78 
79     fseek( pdfs->file, 0, 2 );
80     fpos   = ftell( pdfs->file );
81     nleng  = 1;
82     nchars = 0;
83     pdf_wr_2bytes( pdfs, nleng );
84     for ( j = 0; j < 30; j++ )
85     {
86         for ( k = 0; k < 100; k++ )
87         {
88             ib = (size_t) *( findex[j] + k );
89             if ( ib != 0 )
90             {
91                 for (;; )
92                 {
93                     ix = *( buffer[ib / 100] + ib % 100 ) / 128 - 64;
94                     iy = *( buffer[ib / 100] + ib % 100 ) % 128 - 64;
95                     ib++;
96                     if ( ix == -64 )
97                         ix = 64;
98                     if ( iy == -64 )
99                         iy = 64;
100                     fputc( ix, pdfs->file );
101                     fputc( iy, pdfs->file );
102                     nleng++;
103                     if ( ix == 64 && iy == 64 )
104                         break;
105                 }
106                 nchars++;
107             }
108         }
109     }
110     nleng--;
111     fseek( pdfs->file, fpos, 0 );
112     pdf_wr_2bytes( pdfs, nleng );
113     pdf_close( pdfs );
114 
115     free( hrshlst );
116 
117     printf( "There are %d characters in font set.\n", nchars - 1 );
118     exit( 0 );
119 }
120