[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

@@ -456,16 +456,25 @@ void CmdTechDrawView::activated(int iMsg)
filename = Base::Tools::escapeEncodeFilename(filename);
auto filespec = DU::cleanFilespecBackslash(filename.toStdString());
openCommand(QT_TRANSLATE_NOOP("Command", "Create Symbol"));
doCommand(Doc, "f = open(\"%s\", 'r')", filespec.c_str());
doCommand(Doc, "import codecs");
doCommand(Doc,
"f = codecs.open(\"%s\", 'r', encoding=\"utf-8\")",
filespec.c_str());
doCommand(Doc, "svg = f.read()");
doCommand(Doc, "f.close()");
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSymbol', '%s')",
doCommand(Doc,
"App.activeDocument().addObject('TechDraw::DrawViewSymbol', '%s')",
FeatName.c_str());
doCommand(
Doc,
"App.activeDocument().%s.translateLabel('DrawViewSymbol', 'Symbol', '%s')",
FeatName.c_str(),
FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewSymbol', 'Symbol', '%s')",
FeatName.c_str(), FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Symbol = svg", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),
FeatName.c_str());
doCommand(Doc,
"App.activeDocument().%s.addView(App.activeDocument().%s)",
PageName.c_str(),
FeatName.c_str());
}
else {
std::string FeatName = getUniqueObjectName("Image");
@@ -1551,7 +1560,8 @@ void CmdTechDrawSymbol::activated(int iMsg)
filename = Base::Tools::escapeEncodeFilename(filename);
auto filespec = DU::cleanFilespecBackslash(filename.toStdString());
openCommand(QT_TRANSLATE_NOOP("Command", "Create Symbol"));
doCommand(Doc, "f = open(\"%s\", 'r')", (const char*)filespec.c_str());
doCommand(Doc, "import codecs");
doCommand(Doc, "f = codecs.open(\"%s\", 'r', encoding=\"utf-8\")", filespec.c_str());
doCommand(Doc, "svg = f.read()");
doCommand(Doc, "f.close()");
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSymbol', '%s')",