From 40900f32e1b74e81fcb249a0a1ce7e49d426b17d Mon Sep 17 00:00:00 2001 From: Andrzej Skrodzki Date: Tue, 16 Dec 2014 13:50:13 -0800 Subject: [PATCH] Fix wrapper with no lines. --- bower.json | 2 +- package.json | 2 +- src/wrappers/wrapper.ts | 2 +- svgtypewriter.js | 4 ++-- test/testSuite/wrapperTestSuite.ts | 10 ++++++++++ test/tests.js | 9 +++++++++ 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/bower.json b/bower.json index 5c35329..7adc782 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "svg-typewriter", "description": "A library for measuring, manipulating, and writing text on SVG.", - "version": "0.1.3", + "version": "0.1.4", "main": ["svgtypewriter.js"], "license": "MIT", "ignore": [ diff --git a/package.json b/package.json index 80eb2a8..402f49e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svgtypewriter", - "version": "0.1.3", + "version": "0.1.4", "description": "A library for measuring, manipulating, and writing text on SVG.", "repository": { "type": "git", diff --git a/src/wrappers/wrapper.ts b/src/wrappers/wrapper.ts index 780586f..87f099e 100644 --- a/src/wrappers/wrapper.ts +++ b/src/wrappers/wrapper.ts @@ -92,7 +92,7 @@ module SVGTypewriter.Wrappers { wrapping: initialWrappingResult, currentLine: "", availableWidth: width, - availableLines: Math.min(height / measurer.measure().height, this._maxLines), + availableLines: Math.min(Math.floor(height / measurer.measure().height), this._maxLines), canFitText: true }; diff --git a/svgtypewriter.js b/svgtypewriter.js index f90dfd5..39509a9 100644 --- a/svgtypewriter.js +++ b/svgtypewriter.js @@ -1,5 +1,5 @@ /*! -SVG Typewriter 0.1.3 (https://github.com/palantir/svg-typewriter) +SVG Typewriter 0.1.4 (https://github.com/palantir/svg-typewriter) Copyright 2014 Palantir Technologies Licensed under MIT (https://github.com/palantir/svg-typewriter/blob/develop/LICENSE) */ @@ -459,7 +459,7 @@ var SVGTypewriter; wrapping: initialWrappingResult, currentLine: "", availableWidth: width, - availableLines: Math.min(height / measurer.measure().height, this._maxLines), + availableLines: Math.min(Math.floor(height / measurer.measure().height), this._maxLines), canFitText: true }; var lines = text.split("\n"); diff --git a/test/testSuite/wrapperTestSuite.ts b/test/testSuite/wrapperTestSuite.ts index e4dd07f..c8fe43a 100644 --- a/test/testSuite/wrapperTestSuite.ts +++ b/test/testSuite/wrapperTestSuite.ts @@ -56,6 +56,16 @@ describe("Wrapper Test Suite", () => { assert.deepEqual(result.noLines, 1, "no wrapping was needed"); }); + it("does not wrap becasue of height", () => { + var dimensions = measurer.measure(token); + var result = wrapper.wrap(token, measurer, dimensions.width, dimensions.height / 2); + assert.deepEqual(result.originalText, token, "original text has been set"); + assert.deepEqual(result.wrappedText, "", "wrapped text is empty"); + assert.deepEqual(result.truncatedText, token, "whole word has been truncated"); + assert.deepEqual(result.noBrokeWords, 0, "non of tokens has been broken"); + assert.deepEqual(result.noLines, 0, "no wrapping was needed"); + }); + it("one time wrapping", () => { var availableWidth = measurer.measure(token).width * 3 / 4; var result = wrapper.wrap(token, measurer, availableWidth); diff --git a/test/tests.js b/test/tests.js index 08d45db..422a7d2 100644 --- a/test/tests.js +++ b/test/tests.js @@ -238,6 +238,15 @@ describe("Wrapper Test Suite", function () { assert.deepEqual(result.noBrokeWords, 0, "non of tokens has been broken"); assert.deepEqual(result.noLines, 1, "no wrapping was needed"); }); + it("does not wrap becasue of height", function () { + var dimensions = measurer.measure(token); + var result = wrapper.wrap(token, measurer, dimensions.width, dimensions.height / 2); + assert.deepEqual(result.originalText, token, "original text has been set"); + assert.deepEqual(result.wrappedText, "", "wrapped text is empty"); + assert.deepEqual(result.truncatedText, token, "whole word has been truncated"); + assert.deepEqual(result.noBrokeWords, 0, "non of tokens has been broken"); + assert.deepEqual(result.noLines, 0, "no wrapping was needed"); + }); it("one time wrapping", function () { var availableWidth = measurer.measure(token).width * 3 / 4; var result = wrapper.wrap(token, measurer, availableWidth);