Package: xpdf
Version: 3.02-12+squeeze1
Tags: patch

fix-580495.patch introduces a pointer variable zoomMenuBtns which is
allocated with 'operator new[]' but freed by a plain 'delete'.
Furthermore, when using fullscreen display, this variable is
uninitialized, which can cause a crash upon closing.

A fixed version of this patch is appended.

Regards,
Wolfram.

description: add additional zoom features
 This merges 2 different feature patches into one working one.
 http://bugs.debian.org/424178 hight patch
 http://bugs.debian.org/578892 bug fix to hight patch
 http://bugs.debian.org/580495 high mag zoom
author: Rogério Brito, Josh Triplett, Emmanuel Thomé
debian-bug: http://bugs.debian.org/580495
Index: xpdf-3.02/xpdf/XPDFViewer.cc
===================================================================
--- xpdf-3.02.orig/xpdf/XPDFViewer.cc	2012-02-09 14:25:22.000000000 +0100
+++ xpdf-3.02/xpdf/XPDFViewer.cc	2012-02-09 17:07:27.000000000 +0100
@@ -140,7 +140,11 @@
   double zoom;
 };
 
-static ZoomMenuInfo zoomMenuInfo[nZoomMenuItems] = {
+static ZoomMenuInfo zoomMenuInfo[] = {
+  { "1600%",    1600 },
+  { "1200%",    1200 },
+  { "800%",      800 },
+  { "600%",      600 },
   { "400%",      400 },
   { "200%",      200 },
   { "150%",      150 },
@@ -150,14 +154,18 @@
   { "25%",        25 },
   { "12.5%",      12.5 },
   { "fit page",  zoomPage },
-  { "fit width", zoomWidth }
+  { "fit width", zoomWidth },
+  { "fit height", zoomHeight }
 };
 
+#define nZoomMenuItems (sizeof(zoomMenuInfo)/sizeof(struct ZoomMenuInfo))
+
 #define maxZoomIdx   0
-#define defZoomIdx   3
-#define minZoomIdx   7
-#define zoomPageIdx  8
-#define zoomWidthIdx 9
+#define defZoomIdx   7
+#define minZoomIdx   nZoomMenuItems - 4
+#define zoomPageIdx  nZoomMenuItems - 3
+#define zoomWidthIdx nZoomMenuItems - 2
+#define zoomHeightIdx nZoomMenuItems -1
 
 //------------------------------------------------------------------------
 
@@ -229,6 +237,7 @@
   { "toggleFullScreenMode",    0, gFalse, gFalse, &XPDFViewer::cmdToggleFullScreenMode },
   { "toggleOutline",           0, gFalse, gFalse, &XPDFViewer::cmdToggleOutline },
   { "windowMode",              0, gFalse, gFalse, &XPDFViewer::cmdWindowMode },
+  { "zoomFitHeight",           0, gFalse, gFalse, &XPDFViewer::cmdZoomFitHeight },
   { "zoomFitPage",             0, gFalse, gFalse, &XPDFViewer::cmdZoomFitPage },
   { "zoomFitWidth",            0, gFalse, gFalse, &XPDFViewer::cmdZoomFitWidth },
   { "zoomIn",                  0, gFalse, gFalse, &XPDFViewer::cmdZoomIn },
@@ -361,6 +370,7 @@
 
 XPDFViewer::~XPDFViewer() {
   delete core;
+  delete[] zoomMenuBtns;
   XmFontListFree(aboutBigFont);
   XmFontListFree(aboutVersionFont);
   XmFontListFree(aboutFixedFont);
@@ -1353,6 +1363,15 @@
   }
 }
 
+void XPDFViewer::cmdZoomFitHeight(GString *args[], int nArgs,
+				  XEvent *event) {
+  if (core->getZoom() != zoomHeight) {
+    setZoomIdx(zoomHeightIdx);
+    displayPage(core->getPageNum(), zoomHeight,
+		core->getRotate(), gTrue, gFalse);
+  }
+}
+
 void XPDFViewer::cmdZoomIn(GString *args[], int nArgs,
 			   XEvent *event) {
   int z;
@@ -1414,6 +1433,7 @@
   screenNum = XScreenNumberOfScreen(XtScreen(app->getAppShell()));
 
   toolBar = None;
+  zoomMenuBtns = NULL;
 #ifndef DISABLE_OUTLINE
   outlineScroll = None;
 #endif
@@ -1731,6 +1751,7 @@
 #else
   Widget menuPane;
   char buf[16];
+  zoomMenuBtns = new Widget[nZoomMenuItems];
   n = 0;
   menuPane = XmCreatePulldownMenu(toolBar, "zoomMenuPane", args, n);
   for (i = 0; i < nZoomMenuItems; ++i) {
Index: xpdf-3.02/xpdf/XPDFViewer.h
===================================================================
--- xpdf-3.02.orig/xpdf/XPDFViewer.h	2012-02-09 14:25:22.000000000 +0100
+++ xpdf-3.02/xpdf/XPDFViewer.h	2012-02-09 14:25:22.000000000 +0100
@@ -40,11 +40,6 @@
 
 //------------------------------------------------------------------------
 
-// NB: this must match the defn of zoomMenuBtnInfo in XPDFViewer.cc
-#define nZoomMenuItems 10
-
-//------------------------------------------------------------------------
-
 struct XPDFViewerCmd {
   char *name;
   int nArgs;
@@ -54,6 +49,8 @@
 };
 
 //------------------------------------------------------------------------
+
+//------------------------------------------------------------------------
 // XPDFViewer
 //------------------------------------------------------------------------
 
@@ -167,6 +164,7 @@
   void cmdWindowMode(GString *args[], int nArgs, XEvent *event);
   void cmdZoomFitPage(GString *args[], int nArgs, XEvent *event);
   void cmdZoomFitWidth(GString *args[], int nArgs, XEvent *event);
+  void cmdZoomFitHeight(GString *args[], int nArgs, XEvent *event);
   void cmdZoomIn(GString *args[], int nArgs, XEvent *event);
   void cmdZoomOut(GString *args[], int nArgs, XEvent *event);
   void cmdZoomPercent(GString *args[], int nArgs, XEvent *event);
@@ -327,7 +325,7 @@
   Widget zoomComboBox;
 #else
   Widget zoomMenu;
-  Widget zoomMenuBtns[nZoomMenuItems];
+  Widget *zoomMenuBtns;
 #endif
   Widget zoomWidget;
   Widget findBtn;
Index: xpdf-3.02/doc/xpdf.1
===================================================================
--- xpdf-3.02.orig/doc/xpdf.1	2012-02-09 14:25:22.000000000 +0100
+++ xpdf-3.02/doc/xpdf.1	2012-02-09 14:25:22.000000000 +0100
@@ -103,9 +103,9 @@
 .TP
 .BI \-z " zoom"
 Set the initial zoom factor.  A number specifies a zoom percentage,
-where 100 means 72 dpi.You may also specify \'page', to fit the page
-to the window size, or \'width', to fit the page width to the window
-width.
+where 100 means 72 dpi.  You may also specify \'page', to fit the page
+to the window size, \'width', to fit the page width to the window width,
+or \'height', to fit the page height to the window height.
 .RB "[config file: " initialZoom "; or X resource: " xpdf.initialZoom ]
 .TP
 .B \-cont
@@ -434,6 +434,9 @@
 .B w
 Set the zoom factor to 'width' (fit page width to window).
 .TP
+.B h
+Set the zoom factor to 'height' (fit page height to window).
+.TP
 .B alt-F
 Toggle full-screen mode.
 .TP
@@ -586,6 +589,9 @@
 .B zoomFitWidth
 Set the zoom factor to fit-width.
 .TP
+.B zoomFitHeight
+Set the zoom factor to fit-height.
+.TP
 .B zoomIn
 Zoom in - go to the next higher zoom factor.
 .TP
@@ -794,6 +800,7 @@
     bind -              any         zoomOut
     bind z              any         zoomFitPage
     bind w              any         zoomFitWidth
+    bind h              any         zoomFitHeight
     bind alt-f          any         toggleFullScreenMode
     bind ctrl-l         any         redraw
     bind ctrl-w         any         closeWindow
Index: xpdf-3.02/doc/xpdfrc.5
===================================================================
--- xpdf-3.02.orig/doc/xpdfrc.5	2012-02-09 14:25:22.000000000 +0100
+++ xpdf-3.02/doc/xpdfrc.5	2012-02-09 14:25:22.000000000 +0100
@@ -365,11 +365,11 @@
 cross-hatching.  This defaults to "no".
 .SH MISCELLANEOUS SETTINGS
 .TP
-.BR initialZoom " \fIpercentage\fR | page | width"
+.BR initialZoom " \fIpercentage\fR | page | width | height"
 Sets the initial zoom factor.  A number specifies a zoom percentage,
 where 100 means 72 dpi.  You may also specify \'page', to fit the page
-to the window size, or \'width', to fit the page width to the window
-width.
+to the window size, \'width', to fit the page width to the window width,
+or \'height', to fit the page height to the window height.
 .TP
 .BR continuousView " yes | no"
 If set to "yes", xpdf will start in continuous view mode, i.e., with
Index: xpdf-3.02/xpdf/GlobalParams.cc
===================================================================
--- xpdf-3.02.orig/xpdf/GlobalParams.cc	2012-02-09 14:25:22.000000000 +0100
+++ xpdf-3.02/xpdf/GlobalParams.cc	2012-02-09 18:19:45.000000000 +0100
@@ -895,6 +895,8 @@
 				     xpdfKeyContextAny, "zoomFitPage"));
   keyBindings->append(new KeyBinding('w', xpdfKeyModNone,
 				     xpdfKeyContextAny, "zoomFitWidth"));
