Why isn't my text path on this circle rendering? - svg
I'm going crosseyed trying to figure out why my text isn't showing up. Before I asked this, I had not seen it working in Firefox as it apparently does now.
<svg style="background-color: white" viewBox="-150 -150 300 300" width="300" height="300">
<circle id="circ0-0" cx="0" cy="0" r="121" stroke="#58595B" stroke-width="3" fill="transparent" style="transform: rotate(90deg)">
</circle>
<text class="donutText" dy="0">
<textPath startOffset="50%" xlink:href="#circ0-0" style="text-anchor: start;">Test test test.</textPath>
</text>
</svg>
Can this be accomplished in all browsers?
It appears that textPaths don't work on circles in all browsers. Only on actual paths, like:
<svg style="background-color: white" viewBox="-150 -150 300 300" width="300" height="300">
<path id="circ0-0" d="M 0 0 m -121, 0 a 121,121 0 1,0 242,0 a 121,121 0 1,0 -242,0" stroke="black" stroke-width="3" fill="white" style="transform: rotate(180deg)">
</path>
<text class="donutText" dy="0">
<textPath startOffset="50" xlink:href="#circ0-0" style="text-anchor: middle;">Test test test.</textPath>
</text>
</svg>
use defs (copy path like circle)
Ok I fix my answer and I use defs to define another path that like circle, it is really easy to change the path-"circle" radius (by for examle the all 125 to 100 and the 250 to 200)
So, it is like use the path only.. but there is advantage to use circle and the path in defs
BTW you can change the start of path by change dx="0"
<svg style="background-color: white" viewBox="-150 -150 300 300" width="300" height="300">
<g>
<defs>
<path d="M 0 0 m -125 0 a 125 125 0 1 0 250 0 a 125 125 0 1 0 -250 0" id="path-circle" />
</defs>
<circle stroke="#58595B" stroke-width="3" fill="transparent" cx="0" cy="0" r="128"/>
<text dx="0">
<textPath xlink:href="#path-circle">Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test</textPath>
</text>
</g>
</svg>
Update by comment
I find that this way is depends on what you need, and only path can be really good solution!
The advantages for use defs (path) are:
The path circle not always accurate - the green circle (path actually), so if we want to display the circle then rather to use circle and for text the path in defs.
When we want the text be written in concave/convex we need to use path, and the path don't always is circle. (that is when you want to display circle but for text use other shape)
For me it is more readable, like if I see that code I understand that there is a circle, and text go on path shape, In contrast to see path and text.. no clear that the path is circle.
<svg style="background-color: white" viewBox="-150 -150 300 300" width="300" height="300">
<g>
<!-- <defs>
<path d="M 0 0 m -125 0 a 125 125 0 1 0 250 0 a 125 125 0 1 0 -250 0" id="path-circle" />
</defs> -->
<!-- <circle stroke="#58595B" stroke-width="3" fill="transparent" cx="0" cy="0" r="128"/> -->
<path stroke="#58595B" stroke-width="3" fill="transparent" d="M 0 0 m -125 0 a 125 125 0 1 0 250 0 a 125 125 0 1 0 -250 0" id="path-circle" />
<path stroke="green" stroke-width="3" fill="transparent"
d="M0,-62c34,0,63,28,62,62s-28,62-62,62s-62-28-62-62S-34,-62,0,-62z" id="path-circle2"
transform="rotate(-45)"/>
<circle stroke="blue" stroke-width="3" fill="transparent" cx="0" cy="0" r="50"/>
<text dx="0" dy="-4">
<textPath xlink:href="#path-circle">Test test test Test test test Test test test Test test test Test test test Test test test Test test test Test test test</textPath>
</text>
<text dx="0" dy="-4">
<textPath xlink:href="#path-circle2">Test2 test2 test2</textPath>
</text>
</g>
</svg>
Related
How to draw letter R with SVG
I have a svg of letter B here is the code: <svg id="logo" xmlns="http://www.w3.org/2000/svg" role="img" viewBox="0 0 84 96"> <title>Logo</title> <g transform="translate(-8.000000, -2.000000)"> <g transform="translate(11.000000, 5.000000)"> <path d="M45.691667,45.15 C48.591667,46.1 50.691667,48.95 50.691667,52.2 C50.691667,57.95 46.691667,61 40.291667,61 L28.541667,61 L28.541667,30.3 L39.291667,30.3 C45.691667,30.3 49.691667,33.15 49.691667,38.65 C49.691667,41.95 47.941667,44.35 45.691667,45.15 Z M33.591667,43.2 L39.241667,43.2 C42.791667,43.2 44.691667,41.85 44.691667,38.95 C44.691667,36.05 42.791667,34.8 39.241667,34.8 L33.591667,34.8 L33.591667,43.2 Z M33.591667,47.5 L33.591667,56.5 L40.191667,56.5 C43.691667,56.5 45.591667,54.75 45.591667,52 C45.591667,49.2 43.691667,47.5 40.191667,47.5 L33.591667,47.5 Z" fill="currentColor" /> <polygon id="Shape" stroke="currentColor" strokeWidth="5" strokeLinecap="round" strokeLinejoin="round" points="39 0 0 22 0 67 39 90 78 68 78 23" /> </g> </g> </svg> And here is how it looks I just need to change letter B to letter R but i don't know the path and it should be centered in polygon
As I've commented: delete the path and add: <text x="39" y="45" dominant-baseline="middle" text-anchor="middle" font-size="30">R</text> where x="39" y="45" are the coords of the center of the hexagon. Please observe that the text is centered around this point (<text x="39" y="45" dominant-baseline="middle" text-anchor="middle") svg{width:90vh} <svg id="logo" xmlns="http://www.w3.org/2000/svg" role="img" viewBox="0 0 84 96"> <title>Logo</title> <g transform="translate(-8.000000, -2.000000)"> <g transform="translate(11.000000, 5.000000)"> <polygon id="Shape" stroke="currentColor" strokeWidth="5" strokeLinecap="round" strokeLinejoin="round" points="39 0 0 22 0 67 39 90 78 68 78 23" fill="none" /> <text x="39" y="45" dominant-baseline="middle" text-anchor="middle" font-size="30">R</text> </g> </g> </svg>
If you don't plan going down the rabit hole of SVG's, try to use a SVG builder, should be faster as easier to visualise. Examples: https://vectorpaint.yaks.co.nz/ https://editor.method.ac/ After you finish you can download and use the svg file or open the file in your editor to see the code
Invert textPath letter from up to down along a path without redraw?
I want to reverse the word compared to the line without having to redraw the line, how to do? /Ps: when I use transform="scale(-1,1)" it doesn't work because the line path is inverted.
You could use <textPath side="..."> for that. However, it's only supported by Firefox right now. <svg viewBox="0 0 100 55" xmlns="http://www.w3.org/2000/svg"> <path id="curve" fill="none" stroke="limegreen" stroke-width="1" d="M10,5 c20,60 50,50 80,10"></path> <text font-size="5" dy="-1"> <textPath href="#curve" startOffset="6" side="left">Dangerous curves ahead</textPath> </text> <text font-size="5" dy="-1"> <textPath href="#curve" startOffset="9" side="right">Dangerous curves ahead</textPath> </text> </svg>
If this is what you have: body{background:white;} <svg width="250" height="200" viewBox="0 0 250 200"> <defs> <path id="thePath" d="M55,100 a70,40 0 1 0 0,-1 z" stroke="#FF0000" fill="transparent" stroke-width="1" ></path> </defs> <use xlink:href="#thePath"></use> <text stroke="#000000" font-size="20"> <textPath xlink:href="#thePath" startOffset="7%"> Some text here </textPath> </text> </svg> You can apply a transformation transform="scale(-1,1) translate(-250,0)" to the path like so: body{background:white;} <svg width="250" height="200" viewBox="0 0 250 200"> <defs> <path id="thePath" d="M55,100 a70,40 0 1 0 0,-1 z" stroke="#FF0000" fill="transparent" stroke-width="1" transform="scale(-1,1) translate(-250,0)"></path> </defs> <use xlink:href="#thePath"></use> <text stroke="#000000" font-size="20"> <textPath xlink:href="#thePath" startOffset="7%"> Some text here </textPath> </text> </svg> I hope this is what you need
svg: can anyone help me to draw an arc?
I'm trying to draw an arc with SVG but I'm stucked. The goal is to get a figure like this: what I get instead is this: Those are the SVG tags I'm playing with: <svg width='500' height='500' xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink' > <g style='transform-origin:center;'> <path d="M 100 50 a 50,50 0 0 0 100,0" stroke="black" fill="red" stroke-width="2" /> </g> </svg> Can anybody help me to understan what's wrong on my node?
<svg width='500' height='500' xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink' > <g style='transform-origin:center;'> <!-- <path d="M 100 50 a 50,50 0 0 0 100,0" stroke="black" fill="red" stroke-width="2" /> --> <path d="M 50 50 a 50,50 270 1 0 25,15" stroke="black" fill="red" stroke-width="2" /> <path d="M 150 150 a 50,50 270 0 0 125,115" stroke="black" fill="red" stroke-width="2" /> </g> </svg> your problem is the large-arc-flag, set it to 1 MDN Reference
How to start svg pattern from begin for two elements separately and how to setup right coordinate system?
I have two thick lines and I want to apply pattern for this lines. Lines should have the same pattern, but start of drawing pattern should start from (0, 0) for each line separately. In my experiment http://jsfiddle.net/69t09wey/ patterns apply like mask. I.e pattern apply for whole svg canvas as invisible layer and where line is visible, pattern also visible. <svg viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg" version="1.1"> <pattern id="pattern-1" width="20" height="20" x="0" y="0" patternUnits = "userSpaceOnUse" > <path d="M 0 0 L 20 20" fill="none" stroke="#0000ff" stroke-width="1"></path> </pattern> <g transform="scale(5)"> <rect x="1" y="1" width="1000" height="1000" fill="none" stroke="blue" /> <path d="M 1 9 L 200 9" fill="red" stroke="url(#pattern-1)" stroke-width="20" /> <path d="M 1 53 L 200 53" fill="red" stroke="url(#pattern-1)" stroke-width="20" /> </g> </svg>
If you make your lines the same. Then move the second one by applying a transform. That will shift the coordinate space of the pattern. <svg viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg" version="1.1"> <pattern id="pattern-1" width="20" height="20" x="0" y="0" patternUnits = "userSpaceOnUse" > <path d="M 0 0 L 20 20" fill="none" stroke="#0000ff" stroke-width="1"></path> </pattern> <g transform="scale(5)"> <rect x="1" y="1" width="1000" height="1000" fill="none" stroke="none" /> <path d="M 1 9 L 200 9" fill="red" stroke="url(#pattern-1)" stroke-width="20" /> <path d="M 1 9 L 200 9" transform="translate(0,44)" fill="red" stroke="url(#pattern-1)" stroke-width="20" /> </g> </svg>
Some elements not visible in browser in svg image
I have svg file exported from flash, I can open that file in Inkscape and I see clouds and a girl. In browsers the girl is visible but the clouds not. In svg they are the same symbol in defs with two groups, and a use element with xlink:href The cloud that are not visible look like this: <defs transform="matrix(1 0 0 1 0 0) "> <symbol id="Symbol__202" viewBox="0 0 94.9 52.4"> <g id="Warstwa.__202"> <g id="group1"> <path id="path27" fill="#FFFFFF" fill-opacity="1" d="M440.5,18.3 Q440.5,15 438.1,12.6 C436.55,11.05 434.7,10.3 432.5,10.3 430.25,10.3 428.35,11.05 426.75,12.6 426.15,13.25 425.65,14 425.25,14.8 425.2,11.1 423.85,7.95 421.25,5.35 418.6,2.7 415.35,1.35 411.5,1.35 407.75,1.35 404.55,2.7 401.9,5.35 400.35,6.9 399.3,8.6 398.65,10.45 397.3,9.6 395.75,9.2 394.05,9.2 392.6,9.2 391.25,9.5 390.05,10.15 389.9,7.8 388.95,5.8 387.3,4.1 385.5,2.25 383.3,1.35 380.7,1.35 378.15,1.35 375.9,2.25 374.05,4.1 372.8,5.4 371.95,6.85 371.55,8.5 368.95,6.85 366,6.05 362.7,6.05 358,6.05 353.95,7.7 350.6,11.05 347.25,14.45 345.6,18.5 345.6,23.25 345.6,27.95 347.25,32 350.6,35.45 353.95,38.8 358,40.45 362.7,40.45 366.9,40.45 370.55,39.1 373.7,36.45 372.1,38.4 371.3,40.65 371.3,43.2 371.3,46.1 372.3,48.55 374.35,50.6 376.5,52.7 379,53.75 381.85,53.75 384.75,53.75 387.25,52.7 389.35,50.6 391.4,48.55 392.45,46.1 392.45,43.2 392.45,42.65 392.4,42.2 392.35,41.75 393.3,41.3 394.25,40.7 395.15,40.05 395.7,42.65 397.05,44.95 399.1,47 402,49.9 405.5,51.35 409.55,51.35 413.65,51.35 417.15,49.9 420.05,47 421.05,46.05 421.85,45 422.5,43.85 423.65,44.25 424.85,44.45 426.1,44.45 429.1,44.45 431.65,43.35 433.75,41.2 435.9,39.1 437,36.55 437,33.55 437,30.7 436,28.25 434,26.15 435.55,25.85 436.9,25.1 438.1,23.95 439.7,22.4 440.5,20.55 440.5,18.3z M385.45,18.8 L385.45,18.9 385.35,18.9 385.45,18.8z M375.5,34.75 C375.7,34.45 375.9,34.2 376.15,34 376.2,34.05 376.25,34.1 376.25,34.25 376,34.4 375.75,34.6 375.5,34.75z"/> <path id="path28" fill="none" stroke="#CCCCCC" stroke-opacity="1" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" d="M440.5,18.3 Q440.5,15 438.1,12.6 C436.55,11.05 434.7,10.3 432.5,10.3 430.25,10.3 428.35,11.05 426.75,12.6 426.15,13.25 425.65,14 425.25,14.8 425.2,11.1 423.85,7.95 421.25,5.35 418.6,2.7 415.35,1.35 411.5,1.35 407.75,1.35 404.55,2.7 401.9,5.35 400.35,6.9 399.3,8.6 398.65,10.45 397.3,9.6 395.75,9.2 394.05,9.2 392.6,9.2 391.25,9.5 390.05,10.15 389.9,7.8 388.95,5.8 387.3,4.1 385.5,2.25 383.3,1.35 380.7,1.35 378.15,1.35 375.9,2.25 374.05,4.1 372.8,5.4 371.95,6.85 371.55,8.5 368.95,6.85 366,6.05 362.7,6.05 358,6.05 353.95,7.7 350.6,11.05 347.25,14.45 345.6,18.5 345.6,23.25 345.6,27.95 347.25,32 350.6,35.45 353.95,38.8 358,40.45 362.7,40.45 366.9,40.45 370.55,39.1 373.7,36.45 372.1,38.4 371.3,40.65 371.3,43.2 371.3,46.1 372.3,48.55 374.35,50.6 376.5,52.7 379,53.75 381.85,53.75 384.75,53.75 387.25,52.7 389.35,50.6 391.4,48.55 392.45,46.1 392.45,43.2 392.45,42.65 392.4,42.2 392.35,41.75 393.3,41.3 394.25,40.7 395.15,40.05 395.7,42.65 397.05,44.95 399.1,47 402,49.9 405.5,51.35 409.55,51.35 413.65,51.35 417.15,49.9 420.05,47 421.05,46.05 421.85,45 422.5,43.85 423.65,44.25 424.85,44.45 426.1,44.45 429.1,44.45 431.65,43.35 433.75,41.2 435.9,39.1 437,36.55 437,33.55 437,30.7 436,28.25 434,26.15 435.55,25.85 436.9,25.1 438.1,23.95 439.7,22.4 440.5,20.55 440.5,18.3z"/> <path id="path30" fill="none" stroke="#CCCCCC" stroke-opacity="1" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" d="M385.45,18.8 L385.35,18.9 385.45,18.9 385.45,18.8z"/> <path id="path35" fill="none" stroke="#CCCCCC" stroke-opacity="1" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" d="M375.5,34.75 C375.75,34.6 376,34.4 376.25,34.25 376.25,34.1 376.2,34.05 376.15,34 375.9,34.2 375.7,34.45 375.5,34.75z"/> </g> </g> </symbol> </defs> ... <use xlink:href="#Symbol__202" id="Symbol.__203" width="94.9" height="52.4" x="0" y="0" transform="matrix(1 0 0 1 813.15 14.5)" overflow="visible"/> and is the same as a girl <use xlink:href="#dziewczynka" id="dziewczynka1" width="80.1" height="187.8" x="-40.05" y="-93.9" transform="matrix(1 0 0 1 50 200)" overflow="visible"/> I tried to remove the dot from ID in the cloud but it didn't change anything. Why the clouds are not visible in the browser?