From 1431cd3d1b83445fddd4e74005b404d6d97d7b22 Mon Sep 17 00:00:00 2001 From: lolcat Date: Tue, 31 Dec 2024 01:01:53 -0500 Subject: [PATCH] cap fixed --- client.js | 128 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 101 insertions(+), 27 deletions(-) diff --git a/client.js b/client.js index baa3a46..04891cb 100644 --- a/client.js +++ b/client.js @@ -1721,45 +1721,119 @@ deek.on("message", async function(msg, user){ var fontsize = Math.floor(image.width * 0.08); ctx.font = fontsize + "px Impact"; ctx.fillStyle = "white"; + ctx.lineJoin = "round"; + ctx.lineCap = "round"; ctx.strokeStyle = "black"; ctx.lineWidth = image.width * 0.01; ctx.textAlign = "center"; - ctx.textBaseline = "top"; + ctx.textBaseline = "bottom"; - var parts = value.replace(/ +/g, " ").split(""); - var tmp_text = ""; - var tmp_text_old = ""; - var text_to_add = ""; - var line = 0; - for(var i=0; i= image.width || - parts.length - 1 === i - ){ - // draw - if(metrics.width >= image.width){ + for(var i=0; i= image.width){ - // put text on next line since it overflows - tmp_text_old = tmp_text_old.trim(); - tmp_text = parts[i]; + if(line != ""){ + + lines.push(line.trim()); + line = ""; + } + + line_tmp = ""; + + // increment letters till we go over the limit + var letters = words[i].split(""); + + for(var k=0; k= image.width){ + + lines.push(line.trim()); + line = letters[k]; + line_tmp = letters[k]; + }else{ + + line += letters[k]; + } + } + + // output remainder + lines.push(line); + line = ""; + line_tmp = ""; - text_to_add = tmp_text_old; }else{ - text_to_add = tmp_text; + // wrap word normally + line_tmp += words[i] + " "; + + if(ctx.measureText(line_tmp.trim()).width >= image.width){ + + // push line + lines.push(line.trim()); + line = ""; + line_tmp = words[i] + " "; + } + + line += words[i] + " "; + } + } + + // output remainder + if(line != ""){ + lines.push(line); + line = ""; + line_tmp = ""; + } + + var tmp_metrics = ctx.measureText(lines[i]); + var space = (tmp_metrics.actualBoundingBoxAscent + tmp_metrics.actualBoundingBoxDescent) / 3; + + if(is_bottom){ + + height = image.height - space; + lines = lines.reverse(); + }else{ + + height = space; + } + + for(var i=0; i