static void pdc_check_stream(pdc_output *out, size_t len) { size_t newsize; size_t cur; pdc_core *pdc = out->pdc; if (out->curpos + len <= out->maxpos) return; pdc_flush_stream(out); if (out->curpos + len <= out->maxpos) return; do { out->maxpos += out->buf_incr; if (out->buf_incr < STREAM_MAXINCR) out->buf_incr *= 2; } while (out->curpos + len > out->maxpos); cur = (size_t) (out->curpos - out->basepos); newsize = (size_t) (out->maxpos - out->basepos); out->basepos = (pdc_byte *) pdc_realloc(pdc, (void *) out->basepos, newsize, "pdc_check_stream"); out->maxpos = out->basepos + newsize; out->curpos = out->basepos + cur; }
void pdf_write_outlines(PDF *p) { int i; if (p->outline_count == 0) /* no outlines: return */ return; pdc_begin_obj(p->out, p->outlines[0].obj_id); /* root outline object */ pdc_begin_dict(p->out); if (p->outlines[0].count != 0) pdc_printf(p->out, "/Count %d\n", COUNT(0)); pdc_objref(p->out, "/First", OBJ_ID(FIRST(0))); pdc_objref(p->out, "/Last", OBJ_ID(LAST(0))); pdc_end_dict(p->out); pdc_end_obj(p->out); /* root outline object */ #define PDF_FLUSH_AFTER_MANY_OUTLINES 1000 /* ca. 50-100 KB */ for (i = 1; i <= p->outline_count; i++) { /* reduce memory usage for many outline entries */ if (i % PDF_FLUSH_AFTER_MANY_OUTLINES == 0) pdc_flush_stream(p->out); pdf_write_outline_dict(p, i); } }
static void pdc_check_stream(pdc_output *out, size_t len) { size_t max; int cur; pdc_stream *stream = &out->stream; pdc_core *pdc = out->pdc; if (stream->curpos + len <= stream->maxpos) return; pdc_flush_stream(out); if (stream->curpos + len <= stream->maxpos) return; max = (size_t) (2*(stream->maxpos - stream->basepos)); cur = stream->curpos - stream->basepos; stream->basepos = (pdc_byte *) pdc_realloc(pdc, (void *) stream->basepos, max, "pdc_check_stream"); stream->maxpos = stream->basepos + max; stream->curpos = stream->basepos + cur; pdc_check_stream(out, len); }
static void pdc_close_stream(pdc_output *out) { pdc_stream *stream = &out->stream; pdc_flush_stream(out); #ifdef HAVE_LIBZ /* * This is delicate: we must ignore the return value because of the * following reasoning: We are called in two situations: * - end of document * - exception * In the first case compression is inactive, so deflateEnd() will * fail only in the second case. However, when an exception occurs * the document is definitely unusable, so we avoid recursive exceptions * or an (unallowed) exception in PDF_delete(). */ (void) deflateEnd(&stream->z); #endif /* close the output file if writing to file, but do not close the * in-core output stream since the caller will have to * fetch the buffer after PDF_close(). */ if (stream->fp == NULL || !stream->writeproc) return; if (stream->mustclose) fclose(stream->fp); /* mark fp as dead in case the error handler jumps in later */ stream->fp = NULL; }
void pdf__end_font(PDF *p) { int i; pdc_t3font *t3font; PDF_SET_STATE(p, pdf_state_document); t3font = p->t3font; t3font->charprocs_id = pdc_alloc_id(p->out); pdc_begin_obj(p->out, t3font->charprocs_id); /* CharProcs dict */ pdc_begin_dict(p->out); for (i = 0; i < t3font->next_glyph; i++) { pdc_put_pdfname(p->out, t3font->glyphs[i].name, strlen(t3font->glyphs[i].name)); pdc_printf(p->out, " %ld 0 R\n", t3font->glyphs[i].charproc_id); } pdc_end_dict(p->out); pdc_end_obj(p->out); /* CharProcs dict */ pdc_begin_obj(p->out, t3font->res_id); pdc_begin_dict(p->out); /* Resource dict */ pdf_write_page_fonts(p); /* Font resources */ pdf_write_page_colorspaces(p); /* Color space resources */ pdf_write_page_pattern(p); /* Pattern resources */ pdf_write_xobjects(p); /* XObject resources */ pdc_end_dict(p->out); /* Resource dict */ pdc_end_obj(p->out); /* Resource object */ p->t3font = (pdc_t3font *) NULL; if (p->flush & pdf_flush_content) pdc_flush_stream(p->out); }
/* Finish the pattern definition. */ void pdf__end_pattern(PDF *p) { /* check whether pdf__save() and pdf__restore() calls are balanced */ if (p->curr_ppt->sl > 0) pdc_error(p->pdc, PDF_E_GSTATE_UNMATCHEDSAVE, 0, 0, 0, 0); pdf_end_text(p); pdc_end_pdfstream(p->out); pdc_end_obj(p->out); /* pattern */ pdc_put_pdfstreamlength(p->out, p->length_id); pdc_begin_obj(p->out, p->res_id); /* Resource object */ pdc_begin_dict(p->out); /* Resource dict */ pdf_write_page_fonts(p); /* Font resources */ pdf_write_page_colorspaces(p); /* Color space resources */ pdf_write_page_pattern(p); /* Pattern resources */ pdf_write_xobjects(p); /* XObject resources */ pdf_write_page_extgstates(p); /* ExtGState resources */ pdc_end_dict(p->out); /* resource dict */ pdc_end_obj(p->out); /* resource object */ pdf_pg_resume(p, -1); if (p->flush & pdc_flush_content) pdc_flush_stream(p->out); if (!p->pdc->smokerun) pdc_logg_cond(p->pdc, 1, trc_api, "[End pattern %d]\n", p->pattern_number -1); }
void pdf__end_font(PDF *p) { int ig; pdf_font *font; pdf_t3font *t3font; PDF_SET_STATE(p, pdf_state_document); font = &p->fonts[p->t3slot]; t3font = font->t3font; /* error message prefix */ pdc_push_errmsg(p->pdc, PDF_E_T3_FONT_PREFIX, font->apiname, 0, 0, 0); if (t3font->pass == 0) { pdf_t3glyph glyph0 = t3font->glyphs[0]; /* search for .notdef glyph */ if (pdc_strcmp(glyph0.name, (char *) pdc_get_notdef_glyphname())) { for (ig = 0; ig < t3font->next_glyph; ig++) { if (!pdc_strcmp(t3font->glyphs[ig].name, (char *) pdc_get_notdef_glyphname())) break; } if (ig < t3font->next_glyph) { pdc_logg_cond(p->pdc, 2, trc_font, "\tGlyph id %d: \"%s\" will be exchanged " "with glyph id 0: \"%s\"\n", ig, t3font->glyphs[ig].name, glyph0.name); t3font->glyphs[0] = t3font->glyphs[ig]; t3font->glyphs[ig] = glyph0; } else { pdc_warning(p->pdc, PDF_E_T3_MISSNOTDEF, 0, 0, 0, 0); } } } if (t3font->pass != 1) { t3font->charprocs_id = pdc_alloc_id(p->out); pdc_begin_obj(p->out, t3font->charprocs_id); /* CharProcs dict */ pdc_begin_dict(p->out); for (ig = 0; ig < t3font->next_glyph; ig++) { pdf_t3glyph *glyph = &t3font->glyphs[ig]; if (glyph->charproc_id != PDC_BAD_ID) { pdf_put_pdfname(p, glyph->name); pdc_objref(p->out, "", glyph->charproc_id); } } pdc_end_dict(p->out); pdc_end_obj(p->out); /* CharProcs dict */ pdc_begin_obj(p->out, t3font->res_id); pdc_begin_dict(p->out); /* Resource dict */ pdf_write_page_fonts(p); /* Font resources */ pdf_write_page_colorspaces(p); /* Color space resources */ pdf_write_page_pattern(p); /* Pattern resources */ pdf_write_xobjects(p); /* XObject resources */ pdc_end_dict(p->out); /* Resource dict */ pdc_end_obj(p->out); /* Resource object */ pdf_pg_resume(p, -1); if (p->flush & pdc_flush_content) pdc_flush_stream(p->out); /* see pdf__begin_glyph */ pdf_init_tstate(p); pdf_init_gstate(p); pdf_init_cstate(p); } pdc_logg_cond(p->pdc, 1, trc_font, "\tEnd of Type3 font \"%s\"\n", font->apiname); pdc_pop_errmsg(p->pdc); if (!p->pdc->smokerun) pdc_logg_cond(p->pdc, 1, trc_api, "[End font %d]\n", p->t3slot); p->t3slot = -1; }