for text-to-path conversion, suppress added style attributes
Steps to reproduce:
Create an SVG file with an embedded stylesheet and text styled according to a CSS class selector from that stylsheet. Invoke inkscape from the command line, on that file, with the --export-text-to-path
and --export-plain-svg=-
options.
What happened?
A converted SVG file is printed to the console, with the style attributes, including now unneeded CSS text style attributes, represented inline in the style
attributes of every path generated from the text.
What should have happened?
In many cases, the user wishes to produce a SVG file that will display in any compliant viewer, that is optimized for size, and that contains limited artifacts of the source material having no effect on proper display.
A recommended approach for Inkscape files is to save to the optimized SVG file type, which invokes scour, or for automated invocation from the command line, to invoke scour explicitly on the file. However, for correct display independent of environment, or with the original font style details unavailable to the viewer of the target file, text-to-path conversion is required. Scour does not perform text-to-path conversion, however, so Inkscape must be used directly for this operation. Conveniently, Inkscape does support this feature in command-line invocation, facilitating automatic processing.
However, Inkscape has a preference for writing all style details into the style
attribute of document items. Whereas it respect class selection from a stylesheet for existing elements, all new elements, including those from text-to-path conversion, contain a detailed value for the style
attribute. This behavior presents an obstacle if the user wishes to utilize the text-to-path feature while also doing any of the following:
- Use styling from a stylesheet rather than inline
style
attribute values. - Keep file size small.
- Hide source details from the viewer of the target file, including original text font and formatting details.
Some of these features are expressly supported in scour, but since the text-to-path conversion is performed by Inkscape, scour is unable to keep the style
attribute out of the generating output. The decision-making abilities of scour are not adequate to undo all of the unwanted changes introduced by Inkscape during the text-to-path conversion. For example, scour does not identify a special case in which item's style can be completely determined by a class selector, permitting removal of the style
attribute with no effect. Further, scour does not recognize that font and text formatting details are not needed for correct display of paths.
General strategies for facilitating text-to-path conversion without the unneeded details added to the style
attribute include not creating a style
attribute if style details are previously resolved exclusively through CSS class selection; and omitting from the resulting path items text-only style attributes, which were previously needed to render the text.
Further notes
A forum discussion alludes to this behavior, where the rationale is explained as a design feature. While this rationale is interesting, it plainly does not describe all use cases, and control for this behavior, including during the command line invocation with --export-text-to-path
, could be added to support customization of behavior according to specific user requirements per invocation.
Related discussions
Inkscape Version and Operating System:
- Inkscape Version: Inkscape 0.92.4 (unknown)
- Operating System: Linux Mint
- Operating System version: 19.1