Update creator-22.js

This commit is contained in:
Kyle
2021-08-06 14:19:04 -07:00
parent 2e97650a13
commit 2587835ccf

View File

@@ -757,6 +757,7 @@ function writeText(textObject, targetContext) {
var textColor = textObject.color || 'black'; var textColor = textObject.color || 'black';
var textFont = textObject.font || 'mplantin'; var textFont = textObject.font || 'mplantin';
var textAlign = textObject.align || 'left'; var textAlign = textObject.align || 'left';
var textJustify = textObject.justify || 'left';
var textShadowColor = textObject.shadow || 'black'; var textShadowColor = textObject.shadow || 'black';
var textShadowOffsetX = scaleWidth(textObject.shadowX) || 0; var textShadowOffsetX = scaleWidth(textObject.shadowX) || 0;
var textShadowOffsetY = scaleHeight(textObject.shadowY) || 0; var textShadowOffsetY = scaleHeight(textObject.shadowY) || 0;
@@ -785,6 +786,7 @@ function writeText(textObject, targetContext) {
var realTextAlign = textAlign; var realTextAlign = textAlign;
savedRollYPosition = null; savedRollYPosition = null;
var drawToPrePTCanvas = false; var drawToPrePTCanvas = false;
var widestLineWidth = 0;
//variables that track various... things? //variables that track various... things?
var newLineSpacing = 0; var newLineSpacing = 0;
var textSize = startingTextSize; var textSize = startingTextSize;
@@ -861,6 +863,12 @@ function writeText(textObject, targetContext) {
textAlign = 'center'; textAlign = 'center';
} else if (possibleCode == 'right') { } else if (possibleCode == 'right') {
textAlign = 'right'; textAlign = 'right';
} else if (possibleCode == 'justify-left') {
textJustify = 'left';
} else if (possibleCode == 'justify-center') {
textJustify = 'center';
} else if (possibleCode == 'justify-right') {
textJustify = 'right';
} else if (possibleCode.includes('fontcolor')) { } else if (possibleCode.includes('fontcolor')) {
textColor = possibleCode.replace('fontcolor', ''); textColor = possibleCode.replace('fontcolor', '');
lineContext.fillStyle = textColor; lineContext.fillStyle = textColor;
@@ -1045,6 +1053,10 @@ function writeText(textObject, targetContext) {
} else if (textAlign == 'right') { } else if (textAlign == 'right') {
horizontalAdjust = textWidth - currentX; horizontalAdjust = textWidth - currentX;
} }
if (currentX > widestLineWidth) {
console.log(currentX);
widestLineWidth = currentX;
}
paragraphContext.drawImage(lineCanvas, horizontalAdjust, currentY); paragraphContext.drawImage(lineCanvas, horizontalAdjust, currentY);
lineY = 0; lineY = 0;
lineContext.clearRect(0, 0, lineCanvas.width, lineCanvas.height); lineContext.clearRect(0, 0, lineCanvas.width, lineCanvas.height);
@@ -1090,6 +1102,19 @@ function writeText(textObject, targetContext) {
if (!textObject.noVerticalCenter) { if (!textObject.noVerticalCenter) {
verticalAdjust = (textHeight - currentY + textSize * 0.15) / 2; verticalAdjust = (textHeight - currentY + textSize * 0.15) / 2;
} }
var finalHorizontalAdjust = 0;
const horizontalAdjustUnit = (textWidth - widestLineWidth) / 2;
if (textJustify == 'right' && textAlign != 'right') {
finalHorizontalAdjust = 2 * horizontalAdjustUnit;
if (textAlign == 'center') {
finalHorizontalAdjust = horizontalAdjustUnit;
}
} else if (textJustify == 'center' && textAlign != 'center') {
finalHorizontalAdjust = horizontalAdjustUnit;
if (textAlign == 'right') {
finalHorizontalAdjust = - horizontalAdjustUnit;
}
}
var trueTargetContext = targetContext; var trueTargetContext = targetContext;
if (drawToPrePTCanvas) { if (drawToPrePTCanvas) {
trueTargetContext = prePTContext; trueTargetContext = prePTContext;
@@ -1101,10 +1126,10 @@ function writeText(textObject, targetContext) {
const shapeY = textY + ptShift[1]; const shapeY = textY + ptShift[1];
trueTargetContext.translate(shapeX, shapeY); trueTargetContext.translate(shapeX, shapeY);
trueTargetContext.rotate(Math.PI * textRotation / 180); trueTargetContext.rotate(Math.PI * textRotation / 180);
trueTargetContext.drawImage(paragraphCanvas, permaShift[0] - canvasMargin, verticalAdjust - canvasMargin + permaShift[1]); trueTargetContext.drawImage(paragraphCanvas, permaShift[0] - canvasMargin + finalHorizontalAdjust, verticalAdjust - canvasMargin + permaShift[1]);
trueTargetContext.restore(); trueTargetContext.restore();
} else { } else {
trueTargetContext.drawImage(paragraphCanvas, textX - canvasMargin + ptShift[0] + permaShift[0], textY - canvasMargin + verticalAdjust + ptShift[1] + permaShift[1]); trueTargetContext.drawImage(paragraphCanvas, textX - canvasMargin + ptShift[0] + permaShift[0] + finalHorizontalAdjust, textY - canvasMargin + verticalAdjust + ptShift[1] + permaShift[1]);
} }
drawingText = false; drawingText = false;
} }