+  keyBindings->append(new KeyBinding('h', xpdfKeyModNone,
+				     xpdfKeyContextAny, "zoomFitHeight"));
   keyBindings->append(new KeyBinding('f', xpdfKeyModAlt,
 				     xpdfKeyContextAny,
 				     "toggleFullScreenMode"));
Index: xpdf-3.02/xpdf/PDFCore.cc
===================================================================
--- xpdf-3.02.orig/xpdf/PDFCore.cc	2012-02-09 14:25:22.000000000 +0100
+++ xpdf-3.02/xpdf/PDFCore.cc	2012-02-09 14:25:22.000000000 +0100
@@ -433,6 +433,12 @@
     dpiA = (hDPI < vDPI) ? hDPI : vDPI;
   } else if (zoomA == zoomWidth) {
     dpiA = (drawAreaWidth / uw) * 72;
+  } else if (zoomA == zoomHeight) {
+    if (continuousMode) {
+      dpiA = ((drawAreaHeight - continuousModePageSpacing) / uh) * 72;
+    } else {
+      dpiA = (drawAreaHeight / uh) * 72;
+    }
   } else {
     dpiA = 0.01 * zoomA * 72;
   }
@@ -1162,6 +1168,24 @@
     dpi1 = 72.0 * (double)drawAreaWidth / pageW;
     sx = 0;
 
+  } else if (zoomA == zoomHeight) {
+    if (continuousMode) {
+      pageH = (rotate == 90 || rotate == 270) ? maxUnscaledPageW
+	                                      : maxUnscaledPageH;
+      dpi1 = 72.0 * (double)(drawAreaHeight - continuousModePageSpacing) / pageH;
+    } else {
+      rot = rotate + doc->getPageRotate(topPage);
+      if (rot >= 360) {
+	rot -= 360;
+      } else if (rot < 0) {
+	rot += 360;
+      }
+      pageH = (rot == 90 || rot == 270) ? doc->getPageCropWidth(topPage)
+	                                : doc->getPageCropHeight(topPage);
+      dpi1 = 72.0 * (double)drawAreaHeight / pageH;
+    }
+    sx = 0;
+
   } else if (zoomA <= 0) {
     return;
 
Index: xpdf-3.02/xpdf/PDFCore.h
===================================================================
--- xpdf-3.02.orig/xpdf/PDFCore.h	2012-02-09 14:25:22.000000000 +0100
+++ xpdf-3.02/xpdf/PDFCore.h	2012-02-09 14:25:22.000000000 +0100
@@ -39,6 +39,7 @@
 
 #define zoomPage  -1
 #define zoomWidth -2
+#define zoomHeight -3
 #define defZoom   125
 #define EPSILON   1.0e-7	// 32-bit floating point machine precision
 
Index: xpdf-3.02/xpdf/XPDFCore.cc
===================================================================
--- xpdf-3.02.orig/xpdf/XPDFCore.cc	2012-02-09 14:25:22.000000000 +0100
+++ xpdf-3.02/xpdf/XPDFCore.cc	2012-02-09 14:25:22.000000000 +0100
@@ -121,6 +121,8 @@
       zoom = zoomPage;
     } else if (!initialZoom->cmp("width")) {
       zoom = zoomWidth;
+    } else if (!initialZoom->cmp("height")) {
+      zoom = zoomHeight;
     } else {
       zoom = atoi(initialZoom->getCString());
       if (zoom <= 0) {
@@ -249,7 +251,7 @@
       width1 = doc->getPageCropWidth(pg);
       height1 = doc->getPageCropHeight(pg);
     }
-    if (zoom == zoomPage || zoom == zoomWidth) {
+    if (zoom == zoomPage || zoom == zoomWidth || zoom == zoomHeight) {
       width = (Dimension)(width1 * 0.01 * defZoom + 0.5);
       height = (Dimension)(height1 * 0.01 * defZoom + 0.5);
     } else {
@@ -1039,7 +1041,7 @@
   XtGetValues(core->drawArea, args, n);
   core->drawAreaWidth = (int)w;
   core->drawAreaHeight = (int)h;
-  if (core->zoom == zoomPage || core->zoom == zoomWidth) {
+  if (core->zoom == zoomPage || core->zoom == zoomWidth || core->zoom == zoomHeight) {
     sx = sy = -1;
   } else {
     sx = core->scrollX;
Index: xpdf-3.02/xpdf/about-text.h
===================================================================
--- xpdf-3.02.orig/xpdf/about-text.h	2007-02-27 23:05:52.000000000 +0100
+++ xpdf-3.02/xpdf/about-text.h	2012-02-09 14:25:22.000000000 +0100
@@ -36,7 +36,7 @@
   "  v              = forward (history path)",
   "  b              = backward (history path)",
   "  0 / + / -      = zoom zero / in / out",
-  "  z / w          = zoom page / page width",
+  "  z / w / h      = zoom page / page width / page height",
   "  alt-F          = toggle full-screen mode",
   "  ctrl-L         = redraw",
   "  q              = quit",

Reply via email to