SVG file not rendered - svg

I have a trouble opening an SVG file under my machine Linux:
Gave this svg file:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="1000px" height="707px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<path id="MyPath" d="M 599,455 A 244,244 0 0,1 723,578" />
</defs>
<use xlink:href="#MyPath" fill="none" stroke="red" />
<text font-family="Verdana" font-size="42.5" fill="blue" >
<textPath xlink:href="#MyPath">
We go up, then we go down, then up again
</textPath>
</text>
</svg>
If I open it with firefox I can see it, but If I open it with gimp for example, I can see nothing.
What part of that file is creating this issue?

You are saying you see no error, so I don't know if this is right:
If you built GIMP yourself, our are not using the system's GIMP for some
reason, there is a chance the devel-files for the SVG libs
were not present when GIMP was built. If taht is the case, it won't be able to
read the SVG file itself.
You didn't say anything about error, so your might be another issue
(for example, the "Verdana" font might not be available for
GIMP, and it being replaced by a font with no visible glyphs)
In any case, the workaround would be to open the SVG file
in Inkscape, and export it as a raster PNG file for you
to work with it in GIMP>

Related

TextPath not rendered in PDF using Apache FOP

I am using Apache FOP to generate PDFs, some pages require SVGs. For the most part, this works fine until I add the TextPath element. I am using this to get curved text. This SVG works in browsers but not in the PDF. Wikipedia shows Batik (the SVG renderer for Apache FOP) is compatible with TextPath: https://en.wikipedia.org/wiki/Comparison_of_layout_engines_(Scalable_Vector_Graphics). But no luck.
Any help on this would be appreciated. Note: I am intentionally trying to add text instead of a rasterized images as the text is being localized and injected in.
Here is a sample of an svg which can be found here: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/textPath.
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<path id="MyPath" fill="none" stroke="red"
d="M10,90 Q90,90 90,45 Q90,10 50,10 Q10,10 10,40 Q10,70 45,70 Q70,70 75,50" />
<text>
<textPath href="#MyPath"> <!-- works if I remove this line -->
Quick brown fox jumps over the lazy dog.
</textPath> <!-- and this line -->
</text>
</svg>
According to the SVG 1.1 recommendation, xlink:href should be used to reference the path element. See https://www.w3.org/TR/SVG11/text.html#TextPathElement.
The following image displays in the Squiggle GUI (Batik 1.12), Firefox and Chrome.
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<path id="MyPath" fill="none" stroke="red"
d="M10,90 Q90,90 90,45 Q90,10 50,10 Q10,10 10,40 Q10,70 45,70 Q70,70 75,50" />
<text>
<textPath xlink:href="#MyPath">
Quick brown fox jumps over the lazy dog.
</textPath>
</text>
</svg>

Issue with z-order of elements in SVG being rendered incorrectly

I created an SVG image as defined by the code below. The issue I am having is that the SVG image is being rendered incorrectly. The z-order of the elements in my SVG are incorrectly being rendered.
Issue: There are 3x rectangles (color = white), which are above another rectangle (color=red). These 3x rectangles are positioned to have the same y-axis as the red rectangle behind it and have the same height. Despite this positioning/height, there is a "red" border that seems to be visible on the edge of the white rectangle due to the red rectangle in the back. It seems that z-order or stacking order of the elements in the rendered image is not being respected.
Below is a screenshot of the SVG image open in the Inkscape showing the issue. Even after converting the SVG image to PNG, the z-order issue still existing.
After troubleshooting with the position, I noticed the issue randomly disappears depending on the value of the y-axis position, or SVG image size (pixels/width/height). For example, if you change edit the SVG from y="2.5807" to y="2.5", the issue goes however. However, this is a NOT a feasible solution for my issue, but the exact positing and SVG image size properties is are fixed can shouldn't be changed.
Updates
I tried #Robert Longson suggestion of using shape-rendering="crispEdges" on the root SVG. It did NOT solve the issue for my use case. Using his suggestion, it does solve the issue on how the image is rendered in a browser, however the issue is still visible in Inkscape or when SVG is converted to PNG. For my use case, I care about how the SVG is rendered after being converted to PNG.
I just found out shape-rendering="crispEdges does work when SVG is converted to PNG, but its dependent on how the conversion process works. If I use rsvg-convert command in Bash, which is provided by librsvg2-bin, to convert the SVG to PNG, the issue is fixed. However, if I use convert command in Bash, which is provided by ImageMagick, the issue still exist. If open the SVG file in Inkscape and then Export as PNG, then the issue still exist.
<svg baseProfile="full" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink" width="912px" height="1140px" preserveAspectRatio="none" viewBox="0,0,8.0,5.0">
<rect x="0" y="0" width="8.0" height="5.0" fill="white" />
<rect x="0" y="2.5807" width="8.0" height="1.0" fill="red" />
<g transform="translate(2.9275,0)">
<rect x="0" y="2.5807" width="0.5" height="1.0" fill="white" />
<rect x="1.0" y="2.5807" width="1.0" height="1.0" fill="white" />
<rect x="2.5" y="2.5807" width="1.5" height="1.0" fill="white" />
</g>
</svg>
that's antialiasing you can turn it off with shape-rendering="crispEdges"
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="912px" height="1140px" preserveAspectRatio="none" viewBox="0,0,8.0,5.0" shape-rendering="crispEdges">
<rect x="0" y="0" width="8.0" height="5.0" fill="white" />
<rect x="0" y="2.5807" width="8.0" height="1.0" fill="red" />
<g transform="translate(2.9275,0)">
<rect x="0" y="2.5807" width="0.5" height="1.0" fill="white" />
<rect x="1.0" y="2.5807" width="1.0" height="1.0" fill="white" />
<rect x="2.5" y="2.5807" width="1.5" height="1.0" fill="white" />
</g>
</svg>

