loleaflet/src/layer/tile/CalcTileLayer.js | 51 ++++++++++++++++++++++++++++++ loleaflet/src/layer/tile/TileLayer.js | 20 +++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-)
New commits: commit e1d3941ad9298436cbdf1d0794c15cd69170f9a9 Author: Dennis Francis <dennis.fran...@collabora.com> AuthorDate: Fri Jun 5 16:58:26 2020 +0530 Commit: Dennis Francis <dennis.fran...@collabora.com> CommitDate: Mon Jul 6 18:56:33 2020 +0200 Handle print-twips 'invalidatecursor' msg correctly Change-Id: I2b35be9228338d35b4aee9209f9b556a6adf5752 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98148 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Tested-by: Jenkins Reviewed-by: Dennis Francis <dennis.fran...@collabora.com> diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js index 0606a0831..ce5707c32 100644 --- a/loleaflet/src/layer/tile/CalcTileLayer.js +++ b/loleaflet/src/layer/tile/CalcTileLayer.js @@ -776,6 +776,26 @@ L.CalcTileLayer = L.TileLayer.extend({ _onCellCursorMsg: function (textMsg) { L.TileLayer.prototype._onCellCursorMsg.call(this, textMsg); this._onUpdateCurrentHeader(); + }, + + _getCursorRectangle: function (msgObj) { + + if (!this.options.printTwipsMsgsEnabled) { + return L.TileLayer.prototype._getCursorRectangle.call(this, msgObj); + } + + if (typeof msgObj !== 'object' || !msgObj.hasOwnProperty('relrect') || + !msgObj.hasOwnProperty('refpoint')) { + // This can happen because the kit sends such messages (sometimes) + // after doing its own parsing (probably needed for writer/impress?). + // These aren't needed for Calc. + return undefined; + } + + var relrect = this._parseRectangle(msgObj.relrect); + var refpoint = this._parsePoint(msgObj.refpoint); + refpoint = this.sheetGeometry.getTileTwipsPointFromPrint(refpoint); + return relrect.add(refpoint); } }); @@ -1006,6 +1026,18 @@ L.SheetGeometry = L.Class.extend({ return this._rows.getGroupsDataInView(); }, + // accepts a point in print twips coordinates and returns the equivalent point + // in tile-twips. + getTileTwipsPointFromPrint: function (point) { // (L.Point) -> L.Point + if (!(point instanceof L.Point)) { + console.error('Bad argument type, expected L.Point'); + return point; + } + + return new L.Point(this._columns.getTileTwipsPosFromPrint(point.x), + this._rows.getTileTwipsPosFromPrint(point.y)); + }, + // accepts a rectangle in print twips coordinates and returns the equivalent rectangle // in tile-twips aligned to the cells. getTileTwipsSheetAreaFromPrint: function (rectangle) { // (L.Bounds) -> L.Bounds @@ -1389,6 +1421,25 @@ L.SheetDimension = L.Class.extend({ return this._maxIndex; }, + // Accepts a position in print twips and returns the corresponding position in tile twips. + getTileTwipsPosFromPrint: function (posPT) { + + if (typeof posPT !== 'number') { + console.error('Wrong argument type'); + return; + } + + var element = this._getSpanAndIndexFromPrintTwipsPos(posPT); + var elementDataTT = this._getElementDataAnyFromSpanByIndex(element.index, element.span, 'tiletwips'); + var elementDataPT = this._getElementDataAnyFromSpanByIndex(element.index, element.span, 'printtwips'); + + var offset = posPT - elementDataPT.startpos; + console.assert(offset >= 0, 'offset should not be negative'); + + // Preserve any offset from the matching column/row start position. + return elementDataTT.startpos + offset; + }, + // Accepts a start and end positions in print twips, and returns the // corresponding positions in tile twips, by first computing the element range. getTileTwipsRangeFromPrint: function (posStartPT, posEndPT) { diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 64c3d9457..6a0d27ba2 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -1247,9 +1247,12 @@ L.TileLayer = L.GridLayer.extend({ _onInvalidateCursorMsg: function (textMsg) { textMsg = textMsg.substring('invalidatecursor:'.length + 1); var obj = JSON.parse(textMsg); + var rectangle = this._getCursorRectangle(obj); + if (rectangle === undefined) { + return; + } var modifierViewId = parseInt(obj.viewId); this._cursorAtMispelledWord = obj.mispelledWord ? Boolean(parseInt(obj.mispelledWord)).valueOf() : false; - var rectangle = this._getCursorRectangle(obj); this._visibleCursor = new L.LatLngBounds( this._twipsToLatLng(rectangle.getTopLeft(), this._map.getZoom()), this._twipsToLatLng(rectangle.getBottomRight(), this._map.getZoom())); @@ -3409,6 +3412,21 @@ L.TileLayer = L.GridLayer.extend({ return this._parseRectangle(msgObj.rectangle); }, + _parsePoint: function (pointString) { + if (typeof pointString !== 'string') { + console.error('invalid point string'); + return undefined; + } + + var pointParts = pointString.match(/\d+/g); + if (pointParts.length < 2) { + console.error('incomplete point'); + return undefined; + } + + return new L.Point(parseInt(pointParts[0]), parseInt(pointParts[1])); + }, + _parseRectangle: function (rectString) { if (typeof rectString !== 'string') { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits