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

extra 1px @ bottom and/or left within code128 [toSVG] #330

Open
xerc opened this issue Mar 16, 2024 · 6 comments
Open

extra 1px @ bottom and/or left within code128 [toSVG] #330

xerc opened this issue Mar 16, 2024 · 6 comments

Comments

@xerc
Copy link

xerc commented Mar 16, 2024

let svg = bwipjs.toSVG(
{
  bcid:  'code128',
  text:  '1ZXXXXXXXXXXXXXXXX',
  scale:   2,
  height: 19,
  backgroundcolor: '#ff0000'
})

Bildschirmfoto 2024-03-16 um 04 45 39

@xerc
Copy link
Author

xerc commented Mar 16, 2024

.replace(/(?<=viewBox=")(0) (0) ([0-9]+) ([0-9]+)(?=")/,
  (match, p1, p2, p3, p4) => {return (++p1)+' '+(p2)+' '+(--p3)+' '+(--p4)})

@xerc xerc changed the title 1px extra height @ code128 1px extra height @ code128 [toSVG] Mar 16, 2024
@xerc xerc changed the title 1px extra height @ code128 [toSVG] extra 1px @ bottom and/or left within code128 [toSVG] Mar 16, 2024
@xerc xerc closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2024
@metafloor
Copy link
Owner

This was a legitimate issue - not sure why you closed it. Although the issue was not the viewBox sizing - some of the SVG drawing primitives were off by one compared to the built-in drawing. Also the text layout had several issues. v4.3.1 provides the fixes.

Manually comparing the images produced by the built-in canvas render vs SVG using the project's demo.html, there is now no perceptible difference.

@xerc xerc reopened this Mar 17, 2024
@xerc xerc closed this as completed Mar 17, 2024
@xerc xerc reopened this Mar 17, 2024
@xerc
Copy link
Author

xerc commented Mar 17, 2024

might this also be an issue? scale:5 => fine @ scale:10
Bildschirmfoto 2024-03-17 um 18 15 11
top SVG & CANVAS bottom (right corner)

@metafloor
Copy link
Owner

metafloor commented Mar 18, 2024

Found the root of this issue. It is the combination of scale factor and stroke width. The svg drawing adjusts coordinates by 0.5px when stroke width is odd, which gives crisp lines by avoiding anti-aliasing. But apparently, it needs to subtract 0.5 when scale is odd, and add 0.5 when scale is even. I will have a release for this later today or tomorrow.

@xerc
Copy link
Author

xerc commented Mar 18, 2024

idea/ theoretical for SVG 1px can be 1px cause scaling can happen later => ignore scale and maybee even width

@xerc
Copy link
Author

xerc commented Mar 23, 2024

@ 4.3.2 ; SVG with BG red

& un-even px width
Bildschirmfoto 2024-03-23 um 11 22 10
& even px width => looks alomst perfect
Bildschirmfoto 2024-03-23 um 12 19 54

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