예제 #1
0
파일: page.c 프로젝트: pwmt/zathura-ps
zathura_error_t
ps_page_init(zathura_page_t* page, SpectrePage* spectre_page)
{
  if (page == NULL) {
    return ZATHURA_ERROR_INVALID_ARGUMENTS;
  }

  zathura_document_t* document      = zathura_page_get_document(page);
  SpectreDocument* spectre_document = zathura_document_get_data(document);

  SpectrePage* ps_page = spectre_document_get_page(spectre_document, zathura_page_get_index(page));
  if (ps_page == NULL) {
    return ZATHURA_ERROR_UNKNOWN;
  }

  int page_width;
  int page_height;
  spectre_page_get_size(ps_page, &(page_width), &(page_height));

  zathura_page_set_width(page, page_width);
  zathura_page_set_height(page, page_height);
  zathura_page_set_data(page, ps_page);

  return ZATHURA_ERROR_OK;
}
예제 #2
0
파일: eps_page.c 프로젝트: Limsik/e17
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;
}
예제 #3
0
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;
}
예제 #4
0
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;

}