Ejemplo n.º 1
0
static void
text_drop_writer(fz_context *ctx, fz_document_writer *wri_)
{
	fz_text_writer *wri = (fz_text_writer*)wri_;
	fz_drop_stext_page(ctx, wri->page);
	fz_drop_output(ctx, wri->out);
}
Ejemplo n.º 2
0
fz_document_writer *
fz_new_pwg_writer(fz_context *ctx, const char *path, const char *options)
{
	fz_pwg_writer *wri = fz_new_derived_document_writer(ctx, fz_pwg_writer, pwg_begin_page, pwg_end_page, pwg_close_writer, pwg_drop_writer);
	const char *val;

	fz_try(ctx)
	{
		fz_parse_draw_options(ctx, &wri->draw, options);
		fz_parse_pwg_options(ctx, &wri->pwg, options);
		if (fz_has_option(ctx, options, "colorspace", &val))
			if (fz_option_eq(val, "mono"))
				wri->mono = 1;
		wri->out = fz_new_output_with_path(ctx, path ? path : "out.pwg", 0);
		fz_write_pwg_file_header(ctx, wri->out);
	}
	fz_catch(ctx)
	{
		fz_drop_output(ctx, wri->out);
		fz_free(ctx, wri);
		fz_rethrow(ctx);
	}

	return (fz_document_writer*)wri;
}
Ejemplo n.º 3
0
void
fz_write_pcl_bitmap(fz_context *ctx, fz_bitmap *bitmap, char *filename, int append, fz_pcl_options *pcl)
{
	FILE *fp;
	fz_output *out = NULL;

	fp = fopen(filename, append ? "ab" : "wb");
	if (!fp)
	{
		fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno));
	}

	fz_var(out);

	fz_try(ctx)
	{
		out = fz_new_output_with_file(ctx, fp, 1);
		fz_output_pcl_bitmap(ctx, out, bitmap, pcl);
	}
	fz_always(ctx)
	{
		fz_drop_output(ctx, out);
	}
	fz_catch(ctx)
	{
		fz_rethrow(ctx);
	}
}
Ejemplo n.º 4
0
void
fz_write_pwg(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, const fz_pwg_options *pwg)
{
	FILE *fp;
	fz_output *out = NULL;

	fp = fopen(filename, append ? "ab" : "wb");
	if (!fp)
	{
		fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno));
	}

	fz_var(out);

	fz_try(ctx)
	{
		out = fz_new_output_with_file(ctx, fp, 1);
		if (!append)
			fz_output_pwg_file_header(ctx, out);
		fz_output_pwg_page(ctx, out, pixmap, pwg);
	}
	fz_always(ctx)
	{
		fz_drop_output(ctx, out);
	}
	fz_catch(ctx)
	{
		fz_rethrow(ctx);
	}
}
Ejemplo n.º 5
0
static void
pwg_drop_writer(fz_context *ctx, fz_document_writer *wri_)
{
	fz_pwg_writer *wri = (fz_pwg_writer*)wri_;
	fz_drop_pixmap(ctx, wri->pixmap);
	fz_drop_output(ctx, wri->out);
}
Ejemplo n.º 6
0
void
fz_save_pixmap_as_pnm(fz_context *ctx, fz_pixmap *pixmap, char *filename)
{
	fz_output *out = fz_new_output_with_path(ctx, filename, 0);
	fz_write_pnm_header(ctx, out, pixmap->w, pixmap->h, pixmap->n, pixmap->alpha);
	fz_write_pnm_band(ctx, out, pixmap->w, pixmap->h, pixmap->n, pixmap->alpha, pixmap->stride, 0, pixmap->h, pixmap->samples);
	fz_drop_output(ctx, out);
}
Ejemplo n.º 7
0
void fz_save_pixmap_as_ps(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append)
{
	fz_output *out = fz_new_output_with_path(ctx, filename, append);
	fz_try(ctx)
		fz_write_pixmap_as_ps(ctx, out, pixmap);
	fz_always(ctx)
		fz_drop_output(ctx, out);
	fz_catch(ctx)
		fz_rethrow(ctx);
}
Ejemplo n.º 8
0
void
fz_save_buffer(fz_context *ctx, fz_buffer *buf, const char *filename)
{
	fz_output *out = fz_new_output_with_path(ctx, filename, 0);
	fz_try(ctx)
		fz_write(ctx, out, buf->data, buf->len);
	fz_always(ctx)
		fz_drop_output(ctx, out);
	fz_catch(ctx)
		fz_rethrow(ctx);
}
Ejemplo n.º 9
0
static void
svg_dev_drop_imp(fz_context *ctx, fz_device *dev)
{
	svg_device *sdev = (svg_device*)dev;
	fz_output *out = sdev->out;

	fz_free(ctx, sdev->tiles);
	fz_drop_buffer(ctx, sdev->defs_buffer);
	fz_drop_output(ctx, sdev->defs);

	fz_printf(ctx, out, "</svg>\n");
}
Ejemplo n.º 10
0
void
fz_save_bitmap_as_pwg(fz_context *ctx, fz_bitmap *bitmap, char *filename, int append, const fz_pwg_options *pwg)
{
	fz_output *out = fz_new_output_with_path(ctx, filename, append);
	fz_try(ctx)
	{
		if (!append)
			fz_write_pwg_file_header(ctx, out);
		fz_write_bitmap_as_pwg_page(ctx, out, bitmap, pwg);
	}
	fz_always(ctx)
		fz_drop_output(ctx, out);
	fz_catch(ctx)
		fz_rethrow(ctx);
}
Ejemplo n.º 11
0
void
fz_drop_output_context(fz_context *ctx)
{
	if (!ctx)
		return;

	if (fz_drop_imp(ctx, ctx->output, &ctx->output->refs))
	{
		fz_try(ctx)
			fz_flush_output(ctx, ctx->output->out);
		fz_catch(ctx)
			fz_warn(ctx, "cannot flush stdout");
		fz_drop_output(ctx, ctx->output->out);

		fz_try(ctx)
			fz_flush_output(ctx, ctx->output->err);
		fz_catch(ctx)
			fz_warn(ctx, "cannot flush stderr");
		fz_drop_output(ctx, ctx->output->err);

		fz_free(ctx, ctx->output);
		ctx->output = NULL;
	}
}
Ejemplo n.º 12
0
pdf_processor *
pdf_new_buffer_processor(fz_context *ctx, fz_buffer *buffer)
{
	pdf_processor *proc;
	fz_output *out = fz_new_output_with_buffer(ctx, buffer);
	fz_try(ctx)
	{
		proc = pdf_new_output_processor(ctx, out);
	}
	fz_catch(ctx)
	{
		fz_drop_output(ctx, out);
		fz_rethrow(ctx);
	}
	return proc;
}
Ejemplo n.º 13
0
static void
svg_dev_drop_device(fz_context *ctx, fz_device *dev)
{
	svg_device *sdev = (svg_device*)dev;
	int i;

	fz_free(ctx, sdev->tiles);
	fz_drop_buffer(ctx, sdev->defs_buffer);
	fz_drop_output(ctx, sdev->defs);
	for (i = 0; i < sdev->num_fonts; i++)
	{
		fz_drop_font(ctx, sdev->fonts[i].font);
		fz_free(ctx, sdev->fonts[i].sentlist);
	}
	fz_free(ctx, sdev->fonts);
}
Ejemplo n.º 14
0
int pdfpages_main(int argc, char **argv)
{
	char *filename = "";
	char *password = "";
	int c;
	fz_output *out = NULL;
	int ret;
	fz_context *ctx;

	while ((c = fz_getopt(argc, argv, "p:")) != -1)
	{
		switch (c)
		{
		case 'p': password = fz_optarg; break;
		default:
			infousage();
			break;
		}
	}

	if (fz_optind == argc)
		infousage();

	ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
	if (!ctx)
	{
		fprintf(stderr, "cannot initialise context\n");
		exit(1);
	}

	fz_var(out);

	ret = 0;
	fz_try(ctx)
	{
		out = fz_stdout(ctx);
		ret = pdfpages_pages(ctx, out, filename, password, &argv[fz_optind], argc-fz_optind);
	}
	fz_catch(ctx)
	{
		ret = 1;
	}
	fz_drop_output(ctx, out);
	fz_drop_context(ctx);
	return ret;
}
Ejemplo n.º 15
0
fz_document_writer *
fz_new_text_writer(fz_context *ctx, const char *format, const char *path, const char *args)
{
	fz_text_writer *wri;

	wri = fz_new_derived_document_writer(ctx, fz_text_writer, text_begin_page, text_end_page, text_close_writer, text_drop_writer);
	fz_try(ctx)
	{
		fz_parse_stext_options(ctx, &wri->opts, args);

		wri->format = FZ_FORMAT_TEXT;
		if (!strcmp(format, "text"))
			wri->format = FZ_FORMAT_TEXT;
		else if (!strcmp(format, "html"))
			wri->format = FZ_FORMAT_HTML;
		else if (!strcmp(format, "xhtml"))
			wri->format = FZ_FORMAT_XHTML;
		else if (!strcmp(format, "stext"))
			wri->format = FZ_FORMAT_STEXT;

		wri->out = fz_new_output_with_path(ctx, path ? path : "out.txt", 0);

		switch (wri->format)
		{
		case FZ_FORMAT_HTML:
			fz_print_stext_header_as_html(ctx, wri->out);
			break;
		case FZ_FORMAT_XHTML:
			fz_print_stext_header_as_xhtml(ctx, wri->out);
			break;
		case FZ_FORMAT_STEXT:
			fz_write_string(ctx, wri->out, "<?xml version=\"1.0\"?>\n");
			fz_write_string(ctx, wri->out, "<document>\n");
			break;
		}
	}
	fz_catch(ctx)
	{
		fz_drop_output(ctx, wri->out);
		fz_free(ctx, wri);
		fz_rethrow(ctx);
	}

	return (fz_document_writer*)wri;
}
Ejemplo n.º 16
0
void
fz_save_pixmap_as_pam(fz_context *ctx, fz_pixmap *pixmap, const char *filename)
{
	fz_band_writer *writer = NULL;
	fz_output *out = fz_new_output_with_path(ctx, filename, 0);

	fz_var(writer);

	fz_try(ctx)
	{
		writer = fz_new_pam_band_writer(ctx, out);
		fz_write_header(ctx, writer, pixmap->w, pixmap->h, pixmap->n, pixmap->alpha, 0, 0, 0, pixmap->colorspace, pixmap->seps);
		fz_write_band(ctx, writer, pixmap->stride, pixmap->h, pixmap->samples);
	}
	fz_always(ctx)
	{
		fz_drop_band_writer(ctx, writer);
		fz_drop_output(ctx, out);
	}
	fz_catch(ctx)
		fz_rethrow(ctx);
}
Ejemplo n.º 17
0
Archivo: output.c Proyecto: HCLAC/mupdf
void
fz_set_stderr(fz_context *ctx, fz_output *err)
{
	fz_drop_output(ctx, ctx->output->err);
	ctx->output->err = err ? err : &fz_stderr_global;
}
Ejemplo n.º 18
0
Archivo: output.c Proyecto: HCLAC/mupdf
void
fz_set_stdout(fz_context *ctx, fz_output *out)
{
	fz_drop_output(ctx, ctx->output->out);
	ctx->output->out = out ? out : &fz_stdout_global;
}
Ejemplo n.º 19
0
static void
pdf_drop_imp_output_processor(fz_context *ctx, pdf_processor *proc)
{
	fz_output *out = ((pdf_output_processor*)proc)->out;
	fz_drop_output(ctx, out);
}
Ejemplo n.º 20
0
/* dest points to the new pages content-streams-dict, src is a reference to 
   one source content-stream */
int copy_content_stream_of_page(fz_context *dest_ctx, pdf_obj *dest, 
	fz_context *src_ctx, pdf_obj *src, 
	struct put_info *info, struct pos_info *pos)
{
	if(!pdf_is_array(dest_ctx, dest) && !pdf_is_indirect(src_ctx, src))
		return(-1);

	/*
	  translation:  1     0    0    1     diff_x diff_y
	  scale:        scale 0    0    scale 0      0
	  rotation:     cos   sin  -sin cos   0      0
	  -------------------------------------------------
	  rotation 0:   1     0    0    1     0      0
	  rotation 90:  0     1    -1   0     0      0
	  rotation 180: -1    0    0    -1    0      0
	  rotation 270: 0     -1   1    0     0      0 
	*/

	fz_buffer *buffer = fz_new_buffer(dest_ctx, 1024);
	fz_output *output = fz_new_output_with_buffer(dest_ctx, buffer);

	fz_printf(dest_ctx, output, "q\n");

	/* set the outer clip region */
	fz_printf(dest_ctx, output, "%f %f %f %f re W n\n", 
		pos->outer_clip_x, pos->outer_clip_y, 
		pos->outer_clip_width, pos->outer_clip_height);

	/* position the page correctly */
	if(pos->rotate == 0) {
		fz_printf(dest_ctx, output, "1 0 0 1 %f %f cm\n", 
			pos->x + pos->content_translate_x, pos->y + pos->content_translate_y);
	} else if(pos->rotate == 90) {
		fz_printf(dest_ctx, output, "0 1 -1 0 %f %f cm\n", pos->x + pos->width, pos->y);
	} else if(pos->rotate == 180) {
		fz_printf(dest_ctx, output, "-1 0 0 -1 %f %f cm\n", 
			pos->width + pos->x - pos->content_translate_x, 
			pos->height + pos->y - pos->content_translate_y);
	} else if(pos->rotate == 270) {
		fz_printf(dest_ctx, output, "0 -1 1 0 %f %f cm\n", pos->x, pos->y + pos->height);
	}
	
