From d85b6573c9ceddc1de21a79fad00dbcc293a861d Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Wed, 15 May 2013 19:37:39 -0700 Subject: [PATCH 1/4] use integer line-height to avoid round-off errors --- src/view/ViewCommandHandlers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index 9b4aff54435..36eca76ca4e 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -171,7 +171,7 @@ define(function (require, exports, module) { var lhOld = parseFloat(lhStyle.substring(0, lhStyle.length - 2)); var fsNew = fsOld + (delta * adjustment); - var lhNew = (fsUnits === lhUnits) ? fsNew * LINE_HEIGHT : lhOld; + var lhNew = (fsUnits === lhUnits) ? Math.round(fsNew * LINE_HEIGHT) : lhOld; var fsStr = fsNew + fsUnits; var lhStr = lhNew + lhUnits; From ebb026f1add92a42d5ec10beaf4e35023f078442 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 16 May 2013 09:50:21 -0700 Subject: [PATCH 2/4] only round off when using px --- src/view/ViewCommandHandlers.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index 36eca76ca4e..f81b7032951 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -171,7 +171,14 @@ define(function (require, exports, module) { var lhOld = parseFloat(lhStyle.substring(0, lhStyle.length - 2)); var fsNew = fsOld + (delta * adjustment); - var lhNew = (fsUnits === lhUnits) ? Math.round(fsNew * LINE_HEIGHT) : lhOld; + var lhNew = lhOld; + if (fsUnits === lhUnits) { + lhNew = fsNew * LINE_HEIGHT; + if (lhUnits === "px") { + // Use integer px value to avoid subsequent round-off differences + lhNew = Math.round(lhNew); + } + } var fsStr = fsNew + fsUnits; var lhStr = lhNew + lhUnits; From cf371f8db8bd58ff65b39b36bcaefcbf96c8ff3d Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Fri, 17 May 2013 08:43:38 -0700 Subject: [PATCH 3/4] tweak to avoid gaps between lines --- src/view/ViewCommandHandlers.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/view/ViewCommandHandlers.js b/src/view/ViewCommandHandlers.js index f81b7032951..89dc1435f4e 100644 --- a/src/view/ViewCommandHandlers.js +++ b/src/view/ViewCommandHandlers.js @@ -75,7 +75,7 @@ define(function (require, exports, module) { * The ratio of line-height to font-size when they use the same units * @type {float} */ - var LINE_HEIGHT = 1.3; + var LINE_HEIGHT = 1.25; /** * @private @@ -175,8 +175,8 @@ define(function (require, exports, module) { if (fsUnits === lhUnits) { lhNew = fsNew * LINE_HEIGHT; if (lhUnits === "px") { - // Use integer px value to avoid subsequent round-off differences - lhNew = Math.round(lhNew); + // Use integer px value to avoid rounding differences + lhNew = Math.ceil(lhNew); } } From 6bc0a9a68749683f024f9a182ab7398c34ad413f Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Fri, 17 May 2013 15:37:39 -0700 Subject: [PATCH 4/4] fix unti test --- test/spec/ViewCommandHandlers-test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/spec/ViewCommandHandlers-test.js b/test/spec/ViewCommandHandlers-test.js index 7e418479ae5..987dbed38c0 100644 --- a/test/spec/ViewCommandHandlers-test.js +++ b/test/spec/ViewCommandHandlers-test.js @@ -121,11 +121,11 @@ define(function (require, exports, module) { }); it("should keep the same font size when opening another document", function () { - var promise, expectedSize, editor; + var promise, originalSize, editor; runs(function () { editor = EditorManager.getCurrentFullEditor(); - expectedSize = editor.getTextHeight() + 1; + originalSize = editor.getTextHeight(); promise = CommandManager.execute(Commands.VIEW_INCREASE_FONT_SIZE); waitsForDone(promise, "Increase font size"); @@ -139,7 +139,7 @@ define(function (require, exports, module) { runs(function () { editor = EditorManager.getCurrentFullEditor(); - expect(editor.getTextHeight()).toBe(expectedSize); + expect(editor.getTextHeight()).toBeGreaterThan(originalSize); }); // This must be in the last spec in the suite.