Skip to content

Commit

Permalink
Fix wrapper with no lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrzej Skrodzki committed Dec 16, 2014
1 parent c3461bf commit 40900f3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/wrappers/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
4 changes: 2 additions & 2 deletions svgtypewriter.js
Original file line number Diff line number Diff line change
@@ -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)
*/
Expand Down Expand Up @@ -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");
Expand Down
10 changes: 10 additions & 0 deletions test/testSuite/wrapperTestSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 40900f3

Please sign in to comment.