Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions overlays/token/multi-template.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
const { Image } = require('canvas')

// For rendering multiple tokens on the same space
function replaceAccentsWithLetters(text) {
// Map accented characters to their regular counterparts
const replacements = {
'á': 'a',
'é': 'e',
'í': 'i',
'ó': 'o',
'ú': 'u',
'Á': 'A',
'É': 'E',
'Í': 'I',
'Ó': 'O',
'Ú': 'U',
'ü': 'u',
'Ü': 'U',
'ä': 'a',
'Ä': 'A',
'ö': 'o',
'Ö': 'O',
'à': 'a',
'è': 'e',
'ì': 'i',
'ò': 'o',
'ù': 'u',
'À': 'A',
'È': 'E',
'Ì': 'I',
'Ò': 'O',
'Ù': 'U',
};

// Replace accented characters with their regular counterparts
return text.replace(/[áéíóúÁÉÍÓÚüÜäÄöÖàèìòùÀÈÌÒÙ]/g, match => replacements[match] || match);
}

const subLabelFontSize = 14;

Expand Down Expand Up @@ -116,7 +149,8 @@ module.exports = ({
// Clip text to fit inside
ctx.save();
ctx.clip();
ctx.fillText(label, xy + offsetX(radius * 0.5, angleToMiddleOfWedge), xy + offsetY(radius * 0.5, angleToMiddleOfWedge));
sanitized_label = replaceAccentsWithLetters(label);
ctx.fillText(sanitized_label, xy + offsetX(radius * 0.5, angleToMiddleOfWedge), xy + offsetY(radius * 0.5, angleToMiddleOfWedge));
ctx.restore();
}

Expand Down