[poppler] poppler/glib: poppler-page.cc, 1.32, 1.33 poppler-page.h, 1.18, 1.19 poppler-private.h, 1.11, 1.12 test-poppler-glib.c, 1.13, 1.14

Kristian Hogsberg krh at freedesktop.org
Mon Aug 22 11:20:14 PDT 2005


Update of /cvs/poppler/poppler/glib
In directory gabe:/tmp/cvs-serv18739/glib

Modified Files:
	poppler-page.cc poppler-page.h poppler-private.h 
	test-poppler-glib.c 
Log Message:
2005-08-22  Kristian Høgsberg  <krh at redhat.com>

        * glib/poppler-page.cc:
        * glib/poppler-page.h:
        * glib/poppler-private.h:
        * glib/test-poppler-glib.c: Patch from Marco to simplify the glib
        rotation API.



Index: poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-page.cc,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- poppler-page.cc	6 Aug 2005 18:09:51 -0000	1.32
+++ poppler-page.cc	22 Aug 2005 18:20:12 -0000	1.33
@@ -45,29 +45,6 @@
 
 G_DEFINE_TYPE (PopplerPage, poppler_page, G_TYPE_OBJECT);
 
-static PopplerOrientation
-get_document_orientation (PopplerPage *page)
-{
-  PopplerOrientation orientation;
-  int rotation = page->page->getRotate ();
-
-  switch (rotation) {
-    case 90:
-      orientation = POPPLER_ORIENTATION_LANDSCAPE;
-      break;
-    case 180:
-      orientation = POPPLER_ORIENTATION_UPSIDEDOWN;
-      break;
-    case 270:
-      orientation = POPPLER_ORIENTATION_SEASCAPE;
-      break;
-    default:
-      orientation = POPPLER_ORIENTATION_PORTRAIT;
-  }
-
-  return orientation;
-}
-
 PopplerPage *
 _poppler_page_new (PopplerDocument *document, Page *page, int index)
 {
@@ -79,7 +56,6 @@
   poppler_page->document = document;
   poppler_page->page = page;
   poppler_page->index = index;
-  poppler_page->orientation = get_document_orientation (poppler_page);
 
   return poppler_page;
 }
@@ -97,54 +73,23 @@
   /* page->page is owned by the document */
 }
 
