static const char * _spectre_render_page (const char *filename, const char *page_label, cairo_surface_t **surface_out) { static const cairo_user_data_key_t key; SpectreDocument *document; SpectreStatus status; int width, height, stride; unsigned char *pixels; cairo_surface_t *surface; document = spectre_document_new (); spectre_document_load (document, filename); status = spectre_document_status (document); if (status) { spectre_document_free (document); return spectre_status_to_string (status); } if (page_label) { SpectrePage *page; SpectreRenderContext *rc; page = spectre_document_get_page_by_label (document, page_label); spectre_document_free (document); if (page == NULL) return "page not found"; spectre_page_get_size (page, &width, &height); rc = spectre_render_context_new (); spectre_render_context_set_page_size (rc, width, height); spectre_page_render (page, rc, &pixels, &stride); spectre_render_context_free (rc); status = spectre_page_status (page); spectre_page_free (page); if (status) { free (pixels); return spectre_status_to_string (status); } } else { spectre_document_get_page_size (document, &width, &height); spectre_document_render (document, &pixels, &stride); spectre_document_free (document); } surface = cairo_image_surface_create_for_data (pixels, CAIRO_FORMAT_RGB24, width, height, stride); cairo_surface_set_user_data (surface, &key, pixels, (cairo_destroy_func_t) free); *surface_out = surface; return NULL; }
Eps_Page * eps_page_new (const Eps_Document *document) { Eps_Page *page; SpectreStatus status; if (!document) return NULL; page = (Eps_Page *)malloc (sizeof (Eps_Page)); if (!page) return NULL; page->document = document->ps_doc; page->page = spectre_document_get_page(document->ps_doc, 0); status = spectre_page_status (page->page); if (status != SPECTRE_STATUS_SUCCESS) { printf ("[eps] %s\n", spectre_status_to_string (status)); free (page); return 0; } page->rc = spectre_render_context_new (); if (!page->rc) { free (page); return NULL; } spectre_render_context_set_rotation (page->rc, 0); spectre_render_context_set_scale (page->rc, 1.0, 1.0); return page; }
void eps_page_render (const Eps_Page *page, Evas_Object *o) { unsigned char *data; unsigned char *d; unsigned int *m = NULL; double hscale; double vscale; SpectreStatus status; int width; int height; int stride; int yy; if (!page || !o) return; spectre_page_render (page->page, page->rc, &data, &stride); status = spectre_page_status (page->page); if (status != SPECTRE_STATUS_SUCCESS) { printf ("[eps] %s\n", spectre_status_to_string (status)); return; } eps_page_scale_get (page, &hscale, &vscale); eps_page_size_get (page, &width, &height); width *= hscale; height *= vscale; evas_object_image_size_set (o, width, height); evas_object_image_fill_set (o, 0, 0, width, height); m = (unsigned int *)evas_object_image_data_get (o, 1); if (!m) { free (data); return; } if (stride == 4 * width) memcpy(m, data, height * stride); else { d = data; for (yy = 0; yy < height; d += stride, m += width, ++yy) { memcpy (m, d, width * 4); } } evas_object_image_data_update_add (o, 0, 0, width, height); evas_object_resize (o, width, height); free (data); }
void eps_page_render_slice (const Eps_Page *page, Evas_Object *o, int x, int y, int width, int height) { unsigned char *data; unsigned char *d; unsigned int *m = NULL; double hscale; double vscale; SpectreStatus status; int stride; int yy; if (!page || !o || (width <= 0) || (height <= 0)) return; spectre_page_render_slice (page->page, page->rc, x, y, width, height, &data, &stride); status = spectre_page_status (page->page); if (status != SPECTRE_STATUS_SUCCESS) { printf ("aie !!%d %d %d %d %d\n", status, x, y, width, height); printf ("[eps] %s\n", spectre_status_to_string (status)); return; } eps_page_scale_get (page, &hscale, &vscale); width *= hscale; height *= vscale; evas_object_image_size_set (o, width, height); evas_object_image_fill_set (o, 0, 0, width, height); m = (unsigned int *)evas_object_image_data_get (o, 1); if (!m) { free (data); return; } d = data + y * stride + x; for (yy = 0; yy < height; d += stride, m += width, ++yy) { memcpy (m, d, width * 4); } evas_object_image_data_update_add (o, 0, 0, width, height); evas_object_resize (o, width, height); free (data); }
void eps_page_page_set (Eps_Page *page, int p) { SpectrePage *new_page; SpectreStatus status; if (!page) return; new_page = spectre_document_get_page(page->document, p); status = spectre_page_status (new_page); if (status != SPECTRE_STATUS_SUCCESS) { printf ("[eps] %s\n", spectre_status_to_string (status)); return; } spectre_page_free (page->page); page->page = new_page; }
bool PostScriptDocument::load(const QString& fileName) { p_filename = fileName; p_internal_document = spectre_document_new(); spectre_document_load(p_internal_document, QFile::encodeName(p_filename)); const SpectreStatus loadStatus = spectre_document_status(p_internal_document); if (loadStatus != SPECTRE_STATUS_SUCCESS) { kDebug() << "ERR:" << spectre_status_to_string(loadStatus); spectre_document_free(p_internal_document); clear(); return FALSE; } int numPages = spectre_document_get_n_pages(p_internal_document); if (numPages > 0) { kDebug() << "Page Count: " << numPages; } else { kWarning() << "Unable to calculate number of pages."; numPages = 0; } int width, height; spectre_document_get_page_size(p_internal_document, &width, &height); if ((width > 0) && (height > 0)) { p_page_size = QSize(width, height); kDebug() << "Page Size: " << width << "x" << height << " (" << PaperSizeUtils::paperSizeToString(PaperSizeUtils::sizeToPaperSize(p_page_size)) << ")"; } else { kWarning() << "Unable to calculate page size."; } SpectreOrientation orientation = spectre_document_get_orientation(p_internal_document); bool reversePage; p_orientation = spectreOrientationToOrientation(orientation, &reversePage); kDebug() << "Page Orientation: " << PaperSizeUtils::orientationToString(p_orientation); kDebug() << "Note: The page orientation may differ from orientation for each page."; /* Load the pages now */ SpectrePage *page; SpectreOrientation pageOrientation; QPrinter::Orientation pageOrientation2; width = 0; height = 0; for (int i = 0; i < numPages; ++i) { pageOrientation = SPECTRE_ORIENTATION_PORTRAIT; page = spectre_document_get_page(p_internal_document, i); if (spectre_document_status(p_internal_document)) { kWarning() << "Error getting page " << i << spectre_status_to_string(spectre_document_status(p_internal_document)); } else { spectre_page_get_size(page, &width, &height); pageOrientation = spectre_page_get_orientation(page); } spectre_page_free(page); pageOrientation2 = spectreOrientationToOrientation(pageOrientation, &reversePage); p_pages.append(PostScriptDocumentPage(QSize(width, height), pageOrientation2, reversePage)); kDebug() << "Append page" << i+1 << "with Size (" << width << "," << height << ")," << PaperSizeUtils::orientationToString(pageOrientation2); } kDebug() << "Loaded" << p_pages.count() << "pages"; p_is_valid = TRUE; return TRUE; }