📄 pdfcore.cc
字号:
} if (scrollX < 0) { scrollX = 0; } h = continuousMode ? totalDocH : page->h; if (scrollY > h - drawAreaHeight) { scrollY = h - drawAreaHeight; } if (scrollY < 0) { scrollY = 0; } // find topPage, and the first and last pages to be rasterized if (continuousMode) { //~ should use a binary search for (i = 2; i <= doc->getNumPages(); ++i) { if (pageY[i-1] > scrollY - drawAreaHeight / 2) { break; } } pg0 = i - 1; for (i = pg0 + 1; i <= doc->getNumPages(); ++i) { if (pageY[i-1] > scrollY) { break; } } topPage = i - 1; for (i = topPage + 1; i <= doc->getNumPages(); ++i) { if (pageY[i-1] > scrollY + drawAreaHeight + drawAreaHeight / 2) { break; } } pg1 = i - 1; // delete pages that are no longer needed and insert new pages // objects that are needed while (pages->getLength() > 0 && ((PDFCorePage *)pages->get(0))->page < pg0) { delete (PDFCorePage *)pages->del(0); } i = pages->getLength() - 1; while (i > 0 && ((PDFCorePage *)pages->get(i))->page > pg1) { delete (PDFCorePage *)pages->del(i--); } j = pages->getLength() > 0 ? ((PDFCorePage *)pages->get(0))->page - 1 : pg1; for (i = pg0; i <= j; ++i) { rot = rotate + doc->getPageRotate(i); if (rot >= 360) { rot -= 360; } else if (rot < 0) { rot += 360; } addPage(i, rot); } j = ((PDFCorePage *)pages->get(pages->getLength() - 1))->page; for (i = j + 1; i <= pg1; ++i) { rot = rotate + doc->getPageRotate(i); if (rot >= 360) { rot -= 360; } else if (rot < 0) { rot += 360; } addPage(i, rot); } } else { pg0 = pg1 = topPage; } // delete tiles that are no longer needed for (i = 0; i < pages->getLength(); ++i) { page = (PDFCorePage *)pages->get(i); j = 0; while (j < page->tiles->getLength()) { tile = (PDFCoreTile *)page->tiles->get(j); if (continuousMode) { y0 = pageY[page->page - 1] + tile->yMin; y1 = pageY[page->page - 1] + tile->yMax; } else { y0 = tile->yMin; y1 = tile->yMax; } if (tile->xMax < scrollX - drawAreaWidth / 2 || tile->xMin > scrollX + drawAreaWidth + drawAreaWidth / 2 || y1 < scrollY - drawAreaHeight / 2 || y0 > scrollY + drawAreaHeight + drawAreaHeight / 2) { delete (PDFCoreTile *)page->tiles->del(j); } else { ++j; } } } // update page positions for (i = 0; i < pages->getLength(); ++i) { page = (PDFCorePage *)pages->get(i); page->xDest = -scrollX; if (continuousMode) { page->yDest = pageY[page->page - 1] - scrollY; } else { page->yDest = -scrollY; } if (continuousMode) { if (page->w < maxPageW) { page->xDest += (maxPageW - page->w) / 2; } if (maxPageW < drawAreaWidth) { page->xDest += (drawAreaWidth - maxPageW) / 2; } } else if (page->w < drawAreaWidth) { page->xDest += (drawAreaWidth - page->w) / 2; } if (continuousMode && totalDocH < drawAreaHeight) { page->yDest += (drawAreaHeight - totalDocH) / 2; } else if (!continuousMode && page->h < drawAreaHeight) { page->yDest += (drawAreaHeight - page->h) / 2; } } // rasterize any new tiles for (i = 0; i < pages->getLength(); ++i) { page = (PDFCorePage *)pages->get(i); x0 = page->xDest; x1 = x0 + page->w - 1; if (x0 < -drawAreaWidth / 2) { x0 = -drawAreaWidth / 2; } if (x1 > drawAreaWidth + drawAreaWidth / 2) { x1 = drawAreaWidth + drawAreaWidth / 2; } x0 = ((x0 - page->xDest) / page->tileW) * page->tileW; x1 = ((x1 - page->xDest) / page->tileW) * page->tileW; y0 = page->yDest; y1 = y0 + page->h - 1; if (y0 < -drawAreaHeight / 2) { y0 = -drawAreaHeight / 2; } if (y1 > drawAreaHeight + drawAreaHeight / 2) { y1 = drawAreaHeight + drawAreaHeight / 2; } y0 = ((y0 - page->yDest) / page->tileH) * page->tileH; y1 = ((y1 - page->yDest) / page->tileH) * page->tileH; for (y = y0; y <= y1; y += page->tileH) { for (x = x0; x <= x1; x += page->tileW) { needTile(page, x, y); } } } // update tile positions for (i = 0; i < pages->getLength(); ++i) { page = (PDFCorePage *)pages->get(i); for (j = 0; j < page->tiles->getLength(); ++j) { tile = (PDFCoreTile *)page->tiles->get(j); tile->xDest = tile->xMin - scrollX; if (continuousMode) { tile->yDest = tile->yMin + pageY[page->page - 1] - scrollY; } else { tile->yDest = tile->yMin - scrollY; } if (continuousMode) { if (page->w < maxPageW) { tile->xDest += (maxPageW - page->w) / 2; } if (maxPageW < drawAreaWidth) { tile->xDest += (drawAreaWidth - maxPageW) / 2; } } else if (page->w < drawAreaWidth) { tile->xDest += (drawAreaWidth - page->w) / 2; } if (continuousMode && totalDocH < drawAreaHeight) { tile->yDest += (drawAreaHeight - totalDocH) / 2; } else if (!continuousMode && page->h < drawAreaHeight) { tile->yDest += (drawAreaHeight - page->h) / 2; } } } // redraw the selection if (selectULX != selectLRX && selectULY != selectLRY) { xorColor[0] = xorColor[1] = xorColor[2] = 0xff; xorRectangle(selectPage, selectULX, selectULY, selectLRX, selectLRY, new SplashSolidColor(xorColor)); } // redraw the window redrawWindow(0, 0, drawAreaWidth, drawAreaHeight, needUpdate); updateScrollbars(); // add to history if (addToHist) { if (++historyCur == pdfHistorySize) { historyCur = 0; } hist = &history[historyCur]; if (hist->fileName) { delete hist->fileName; } if (doc->getFileName()) { hist->fileName = doc->getFileName()->copy(); } else { hist->fileName = NULL; } hist->page = topPage; if (historyBLen < pdfHistorySize) { ++historyBLen; } historyFLen = 0; }}void PDFCore::addPage(int pg, int rot) { PDFCorePage *page; int w, h, t, tileW, tileH, i; w = (int)((doc->getPageCropWidth(pg) * dpi) / 72 + 0.5); h = (int)((doc->getPageCropHeight(pg) * dpi) / 72 + 0.5); if (rot == 90 || rot == 270) { t = w; w = h; h = t; } tileW = 2 * drawAreaWidth; if (tileW < 1500) { tileW = 1500; } if (tileW > w) { tileW = w; } tileH = 2 * drawAreaHeight; if (tileH < 1500) { tileH = 1500; } if (tileH > h) { tileH = h; } page = new PDFCorePage(pg, w, h, tileW, tileH); for (i = 0; i < pages->getLength() && pg > ((PDFCorePage *)pages->get(i))->page; ++i) ; pages->insert(i, page);}void PDFCore::needTile(PDFCorePage *page, int x, int y) { PDFCoreTile *tile; TextOutputDev *textOut; int xDest, yDest, sliceW, sliceH; int i; for (i = 0; i < page->tiles->getLength(); ++i) { tile = (PDFCoreTile *)page->tiles->get(i); if (x == tile->xMin && y == tile->yMin) { return; } } setBusyCursor(gTrue); sliceW = page->tileW; if (x + sliceW > page->w) { sliceW = page->w - x; } sliceH = page->tileH; if (y + sliceH > page->h) { sliceH = page->h - y; } xDest = x - scrollX; if (continuousMode) { yDest = y + pageY[page->page - 1] - scrollY; } else { yDest = y - scrollY; } if (continuousMode) { if (page->w < maxPageW) { xDest += (maxPageW - page->w) / 2; } if (maxPageW < drawAreaWidth) { xDest += (drawAreaWidth - maxPageW) / 2; } } else if (page->w < drawAreaWidth) { xDest += (drawAreaWidth - page->w) / 2; } if (continuousMode && totalDocH < drawAreaHeight) { yDest += (drawAreaHeight - totalDocH) / 2; } else if (!continuousMode && page->h < drawAreaHeight) { yDest += (drawAreaHeight - page->h) / 2; } curTile = tile = newTile(xDest, yDest); curPage = page; tile->xMin = x; tile->yMin = y; tile->xMax = x + sliceW; tile->yMax = y + sliceH; tile->edges = 0; if (tile->xMin == 0) { tile->edges |= pdfCoreTileLeftEdge; } if (tile->xMax == page->w) { tile->edges |= pdfCoreTileRightEdge; } if (continuousMode) { if (tile->yMin == 0) { tile->edges |= pdfCoreTileTopSpace; if (page->page == 1) { tile->edges |= pdfCoreTileTopEdge; } } if (tile->yMax == page->h) { tile->edges |= pdfCoreTileBottomSpace; if (page->page == doc->getNumPages()) { tile->edges |= pdfCoreTileBottomEdge; } } } else { if (tile->yMin == 0) { tile->edges |= pdfCoreTileTopEdge; } if (tile->yMax == page->h) { tile->edges |= pdfCoreTileBottomEdge; } } doc->displayPageSlice(out, page->page, dpi, dpi, rotate, gFalse, gTrue, gFalse, x, y, sliceW, sliceH); tile->bitmap = out->takeBitmap(); memcpy(tile->ctm, out->getDefCTM(), 6 * sizeof(double)); memcpy(tile->ictm, out->getDefICTM(), 6 * sizeof(double)); if (!page->links) { page->links = doc->getLinks(page->page); } if (!page->text) { if ((textOut = new TextOutputDev(NULL, gTrue, gFalse, gFalse))) { doc->displayPage(textOut, page->page, dpi, dpi, rotate, gFalse, gTrue, gFalse); page->text = textOut->takeText(); delete textOut; } } page->tiles->append(tile); curTile = NULL; curPage = NULL; setBusyCursor(gFalse);}GBool PDFCore::gotoNextPage(int inc, GBool top) { int pg, scrollYA; if (!doc || doc->getNumPages() == 0 || topPage >= doc->getNumPages()) { return gFalse; } if ((pg = topPage + inc) > doc->getNumPages()) { pg = doc->getNumPages(); } if (continuousMode) { scrollYA = -1; } else if (top) { scrollYA = 0; } else { scrollYA = scrollY; } update(pg, scrollX, scrollYA, zoom, rotate, gFalse, gTrue); return gTrue;}GBool PDFCore::gotoPrevPage(int dec, GBool top, GBool bottom) { int pg, scrollYA; if (!doc || doc->getNumPages() == 0 || topPage <= 1) { return gFalse; } if ((pg = topPage - dec) < 1) { pg = 1; } if (continuousMode) { scrollYA = -1; } else if (top) { scrollYA = 0; } else if (bottom) { scrollYA = ((PDFCorePage *)pages->get(0))->h - drawAreaHeight; if (scrollYA < 0) { scrollYA = 0; } } else { scrollYA = scrollY; } update(pg, scrollX, scrollYA, zoom, rotate, gFalse, gTrue); return gTrue;}GBool PDFCore::gotoNamedDestination(GString *dest) { LinkDest *d; if (!doc) { return gFalse; } if (!(d = doc->findDest(dest))) { return gFalse; } displayDest(d, zoom, rotate, gTrue); delete d; return gTrue;}GBool PDFCore::goForward() { int pg; if (historyFLen == 0) { return gFalse; } if (++historyCur == pdfHistorySize) { historyCur = 0; } --historyFLen; ++historyBLen; if (!doc || history[historyCur].fileName->cmp(doc->getFileName()) != 0) { if (loadFile(history[historyCur].fileName) != errNone) { return gFalse; } } pg = history[historyCur].page; update(pg, scrollX, continuousMode ? -1 : scrollY, zoom, rotate, gFalse, gFalse); return gTrue;}GBool PDFCore::goBackward() { int pg; if (historyBLen <= 1) { return gFalse; } if (--historyCur < 0) { historyCur = pdfHistorySize - 1; } --historyBLen; ++historyFLen; if (!doc || history[historyCur].fileName->cmp(doc->getFileName()) != 0) { if (loadFile(history[historyCur].fileName) != errNone) { return gFalse; } } pg = history[historyCur].page; update(pg, scrollX, continuousMode ? -1 : scrollY, zoom, rotate, gFalse, gFalse); return gTrue;}void PDFCore::scrollLeft(int nCols) { scrollTo(scrollX - nCols, scrollY);}void PDFCore::scrollRight(int nCols) { scrollTo(scrollX + nCols, scrollY);}void PDFCore::scrollUp(int nLines) { scrollTo(scrollX, scrollY - nLines);}void PDFCore::scrollUpPrevPage(int nLines) { if (!continuousMode && scrollY == 0) { gotoPrevPage(1, gFalse, gTrue); } else { scrollTo(scrollX, scrollY - nLines); }}void PDFCore::scrollDown(int nLines) { scrollTo(scrollX, scrollY + nLines);}void PDFCore::scrollDownNextPage(int nLines) { if (!continuousMode && scrollY >= ((PDFCorePage *)pages->get(0))->h - drawAreaHeight) { gotoNextPage(1, gTrue); } else { scrollTo(scrollX, scrollY + nLines); }}void PDFCore::scrollPageUp() { if (!continuousMode && scrollY == 0) { gotoPrevPage(1, gFalse, gTrue); } else { scrollTo(scrollX, scrollY - drawAreaHeight); }}void PDFCore::scrollPageDown() { if (!continuousMode && scrollY >= ((PDFCorePage *)pages->get(0))->h - drawAreaHeight) { gotoNextPage(1, gTrue); } else { scrollTo(scrollX, scrollY + drawAreaHeight); }}void PDFCore::scrollTo(int x, int y) { update(topPage, x, y < 0 ? 0 : y, zoom, rotate, gFalse, gFalse);}void PDFCore::scrollToLeftEdge() { update(topPage, 0, scrollY, zoom, rotate, gFalse, gFalse);}void PDFCore::scrollToRightEdge() { PDFCorePage *page; page = (PDFCorePage *)pages->get(0); update(topPage, page->w - drawAreaWidth, scrollY, zoom, rotate, gFalse, gFalse);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -