[Libreoffice-commits] online.git: loleaflet/src
Dennis Francis (via logerrit)
logerrit at kemper.freedesktop.org
Mon Jul 6 17:05:13 UTC 2020
loleaflet/src/layer/tile/CalcTileLayer.js | 50 +++++++++++++++++++++++++++---
loleaflet/src/layer/tile/TileLayer.js | 33 ++++++++++++++++---
2 files changed, 73 insertions(+), 10 deletions(-)
New commits:
commit 46cfff2418e10671c264504eba137ebde8cd98a6
Author: Dennis Francis <dennis.francis at collabora.com>
AuthorDate: Sun Jun 21 17:19:30 2020 +0530
Commit: Dennis Francis <dennis.francis at collabora.com>
CommitDate: Mon Jul 6 19:04:53 2020 +0200
print-twips messaging for graphics
All graphic-selection messages from core are in print-twips if
sc_print_twips_msgs is set in SAL_LOK_OPTIONS. So do all the necessary
conversions on intercepting the message.
In addition, in this mode the core expects the parameters of the command
'.uno:TransformDialog' to be in print-twips. This is also done in this
patch.
Change-Id: Ief8a0d4677f83f26b135ce47b68c27bff5aaf5c9
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98157
Tested-by: Jenkins
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Dennis Francis <dennis.francis at collabora.com>
diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js
index 62d8b6072..f2bfcd4eb 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -1075,6 +1075,18 @@ L.SheetGeometry = L.Class.extend({
this._rows.getTileTwipsPosFromPrint(point.y));
},
+ // accepts a point in tile-twips coordinates and returns the equivalent point
+ // in print-twips.
+ getPrintTwipsPointFromTile: 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.getPrintTwipsPosFromTile(point.x),
+ this._rows.getPrintTwipsPosFromTile(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
@@ -1370,12 +1382,17 @@ L.SheetDimension = L.Class.extend({
});
},
- // computes element index from tile-twips position.
- _getIndexFromTileTwipsPos: function (pos) {
+ // computes element index from tile-twips position and returns
+ // an object with this index and the span data.
+ _getSpanAndIndexFromTileTwipsPos: function (pos) {
+ var result = {};
var span = this._visibleSizes.getSpanDataByCustomDataField(pos, 'postiletwips');
+ result.span = span;
if (span === undefined) {
// enforce limits.
- return (pos >= 0) ? this._maxIndex : 0;
+ result.index = (pos >= 0) ? this._maxIndex : 0;
+ result.span = this._visibleSizes.getSpanDataByIndex(result.index);
+ return result;
}
var elementCount = span.end - span.start + 1;
var posStart = ((span.data.posdevpx - span.data.sizedev * elementCount) /
@@ -1386,7 +1403,13 @@ L.SheetDimension = L.Class.extend({
// always round down as relativeIndex is zero-based.
var relativeIndex = Math.floor((pos - posStart) / sizeOne);
- return span.start + relativeIndex;
+ result.index = span.start + relativeIndex;
+ return result;
+ },
+
+ // computes element index from tile-twips position.
+ _getIndexFromTileTwipsPos: function (pos) {
+ return this._getSpanAndIndexFromTileTwipsPos(pos).index;
},
// computes element index from print twips position and returns
@@ -1477,6 +1500,25 @@ L.SheetDimension = L.Class.extend({
return elementDataTT.startpos + offset;
},
+ // Accepts a position in tile twips and returns the corresponding position in print twips.
+ getPrintTwipsPosFromTile: function (posTT) {
+
+ if (typeof posTT !== 'number') {
+ console.error('Wrong argument type');
+ return;
+ }
+
+ var element = this._getSpanAndIndexFromTileTwipsPos(posTT);
+ var elementDataTT = this._getElementDataAnyFromSpanByIndex(element.index, element.span, 'tiletwips');
+ var elementDataPT = this._getElementDataAnyFromSpanByIndex(element.index, element.span, 'printtwips');
+
+ var offset = posTT - elementDataTT.startpos;
+ console.assert(offset >= 0, 'offset should not be negative');
+
+ // Preserve any offset from the matching column/row start position.
+ return elementDataPT.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 92a3e6805..e48406405 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -1044,10 +1044,11 @@ L.TileLayer = L.GridLayer.extend({
var topLeftTwips = new L.Point(msgData[0], msgData[1]);
var offset = new L.Point(msgData[2], msgData[3]);
var bottomRightTwips = topLeftTwips.add(offset);
- this._graphicSelectionTwips = new L.Bounds(topLeftTwips, bottomRightTwips);
+ this._graphicSelectionTwips = this._getGraphicSelectionRectangle(
+ new L.Bounds(topLeftTwips, bottomRightTwips));
this._graphicSelection = new L.LatLngBounds(
- this._twipsToLatLng(topLeftTwips, this._map.getZoom()),
- this._twipsToLatLng(bottomRightTwips, this._map.getZoom()));
+ this._twipsToLatLng(this._graphicSelectionTwips.getTopLeft(), this._map.getZoom()),
+ this._twipsToLatLng(this._graphicSelectionTwips.getBottomRight(), this._map.getZoom()));
this._graphicSelectionAngle = (msgData.length > 4) ? msgData[4] : 0;
@@ -1110,9 +1111,11 @@ L.TileLayer = L.GridLayer.extend({
var topLeftTwips = new L.Point(parseInt(strTwips[0]), parseInt(strTwips[1]));
var offset = new L.Point(parseInt(strTwips[2]), parseInt(strTwips[3]));
var bottomRightTwips = topLeftTwips.add(offset);
+ var boundRectTwips = this._getGraphicSelectionRectangle(
+ new L.Bounds(topLeftTwips, bottomRightTwips));
this._graphicViewMarkers[viewId].bounds = new L.LatLngBounds(
- this._twipsToLatLng(topLeftTwips, this._map.getZoom()),
- this._twipsToLatLng(bottomRightTwips, this._map.getZoom()));
+ this._twipsToLatLng(boundRectTwips.getTopLeft(), this._map.getZoom()),
+ this._twipsToLatLng(boundRectTwips.getBottomRight(), this._map.getZoom()));
}
else {
this._graphicViewMarkers[viewId].bounds = L.LatLngBounds.createDefault();
@@ -2503,6 +2506,10 @@ L.TileLayer = L.GridLayer.extend({
if (newPos.y < 0)
newPos.y = 0;
+ if (this.isCalc() && this.options.printTwipsMsgsEnabled) {
+ newPos = this.sheetGeometry.getPrintTwipsPointFromTile(newPos);
+ }
+
param = {
TransformPosX: {
type: 'long',
@@ -2635,6 +2642,10 @@ L.TileLayer = L.GridLayer.extend({
}
}
+ if (this.isCalc() && this.options.printTwipsMsgsEnabled) {
+ newPos = this.sheetGeometry.getPrintTwipsPointFromTile(newPos);
+ }
+
// fill params for uno command
var param = {
TransformPosX: {
@@ -3386,7 +3397,7 @@ L.TileLayer = L.GridLayer.extend({
}
},
- // convert the area in print-twips to tile-twips by computing the involved cell-range.
+ // converts rectangle in print-twips to tile-twips rectangle of the smallest cell-range that encloses it.
_convertToTileTwipsSheetArea: function (rectangle) {
if (!(rectangle instanceof L.Bounds) || !this.options.printTwipsMsgsEnabled) {
return rectangle;
@@ -3395,6 +3406,16 @@ L.TileLayer = L.GridLayer.extend({
return this.sheetGeometry.getTileTwipsSheetAreaFromPrint(rectangle);
},
+ _getGraphicSelectionRectangle: function (rectangle) {
+ if (!(rectangle instanceof L.Bounds) || !this.options.printTwipsMsgsEnabled) {
+ return rectangle;
+ }
+
+ var rectSize = rectangle.getSize();
+ var newTopLeft = this.sheetGeometry.getTileTwipsPointFromPrint(rectangle.getTopLeft());
+ return new L.Bounds(newTopLeft, newTopLeft.add(rectSize));
+ },
+
_getEditCursorRectangle: function (msgObj) {
if (typeof msgObj !== 'object' || !msgObj.hasOwnProperty('rectangle')) {
More information about the Libreoffice-commits
mailing list