void plD_state_plm(PLStream *pls, PLINT op) { U_CHAR c = (U_CHAR) CHANGE_STATE; int i; dbug_enter("plD_state_plm"); plm_wr( pdf_wr_1byte(pls->pdfs, c) ); plm_wr( pdf_wr_1byte(pls->pdfs, op) ); switch (op) { case PLSTATE_WIDTH: plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) (pls->width)) ); break; case PLSTATE_COLOR0: plm_wr( pdf_wr_2bytes(pls->pdfs, (short) pls->icol0) ); if (pls->icol0 == PL_RGB_COLOR) { plm_wr( pdf_wr_1byte(pls->pdfs, pls->curcolor.r) ); plm_wr( pdf_wr_1byte(pls->pdfs, pls->curcolor.g) ); plm_wr( pdf_wr_1byte(pls->pdfs, pls->curcolor.b) ); } break; case PLSTATE_COLOR1: plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->icol1) ); break; case PLSTATE_FILL: plm_wr( pdf_wr_1byte(pls->pdfs, (U_CHAR) pls->patt) ); break; case PLSTATE_CMAP0: plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->ncol0) ); for (i = 0; i < pls->ncol0; i++) { plm_wr( pdf_wr_1byte(pls->pdfs, pls->cmap0[i].r) ); plm_wr( pdf_wr_1byte(pls->pdfs, pls->cmap0[i].g) ); plm_wr( pdf_wr_1byte(pls->pdfs, pls->cmap0[i].b) ); } break; case PLSTATE_CMAP1: plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->ncol1) ); for (i = 0; i < pls->ncol1; i++) { plm_wr( pdf_wr_1byte(pls->pdfs, pls->cmap1[i].r) ); plm_wr( pdf_wr_1byte(pls->pdfs, pls->cmap1[i].g) ); plm_wr( pdf_wr_1byte(pls->pdfs, pls->cmap1[i].b) ); } break; } }
static void UpdateIndex(PLStream *pls, FPOS_T cp_offset) { PLmDev *dev = (PLmDev *) pls->dev; FILE *file = pls->OutFile; /* Update file index. Right now only number of pages. */ /* The ordering here is critical */ if (dev->index_offset > 0) { pldebug("UpdateIndex (plmeta.c)", "Location: %d, seeking to: %d\n", (int) cp_offset, (int) dev->lp_offset); if (pl_fsetpos(file, &dev->index_offset)) { sprintf(buffer, "UpdateIndex (plmeta.c): fsetpos to index_offset (%d) failed", (int) dev->index_offset); plexit(buffer); } plm_wr( pdf_wr_header(pls->pdfs, "pages") ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->page) ); pldebug("UpdateIndex (plmeta.c)", "Location: %d, seeking to: %d\n", (int) dev->lp_offset, (int) cp_offset); if (pl_fsetpos(file, &cp_offset)) { sprintf(buffer, "UpdateIndex (plmeta.c): fsetpos to cp_offset (%d) failed", (int) cp_offset); plexit(buffer); } } }
static void plm_fill(PLStream *pls) { PLmDev *dev = (PLmDev *) pls->dev; dbug_enter("plm_fill"); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->dev_npts) ); plm_wr( pdf_wr_2nbytes(pls->pdfs, (U_SHORT *) pls->dev_x, pls->dev_npts) ); plm_wr( pdf_wr_2nbytes(pls->pdfs, (U_SHORT *) pls->dev_y, pls->dev_npts) ); dev->xold = PL_UNDEFINED; dev->yold = PL_UNDEFINED; }
void plD_polyline_plm(PLStream *pls, short *xa, short *ya, PLINT npts) { PLmDev *dev = (PLmDev *) pls->dev; U_CHAR c = (U_CHAR) POLYLINE; dbug_enter("plD_polyline_plm"); plm_wr( pdf_wr_1byte(pls->pdfs, c) ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) npts) ); plm_wr( pdf_wr_2nbytes(pls->pdfs, (U_SHORT *) xa, npts) ); plm_wr( pdf_wr_2nbytes(pls->pdfs, (U_SHORT *) ya, npts) ); dev->xold = xa[npts - 1]; dev->yold = ya[npts - 1]; }
static void WritePageInfo(PLStream *pls, FPOS_T pp_offset) { PLmDev *dev = (PLmDev *) pls->dev; FILE *file = pls->OutFile; int isfile = (pls->output_type == 0); U_CHAR c; FPOS_T cp_offset=0; /* Update table of contents. */ if (isfile) { if (pl_fgetpos(file, &cp_offset)) plexit("WritePageInfo (plmeta.c): fgetpos call failed"); UpdateIndex(pls, cp_offset); } /* Write new page header */ if (dev->notfirst) c = BOP; else { c = BOP0; dev->notfirst = 1; } plm_wr( pdf_wr_1byte(pls->pdfs, c) ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->page) ); plm_wr( pdf_wr_4bytes(pls->pdfs, (U_LONG) pp_offset) ); plm_wr( pdf_wr_4bytes(pls->pdfs, (U_LONG) 0) ); /* Update last page offset with current page value */ dev->lp_offset = cp_offset; /* Write some page state information just to make things nice later on */ /* Eventually there will be more */ plD_state_plm(pls, PLSTATE_COLOR0); }
int main( void ) { short j, k, ib, nindx, nchars, nleng, htab, zero; short *hrshlst; signed char ix, iy; long fpos; PDFstrm *pdfs; hrshlst = (short *) malloc( 4 * 176 * sizeof ( short ) ); ib = 0; for ( j = 0; j < 4; j++ ) for ( k = 0; k < 176; k++ ) hrshlst[ib++] = *( hersh[j] + k ); pdfs = pdf_fopen( PL_XFONT, "wb+" ); if ( !pdfs ) { printf( "Error opening extended font file.\n" ); exit( 1 ); } htab = 4 * 256 + 176; pdf_wr_2bytes( pdfs, htab ); pdf_wr_2nbytes( pdfs, (U_SHORT *) hrshlst, 4 * 176 ); nleng = 1; zero = 0; nindx = 0; fpos = ftell( pdfs->file ); pdf_wr_2bytes( pdfs, nindx ); for ( j = 0; j < 30; j++ ) { for ( k = 0; k < 100; k++ ) { ib = *( findex[j] + k ); 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 ); fseek( pdfs->file, 0, 2 ); fpos = ftell( pdfs->file ); nleng = 1; nchars = 0; pdf_wr_2bytes( pdfs, nleng ); for ( j = 0; j < 30; j++ ) { for ( k = 0; k < 100; k++ ) { ib = *( findex[j] + k ); 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 ); printf( "There are %d characters in font set.\n", nchars - 1 ); exit( 0 ); }
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 ); }
static void WriteFileHeader(PLStream *pls) { PLmDev *dev = (PLmDev *) pls->dev; FILE *file = pls->OutFile; int isfile = (pls->output_type == 0); dbug_enter("WriteFileHeader(PLStream *pls"); plm_wr( pdf_wr_header(pls->pdfs, PLMETA_HEADER) ); plm_wr( pdf_wr_header(pls->pdfs, PLMETA_VERSION) ); /* Write file index info. Right now only number of pages. */ /* The order here is critical */ if (isfile) { if (pl_fgetpos(file, &dev->index_offset)) plexit("WriteFileHeader: fgetpos call failed"); } plm_wr( pdf_wr_header(pls->pdfs, "pages") ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) 0) ); /* Write initialization info. Tag via strings to make backward compatibility with old metafiles as easy as possible. */ plm_wr( pdf_wr_header(pls->pdfs, "xmin") ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) dev->xmin) ); plm_wr( pdf_wr_header(pls->pdfs, "xmax") ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) dev->xmax) ); plm_wr( pdf_wr_header(pls->pdfs, "ymin") ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) dev->ymin) ); plm_wr( pdf_wr_header(pls->pdfs, "ymax") ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) dev->ymax) ); plm_wr( pdf_wr_header(pls->pdfs, "pxlx") ); plm_wr( pdf_wr_ieeef(pls->pdfs, (float) dev->pxlx) ); plm_wr( pdf_wr_header(pls->pdfs, "pxly") ); plm_wr( pdf_wr_ieeef(pls->pdfs, (float) dev->pxly) ); /* Geometry info, needed to properly transmit e.g. aspect ratio, via the length params. Not sure if the others are useful, but they're included for completeness. */ plm_wr( pdf_wr_header(pls->pdfs, "xdpi") ); plm_wr( pdf_wr_ieeef(pls->pdfs, (float) pls->xdpi) ); plm_wr( pdf_wr_header(pls->pdfs, "ydpi") ); plm_wr( pdf_wr_ieeef(pls->pdfs, (float) pls->ydpi) ); plm_wr( pdf_wr_header(pls->pdfs, "xlength") ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->xlength) ); plm_wr( pdf_wr_header(pls->pdfs, "ylength") ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->ylength) ); plm_wr( pdf_wr_header(pls->pdfs, "xoffset") ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->xoffset) ); plm_wr( pdf_wr_header(pls->pdfs, "yoffset") ); plm_wr( pdf_wr_2bytes(pls->pdfs, (U_SHORT) pls->yoffset) ); plm_wr( pdf_wr_header(pls->pdfs, "") ); }