From 219a15da23b529faa66cfa56dd7276179e9cc701 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 16 Jul 2018 20:00:42 +0300 Subject: [PATCH] Fix issue with export non-latin DXF file name on Windows. --HG-- branch : develop --- src/libs/vdxf/vdxfengine.cpp | 29 +++++++++++++++++++++++++++-- src/libs/vdxf/vdxfengine.h | 3 +++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/libs/vdxf/vdxfengine.cpp b/src/libs/vdxf/vdxfengine.cpp index 708c6ef1b..0e7542038 100644 --- a/src/libs/vdxf/vdxfengine.cpp +++ b/src/libs/vdxf/vdxfengine.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -109,7 +110,8 @@ bool VDxfEngine::begin(QPaintDevice *pdev) return false; } - input = QSharedPointer(new dx_iface(fileName.toStdString(), m_version, varMeasurement, varInsunits)); + input = QSharedPointer(new dx_iface(getFileNameForLocale(), m_version, varMeasurement, + varInsunits)); input->AddQtLTypes(); input->AddDefLayers(); return true; @@ -611,7 +613,8 @@ bool VDxfEngine::ExportToAAMA(const QVector &details) return false; } - input = QSharedPointer(new dx_iface(fileName.toStdString(), m_version, varMeasurement, varInsunits)); + input = QSharedPointer(new dx_iface(getFileNameForLocale(), m_version, varMeasurement, + varInsunits)); input->AddAAMAHeaderData(); if (m_version > DRW::AC1009) { @@ -849,6 +852,28 @@ DRW_Entity *VDxfEngine::AAMAText(const QPointF &pos, const QString &text, const return textLine; } +//--------------------------------------------------------------------------------------------------------------------- +std::string VDxfEngine::FromUnicodeToCodec(const QString &str, QTextCodec *codec) +{ + const QByteArray encodedString = codec->fromUnicode(str); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) + return encodedString.toStdString(); +#else + return std::string(encodedString.constData(), static_cast(encodedString.length())); +#endif +} + +//--------------------------------------------------------------------------------------------------------------------- +std::string VDxfEngine::getFileNameForLocale() const +{ +#if defined(Q_OS_WIN) + return VDxfEngine::FromUnicodeToCodec(fileName, QTextCodec::codecForLocale()); +#else + return fileName.toStdString(); +#endif +} + //--------------------------------------------------------------------------------------------------------------------- template P *VDxfEngine::CreateAAMAPolygon(const QVector &polygon, const QString &layer, bool forceClosed) diff --git a/src/libs/vdxf/vdxfengine.h b/src/libs/vdxf/vdxfengine.h index 414d9bf82..f6b266c05 100644 --- a/src/libs/vdxf/vdxfengine.h +++ b/src/libs/vdxf/vdxfengine.h @@ -124,6 +124,9 @@ private: template Q_REQUIRED_RESULT P *CreateAAMAPolygon(const QVector &polygon, const QString &layer, bool forceClosed); + + static std::string FromUnicodeToCodec(const QString &str, QTextCodec *codec); + std::string getFileNameForLocale() const; }; #endif // VDXFENGINE_H