From 106f1fd111a75778a2c61424290f33295cec9964 Mon Sep 17 00:00:00 2001 From: wbfsa Date: Tue, 18 Aug 2020 00:38:02 +0800 Subject: [PATCH] fix(text get wrong height when zoom): fix height --- src/controllers/zoom.js | 21 ++++++++++++++++++--- src/global/getRowlen.js | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/controllers/zoom.js b/src/controllers/zoom.js index 56ba16b..1adc4a9 100644 --- a/src/controllers/zoom.js +++ b/src/controllers/zoom.js @@ -5,6 +5,9 @@ import {changeSheetContainerSize} from './resize'; import { jfrefreshgrid_rhcw } from '../global/refresh'; + +let luckysheetZoomTimeout = null; + export function zoomChange(ratio){ if(Store.flowdata==null || Store.flowdata.length==0){ return; @@ -12,9 +15,13 @@ export function zoomChange(ratio){ Store.zoomRatio = ratio; - jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); - - changeSheetContainerSize(); + clearTimeout(luckysheetZoomTimeout); + luckysheetZoomTimeout = setTimeout(() => { + jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); + changeSheetContainerSize(); + }, 100); + + } @@ -31,6 +38,10 @@ export function zoomInitial(){ currentRatio = currentRatio-0.1; + if(currentRatio==Store.zoomRatio){ + currentRatio = currentRatio-0.1; + } + if(currentRatio<=0.1){ currentRatio = 0.1; } @@ -51,6 +62,10 @@ export function zoomInitial(){ currentRatio = currentRatio+0.1; + if(currentRatio==Store.zoomRatio){ + currentRatio = currentRatio+0.1; + } + if(currentRatio>=4){ currentRatio = 4; } diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js index 8d16a4e..9b7725a 100644 --- a/src/global/getRowlen.js +++ b/src/global/getRowlen.js @@ -181,7 +181,7 @@ function getMeasureText(value, ctx){ cache.width *= Store.zoomRatio; cache.actualBoundingBoxDescent *= Store.zoomRatio; cache.actualBoundingBoxAscent *= Store.zoomRatio; - Store.measureTextCache[value + "_" + ctx.font] = cache; + Store.measureTextCache[value + "_" + Store.zoomRatio + "_" + ctx.font] = cache; return cache; }