	if(pos->bleed_clip_x != 0.0 || pos->bleed_clip_y != 0.0 || 
		pos->bleed_clip_width != 0.0 || pos->bleed_clip_height != 0.0)
	{
		fz_printf(dest_ctx, output, "%f %f %f %f re W n\n", 
			pos->bleed_clip_x, pos->bleed_clip_y, pos->bleed_clip_width, pos->bleed_clip_height);
	}

 	int src_num = pdf_to_num(src_ctx, src);
	int src_gen = pdf_to_gen(src_ctx, src);
	fz_stream *input = pdf_open_stream(src_ctx, info->src_doc, src_num, src_gen);

	rename_res_in_content_stream(src_ctx, input, dest_ctx, output, info->rename_dict);

	fz_printf(dest_ctx, output, "Q");

	fz_drop_output(dest_ctx, output);
	fz_drop_stream(dest_ctx, input);
	
	int new_num = pdf_create_object(dest_ctx, info->dest_doc);
	pdf_obj *new_ref = pdf_new_indirect(dest_ctx, info->dest_doc, new_num, 0);

	/* each stream has a dict containing at least its length... */
	pdf_obj *stream_info_dict = pdf_new_dict(dest_ctx, info->dest_doc, 1);
	pdf_dict_puts_drop(dest_ctx, stream_info_dict, "Length", pdf_new_int(dest_ctx, info->dest_doc, buffer->len));
	pdf_update_object(dest_ctx, info->dest_doc, new_num, stream_info_dict);
	pdf_drop_obj(dest_ctx, stream_info_dict);

