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.

25 lines
716 B
JavaScript

'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");
context.strokeStyle = options.strokeColor;
context.fillStyle = options.fillColor;
}