[bug] Alignment of non-left-aligned text

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
HowThatWorks
Posts: 29
Joined: Mon Feb 10, 2020 4:27 pm
Contact:

[bug] Alignment of non-left-aligned text

Post by HowThatWorks »

Whilst making some templates for TechDraw I noticed that even after I got rid of all transform and xml:space="preserve" statments, text that was centred or right-aligned would would end up consistently to the left of where it was supposed to be. Compare how this test SVG[1] looks in Inkscape:
justification_inkscape.png
justification_inkscape.png (23.54 KiB) Viewed 1013 times
with how it looks in FreeCAD 0.21[2] and 0.22[3]:
justification_FC21.png
justification_FC21.png (30.57 KiB) Viewed 1013 times
Both versions show identical leftward shifts of the non-left-aligned text, with the right-aligned text being notable more shifted.

Interestingly, if I use TechDraw_Symbol to import the same SVG, FreeCAD almost gets it correct[4]:
justification_FC22_symbol.png
justification_FC22_symbol.png (28.44 KiB) Viewed 1013 times
You have to zoom in to see it, but centred and right-aligned text is shifted slightly to the right this time, with the shift being greater for right-aligned text. Again, the shift is identical for 0.21 and 0.22^.

If you export the page to SVG via TechDraw_ExportPageSVG, then open the output SVG in Inkscape it look fine, but if you export to PDF directly (via File > Export PDF...) then the shift persists. This more or less mandates exporting to SVG then using Inkscape or whatever else to export to PDF.

I'm pretty sure this is just a straight up bug, but I want to make sure I'm not missing something obvious before submitting something to the bug tracker.

[1]
justification.svg
(6.14 KiB) Downloaded 14 times
All of capital As have their text anchor on the long green line. The red capital As are duplicates converted to paths and placed behind the corresponding text object - they should be covered by the black text.

[2]

Code: Select all

OS: Windows 10 build 19045
Word size of FreeCAD: 64-bit
Version: 0.21.1.33668 +26 (Git)
Build type: Release
Branch: (HEAD detached at 0.21.1)
Hash: f6708547a9bb3f71a4aaade12109f511a72c207c
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: English/United Kingdom (en_GB)
Installed mods: 
  * Assembly4 0.12.5
  * ExplodedAssembly
  * fasteners 0.4.52
[3]

Code: Select all

OS: Windows 10 build 19045
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.35735 (Git)
Build type: Release
Branch: main
Hash: c12a5c2a163c1a277cf273106899209792be152d
Python 3.10.13, Qt 5.15.8, Coin 4.0.2, Vtk 9.2.6, OCC 7.6.3
Locale: English/United Kingdom (en_GB)
Installed mods: 
  * Assembly4 0.12.5
  * ExplodedAssembly
  * fasteners 0.4.52
User avatar
onekk
Veteran
Posts: 6013
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: [bug] Alignment of non-left-aligned text

Post by onekk »

To make things short there are different standards and it depends heavily on what defaults the PDF or SVG program is expecting (many programs have preferences to set this).

Are you aware that InkScape use his own flavour of SVG snd have an option to export and read standard SVG?

If you open an SVG file saved with Inkscape you will find a bunch of "sodipodi" extension (that probably was the name of some components of Inkscape), but you can export files in SVG standard or compatible format I don't remember well the exact terminology Inkscape is using.

Sadly standards are made to be broken. :-D

Kind Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
HowThatWorks
Posts: 29
Joined: Mon Feb 10, 2020 4:27 pm
Contact:

Re: [bug] Alignment of non-left-aligned text

Post by HowThatWorks »

I think you're talking about Save As... Plain SVG. That gets rid of any sodipodi entries (see attached), but doesn't fix the error.
Attachments
justification_no_sodipodi.svg
(6.14 KiB) Downloaded 1 time
User avatar
wandererfan
Veteran
Posts: 6198
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [bug] Alignment of non-left-aligned text

Post by wandererfan »

Inkscape renders svg using the full svg specification, while TechDraw only supports svg-tiny.

I don't have a computer with me, so I can't provide a full answer, but this would be my first guess.

My next guess would be a difference in how qt-svg handles the left-bearing of text glyphs.
HowThatWorks
Posts: 29
Joined: Mon Feb 10, 2020 4:27 pm
Contact:

Re: [bug] Alignment of non-left-aligned text

Post by HowThatWorks »

Text alignment is part of SVG Tiny 1.2 (https://www.w3.org/TR/SVGMobile/text.ht ... Properties), so it should be working. I have the suspicion that qt-svg is somehow applying the offset needed for non-left-aligned text twice, I'll see if I can substantiate that when I have time later.

[edit] And another thing: if it is a bug in qt-svg, then why does TechDraw_Symbol almost get it right? What is Import Page from File doing that Import SVG Symbol isn't?
User avatar
wandererfan
Veteran
Posts: 6198
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [bug] Alignment of non-left-aligned text

Post by wandererfan »

HowThatWorks wrote: Sat Jan 27, 2024 3:35 am
According to this: https://bugreports.qt.io/browse/QTBUG-11072, "... explicit positioning of tspans is not part of the SVG Tiny 1.2 specification, which is what Qt supports."

If I move the A from the tspan to the text everything is positioned correctly. Don't know yet why it looks better as a symbol than it does as a template.
explicittspanPositioning.png
explicittspanPositioning.png (14.56 KiB) Viewed 555 times
HowThatWorks
Posts: 29
Joined: Mon Feb 10, 2020 4:27 pm
Contact:

Re: [bug] Alignment of non-left-aligned text

Post by HowThatWorks »

Ah, that'll do it. Thanks! TechDraw_PageTemplate now gets it wrong in the same way as TechDraw_Symbol, which is going to bug me endlessly but it's hardly a deal breaker.

It's kind of amazing that Inkscape doesn't have an easy way to produce an SVG Tiny file, given how important it is.
User avatar
wandererfan
Veteran
Posts: 6198
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [bug] Alignment of non-left-aligned text

Post by wandererfan »

Progress of a sort. Jiggled the code a bit to make template and symbol behave the same and skip the editable text processing.

The problem seems to be in the code that finds the editable text fields in the template and fills in the values from the EditableTexts property. Haven't yet figured out what happens to the svg.
Attachments
AlignmentProgress.png
AlignmentProgress.png (19.51 KiB) Viewed 389 times
User avatar
wandererfan
Veteran
Posts: 6198
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: [bug] Alignment of non-left-aligned text

Post by wandererfan »

I grabbed the svg from 2 places in the template code, then used insert symbol to add them to a page. 1 is formatted as we would expect and the other shows the mis-alignment.

When I compare the 2 svg file, I can not see what causes this. If somebody with better eyes or svg knowledge can figure out the difference, that would be much appreciated.
DifferentResults.png
DifferentResults.png (27.47 KiB) Viewed 345 times
Attachments
FromQBASymbolWorks.svg
(6.14 KiB) Downloaded 3 times
FromQStringSymbolNoWork.svg
(5.74 KiB) Downloaded 3 times
HowThatWorks
Posts: 29
Joined: Mon Feb 10, 2020 4:27 pm
Contact:

Re: [bug] Alignment of non-left-aligned text

Post by HowThatWorks »

So FromQBASymbolWorks.svg is identical to original SVG, except for the addition of two blank lines at the end of the file - no problem there.

Ignoring differences in indentation and line breaks, FromQStringSymbolNoWork.svg differs in a few ways. First, the XML header uses ' instead of ", but everywhere else it uses ", which is such an odd change to make. Second, whilst the the path and text objects are all in the same order, the elements within each are listed in different orders. For example, this:

Code: Select all

  <text
     style="font-size:10px;line-height:1;font-family:osifont;-inkscape-font-specification:osifont;text-align:end;text-decoration:none;text-decoration-line:none;text-decoration-color:#000000;word-spacing:0px;text-orientation:sideways;text-anchor:end;fill:#000000;stroke-width:2;stroke-linejoin:round;stop-color:#000000"
     x="37"
     y="44.868683"
     id="text20"><tspan
       id="tspan20"
       style="font-size:10px;text-align:end;text-anchor:end;stroke-width:2"
       x="37"
       y="44.868683">A</tspan></text>
becomes this:

Code: Select all

  <text
     y="44.868683"
     id="text20"
     style="font-size:10px;line-height:1;font-family:osifont;-inkscape-font-specification:osifont;text-align:end;text-decoration:none;text-decoration-line:none;text-decoration-color:#000000;word-spacing:0px;text-orientation:sideways;text-anchor:end;fill:#000000;stroke-width:2;stroke-linejoin:round;stop-color:#000000"
     x="37"><tspan
     y="44.868683"
     id="tspan20"
     style="font-size:10px;text-align:end;text-anchor:end;stroke-width:2"
     x="37">A</tspan></text>
(once we throw in a few line breaks and spaces to make it easier to compare.)

The reordering is consistent, for text it's y, id, style, x, even in the tspan tags. Paths become id, aria-label, d, style. None of the elements change, just their order. The only thing I can think of is that somehow x coming after y is messing things up, but that's kind of an absurd bug.
Post Reply