diff --git a/common/Scrolls/mobileTouchManagerBase.js b/common/Scrolls/mobileTouchManagerBase.js index 4d514317ea..3b59b221d2 100644 --- a/common/Scrolls/mobileTouchManagerBase.js +++ b/common/Scrolls/mobileTouchManagerBase.js @@ -2012,7 +2012,7 @@ { this.delegate.HtmlPage.NoneRepaintPages = true; - this.ZoomDistance = this.getPointerDistance(e); + this.ZoomDistance = this.getPointerDistance(e, true); this.ZoomValue = this.delegate.GetZoom(); break; @@ -2102,7 +2102,12 @@ this.delegate.HtmlPage.NoneRepaintPages = false; if (this.delegate.IsNativeViewer && this.delegate.IsNativeViewer()) + { this.delegate.DrawingDocument.m_oDocumentRenderer.paint(); + // очищаем координаты зума для мобильного веба + this.delegate.DrawingDocument.m_oDocumentRenderer.skipClearZoomCoord = false; + this.delegate.DrawingDocument.m_oDocumentRenderer.clearZoomCoord(); + } this.delegate.HtmlPage.m_bIsFullRepaint = true; this.delegate.HtmlPage.OnScroll(); @@ -2204,7 +2209,7 @@ return true; }; - CMobileTouchManagerBase.prototype.getPointerDistance = function(e) + CMobileTouchManagerBase.prototype.getPointerDistance = function(e, bFixZoomCoord) { var isPointers = this.checkPointerEvent(e); if (e.touches && (e.touches.length > 1) && !isPointers) @@ -2215,6 +2220,12 @@ var _x2 = (e.touches[1].pageX !== undefined) ? e.touches[1].pageX : e.touches[1].clientX; var _y2 = (e.touches[1].pageY !== undefined) ? e.touches[1].pageY : e.touches[1].clientY; + // запоминаем координаты между тачами только на старте + if (bFixZoomCoord && this.delegate.IsNativeViewer && this.delegate.IsNativeViewer()) { + this.delegate.DrawingDocument.m_oDocumentRenderer.fixZoomCoord( ( ( _x1 + _x2 ) / 2 ), ( ( _y1 + _y2 ) / 2 ) ); + this.delegate.DrawingDocument.m_oDocumentRenderer.skipClearZoomCoord = true; + } + return Math.sqrt((_x1 - _x2) * (_x1 - _x2) + (_y1 - _y2) * (_y1 - _y2)); } else if (isPointers) @@ -2233,6 +2244,11 @@ if (_counter > 1) break; } + // запоминаем координаты между тачами только на старте + if (bFixZoomCoord && this.delegate.IsNativeViewer && this.delegate.IsNativeViewer()) { + this.delegate.DrawingDocument.m_oDocumentRenderer.fixZoomCoord( ( ( _touch1.X + _touch2.X ) / 2 ), ( ( _touch1.Y + _touch2.Y ) / 2 ) ); + this.delegate.DrawingDocument.m_oDocumentRenderer.skipClearZoomCoord = true; + } return Math.sqrt((_touch1.X - _touch2.X) * (_touch1.X - _touch2.X) + (_touch1.Y - _touch2.Y) * (_touch1.Y - _touch2.Y)); } diff --git a/pdf/src/viewer.js b/pdf/src/viewer.js index 551aa85008..6d51043586 100644 --- a/pdf/src/viewer.js +++ b/pdf/src/viewer.js @@ -148,6 +148,8 @@ this.zoomMode = ZoomMode.Custom; this.zoom = 1; + this.zoomCoordinate = null; + this.skipClearZoomCoord = false; this.drawingPages = []; this.isRepaint = false; @@ -441,12 +443,18 @@ { this.scrollX = pos; this.scrollMaxX = maxPos; + if (this.Api.WordControl.MobileTouchManager && this.Api.WordControl.MobileTouchManager.iScroll) + this.Api.WordControl.MobileTouchManager.iScroll.x = - Math.max(0, Math.min(pos, maxPos)); + this.paint(); }; this.scrollVertical = function(pos, maxPos) { this.scrollY = pos; this.scrollMaxY = maxPos; + if (this.Api.WordControl.MobileTouchManager && this.Api.WordControl.MobileTouchManager.iScroll) + this.Api.WordControl.MobileTouchManager.iScroll.y = - Math.max(0, Math.min(pos, maxPos)); + this.paint(); }; @@ -458,6 +466,7 @@ this.x = rect.x; this.y = rect.y; + var oldsize = {w: this.width, h: this.height}; this.width = this.parent.offsetWidth - this.scrollWidth; this.height = this.parent.offsetHeight; @@ -466,7 +475,10 @@ else if (this.zoomMode === ZoomMode.Page) this.zoom = this.calculateZoomToHeight(); - var lastPosition = this.getFirstPagePosition(); + // в мобильной версии мы будем получать координаты от MobileTouchManager (до этого момента они уже должны быть) и не нужно их запоминать, так как мы перетрём нужные нам значения + // ну а если их нет и зум произошёл не от тача, то запоминаем их как при обычном зуме + if (!this.zoomCoordinate) + this.fixZoomCoord( (this.width >> 1), (this.height >> 1) ); this.sendEvent("onZoom", this.zoom, this.zoomMode); @@ -551,13 +563,21 @@ if (this.scrollY >= this.scrollMaxY) this.scrollY = this.scrollMaxY; - if (lastPosition) + if (this.zoomCoordinate) { - var drawingPage = this.drawingPages[lastPosition.page]; - var newScrollY = drawingPage.Y + lastPosition.scrollY - lastPosition.y; + var newPoint = this.ConvertCoordsToCursor(this.zoomCoordinate.x, this.zoomCoordinate.y, this.zoomCoordinate.index); + // oldsize используется чтобы при смене ориентации экрана был небольшой скролл + var shiftX = this.Api.isMobileVersion ? ( (oldsize.w - this.width) >> 1) : 0; + var shiftY = this.Api.isMobileVersion ? ( (oldsize.h - this.height) >> 1) : 0; + var newScrollX = this.scrollX + newPoint.x - this.zoomCoordinate.xShift + shiftX; + var newScrollY = this.scrollY + newPoint.y - this.zoomCoordinate.yShift + shiftY; + newScrollX = Math.max(0, Math.min(newScrollX, this.scrollMaxX) ); + newScrollY = Math.max(0, Math.min(newScrollY, this.scrollMaxY) ); + if (this.scrollY == 0 && !this.Api.isMobileVersion) + newScrollY = 0; - if (newScrollY < this.scrollMaxY) - this.m_oScrollVerApi.scrollToY(newScrollY); + this.m_oScrollVerApi.scrollToY(newScrollY); + this.m_oScrollHorApi.scrollToX(newScrollX); } if (this.thumbnails) @@ -567,6 +587,9 @@ if (this.Api.WordControl.MobileTouchManager) this.Api.WordControl.MobileTouchManager.Resize(); + + if (!this.Api.isMobileVersion || !this.skipClearZoomCoord) + this.clearZoomCoord(); }; this.onLoadModule = function() @@ -833,6 +856,26 @@ return Math.min(zoom1, zoom2); }; + this.fixZoomCoord = function(x, y) + { + if (this.Api.isMobileVersion) + { + x -= this.x; + y -= this.y; + } + this.zoomCoordinate = this.getPageByCoords2(x, y); + if (this.zoomCoordinate) + { + this.zoomCoordinate['xShift'] = x; + this.zoomCoordinate['yShift'] = y; + } + }; + + this.clearZoomCoord = function() + { + // нужно очищать, чтобы при любом ресайзе мы не скролились к последней сохранённой точке + this.zoomCoordinate = null; + }; this.getFirstPagePosition = function() { @@ -1939,6 +1982,32 @@ }; }; + this.ConvertCoordsToCursor = function(x, y, pageIndex) + { + var dKoef = (this.zoom * g_dKoef_mm_to_pix); + var rPR = 1;//AscCommon.AscBrowser.retinaPixelRatio; + let yPos = this.scrollY >> 0; + let xCenter = this.width >> 1; + if (this.documentWidth > this.width) + { + xCenter = (this.documentWidth >> 1) - (this.scrollX) >> 0; + } + + let page = this.drawingPages[pageIndex]; + + let _w = (page.W * rPR) >> 0; + let _h = (page.H * rPR) >> 0; + let _x = ( (xCenter * rPR) >> 0) - (_w >> 1); + let _y = ( (page.Y - yPos) * rPR) >> 0; + + var x_pix = (_x + x * dKoef) >> 0; + var y_pix = (_y + y * dKoef) >> 0; + var w_pix = (_w * dKoef) >> 0; + var h_pix = (_h * dKoef) >> 0 + + return ( {x : x_pix, y : y_pix, w : w_pix, h: h_pix} ); + }; + this.Copy = function(_text_format) { return this.file.copy(_text_format);