PDFLIB_API void PDFLIB_CALL PDF_set_border_style(PDF *p, const char *style, float width) { static const char fn[] = "PDF_set_border_style"; PDF_TRACE(("%s\t(pdf[%p], \"%s\", %f);\n", fn, (void *) p, style, width)); if (PDF_SANITY_CHECK_FAILED(p)) return; PDF_CHECK_SCOPE(p, fn, pdf_state_document | pdf_state_page); if (style == NULL) p->border_style = border_solid; else if (!strcmp(style, "solid")) p->border_style = border_solid; else if (!strcmp(style, "dashed")) p->border_style = border_dashed; else pdf_error(p, PDF_ValueError, "Unknown annotation border style '%s'", style); if (width < 0.0) pdf_error(p, PDF_ValueError, "Negative annotation border width %f", width); p->border_width = width; }
/* p may be NULL on the first call - we don't use it anyway */ static void * pdf_malloc(PDF *p, size_t size, const char *caller) { void *ret; /* the behavior of malloc(0) is undefined in ANSI C, and may * result in a NULL pointer return value which makes PDFlib bail out. */ if (size == (size_t) 0) { size = (size_t) 1; if (p != NULL) { pdf_error(p, PDF_NonfatalError, "Tried to allocate 0 bytes in %s!\n", caller); } } ret = malloc(size); #ifdef DEBUG if (p != NULL && p->debug['m']) fprintf(stderr, "%x malloced, size %d from %s, page %d\n", (int)ret, size, caller, p->current_page); #endif /* Special error handling at first allocation (for p itself) */ if (p != NULL) { if (ret == NULL) { pdf_error(p, PDF_MemoryError, "Couldn't allocate memory in %s!\n", caller); } } return ret; }
PDFLIB_API void PDFLIB_CALL PDF_set_border_color(PDF *p, float red, float green, float blue) { static const char fn[] = "PDF_set_border_color"; PDF_TRACE(("%s\t(pdf[%p], %f, %f, %f);\n", fn, (void *) p, red, green, blue)); if (PDF_SANITY_CHECK_FAILED(p)) return; PDF_CHECK_SCOPE(p, fn, pdf_state_document | pdf_state_page); if (red < 0.0 || red > 1.0) pdf_error(p, PDF_ValueError, "Bogus red color value %f for annotation border", red); if (green < 0.0 || green > 1.0) pdf_error(p, PDF_ValueError, "Bogus green color value %f for annotation border", green); if (blue < 0.0 || blue > 1.0) pdf_error(p, PDF_ValueError, "Bogus blue color value %f for annotation border", blue); p->border_red = red; p->border_green = green; p->border_blue = blue; }
/* We cook up our own calloc routine, using the caller-supplied * malloc and memset. */ static void * pdf_calloc(PDF *p, size_t size, const char *caller) { void *ret; /* see pdf_malloc() */ if (size == (size_t) 0) { size = (size_t) 1; if (p != NULL) { pdf_error(p, PDF_NonfatalError, "Tried to (c)allocate 0 bytes in %s!\n", caller); } } if ((ret = p->malloc(p, size, caller)) == NULL) { pdf_error(p, PDF_MemoryError, "Couldn't (c)allocate memory in %s!\n", caller); } memset(ret, 0, size); #ifdef DEBUG if (p->debug['c']) fprintf(stderr, "%x calloced, size %d from %s, page %d\n", (int) ret, size, caller, p->current_page); #endif return ret; }
/* Add a link to another PDF file */ PDFLIB_API void PDFLIB_CALL PDF_add_pdflink( PDF *p, float llx, float lly, float urx, float ury, const char *filename, int page, const char *desttype) { static const char fn[] = "PDF_add_pdflink"; pdf_annot *ann; PDF_TRACE(("%s\t(pdf[%p], %f, %f, %f, %f, \"%s\", %d, \"%s\");\n", fn, (void *) p, llx, lly, urx, ury, filename, page, desttype)); if (PDF_SANITY_CHECK_FAILED(p)) return; PDF_CHECK_SCOPE(p, fn, pdf_state_page); if (filename == NULL) pdf_error(p, PDF_ValueError, "NULL filename in PDF_add_pdflink"); ann = (pdf_annot *) p->malloc(p, sizeof(pdf_annot), "PDF_add_pdflink"); ann->filename = pdf_strdup(p, filename); ann->type = ann_pdflink; ann->dest.page = page; if (desttype == NULL) ann->dest.type = fitpage; else if (!strcmp(desttype, "retain")) ann->dest.type = retain; else if (!strcmp(desttype, "fitpage")) ann->dest.type = fitpage; else if (!strcmp(desttype, "fitwidth")) ann->dest.type = fitwidth; else if (!strcmp(desttype, "fitheight")) ann->dest.type = fitheight; else if (!strcmp(desttype, "fitbbox")) ann->dest.type = fitbbox; else pdf_error(p, PDF_ValueError, "Unknown destination type '%s' in PDF_add_pdflink", desttype); ann->rect.llx = llx; ann->rect.lly = lly; ann->rect.urx = urx; ann->rect.ury = ury; pdf_add_annot(p, ann); }
PDFLIB_API void PDFLIB_CALL PDF_setcmykcolor_stroke(PDF *p, float cyan, float magenta, float yellow, float black) { char buf1[FLOATBUFSIZE], buf2[FLOATBUFSIZE], buf3[FLOATBUFSIZE]; char buf4[FLOATBUFSIZE]; if (PDF_SANITY_CHECK_FAILED(p)) return; if (cyan < 0.0 || cyan > EPSILON || magenta < 0.0 || magenta > EPSILON || yellow < 0.0 || yellow > EPSILON || black < 0.0 || black > EPSILON) { pdf_error(p, PDF_NonfatalError, "Bogus color value (%f/%f/%f/%f) in PDF_setcmykcolor_stroke", cyan, magenta, yellow, black); return; } pdf_printf(p, "%s %s %s %s K\n", pdf_float(buf1, cyan), pdf_float(buf2, magenta), pdf_float(buf3, yellow), pdf_float(buf4, black)); p->cstate[p->sl].stroke.cs = DeviceCMYK; p->cstate[p->sl].fill.val.cmyk.c = cyan; p->cstate[p->sl].fill.val.cmyk.m = magenta; p->cstate[p->sl].fill.val.cmyk.y = yellow; p->cstate[p->sl].fill.val.cmyk.k = black; }
PDFLIB_API void PDFLIB_CALL PDF_setrgbcolor_stroke(PDF *p, float red, float green, float blue) { char buf1[FLOATBUFSIZE], buf2[FLOATBUFSIZE], buf3[FLOATBUFSIZE]; if (PDF_SANITY_CHECK_FAILED(p)) return; if (red < 0.0 || red > EPSILON || green < 0.0 || green > EPSILON || blue < 0.0 || blue > EPSILON) { pdf_error(p, PDF_NonfatalError, "Bogus color value (%f/%f/%f) in PDF_setrgbcolor_stroke", red, green, blue); return; } if (red == green && green == blue) PDF_setgray_stroke(p, red); else { pdf_printf(p, "%s %s %s RG\n", pdf_float(buf1, red), pdf_float(buf2, green), pdf_float(buf3, blue)); p->cstate[p->sl].stroke.cs = DeviceRGB; p->cstate[p->sl].stroke.val.rgb.r = red; p->cstate[p->sl].stroke.val.rgb.g = green; p->cstate[p->sl].stroke.val.rgb.b = blue; } }
static void pdf_write_pattern_color(PDF *p, pdf_bool fill) { pdf_color color; /* fetch the current fill or stroke color and apply it to the pattern */ if (fill) color = p->cstate[p->sl].fill; else color = p->cstate[p->sl].stroke; if (color.cs == DeviceGray || color.cs == Separation) { pdf_printf(p, "%f", color.val.gray); } else if (color.cs == DeviceRGB) { pdf_printf(p, "%f %f %f", color.val.rgb.r, color.val.rgb.g, color.val.rgb.b); } else if (color.cs == DeviceCMYK) { pdf_printf(p, "%f %f %f %f", color.val.cmyk.c, color.val.cmyk.m, color.val.cmyk.y, color.val.cmyk.k); } else { pdf_error(p, PDF_SystemError, "Unknown color space in pdf_write_pattern_color"); } }
PDFLIB_API void PDFLIB_CALL PDF_close(PDF *p) { static const char fn[] = "PDF_close"; PDF_TRACE(("%s\t\t(pdf[%p]);\n", fn, (void *) p)); if (PDF_SANITY_CHECK_FAILED(p)) return; PDF_CHECK_SCOPE(p, fn, pdf_state_document); if (PDF_GET_STATE(p) != pdf_state_error) { if (p->current_page == 0) pdf_error(p, PDF_RuntimeError, "Empty document"); pdf_wrapup_document(p); /* dump the remaining PDF structures */ } pdf_flush_stream(p); pdf_cleanup_document(p); /* UPR stuff not released here but in PDF_delete() */ PDF_SET_STATE(p, fn, pdf_state_object); }
static void pdf_setgraycolor(PDF *p, const char *type, float g) { pdf_cstate *cs = &p->cstate[p->sl]; if (g < 0.0 || g > EPSILON ) { pdf_error(p, PDF_NonfatalError, "Bogus gray value (%f) in PDF_setcolor", g); return; } if (!strcmp(type, "fill") || !strcmp(type, "both")) { if (cs->fill.cs != DeviceGray || cs->fill.val.gray != g) { if (PDF_GET_STATE(p) != pdf_state_document) pdf_printf(p, "%f g\n", g); cs->fill.cs = DeviceGray; cs->fill.val.gray = g; } } if (!strcmp(type, "stroke") || !strcmp(type, "both")) { if (cs->stroke.cs != DeviceGray || cs->stroke.val.gray != g) { if (PDF_GET_STATE(p) != pdf_state_document) pdf_printf(p, "%f G\n", g); cs->stroke.cs = DeviceGray; cs->stroke.val.gray = g; } } }
void pdf_write(PDF *p, const void *data, size_t size) { #ifdef HAVE_LIBZ if (p->stream.compress) { p->stream.z.avail_in = (uInt) size; p->stream.z.next_in = (Bytef *) data; p->stream.z.avail_out = 0; while (p->stream.z.avail_in > 0) { if (p->stream.z.avail_out == 0) { /* estimate output buffer size */ pdf_check_stream(p, (size_t) (p->stream.z.avail_in/4 + 16)); p->stream.z.next_out = (Bytef *) p->stream.curpos; p->stream.z.avail_out = (uInt) (p->stream.maxpos - p->stream.curpos); } if (deflate(&(p->stream.z), Z_NO_FLUSH) != Z_OK) pdf_error(p, PDF_SystemError, "Compression error (Z_NO_FLUSH)"); p->stream.curpos = p->stream.z.next_out; } }else { #endif /* HAVE_LIBZ */ pdf_check_stream(p, size); memcpy(p->stream.curpos, data, size); p->stream.curpos += size; #ifdef HAVE_LIBZ } #endif /* HAVE_LIBZ */ }
/* Add a link to an arbitrary Internet resource (URL) */ PDFLIB_API void PDFLIB_CALL PDF_add_weblink( PDF *p, float llx, float lly, float urx, float ury, const char *url) { static const char fn[] = "PDF_add_weblink"; pdf_annot *ann; PDF_TRACE(("%s\t(pdf[%p], %f, %f, %f, %f, \"%s\");\n", fn, (void *) p, llx, lly, urx, ury, url)); if (PDF_SANITY_CHECK_FAILED(p)) return; PDF_CHECK_SCOPE(p, fn, pdf_state_page); if (url == NULL || *url == '\0') pdf_error(p, PDF_ValueError, "NULL URL in PDF_add_weblink"); ann = (pdf_annot *) p->malloc(p, sizeof(pdf_annot), "PDF_add_weblink"); ann->filename = pdf_strdup(p, url); ann->type = ann_weblink; ann->rect.llx = llx; ann->rect.lly = lly; ann->rect.urx = urx; ann->rect.ury = ury; pdf_add_annot(p, ann); }
PDFLIB_API void PDFLIB_CALL PDF_setcolor( PDF *p, const char *fstype, const char *colorspace, float c1, float c2, float c3, float c4) { static const char fn[] = "PDF_setcolor"; PDF_TRACE(("%s\t(pdf[%p], \"%s\", \"%s\", %f, %f, %f, %f);\n", fn, (void *) p, fstype, colorspace, c1, c2, c3, c4)); if (PDF_SANITY_CHECK_FAILED(p)) return; PDF_CHECK_SCOPE(p, fn, pdf_state_ppt | pdf_state_document); if (!fstype || !*fstype) pdf_error(p, PDF_ValueError, "Missing type in PDF_setcolor"); if (strcmp(fstype, "fill") && strcmp(fstype, "stroke") && strcmp(fstype, "both")) pdf_error(p, PDF_ValueError, "Unknown type in PDF_setcolor"); if (!colorspace || !*colorspace) pdf_error(p, PDF_ValueError, "Missing color space in PDF_setcolor"); if (!strcmp(colorspace, "gray")) pdf_setgraycolor(p, fstype, c1); else if (!strcmp(colorspace, "rgb")) pdf_setrgbcolor2(p, fstype, c1, c2, c3); else if (!strcmp(colorspace, "cmyk")) pdf_setcmykcolor(p, fstype, c1, c2, c3, c4); else if (!strcmp(colorspace, "spot")) pdf_setspotcolor(p, fstype, (int) c1, c2); else if (!strcmp(colorspace, "pattern")) pdf_setpatterncolor(p, fstype, (int) c1); else pdf_error(p, PDF_ValueError, "Unknown color space '%s' in PDF_setcolor", colorspace); }
void pdf_compress_init(PDF *p) { if (deflateInit(&p->stream.z, p->compress) != Z_OK) pdf_error(p, PDF_SystemError, "Compression error (deflateInit)"); p->stream.compress = pdf_true; }
void replace_packet_fonts(internal_font_number f, integer *old_fontid, integer *new_fontid, int count) { int c, cmd, cur_packet_byte, lf, k,l; charinfo *co; real_eight_bits *vf_packets; k = 0; for (c = font_bc(f);c <= font_ec(f);c++) { if (char_exists(f,c)) { co = get_charinfo(f,c); vf_packets = get_charinfo_packets(co); if (vf_packets == NULL) continue; cur_packet_byte = 0; while ((cmd = vf_packets[cur_packet_byte]) != packet_end_code) { cur_packet_byte++; switch (cmd) { case packet_font_code: packet_number(lf); for (l=0;l<count;l++) { if (old_fontid[l]==lf) { break; } } if(l<count) { k = new_fontid[l]; vf_packets[(cur_packet_byte-4)] = (k&0xFF000000)>>24; vf_packets[(cur_packet_byte-3)] = (k&0x00FF0000)>>16; vf_packets[(cur_packet_byte-2)] = (k&0x0000FF00)>>8; vf_packets[(cur_packet_byte-1)] = (k&0x000000FF); } break; case packet_push_code: case packet_pop_code: case packet_nop_code: break; case packet_char_code: case packet_right_code: case packet_down_code: case packet_node_code: cur_packet_byte+=4; break; case packet_rule_code: cur_packet_byte+=8; break; case packet_special_code: packet_number(k); while (k-- > 0) (void)do_packet_byte(); break; default: pdf_error(maketexstring("vf"), maketexstring("invalid DVI command")); } } } }
void pdf_scope_error(PDF *p, const char *funame) { if (PDF_GET_STATE(p) == pdf_state_error) return; pdf_error(p, PDF_RuntimeError, "function '%s' must not be called in '%s' scope", funame, pdf_current_scope(p)); }
static void pdf_setspotcolor(PDF *p, const char *type, int spotcolor, float tint) { pdf_cstate *cs = &p->cstate[p->sl]; if (spotcolor < 0 || spotcolor >= p->colorspaces_number) pdf_error(p, PDF_ValueError, "Invalid spot color number %d in PDF_setcolor", spotcolor); if (tint < 0.0 || tint > EPSILON ) pdf_error(p, PDF_ValueError, "Bogus spot color tint value (%f) in PDF_setcolor", tint); if (!strcmp(type, "fill") || !strcmp(type, "both")) { if (cs->fill.cs != Separation || cs->fill.val.sep.cs != spotcolor || cs->fill.val.sep.tint != tint) { if (PDF_GET_STATE(p) != pdf_state_document) pdf_printf(p, "/CS%d cs %f scn\n", spotcolor, tint); p->cstate[p->sl].fill.cs = Separation; p->cstate[p->sl].fill.val.sep.cs = spotcolor; p->cstate[p->sl].fill.val.sep.tint = tint; } } if (!strcmp(type, "stroke") || !strcmp(type, "both")) { if (cs->fill.cs != Separation || cs->fill.val.sep.cs != spotcolor || cs->fill.val.sep.tint != tint) { if (PDF_GET_STATE(p) != pdf_state_document) pdf_printf(p, "/CS%d CS %f SCN\n", spotcolor, tint); p->cstate[p->sl].stroke.cs = Separation; p->cstate[p->sl].stroke.val.sep.cs = spotcolor; p->cstate[p->sl].stroke.val.sep.tint = tint; } } p->colorspaces[spotcolor].used_on_current_page = pdf_true; }
/* Finish the pattern definition. */ PDFLIB_API void PDFLIB_CALL PDF_end_pattern(PDF *p) { static const char fn[] = "PDF_end_pattern"; long length; PDF_TRACE(("%s\t(pdf[%p]);\n", fn, (void *) p)); if (PDF_SANITY_CHECK_FAILED(p)) return; PDF_CHECK_SCOPE(p, fn, pdf_state_pattern); /* check whether PDF_save() and PDF_restore() calls are balanced */ if (p->sl > 0) pdf_error(p, PDF_RuntimeError, "Unmatched save level at end of pattern"); pdf_end_text(p); p->contents = c_none; if (p->compresslevel) pdf_compress_end(p); length = pdf_tell(p) - p->start_contents_pos; pdf_end_stream(p); pdf_end_obj(p); /* pattern */ pdf_begin_obj(p, p->contents_length_id); /* Length object */ pdf_printf(p, "%ld\n", length); pdf_end_obj(p); pdf_begin_obj(p, p->res_id); /* Resource object */ pdf_begin_dict(p); /* Resource dict */ pdf_write_page_procsets(p); /* ProcSet resources */ 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_end_dict(p); /* resource dict */ pdf_end_obj(p); /* resource object */ PDF_POP_STATE(p, fn); if (p->flush & PDF_FLUSH_PAGE) pdf_flush_stream(p); }
PDFLIB_API void PDFLIB_CALL PDF_add_thumbnail(PDF *p, int im) { static const char fn[] = "PDF_add_thumbnail"; pdf_image *image; PDF_TRACE(("%s\t(pdf[%p], %d);\n", fn, (void *) p, im)); if (PDF_SANITY_CHECK_FAILED(p)) return; PDF_CHECK_SCOPE(p, fn, pdf_state_page); if (im < 0 || im >= p->images_capacity || !p->images[im].in_use) pdf_error(p, PDF_ValueError, "Bad image number %d in PDF_add_thumbnail", im); if (p->thumb_id != BAD_ID) pdf_error(p, PDF_RuntimeError, "More than one thumbnail for this page (PDF_add_thumbnail)"); image = &p->images[im]; if (image->strips > 1) pdf_error(p, PDF_RuntimeError, "Can't use multi-strip images as thumbnails"); if (image->width > MAX_THUMBNAIL_SIZE || image->height > MAX_THUMBNAIL_SIZE) pdf_error(p, PDF_ValueError, "Thumbnail image larger than %d pixels", MAX_THUMBNAIL_SIZE); if (image->colorspace != DeviceGray && image->colorspace != DeviceRGB && image->colorspace != Indexed) pdf_error(p, PDF_RuntimeError, "Unsupported color space in thumbnail image"); /* Add the image to the thumbnail key of the current page. */ p->thumb_id = p->xobjects[image->no].obj_id; }
PDFLIB_API int PDFLIB_CALL PDF_makespotcolor(PDF *p, const char *spotname, int len) { static const char fn[] = "PDF_makespotcolor"; char *quotedspotname; int ret; PDF_TRACE(("%s\t(pdf[%p], \"%s\");\n", fn, (void *) p, spotname)); if (PDF_SANITY_CHECK_FAILED(p)) return -1; PDF_CHECK_SCOPE(p, fn, pdf_state_ppt | pdf_state_document); if (spotname == NULL || *spotname == 0) pdf_error(p, PDF_ValueError, "Empty spot color name"); if (p->cstate[p->sl].fill.cs == PatternCS || p->cstate[p->sl].fill.cs == Indexed || p->cstate[p->sl].fill.cs == Separation) pdf_error(p, PDF_RuntimeError, "Spot colors can only be based on simple color spaces"); if (len == 0) len = (int) strlen(spotname); if (len > PDF_MAX_SPOTNAME) pdf_error(p, PDF_ValueError, "Spot color name too long"); quotedspotname = (char *) p->malloc(p, (size_t) (3*len + 1), "PDF_makespotcolor"); pdf_make_quoted_name(p, spotname, (size_t) len, quotedspotname); ret = pdf_add_colorspace(p, Separation, quotedspotname); p->free(p, quotedspotname); return ret; }
PDFLIB_API void PDFLIB_CALL PDF_delete(PDF *p) { static const char fn[] = "PDF_delete"; PDF_TRACE(("%s\t(pdf[%p]);\n", fn, (void *) p)); if (PDF_SANITY_CHECK_FAILED(p)) return; if (p->errorhandler == NULL) return; /* nothing to do with dummy PDF struct (see PDF_new2()) */ PDF_CHECK_SCOPE(p, fn, pdf_state_object); /* check whether the caller forgot to fetch the last chunk of data */ if (PDF_GET_STATE(p) != pdf_state_error && pdf_buffer_not_empty(p)) { pdf_error(p, PDF_RuntimeError, "Must call PDF_get_buffer() after PDF_close()"); } /* * Clean up page-related stuff if necessary. Do not raise * an error here since we may be called from the error handler. */ if (PDF_GET_STATE(p) != pdf_state_object) { pdf_cleanup_document(p); } /* close the output stream. * This can't be done in PDF_close() because the caller may fetch * the buffer only after PDF_close()ing the document. */ pdf_close_stream(p); pdf_cleanup_resources(p); /* release the resources tree */ #ifdef HAVE_PDI pdf_cleanup_pdi(p); #endif if (p->binding) p->free(p, p->binding); if (p->prefix) p->free(p, p->prefix); /* free the PDF structure and try to protect against duplicated calls */ p->magic = 0L; /* we don't reach this with the wrong magic */ p->free(p, (void *)p); }
PDFLIB_API void PDFLIB_CALL PDF_set_border_dash(PDF *p, float b, float w) { static const char fn[] = "PDF_set_border_dash"; PDF_TRACE(("%s\t(pdf[%p], %f, %f);\n", fn, (void *) p, b, w)); if (PDF_SANITY_CHECK_FAILED(p)) return; PDF_CHECK_SCOPE(p, fn, pdf_state_document | pdf_state_page); if (b < 0.0) pdf_error(p, PDF_ValueError, "Negative first annotation border dash value %f", b); if (w < 0.0) pdf_error(p, PDF_ValueError, "Negative second annotation border dash value %f", w); p->border_dash1 = b; p->border_dash2 = w; }
int pdf_open_JPEG_data( PDF *p, int imageslot, const char *filename, const char *stringparam, int intparam) { pdf_error(p, PDF_NonfatalError, "JPEG images not supported in this configuration"); return -1; }
static void pdf_setcmykcolor( PDF *p, const char *type, float cyan, float magenta, float yellow, float black) { pdf_cstate *cs = &p->cstate[p->sl]; if (cyan < 0.0 || cyan > EPSILON || magenta < 0.0 || magenta > EPSILON || yellow < 0.0 || yellow > EPSILON || black < 0.0 || black > EPSILON) { pdf_error(p, PDF_NonfatalError, "Bogus CMYK color value (%f/%f/%f/%f) in PDF_setcolor", cyan, magenta, yellow, black); return; } if (!strcmp(type, "fill") || !strcmp(type, "both")) { if (cs->fill.cs != DeviceCMYK || cs->fill.val.cmyk.c != cyan || cs->fill.val.cmyk.m != magenta || cs->fill.val.cmyk.y != yellow || cs->fill.val.cmyk.k != black) { if (PDF_GET_STATE(p) != pdf_state_document) pdf_printf(p, "%f %f %f %f k\n", cyan, magenta, yellow, black); cs->fill.cs = DeviceCMYK; cs->fill.val.cmyk.c = cyan; cs->fill.val.cmyk.m = magenta; cs->fill.val.cmyk.y = yellow; cs->fill.val.cmyk.k = black; } } if (!strcmp(type, "stroke") || !strcmp(type, "both")) { if (cs->stroke.cs != DeviceCMYK || cs->stroke.val.cmyk.c != cyan || cs->stroke.val.cmyk.m != magenta || cs->stroke.val.cmyk.y != yellow || cs->stroke.val.cmyk.k != black) { if (PDF_GET_STATE(p) != pdf_state_document) pdf_printf(p, "%f %f %f %f K\n", cyan, magenta, yellow, black); cs->stroke.cs = DeviceCMYK; cs->stroke.val.cmyk.c = cyan; cs->stroke.val.cmyk.m = magenta; cs->stroke.val.cmyk.y = yellow; cs->stroke.val.cmyk.k = black; } } }
void pdf_cleanup_page_annots(PDF *p) { pdf_annot *ann, *old; for (ann = p->annots; ann != (pdf_annot *) NULL; /* */ ) { switch (ann->type) { case ann_text: if (ann->contents) p->free(p, ann->contents); if (ann->title) p->free(p, ann->title); break; case ann_locallink: break; case ann_launchlink: p->free(p, ann->filename); break; case ann_pdflink: p->free(p, ann->filename); break; case ann_weblink: p->free(p, ann->filename); break; case ann_attach: p->free(p, ann->filename); if (ann->contents) p->free(p, ann->contents); if (ann->title) p->free(p, ann->title); if (ann->mimetype) p->free(p, ann->mimetype); break; default: pdf_error(p, PDF_SystemError, "Unknown annotation type %d", ann->type); } old = ann; ann = old->next; p->free(p, old); } p->annots = NULL; }
/* Allocate a PDFlib-local buffer and copy the string including * the terminating sentinel. If the string starts with the Unicode BOM * it is considered a Unicode string, and must be terminated by * two null bytes. Otherwise it is considered a plain C string and * must be terminated by a single null byte. * The caller is responsible for freeing the buffer. */ char * pdf_strdup(PDF *p, const char *text) { char *buf; size_t len; if (text == NULL) pdf_error(p, PDF_SystemError, "NULL string in pdf_strdup"); len = pdf_strlen(text); buf = (char *) p->malloc(p, len, "pdf_strdup"); memcpy(buf, text, len); return buf; }
void pdf_compress_end(PDF *p) { int status; /* Finish the stream */ do { pdf_check_stream(p, 128); p->stream.z.next_out = (Bytef *) p->stream.curpos; p->stream.z.avail_out = (uInt) (p->stream.maxpos - p->stream.curpos); status = deflate(&(p->stream.z), Z_FINISH); p->stream.curpos = p->stream.z.next_out; if (status != Z_STREAM_END && status != Z_OK) pdf_error(p, PDF_SystemError, "Compression error (Z_FINISH)"); } while (status != Z_STREAM_END); if (deflateEnd(&p->stream.z) != Z_OK) pdf_error(p, PDF_SystemError, "Compression error (deflateEnd)"); p->stream.compress = pdf_false; }
PDFLIB_API void PDFLIB_CALL PDF_setgray(PDF *p, float g) { if (PDF_SANITY_CHECK_FAILED(p)) return; if (g < 0.0 || g > EPSILON ) { pdf_error(p, PDF_NonfatalError, "Bogus gray value (%f) in PDF_setgray", g); return; } PDF_setgray_stroke(p, g); PDF_setgray_fill(p, g); }
static void pdf_free(PDF *p, void *mem) { #ifdef DEBUG if (p->debug['f']) fprintf(stderr, "%x freed, page %d\n", (int) mem, p->current_page); #endif /* We mustn't raise a fatal error here to avoid potential recursion */ if (mem == NULL) { pdf_error(p, PDF_NonfatalError, "(Internal) Tried to free null pointer"); return; } free(mem); }
static void * pdf_realloc(PDF *p, void *mem, size_t size, const char *caller) { void *ret; if ((ret = realloc(mem, size)) == NULL) { pdf_error(p, PDF_MemoryError, "Couldn't reallocate memory in %s!\n", caller); } #ifdef DEBUG if (p->debug['r']) fprintf(stderr, "%x realloced to %x, %d from %s, page %d\n", (int) mem, (int) ret, (int) size, caller, p->current_page); #endif return ret; }