Skip to content

Commit

Permalink
fixed infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
namniak committed Jan 17, 2016
1 parent 3d0aecc commit 582623b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
canvas-text-wrapper
=================
##v0.6.7
##v0.7.0


## Syntax
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "canvas-text-wrapper",
"version": "0.6.7",
"version": "0.7.0",
"ignore": [
"**/.*",
"**/*.log",
Expand Down
28 changes: 16 additions & 12 deletions canvas-text-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! canvas-text-wrapper
* https://github.com/namniak/canvas-text-wrapper
* Version: 0.6.7
* Version: 0.7.0
* MIT License (http://www.opensource.org/licenses/mit-license.html)
*/

Expand Down Expand Up @@ -169,17 +169,21 @@
lines[j] = '';

if (opts.lineBreak === 'auto') {
while ((context.measureText(lines[j] + words[i]).width <= MAX_TXT_WIDTH) && (i < words.length)) {

lines[j] += words[i] + ' ';
i++;

if (opts.allowNewLine) {
for (var k = 0; k < newLineIndexes.length; k++) {
if (newLineIndexes[k] === i) {
j++;
lines[j] = '';
break;
if (context.measureText(lines[j] + words[i]).width > MAX_TXT_WIDTH) {
break;
} else {
while ((context.measureText(lines[j] + words[i]).width <= MAX_TXT_WIDTH) && (i < words.length)) {

lines[j] += words[i] + ' ';
i++;

if (opts.allowNewLine) {
for (var k = 0; k < newLineIndexes.length; k++) {
if (newLineIndexes[k] === i) {
j++;
lines[j] = '';
break;
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions canvas-text-wrapper.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "canvas-text-wrapper",
"description": "Split canvas text into lines on specified rule with optional alignment, padding, and more. Supports HDPI screens.",
"version": "0.6.7",
"version": "0.7.0",
"license": "MIT",
"main": "canvas-text-wrapper.min.js",
"keywords": [
Expand Down

0 comments on commit 582623b

Please sign in to comment.