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

SVG not showing transparency applied to black #4700

Closed
1 task done
TimeTravelPenguin opened this issue Aug 7, 2024 · 3 comments
Closed
1 task done

SVG not showing transparency applied to black #4700

TimeTravelPenguin opened this issue Aug 7, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@TimeTravelPenguin
Copy link

TimeTravelPenguin commented Aug 7, 2024

Description

I am not entirely sure if issue #2546 is the same as this one or not. I have made a demo to showcase the issue.

I have created a simple demonstration. Attached is a plain white square svg, filled white with a black stroke. In Typst, I am replacing the values "#000" and #fff with new colors. To compare, I also print a square with matching fill.

The white square svg: https://github.com/user-attachments/assets/288902cc-2cfc-4fa2-9111-eead8bde20e5)

The demo:

= Square

#for i in (red, green, blue, black) {
  let c = i.transparentize(80%)
  stack(dir: ltr, square(fill: i, width: 1cm), square(fill: c, width: 1cm))
}

= SVG

#let helper(raw, c) = {
  raw.replace("#fff", c.to-hex()).replace("#000", c.to-hex())
}

#for i in (red, green, blue, black) {
  let c = i.transparentize(80%)

  let raw = read("imgs/square.svg")
  let raw_transp = read("imgs/square.svg")

  raw = helper(raw, i)
  raw_transp = helper(raw_transp, c)

  stack(
    dir: ltr,
    image.decode(raw, width: 1cm),
    image.decode(raw_transp, width: 1cm),
  )
}

The result:

CleanShot 2024-08-08 at 02 31 49@2x

As you can see, the final SVG row is completely unchanged.

Reproduction URL

No response

Operating system

macOS

Typst version

  • I am using the latest version of Typst
@TimeTravelPenguin TimeTravelPenguin added the bug Something isn't working label Aug 7, 2024
@EpicEricEE
Copy link
Contributor

Without having tested it, I think this line in your helper function is problematic when c is black with 80% transparency (#00000033):

raw.replace("#fff", c.to-hex()).replace("#000", c.to-hex())

You first replace the #fff in the SVG with #00000033 but then replace the #000 at the start with another #00000033 so you get a resulting color of #0000003300033 which is obviously invalid.

@LaurenzV
Copy link
Sponsor Collaborator

LaurenzV commented Aug 7, 2024

That's the SVG generated for the black one:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/ svg11.dtd">
<svg width="100%" height="100%" viewBox="0 0 512 512" version="1.1" xmlns="http://www.w3.org/ 2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http:// www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke- linejoin:round;stroke-miterlimit:1.5;">
<rect x="30.361" y="30.361" width="451.277" height="451.277" style="fill:#0000003300033;stroke:#00000033;stroke-width:1px;"/> </svg>

That fill doesn't look very correct...

@LaurenzV
Copy link
Sponsor Collaborator

LaurenzV commented Aug 7, 2024

Guess I will close this then, as this is more of a logic bug. It should work fine once you fix that.

@LaurenzV LaurenzV closed this as not planned Won't fix, can't repro, duplicate, stale Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants