Exemple #1
0
static void
svg_dev_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate)
{
	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] = { 1, 1, 1 };
	font *fnt;

	fz_bound_text(ctx, text, NULL, ctm, &bounds);

	out = start_def(sdev);
	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, "<text");
	svg_dev_fill_color(sdev, fz_device_rgb(ctx), white, 0.0f);
	svg_dev_text(sdev, ctm, text);
	fnt = svg_dev_text_as_paths_defs(dev, text, ctm);
	svg_dev_text_as_paths_fill(dev, text, ctm, fz_device_rgb(ctx), white, 1.0f, fnt);
	fz_printf(out, "</mask>\n");
	out = end_def(sdev);
	fz_printf(out, "<g mask=\"url(#ma%d)\">\n", num);
}
Exemple #2
0
static void
svg_dev_clip_stroke_text(fz_context *ctx, fz_device *dev, fz_text *text, 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] = { 255, 255, 255 };
	font *fnt;
	fz_text_span *span;

	fz_bound_text(ctx, text, NULL, 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, "<text");
	svg_dev_stroke_state(ctx, sdev, stroke, &fz_identity);
	svg_dev_stroke_color(ctx, sdev, fz_device_rgb(ctx), white, 0.0f);
	svg_dev_text(ctx, sdev, ctm, text);
	for (span = text->head; span; span = span->next)
	{
		fnt = svg_dev_text_span_as_paths_defs(ctx, dev, span, ctm);
		svg_dev_text_span_as_paths_stroke(ctx, dev, span, stroke, ctm, fz_device_rgb(ctx), white, 1.0f, fnt);
	}
	fz_printf(ctx, out, "</mask>\n");
	out = end_def(ctx, sdev);
	fz_printf(ctx, out, "<g mask=\"url(#ma%d)\">\n", num);
}
static int end_lb25_seenophy(unicode_lb_info_t i)
{
	int rc=unwind_lb25_seenophy(i);

	if (rc == 0)
		rc=end_def(i);
	return rc;
}
Exemple #4
0
static void
svg_dev_end_mask(fz_context *ctx, fz_device *dev)
{
	svg_device *sdev = (svg_device*)dev;
	fz_output *out = sdev->out;
	int mask = 0;

	if (dev->container_len > 0)
		mask = (int)dev->container[dev->container_len-1].user;

	fz_printf(ctx, out, "\"/></mask>\n");
	out = end_def(ctx, sdev);
	fz_printf(ctx, out, "<g mask=\"url(#ma%d)\">\n", mask);

}
Exemple #5
0
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);
}
Exemple #6
0
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;
	int num = sdev->id++;

	out = start_def(sdev);
	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");
	out = end_def(sdev);
	fz_printf(out, "<g clip-path=\"url(#cp%d)\">\n", num);
}
Exemple #7
0
static void
svg_dev_clip_path(fz_context *ctx, fz_device *dev, const fz_path *path, int even_odd, const fz_matrix *ctm, const fz_rect *scissor)
{
	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);
}
Exemple #8
0
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);
}
Exemple #9
0
static void
svg_dev_clip_stroke_path(fz_context *ctx, fz_device *dev, fz_path *path, const fz_rect *rect, 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);
}
Exemple #10
0
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);
}
Exemple #11
0
static font *
svg_dev_text_span_as_paths_defs(fz_context *ctx, fz_device *dev, fz_text_span *span, const fz_matrix *ctm)
{
	svg_device *sdev = (svg_device*)dev;
	fz_output *out = sdev->out;
	int i, font_idx;
	font *fnt;
	fz_matrix shift = fz_identity;

	for (font_idx = 0; font_idx < sdev->num_fonts; font_idx++)
	{
		if (sdev->fonts[font_idx].font == span->font)
			break;
	}
	if (font_idx == sdev->num_fonts)
	{
		/* New font */
		if (font_idx == sdev->max_fonts)
		{
			int newmax = sdev->max_fonts * 2;
			if (newmax == 0)
				newmax = 4;
			sdev->fonts = fz_resize_array(ctx, sdev->fonts, newmax, sizeof(*sdev->fonts));
			memset(&sdev->fonts[font_idx], 0, (newmax - font_idx) * sizeof(sdev->fonts[0]));
			sdev->max_fonts = newmax;
		}
		sdev->fonts[font_idx].id = sdev->id++;
		sdev->fonts[font_idx].font = fz_keep_font(ctx, span->font);
		sdev->num_fonts++;
	}
	fnt = &sdev->fonts[font_idx];

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

		if (gid < 0)
			continue;
		if (gid >= fnt->max_sentlist)
		{
			int j;
			fnt->sentlist = fz_resize_array(ctx, fnt->sentlist, gid+1, sizeof(fnt->sentlist[0]));
			for (j = fnt->max_sentlist; j <= gid; j++)
			{
				fnt->sentlist[j].x_off = FLT_MIN;
				fnt->sentlist[j].y_off = FLT_MIN;
			}
			fnt->max_sentlist = gid+1;
		}
		if (fnt->sentlist[gid].x_off == FLT_MIN)
		{
			/* Need to send this one */
			fz_rect rect;
			fz_path *path;
			path = fz_outline_glyph(ctx, span->font, gid, &fz_identity);
			if (path)
			{
				fz_bound_path(ctx, path, NULL, &fz_identity, &rect);
				shift.e = -rect.x0;
				shift.f = -rect.y0;
				fz_transform_path(ctx, path, &shift);
				out = start_def(ctx, sdev);
				fz_printf(ctx, out, "<symbol id=\"font_%x_%x\">", fnt->id, gid);
				fz_printf(ctx, out, "<path");
				svg_dev_path(ctx, sdev, path);
				fz_printf(ctx, out, "/>\n");
			}
			else
			{
				fz_bound_glyph(ctx, span->font, gid, &fz_identity, &rect);
				shift.e = -rect.x0;
				shift.f = -rect.y0;
				out = start_def(ctx, sdev);
				fz_printf(ctx, out, "<symbol id=\"font_%x_%x\">", fnt->id, gid);
				fz_run_t3_glyph(ctx, span->font, gid, &shift, dev);
			}
			fz_printf(ctx, out, "</symbol>");
			out = end_def(ctx, sdev);
			fnt->sentlist[gid].x_off = rect.x0;
			fnt->sentlist[gid].y_off = rect.y0;
		}
	}
	return fnt;
}