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

Mihai Varga mihai.varga at collabora.com
Fri Dec 18 04:41:28 PST 2015


 loleaflet/reference.html              |   43 +++++++++++++++++++++++++++++++++-
 loleaflet/src/control/Scroll.js       |    6 ++++
 loleaflet/src/core/Socket.js          |   34 ++++++++++++++++++--------
 loleaflet/src/layer/tile/GridLayer.js |    6 +---
 loleaflet/src/layer/tile/TileLayer.js |   21 ++++++++++------
 loleaflet/src/map/Map.js              |    5 ++-
 6 files changed, 90 insertions(+), 25 deletions(-)

New commits:
commit 6ae4bdf2a14998a3e9e6bdd116bea23a46d07373
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Fri Dec 18 14:40:46 2015 +0200

    loleaflet: allow specifying the starting zoom level

diff --git a/loleaflet/reference.html b/loleaflet/reference.html
index b15b7dd..3e28ec0 100644
--- a/loleaflet/reference.html
+++ b/loleaflet/reference.html
@@ -1491,6 +1491,33 @@ unexpected behaviour.</h4>
 		<td>Whether the document is automatically zoomed so that the width fits the viewing area when
             the window is resized. The document will not be zoomed in more than map.options.zoom.</td>
 	</tr>
+	<tr>
+		<td><code><b>zoom</b></code></td>
+		<td><code>Number</code></td>
+		<td><code><span class="literal">10</span></code></td>
+		<td>Default zoom level in which the document will be loaded.</td>
+	</tr>
+	<tr>
+		<td><code><b>tileWidthTwips</b></code></td>
+		<td><code>Number</code></td>
+		<td><code><span class="literal">3000</span></code></td>
+		<td>Default tile width in twips (how much of the document is covered horizontally in a 256x256 pixels tile).
+            Unless you know what you are doing, this should not be modified.</td>
+	</tr>
+	<tr>
+		<td><code><b>tileHeightTwips</b></code></td>
+		<td><code>Number</code></td>
+		<td><code><span class="literal">3000</span></code></td>
+		<td>Default tile height in twips (how much of the document is covered vertically in a 256x256 pixels tile).
+            Unless you know what you are doing, this should not be modified.</td>
+	</tr>
+	<tr>
+		<td><code><b>defaultZoom</b></code></td>
+		<td><code>Number</code></td>
+		<td><code><span class="literal">10</span></code></td>
+		<td>The zoom level at which the tile size in twips equals the default size (3000 x 3000).
+            Unless you know what you are doing, this should not be modified.</td>
+	</tr>
 </table>
 
 <h2 id="loleaflet-general">General</h2>
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 1c7397f2..e8d34ef 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -107,32 +107,45 @@ L.Socket = {
 
 		if (textMsg.startsWith('status:') && !this._map._docLayer) {
 			// first status message, we need to create the document layer
+			var tileWidthTwips = this._map.options.tileWidthTwips;
+			var tileHeightTwips = this._map.options.tileHeightTwips;
+			if (this._map.options.zoom !== this._map.options.defaultZoom) {
+				var scale = this._map.options.crs.scale(this._map.options.defaultZoom - this._map.options.zoom);
+				tileWidthTwips = Math.round(tileWidthTwips * scale);
+				tileHeightTwips = Math.round(tileHeightTwips * scale);
+			}
+
 			var command = this.parseServerCmd(textMsg);
 			var docLayer = null;
 			if (command.type === 'text') {
 				docLayer = new L.WriterTileLayer('', {
 					permission: this._map.options.permission,
+					tileWidthTwips: tileWidthTwips,
+					tileHeightTwips: tileHeightTwips,
 					docType: command.type
 				});
 			}
 			else if (command.type === 'spreadsheet') {
 				docLayer = new L.CalcTileLayer('', {
 					permission: this._map.options.permission,
+					tileWidthTwips: tileWidthTwips,
+					tileHeightTwips: tileHeightTwips,
 					docType: command.type
 				});
 			}
 			else {
-				if (command.type === 'presentation') {
+				if (command.type === 'presentation' &&
+						this._map.options.defaultZoom === this._map.options.zoom) {
+					// If we have a presentation document and the zoom level has not been set
+					// in the options, resize the document so that it fits the viewing area
 					var verticalTiles = this._map.getSize().y / 256;
-					var tileTwipsSize = Math.round(command.height / verticalTiles);
-				}
-				else {
-					tileTwipsSize = 3000;
+					tileWidthTwips = Math.round(command.height / verticalTiles);
+					tileHeightTwips = Math.round(command.height / verticalTiles);
 				}
 				docLayer = new L.ImpressTileLayer('', {
 					permission: this._map.options.permission,
-					tileWidthTwips: tileTwipsSize,
-					tileHeightTwips: tileTwipsSize,
+					tileWidthTwips: tileWidthTwips,
+					tileHeightTwips: tileHeightTwips,
 					docType: command.type
 				});
 			}
@@ -224,10 +237,11 @@ L.Socket = {
 			}
 		}
 		if (command.tileWidth && command.tileHeight && this._map._docLayer) {
+			var defaultZoom = this._map.options.zoom;
 			var scale = command.tileWidth / this._map._docLayer.options.tileWidthTwips;
-			// scale = 1.2 ^ (10 - zoom)
-			// zoom = 10 -log(scale) / log(1.2)
-			command.zoom = Math.round(10 - Math.log(scale) / Math.log(1.2));
+			// scale = 1.2 ^ (defaultZoom - zoom)
+			// zoom = defaultZoom -log(scale) / log(1.2)
+			command.zoom = Math.round(defaultZoom - Math.log(scale) / Math.log(1.2));
 		}
 		return command;
 	}
diff --git a/loleaflet/src/layer/tile/GridLayer.js b/loleaflet/src/layer/tile/GridLayer.js
index e023189..ed9211c 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -17,10 +17,8 @@ L.GridLayer = L.Layer.extend({
 		zIndex: null,
 		bounds: null,
 
-		minZoom: 0,
+		minZoom: 0
 		// maxZoom: <Number>
-		tileWidthTwips: 3000,
-		tileHeightTwips: 3000
 	},
 
 	initialize: function (options) {
@@ -359,7 +357,7 @@ L.GridLayer = L.Layer.extend({
 
 	_updateTileTwips: function () {
 		// smaller zoom = zoom in
-		var factor = Math.pow(1.2, (10 - this._tileZoom));
+		var factor = Math.pow(1.2, (this._map.options.zoom - this._tileZoom));
 		this._tileWidthTwips = Math.round(this.options.tileWidthTwips * factor);
 		this._tileHeightTwips = Math.round(this.options.tileHeightTwips * factor);
 	},
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 1f8042e..9f650c0 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -13,8 +13,9 @@ L.Map = L.Evented.extend({
 		fadeAnimation: true,
 		trackResize: true,
 		markerZoomAnimation: true,
-		edit: false,
-		readonly: false
+		defaultZoom: 10,
+		tileWidthTwips: 3000,
+		tileHeightTwips: 3000
 	},
 
 	initialize: function (id, options) { // (HTMLElement or String, Object)
commit d7b37ea25a4af12ae037ac9a7b0d31c3dbc2cd84
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Fri Dec 18 12:50:07 2015 +0200

    loleaflet: map.fitWidthZoom(maxZoom) method
    
    I've also added an initialization parameter that controls whether the
    document should automatically call fitWidthZoom on resize.

diff --git a/loleaflet/reference.html b/loleaflet/reference.html
index 5409c99..b15b7dd 100644
--- a/loleaflet/reference.html
+++ b/loleaflet/reference.html
@@ -1484,6 +1484,13 @@ unexpected behaviour.</h4>
 		<td><code><span class="literal">true</span></code></td>
 		<td>Whether the print handler is active (for Chrome).</td>
 	</tr>
+	<tr>
+		<td><code><b>autoFitWidth</b></code></td>
+		<td><code>Boolean</code></td>
+		<td><code><span class="literal">true</span></code></td>
+		<td>Whether the document is automatically zoomed so that the width fits the viewing area when
+            the window is resized. The document will not be zoomed in more than map.options.zoom.</td>
+	</tr>
 </table>
 
 <h2 id="loleaflet-general">General</h2>
@@ -1619,7 +1626,14 @@ unexpected behaviour.</h4>
 		<td><code>undfined</code></td>
 		<td>Cancels the automatic update for the preview defined by 'id'.</td>
 	</tr>
-
+	<tr>
+		<td><code><b>fitWidthZoom</b>(
+			<nobr><Number><i>maxZoom</i>)</nobr>
+        </code></td>
+		<td><code>undfined</code></td>
+		<td>Zooms in or out so that the document's width fits the viewing area. The document will not zoom in more
+            than `maxZoom` if the parameter is provided.</td>
+	</tr>
 </table>
 
 <h3 id="scroll-options">ScrollOptions</h3>
diff --git a/loleaflet/src/control/Scroll.js b/loleaflet/src/control/Scroll.js
index b3109b9..cc980ae 100644
--- a/loleaflet/src/control/Scroll.js
+++ b/loleaflet/src/control/Scroll.js
@@ -46,5 +46,11 @@ L.Map.include({
 		else {
 			this.off('moveend', this._docLayer._updateScrollOffset, this._docLayer);
 		}
+	},
+
+	fitWidthZoom: function (maxZoom) {
+		if (this._docLayer) {
+			this._docLayer._fitWidthZoom(null, maxZoom);
+		}
 	}
 });
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 1a3ef06..f14d67c 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -128,7 +128,9 @@ L.TileLayer = L.GridLayer.extend({
 		map.on('dragstart', this._onDragStart, this);
 		map.on('requestloksession', this._onRequestLOKSession, this);
 		map.on('error', this._mapOnError, this);
-		map.on('resize', this._fitDocumentHorizontally, this);
+		if (map.options.autoFitWidth !== false) {
+			map.on('resize', this._fitWidthZoom, this);
+		}
 		// Retrieve the initial cell cursor position (as LOK only sends us an
 		// updated cell cursor when the selected cell is changed and not the initial
 		// cell).
@@ -931,19 +933,22 @@ L.TileLayer = L.GridLayer.extend({
 		L.Socket.sendMessage('requestloksession');
 	},
 
-	_fitDocumentHorizontally: function (e) {
-		if (this._docType !== 'spreadsheet') {
+	_fitWidthZoom: function (e, maxZoom) {
+		var size = e ? e.newSize : this._map.getSize();
+		maxZoom = maxZoom ? maxZoom : this._map.options.zoom;
+		if (this._docType !== 'spreadsheet' || !e) {
+			// If it's not a spreadsheet or the method has been invoked manually
 			var crsScale = this._map.options.crs.scale(1);
-			if (this._docPixelSize.x > e.newSize.x) {
-				var ratio = this._docPixelSize.x / e.newSize.x;
+			if (this._docPixelSize.x > size.x) {
+				var ratio = this._docPixelSize.x / size.x;
 				var zoomDelta = Math.ceil(Math.log(ratio) / Math.log(crsScale));
 				this._map.setZoom(Math.max(1, this._map.getZoom() - zoomDelta), {animate: false});
 			}
-			else if (e.newSize.x / this._docPixelSize.x > crsScale) {
+			else if (size.x / this._docPixelSize.x > crsScale) {
 				// we could zoom in
-				ratio = e.newSize.x / this._docPixelSize.x;
+				ratio = size.x / this._docPixelSize.x;
 				zoomDelta = Math.ceil(Math.log(ratio) / Math.log(crsScale));
-				this._map.setZoom(Math.min(10, this._map.getZoom() + zoomDelta), {animate: false});
+				this._map.setZoom(Math.min(maxZoom, this._map.getZoom() + zoomDelta), {animate: false});
 			}
 		}
 	},


More information about the Libreoffice-commits mailing list