-
-
Notifications
You must be signed in to change notification settings - Fork 795
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 arrowheads missing since 0.11 #3715
Comments
cc: @LaurenzV |
Interesting. The SVG uses a feature that I only only recently implemented in resvg, but I still can reproduce the bug on main, so looks like there is still some bug. As for why it worked in 0.10, I have no idea, in theory it shouldn't work in either of them... But I will take a look. |
I submitted a path for this upstream: RazrFalcon/resvg#725 Thanks for the report! Should probably be fixed by the next release. |
Is this bug fixed in resvg? Arrow missing for svg is quite disturbing. |
Yes, it's fixed in resvg. Keep in mind that you can work around this though by replacing instances of "context-fill" and "context-stroke" with the color you want in the SVG. |
OK, thanks. Then we just need to wait for typst to update |
It seems like Typst 0.11.1 still uses resvg 0.38.0, which does not yet incorporate the fix. |
Yes, indeed, 0.11.1 was just a patch release for some issues, but it didn't include this one. |
Until then, if you are in a pinch, you can install the Julia programming language, and run the script below. I am currently using it to convert all my svg illustrations to png files for my masters thesis: using Rsvg
using Cairo
"""
svg2png(filename_in, overwrite=false, dpi::Real=300)
Load an SVG file `filename_in`, use Rsvg.jl to render the image
for cairo, then use Cairo.jl to write that image to a PNG file.
"""
function svg2png(filename_in, overwrite=false, dpi::Real=300)
if !isfile(filename_in)
error("The given filename $filename_in returned `false` when passed to `isfile`. Are you sure that the file exists?")
end
filename_in_noext, input_extension = splitext(filename_in)
if input_extension != ".svg"
error("Extension of given filename $filename_in is $filename_in_ext, where \".svg\" was expected. Aborting.")
end
filename_out = filename_in_noext * ".png"
if isfile(filename_out) && !overwrite
error("Output file $filename_out already exists, and the second positional argument `overwrite` is set to false. Aborting.")
end
r = Rsvg.handle_new_from_file(filename_in)
Rsvg.handle_set_dpi(r, float(dpi)) # Conversion to float due to unnecessary contraints on arguments to Rsvg.handle_set_dpi
d = Rsvg.handle_get_dimensions(r)
cs = Cairo.CairoImageSurface(d.width,d.height,Cairo.FORMAT_ARGB32)
c = Cairo.CairoContext(cs)
Rsvg.handle_render_cairo(c,r)
Cairo.write_to_png(cs,filename_out)
return nothing
end
function convert_all_svgs(dir, overwrite=false, dpi::Real=300)
if !isdir(dir)
error("The given directory $dir returned false when passed to `isdir`. Are you sure the directory exists?")
end
map(readdir(dir, join=true)) do filename
if splitext(filename)[2]==".svg"
svg2png(filename, overwrite, dpi)
end
end
end
# With my svg files inside a folder "illustrations", I
# then just run `convert_all_svgs("illustrations", true)` |
I mean, as mentioned above, if all your arrows are in the same color, you could instead just write a script that replaces all instances of |
Opening the SVG in a text editor and doing that search-and-replace does indeed sound quite a lot easier 😅 However, it would fail to preserve the colours of the true SVG, no? Sometimes, in the preview (vscode extension), the arrowheads were indeed filled as black, which was quite visually disruptive. |
Well, no, but if you have a script that converts SVGs into images, it is probably even easier to write a script that reads all SVGs and makes those two replacements, right? 😄 But your choice obviously!
Yeah, that's true. If your arrows have different colors and it's important to preserve them, then I guess rasterizing is the only option for now... |
You may not even need a script – there are tools that can do search and replace across multiple files: Eclipse, VS Code, sed (using the In my case, the following two replacements (applied to ≈80 files with Eclipse) worked perfectly:
|
Description
Since Typst 0.11, some arrow heads in SVG files are no longer rendered.
Example
SVG files (both from Inkscape):
1.svg:
2.svg:
arrows.typ:
When compiled with Typst 0.10:
When compiled with Typst 0.11:
All file as .zip: arrows.zip
Operating system
Windows, Linux
The text was updated successfully, but these errors were encountered: