Permalink
Browse files

forward search for sumatra pdf

  • Loading branch information...
1 parent 6880f3f commit 1d4f66f479cdb619b6903ba2736a336f912091a7 @jjallaire jjallaire committed with jcheng5 May 2, 2012
View
@@ -28,6 +28,7 @@ used by these components are included below):
- ZLib
- Sundown
- highlight.js
+- SumatraPDF
GNU GPL Version 3
View
@@ -24,6 +24,11 @@ RStudio for Windows is bundled with various binaries from the MSYS
project. You can obtain the source code for MSYS at:
http://sourceforge.net/projects/mingw/files/MSYS/
+
+RStudio for Windows is bunled with a binary copy of SumatraPDF.
+You can obtain the source code for SumatraPDF at:
+
+ http://code.google.com/p/sumatrapdf/
In the alternate, you may request a copy of the GNU DiffUtils or MSYS
source code by e-mail to info@rstudio.org.
@@ -16,6 +16,7 @@ set JUNIT_FILE=junit-4.9b3.jar
set GNUDIFF_FILE=gnudiff.zip
set GNUGREP_FILE=gnugrep-2.5.4.zip
set MSYS_SSH_FILE=msys_ssh.zip
+set SUMATRA_PDF_FILE=SumatraPDF-2.0.1.zip
if not exist boost-win (
wget %WGET_ARGS% "%BASEURL%%BOOST_FILE%"
@@ -55,6 +56,14 @@ if not exist msys_ssh (
del "%MSYS_SSH_FILE%"
)
+if not exist sumatra (
+ wget %WGET_ARGS% "%BASEURL%%SUMATRA_PDF_FILE%"
+ mkdir sumatra
+ echo Unzipping %SUMATRA_PDF_FILE%
+ unzip %UNZIP_ARGS% "%SUMATRA_PDF_FILE%" -d sumatra
+ del "%SUMATRA_PDF_FILE%"
+)
+
if not exist ..\..\src\gwt\lib (
mkdir ..\..\src\gwt\lib
)
@@ -0,0 +1,2 @@
+sumatrapdfprefs.dat
+sumatrapdfcache
@@ -42,6 +42,7 @@ external-consoleio-path=${CMAKE_CURRENT_BINARY_DIR}/session/consoleio/consoleio.
external-gnudiff-path=${RSTUDIO_WINDOWS_DEPENDENCIES_DIR}/gnudiff
external-gnugrep-path=${RSTUDIO_WINDOWS_DEPENDENCIES_DIR}/gnugrep
external-msysssh-path=${RSTUDIO_WINDOWS_DEPENDENCIES_DIR}/msys_ssh
+external-sumatra-path=${RSTUDIO_WINDOWS_DEPENDENCIES_DIR}/sumatra
external-hunspell-dictionaries-path=${RSTUDIO_DEPENDENCIES_DIR}/common/dictionaries
@@ -75,6 +75,11 @@ if(WIN32 OR APPLE)
${CMAKE_CURRENT_SOURCE_DIR}/synctex/evince/EvinceSynctex.hpp
)
endif()
+if(NOT WIN32)
+ list(REMOVE_ITEM MOC_DESKTOP_HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/synctex/sumatra/SumatraSynctex.hpp
+ )
+endif()
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)
@@ -117,6 +122,7 @@ if(WIN32)
DesktopWin32ApplicationLaunch.cpp
DesktopRVersion.cpp
DesktopWin32DetectRHome.cpp
+ synctex/sumatra/SumatraSynctex.cpp
)
list(REMOVE_ITEM MOC_DESKTOP_HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/DesktopPosixApplication.hpp
@@ -89,8 +89,8 @@ MainWindow::MainWindow(QUrl url) :
QString MainWindow::getSumatraPdfExePath()
{
QWebFrame* pMainFrame = webView()->page()->mainFrame();
- QString sumatraPath = pMainFrame->evaluateJavaScript(
- QString::fromAscii("window.getSumatraPdfExePath()")).toString();
+ QString sumatraPath = pMainFrame->evaluateJavaScript(QString::fromAscii(
+ "window.desktopHooks.getSumatraPdfExePath()")).toString();
return sumatraPath;
}
@@ -23,10 +23,10 @@
#include "DesktopUtils.hpp"
// per-platform synctex implemetnations
-#if defined(Q_OS_DARWIN)
+#if defined(Q_WS_MACX)
#elif defined(Q_OS_WIN)
-
+#include "synctex/sumatra/SumatraSynctex.hpp"
#elif defined(Q_OS_LINUX)
#include "synctex/evince/EvinceSynctex.hpp"
#endif
@@ -61,7 +61,12 @@ SynctexViewer s_viewer;
SynctexViewer discoverViewer()
{
- return SynctexViewer();
+ SynctexViewer sv;
+ sv.name = QString::fromAscii("SumatraPDF");
+ sv.versionMajor = 2;
+ sv.versionMinor = 0;
+ sv.versionPatch = 1;
+ return sv;
}
#elif defined(Q_OS_LINUX)
@@ -141,10 +146,10 @@ QString Synctex::desktopViewerName()
Synctex* Synctex::create(MainWindow* pMainWindow)
{
// per-platform synctex implemetnations
-#if defined(Q_OS_DARWIN)
+#if defined(Q_WS_MACX)
return new Synctex(pMainWindow);
#elif defined(Q_OS_WIN)
- return new Synctex(pMainWindow);
+ return new synctex::SumatraSynctex(pMainWindow);
#elif defined(Q_OS_LINUX)
return new synctex::EvinceSynctex(pMainWindow);
#else
@@ -0,0 +1,72 @@
+/*
+ * SumatraSynctex.cpp
+ *
+ * Copyright (C) 2009-12 by RStudio, Inc.
+ *
+ * This program is licensed to you under the terms of version 3 of the
+ * GNU Affero General Public License. This program is distributed WITHOUT
+ * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
+ * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
+ *
+ */
+
+#include "SumatraSynctex.hpp"
+
+#include <boost/lexical_cast.hpp>
+
+#include <core/Log.hpp>
+#include <core/Error.hpp>
+
+#include "DesktopUtils.hpp"
+
+using namespace core;
+
+namespace desktop {
+namespace synctex {
+
+namespace {
+
+
+QStringList standardSumatraArgs()
+{
+ QStringList args;
+ args.append(QString::fromAscii("-bg-color"));
+ args.append(QString::fromAscii("#ffffff"));
+ args.append(QString::fromAscii("-reuse-instance"));
+ return args;
+}
+
+
+} // anonymous namespace
+
+SumatraSynctex::SumatraSynctex(MainWindow* pMainWindow)
+ : Synctex(pMainWindow)
+{
+ sumatraExePath_ = pMainWindow->getSumatraPdfExePath();
+}
+
+void SumatraSynctex::syncView(const QString& pdfFile,
+ const QString& srcFile,
+ const QPoint& srcLoc)
+{
+ QStringList args = standardSumatraArgs();
+ args.append(QString::fromAscii("-forward-search"));
+ args.append(srcFile);
+ args.append(
+ QString::fromStdString(boost::lexical_cast<std::string>(srcLoc.x())));
+ args.append(pdfFile);
+ QProcess::startDetached(sumatraExePath_, args);
+}
+
+void SumatraSynctex::syncView(const QString& pdfFile, int page)
+{
+ QStringList args = standardSumatraArgs();
+ args.append(QString::fromAscii("-page"));
+ args.append(QString::fromStdString(boost::lexical_cast<std::string>(page)));
+ args.append(pdfFile);
+ QProcess::startDetached(sumatraExePath_, args);
+}
+
+} // namesapce synctex
+} // namespace desktop
@@ -0,0 +1,50 @@
+/*
+ * SumatraSynctex.hpp
+ *
+ * Copyright (C) 2009-12 by RStudio, Inc.
+ *
+ * This program is licensed to you under the terms of version 3 of the
+ * GNU Affero General Public License. This program is distributed WITHOUT
+ * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
+ * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
+ *
+ */
+
+#ifndef DESKTOP_SYNCTEX_SUMATRASYNCTEX_HPP
+#define DESKTOP_SYNCTEX_SUMATRASYNCTEX_HPP
+
+#include <QObject>
+#include <QMap>
+#include <QPoint>
+
+#include <DesktopSynctex.hpp>
+
+namespace desktop {
+
+class MainWindow;
+
+namespace synctex {
+
+class SumatraSynctex : public Synctex
+{
+ Q_OBJECT
+
+public:
+ explicit SumatraSynctex(MainWindow* pMainWindow);
+
+ virtual void syncView(const QString& pdfFile,
+ const QString& srcFile,
+ const QPoint& srcLoc);
+
+ virtual void syncView(const QString& pdfFile, int pdfPage);
+
+private:
+ QString sumatraExePath_;
+};
+
+
+} // namespace synctex
+} // namespace desktop
+
+#endif // DESKTOP_SYNCTEX_SUMATRASYNCTEX_HPP
@@ -268,7 +268,7 @@ if (NOT RSTUDIO_SESSION_WIN64)
endif()
endif()
- # install gnudiff and mysys_ssh on windows
+ # install gnudiff, mysys_ssh, and sumatra-pdf on windows
if(WIN32)
install(DIRECTORY "${RSTUDIO_WINDOWS_DEPENDENCIES_DIR}/gnudiff"
USE_SOURCE_PERMISSIONS
@@ -279,6 +279,12 @@ if (NOT RSTUDIO_SESSION_WIN64)
install(DIRECTORY "${RSTUDIO_WINDOWS_DEPENDENCIES_DIR}/msys_ssh"
USE_SOURCE_PERMISSIONS
DESTINATION ${RSTUDIO_INSTALL_BIN})
+
+
+ install(PROGRAMS "${RSTUDIO_WINDOWS_DEPENDENCIES_DIR}/sumatra/SumatraPDF.exe"
+ DESTINATION "${RSTUDIO_INSTALL_BIN}/sumatra")
+ install(FILES resources/sumatrapdfrestrict.ini
+ DESTINATION "${RSTUDIO_INSTALL_BIN}/sumatra")
endif()
endif()
@@ -456,9 +456,10 @@ void handleClientInit(const boost::function<void()>& initFunction,
sessionInfo["internal_pdf_preview_enabled"] =
modules::authoring::isPdfViewerSupported(userAgent);
- // send sumatra pdf if we are on windows
+ // send sumatra pdf exe path if we are on windows
#ifdef _WIN32
- sessionInfo["sumatra_pdf_exe_path"] = "";
+ sessionInfo["sumatra_pdf_exe_path"] =
+ options.sumatraPath().complete("SumatraPDF.exe").absolutePath();
#endif
// send response (we always set kEventsPending to false so that the client
@@ -252,6 +252,9 @@ core::ProgramStatus Options::read(int argc, char * const argv[])
("external-msysssh-path",
value<std::string>(&msysSshPath_)->default_value("bin/msys_ssh"),
"Path to msys_ssh utilities (windows-only)")
+ ("external-sumatra-path",
+ value<std::string>(&sumatraPath_)->default_value("bin/sumatra"),
+ "Path to SumatraPDF (windows-only)")
("external-hunspell-dictionaries-path",
value<std::string>(&hunspellDictionariesPath_)->default_value("resources/dictionaries"),
"Path to hunspell dictionaries");
@@ -362,7 +365,7 @@ core::ProgramStatus Options::read(int argc, char * const argv[])
resolvePath(resourcePath, &gnudiffPath_);
resolvePath(resourcePath, &gnugrepPath_);
resolvePath(resourcePath, &msysSshPath_);
-
+ resolvePath(resourcePath, &sumatraPath_);
#endif
resolvePath(resourcePath, &hunspellDictionariesPath_);
@@ -197,6 +197,11 @@ class Options : boost::noncopyable
{
return core::FilePath(msysSshPath_.c_str());
}
+
+ core::FilePath sumatraPath() const
+ {
+ return core::FilePath(sumatraPath_.c_str());
+ }
core::FilePath hunspellDictionariesPath() const
{
@@ -319,6 +324,7 @@ class Options : boost::noncopyable
std::string gnudiffPath_;
std::string gnugrepPath_;
std::string msysSshPath_;
+ std::string sumatraPath_;
std::string hunspellDictionariesPath_;
// user info
@@ -0,0 +1,60 @@
+; To apply this configuration, copy this file into
+; the same directory as SumatraPDF.exe.
+
+; All settings listed below can have a value of either
+; 0 for disabling the feature or 1 for enabling the feature
+; (missing settings default to 0).
+
+[Policies]
+; Whether SumatraPDF should be allowed to access the Internet.
+; Needed for:
+; * Checking for updates
+; * Sending crash reports
+InternetAccess = 0
+
+; Whether SumatraPDF should allow access to the file system.
+; Needed for:
+; * Opening files through dialog
+; * Saving file or bookmark shortcut
+; * Opening a web browser after a click on a hyperlink
+; * Launching external PDF viewers, LaTeX source editors or media players
+; * Displaying Frequently Read page (also requires SavePreferences)
+; * Reopening recently opened files
+DiskAccess = 1
+
+; Whether SumatraPDF should save user preferences on exit.
+; Needed for:
+; * Changing settings
+; * Favorites menu
+; * Remembering recently opened files (includes Frequently Read page)
+SavePreferences = 0
+
+; Whether SumatraPDF should be allowed to write to the Registry.
+; Needed for:
+; * Making SumatraPDF a default PDF viewer
+RegistryAccess = 0
+
+; Whether SumatraPDF should be allowed to print.
+; Needed for:
+; * Printing (parts of) a document
+PrinterAccess = 1
+
+; Whether users should be allowed to select and copy content.
+; Needed for:
+; * Selecting with the mouse
+; * Select all
+; * Copying the selection
+CopySelection = 1
+
+; What protocols for links inside documents should be passed
+; on to the operating system (e.g. for opening a browser).
+; Default: http,https,mailto (web links and email addresses)
+LinkProtocols = http,https,mailto
+
+; What file types should be opened in an external application
+; if they're linked to by a (PDF) document and can't be opened
+; within SumatraPDF itself (use "*" for all types)
+; These file types are stored as "PerceivedType" in the Registry,
+; common values: audio, video, image, document, text, system
+; Default: audio,video,webpage
+SafeFileTypes = audio,video,webpage

0 comments on commit 1d4f66f

Please sign in to comment.