deeplook / svglib

Read SVG files and convert them to other formats.
GNU Lesser General Public License v3.0
325 stars 79 forks source link

textLength attribute not handled #345

Open MattiWheels opened 2 years ago

MattiWheels commented 2 years ago

No errors are thrown but the expected output is not produced.

SVG Document:

<svg version="1.1" id="Design5" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" 
     viewBox="0 0 600 100" style="enable-background:new 0 0 600 100;" xml:space="preserve">
    <defs>
        <style type="text/css">
            .line1 {
                font-size:120px;
                font-family:"Helvetica";
                fill: #33ffaa;
            }
        </style>
    </defs>
    <text textLength='440' lengthAdjust="spacing" transform="matrix(1 0 0 1 0 90)" class="line1">
        SomeText
    </text>
</svg>

SVG Appearance: image

Using code based on the documentation:

from svglib.svglib import svg2rlg
from reportlab.graphics import renderPM
logo = svg2rlg(svg_file)
renderPM.drawToFile(logo, png_file, fmt='PNG')

Produces this result: image

Note: The grey background shown in the SVG appearance is just the preview area in VS Code and is not a part of the design. Also, sorry for the cursor appearing in the screenshot.

github-actions[bot] commented 2 years ago

Thank you for raising your first issue! Your help to improve svglib is much appreciated!

claudep commented 2 years ago

Confirmed, svglib does not consider the textLength attribute.

reportlab String shape does only support a limited set of attributes. Not sure if svglib could implement that or if we should simply document the limitation.

MattiWheels commented 2 years ago

@claudep Thanks for your response on this issue. I am finding that Python and JS libraries don't support the use of certain properties like textLength, lengthAdjust, and some transforms. I'm sure there are more unsupported properties, but these are the ones that I am having troubles with.

The solution I have found is to use ExtendScript and make these adjustments using Illustrator actions / automation. I'm hoping to find a replacement, since Python or JS can outpace ExtendScript by a longshot (I'm hoping to generate over 150k images for a database with this technique).