Jump to content
Sign in to follow this  
Philip Federici

[Fixed] Multiple text white spaces in SVG export

Recommended Posts

Dear Developers,

 

When exporting a file to SVG with text fields (ASCII art in my case) multiple spaces are written as simple consequent spaces in the XML file.

Unfortunately XML, as HTML, will display these as a single space. Declaring xml:space="preserve" as you do, unfortunately does not suffice, because it works only if the string contains only spaces. A better approach would be to use non-breaking spaces:  

To keep the XML more readable you could code it to change from simple to non-breaking spaces only from the second consequent (included) onwards, so that normal prose would not be cluttered. Just a thought.

 

Thank you in advance.

Kind Regards,

 

Philip

Share this post


Link to post
Share on other sites

Hi Philip, welcome to the forums.

 

The XML Specification says, the value "preserve" indicates the intent that applications preserve all the white space. That seems pretty unambiguous. The SVG Specification is even clearer:

When xml:space="preserve", the SVG user agent will do the following using a copy of the original character data content. It will convert all newline and tab characters into space characters. Then, it will draw all space characters, including leading, trailing and multiple contiguous space characters. Thus, when drawn with xml:space="preserve", the string "a   b" (three spaces between "a" and "b") will produce a larger separation between "a" and "b" than "a b" (one space between "a" and "b").

 

Firefox and Illustrator interpret as I would expect, preserving all the white space even in non-empty nodes. However, I see that some other apps don't, including Safari and Finder Preview. Those apps are just not interpreting the SVG according to the specification. I appreciate you may have to work with broken apps, so I'll see about getting this changed. Thanks for the report.

Share this post


Link to post
Share on other sites

Thanks Philip,

What are you using to view your SVGs? I've found that IE will always ignore spaces even when xml:space="preserve" is placed in line with the element, Firefox will always treat them as separate spaces (even if preserve is not in line with the element) and both Safari & Chrome will only treat them as separate spaces if preserve is placed in line with the element.

Regarding vector software Affinity, Illustrator, Inkscape and DrawPlus all treat them as separate spaces.

 

When using non-breaking spaces all browsers and applications above treated the white space as you would expect.

 

Share this post


Link to post
Share on other sites

Thank you both,

 

I experienced the phenomenon in Safari 9.0.3 (11601.4.4) on El Capitan 10.11.3 (15D21). I did some research and using non-breaking spaces seems to be the most robust solution. I apologise if I suggested that the exported SVG does not comply with XML Specification, I did not mean to. In fact I have never used a better software in this respect.

In my case adding preserve in line would have made the file bigger than converting the spaces to non-breaking. I suspect this stands true for most projects on Affinity, but I may be wrong.

 

Philip

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×