summaryrefslogtreecommitdiff
path: root/xps/xpsopacity.c
blob: e5b0f787b47197fa53c08b564cf3c079280e791d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "fitz.h"
#include "muxps.h"

void
xps_begin_opacity(xps_context *ctx, fz_matrix ctm, fz_rect area,
	char *base_uri, xps_resource *dict,
	char *opacity_att, xps_item *opacity_mask_tag)
{
	float opacity;

	if (!opacity_att && !opacity_mask_tag)
		return;

	opacity = 1.0;
	if (opacity_att)
		opacity = atof(opacity_att);

	if (opacity_mask_tag && !strcmp(xps_tag(opacity_mask_tag), "SolidColorBrush"))
	{
		char *scb_opacity_att = xps_att(opacity_mask_tag, "Opacity");
		char *scb_color_att = xps_att(opacity_mask_tag, "Color");
		if (scb_opacity_att)
			opacity = opacity * atof(scb_opacity_att);
		if (scb_color_att)
		{
			fz_colorspace *colorspace;
			float samples[32];
			xps_parse_color(ctx, base_uri, scb_color_att, &colorspace, samples);
			opacity = opacity * samples[0];
		}
		opacity_mask_tag = NULL;
	}

	if (ctx->opacity_top + 1 < nelem(ctx->opacity))
	{
		ctx->opacity[ctx->opacity_top + 1] = ctx->opacity[ctx->opacity_top] * opacity;
		ctx->opacity_top++;
	}

	if (opacity_mask_tag)
	{
		ctx->dev->beginmask(ctx->dev->user, area, 0, NULL, NULL);
		xps_parse_brush(ctx, ctm, area, base_uri, dict, opacity_mask_tag);
		ctx->dev->endmask(ctx->dev->user);
	}
}

void
xps_end_opacity(xps_context *ctx, char *base_uri, xps_resource *dict,
	char *opacity_att, xps_item *opacity_mask_tag)
{
	if (!opacity_att && !opacity_mask_tag)
		return;

	if (ctx->opacity_top > 0)
		ctx->opacity_top--;

	if (opacity_mask_tag)
	{
		if (strcmp(xps_tag(opacity_mask_tag), "SolidColorBrush"))
			ctx->dev->popclip(ctx->dev->user);
	}
}