Skip to content
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

bbox() returns zeros for text elems? #104

Open
matehegedus opened this issue May 9, 2023 · 2 comments
Open

bbox() returns zeros for text elems? #104

matehegedus opened this issue May 9, 2023 · 2 comments

Comments

@matehegedus
Copy link

Hi,

I have the following problem, when I am using bbox()-es for some calculations, in my node.js environment it returns only zeros (although in web it works well)

this is my minimal reproduction:

 config.setFontDir("src/fonts/Roboto");
  config.setFontFamilyMappings({
    Roboto: "Roboto-Black.ttf",
    "sans-serif": "Roboto-Black.ttf",
    "Roboto-Bold": "Roboto-Bold.ttf",
  });
  config.preloadFonts();
  const window = createSVGWindow();
  const { document } = window;
  registerWindow(window, document);
  const draw = SVG(document.documentElement);

  draw.attr({
    width: 200,
    height: 200,
  });

  const group = draw.group().id(`txtGroup-example`);
  const textELem = group
    .text("label")
    .fill("red")
    .attr({
      x: 50,
      y: 50,
      "text-anchor": "middle",
      "dominant-baseline": "auto",
      transform: `rotate(${90},${50},${50})`,
      "font-size": `${16}px`,
      "font-family": `Roboto`,
    });

  const bbox = textELem.bbox();
  console.log("group :>> ", bbox); //every element inside bbox will be zero

Am I doing something wrong ?

Thanks

@matehegedus
Copy link
Author

My bad, I was using 'font-size: 16px', although it should be only '16'. This caused the issue in node.js

@Fuzzyma
Copy link
Member

Fuzzyma commented May 9, 2023

Glad you figured it out. That would have taken me ages to realize :D

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

No branches or pull requests

2 participants