[Libreoffice-commits] online.git: loleaflet/src

Henry Castro hcastro at collabora.com
Mon Mar 20 03:16:20 UTC 2017


 loleaflet/src/core/LOUtil.js             |   16 ++++++++++++++++
 loleaflet/src/layer/AnnotationManager.js |   21 +++++++++++----------
 2 files changed, 27 insertions(+), 10 deletions(-)

New commits:
commit 7bf26378721ef6c63edd589f463db210e0efe59f
Author: Henry Castro <hcastro at collabora.com>
Date:   Sun Mar 19 23:16:34 2017 -0400

    loleaflet: use textRange property to select the text
    
    Change-Id: Ie396b199b33ab322a015ce77272430fcf83ef17b

diff --git a/loleaflet/src/core/LOUtil.js b/loleaflet/src/core/LOUtil.js
index 237edbe3..286f2fa4 100644
--- a/loleaflet/src/core/LOUtil.js
+++ b/loleaflet/src/core/LOUtil.js
@@ -62,5 +62,21 @@ L.LOUtil = {
 		var topLeft = L.point(parseInt(numbers[0]), parseInt(numbers[1]));
 		var bottomRight = topLeft.add(L.point(parseInt(numbers[2]), parseInt(numbers[3])));
 		return L.bounds(topLeft, bottomRight);
+	},
+
+	stringToRectangles: function(strRect) {
+		var matches = strRect.match(/\d+/g);
+		var rectangles = [];
+		if (matches !== null) {
+			for (var itMatch = 0; itMatch < matches.length; itMatch += 4) {
+				var topLeft = L.point(parseInt(matches[itMatch]), parseInt(matches[itMatch + 1]));
+				var size = L.point(parseInt(matches[itMatch + 2]), parseInt(matches[itMatch + 3]));
+				var topRight = topLeft.add(L.point(size.x, 0));
+				var bottomLeft = topLeft.add(L.point(0, size.y));
+				var bottomRight = topLeft.add(size);
+				rectangles.push([bottomLeft, bottomRight, topLeft, topRight]);
+			}
+		}
+		return rectangles;
 	}
 };
diff --git a/loleaflet/src/layer/AnnotationManager.js b/loleaflet/src/layer/AnnotationManager.js
index bca8e15d..a21bf121 100644
--- a/loleaflet/src/layer/AnnotationManager.js
+++ b/loleaflet/src/layer/AnnotationManager.js
@@ -101,20 +101,21 @@ L.AnnotationManager = L.Class.extend({
 
 	update: function () {
 		var topRight = this._map.project(this._map.options.maxBounds.getNorthEast());
-		var point, bounds;
+		var point, rectangles;
 		this.layout();
 		if (this._selected.annotation) {
 			point = this._map._docLayer._twipsToPixels(this._selected.annotation._data.anchorPos.min);
-			bounds = L.latLngBounds(this._map._docLayer._twipsToLatLng(this._selected.annotation._data.anchorPos.getBottomLeft()),
-				this._map._docLayer._twipsToLatLng(this._selected.annotation._data.anchorPos.getTopRight()));
 			this._map._docLayer._selections.clearLayers();
-			this._map._docLayer._selections.addLayer(L.rectangle(bounds,{
-				pointerEvents: 'none',
-				fillColor: '#43ACE8',
-				fillOpacity: 0.25,
-				weight: 2,
-				opacity: 0.25
-			}));
+			rectangles = L.PolyUtil.rectanglesToPolygons(L.LOUtil.stringToRectangles(this._selected.annotation._data.textRange), this._map._docLayer);
+			if (rectangles.length > 0) {
+				this._map._docLayer._selections.addLayer(L.polygon(rectangles, {
+					pointerEvents: 'none',
+					fillColor: '#43ACE8',
+					fillOpacity: 0.25,
+					weight: 2,
+					opacity: 0.25
+				}));
+			}
 			this._selected.annotation.setLatLng(this._map.unproject(L.point(topRight.x, point.y)));
 		}
 	},


More information about the Libreoffice-commits mailing list