6

Here is a Jsfiddle demo

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<svg width="100%" height="100%" viewBox="0 0 1000 300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <defs>
        <path id="MyPath" d="M 100 200 
             C 200 100 300   0 400 100
             C 500 200 600 300 700 200
             C 800 100 900 100 900 100" />
    </defs>
    <use xlink:href="#MyPath" fill="none" stroke="red" />
    <text class="material-icons">
        <textPath xlink:href="#MyPath">&#xe55d; &#xe55d; &#xe55d; &#xe55d;</textPath>
    </text>
    <!-- Show outline of the viewport using 'rect' element -->
    <rect x="1" y="1" width="998" height="298" fill="none" stroke="black" stroke-width="2" />
</svg>

&#xe55d; is a special character which is displayed as an "arrow".

There is a problem in the demo above: The direction of the arrow in the <textPath> is perpendicular to the <path>, while I need to set its direction to be the same (in parallel) as the path.

Therefore, I need to rotate 90 degree for each character in the text &#xe55d; &#xe55d; &#xe55d; &#xe55d; (not the whole sentence)..

I found this post about rotating characters, but it looks not ideal because it needs to "Encapsule each letter in a element with jQuery". Maybe there is a way to do this easier in SVG?

Does anyone have ideas about how to rotate each character of a word in <textPath> node?

Community
  • 1
  • 1
Hanfei Sun
  • 45,281
  • 39
  • 129
  • 237
  • there was a discussion before http://stackoverflow.com/questions/22736968/is-there-a-way-to-draw-a-rectangle-around-single-letters-on-a-svg-textpath but it is a lot of javascript code – Dickens A S Jun 27 '15 at 17:18

1 Answers1

4

Just add this style="writing-mode: tb; glyph-orientation-vertical: 180;" to text

I hope this is what you wanted :

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<svg width="100%" height="100%" viewBox="0 0 1000 300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <defs>
        <path id="MyPath" d="M 100 200 
             C 200 100 300   0 400 100
             C 500 200 600 300 700 200
             C 800 100 900 100 900 100" />
    </defs>
    <use xlink:href="#MyPath" fill="none" stroke="red" />
    <text class="material-icons" style="writing-mode: tb; glyph-orientation-vertical: 180;">
        <textPath xlink:href="#MyPath">&#xe55d; &#xe55d; &#xe55d; &#xe55d;</textPath>
    </text>
    <!-- Show outline of the viewport using 'rect' element -->
    <rect x="1" y="1" width="998" height="298" fill="none" stroke="black" stroke-width="2" />
</svg>
Siddharth Thevaril
  • 3,722
  • 3
  • 35
  • 71
  • Good answer, was just about to do this myself. I had been looking at the 'rotate' attributes for text/tspans as well, but couldn't seem to get that to work. – Ian Jun 27 '15 at 19:21
  • Really cool! Firefox seems to not support `writing-mode` now: https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode . Hope Firefox(Gecko) will support `writing-mode` in the future. – Hanfei Sun Jun 28 '15 at 03:47
  • It's coming soon to Firefox but with CSS3 syntax, not SVG syntax. – Robert Longson Jun 28 '15 at 06:32