Skip to content

Right-aligned text with leading/trailing spaces rendered incorrectly #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kangax opened this issue Oct 1, 2013 · 9 comments
Open

Comments

@kangax
Copy link
Collaborator

kangax commented Oct 1, 2013

Using a simple test like this:

ctx.font = '30px Arial';
ctx.textAlign = 'right';
ctx.strokeRect(100, 100, 100, 100);
ctx.fillText('   foobar', 100, 100);

... I'm getting incorrect rendering in latest node-canvas:

leading_spaces_nodecanvas

compare to the same output in Chrome (and FF):

leading_spaces_chrome

There's a similar problem with trailing spaces.

node-canvas:

trailing_spaces_nodecanvas

Chrome (FF):

trailing_spaces_chrome

@konkissner
Copy link

same for i-text elements with textAlign: center.

this is the canvas rendered in chrome:
bildschirmfoto 2015-09-04 um 15 02 35

this one is generated with node-canvas:
bildschirmfoto 2015-09-04 um 15 02 44

Any ideas or workarounds?

@Joesmi
Copy link

Joesmi commented Feb 8, 2016

Hello, has anything happened on this front? Thanks for letting us know.

@StephanBijzitter
Copy link

+1 We also need a fix for this. @LinusU

@duydodevgithub
Copy link

Version

2.3.6

Steps to reproduce

We seem to have same problem with text position after saving to PNG. Attached is the design and the final PNG.
Here is my environment information:

  • Node 8.11.6
  • Fabric: 2.3.6
  • Node-canvas: 1.6.11

fabricissue

@asturur Any thoughts about this issue? Thank you so much !

@asturur
Copy link
Contributor

asturur commented Jan 18, 2019

when i have time to update to node-canvas 2, i ll swarm over those old fabricjs bugs.

Now we are on 1.6 and that is unsupported. This means that we can't really invest time in research and fixes.

@akinnee
Copy link

akinnee commented Jan 18, 2019

I'm running into an issue like this. Using canvas in the browser my text is centered. Running the same text rendering code but using node-canvas results in seemingly random text alignment.

browser canvas:
screen shot 2019-01-18 at 11 25 47 am
screen shot 2019-01-18 at 11 26 20 am
screen shot 2019-01-18 at 11 26 41 am

node-canvas:
screen shot 2019-01-18 at 11 28 02 am
screen shot 2019-01-18 at 11 28 09 am
screen shot 2019-01-18 at 11 28 17 am
screen shot 2019-01-18 at 11 28 21 am
screen shot 2019-01-18 at 11 28 35 am

And here's my function for rendering my lines of text:

function renderLines({ canvasContext, lines, x, y }) {
  const lineHeight = canvasContext.measureText('M').width * 1.2;
  const startY = y - (lines.length - 1) * lineHeight / 2;
  lines.forEach((line, index) => {
    const lineY = startY + index * lineHeight;
    canvasContext.fillText(line.trim(), x, lineY);
  });
}

I'm using node-canvas 2.3.1.

@andreafalzetti
Copy link

Same issue here. Node.js tex-align is off compared to the browser. Anyone found a solution?

@asturur
Copy link
Contributor

asturur commented Jun 3, 2020

I think we have some text align test in node and they work. What kind of font are you using? If you have a simple index.js that can print the text not correctly aligned, that woulds help. Maybe with a vertical line for reference where the alignemnt should be

@aman-webdev
Copy link

I am facing an issue with top alignment, on browser its okay but on node its adding extra space at the top , happening with all fonts

browser
image
node
image

Some extra space is coming at the top in node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests