Skip to content

Commit

Permalink
implement styling of fill/stroke/strokeWidth when using Font.draw() o…
Browse files Browse the repository at this point in the history
…r Glyph.draw()
  • Loading branch information
Connum committed Nov 5, 2023
1 parent 9266555 commit f7590ad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ Font.prototype.getPath = function(text, x, y, fontSize, options) {
const glyphPath = glyph.getPath(gX, gY, gFontSize, options, this);
fullPath.extend(glyphPath);
});

if ( options.style !== undefined ) {
fullPath.applyStyles(options.style);
}
return fullPath;
};

Expand Down
4 changes: 4 additions & 0 deletions src/glyph.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ Glyph.prototype.getPath = function(x, y, fontSize, options, font) {
}
}

if ( options.style !== undefined ) {
p.applyStyles(options.style);
}

return p;
};

Expand Down
18 changes: 18 additions & 0 deletions src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,4 +658,22 @@ Path.prototype.toDOMElement = function(options, pathData) {
return newPath;
};

/**
* Apply styles to the path
* @param {object} [styles] - Styles object {fill,stroke,strokeWidth}
* @return {Path}
*/
Path.prototype.applyStyles = function(styles) {
if ( styles !== undefined ) {
const pathStyles = ['fill','stroke','strokeWidth'];
for(let s = 0; s < pathStyles.length; s++) {
const styleProp = pathStyles[s];
if ( styles[styleProp] !== undefined ) {
this[styleProp] = styles[styleProp];
}
}
}
return this;
}

export default Path;

0 comments on commit f7590ad

Please sign in to comment.