Пример #1
0
int
xps_open_stream(xps_context **ctxp, fz_stream *file)
{
	xps_context *ctx;
	int code;

	ctx = fz_malloc(file->ctx, sizeof(xps_context));
	memset(ctx, 0, sizeof(xps_context));

	ctx->ctx = file->ctx;
	ctx->file = fz_keep_stream(file);

	code = xps_find_and_read_zip_dir(ctx);
	if (code < 0)
	{
		xps_free_context(ctx);
		return fz_error_note(file->ctx, code, "cannot read zip central directory");
	}

	code = xps_read_page_list(ctx);
	if (code)
	{
		xps_free_context(ctx);
		return fz_error_note(file->ctx, code, "cannot read page list");
	}

	*ctxp = ctx;
	return fz_okay;
}
Пример #2
0
void pdfapp_close(pdfapp_t *app)
{
	if (app->cache)
		fz_free_glyph_cache(app->cache);
	app->cache = NULL;

	if (app->image)
		fz_drop_pixmap(app->image);
	app->image = NULL;

	if (app->outline)
		pdf_free_outline(app->outline);
	app->outline = NULL;

	if (app->xref)
	{
		if (app->xref->store)
			pdf_free_store(app->xref->store);
		app->xref->store = NULL;

		pdf_free_xref(app->xref);
		app->xref = NULL;
	}

	if (app->xps)
	{
		xps_free_context(app->xps);
		app->xps = NULL;
	}

	fz_flush_warnings();
}
Пример #3
0
static int
xps_open_directory(fz_context *fctx, xps_context **ctxp, char *directory)
{
	xps_context *ctx;
	int code;

	ctx = fz_malloc(fctx, sizeof(xps_context));
	memset(ctx, 0, sizeof(xps_context));

	ctx->directory = fz_strdup(fctx, directory);
	ctx->ctx = fctx;

	code = xps_read_page_list(ctx);
	if (code)
	{
		xps_free_context(ctx);
		return fz_error_note(fctx, code, "cannot read page list");
	}

	*ctxp = ctx;
	return fz_okay;
}
Пример #4
0
int main(int argc, char **argv)
{
	int grayscale = 0;
	int accelerate = 1;
	xps_context *ctx;
	int code;
	int c;

	while ((c = fz_getopt(argc, argv, "o:p:r:Aadglmtx5")) != -1)
	{
		switch (c)
		{
		case 'o': output = fz_optarg; break;
		case 'r': resolution = atof(fz_optarg); break;
		case 'A': accelerate = 0; break;
		case 'a': savealpha = 1; break;
		case 'l': showoutline++; break;
		case 'm': showtime++; break;
		case 't': showtext++; break;
		case 'x': showxml++; break;
		case '5': showmd5++; break;
		case 'g': grayscale++; break;
		case 'd': uselist = 0; break;
		default: usage(); break;
		}
	}

	if (fz_optind == argc)
		usage();

	if (!showtext && !showxml && !showtime && !showmd5 && !showoutline && !output)
	{
		printf("nothing to do\n");
		exit(0);
	}

	if (accelerate)
		fz_accelerate();

	glyphcache = fz_new_glyph_cache();

	colorspace = fz_device_rgb;
	if (grayscale)
		colorspace = fz_device_gray;
	if (output && strstr(output, ".pgm"))
		colorspace = fz_device_gray;
	if (output && strstr(output, ".ppm"))
		colorspace = fz_device_rgb;

	timing.count = 0;
	timing.total = 0;
	timing.min = 1 << 30;
	timing.max = 0;
	timing.minpage = 0;
	timing.maxpage = 0;

	if (showxml)
		printf("<?xml version=\"1.0\"?>\n");

	while (fz_optind < argc)
	{
		filename = argv[fz_optind++];

		code = xps_open_file(&ctx, filename);
		if (code)
			die(fz_rethrow(code, "cannot open document: %s", filename));

		if (showxml)
			printf("<document name=\"%s\">\n", filename);

		if (showoutline)
			drawoutline(ctx);

		if (showtext || showxml || showtime || showmd5 || output)
		{
			if (fz_optind == argc || !isrange(argv[fz_optind]))
				drawrange(ctx, "1-");
			if (fz_optind < argc && isrange(argv[fz_optind]))
				drawrange(ctx, argv[fz_optind++]);
		}

		if (showxml)
			printf("</document>\n");

		xps_free_context(ctx);
	}

	if (showtime)
	{
		printf("total %dms / %d pages for an average of %dms\n",
			timing.total, timing.count, timing.total / timing.count);
		printf("fastest page %d: %dms\n", timing.minpage, timing.min);
		printf("slowest page %d: %dms\n", timing.maxpage, timing.max);
	}

	fz_free_glyph_cache(glyphcache);

	return 0;
}