void eps_page_size_get (const Eps_Page *page, int *width, int *height) { SpectreOrientation orientation; int w = 0; int h = 0; if (page && page->page) { spectre_page_get_size (page->page, &w, &h); orientation = spectre_page_get_orientation (page->page); switch (orientation) { case SPECTRE_ORIENTATION_REVERSE_PORTRAIT: case SPECTRE_ORIENTATION_PORTRAIT: if (width) *width = w; if (height) *height = h; return; case SPECTRE_ORIENTATION_LANDSCAPE: case SPECTRE_ORIENTATION_REVERSE_LANDSCAPE: if (width) *width = h; if (height) *height = w; return; } } if (width) *width = 0; if (height) *height = 0; }
Eps_Page_Orientation eps_page_orientation_get (const Eps_Page *page) { SpectreOrientation orientation; if (!page) return EPS_PAGE_ORIENTATION_PORTRAIT; orientation = spectre_page_get_orientation (page->page); switch (orientation) { case SPECTRE_ORIENTATION_LANDSCAPE: return EPS_PAGE_ORIENTATION_LANDSCAPE; case SPECTRE_ORIENTATION_REVERSE_PORTRAIT: return EPS_PAGE_ORIENTATION_UPSIDEDOWN; case SPECTRE_ORIENTATION_REVERSE_LANDSCAPE: return EPS_PAGE_ORIENTATION_SEASCAPE; case SPECTRE_ORIENTATION_PORTRAIT: return EPS_PAGE_ORIENTATION_PORTRAIT; /* should not be possible but we return EPS_PAGE_ORIENTATION_PORTRAIT in default case */ default: return EPS_PAGE_ORIENTATION_PORTRAIT; } }
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; }