-static int
-poppler_page_get_rotate (PopplerPage *page)
-{
-  int rotate;
-
-  switch (page->orientation) {
-    case POPPLER_ORIENTATION_PORTRAIT:
-      rotate = 0;
-      break;
-    case POPPLER_ORIENTATION_LANDSCAPE:
-      rotate = 90;
-      break;
-    case POPPLER_ORIENTATION_UPSIDEDOWN:
-      rotate = 180;
-      break;
-    case POPPLER_ORIENTATION_SEASCAPE:
-      rotate = 270;
-      break;
-    default:
-      rotate = page->page->getRotate ();
-  }
-
-  return rotate - page->page->getRotate ();
-}
-
 void
 poppler_page_get_size (PopplerPage *page,
 		       double      *width,
 		       double      *height)
 {
   double page_width, page_height;
+  int rotate;
 
   g_return_if_fail (POPPLER_IS_PAGE (page));
 
-  switch (page->orientation) {
-    case POPPLER_ORIENTATION_PORTRAIT:
-    case POPPLER_ORIENTATION_UPSIDEDOWN:
-      page_width = page->page->getWidth ();
-      page_height = page->page->getHeight ();
-      break;
-    case POPPLER_ORIENTATION_LANDSCAPE:
-    case POPPLER_ORIENTATION_SEASCAPE:
-      page_width = page->page->getHeight ();
-      page_height = page->page->getWidth ();
-      break;
-    default:
-      page_width = page_height = 0;
-      g_assert_not_reached ();
+  rotate = page->page->getRotate ();
+  if (rotate == 90 || rotate == 270) {
+    page_height = page->page->getWidth ();
+    page_width = page->page->getHeight ();
+  } else {
+    page_width = page->page->getWidth ();
+    page_height = page->page->getHeight ();
   }
 
   if (width != NULL)
@@ -179,20 +124,8 @@
   int cairo_width, cairo_height, cairo_rowstride;
   unsigned char *cairo_data;
 
-  switch (page->orientation) {
-  case POPPLER_ORIENTATION_PORTRAIT:
-  case POPPLER_ORIENTATION_UPSIDEDOWN:
-    cairo_width = MAX ((int)(page->page->getWidth() * scale + 0.5), 1);
-    cairo_height = MAX ((int)(page->page->getHeight() * scale + 0.5), 1);
-    break;
-  case POPPLER_ORIENTATION_LANDSCAPE:
-  case POPPLER_ORIENTATION_SEASCAPE:
-    cairo_width = MAX ((int)(page->page->getHeight() * scale + 0.5), 1);
-    cairo_height = MAX ((int)(page->page->getWidth() * scale + 0.5), 1);
-    break;
-  default:
-    g_assert_not_reached();
-  }
+  cairo_width = MAX ((int)(page->page->getWidth() * scale + 0.5), 1);
+  cairo_height = MAX ((int)(page->page->getHeight() * scale + 0.5), 1);
 
   output_dev = page->document->output_dev;
   cairo_rowstride = cairo_width * 4;
@@ -331,7 +264,7 @@
  * @src_y: y coordinate of upper left corner
  * @src_width: width of rectangle to render
  * @src_height: height of rectangle to render
- * @ppp: pixels per point
+ * @rotation: rotate the document by the specified degree
  * @pixbuf: pixbuf to render into
  *
  * First scale the document to match the specified pixels per point,
@@ -343,6 +276,7 @@
 			       int src_x, int src_y,
 			       int src_width, int src_height,
 			       double scale,
+			       int rotation,
 			       GdkPixbuf *pixbuf)
 {
   OutputDevData data;
@@ -355,7 +289,7 @@
 
   page->page->displaySlice(page->document->output_dev,
 			   72.0 * scale, 72.0 * scale,
-			   poppler_page_get_rotate (page),
+			   rotation,
 			   gTrue, /* Crop */
 			   src_x, src_y,
 			   src_width, src_height,
@@ -372,8 +306,7 @@
     page->text_dev = new TextOutputDev (NULL, gTrue, gFalse, gFalse);
 
     page->gfx = page->page->createGfx(page->text_dev,
-				      72.0, 72.0,
-				      poppler_page_get_rotate (page),
+				      72.0, 72.0, 0,
 				      gTrue, /* Crop */
 				      -1, -1, -1, -1,
 				      NULL, /* links */
@@ -650,7 +583,7 @@
   g_return_val_if_fail (selection != NULL, NULL);
 
   text_dev = poppler_page_get_text_output_dev (page);
-  height = page->page->getHeight ();
+  poppler_page_get_size (page, NULL, &height);
 
   pdf_selection.x1 = selection->x1;
   pdf_selection.y1 = height - selection->y2;
@@ -695,8 +628,8 @@
   output_dev = new TextOutputDev (NULL, gTrue, gFalse, gFalse);
   doc = page->document->doc;
 
-  height = page->page->getHeight ();
-  page->page->display (output_dev, 72, 72, poppler_page_get_rotate (page),
+  poppler_page_get_size (page, NULL, &height);
+  page->page->display (output_dev, 72, 72, 0,
 		       gTrue, NULL, doc->getCatalog());
   
   matches = NULL;
@@ -747,7 +680,7 @@
 
 
   ps_file->document->doc->displayPage (ps_file->out, page->index + 1, 72.0, 72.0,
-				       poppler_page_get_rotate (page), gTrue, gFalse);
+				       0, gTrue, gFalse);
 }
 
 static void
@@ -871,39 +804,6 @@
 	g_list_free (list);
 }
 
-/**
- * poppler_page_set_orientation:
- * @page: a #PopplerPage
- * @orientation: a #PopplerOrientation
- *
- * Force the orientation of the page to be the specified one
- *
- **/
-void
-poppler_page_set_orientation (PopplerPage        *page,
-			      PopplerOrientation  orientation)
-{
-  g_return_if_fail (POPPLER_IS_PAGE (page));
-
-  page->orientation = orientation;
-}
-
-/**
- * poppler_page_get_orientation:
- * @page: a #PopplerPage
- * @orientation: a #PopplerOrientation
- *
- * Return the orientation of the specified page
- *
- * Return value: a #PopplerOrientation
- **/
-PopplerOrientation
-poppler_page_get_orientation (PopplerPage *page)
-{
-  g_return_val_if_fail (POPPLER_IS_PAGE (page), POPPLER_ORIENTATION_PORTRAIT);
-
-  return page->orientation;
-}
 /* PopplerRectangle type */
 
 GType

Index: poppler-page.h
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-page.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- poppler-page.h	6 Aug 2005 18:09:51 -0000	1.18
+++ poppler-page.h	22 Aug 2005 18:20:12 -0000	1.19
@@ -41,13 +41,11 @@
 						       int                 src_width,
 						       int                 src_height,
 						       double              scale,
+						       int                 rotation,
 						       GdkPixbuf          *pixbuf);
 void                poppler_page_get_size             (PopplerPage        *page,
 						       double             *width,
 						       double             *height);
-PopplerOrientation  poppler_page_get_orientation      (PopplerPage        *page);
-void                poppler_page_set_orientation      (PopplerPage        *page,
-						       PopplerOrientation  orientation);
 int                 poppler_page_get_index            (PopplerPage        *page);
 GdkPixbuf          *poppler_page_get_thumbnail        (PopplerPage        *page);
 gboolean            poppler_page_get_thumbnail_size   (PopplerPage        *page,

Index: poppler-private.h
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-private.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- poppler-private.h	27 Jul 2005 19:21:08 -0000	1.11
+++ poppler-private.h	22 Aug 2005 18:20:12 -0000	1.12
@@ -51,7 +51,6 @@
   PopplerDocument *document;
   Page *page;
   int index;
-  PopplerOrientation orientation;
   TextOutputDev *text_dev;
   Gfx *gfx;
 };

Index: test-poppler-glib.c
===================================================================
RCS file: /cvs/poppler/poppler/glib/test-poppler-glib.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- test-poppler-glib.c	30 Jun 2005 19:44:33 -0000	1.13
+++ test-poppler-glib.c	22 Aug 2005 18:20:12 -0000	1.14
@@ -135,7 +135,7 @@
 
   pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 220, 220);
   gdk_pixbuf_fill (pixbuf, 0x00106000);
-  poppler_page_render_to_pixbuf (page, 100, 100, 200, 200, 1, pixbuf);
+  poppler_page_render_to_pixbuf (page, 100, 100, 200, 200, 1, 0, pixbuf);
 
   gdk_pixbuf_save (pixbuf, "slice.png", "png", &error, NULL);
   printf ("\tslice:\t\tsaved 200x200 slice at (100, 100) as slice.png\n");



More information about the poppler mailing list