Bad SVG text quality in Opera

I am trying to render an SVG document containing some text. Everything is good in Chrome/FF/Safari:
But in Opera (v12.14, Mac OS X) font looks very ugly:
Is this normal or maybe I am doing something wrong? Is it possible to improve rendering quality? Here is the code:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="400" height="200" version="1.1" xmlns="http://www.w3.org/2000/svg">
<text x="10" y="30" font-family="Arial" font-size="12" font-weight="bold">123 xyz XYZ</text>
<text x="10" y="50" font-family="Arial" font-size="12" font-weight="bold" fill="#666">123 xyz XYZ</text>
<text x="10" y="70" font-family="Arial" font-size="12" font-weight="normal" fill="#444">123 xyz XYZ</text>
<text x="10" y="88" font-family="Arial" font-size="10" font-weight="normal" fill="#444">123 xyz XYZ</text>
</svg>
I've tried:
embedding fonts using #font-face;
using fonts other than Arial;
setting text-rendering="optimizeLegibility".
None of this helps.
Edit
The solution is to use text-rendering="geometricPrecision" (see Erik Dahlström's answer):
The result is still worse than in other browsers, but it seems that for now it is the best that one can get in Opera for Mac OS.
I've also tried to translate the content by 0.5px in both directions. It slightly changes the output, but doesn't improve the quality in general.
Looks like subpixel text rendering is disabled for text inside SVG on Mac.
A workaround is to specify text-rendering="geometricPrecision". That makes Opera use glyph outlines for rendering instead of deferring the text rendering to the platform. However, note that this typically tends to be slightly less performant. Also note that using geometricPrecision doesn't enable subpixel text rendering in Opera, but the text will usually look a little different (usually a slight blur depending on the pixel grid alignment).

SVG Font Rendering Problems while rendering Text on a Path in Chrome and Safari

I try to render some text along a bezier curve path in SVG:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<path id='menu_path' d="M 80,40 Q 200,85 245,205" stroke="none" fill="none"/>
<text fill="white">
<textPath xlink:href="#menu_path">News Info Presse Musik</textPath>
</text>
</svg>
In Firefox this works fine, but in Chrome and Safari, the text looks ugly (look at "Musik"). Even when I use monospace fonts and set the text to uppercase it does not change.
Here the Screenshots:
http://imageshack.us/a/img18/3195/svgrendering.png
http://imageshack.us/a/img705/7334/svgrenderingwithpath.png
Does somebody have an idea on how to avoid this?
I created a jsfiddle which shows the problem:
http://jsfiddle.net/v6esx/
Thank you!

inkscape to convert svg -> png: pagesize?

I need to convert svg to png at the command-line. I tried using imagemagick but it seems to have a bug when used with rotate transforms, e.g. this sample s3.svg:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg">
<g id="layer1">
<circle cx="200" cy="200" r="200" stroke="black"
stroke-width="0.5" fill="none"/>
<g transform="rotate(48 200 200)">
<path id="path00" style="fill:#dca08c;stroke:#000000;stroke-width:1"
d="M 200,0 L 400,200 L 200,400 L 0,200 z"/>
</g>
</g>
</svg>
I was able to use inkscape at the command-line:
c:\app\inkscape\portable\App\Inkscape\inkscape.com -f s3.svg -e s3.png --export-background=white --export-area=0:652:400:1052
but SVG coordinates (0,0) are defined at the upper left whereas in inkscape's export the export area is (0,0) defined at the lower left.
How can I use inkscape to export without the magic number 1052 that defines the page height?
One way that might help is to draw an area you want as a container, give it an id, and export that with the -i id option. Give the wrapper blank background/border if it shouldn't be visible.
Edit (adding example):
I used this xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg">
<g id="layer1">
<rect width="400" height="600" id="wrapper" fill="none"></rect>
<circle cx="200" cy="200" r="200" stroke="black"
stroke-width="0.5" fill="none"/>
<g transform="rotate(48 200 200)">
<path id="path00" style="fill:#dca08c;stroke:#000000;stroke-width:1"
d="M 200,0 L 400,200 L 200,400 L 0,200 z"/>
</g>
</g>
</svg>
And with this command (I'm on a mac, so translate specific OS as needed) I could control the size/position of the output png:
/Applications/Inkscape.app/Contents/Resources/bin/inkscape -f test.svg -e out.png -i wrapper
I'm not an svg expert so I'm not sure if there are some specific things inkscape does, but I've always found it very web compliant. In the past I've used its svg files directly in web pages.
It seems what you are trying to export is the whole drawing.
inkscape has the option to export the drawing with --export-area-drawing instead of specifying the area to export.
c:\app\inkscape\portable\App\Inkscape\inkscape.com -f s3.svg -e s3.png --export-background=white --export-area-drawing
If the problem is not knowing the page height then the following syntax might help?
c:\app\inkscape\portable\App\Inkscape\inkscape.com s3.svg -z --query-height
This should return the pixel height of the document, you can use the returned number in your export call.
Inkscape has canvas size option, I had the same problem exporting for the web - your image drops out of the viewport.
Change canvas/artboard size to meet the size of element you are exporting

Resources