Actualmente estoy trabajando en un proyecto WebGL. Se me pide que configure las alineaciones de texto como un documento de Microsoft Word como se representa en Alineaciones de texto .
Hasta ahora, he logrado alineaciones 'izquierda', 'derecha' y 'centro' usando la documentación de Mozilla
Me pregunto si 'justificar' se puede lograr de alguna manera (el último en la imagen de alineaciones de texto).
Mi fragmento de código:
let randomText = "abcd" let textAlignValue = "center" textCanvas = document.createElement('canvas'); ctx = textCanvas.getContext('2d'); ctx.font = '15px arial'; // pick font size and font family ctx.clearRect(0, 0, textCanvas.width, textCanvas.height); // clear content ctx.fillStyle = 'yellow'; // background color ctx.fillRect(0, 0, textCanvas.width, textCanvas.height); // fill background ctx.fillStyle = 'black'; // text color ctx.textAlign = textAlignValue; // align text ctx.fillText(randomText, textCanvas.width / 2, textCanvas.height / 2); // fill text