SVG/Inkscape - "Failed to load the requested file" - html

Hopefully someone out there knows about SVG files. I'm just running through a Mozilla tutorial about SVG graphics and one of the exercises is reviewing this code:
<?xml version="1.0" standalone="no"?>
<svg width="200" height="280" xmlns="http://www/w3.org/2000/svg" version="1.1">
<polyline points="40 60 80 20 120 60" stroke="black" stroke-width="20"
stroke-linecap="butt" fill="none" stroke-linejoin="miter"/>
<polyline points="40 160 80 120 120 160" stroke="black" stroke-width="20"
stroke-linecap="round" fill="none" stroke-linejoin="round"/>
<polyline points="40 260 80 220 120 260" stroke="black" stroke-width="20"
stroke-linecap="square" fill="none" stroke-linejoin="bevel"/>
</svg>
It's supposed to create a graphic of three angles pointing upward.
I have 8 other SVG files which convert to Inkscape without any problem. But the graphic from the code above will not convert over to Inkscape, and Inkscape gives me this error: "Failed to load the requested file"
Is there something I'm missing? I've tried to change all the parameters in the code thinking maybe the graphic is too big but it still doesn't work.

Well, I answered my own question. I converted the SVG file to an HTML, and I opened the file in my browser and the graphic is displayed!

Related

Last Alphabet of SVG text is cutting in Firefox

I have this Simple SVG with text inside, on chrome and Safari its working fine, but on FIREFOX the last alphabet of the text is not showing at all. (in this case 'l' from 'atul' is not showing on firefox.)
<svg viewBox="0 0 100 100" height="250" width="250">
<path id="p1" d="M50 10 a 40 40 1 1 0 1 0" pathLength="1.99" style="fill: red;"></path>
<text font-size="6" text-anchor="middle">
<textPath href="#p1" startOffset="1" side="center" style="letter-spacing:1px;font-weight:600;text-transform:uppercase; dominant-baseline: ideographic;">Atul</textPath>
</text>
</svg>
just copy and paste this svg in your HTML and try to render it in Firefox.
I want to understand the problem along with solution if anyone can explain please.
Thanks in advance.
The issue is that there's trailing whitespace after the </textPath> Firefox stops the textPath processing one character too soon when it encounters that whitespace.
This is fixed in bug 1809688. It's currently scheduled to be fixed in Firefox 111, but you can try it in a nightly already.
I'm not able to explain this, but here I have three different SVG elements. The first two are modified versions of the code that I copied from your snippet. They both have the issue. And the last one is an edited version of the example on MDN. So, example 2 and 3 are how I would write the code -- using SVG attributes for most of the styling, but most importantly the pathLength should have a larger value to avoid any rendering problems.
Even though I removed all the attributes and styling possible from example 1 it still has the issue. And as I see it example 2 and 3 are exactly the same code (except from the ids referring to the paths), so I'm not able to explain the difference.
If anyone can spots the difference please comment.
Well, try to rewrite your code... 🙂
<svg viewBox="0 0 100 100" width="200" height="200">
<path id="p1" fill="none" d="M50 10 a 40 40 1 1 0 1 0 z"/>
<text>
<textPath href="#p1">Atul</textPath>
</text>
</svg>
<svg viewBox="0 0 100 100" width="200" height="200">
<path id="p2" fill="red" d="M50 10 a 40 40 1 1 0 1 0 z"
pathLength="100"/>
<text font-size="6" font-weight="600" text-anchor="middle"
dominant-baseline="ideographic"
style="text-transform: uppercase;letter-spacing:1px;">
<textPath href="#p2" startOffset="50">Atul</textPath>
</text>
</svg>
<svg viewBox="0 0 100 100" width="200" height="200">
<path id="p3" fill="red" d="M50 10 a 40 40 1 1 0 1 0 z"
pathLength="100"/>
<text font-size="6" font-weight="600" text-anchor="middle"
dominant-baseline="ideographic"
style="text-transform: uppercase;letter-spacing:1px;">
<textPath href="#p3" startOffset="50">Atul</textPath>
</text>
</svg>

Embed SVG image in HTML and keep text as text

