Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can query the computed lengths of the string that should go on the path, and the length of the path. Then compare the two, if the string length is longer than the path length then text will fall off the path.</p> <p>You can also use the knowledge of the path length to squeeze the string to fit, like this:</p> <pre><code>&lt;svg viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"&gt; &lt;defs&gt; &lt;path id="s3" d="M 10,90 Q 100,15 200,70 "/&gt; &lt;/defs&gt; &lt;g&gt; &lt;text font-size="20"&gt; &lt;textPath xlink:href="#s3" textLength="204" lengthAdjust="spacingAndGlyphs"&gt; The quick brown fox jumps over the lazy dog &lt;/textPath&gt; &lt;/text&gt; &lt;use x="0" y="0" xlink:href="#s3" stroke="black" fill="none"/&gt; &lt;/g&gt; &lt;/svg&gt; </code></pre> <p>Here's an example where the string length is manipulated by decreasing the font-size:</p> <pre><code>&lt;svg viewBox="0 0 500 300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"&gt; &lt;defs&gt; &lt;path id="s3" d="M 10,90 Q 100,15 200,70 "/&gt; &lt;/defs&gt; &lt;g&gt; &lt;text font-size="20" font-family="Arial,Helvetica,sans-serif"&gt; &lt;textPath id="tp" xlink:href="#s3" lengthAdjust="spacingAndGlyphs"&gt; The quick brown fox jumps over the lazy dog &lt;/textPath&gt; &lt;/text&gt; &lt;use x="0" y="0" xlink:href="#s3" stroke="black" fill="none"/&gt; &lt;/g&gt; &lt;script&gt;&lt;![CDATA[ var textpath = document.getElementById("tp"); var path = document.getElementById("s3"); var fontsize = 20; while (textpath.getComputedTextLength() &gt; path.getTotalLength()) { fontsize -= 0.01; textpath.setAttribute("font-size", fontsize); } ]]&gt;&lt;/script&gt; &lt;/svg&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload