Skip to content

Commit

Permalink
Ignore maxWidth in fillText and strokeText if it is undefined (#1455)
Browse files Browse the repository at this point in the history
* Ignore maxWidth if it is undefined

* Temporarily disable flaky build for Node.js 12

* Replace decrement with constant assignment for better performance

* Allow test failure instead of disabling build
  • Loading branch information
Hakerh400 authored and zbjornson committed Jul 12, 2019
1 parent f5b9814 commit a0ef7dd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ node_js:
- '10'
- '8'
- '6'
matrix:
allow_failures:
- node_js: '12'
addons:
apt:
sources:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
### Changed
### Added
### Fixed
* Ignore `maxWidth` in `fillText` and `strokeText` if it is undefined

2.6.0
==================
Expand Down
4 changes: 4 additions & 0 deletions src/CanvasRenderingContext2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,10 @@ get_text_scale(PangoLayout *layout, double maxWidth) {
void
paintText(const Nan::FunctionCallbackInfo<Value> &info, bool stroke) {
int argsNum = info.Length() >= 4 ? 3 : 2;

if (argsNum == 3 && info[3]->IsUndefined())
argsNum = 2;

double args[3];
if(!checkArgs(info, args, argsNum, 1))
return;
Expand Down
17 changes: 17 additions & 0 deletions test/canvas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,23 @@ describe('Canvas', function () {
});
});

it('Context2d#fillText()', function () {
[
[['A', 10, 10], true],
[['A', 10, 10, undefined], true],
[['A', 10, 10, NaN], false],
].forEach(([args, shouldDraw]) => {
const canvas = createCanvas(20, 20)
const ctx = canvas.getContext('2d')

ctx.textBaseline = 'middle'
ctx.textAlign = 'center'
ctx.fillText(...args)

assert.strictEqual(ctx.getImageData(0, 0, 20, 20).data.some(a => a), shouldDraw)
})
})

it('Context2d#currentTransform', function () {
var canvas = createCanvas(20, 20);
var ctx = canvas.getContext('2d');
Expand Down

0 comments on commit a0ef7dd

Please sign in to comment.