I was exporting several SVG files from TechDraw and I did notice the resulting file is unexpectedly large. This led me to (sometimes quite deep) research and finally to refactoring the SVG handling code. Here is a list of issues and related changes:
- Updating a XML document by a pack of regular expressions is rather an emergency solution. Qt offers XML DOM and XML Query modules. These can be interconnected via QDomNodeModel (BSD licensed) by Stanislaw Adaszewski. I have added proper XML namespaces handling to his model and now we can fully use the advantages of DOM and XQuery for e.g. working with editable texts.
- Qt QSvgGenerator class does not generate (not even remotely) the same code as the QSvgRenderer previously accepted. This is particularly displeasing with template texts, which end up as (huge) series of paths, due to QSvgRenderer's unkind SVG stroke handling. Needless to say, later change of such a beast is almost impossible. Thus in my pull request, I offer inserting the template SVG code directly into the resulting file, bypassing the QSvgRenderer -> QSvgGenerator roundtrip. The template keeps its whole structure, just editable texts are updated.
- For some unknown reason (comfortableness?) Qt inserts a lot of empty SVG group <g> elements with no childs, but a lot of useless attributes. We can simply remove these, as they are of no significance. Together with changes above, an exported A4 ISO 7200 page with a single drawing is reduced from 142kB to reasonable 8kB.
- After "resolving" the screen/SVG font size issue last week, I have found out there is much simpler and better solution: To set the font size in pixels (i.e. tenths of virtual mm in our case), instead of "points" computed from logical DPI. This change is also neccessary, if we want to include the SVG template directly and not squeezed through warped Qt SVG processing.
- Last but not least, I understand the usage of xml:space="preserve" attribute in SVG, but it should be put directly on the <tspan> elements and not on template's <text> items. Any SVG processing changing the amount of spaces (e.g. different indentation) then breaks the actual position of affected labels. I have removed xml:space attributes from all SVG templates and my solution is to add them programatically to each editable <tspan> during the editable texts replacement phase. Inner spaces are preserved, but whole texts are never shifted.