📄 xpdfviewer.cc
字号:
//========================================================================//// XPDFViewer.cc//// Copyright 2002 Glyph & Cog, LLC////========================================================================#include <aconf.h>#ifdef USE_GCC_PRAGMAS#pragma implementation#endif#include <stdlib.h>#include <string.h>#include <ctype.h>#include <X11/cursorfont.h>#ifdef HAVE_X11_XPM_H#include <X11/xpm.h>#endif#include "gmem.h"#include "gfile.h"#include "GString.h"#include "GList.h"#include "Error.h"#include "GlobalParams.h"#include "PDFDoc.h"#include "ErrorCodes.h"#include "Outline.h"#include "UnicodeMap.h"#ifndef DISABLE_OUTLINE#define Object XtObject#include "XPDFTree.h"#undef Object#endif#include "XPDFApp.h"#include "XPDFViewer.h"#include "XPixmapOutputDev.h"#include "PSOutputDev.h"#include "config.h"// these macro defns conflict with xpdf's Object class#ifdef LESSTIF_VERSION#undef XtDisplay#undef XtScreen#undef XtWindow#undef XtParent#undef XtIsRealized#endif#if XmVERSION <= 1#define XmSET True#define XmUNSET False#endif//------------------------------------------------------------------------// GUI includes//------------------------------------------------------------------------#include "xpdfIcon.xpm"#include "leftArrow.xbm"#include "leftArrowDis.xbm"#include "dblLeftArrow.xbm"#include "dblLeftArrowDis.xbm"#include "rightArrow.xbm"#include "rightArrowDis.xbm"#include "dblRightArrow.xbm"#include "dblRightArrowDis.xbm"#include "backArrow.xbm"#include "backArrowDis.xbm"#include "forwardArrow.xbm"#include "forwardArrowDis.xbm"#include "find.xbm"#include "findDis.xbm"#include "print.xbm"#include "printDis.xbm"#include "about.xbm"#include "about-text.h"//------------------------------------------------------------------------XPDFViewer::XPDFViewer(XPDFApp *appA, GString *fileName, int pageA, GString *destName, GString *ownerPassword, GString *userPassword) { LinkDest *dest; int pg, z; GString *dir; app = appA; win = NULL; core = NULL; password = NULL; ok = gFalse;#ifndef DISABLE_OUTLINE outlineLabels = NULL; outlineLabelsLength = outlineLabelsSize = 0;#endif // do Motif-specific initialization and create the window; // this also creates the core object initWindow(); initAboutDialog(); initOpenDialog(); initFindDialog(); initSaveAsDialog(); initPrintDialog(); initPasswordDialog(); dest = NULL; // make gcc happy pg = pageA; // make gcc happy if (fileName) { if (loadFile(fileName, ownerPassword, userPassword)) { getPageAndDest(pageA, destName, &pg, &dest); if (pg > 0) { core->resizeToPage(pg); } dir = makePathAbsolute(grabPath(fileName->getCString())); setOpenDialogDir(dir->getCString()); setSaveAsDialogDir(dir->getCString()); delete dir; } else { return; } } // map the window -- we do this after calling resizeToPage to avoid // an annoying on-screen resize mapWindow(); // display the first page z = app->getFullScreen() ? zoomPage : core->getZoom(); if (dest) { displayDest(dest, z, core->getRotate(), gTrue); delete dest; } else { displayPage(pg, z, core->getRotate(), gTrue, gTrue); } ok = gTrue;}XPDFViewer::~XPDFViewer() { delete core; XmFontListFree(aboutBigFont); XmFontListFree(aboutVersionFont); XmFontListFree(aboutFixedFont); closeWindow();#ifndef DISABLE_OUTLINE if (outlineLabels) { gfree(outlineLabels); }#endif if (password) { delete password; }}void XPDFViewer::open(GString *fileName, int pageA, GString *destName) { LinkDest *dest; int pg, z; if (!core->getDoc() || fileName->cmp(core->getDoc()->getFileName())) { if (!loadFile(fileName, NULL, NULL)) { return; } } getPageAndDest(pageA, destName, &pg, &dest); z = app->getFullScreen() ? zoomPage : core->getZoom(); if (dest) { displayDest(dest, z, core->getRotate(), gTrue); delete dest; } else { displayPage(pg, z, core->getRotate(), gTrue, gTrue); }}void XPDFViewer::clear() { char *title; XmString s; core->clear(); // set up title, number-of-pages display title = app->getTitle() ? app->getTitle()->getCString() : (char *)xpdfAppName; XtVaSetValues(win, XmNtitle, title, XmNiconName, title, NULL); s = XmStringCreateLocalized(""); XtVaSetValues(pageNumText, XmNlabelString, s, NULL); XmStringFree(s); s = XmStringCreateLocalized(" of 0"); XtVaSetValues(pageCountLabel, XmNlabelString, s, NULL); XmStringFree(s); // disable buttons XtVaSetValues(prevTenPageBtn, XmNsensitive, False, NULL); XtVaSetValues(prevPageBtn, XmNsensitive, False, NULL); XtVaSetValues(nextTenPageBtn, XmNsensitive, False, NULL); XtVaSetValues(nextPageBtn, XmNsensitive, False, NULL);}//------------------------------------------------------------------------// load / display//------------------------------------------------------------------------GBool XPDFViewer::loadFile(GString *fileName, GString *ownerPassword, GString *userPassword) { return core->loadFile(fileName, ownerPassword, userPassword) == errNone;}void XPDFViewer::reloadFile() { int pg; if (!core->getDoc()) { return; } pg = core->getPageNum(); loadFile(core->getDoc()->getFileName()); if (pg > core->getDoc()->getNumPages()) { pg = core->getDoc()->getNumPages(); } displayPage(pg, core->getZoom(), core->getRotate(), gFalse, gFalse);}void XPDFViewer::displayPage(int pageA, int zoomA, int rotateA, GBool scrollToTop, GBool addToHist) { core->displayPage(pageA, zoomA, rotateA, scrollToTop, addToHist);}void XPDFViewer::displayDest(LinkDest *dest, int zoomA, int rotateA, GBool addToHist) { core->displayDest(dest, zoomA, rotateA, addToHist);}void XPDFViewer::getPageAndDest(int pageA, GString *destName, int *pageOut, LinkDest **destOut) { Ref pageRef; // find the page number for a named destination *pageOut = pageA; *destOut = NULL; if (destName && (*destOut = core->getDoc()->findDest(destName))) { if ((*destOut)->isPageRef()) { pageRef = (*destOut)->getPageRef(); *pageOut = core->getDoc()->findPage(pageRef.num, pageRef.gen); } else { *pageOut = (*destOut)->getPageNum(); } } if (*pageOut <= 0) { *pageOut = 1; } if (*pageOut > core->getDoc()->getNumPages()) { *pageOut = core->getDoc()->getNumPages(); }}//------------------------------------------------------------------------// password dialog//------------------------------------------------------------------------GString *XPDFViewer::reqPasswordCbk(void *data, GBool again) { XPDFViewer *viewer = (XPDFViewer *)data; viewer->getPassword(again); return viewer->password;}//------------------------------------------------------------------------// actions//------------------------------------------------------------------------void XPDFViewer::actionCbk(void *data, char *action) { XPDFViewer *viewer = (XPDFViewer *)data; if (!strcmp(action, "Quit")) { viewer->app->quit(); }}//------------------------------------------------------------------------// keyboard/mouse input//------------------------------------------------------------------------void XPDFViewer::keyPressCbk(void *data, char *s, KeySym key, Guint modifiers) { XPDFViewer *viewer = (XPDFViewer *)data; int z; if (s[0]) { switch (s[0]) { case 'O': case 'o': viewer->mapOpenDialog(gFalse); break; case 'R': case 'r': viewer->reloadFile(); break; case 'F': case 'f': case '\006': // ctrl-F if (viewer->core->getDoc()) { XtManageChild(viewer->findDialog); } break; case '\007': // ctrl-G if (viewer->core->getDoc()) { XPDFViewer::findFindCbk(None, viewer, NULL); } break; case '\020': // ctrl-P if (viewer->core->getDoc()) { XtManageChild(viewer->printDialog); } break; case 'N': case 'n': viewer->core->gotoNextPage(1, !(modifiers & Mod5Mask)); break; case 'P': case 'p': viewer->core->gotoPrevPage(1, !(modifiers & Mod5Mask), gFalse); break; case ' ': if (viewer->app->getFullScreen()) { viewer->core->gotoNextPage(1, gTrue); } else { viewer->core->scrollPageDown(); } break; case '\b': // bs case '\177': // del if (viewer->app->getFullScreen()) { viewer->core->gotoPrevPage(1, gTrue, gFalse); } else { viewer->core->scrollPageUp(); } break; case 'v': viewer->core->goForward(); break; case 'b': viewer->core->goBackward(); break; case 'g': if (!viewer->app->getFullScreen()) { XmTextFieldSetSelection( viewer->pageNumText, 0, strlen(XmTextFieldGetString(viewer->pageNumText)), XtLastTimestampProcessed(viewer->display)); XmProcessTraversal(viewer->pageNumText, XmTRAVERSE_CURRENT); } break; case 'h': // vi-style left if (!viewer->app->getFullScreen() && viewer->app->getViKeys()) { viewer->core->scrollLeft(); } break; case 'l': // vi-style right if (!viewer->app->getFullScreen() && viewer->app->getViKeys()) { viewer->core->scrollRight(); } break; case 'k': // vi-style up if (!viewer->app->getFullScreen() && viewer->app->getViKeys()) { viewer->core->scrollUp(); } break; case 'j': // vi-style down if (!viewer->app->getFullScreen() && viewer->app->getViKeys()) { viewer->core->scrollDown(); } break; case '0': if (!viewer->app->getFullScreen() && viewer->core->getZoom() != defZoom) { XtVaSetValues(viewer->zoomMenu, XmNmenuHistory, viewer->getZoomMenuBtn(defZoom), NULL); viewer->displayPage(viewer->core->getPageNum(), defZoom, viewer->core->getRotate(), gTrue, gFalse); } break; case '+': if (!viewer->app->getFullScreen() && viewer->core->getZoom() >= minZoom && viewer->core->getZoom() < maxZoom) { z = viewer->core->getZoom() + 1; XtVaSetValues(viewer->zoomMenu, XmNmenuHistory, viewer->getZoomMenuBtn(z), NULL); viewer->displayPage(viewer->core->getPageNum(), z, viewer->core->getRotate(), gTrue, gFalse); } break; case '-': if (!viewer->app->getFullScreen() && viewer->core->getZoom() > minZoom && viewer->core->getZoom() <= maxZoom) { z = viewer->core->getZoom() - 1; XtVaSetValues(viewer->zoomMenu, XmNmenuHistory, viewer->getZoomMenuBtn(z), NULL); viewer->displayPage(viewer->core->getPageNum(), z,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -