void epdf_document_delete(Epdf_Document* doc) { if(!doc) return; if(doc->outline) { pdf_dropoutline(doc->outline); doc->outline = NULL; } if(doc->xref->store) { pdf_dropstore(doc->xref->store); doc->xref->store = NULL; } pdf_closexref(doc->xref); doc->xref = NULL; if(doc->rast) { fz_droprenderer(doc->rast); doc->rast = NULL; } free(doc); }
static void pdfClose(PDFContext* ctx) { if (ctx->page) pdf_droppage(ctx->page); ctx->page = 0; if (ctx->pages) pdf_droppagetree(ctx->pages); ctx->pages = 0; /*if (ctx->image) fz_droppixmap(ctx->image); ctx->image = nil;*/ if (ctx->outline) pdf_dropoutline(ctx->outline); ctx->outline = 0; if (ctx->xref->store) pdf_dropstore(ctx->xref->store); ctx->xref->store = 0; pdf_closexref(ctx->xref); ctx->xref = 0; if (ctx->rast) fz_droprenderer(ctx->rast); ctx->rast = 0; //printf("alloc_current = %d\n", (int)alloc_current); }
void drawmain(int argc, char **argv) { fz_error *error; char *password = ""; int c; enum { NO_FILE_OPENED, NO_PAGES_DRAWN, DREW_PAGES } state; while ((c = getopt(argc, argv, "b:d:o:r:txm")) != -1) { switch (c) { case 'b': drawbands = atoi(optarg); break; case 'd': password = optarg; break; case 'o': drawpattern = optarg; break; case 'r': drawzoom = (float)(atof(optarg) / 72.0); break; case 't': drawmode = DRAWTXT; break; case 'x': drawmode = DRAWXML; break; case 'm': benchmark = 1; break; default: drawusage(); break; } } if (optind == argc) drawusage(); error = fz_newrenderer(&drawgc, pdf_devicergb, 0, 1024 * 512); if (error) die(error); state = NO_FILE_OPENED; while (optind < argc) { if (strstr(argv[optind], ".pdf")) { if (state == NO_PAGES_DRAWN) drawpages("1-"); opensrc(argv[optind], password, 1); state = NO_PAGES_DRAWN; } else { drawpages(argv[optind]); state = DREW_PAGES; } optind++; } if (state == NO_PAGES_DRAWN) drawpages("1-"); closesrc(); fz_droprenderer(drawgc); }
void die(fz_error *eo) { fflush(stdout); fz_printerror(eo); fz_droperror(eo); fflush(stderr); if (drawgc) fz_droprenderer(drawgc); closesrc(); abort(); }
static void local_cleanup(void) { if (xref && xref->store) { pdf_dropstore(xref->store); xref->store = nil; } if (drawgc) { fz_droprenderer(drawgc); drawgc = nil; } }
fz_error fz_rendert3glyph(fz_glyph *glyph, fz_font *font, int gid, fz_matrix trm) { fz_error error; fz_renderer *gc; fz_tree *tree; fz_matrix ctm; fz_irect bbox; /* TODO: make it reentrant */ static fz_pixmap *pixmap = nil; if (pixmap) { fz_droppixmap(pixmap); pixmap = nil; } if (gid < 0 || gid > 255) return fz_throw("assert: glyph out of range"); tree = font->t3procs[gid]; if (!tree) { glyph->w = 0; glyph->h = 0; return fz_okay; } ctm = fz_concat(font->t3matrix, trm); bbox = fz_roundrect(fz_boundtree(tree, ctm)); error = fz_newrenderer(&gc, pdf_devicegray, 1, 4096); if (error) return fz_rethrow(error, "cannot create renderer"); error = fz_rendertree(&pixmap, gc, tree, ctm, bbox, 0); fz_droprenderer(gc); if (error) return fz_rethrow(error, "cannot render glyph"); assert(pixmap->n == 1); glyph->x = pixmap->x; glyph->y = pixmap->y; glyph->w = pixmap->w; glyph->h = pixmap->h; glyph->samples = pixmap->samples; return fz_okay; }
static fz_error * t3render(fz_glyph *glyph, fz_font *fzfont, int cid, fz_matrix trm) { pdf_font *font = (pdf_font*)fzfont; fz_error *error; fz_renderer *gc; fz_tree *tree; fz_pixmap *pixmap; fz_matrix ctm; fz_irect bbox; if (cid < 0 || cid > 255) return fz_throw("assert: glyph out of range"); tree = font->charprocs[cid]; if (!tree) { glyph->w = 0; glyph->h = 0; return fz_okay; } ctm = fz_concat(font->matrix, trm); bbox = fz_roundrect(fz_boundtree(tree, ctm)); error = fz_newrenderer(&gc, pdf_devicegray, 1, GCMEM); if (error) return fz_rethrow(error, "cannot create renderer"); error = fz_rendertree(&pixmap, gc, tree, ctm, bbox, 0); fz_droprenderer(gc); if (error) return fz_rethrow(error, "cannot render glyph"); assert(pixmap->n == 1); glyph->x = pixmap->x; glyph->y = pixmap->y; glyph->w = pixmap->w; glyph->h = pixmap->h; glyph->samples = pixmap->samples; return fz_okay; }
void drawmain(int argc, char **argv) { fz_error *error; char *password = ""; int c; while ((c = getopt(argc, argv, "b:d:o:r:tx")) != -1) { switch (c) { case 'b': drawbands = atoi(optarg); break; case 'd': password = optarg; break; case 'o': drawpattern = optarg; break; case 'r': drawzoom = atof(optarg) / 72.0; break; case 't': drawmode = DRAWTXT; break; case 'x': drawmode = DRAWXML; break; default: drawusage(); break; } } if (optind == argc) drawusage(); error = fz_newrenderer(&drawgc, pdf_devicergb, 0, 1024 * 512); if (error) die(error); while (optind < argc) { if (strstr(argv[optind], ".pdf")) opensrc(argv[optind], password, 1); else drawpages(argv[optind]); optind++; } closesrc(); fz_droprenderer(drawgc); }