Save and restore before rendering labels
This commit is contained in:
+6
-15
@@ -401,30 +401,21 @@ export const resetTransform = createTransform();
|
|||||||
*/
|
*/
|
||||||
export function drawImageOrLabel(context,
|
export function drawImageOrLabel(context,
|
||||||
transform, opacity, labelOrImage, originX, originY, w, h, x, y, scale) {
|
transform, opacity, labelOrImage, originX, originY, w, h, x, y, scale) {
|
||||||
let alpha;
|
context.save();
|
||||||
if (opacity != 1) {
|
|
||||||
alpha = context.globalAlpha;
|
|
||||||
context.globalAlpha = alpha * opacity;
|
|
||||||
}
|
|
||||||
if (transform) {
|
if (transform) {
|
||||||
context.setTransform.apply(context, transform);
|
context.setTransform.apply(context, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
const isLabel = !!(/** @type {*} */ (labelOrImage).contextInstructions);
|
if ((/** @type {*} */ (labelOrImage).contextInstructions)) {
|
||||||
|
// label
|
||||||
if (isLabel) {
|
|
||||||
context.translate(x, y);
|
context.translate(x, y);
|
||||||
context.scale(scale, scale);
|
context.scale(scale, scale);
|
||||||
executeLabelInstructions(/** @type {import("./canvas/Executor.js").Label} */ (labelOrImage), context);
|
executeLabelInstructions(/** @type {import("./canvas/Executor.js").Label} */ (labelOrImage), context);
|
||||||
} else {
|
} else {
|
||||||
|
// image
|
||||||
context.drawImage(/** @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} */ (labelOrImage), originX, originY, w, h, x, y, w * scale, h * scale);
|
context.drawImage(/** @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} */ (labelOrImage), originX, originY, w, h, x, y, w * scale, h * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opacity != 1) {
|
context.restore();
|
||||||
context.globalAlpha = alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transform || isLabel) {
|
|
||||||
context.setTransform.apply(context, resetTransform);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user