You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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."""functionsvg2png(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"ifisfile(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)
returnnothingendfunctionconvert_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?")
endmap(readdir(dir, join=true)) do filename
ifsplitext(filename)[2]==".svg"svg2png(filename, overwrite, dpi)
endendend# 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 context-fill and context-stroke with black, then you don't need to convert the SVGs into bitmap images.
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.
Opening the SVG in a text editor and doing that search-and-replace does indeed sound quite a lot easier 😅
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!
However, it would fail to preserve the colours of the true SVG, no?
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-place option), and probably many more. As @LaurenzV noted, this is only practical if all of the arrows are the same color.
In my case, the following two replacements (applied to ≈80 files with Eclipse) worked perfectly:
Activity
laurmaedje commentedon Mar 18, 2024
cc: @LaurenzV
LaurenzV commentedon Mar 18, 2024
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.
LaurenzV commentedon Mar 18, 2024
I submitted a path for this upstream: linebender/resvg#725
Thanks for the report! Should probably be fixed by the next release.
wenbin-liu commentedon Apr 18, 2024
Is this bug fixed in resvg? Arrow missing for svg is quite disturbing.
LaurenzV commentedon Apr 18, 2024
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.
wenbin-liu commentedon Apr 18, 2024
OK, thanks. Then we just need to wait for typst to update
deffi commentedon May 21, 2024
It seems like Typst 0.11.1 still uses resvg 0.38.0, which does not yet incorporate the fix.
LaurenzV commentedon May 21, 2024
Yes, indeed, 0.11.1 was just a patch release for some issues, but it didn't include this one.
KronosTheLate commentedon May 27, 2024
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:
LaurenzV commentedon May 27, 2024
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
context-fillandcontext-strokewithblack, then you don't need to convert the SVGs into bitmap images.KronosTheLate commentedon May 27, 2024
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.
LaurenzV commentedon May 27, 2024
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...
deffi commentedon May 27, 2024
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-placeoption), and probably many more. As @LaurenzV noted, this is only practical if all of the arrows are the same color.In my case, the following two replacements (applied to ≈80 files with Eclipse) worked perfectly:
fill:context-stroke→fill:#000000stroke:context-stroke→stroke:noneLaurenzV commentedon Jun 6, 2024
Has been fixed on main.