Skip to content

Commit f7590ad

Browse files
committed
implement styling of fill/stroke/strokeWidth when using Font.draw() or Glyph.draw()
1 parent 9266555 commit f7590ad

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/font.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ Font.prototype.getPath = function(text, x, y, fontSize, options) {
366366
const glyphPath = glyph.getPath(gX, gY, gFontSize, options, this);
367367
fullPath.extend(glyphPath);
368368
});
369+
370+
if ( options.style !== undefined ) {
371+
fullPath.applyStyles(options.style);
372+
}
369373
return fullPath;
370374
};
371375

src/glyph.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ Glyph.prototype.getPath = function(x, y, fontSize, options, font) {
187187
}
188188
}
189189

190+
if ( options.style !== undefined ) {
191+
p.applyStyles(options.style);
192+
}
193+
190194
return p;
191195
};
192196

src/path.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,4 +658,22 @@ Path.prototype.toDOMElement = function(options, pathData) {
658658
return newPath;
659659
};
660660

661+
/**
662+
* Apply styles to the path
663+
* @param {object} [styles] - Styles object {fill,stroke,strokeWidth}
664+
* @return {Path}
665+
*/
666+
Path.prototype.applyStyles = function(styles) {
667+
if ( styles !== undefined ) {
668+
const pathStyles = ['fill','stroke','strokeWidth'];
669+
for(let s = 0; s < pathStyles.length; s++) {
670+
const styleProp = pathStyles[s];
671+
if ( styles[styleProp] !== undefined ) {
672+
this[styleProp] = styles[styleProp];
673+
}
674+
}
675+
}
676+
return this;
677+
}
678+
661679
export default Path;

0 commit comments

Comments
 (0)