	pdf_update_stream(dest_ctx, info->dest_doc, new_ref, buffer, 0);
	fz_drop_buffer(dest_ctx, buffer);

	pdf_array_push(dest_ctx, dest, new_ref);
	pdf_drop_obj(dest_ctx, new_ref);

	return(0);
}
Ejemplo n.º 21
0
static void savefont(pdf_obj *dict, int num)
{
	char namebuf[1024];
	fz_buffer *buf;
	pdf_obj *stream = NULL;
	pdf_obj *obj;
	char *ext = "";
	fz_output *out;
	char *fontname = "font";
	size_t len;
	unsigned char *data;

	obj = pdf_dict_get(ctx, dict, PDF_NAME_FontName);
	if (obj)
		fontname = pdf_to_name(ctx, obj);

	obj = pdf_dict_get(ctx, dict, PDF_NAME_FontFile);
	if (obj)
	{
		stream = obj;
		ext = "pfa";
	}

	obj = pdf_dict_get(ctx, dict, PDF_NAME_FontFile2);
	if (obj)
	{
		stream = obj;
		ext = "ttf";
	}

	obj = pdf_dict_get(ctx, dict, PDF_NAME_FontFile3);
	if (obj)
	{
		stream = obj;

		obj = pdf_dict_get(ctx, obj, PDF_NAME_Subtype);
		if (obj && !pdf_is_name(ctx, obj))
			fz_throw(ctx, FZ_ERROR_GENERIC, "invalid font descriptor subtype");

		if (pdf_name_eq(ctx, obj, PDF_NAME_Type1C))
			ext = "cff";
		else if (pdf_name_eq(ctx, obj, PDF_NAME_CIDFontType0C))
			ext = "cid";
		else if (pdf_name_eq(ctx, obj, PDF_NAME_OpenType))
			ext = "otf";
		else
			fz_throw(ctx, FZ_ERROR_GENERIC, "unhandled font type '%s'", pdf_to_name(ctx, obj));
	}

	if (!stream)
	{
		fz_warn(ctx, "unhandled font type");
		return;
	}

	buf = pdf_load_stream(ctx, doc, pdf_to_num(ctx, stream));
	len = fz_buffer_storage(ctx, buf, &data);
	fz_try(ctx)
	{
		snprintf(namebuf, sizeof(namebuf), "%s-%04d.%s", fontname, num, ext);
		printf("extracting font %s\n", namebuf);
		out = fz_new_output_with_path(ctx, namebuf, 0);
		fz_try(ctx)
			fz_write(ctx, out, data, len);
		fz_always(ctx)
			fz_drop_output(ctx, out);
		fz_catch(ctx)
			fz_rethrow(ctx);
	}
	fz_always(ctx)
		fz_drop_buffer(ctx, buf);
	fz_catch(ctx)
		fz_rethrow(ctx);
}
Ejemplo n.º 22
0
void
fz_save_gproof(fz_context *ctx, const char *pdf_file, fz_document *doc, const char *filename, int res,
				const char *print_profile, const char *display_profile)
{
	int i;
	int num_pages = fz_count_pages(ctx, doc);
	fz_output *out;
	fz_page *page = NULL;

	fz_var(page);

	if (num_pages <= 0)
		fz_throw(ctx, FZ_ERROR_GENERIC, "Cannot write a 0 page GProof skeleton file");

	out = fz_new_output_with_path(ctx, filename, 0);

	fz_try(ctx)
	{
		/* File Signature: GPRO */
		fz_write_int32_le(ctx, out, 0x4f525047);

		/* Version = 1 */
		fz_write_byte(ctx, out, 1);
		fz_write_byte(ctx, out, 0);

		/* Resolution */
		fz_write_int32_le(ctx, out, res);

		/* Num Pages */
		fz_write_int32_le(ctx, out, num_pages);

		for (i = 0; i < num_pages; i++)
		{
			fz_rect rect;
			int w, h;

			page = fz_load_page(ctx, doc, i);
			fz_bound_page(ctx, page, &rect);
			fz_drop_page(ctx, page);
			page = NULL;

			/* Same lack of rounding as gs uses */
			w = (int)((rect.x1 - rect.x0) * res / 72.0);
			h = (int)((rect.y1 - rect.y0) * res / 72.0);
			fz_write_int32_le(ctx, out, w);
			fz_write_int32_le(ctx, out, h);
		}

		/* Filenames */
		fz_write(ctx, out, pdf_file, strlen(pdf_file)+1);
		fz_write(ctx, out, print_profile, strlen(print_profile) + 1);
		fz_write(ctx, out, display_profile, strlen(display_profile) + 1);

	}
	fz_always(ctx)
	{
		fz_drop_page(ctx, page);
		fz_drop_output(ctx, out);
	}
	fz_catch(ctx)
	{
		fz_rethrow(ctx);
	}
}