You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When set different baseline, the rendering positions are different to node-canvas.
Code
Click to show the code
import{createCanvas}from"canvas";importfsfrom"node:fs";import{Canvas}from"skia-canvas";// skia-canvasletskiaCanvas=newCanvas(1000,1000);testDrawText(skiaCanvas,"skia-canvas");awaitskiaCanvas.saveAs("skia-canvas.pdf");// node-canvasletnodeCanvas=newcreateCanvas(1000,1000,"pdf");nodeCanvas.getContext("2d").textDrawingMode="glyph";testDrawText(nodeCanvas,"node-canvas");fs.writeFileSync("node-canvas.pdf",nodeCanvas.toBuffer());functiontestDrawText(canvas,tip){constcrossLineHalfWidth=25;conststep=60;constx=50;lety=60;letfontFamily="zcool-gdh";lettext="The quick brown fox jumps over the lazy dog";letctx=canvas.getContext("2d");ctx.strokeStyle="purple";ctx.fillStyle="black";ctx.lineWidth=1;ctx.font=`normal 20pt '${fontFamily}'`;constbaselines=["top","hanging","middle","alphabetic","ideographic","bottom"];drawTextWithTip(tip);baselines.forEach((baseline,index)=>drawTextWithCrossLine(text,x,y+step*(index+1),baseline));y=600;fontFamily="Times new Roman";ctx.font=`normal 12pt '${fontFamily}'`;text="Abcdefg";drawTextWithLine(text,x+100,y);functiondrawTextWithCrossLine(text,x,y,baseline){ctx.textBaseline=baseline;ctx.fillText(`${text}(${baseline})`,x,y);ctx.moveTo(x-crossLineHalfWidth,y);ctx.lineTo(x+crossLineHalfWidth,y);ctx.stroke();ctx.moveTo(x,y-crossLineHalfWidth);ctx.lineTo(x,y+crossLineHalfWidth);ctx.stroke();}functiondrawTextWithLine(text,x,y){ctx.moveTo(0,y);ctx.lineTo(x+1000,y);ctx.stroke();baselines.forEach((baseline,index)=>{constnewX=x+step*2*index;ctx.textBaseline="alphabetic";ctx.fillText(baseline,newX,y-step);ctx.textBaseline=baseline;ctx.fillText(text,newX,y);});}functiondrawTextWithTip(text){ctx.textBaseline="alphabetic";ctx.fillText(text,x,y);}}
result
file
This is is the result PDF and font file: all-file.zip
See the result, the width is basically the same, but the height is very different(skia-canvas is 32 and node-cnavas is 26.67, web-canvas is 27). Is this caused by different calculation algorithms for font metrics? The difference in metrics between node-canvas and web-canvas is even smaller.
The text was updated successfully, but these errors were encountered:
When set different baseline, the rendering positions are different to node-canvas.
Code
Click to show the code
result
file
This is is the result PDF and font file: all-file.zip
Question
node-cnavas
, maybe this is a issue like as TextMetrics & rendered text changed from v1.0.2 to v^2.0.0 #208height
very different, I usemeasureText
api, the result is this:And In chrome, metrics is:
See the result, the width is basically the same, but the height is very different(
skia-canvas
is32
andnode-cnavas
is26.67
,web-canvas
is27
). Is this caused by different calculation algorithms for font metrics? The difference in metrics betweennode-canvas
andweb-canvas
is even smaller.The text was updated successfully, but these errors were encountered: