summaryrefslogtreecommitdiff
path: root/source/fitz/test-device.c
blob: ffa3917bd4d35c79820eee3b8c12cf4e29501647 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <mupdf/fitz.h>

static void
fz_test_colorspace(fz_context *ctx, fz_colorspace *colorspace, int *iscolor)
{
	if (colorspace && colorspace != fz_device_gray(ctx))
		*iscolor = 1;
}

static void
fz_test_color(fz_context *ctx, fz_colorspace *colorspace, float *color, int *iscolor)
{
	if (!*iscolor && colorspace && colorspace != fz_device_gray(ctx))
	{
		float rgb[3];
		fz_convert_color(ctx, fz_device_rgb(ctx), rgb, colorspace, color);
		if (rgb[0] != rgb[1] || rgb[0] != rgb[2])
			*iscolor = 1;
	}
}

static void
fz_test_fill_path(fz_device *dev, fz_path *path, int even_odd, const fz_matrix *ctm,
	fz_colorspace *colorspace, float *color, float alpha)
{
	fz_test_color(dev->ctx, colorspace, color, dev->user);
}

static void
fz_test_stroke_path(fz_device *dev, fz_path *path, fz_stroke_state *stroke,
	const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha)
{
	fz_test_color(dev->ctx, colorspace, color, dev->user);
}

static void
fz_test_fill_text(fz_device *dev, fz_text *text, const fz_matrix *ctm,
	fz_colorspace *colorspace, float *color, float alpha)
{
	fz_test_color(dev->ctx, colorspace, color, dev->user);
}

static void
fz_test_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke,
	const fz_matrix *ctm, fz_colorspace *colorspace, float *color, float alpha)
{
	fz_test_color(dev->ctx, colorspace, color, dev->user);
}

static void
fz_test_fill_shade(fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha)
{
	fz_test_colorspace(dev->ctx, shade->colorspace, dev->user);
}

static void
fz_test_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha)
{
	fz_test_colorspace(dev->ctx, image->colorspace, dev->user);
}

static void
fz_test_fill_image_mask(fz_device *dev, fz_image *image, const fz_matrix *ctm,
	fz_colorspace *colorspace, float *color, float alpha)
{
	fz_test_color(dev->ctx, colorspace, color, dev->user);
}

fz_device *
fz_new_test_device(fz_context *ctx, int *iscolor)
{
	fz_device *dev = fz_new_device(ctx, iscolor);

	dev->fill_path = fz_test_fill_path;
	dev->stroke_path = fz_test_stroke_path;
	dev->fill_text = fz_test_fill_text;
	dev->stroke_text = fz_test_stroke_text;
	dev->fill_shade = fz_test_fill_shade;
	dev->fill_image = fz_test_fill_image;
	dev->fill_image_mask = fz_test_fill_image_mask;

	*iscolor = 0;

	return dev;
}