1
/* This file is part of Libspectre.
3
* Copyright (C) 2007 Albert Astals Cid <aacid@kde.org>
4
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
6
* Libspectre is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2, or (at your option)
11
* Libspectre is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
#include "spectre-page.h"
26
#include "spectre-device.h"
27
#include "spectre-private.h"
28
#include "spectre-utils.h"
42
_spectre_page_new (unsigned int page_index,
47
page = calloc (1, sizeof (SpectrePage));
51
page->index = page_index;
54
page->doc = psdocreference (doc);
60
spectre_page_free (SpectrePage *page)
66
psdocdestroy (page->doc);
74
spectre_page_status (SpectrePage *page)
76
_spectre_return_val_if_fail (page != NULL, SPECTRE_STATUS_INVALID_PAGE);
82
spectre_page_get_index (SpectrePage *page)
84
_spectre_return_val_if_fail (page != NULL, 0);
90
spectre_page_get_label (SpectrePage *page)
92
_spectre_return_val_if_fail (page != NULL, NULL);
94
return page->doc->numpages > 0 ? page->doc->pages[page->index].label : NULL;
98
spectre_page_get_orientation (SpectrePage *page)
100
int page_orientation = NONE;
102
_spectre_return_val_if_fail (page != NULL, SPECTRE_ORIENTATION_PORTRAIT);
104
if (page->doc->numpages > 0) {
105
page_orientation = page->doc->pages[page->index].orientation != NONE ?
106
page->doc->pages[page->index].orientation :
107
page->doc->default_page_orientation;
110
if (page_orientation == NONE)
111
page_orientation = page->doc->orientation;
113
switch (page_orientation) {
116
return SPECTRE_ORIENTATION_PORTRAIT;
118
return SPECTRE_ORIENTATION_LANDSCAPE;
120
return SPECTRE_ORIENTATION_REVERSE_LANDSCAPE;
122
return SPECTRE_ORIENTATION_REVERSE_PORTRAIT;
127
spectre_page_get_size (SpectrePage *page,
131
_spectre_return_if_fail (page != NULL);
133
if (page->width == -1 || page->height == -1) {
134
int urx, ury, llx, lly;
136
psgetpagebox (page->doc, page->index,
137
&urx, &ury, &llx, &lly);
139
page->width = urx - llx;
140
page->height = ury - lly;
144
*width = page->width;
146
*height = page->height;
150
spectre_page_render (SpectrePage *page,
151
SpectreRenderContext *rc,
152
unsigned char **page_data,
155
SpectreDevice *device;
158
_spectre_return_if_fail (page != NULL);
159
_spectre_return_if_fail (rc != NULL);
161
spectre_page_get_size (page, &width, &height);
163
device = spectre_device_new (page->doc);
164
page->status = spectre_device_render (device, page->index, rc,
166
page_data, row_length);
167
spectre_device_free (device);
171
spectre_page_render_slice (SpectrePage *page,
172
SpectreRenderContext *rc,
177
unsigned char **page_data,
180
SpectreDevice *device;
183
_spectre_return_if_fail (page != NULL);
184
_spectre_return_if_fail (rc != NULL);
186
spectre_page_get_size (page, NULL, &page_height);
188
device = spectre_device_new (page->doc);
189
page->status = spectre_device_render (device, page->index, rc,
190
x, page_height - (y + height),
192
page_data, row_length);
193
spectre_device_free (device);