コード例 #1
0
ファイル: svg-device.c プロジェクト: haggl/mupdf
static void
svg_dev_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha)
{
	svg_device *sdev = (svg_device *)dev->user;
	fz_context *ctx = dev->ctx;
	fz_output *out = sdev->out;
	fz_matrix local_ctm = *ctm;
	fz_matrix scale = { 1.0f/image->w, 0, 0, 1.0f/image->h, 0, 0};

	fz_concat(&local_ctm, &scale, ctm);
	fz_printf(out, "<image");
	svg_dev_ctm(sdev, &local_ctm);
	fz_printf(out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h);
	switch (image->buffer == NULL ? FZ_IMAGE_JPX : image->buffer->params.type)
	{
	case FZ_IMAGE_JPEG:
		fz_printf(out, "image/jpeg;base64,");
		send_data_base64(out, image->buffer->buffer);
		break;
	case FZ_IMAGE_PNG:
		fz_printf(out, "image/png;base64,");
		send_data_base64(out, image->buffer->buffer);
		break;
	default:
		{
			fz_buffer *buf = fz_image_as_png(ctx, image, image->w, image->h);
			fz_printf(out, "image/png;base64,");
			send_data_base64(out, buf);
			fz_drop_buffer(ctx, buf);
			break;
		}
	}
	fz_printf(out, "\"/>\n");
}
コード例 #2
0
ファイル: svg-device.c プロジェクト: haggl/mupdf
static void
svg_dev_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, const fz_matrix *ctm,
	fz_colorspace *colorspace, float *color, float alpha)
{
	svg_device *sdev = dev->user;
	fz_output *out = sdev->out;

	fz_printf(out, "<text");
	svg_dev_ctm(sdev, ctm);
	svg_dev_stroke_state(sdev, stroke);
	svg_dev_stroke_color(sdev, colorspace, color, alpha);
	svg_dev_text(sdev, ctm, text);
}
コード例 #3
0
ファイル: svg-device.c プロジェクト: ArphonePei/PDFConverter
static int
svg_dev_begin_tile(fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id)
{
	svg_device *sdev = (svg_device *)dev->user;
	fz_output *out = sdev->out;
	fz_context *ctx = dev->ctx;
	fz_matrix inverse;
	int num;
	tile *t;

	if (sdev->num_tiles == sdev->max_tiles)
	{
		int n = (sdev->num_tiles == 0 ? 4 : sdev->num_tiles * 2);

		sdev->tiles = fz_resize_array(ctx, sdev->tiles, n, sizeof(tile));
		sdev->max_tiles = n;
	}
	num = sdev->num_tiles++;
	t = &sdev->tiles[num];
	t->area = *area;
	t->view = *view;
	t->ctm = *ctm;
	t->pattern = sdev->id++;
	t->step.x = xstep;
	t->step.y = ystep;

	/* view = area of our reference tile in pattern space.
	 * area = area to tile into in pattern space.
	 * xstep/ystep = pattern repeat step in pattern space.
	 * All of these need to be transformed by ctm to get to device space.
	 * SVG only allows us to specify pattern tiles as axis aligned
	 * rectangles, so we send these through as is, and ensure that the
	 * correct matrix is used on the fill.
	 */

	/* In svg, the reference tile is taken from (x,y) to (x+width,y+height)
	 * and is repeated at (x+n*width,y+m*height) for all integer n and m.
	 * This means that width and height correspond to xstep and ystep. */
	fz_printf(out, "<pattern id=\"pa%d\" patternUnits=\"userSpaceOnUse\" patternContentUnits=\"userSpaceOnUse\"",
		t->pattern);
	fz_printf(out, " x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\">\n",
		view->x0, view->y0, xstep, ystep);
	/* All the pattern contents will have their own ctm applied. Let's
	 * undo the current one to allow for this */
	fz_invert_matrix(&inverse, ctm);
	fz_printf(out, "<g");
	svg_dev_ctm(sdev, &inverse);
	fz_printf(out, ">\n");

	return 0;
}
コード例 #4
0
ファイル: svg-device.c プロジェクト: songtzu/mupdf-4
static void
svg_dev_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm,
	fz_colorspace *colorspace, float *color, float alpha)
{
	svg_device *sdev = (svg_device*)dev;
	fz_output *out = sdev->out;

	fz_printf(ctx, out, "<path");
	svg_dev_ctm(ctx, sdev, ctm);
	svg_dev_stroke_state(ctx, sdev, stroke, &fz_identity);
	svg_dev_stroke_color(ctx, sdev, colorspace, color, alpha);
	svg_dev_path(ctx, sdev, path);
	fz_printf(ctx, out, "/>\n");
}
コード例 #5
0
ファイル: svg-device.c プロジェクト: haggl/mupdf
static void
svg_dev_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke, const fz_matrix *ctm,
	fz_colorspace *colorspace, float *color, float alpha)
{
	svg_device *sdev = dev->user;
	fz_output *out = sdev->out;

	fz_printf(out, "<path");
	svg_dev_ctm(sdev, ctm);
	svg_dev_stroke_state(sdev, stroke);
	svg_dev_stroke_color(sdev, colorspace, color, alpha);
	svg_dev_path(sdev, path);
	fz_printf(out, "/>\n");
}
コード例 #6
0
ファイル: svg-device.c プロジェクト: songtzu/mupdf-4
static void
svg_dev_fill_path(fz_context *ctx, fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm,
	fz_colorspace *colorspace, float *color, float alpha)
{
	svg_device *sdev = (svg_device*)dev;
	fz_output *out = sdev->out;

	fz_printf(ctx, out, "<path");
	svg_dev_ctm(ctx, sdev, ctm);
	svg_dev_path(ctx, sdev, path);
	svg_dev_fill_color(ctx, sdev, colorspace, color, alpha);
	if (even_odd)
		fz_printf(ctx, out, " fill-rule=\"evenodd\"");
	fz_printf(ctx, out, "/>\n");
}
コード例 #7
0
ファイル: svg-device.c プロジェクト: haggl/mupdf
static void
svg_dev_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm)
{
	svg_device *sdev = dev->user;
	fz_output *out = sdev->out;
	int num = sdev->id++;

	fz_printf(out, "<clipPath id=\"cp%d\">\n", num);
	fz_printf(out, "<path");
	svg_dev_ctm(sdev, ctm);
	svg_dev_path(sdev, path);
	if (even_odd)
		fz_printf(out, " fill-rule=\"evenodd\"");
	fz_printf(out, "/>\n</clipPath>\n<g clip-path=\"url(#cp%d)\">\n", num);
}
コード例 #8
0
ファイル: svg-device.c プロジェクト: zvonik/DocsRasterizer
static void
svg_dev_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm,
	fz_colorspace *colorspace, const float *color, float alpha)
{
	svg_device *sdev = (svg_device*)dev;
	fz_compressed_buffer *buffer;

	fz_output *out;
	fz_matrix local_ctm = *ctm;
	fz_matrix scale = { 0 };
	int mask = sdev->id++;

	scale.a = 1.0f / image->w;
	scale.d = 1.0f / image->h;

	fz_concat(&local_ctm, &scale, ctm);
	out = start_def(ctx, sdev);
	fz_printf(ctx, out, "<mask id=\"ma%d\"><image", mask);
	fz_printf(ctx, out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h);
	buffer = fz_compressed_image_buffer(ctx, image);
	switch (buffer == NULL ? FZ_IMAGE_JPX : buffer->params.type)
	{
	case FZ_IMAGE_JPEG:
		fz_printf(ctx, out, "image/jpeg;base64,");
		send_data_base64(ctx, out, buffer->buffer);
		break;
	case FZ_IMAGE_PNG:
		fz_printf(ctx, out, "image/png;base64,");
		send_data_base64(ctx, out, buffer->buffer);
		break;
	default:
		{
			fz_buffer *buf = fz_new_buffer_from_image_as_png(ctx, image);
			fz_printf(ctx, out, "image/png;base64,");
			send_data_base64(ctx, out, buf);
			fz_drop_buffer(ctx, buf);
			break;
		}
	}
	fz_printf(ctx, out, "\"/></mask>\n");
	out = end_def(ctx, sdev);
	fz_printf(ctx, out, "<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\"", image->w, image->h);
	svg_dev_fill_color(ctx, sdev, colorspace, color, alpha);
	svg_dev_ctm(ctx, sdev, &local_ctm);
	fz_printf(ctx, out, " mask=\"url(#ma%d)\"/>\n", mask);
}
コード例 #9
0
ファイル: svg-device.c プロジェクト: songtzu/mupdf-4
static void
svg_dev_clip_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, const fz_matrix *ctm)
{
	svg_device *sdev = (svg_device*)dev;
	fz_output *out;

	int num = sdev->id++;

	out = start_def(ctx, sdev);
	fz_printf(ctx, out, "<clipPath id=\"cp%d\">\n", num);
	fz_printf(ctx, out, "<path");
	svg_dev_ctm(ctx, sdev, ctm);
	svg_dev_path(ctx, sdev, path);
	if (even_odd)
		fz_printf(ctx, out, " fill-rule=\"evenodd\"");
	fz_printf(ctx, out, "/>\n</clipPath>\n");
	out = end_def(ctx, sdev);
	fz_printf(ctx, out, "<g clip-path=\"url(#cp%d)\">\n", num);
}
コード例 #10
0
ファイル: svg-device.c プロジェクト: ArphonePei/PDFConverter
static void
svg_dev_end_tile(fz_device *dev)
{
	svg_device *sdev = (svg_device *)dev->user;
	fz_output *out = sdev->out;
	int num;
	tile *t;

	if (sdev->num_tiles == 0)
		return;
	num = --sdev->num_tiles;
	t = &sdev->tiles[num];

	fz_printf(out, "</g>\n</pattern>\n");
	fz_printf(out, "<rect");
	svg_dev_ctm(sdev, &t->ctm);
	fz_printf(out, " fill=\"url(#pa%d)\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"/>\n",
		t->pattern, t->area.x0, t->area.y0, t->area.x1 - t->area.x0, t->area.y1 - t->area.y0);
}
コード例 #11
0
ファイル: svg-device.c プロジェクト: zvonik/DocsRasterizer
static void
svg_dev_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha)
{
	svg_device *sdev = (svg_device*)dev;
	fz_output *out = sdev->out;
	fz_compressed_buffer *buffer;

	fz_matrix local_ctm = *ctm;
	fz_matrix scale = { 0 };

	scale.a = 1.0f / image->w;
	scale.d = 1.0f / image->h;

	fz_concat(&local_ctm, &scale, ctm);
	if (alpha != 1.0f)
		fz_printf(ctx, out, "<g opacity=\"%g\">", alpha);
	fz_printf(ctx, out, "<image");
	svg_dev_ctm(ctx, sdev, &local_ctm);
	buffer = fz_compressed_image_buffer(ctx, image);
	fz_printf(ctx, out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h);
	switch (buffer == NULL ? FZ_IMAGE_JPX : buffer->params.type)
	{
	case FZ_IMAGE_JPEG:
		fz_printf(ctx, out, "image/jpeg;base64,");
		send_data_base64(ctx, out, buffer->buffer);
		break;
	case FZ_IMAGE_PNG:
		fz_printf(ctx, out, "image/png;base64,");
		send_data_base64(ctx, out, buffer->buffer);
		break;
	default:
		{
			fz_buffer *buf = fz_new_buffer_from_image_as_png(ctx, image);
			fz_printf(ctx, out, "image/png;base64,");
			send_data_base64(ctx, out, buf);
			fz_drop_buffer(ctx, buf);
			break;
		}
	}
	fz_printf(ctx, out, "\"/>\n");
	if (alpha != 1.0f)
		fz_printf(ctx, out, "</g>");
}
コード例 #12
0
ファイル: svg-device.c プロジェクト: songtzu/mupdf-4
static void
svg_dev_text_span_as_paths_stroke(fz_context *ctx, fz_device *dev, fz_text_span *span,
	fz_stroke_state *stroke, const fz_matrix *ctm,
	fz_colorspace *colorspace, float *color, float alpha, font *fnt)
{
	svg_device *sdev = (svg_device*)dev;
	fz_output *out = sdev->out;

	fz_matrix local_trm, local_trm2;
	int i;
	fz_matrix shift = { 1, 0, 0, 1, 0, 0};

	/* Rely on the fact that trm.{e,f} == 0 */
	local_trm.a = span->trm.a;
	local_trm.b = span->trm.b;
	local_trm.c = span->trm.c;
	local_trm.d = span->trm.d;
	local_trm.e = 0;
	local_trm.f = 0;

	for (i=0; i < span->len; i++)
	{
		fz_text_item *it = &span->items[i];
		int gid = it->gid;

		if (gid < 0)
			continue;

		shift.e = fnt->sentlist[gid].x_off;
		shift.f = fnt->sentlist[gid].y_off;
		local_trm.e = it->x;
		local_trm.f = it->y;
		fz_concat(&local_trm2, &local_trm, ctm);
		fz_concat(&local_trm2, &shift, &local_trm2);
		fz_printf(ctx, out, "<use xlink:href=\"#font_%x_%x\"", fnt->id, gid);
		svg_dev_stroke_state(ctx, sdev, stroke, &local_trm2);
		svg_dev_ctm(ctx, sdev, &local_trm2);
		svg_dev_stroke_color(ctx, sdev, colorspace, color, alpha);
		fz_printf(ctx, out, "/>\n");
	}
}
コード例 #13
0
ファイル: svg-device.c プロジェクト: BYogesh/mupdf
static void
svg_dev_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm)
{
	svg_device *sdev = (svg_device *)dev->user;
	fz_context *ctx = dev->ctx;
	fz_output *out;
	fz_matrix local_ctm = *ctm;
	fz_matrix scale = { 0 };
	int mask = sdev->id++;

	scale.a = 1.0f / image->w;
	scale.d = 1.0f / image->h;

	fz_concat(&local_ctm, &scale, ctm);
	out = start_def(sdev);
	fz_printf(out, "<mask id=\"ma%d\"><image", mask);
	svg_dev_ctm(sdev, &local_ctm);
	fz_printf(out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h);
	switch (image->buffer == NULL ? FZ_IMAGE_JPX : image->buffer->params.type)
	{
	case FZ_IMAGE_JPEG:
		fz_printf(out, "image/jpeg;base64,");
		send_data_base64(out, image->buffer->buffer);
		break;
	case FZ_IMAGE_PNG:
		fz_printf(out, "image/png;base64,");
		send_data_base64(out, image->buffer->buffer);
		break;
	default:
		{
			fz_buffer *buf = fz_new_png_from_image(ctx, image, image->w, image->h);
			fz_printf(out, "image/png;base64,");
			send_data_base64(out, buf);
			fz_drop_buffer(ctx, buf);
			break;
		}
	}
	fz_printf(out, "\"/></mask>\n");
	out = end_def(sdev);
	fz_printf(out, "<g mask=\"url(#ma%d)\">\n", mask);
}
コード例 #14
0
ファイル: svg-device.c プロジェクト: haggl/mupdf
static void
svg_dev_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_stroke_state *stroke, const fz_matrix *ctm)
{
	svg_device *sdev = dev->user;
	fz_output *out = sdev->out;
	fz_context *ctx = dev->ctx;
	fz_rect bounds;
	int num = sdev->id++;
	float white[3] = { 255, 255, 255 };

	fz_bound_path(ctx, path, stroke, ctm, &bounds);

	fz_printf(out, "<mask id=\"ma%d\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" maskUnits=\"userSpaceOnUse\" maskContentUnits=\"userSpaceOnUse\">\n",
		num, bounds.x0, bounds.y0, bounds.x1 - bounds.x0, bounds.y1 - bounds.y0);
	fz_printf(out, "<path");
	svg_dev_ctm(sdev, ctm);
	svg_dev_stroke_state(sdev, stroke);
	svg_dev_stroke_color(sdev, fz_device_rgb(ctx), white, 1);
	svg_dev_path(sdev, path);
	fz_printf(out, "/>\n</mask>\n<g mask=\"url(#ma%d)\">\n", num);
}
コード例 #15
0
ファイル: svg-device.c プロジェクト: paragasu/mupdf
static void
svg_dev_clip_stroke_path(fz_context *ctx, fz_device *dev, const fz_path *path, const fz_rect *rect, const fz_stroke_state *stroke, const fz_matrix *ctm)
{
	svg_device *sdev = (svg_device*)dev;

	fz_output *out;
	fz_rect bounds;
	int num = sdev->id++;
	float white[3] = { 1, 1, 1 };

	fz_bound_path(ctx, path, stroke, ctm, &bounds);

	out = start_def(ctx, sdev);
	fz_printf(ctx, out, "<mask id=\"ma%d\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" maskUnits=\"userSpaceOnUse\" maskContentUnits=\"userSpaceOnUse\">\n",
		num, bounds.x0, bounds.y0, bounds.x1 - bounds.x0, bounds.y1 - bounds.y0);
	fz_printf(ctx, out, "<path");
	svg_dev_ctm(ctx, sdev, ctm);
	svg_dev_stroke_state(ctx, sdev, stroke, &fz_identity);
	svg_dev_stroke_color(ctx, sdev, fz_device_rgb(ctx), white, 1);
	svg_dev_path(ctx, sdev, path);
	fz_printf(ctx, out, "/>\n</mask>\n");
	out = end_def(ctx, sdev);
	fz_printf(ctx, out, "<g mask=\"url(#ma%d)\">\n", num);
}
コード例 #16
0
ファイル: svg-device.c プロジェクト: songtzu/mupdf-4
static void
svg_dev_end_tile(fz_context *ctx, fz_device *dev)
{
	svg_device *sdev = (svg_device*)dev;
	fz_output *out = sdev->out;
	int num, cp = -1;
	tile *t;
	fz_matrix inverse;
	float x, y, w, h;

	if (sdev->num_tiles == 0)
		return;
	num = --sdev->num_tiles;
	t = &sdev->tiles[num];

	fz_printf(ctx, out, "</symbol>\n");

	/* In svg, the reference tile is taken from (x,y) to (x+width,y+height)
	 * and is repeated at (x+n*width,y+m*height) for all integer n and m.
	 * This means that width and height generally correspond to xstep and
	 * ystep. There are exceptional cases where we have to break this
	 * though; when xstep/ystep are smaller than the width/height of the
	 * pattern tile, we need to render the pattern contents several times
	 * to ensure that the pattern tile contains everything. */

	fz_printf(ctx, out, "<pattern id=\"pa%d\" patternUnits=\"userSpaceOnUse\" patternContentUnits=\"userSpaceOnUse\"",
		t->pattern);
	fz_printf(ctx, out, " x=\"0\" y=\"0\" width=\"%g\" height=\"%g\">\n",
		t->step.x, t->step.y);

	if (t->view.x0 > 0 || t->step.x < t->view.x1 || t->view.y0 > 0 || t->step.y < t->view.y1)
	{
		cp = sdev->id++;
		fz_printf(ctx, out, "<clipPath id=\"cp%d\">\n", cp);
		fz_printf(ctx, out, "<path d=\"M %g %g L %g %g L %g %g L %g %g Z\"/>",
			t->view.x0, t->view.y0,
			t->view.x1, t->view.y0,
			t->view.x1, t->view.y1,
			t->view.x0, t->view.y1);
		fz_printf(ctx, out, "</clipPath>\n");
		fz_printf(ctx, out, "<g clip-path=\"url(#cp%d)\">\n", cp);
	}

	/* All the pattern contents will have their own ctm applied. Let's
	 * undo the current one to allow for this */
	fz_invert_matrix(&inverse, &t->ctm);
	fz_printf(ctx, out, "<g");
	svg_dev_ctm(ctx, sdev, &inverse);
	fz_printf(ctx, out, ">\n");

	w = t->view.x1 - t->view.x0;
	h = t->view.y1 - t->view.y0;

	for (x = 0; x > -w; x -= t->step.x)
		for (y = 0; y > -h; y -= t->step.y)
			fz_printf(ctx, out, "<use x=\"%g\" y=\"%g\" xlink:href=\"#pac%d\"/>", x, y, t->pattern);

	fz_printf(ctx, out, "</g>\n");
	if (cp != -1)
		fz_printf(ctx, out, "</g>\n");
	fz_printf(ctx, out, "</pattern>\n");
	out = end_def(ctx, sdev);

	/* Finally, fill a rectangle with the pattern. */
	fz_printf(ctx, out, "<rect");
	svg_dev_ctm(ctx, sdev, &t->ctm);
	fz_printf(ctx, out, " fill=\"url(#pa%d)\" x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"/>\n",
		t->pattern, t->area.x0, t->area.y0, t->area.x1 - t->area.x0, t->area.y1 - t->area.y0);
}