[poppler] poppler/glib: poppler-page.cc, 1.13, 1.14 poppler-page.h, 1.10, 1.11 poppler-private.h, 1.4, 1.5 poppler.h, 1.3, 1.4

Kristian Hogsberg krh at freedesktop.org
Thu Apr 14 19:25:13 PDT 2005


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

Modified Files:
	poppler-page.cc poppler-page.h poppler-private.h poppler.h 
Log Message:
2005-04-14  Kristian Høgsberg  <krh at redhat.com>

        * glib/poppler-page.cc:
        * glib/poppler-page.h:
        * glib/poppler-private.h:
        * glib/poppler.h: Patch from Marco Pesenti Gritti to set page
        orientaton.



Index: poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-page.cc,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- poppler-page.cc	7 Apr 2005 22:01:51 -0000	1.13
+++ poppler-page.cc	15 Apr 2005 02:25:11 -0000	1.14
@@ -75,17 +75,90 @@
   /* page->page is owned by the document */
 }
 
+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;
+}
+
+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)
 {
+  PopplerOrientation orientation;
+  double page_width, page_height;
+
   g_return_if_fail (POPPLER_IS_PAGE (page));
 
+  if (page->orientation == POPPLER_ORIENTATION_DOCUMENT) {
+    orientation = get_document_orientation (page);
+  } else {
+    orientation = page->orientation;
+  }
+
+  switch (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 ();
+  }
+
   if (width != NULL)
-    *width = page->page->getWidth ();
+    *width = page_width;
   if (height != NULL)
-    *height = page->page->getHeight ();
+    *height = page_height;
 }
 
 int
@@ -117,7 +190,7 @@
   output_dev->startDoc(page->document->doc->getXRef ());
 
   page->page->displaySlice(output_dev, 72.0 * scale, 72.0 * scale,
-			   0, /* Rotate */
+			   poppler_page_get_rotate (page),
 			   gTrue, /* Crop */
 			   src_x, src_y,
 			   src_width, src_height,
@@ -182,7 +255,7 @@
   output_dev->startDoc(page->document->doc->getXRef ());
 
   page->page->displaySlice(output_dev, 72.0 * scale, 72.0 * scale,
-			   0, /* Rotate */
+			   poppler_page_get_rotate (page),
 			   gTrue, /* Crop */
 			   src_x, src_y,
 			   src_width, src_height,
@@ -365,7 +438,8 @@
   doc = page->document->doc;
 
   height = page->page->getHeight ();
-  page->page->display(output_dev, 72, 72, 0, gTrue, NULL, doc->getCatalog());
+  page->page->display(output_dev, 72, 72, poppler_page_get_rotate (page),
+		      gTrue, NULL, doc->getCatalog());
 
   y1 = height - rect->y2;
   y2 = height - rect->y1;
@@ -409,7 +483,8 @@
   doc = page->document->doc;
 
   height = page->page->getHeight ();
-  page->page->display (output_dev, 72, 72, 0, gTrue, NULL, doc->getCatalog());
+  page->page->display (output_dev, 72, 72, poppler_page_get_rotate (page),
+		       gTrue, NULL, doc->getCatalog());
   
   matches = NULL;
   while (output_dev->findText (ucs4, ucs4_len,
@@ -446,8 +521,8 @@
   g_return_if_fail (POPPLER_IS_PAGE (page));
   g_return_if_fail (ps_file != NULL);
 
-  ps_file->document->doc->displayPage (ps_file->out, page->index + 1,
-				       72.0, 72.0, 0, gTrue, gFalse);
+  ps_file->document->doc->displayPage (ps_file->out, page->index + 1, 72.0, 72.0,
+				       poppler_page_get_rotate (page), gTrue, gFalse);
 }
 
 static void
@@ -490,6 +565,7 @@
 static void
 poppler_page_init (PopplerPage *page)
 {
+  page->orientation = POPPLER_ORIENTATION_DOCUMENT;
 }
 
 
@@ -564,3 +640,20 @@
 	g_list_foreach (list, (GFunc) (poppler_mapping_free), NULL);
 	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;
+}

Index: poppler-page.h
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-page.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- poppler-page.h	7 Apr 2005 22:01:51 -0000	1.10
+++ poppler-page.h	15 Apr 2005 02:25:11 -0000	1.11
@@ -31,27 +31,29 @@
 
 
 GType      poppler_page_get_type         (void) G_GNUC_CONST;
-void       poppler_page_render_to_pixbuf   (PopplerPage   *page,
-					    int            src_x,
-					    int            src_y,
-					    int            src_width,
-					    int            src_height,
-					    double         scale,
-					    GdkPixbuf     *pixbuf,
-					    int            dest_x,
-					    int            dest_y);
-void       poppler_page_get_size           (PopplerPage   *page,
-					    double        *width,
-					    double        *height);
-int        poppler_page_get_index          (PopplerPage   *page);
-GdkPixbuf *poppler_page_get_thumbnail      (PopplerPage   *page);
-gboolean   poppler_page_get_thumbnail_size (PopplerPage   *page,
-					    int           *width,
-					    int           *height);
-GList     *poppler_page_find_text          (PopplerPage   *page,
-					    const  char   *text);
-void	   poppler_page_render_to_ps	   (PopplerPage   *page,
-					    PopplerPSFile *ps_file);
+void       poppler_page_render_to_pixbuf   (PopplerPage        *page,
+					    int                 src_x,
+					    int                 src_y,
+					    int                 src_width,
+					    int                 src_height,
+					    double              scale,
+					    GdkPixbuf          *pixbuf,
+					    int                 dest_x,
+					    int                 dest_y);
+void       poppler_page_get_size           (PopplerPage        *page,
+					    double             *width,
+					    double             *height);
+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,
+					    int                *width,
+					    int                *height);
+GList     *poppler_page_find_text          (PopplerPage        *page,
+					    const  char        *text);
+void	   poppler_page_render_to_ps	   (PopplerPage        *page,
+					    PopplerPSFile      *ps_file);
 
 /* A rectangle on a page, with coordinates in PDF points. */
 typedef struct
@@ -75,7 +77,6 @@
 GList *poppler_page_get_link_mapping  (PopplerPage *page);
 void   poppler_page_free_link_mapping (GList       *list);
 
-
 G_END_DECLS
 
 #endif /* __POPPLER_GLIB_H__ */

Index: poppler-private.h
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-private.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- poppler-private.h	7 Apr 2005 22:01:51 -0000	1.4
+++ poppler-private.h	15 Apr 2005 02:25:11 -0000	1.5
@@ -23,6 +23,7 @@
   PopplerDocument *document;
   Page *page;
   int index;
+  PopplerOrientation orientation;
 };
 
 PopplerPage   *_poppler_page_new   (PopplerDocument *document,

Index: poppler.h
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- poppler.h	30 Mar 2005 04:04:53 -0000	1.3
+++ poppler.h	15 Apr 2005 02:25:11 -0000	1.4
@@ -34,6 +34,15 @@
   POPPLER_ERROR_ENCRYPTED
 } PopplerError;
 
+typedef enum
+{
+	POPPLER_ORIENTATION_DOCUMENT,
+	POPPLER_ORIENTATION_PORTRAIT,
+	POPPLER_ORIENTATION_LANDSCAPE,
+	POPPLER_ORIENTATION_UPSIDEDOWN,
+	POPPLER_ORIENTATION_SEASCAPE
+} PopplerOrientation;
+
 G_END_DECLS
 
 #include "poppler-document.h"



More information about the poppler mailing list