PDF.js with incorrect zoom
PDF.js with incorrect zoom

As part of my job as Student Programmer at MIST I have the opportunity to contribute to Free and Open Source Software projects. In addition to giving back to the community, this provides a valuable opportunity to gain software development experience by working with different codebases, styles, and workflows. In this first post on the MIST Blog I will describe my experience contributing a bug fix to the Mozilla project PDF.js.

PDF.js is a project to implement a PDF reader in HTML and JavaScript. Its goal is to decrease users’ reliance on proprietary PDF readers to display documents on the Web. Formerly available as an add-on, PDF.js has been integrated with Mozilla Firefox since version 19.

Although PDF.js is capable of properly displaying many complex documents, many features remain unimplemented and many bugs persist. One of the bugs I encountered on my OSX development machine was that the PDF.js user interface zoomed along with the content when using the command key. This had been reported in the Mozilla bug-tracking system for several months before I decided to find a solution.

After downloading the source code, running it in a local environment, and browsing files for evidence of the cause, I discovered that there was a flaw in the logic that handled keyboard events. In particular, the code did not properly distinguish between the control key and the command key peculiar to Macs. I made the necessary changes and submitted a pull request to the PDF.js team for review. After ensuring the changes passed automated tests and squashing the commits as instructed by one of the contributors, my solution was accepted and the bug report was closed. According to Bugzilla, the fix should appear in Firefox 40.

commit 34d3b96b52fe95531b0a4ff14659edabcc6ba9ee
Author: Taylor Brown <browtayl@onid.oregonstate.edu>
Date:   Thu Apr 9 16:51:16 2015 -0700

    prevent viewer from zooming on cmd+mousewheel

diff --git a/web/viewer.js b/web/viewer.js
index f9788d8..87ea071 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -1981,7 +1981,8 @@ function handleMouseWheel(evt) {
   if (PresentationMode.active) {
     evt.preventDefault();
     PDFViewerApplication.mouseScroll(ticks * MOUSE_WHEEL_DELTA_FACTOR);
-  } else if (evt.ctrlKey) { // Only zoom the pages, not the entire viewer
+  } else if (evt.ctrlKey || evt.metaKey) {
+    // Only zoom the pages, not the entire viewer
     evt.preventDefault();
     PDFViewerApplication[direction](Math.abs(ticks));
   }

I have uploaded a screencast to OSU MediaSpace demonstrating the problem and the solution. It was satisfying to make a small but meaningful contribution to a widely-used Free Software project in the course of my work, and I look forward to doing so again.

Print Friendly, PDF & Email

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

required