Consider an SVG image with text. Is it possible to embed it into an HTML document using an image tag (or any other) and keep the text as text, so it can be selected or searched for e.g. using "control+find"?
A plain image tag does not achieve this:
<image src="https://www.w3.org/TR/SVG11/images/text/toap04.svg"></image>
You have a couple of options when embedding an SVG with selectable text.
Inline SVG
You can embed an inline SVG in an HTML document using the <svg> tag.
<svg width="453px" height="136px" viewBox="0 0 1000 300">
<defs>
<path id="MyPath" d="M 100 125
C 150 125 250 175 300 175
C 350 175 450 125 500 125
C 550 125 650 175 700 175
C 750 175 850 125 900 125" />
</defs>
<use xlink:href="#MyPath" fill="none" stroke="red" />
<text font-family="Verdana" font-size="60" fill="blue" letter-spacing="2">
<textPath xlink:href="#MyPath">
Choose shame or get war
</textPath>
</text>
<rect x="1" y="1" width="998" height="298" fill="none" stroke="blue" stroke-width="2" />
</svg>
<object> tag
You can also use the <object> tag when linking to an external SVG.
<object data="https://www.w3.org/TR/SVG11/images/text/toap04.svg" width="453" height="136"></object>
You can load any external file, and inline it, with the <load-file> (native javascript) Web Component.
Loads of options, unlicensed and only 8 lines of code:
Dev.To blog post <load-file> Web Component
<script src="https://load-file.github.io/element.js"></script>
<load-file replaceWith src="https://www.w3.org/TR/SVG11/images/text/toap04.svg"></load-file>
<style>
svg{ background:lightgreen }
rect { stroke:green; stroke-width:60; rx:60 }
</style>

Why doesn't this SVG display?

I'm working on a project that uses svg. I generate this svg code thanks to an ocaml library:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:l="http://www.w3.org/1999/xlink" version="1.1" width="161.8mm" height="100mm" viewBox="0 0 161.8 100" color-profile="auto" color-interpolation="linearRGB" color-interpolation-filters="linearRGB">
<g fill="none" stroke-miterlimit="9.98123" transform="matrix(100 0 0 -100 -0 100)">
<defs>
<path id="i1" d="M0 0L1.618 0L1.618 1L0 1Z"/>
</defs>
<use l:href="#i1" fill="#50C878"/>
</g>
</svg>
When I use gthumb or GIMP to display the svg, it prints the correct green square. However, when I include this block of code in Chromium or Firefox, the block appears in the html tree but nothing is display. This is the first time I use svg: after several researches on Google, I can't find anything....
Does someone know why it doesn't work ?
Edit
Solve with the answer:
<use xlink:href="#i1">

Does SVG path element support a lifting of the pen?

In SVG there are different commands used such as move pen, draw line, draw curve and so on like so:
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
<path d="M10 10 H 90 V 90 H 10 L 10 10"/>
</svg>
Is there a command that lifts the pen and then sets the pen down again? As an example, is there a single value of SVG path data that would draw parallel lines that do not intersect inside a single path element?
More info on SVG on MDN.
Thanks to #RobertLongson for pointing this out.
I can use move more than once. In this case it is in the middle of the statement.
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
<path d="M10 10 H 90 M 10 90 H 90" stroke="red"
stroke-width="3" fill="none"/>
</svg>

Adjacent lines inside svg path with stroke-width

I have a svg with multiple lines inside a path.
<path stroke-width="13" stroke="black" fill="orange" d="M 100 100 L 300 100 Z L200 300 z"/>
Because of the stroke-width the lines intersect
Is there any way of making the path continuous without altering the "d" attribute?
Edit:
I am interested in how you can control the joins of multiple objects inside the same path while having a stroke-width defined.
If I would change the "d" attribute and remove the middle Z so that the lines form a triangle the stroke problem would disappear
That's one hell of an overhang for two lines that meet at a point. (Are you using Firefox by any chance? I saw something very similar recently.)
If you want a neat join between two disjoint line segments, your best bet would be to draw them with rounded end caps by adding stroke-linejoin="round" and stroke-linecap="round" to the path element.
And if my suspicion is correct, you can fix the overhang problem by changing fill="orange" to fill="none". Try this:
<svg viewBox="50 50 400 400" width="350" height="350">
<path stroke-width="13"
stroke="black"
fill="none"
stroke-linejoin="round"
stroke-linecap="round"
d="M 100 100 L 300 100 Z L200 300 z"
/>
</svg>