Skip to content

Commit

Permalink
add tests, update README, linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Connum committed Nov 5, 2023
1 parent f7590ad commit 567ad16
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ Create a Path that represents the given text.
* `fontSize`: Size of the text in pixels (default: `72`).

Options is an optional object containing:
* `kerning`: if true takes kerning information into account (default: `true`)
* `kerning`: if `true`, takes kerning information into account (default: `true`)
* `features`: an object with [OpenType feature tags](https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags) as keys, and a boolean value to enable each feature.
Currently only ligature features `"liga"` and `"rlig"` are supported (default: `true`).
* `hinting`: if true uses TrueType font hinting if available (default: `false`).
* `style`: An object of possible styling properties (fill, stroke, strokeWidth) applied to the resulting Path

_**Note:** there is also `Font.getPaths()` with the same arguments, which returns a list of Paths._

Expand All @@ -213,6 +214,7 @@ Options is an optional object containing:
* `features`: an object with [OpenType feature tags](https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags) as keys, and a boolean value to enable each feature.
Currently only ligature features `"liga"` and `"rlig"` are supported (default: `true`).
* `hinting`: if true uses TrueType font hinting if available (default: `false`).
* `style`: An object of possible styling properties (fill, stroke, strokeWidth) applied to the resulting Path

#### `Font.drawPoints(ctx, text, x, y, fontSize, options)`
Draw the points of all glyphs in the text. On-curve points will be drawn in blue, off-curve points will be drawn in red. The arguments are the same as `Font.draw()`.
Expand Down
2 changes: 1 addition & 1 deletion src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,6 @@ Path.prototype.applyStyles = function(styles) {
}
}
return this;
}
};

export default Path;
16 changes: 16 additions & 0 deletions test/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,20 @@ describe('font.js', function() {
});

});

describe('style handling', function() {
let font;

before(function() {
font = loadSync('./test/fonts/Roboto-Black.ttf');
});

it('should apply style options to the path', function() {
const options = {
style: { fill: '#ffaa00' }
};
const path = font.getPath('X', 0, 0, 72, options);
assert.equal(path.fill, '#ffaa00');
});
});
});
18 changes: 18 additions & 0 deletions test/glyph.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@ describe('glyph.js', function() {
});
});
});

describe('style handling', function() {
let font;
let glyph;

before(function() {
font = loadSync('./test/fonts/Roboto-Black.ttf');
glyph = font.charToGlyph('A');
});

it('should apply style options to the path', function() {
const options = {
style: { fill: '#ffaa00' }
};
const path = glyph.getPath(0, 0, 72, options, font);
assert.equal(path.fill, '#ffaa00');
});
});
});

describe('glyph.js on low memory mode', function() {
Expand Down
14 changes: 14 additions & 0 deletions test/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ describe('path.js', function() {
emptyPath.fill = 'black';
assert.equal(emptyPath.toDOMElement().getAttribute('fill'), undefined);
});

it('should apply styles via applyStyles()', function() {
const styles = {
fill: '#ffaa00',
stroke: '#6600aa',
strokeWidth: 5
};
emptyPath.applyStyles(styles);
assert.deepEqual({
fill: emptyPath.fill,
stroke: emptyPath.stroke,
strokeWidth: emptyPath.strokeWidth
}, styles);
});

after(() => {
delete global.document;
Expand Down

0 comments on commit 567ad16

Please sign in to comment.