Skip to content

Commit 567ad16

Browse files
committed
add tests, update README, linting
1 parent f7590ad commit 567ad16

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,11 @@ Create a Path that represents the given text.
194194
* `fontSize`: Size of the text in pixels (default: `72`).
195195

196196
Options is an optional object containing:
197-
* `kerning`: if true takes kerning information into account (default: `true`)
197+
* `kerning`: if `true`, takes kerning information into account (default: `true`)
198198
* `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.
199199
Currently only ligature features `"liga"` and `"rlig"` are supported (default: `true`).
200200
* `hinting`: if true uses TrueType font hinting if available (default: `false`).
201+
* `style`: An object of possible styling properties (fill, stroke, strokeWidth) applied to the resulting Path
201202

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

@@ -213,6 +214,7 @@ Options is an optional object containing:
213214
* `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.
214215
Currently only ligature features `"liga"` and `"rlig"` are supported (default: `true`).
215216
* `hinting`: if true uses TrueType font hinting if available (default: `false`).
217+
* `style`: An object of possible styling properties (fill, stroke, strokeWidth) applied to the resulting Path
216218

217219
#### `Font.drawPoints(ctx, text, x, y, fontSize, options)`
218220
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()`.

src/path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,6 @@ Path.prototype.applyStyles = function(styles) {
674674
}
675675
}
676676
return this;
677-
}
677+
};
678678

679679
export default Path;

test/font.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,20 @@ describe('font.js', function() {
9292
});
9393

9494
});
95+
96+
describe('style handling', function() {
97+
let font;
98+
99+
before(function() {
100+
font = loadSync('./test/fonts/Roboto-Black.ttf');
101+
});
102+
103+
it('should apply style options to the path', function() {
104+
const options = {
105+
style: { fill: '#ffaa00' }
106+
};
107+
const path = font.getPath('X', 0, 0, 72, options);
108+
assert.equal(path.fill, '#ffaa00');
109+
});
110+
});
95111
});

test/glyph.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,24 @@ describe('glyph.js', function() {
133133
});
134134
});
135135
});
136+
137+
describe('style handling', function() {
138+
let font;
139+
let glyph;
140+
141+
before(function() {
142+
font = loadSync('./test/fonts/Roboto-Black.ttf');
143+
glyph = font.charToGlyph('A');
144+
});
145+
146+
it('should apply style options to the path', function() {
147+
const options = {
148+
style: { fill: '#ffaa00' }
149+
};
150+
const path = glyph.getPath(0, 0, 72, options, font);
151+
assert.equal(path.fill, '#ffaa00');
152+
});
153+
});
136154
});
137155

138156
describe('glyph.js on low memory mode', function() {

test/path.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ describe('path.js', function() {
153153
emptyPath.fill = 'black';
154154
assert.equal(emptyPath.toDOMElement().getAttribute('fill'), undefined);
155155
});
156+
157+
it('should apply styles via applyStyles()', function() {
158+
const styles = {
159+
fill: '#ffaa00',
160+
stroke: '#6600aa',
161+
strokeWidth: 5
162+
};
163+
emptyPath.applyStyles(styles);
164+
assert.deepEqual({
165+
fill: emptyPath.fill,
166+
stroke: emptyPath.stroke,
167+
strokeWidth: emptyPath.strokeWidth
168+
}, styles);
169+
});
156170

157171
after(() => {
158172
delete global.document;

0 commit comments

Comments
 (0)