/* Creates a file depending on PDC_FILE_ASCII and pdc->asciifile. */ size_t pdc_write_file( pdc_core *pdc, const char *filename, const char *qualifier, const char *content, size_t len, int flags) { size_t wlen = 0; pdc_file *sfp; sfp = pdc_fopen(pdc, filename, qualifier, NULL, 0, flags); if (sfp != NULL) { wlen = pdc_fwrite_ascii(pdc, content, len, sfp->fp); if (wlen < len) { pdc_set_fwrite_errmsg(pdc, filename); PDC_RETHROW(pdc); } pdc_fclose(sfp); } return wlen; }
size_t pdc_fwrite(const void *ptr, size_t size, size_t nmemb, pdc_file *sfp) { static const char fn[] = "pdc_fwrite"; if (sfp->wrmode) { size_t poslen, nbytes = 0; if (sfp->fp) { size_t total = pdc__fwrite(ptr, size, nmemb, sfp->fp); if (total < size * nmemb) { pdc_set_fwrite_errmsg(sfp->pdc, sfp->filename); PDC_RETHROW(sfp->pdc); } return total; } nbytes = size * nmemb; if (sfp->pos + nbytes > sfp->limit) { poslen = (size_t) (sfp->pos - sfp->data); size = poslen + nbytes; sfp->data = (pdc_byte *) pdc_realloc(sfp->pdc, sfp->data, size, fn); sfp->pos = sfp->data + poslen; sfp->end = sfp->data + size; sfp->limit = sfp->end; } memcpy(sfp->pos, ptr, nbytes); sfp->pos += nbytes; if (sfp->pos > sfp->end) sfp->end = sfp->pos; } else { nmemb = 0; } return nmemb; }
pdc_bool pdf_t1open_fontfile(PDF *p, pdf_font *font, const char *filename, PDF_data_source *t1src, pdc_bool requested) { static const char *fn = "pdf_t1open_fontfile"; t1_private_data *t1 = NULL; pdc_file *fp = NULL; const char *stemp = NULL; pdc_byte magic[PFA_TESTBYTE]; char fullname[PDC_FILENAMELEN]; int fflags = PDC_FILE_BINARY; pdc_bool ispfb = pdc_true; if (filename) { pdc_bool retval = pdc_true; pdc_bool fnamegiven = (strcmp(filename, FNT_MISSING_FILENAME) == 0) ? pdc_false : pdc_true; (void) retval; if (fnamegiven) { fp = pdc_fsearch_fopen(p->pdc, filename, fullname, "PostScript Type1 ", fflags); if (fp == NULL) { if (t1src) PDC_RETHROW(p->pdc); return pdc_check_fopen_errmsg(p->pdc, requested); } pdc_logg_cond(p->pdc, 1, trc_font, "\tLoading PostScript Type1 fontfile \"%s\":\n", fullname); } } if (fp) { pdc_fread(magic, 1, PFA_TESTBYTE, fp); stemp = filename; } else if (font->ft.img) { strncpy((char *) magic, (const char *)font->ft.img, PFA_TESTBYTE); stemp = font->ft.name; } /* try to identify PFA files */ if (magic[0] != PFB_MARKER) { char startsequ[PFA_TESTBYTE + 1]; strcpy(startsequ, FNT_PFA_STARTSEQU); if (strncmp((const char *) magic, startsequ, PFA_TESTBYTE)) { if (fp) pdc_fclose(fp); pdc_set_errmsg(p->pdc, PDF_E_T1_NOFONT, stemp, 0, 0, 0); if (t1src) PDC_RETHROW(p->pdc); return pdc_false; } ispfb = pdc_false; } pdc_logg_cond(p->pdc, 1, trc_font, "\tPostScript Type1 font of format \"%s\" detected\n", ispfb ? "PFB" : "PFA"); if (t1src) { t1src->private_data = (unsigned char *) pdc_malloc(p->pdc, sizeof(t1_private_data), fn); t1 = (t1_private_data *) t1src->private_data; if (filename) { pdc_fclose(fp); if (ispfb) { t1->fontfile = pdc_fsearch_fopen(p->pdc, fullname, NULL, "PFB ", fflags); } else { t1->fontfile = pdc_fsearch_fopen(p->pdc, fullname, NULL, "PFA ", PDC_FILE_TEXT); } if (t1->fontfile == NULL) PDC_RETHROW(p->pdc); } else if (font->ft.img) { /* only for virtual PFB files */ t1->fontfile = NULL; t1->img = font->ft.img; t1->pos = font->ft.img; t1->end = font->ft.img + font->ft.filelen; } t1src->init = t1data_init; t1src->fill = ispfb ? PFB_data_fill : PFA_data_fill; t1src->terminate = t1data_terminate; } else if (fp != NULL) { if (pdc_file_isvirtual(fp) == pdc_true) { if (ispfb) font->ft.img = (pdc_byte *) pdc_freadall(fp, &font->ft.filelen, NULL); font->ft.imgname = pdc_strdup(p->pdc, fullname); pdc_lock_pvf(p->pdc, font->ft.imgname); } font->ft.filename = pdc_strdup(p->pdc, fullname); pdc_fclose(fp); } return pdc_true; }