RichAnno scrambled on SVG export

Discussions about the development of the TechDraw workbench
User avatar
uwestoehr
Posts: 1368
Joined: Sun Jan 27, 2019 3:21 am

RichAnno scrambled on SVG export

Postby uwestoehr » Sat Feb 01, 2020 10:00 pm

- open this example file:
TD-test.FCStd
testfile
(138.06 KiB) Downloaded 6 times
- use the menu TechDraw -> Export page as SVG

result:
td-test.svg
SVG result
(138.39 KiB) Downloaded 10 times

As you can see, the RichTextAnno is scrambled in the SVG.

- now use the menu File -> Export PDF

result: everything looks fine:
td-test.pdf
PDF result
(187.61 KiB) Downloaded 2 times
This issue is independent in the SVG namespace issue.
User avatar
wandererfan
Posts: 3677
Joined: Tue Nov 06, 2012 5:42 pm

Re: RichAnno scrambled on SVG export

Postby wandererfan » Sun Feb 02, 2020 3:43 pm

uwestoehr wrote:
Sat Feb 01, 2020 10:00 pm
As you can see, the RichTextAnno is scrambled in the SVG.
The font size for RTA is being written in "user coordinates" (10x in our case), but being interpreted as "absolute coordinates" when read.

Not sure why plain Annotation is not affected by this.

Will have to change the way RTA font size is written to Svg.
User avatar
wandererfan
Posts: 3677
Joined: Tue Nov 06, 2012 5:42 pm

Re: RichAnno scrambled on SVG export

Postby wandererfan » Wed Feb 05, 2020 12:41 am

uwestoehr wrote:
Sat Feb 01, 2020 10:00 pm
As you can see, the RichTextAnno is scrambled in the SVG.
2 of 3 issues (text size & position) fixed by this git commit d68fcb8cc5.

If I've understood what I read, there is no easy fix to the line spacing problem. We'll need
to split the text into individual lines and position each one separately.
User avatar
uwestoehr
Posts: 1368
Joined: Sun Jan 27, 2019 3:21 am

Re: RichAnno scrambled on SVG export

Postby uwestoehr » Wed Feb 05, 2020 11:05 am

wandererfan wrote:
Wed Feb 05, 2020 12:41 am
2 of 3 issues (text size & position) fixed by this git commit d68fcb8cc5.
I tested and this is what I get now:
firefox_WGGBqjAb7u.png
actual result
firefox_WGGBqjAb7u.png (11.15 KiB) Viewed 285 times

This is what I got before your commit:
firefox_v6VKy3gfHV.png
former result
firefox_v6VKy3gfHV.png (13.61 KiB) Viewed 285 times

Here is the SVG for the box as it should look:
TD-test-correct-box.svg
SVG of only the correctly-looking box
(35.04 KiB) Downloaded 6 times
(I exported the TD page to PDF, then opened the PDF with Inkscape, cleaned it up and saved it as plain SVG.) This SVG shows correct on all 3 browsers I can test (Chrome, Firefox and Edge). This should helps us to find out how to export the RichText box to SVG.
User avatar
Kunda1
Posts: 7093
Joined: Thu Jan 05, 2017 9:03 pm

Re: RichAnno scrambled on SVG export

Postby Kunda1 » Wed Feb 05, 2020 3:54 pm

Can we make TechDraw unit test to spot any future regressions of RichTextAnno ?
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
wandererfan
Posts: 3677
Joined: Tue Nov 06, 2012 5:42 pm

Re: RichAnno scrambled on SVG export

Postby wandererfan » Thu Feb 06, 2020 1:48 am

Kunda1 wrote:
Wed Feb 05, 2020 3:54 pm
Can we make TechDraw unit test to spot any future regressions of RichTextAnno ?
Open to suggestions. Not sure how unit test will tell if result "looks right".
User avatar
wandererfan
Posts: 3677
Joined: Tue Nov 06, 2012 5:42 pm

Re: RichAnno scrambled on SVG export

Postby wandererfan » Fri Feb 07, 2020 7:51 pm

uwestoehr wrote:
Wed Feb 05, 2020 11:05 am
(I exported the TD page to PDF, then opened the PDF with Inkscape, cleaned it up and saved it as plain SVG.) This SVG shows correct on all 3 browsers I can test (Chrome, Firefox and Edge). This should helps us to find out how to export the RichText box to SVG.
The problem is that we don't make the Svg in the case of RichTextAnno. We rely on a chain of QTextEdit/QTextDocument/QSvgGenerator and I don't know how many other Qt routines to produce Svg that is equivalent to the original rich text.

I'm leaning towards exporting the RichTextAnno as plain text. This seems to be reliable in terms of delivering a useful result, but of course most of the formatting is lost. That seems better than delivering corrupted text.
User avatar
wandererfan
Posts: 3677
Joined: Tue Nov 06, 2012 5:42 pm

Re: RichAnno scrambled on SVG export

Postby wandererfan » Fri Feb 14, 2020 12:57 pm

uwestoehr wrote:
Sat Feb 01, 2020 10:00 pm
As you can see, the RichTextAnno is scrambled in the SVG.
This commit git commit f00fca547 changes Svg export of RichTextAnno to use plain text. Plain Text appears in approximately the right place on the page and is easily changed in Inkscape.
User avatar
uwestoehr
Posts: 1368
Joined: Sun Jan 27, 2019 3:21 am

Re: RichAnno scrambled on SVG export

Postby uwestoehr » Fri Feb 14, 2020 3:17 pm

wandererfan wrote:
Fri Feb 14, 2020 12:57 pm
This commit git commit f00fca547 changes Svg export of RichTextAnno to use plain text. Plain Text appears in approximately the right place on the page and is easily changed in Inkscape.
But this does destroy the rich text feature and when inserting rich text, I explicitly want this. :?
If there is no border, OK, but now the text size, shape and decorations are all lost. So in fact it is a plain text annotation.

There is also a regression because when you open the example file of my initial commit you get on opening this error:

Code: Select all

Reading failed from embedded file: PartShape8.brp (133002 bytes, 49082 bytes compressed)
User avatar
wandererfan
Posts: 3677
Joined: Tue Nov 06, 2012 5:42 pm

Re: RichAnno scrambled on SVG export

Postby wandererfan » Fri Feb 14, 2020 6:34 pm

uwestoehr wrote:
Fri Feb 14, 2020 3:17 pm
But this does destroy the rich text feature and when inserting rich text, I explicitly want this. :?
If there is no border, OK, but now the text size, shape and decorations are all lost. So in fact it is a plain text annotation.
At the moment, the choice is between scrambled rich text or plain text. Rich text to Svg isn't on the table.
There is also a regression because when you open the example file of my initial commit you get on opening
this error:

Code: Select all

Reading failed from embedded file: PartShape8.brp (133002 bytes, 49082 bytes compressed)
Not sure what this means. We don't read any brep files in TD.