23 #include <glib/gi18n-lib.h>
25 #include <libspectre/spectre.h>
63 spectre_document_free (ps->
doc);
68 spectre_exporter_free (ps->
exporter);
72 G_OBJECT_CLASS (ps_document_parent_class)->dispose (
object);
84 filename = g_filename_from_uri (uri, NULL, error);
88 ps->
doc = spectre_document_new ();
90 spectre_document_load (ps->
doc, filename);
91 if (spectre_document_status (ps->
doc)) {
94 filename_dsp = g_filename_display_name (filename);
98 _(
"Failed to load document ā%sā"),
100 g_free (filename_dsp);
119 filename = g_filename_from_uri (uri, NULL, error);
123 spectre_document_save (ps->
doc, filename);
124 if (spectre_document_status (ps->
doc)) {
127 filename_dsp = g_filename_display_name (filename);
131 _(
"Failed to save document ā%sā"),
133 g_free (filename_dsp);
149 return spectre_document_get_n_pages (ps->
doc);
157 SpectrePage *ps_page;
160 ps_page = spectre_document_get_page (ps->
doc, index);
171 switch (spectre_page_get_orientation (page)) {
173 case SPECTRE_ORIENTATION_PORTRAIT:
175 case SPECTRE_ORIENTATION_LANDSCAPE:
177 case SPECTRE_ORIENTATION_REVERSE_PORTRAIT:
179 case SPECTRE_ORIENTATION_REVERSE_LANDSCAPE:
192 SpectrePage *ps_page;
193 gdouble page_width, page_height;
194 gint pwidth, pheight;
199 spectre_page_get_size (ps_page, &pwidth, &pheight);
202 if (rotate == 90 || rotate == 270) {
203 page_height = pwidth;
204 page_width = pheight;
207 page_height = pheight;
215 *height = page_height;
229 if (g_utf8_validate (label, -1, NULL))
230 return g_strdup (label);
233 utf8 = g_convert (label, -1,
"utf-8",
"latin1", NULL, NULL, NULL);
235 utf8 = g_convert (label, -1,
"utf-8",
"ASCII", NULL, NULL, NULL);
245 const gchar *creator;
246 SpectrePage *ps_page;
256 creator = spectre_document_get_creator (ps->
doc);
258 ps_page = spectre_document_get_page (ps->
doc, 0);
259 spectre_page_get_size (ps_page, &width, &height);
260 spectre_page_free (ps_page);
262 info->title = g_strdup (spectre_document_get_title (ps->
doc));
263 info->format = g_strdup (spectre_document_get_format (ps->
doc));
264 info->creator = g_strdup (creator ? creator : spectre_document_get_for (ps->
doc));
265 info->n_pages = spectre_document_get_n_pages (ps->
doc);
266 info->paper_width = width / 72.0f * 25.4f;
267 info->paper_height = height / 72.0f * 25.4f;
276 info->
name =
"libspectre";
277 info->
version = SPECTRE_VERSION_STRING;
282 static cairo_surface_t *
286 SpectrePage *ps_page;
287 SpectreRenderContext *src;
291 gint swidth, sheight;
295 cairo_surface_t *surface;
296 static const cairo_user_data_key_t key;
298 ps_page = (SpectrePage *)rc->page->backend_page;
300 spectre_page_get_size (ps_page, &width_points, &height_points);
307 if (rotation == 90 || rotation == 270) {
315 src = spectre_render_context_new ();
316 spectre_render_context_set_scale (src,
317 (gdouble)swidth / width_points,
318 (gdouble)sheight / height_points);
319 spectre_render_context_set_rotation (src, rotation);
320 spectre_page_render (ps_page, src, &data, &stride);
321 spectre_render_context_free (src);
327 if (spectre_page_status (ps_page)) {
328 g_warning (
"%s", spectre_status_to_string (spectre_page_status (ps_page)));
334 surface = cairo_image_surface_create_for_data (data,
338 cairo_surface_set_user_data (surface, &key,
339 data, (cairo_destroy_func_t)g_free);
346 GObjectClass *object_class = G_OBJECT_CLASS (klass);
370 spectre_exporter_free (ps->
exporter);
375 spectre_exporter_new (ps->
doc,
376 SPECTRE_EXPORTER_FORMAT_PS);
380 spectre_exporter_new (ps->
doc,
381 SPECTRE_EXPORTER_FORMAT_PDF);
384 g_assert_not_reached ();
396 spectre_exporter_do_page (ps->
exporter, rc->page->index);
404 spectre_exporter_end (ps->
exporter);