Skip to content

Commit

Permalink
Merge pull request #1 from julienw/1137097-fix-overflow-issue
Browse files Browse the repository at this point in the history
Bug 1137097 - Report when the font fit algorithm couldn't fit the availa...
  • Loading branch information
julienw committed Mar 20, 2015
2 parents 46a3162 + 08114e2 commit 9d00191
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions font-fit.js
Expand Up @@ -51,7 +51,7 @@ var BUFFER = 3;
* - {Number} `max` Max font-size (px) (optional)
*
* @param {Object} config
* @return {Object} {fontSize,textWidth}
* @return {Object} {fontSize,overflowing,textWidth}
*/
module.exports = function(config) {
debug('font fit', config);
Expand All @@ -70,7 +70,8 @@ module.exports = function(config) {

return {
textWidth: textWidth,
fontSize: fontSize
fontSize: fontSize,
overflowing: textWidth > space
};
};

Expand Down
5 changes: 4 additions & 1 deletion test/test.js
Expand Up @@ -68,12 +68,14 @@ suite('FontFit', function() {
this.config.text = createStringOfWidth(1000, this.config.font);
var result = fontFit(this.config);
assert.equal(result.fontSize, 16);
assert.isTrue(result.overflowing);
});

test('It doesn\'t go any higher than the max fontSize', function() {
this.config.text = createStringOfWidth(10, this.config.font);
var result = fontFit(this.config);
assert.equal(result.fontSize, 24);
assert.isFalse(result.overflowing);
});

test('It ignores whitespace (just like HTML does)', function() {
Expand All @@ -95,7 +97,8 @@ suite('FontFit', function() {

test('It uses a 3px buffer', function() {
this.config.text = createStringOfWidth(100, this.config.font);
assert.ok(fontFit(this.config).textWidth <= 97, 'text width is at least 3px < overall space');
var result = fontFit(this.config);
assert.ok(result.textWidth <= 97, 'text width is at least 3px < overall space');
});
});

Expand Down

0 comments on commit 9d00191

Please sign in to comment.