[poppler] poppler/glib: poppler-action.cc, 1.9, 1.9.2.1 poppler-page.cc, 1.51, 1.51.2.1

Albert Astals Cid aacid at kemper.freedesktop.org
Sun Jan 28 07:56:19 PST 2007


Update of /cvs/poppler/poppler/glib
In directory kemper:/tmp/cvs-serv4746/glib

Modified Files:
      Tag: POPPLER_0_5_X
	poppler-action.cc poppler-page.cc 
Log Message:
        * glib/poppler-page.cc: Make link mapping coordinates follow page
        rotation. Patch by Carlos Garcia Campos <carlosgc at gnome.org>
        * glib/poppler-action.cc: Fix link destination coordinates. Patch by
        Carlos Garcia Campos <carlosgc at gnome.org>


Index: poppler-action.cc
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-action.cc,v
retrieving revision 1.9
retrieving revision 1.9.2.1
diff -u -d -r1.9 -r1.9.2.1
--- poppler-action.cc	19 May 2006 22:26:03 -0000	1.9
+++ poppler-action.cc	28 Jan 2007 15:56:17 -0000	1.9.2.1
@@ -249,7 +249,20 @@
 	dest->change_left = link_dest->getChangeLeft ();
 	dest->change_top = link_dest->getChangeTop ();
 	dest->change_zoom = link_dest->getChangeZoom ();
-
+	
+	if (dest->page_num > 0) {
+		PopplerPage *page;
+		
+		page = poppler_document_get_page (document, dest->page_num - 1);
+		
+		dest->left -= page->page->getCropBox ()->x1;
+		dest->bottom -= page->page->getCropBox ()->x1;
+		dest->right -= page->page->getCropBox ()->y1;
+		dest->top -= page->page->getCropBox ()->y1;
+		
+		g_object_unref (page);
+	}
+	
 	return dest;
 }
 

Index: poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/glib/poppler-page.cc,v
retrieving revision 1.51
retrieving revision 1.51.2.1
diff -u -d -r1.51 -r1.51.2.1
--- poppler-page.cc	21 Sep 2006 22:40:53 -0000	1.51
+++ poppler-page.cc	28 Jan 2007 15:56:17 -0000	1.51.2.1
@@ -825,7 +825,6 @@
 {
 }
 
-
 /**
  * poppler_page_get_link_mapping:
  * @page: A #PopplerPage
@@ -839,52 +838,87 @@
 GList *
 poppler_page_get_link_mapping (PopplerPage *page)
 {
-	GList *map_list = NULL;
-	gint i;
-	Links *links;
-	Object obj;
-
-	g_return_val_if_fail (POPPLER_IS_PAGE (page), NULL);
-
-	links = new Links (page->page->getAnnots (&obj),
-			   page->document->doc->getCatalog ()->getBaseURI ());
-	obj.free ();
-
-	if (links == NULL)
-		return NULL;
-
-	for (i = 0; i < links->getNumLinks (); i++) {
-		PopplerLinkMapping *mapping;
-		LinkAction *link_action;
-		Link *link;
-
-		link = links->getLink (i);
-		link_action = link->getAction ();
-
-		/* Create the mapping */
-		mapping = g_new (PopplerLinkMapping, 1);
-		mapping->action = _poppler_action_new (page->document, link_action, NULL);
-		link->getRect (&(mapping->area.x1), &(mapping->area.y1),
-			       &(mapping->area.x2), &(mapping->area.y2));
-
-		mapping->area.x1 -= page->page->getCropBox()->x1;
-		mapping->area.x2 -= page->page->getCropBox()->x1;
-		mapping->area.y1 -= page->page->getCropBox()->y1;
-		mapping->area.y2 -= page->page->getCropBox()->y1;
-
-		map_list = g_list_prepend (map_list, mapping);
+  GList *map_list = NULL;
+  gint i;
+  Links *links;
+  Object obj;
+  double width, height;
+  
+  g_return_val_if_fail (POPPLER_IS_PAGE (page), NULL);
+  
+  links = new Links (page->page->getAnnots (&obj),
+		     page->document->doc->getCatalog ()->getBaseURI ());
+  obj.free ();
+  
+  if (links == NULL)
+    return NULL;
+  
+  poppler_page_get_size (page, &width, &height);
+  
+  for (i = 0; i < links->getNumLinks (); i++)
+    {
+      PopplerLinkMapping *mapping;
+      PopplerRectangle rect;
+      LinkAction *link_action;
+      Link *link;
+      
+      link = links->getLink (i);
+      link_action = link->getAction ();
+      
+      /* Create the mapping */
+      mapping = g_new (PopplerLinkMapping, 1);
+      mapping->action = _poppler_action_new (page->document, link_action, NULL);
+      
+      link->getRect (&rect.x1, &rect.y1, &rect.x2, &rect.y2);
+      
+      switch (page->page->getRotate ())
+        {
+        case 90:
+	  mapping->area.x1 = rect.y1;
+	  mapping->area.y1 = height - rect.x2;
+	  mapping->area.x2 = mapping->area.x1 + (rect.y2 - rect.y1);
+	  mapping->area.y2 = mapping->area.y1 + (rect.x2 - rect.x1);
+	  
+	  break;
+	case 180:
+	  mapping->area.x1 = width - rect.x2;
+	  mapping->area.y1 = height - rect.y2;
+	  mapping->area.x2 = mapping->area.x1 + (rect.x2 - rect.x1);
+	  mapping->area.y2 = mapping->area.y1 + (rect.y2 - rect.y1);
+	  
+	  break;
+	case 270:
+	  mapping->area.x1 = width - rect.y2;
+	  mapping->area.y1 = rect.x1;
+	  mapping->area.x2 = mapping->area.x1 + (rect.y2 - rect.y1);
+	  mapping->area.y2 = mapping->area.y1 + (rect.x2 - rect.x1);
+	  
+	  break;
+	default:
+	  mapping->area.x1 = rect.x1;
+	  mapping->area.y1 = rect.y1;
+	  mapping->area.x2 = rect.x2;
+	  mapping->area.y2 = rect.y2;
 	}
-
-	delete links;
-
-	return map_list;
+			
+      mapping->area.x1 -= page->page->getCropBox()->x1;
+      mapping->area.x2 -= page->page->getCropBox()->x1;
+      mapping->area.y1 -= page->page->getCropBox()->y1;
+      mapping->area.y2 -= page->page->getCropBox()->y1;
+      
+      map_list = g_list_prepend (map_list, mapping);
+    }
+  
+  delete links;
+  
+  return map_list;
 }
 
 static void
 poppler_mapping_free (PopplerLinkMapping *mapping)
 {
-	poppler_action_free (mapping->action);
-	g_free (mapping);
+  poppler_action_free (mapping->action);
+  g_free (mapping);
 }
 
 /**
@@ -899,11 +933,11 @@
 void
 poppler_page_free_link_mapping (GList *list)
 {
-	if (list == NULL)
-		return;
+  if (list == NULL)
+    return;
 
-	g_list_foreach (list, (GFunc) (poppler_mapping_free), NULL);
-	g_list_free (list);
+  g_list_foreach (list, (GFunc) (poppler_mapping_free), NULL);
+  g_list_free (list);
 }
 
 /* PopplerRectangle type */



More information about the poppler mailing list