summaryrefslogtreecommitdiff
path: root/libspectre/spectre-render-context.c
blob: f7a1dc98b693a8826e98c7e471e81fe7fb52e508 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* This file is part of Libspectre.
 * 
 * Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
 * Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
 *
 * Libspectre is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2; or (at your option)
 * any later version.
 *
 * Libspectre is distributed in the hope that it will be useful;
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not; write to the Free Software
 * Foundation; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <stdlib.h>

#include "spectre-render-context.h"
#include "spectre-page.h"
#include "spectre-private.h"
#include "spectre-utils.h"

SpectreRenderContext *
spectre_render_context_new (void)
{
	SpectreRenderContext *rc;

	rc = malloc (sizeof (SpectreRenderContext));
	if (!rc)
		return NULL;

	rc->x_scale = 1.0;
	rc->y_scale = 1.0;
	rc->orientation = 0;
	rc->x_dpi = 72.0;
	rc->y_dpi = 72.0;
	rc->width = -1;
	rc->height = -1;
	rc->text_alpha_bits = 4;
	rc->graphic_alpha_bits = 2;
	rc->use_platform_fonts = TRUE;
	
	return rc;
}

void
spectre_render_context_free (SpectreRenderContext *rc)
{
	if (!rc)
		return;

	free (rc);
}

void
spectre_render_context_set_scale (SpectreRenderContext *rc,
				  double                x_scale,
				  double                y_scale)
{
	_spectre_return_if_fail (rc != NULL);

	rc->x_scale = x_scale;
	rc->y_scale = y_scale;
}

void 
spectre_render_context_get_scale (SpectreRenderContext *rc,
				  double               *x_scale,
				  double               *y_scale)
{
	_spectre_return_if_fail (rc != NULL);

	if (x_scale)
		*x_scale = rc->x_scale;
	if (y_scale)
		*y_scale = rc->y_scale;
}

void
spectre_render_context_set_rotation (SpectreRenderContext *rc,
				     unsigned int          rotation)
{
	_spectre_return_if_fail (rc != NULL);

	rotation %= 360;

	if (rotation >= 0 && rotation < 90)
		rc->orientation = SPECTRE_ORIENTATION_PORTRAIT;
	else if (rotation >= 90 && rotation < 180)
		rc->orientation = SPECTRE_ORIENTATION_LANDSCAPE;
	else if (rotation >= 180 && rotation < 270)
		rc->orientation = SPECTRE_ORIENTATION_REVERSE_PORTRAIT;
	else if (rotation >= 270 && rotation < 360)
		rc->orientation = SPECTRE_ORIENTATION_REVERSE_LANDSCAPE;
}
	
unsigned int
spectre_render_context_get_rotation (SpectreRenderContext *rc)
{
	_spectre_return_val_if_fail (rc != NULL, 0);

	switch (rc->orientation) {
	default:
	case SPECTRE_ORIENTATION_PORTRAIT:
		return 0;
	case SPECTRE_ORIENTATION_LANDSCAPE:
		return 90;
	case SPECTRE_ORIENTATION_REVERSE_PORTRAIT:
		return 180;
	case SPECTRE_ORIENTATION_REVERSE_LANDSCAPE:
		return 270;
	}
	
	return 0;
}

void
spectre_render_context_set_resolution (SpectreRenderContext *rc,
				       double                x_dpi,
				       double                y_dpi)
{
	_spectre_return_if_fail (rc != NULL);

	rc->x_dpi = x_dpi;
	rc->y_dpi = y_dpi;
}

void
spectre_render_context_get_resolution (SpectreRenderContext *rc,
				       double               *x_dpi,
				       double               *y_dpi)
{
	_spectre_return_if_fail (rc != NULL);

	if (x_dpi)
		*x_dpi = rc->x_dpi;
	if (y_dpi)
		*y_dpi = rc->y_dpi;
}

void
spectre_render_context_set_page_size (SpectreRenderContext *rc,
				      int                   width,
				      int                   height)
{
	_spectre_return_if_fail (rc != NULL);
		
	rc->width = width;
	rc->height = height;
}

void
spectre_render_context_get_page_size (SpectreRenderContext *rc,
				      int                  *width,
				      int                  *height)
{
	_spectre_return_if_fail (rc != NULL);

	if (width)
		*width = rc->width;
	if (height)
		*height = rc->height;
}

void
spectre_render_context_set_use_platform_fonts (SpectreRenderContext *rc,
					       int                   use_platform_fonts)
{
	_spectre_return_if_fail (rc != NULL);

	rc->use_platform_fonts = use_platform_fonts;
}

int
spectre_render_context_get_use_platform_fonts (SpectreRenderContext *rc)
{
	_spectre_return_val_if_fail (rc != NULL, FALSE);

	return rc->use_platform_fonts;
}

void
spectre_render_context_set_antialias_bits (SpectreRenderContext *rc,
					   int                   graphics_bits,
					   int                   text_bits)
{
	_spectre_return_if_fail (rc != NULL);

	rc->graphic_alpha_bits = graphics_bits;
	rc->text_alpha_bits = text_bits;
}

void
spectre_render_context_get_antialias_bits (SpectreRenderContext *rc,
					   int                  *graphics_bits,
					   int                  *text_bits)
{
	_spectre_return_if_fail (rc != NULL);

	if (graphics_bits)
		*graphics_bits = rc->graphic_alpha_bits;
	if (text_bits)
		*text_bits = rc->text_alpha_bits;
}