From 1a6fc92e4b2e36b6a64a348827ec9ea83069168d Mon Sep 17 00:00:00 2001 From: Nikita Khromov Date: Tue, 11 Feb 2025 15:55:06 +0700 Subject: [PATCH 1/3] [pdf] Improved appearance of Move Pages --- pdf/src/thumbnails.js | 66 +++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/pdf/src/thumbnails.js b/pdf/src/thumbnails.js index 953b57fd59..6f87351173 100644 --- a/pdf/src/thumbnails.js +++ b/pdf/src/thumbnails.js @@ -1139,60 +1139,79 @@ CDocument.prototype.prepareDragGhost = function(dp, countPages) { if (!this.dragCanvas) return; - // Уменьшаем «призрак» до 70% от исходного размера страницы + // Reduce the "ghost" to 70% of the original page size let w = dp.pageRect.w * 0.7; let h = dp.pageRect.h * 0.7; - this.dragCanvas.width = w; - this.dragCanvas.height = h; + this.dragCanvas.width = w + 15; + this.dragCanvas.height = h + 15; this.dragCanvas.style.display = "block"; - // Очищаем canvas + // Clear the canvas this.dragCtx.clearRect(0, 0, w, h); - // Рисуем миниатюру страницы + // If a stack of pages needs to be created + if (countPages && countPages > 1) { + let offsets = []; + if (countPages === 2) { + // For two pages — one additional copy + offsets.push({ x: 5, y: 5 }); + } else if (countPages >= 3) { + // For three or more — two additional copies + offsets.push({ x: 10, y: 10 }); + offsets.push({ x: 5, y: 5 }); + } + + // Draw additional copies (background pages) + for (let offset of offsets) { + this.dragCtx.fillStyle = PageStyle.emptyColor; + this.dragCtx.fillRect(offset.x, offset.y, w, h); + this.dragCtx.strokeRect(offset.x, offset.y, w, h); + } + } + + // Draw the main page on top (without offset) if (dp.page.image) { this.dragCtx.drawImage(dp.page.image, 0, 0, w, h); } else { this.dragCtx.fillStyle = PageStyle.emptyColor; this.dragCtx.fillRect(0, 0, w, h); } + this.dragCtx.strokeRect(0, 0, w, h); - // Устанавливаем прозрачность - this.dragCanvas.style.opacity = "0.9"; + // Set opacity + this.dragCanvas.style.opacity = 0.95; - // Дополнительно выводим количество страниц, которое мы перетаскиваем + // If more than one page is being dragged, display text with the number of pages if (countPages && countPages > 1) { let text = countPages + " pages"; - let fontSize = 16; // или распарсить из ctx.font + let fontSize = 16; // can be parsed from ctx.font this.dragCtx.font = fontSize + "px Arial"; - - // Получаем ширину текста + + // Calculate text dimensions let metrics = this.dragCtx.measureText(text); let textWidth = metrics.width; - let textHeight = fontSize; - let textX = (w - textWidth) / 2; - let textY = (h - textHeight) / 2; - - // Координаты центра canvas - let centerX = w / 2; + let textY = (h - textHeight); let padding = 4; - // 1. Рисуем полупрозрачный фон (или белый/любой другой) - this.dragCtx.fillStyle = "rgba(255, 255, 255, 1)"; // Белый с прозрачностью + let centerX = w / 2; + + // Draw background for text + this.dragCtx.fillStyle = "rgba(255, 255, 255, 1)"; this.dragCtx.fillRect( - centerX - textWidth / 2 - padding, + centerX - textWidth / 2 - padding, textY - textHeight, - textWidth + padding * 2, + textWidth + padding * 2, textHeight + padding * 2 ); - + + // Draw text this.dragCtx.fillStyle = "rgba(0, 0, 0, 1)"; this.dragCtx.fillText(text, textX, textY); } - // Перемещаем «призрак» в положение курсора + // Move the "ghost" to the cursor position this.moveDragGhost(AscCommon.global_mouseEvent.X, AscCommon.global_mouseEvent.Y); }; @@ -1230,7 +1249,6 @@ let oDoc = this.viewer.doc; - let _t = this; oDoc.DoAction(function() { oDoc.MovePages(selectedIndices, toIndex); oDoc.Viewer.navigateToPage(toIndex); From a2436fb5fbcb09faf73fbe84ac89e7812d337fe0 Mon Sep 17 00:00:00 2001 From: Nikita Khromov Date: Tue, 11 Feb 2025 16:03:25 +0700 Subject: [PATCH 2/3] [pdf][thumbnails] Fix calc pages height --- pdf/src/thumbnails.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pdf/src/thumbnails.js b/pdf/src/thumbnails.js index 6f87351173..20e2df2172 100644 --- a/pdf/src/thumbnails.js +++ b/pdf/src/thumbnails.js @@ -222,8 +222,14 @@ { let isLandscape = oViewer.isLandscapePage(this.pages[i].num); - if (this.pages[i].page.height > maxPageHeight) - maxPageHeight = false == isLandscape ? this.pages[i].page.height : this.pages[i].page.width; + if (isLandscape) { + if (this.pages[i].page.width > maxPageHeight) + maxPageHeight = this.pages[i].page.width; + } + else { + if (this.pages[i].page.height > maxPageHeight) + maxPageHeight = this.pages[i].page.height; + } } var blockHeight = (maxPageHeight * zoom) >> 0; From caecd26acfc4307b9fbd657f38f5c004f3ab42f1 Mon Sep 17 00:00:00 2001 From: Nikita Khromov Date: Tue, 11 Feb 2025 16:47:54 +0700 Subject: [PATCH 3/3] [pdf][thumbnails] Resize after move --- pdf/src/document.js | 3 +++ pdf/src/history/documentChanges.js | 3 +++ pdf/src/thumbnails.js | 21 ++++++++++++++++----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pdf/src/document.js b/pdf/src/document.js index f15adf8f52..02d6487d50 100644 --- a/pdf/src/document.js +++ b/pdf/src/document.js @@ -2391,8 +2391,11 @@ var CPresentation = CPresentation || function(){}; for (let i = nStart; i <= nEnd; i++) { oThumbnails._repaintPage(i); } + + oThumbnails.setNeedResize(true); } + this.Viewer.resize(true); this.Viewer.paint(); return true; }; diff --git a/pdf/src/history/documentChanges.js b/pdf/src/history/documentChanges.js index bdcc3afa4b..fc45244ce9 100644 --- a/pdf/src/history/documentChanges.js +++ b/pdf/src/history/documentChanges.js @@ -1125,7 +1125,10 @@ CChangesPDFDocumentMovePage.prototype.private_SetValue = function(nNewPos) for (let i = nStart; i <= nEnd; i++) { oThumbnails._repaintPage(i); } + + oThumbnails.setNeedResize(true); } + oDoc.Viewer.resize(true); oDoc.Viewer.paint(); }; \ No newline at end of file diff --git a/pdf/src/thumbnails.js b/pdf/src/thumbnails.js index 20e2df2172..97df1ba36b 100644 --- a/pdf/src/thumbnails.js +++ b/pdf/src/thumbnails.js @@ -618,7 +618,11 @@ // rendering CDocument.prototype._paint= function() { - if (!this.canvas) return; + if (!this.canvas || !this.viewer.canInteract()) return; + if (this.isNeedResize()) { + this.resize(); + } + let ctx= this.canvas.getContext("2d"); this.canvas.width= this.canvas.width; ctx.fillStyle= ThumbnailsStyle.backgroundColor; @@ -654,6 +658,12 @@ this.resize(); }; + CDocument.prototype.setNeedResize = function(bResize) { + this.needResize = bResize; + }; + CDocument.prototype.isNeedResize = function() { + return !!this.needResize; + }; CDocument.prototype._resize = function(isZoomUpdated) { var element = document.getElementById(this.id); @@ -769,6 +779,7 @@ this.documentHeight = blockTop; + this.setNeedResize(false); this.updateScroll(scrollV); this.calculateVisibleBlocks(); this.repaint(); @@ -1153,8 +1164,11 @@ this.dragCanvas.height = h + 15; this.dragCanvas.style.display = "block"; + // Set opacity + this.dragCanvas.style.opacity = 0.95; + // Clear the canvas - this.dragCtx.clearRect(0, 0, w, h); + this.dragCtx.clearRect(0, 0, this.dragCanvas.width, this.dragCanvas.height); // If a stack of pages needs to be created if (countPages && countPages > 1) { @@ -1185,9 +1199,6 @@ } this.dragCtx.strokeRect(0, 0, w, h); - // Set opacity - this.dragCanvas.style.opacity = 0.95; - // If more than one page is being dragged, display text with the number of pages if (countPages && countPages > 1) { let text = countPages + " pages";