[Techdraw] Import SVG files with UTF-8 encoding (#18816)

* [Techdraw] Fix importing SVG files with UTF-8 encoding

* [Techdraw] fix Lint feedback
This commit is contained in:
Syres916
2025-01-06 17:32:56 +00:00
committed by GitHub
parent 5236541045
commit b86e1adb22
4 changed files with 63 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
import FreeCAD
import codecs
import os
import unittest
from .TechDrawTestUtilities import createPageWithSVGTemplate
@@ -21,7 +22,26 @@ class DrawViewSymbolTest(unittest.TestCase):
sym = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewSymbol", "TestSymbol")
path = os.path.dirname(os.path.abspath(__file__))
symbolFileSpec = path + "/TestSymbol.svg"
f = open(symbolFileSpec, "r")
f = codecs.open(symbolFileSpec, "r", encoding="utf-8")
svg = f.read()
f.close()
sym.Symbol = svg
self.page.addView(sym)
sym.X = 220.0
sym.Y = 150.0
FreeCAD.ActiveDocument.recompute()
self.assertTrue("Up-to-date" in sym.State)
def testNonAsciiSymbol(self):
"""Tests if a Non-Ascii symbol can be added to page"""
sym = FreeCAD.ActiveDocument.addObject(
"TechDraw::DrawViewSymbol", "NonAsciiSymbol"
)
path = os.path.dirname(os.path.abspath(__file__))
symbolFileSpec = path + "/TestNonAsciiSymbol.svg"
f = codecs.open(symbolFileSpec, "r", encoding="utf-8")
svg = f.read()
f.close()
sym.Symbol = svg
@@ -34,5 +54,6 @@ class DrawViewSymbolTest(unittest.TestCase):
self.assertTrue("Up-to-date" in sym.State)
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns="http://www.w3.org/2000/svg" version="1.1"
xmlns:freecad="http://www.freecad.org/wiki/index.php?title=Svg_Namespace"
width ="57.0mm"
height="10mm"
viewBox="0 0 57.0 10">
<g id="first-frame"
style="fill:#fff;fill-opacity:1;stroke:#000;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:round;font-size:5.0;text-anchor:middle;font-family:osifont">
<rect width="56.5" height="9.5" x="0.25" y="0.25" />
<circle cx="5.0" cy="5.0" r="1.75" />
<path d="m 2 5 h 6 m -3 -3 v 6 " />
<path d="m 9.75 0.25 v 9.5 " />
<text freecad:editable="Value1" x="20.0" y="7" fill="#000"> <tspan>⌀ 0,01</tspan> </text>
<path d="m 28.25 0.25 v 9.5 " />
<text freecad:editable="Value2" x="34.0" y="7" fill="#000"> <tspan>Ä</tspan> </text>
<path d="m 37.75 0.25 v 9.5 " />
<text freecad:editable="Value3" x="43.5" y="7" fill="#000"> <tspan>Ö</tspan> </text>
<path d="m 47.25 0.25 v 9.5 " />
<text freecad:editable="Value4" x="53.0" y="7" fill="#000"> <tspan>Ü</tspan> </text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB