You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const canvassed = require("canvassed");
|
|
|
|
const defaultValue = require("default-value");
|
|
|
|
|
|
|
|
module.exports = function setTextStyles(context, options) {
|
|
|
|
canvassed.validateSync(options, {
|
|
|
|
fontFamily: "required",
|
|
|
|
fontSize: "required"
|
|
|
|
});
|
|
|
|
|
|
|
|
let fontSegments = [
|
|
|
|
options.fontStyle,
|
|
|
|
options.fontVariant,
|
|
|
|
options.fontWeight,
|
|
|
|
`${options.fontSize}px`, // FIXME: Other units?
|
|
|
|
`'${options.fontFamily}'` // FIXME: Escaping of font family names containing a '
|
|
|
|
];
|
|
|
|
|
|
|
|
context.font = fontSegments.filter(segment => (segment != null)).join(" ");
|
|
|
|
context.textBaseline = defaultValue(options.textBaseline, "alphabetic");
|
|
|
|
|
|
|
|
if (options.isStroke) {
|
|
|
|
context.strokeStyle = options.color;
|
|
|
|
} else {
|
|
|
|
context.fillStyle = options.color;
|
|
|
|
}
|
|
|
|
}
|