Improve conversion for dxf file export.
We never checked if it really works. And it doesn't in many cases. Not always Qt recognizes standard ANSI_* names as valid aliases for codepages. Because codec itself can have many aliases we will test them one by one until one will fit. --HG-- branch : develop
This commit is contained in:
parent
9f01aa7136
commit
24e50455b0
|
@ -28,6 +28,138 @@
|
|||
|
||||
#include "dxfdef.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
|
||||
const QString endStringPlaceholder = QStringLiteral("%&?_?&%");
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QMap<QString, QString> LocaleMap()
|
||||
{
|
||||
QMap <QString, QString> locMap
|
||||
{
|
||||
{"croatian", "ISO8859-2"},
|
||||
{"cs", "ISO8859-2"},
|
||||
{"cs_CS", "ISO8859-2"},
|
||||
{"cs_CZ", "ISO8859-2"},
|
||||
{"cz", "ISO8859-2"},
|
||||
{"cz_CZ", "ISO8859-2"},
|
||||
{"czech", "ISO8859-2"},
|
||||
{"hr", "ISO8859-2"},
|
||||
{"hr_HR", "ISO8859-2"},
|
||||
{"hu", "ISO8859-2"},
|
||||
{"hu_HU", "ISO8859-2"},
|
||||
{"hungarian", "ISO8859-2"},
|
||||
{"pl", "ISO8859-2"},
|
||||
{"pl_PL", "ISO8859-2"},
|
||||
{"polish", "ISO8859-2"},
|
||||
{"ro", "ISO8859-2"},
|
||||
{"ro_RO", "ISO8859-2"},
|
||||
{"rumanian", "ISO8859-2"},
|
||||
{"serbocroatian", "ISO8859-2"},
|
||||
{"sh", "ISO8859-2"},
|
||||
{"sh_SP", "ISO8859-2"},
|
||||
{"sh_YU", "ISO8859-2"},
|
||||
{"sk", "ISO8859-2"},
|
||||
{"sk_SK", "ISO8859-2"},
|
||||
{"sl", "ISO8859-2"},
|
||||
{"sl_CS", "ISO8859-2"},
|
||||
{"sl_SI", "ISO8859-2"},
|
||||
{"slovak", "ISO8859-2"},
|
||||
{"slovene", "ISO8859-2"},
|
||||
{"sr_SP", "ISO8859-2"},
|
||||
|
||||
{"eo", "ISO8859-3"},
|
||||
|
||||
{"ee", "ISO8859-4"},
|
||||
{"ee_EE", "ISO8859-4"},
|
||||
|
||||
{"mk", "ISO8859-5"},
|
||||
{"mk_MK", "ISO8859-5"},
|
||||
{"sp", "ISO8859-5"},
|
||||
{"sp_YU", "ISO8859-5"},
|
||||
|
||||
{"id", "ISO8859-1"},
|
||||
{"id_ID", "ISO8859-1"},
|
||||
|
||||
{"ar_AA", "ISO8859-6"},
|
||||
{"ar_SA", "ISO8859-6"},
|
||||
{"arabic", "ISO8859-6"},
|
||||
|
||||
{"el", "ISO8859-7"},
|
||||
{"el_GR", "ISO8859-7"},
|
||||
{"greek", "ISO8859-7"},
|
||||
|
||||
{"hebrew", "ISO8859-8"},
|
||||
{"he", "ISO8859-8"},
|
||||
{"he_IL", "ISO8859-8"},
|
||||
{"iw", "ISO8859-8"},
|
||||
{"iw_IL", "ISO8859-8"},
|
||||
|
||||
{"tr", "ISO8859-9"},
|
||||
{"tr_TR", "ISO8859-9"},
|
||||
{"turkish", "ISO8859-9"},
|
||||
|
||||
{"lt", "ISO8859-13"},
|
||||
{"lt_LT", "ISO8859-13"},
|
||||
{"lv", "ISO8859-13"},
|
||||
{"lv_LV", "ISO8859-13"},
|
||||
|
||||
{"et", "ISO8859-15"},
|
||||
{"et_EE", "ISO8859-15"},
|
||||
{"br_FR", "ISO8859-15"},
|
||||
{"ca_ES", "ISO8859-15"},
|
||||
{"de", "ISO8859-15"},
|
||||
{"de_AT", "ISO8859-15"},
|
||||
{"de_BE", "ISO8859-15"},
|
||||
{"de_DE", "ISO8859-15"},
|
||||
{"de_LU", "ISO8859-15"},
|
||||
{"en_IE", "ISO8859-15"},
|
||||
{"es", "ISO8859-15"},
|
||||
{"es_ES", "ISO8859-15"},
|
||||
{"eu_ES", "ISO8859-15"},
|
||||
{"fi", "ISO8859-15"},
|
||||
{"fi_FI", "ISO8859-15"},
|
||||
{"finnish", "ISO8859-15"},
|
||||
{"fr", "ISO8859-15"},
|
||||
{"fr_FR", "ISO8859-15"},
|
||||
{"fr_BE", "ISO8859-15"},
|
||||
{"fr_LU", "ISO8859-15"},
|
||||
{"french", "ISO8859-15"},
|
||||
{"ga_IE", "ISO8859-15"},
|
||||
{"gl_ES", "ISO8859-15"},
|
||||
{"it", "ISO8859-15"},
|
||||
{"it_IT", "ISO8859-15"},
|
||||
{"oc_FR", "ISO8859-15"},
|
||||
{"nl", "ISO8859-15"},
|
||||
{"nl_BE", "ISO8859-15"},
|
||||
{"nl_NL", "ISO8859-15"},
|
||||
{"pt", "ISO8859-15"},
|
||||
{"pt_PT", "ISO8859-15"},
|
||||
{"pt_BR", "ISO8859-15"},
|
||||
{"sv_FI", "ISO8859-15"},
|
||||
{"wa_BE", "ISO8859-15"},
|
||||
|
||||
{"uk", "KOI8-U"},
|
||||
{"uk_UA", "KOI8-U"},
|
||||
{"ru_YA", "KOI8-U"},
|
||||
{"ukrainian", "KOI8-U"},
|
||||
{"ru_RU", "KOI8-U"},
|
||||
|
||||
{"be", "KOI8-R"},
|
||||
{"be_BY", "KOI8-R"},
|
||||
{"bg", "KOI8-R"},
|
||||
{"bg_BG", "KOI8-R"},
|
||||
{"bulgarian", "KOI8-R"},
|
||||
{"ba_RU", "KOI8-R"},
|
||||
{"ky", "KOI8-R"},
|
||||
{"ky_KG", "KOI8-R"},
|
||||
{"kk", "KOI8-R"},
|
||||
{"kk_KZ", "KOI8-R"},
|
||||
|
||||
{"zh", "CP932"},
|
||||
{"zh_CN", "CP932"},
|
||||
};
|
||||
|
||||
return locMap;
|
||||
}
|
||||
|
|
|
@ -57,4 +57,6 @@ static inline bool DL_FuzzyComparePossibleNulls(double p1, double p2)
|
|||
}
|
||||
}
|
||||
|
||||
QMap <QString, QString> LocaleMap();
|
||||
|
||||
#endif // DXFDEF_H
|
||||
|
|
|
@ -362,122 +362,6 @@ void dx_iface::AddBlock(dx_ifaceBlock *block)
|
|||
|
||||
std::string dx_iface::LocaleToISO()
|
||||
{
|
||||
QMap <std::string, std::string> locMap;
|
||||
locMap["croatian"] = "ISO8859-2";
|
||||
locMap["cs"] = "ISO8859-2";
|
||||
locMap["cs_CS"] = "ISO8859-2";
|
||||
locMap["cs_CZ"] = "ISO8859-2";
|
||||
locMap["cz"] = "ISO8859-2";
|
||||
locMap["cz_CZ"] = "ISO8859-2";
|
||||
locMap["czech"] = "ISO8859-2";
|
||||
locMap["hr"] = "ISO8859-2";
|
||||
locMap["hr_HR"] = "ISO8859-2";
|
||||
locMap["hu"] = "ISO8859-2";
|
||||
locMap["hu_HU"] = "ISO8859-2";
|
||||
locMap["hungarian"] = "ISO8859-2";
|
||||
locMap["pl"] = "ISO8859-2";
|
||||
locMap["pl_PL"] = "ISO8859-2";
|
||||
locMap["polish"] = "ISO8859-2";
|
||||
locMap["ro"] = "ISO8859-2";
|
||||
locMap["ro_RO"] = "ISO8859-2";
|
||||
locMap["rumanian"] = "ISO8859-2";
|
||||
locMap["serbocroatian"] = "ISO8859-2";
|
||||
locMap["sh"] = "ISO8859-2";
|
||||
locMap["sh_SP"] = "ISO8859-2";
|
||||
locMap["sh_YU"] = "ISO8859-2";
|
||||
locMap["sk"] = "ISO8859-2";
|
||||
locMap["sk_SK"] = "ISO8859-2";
|
||||
locMap["sl"] = "ISO8859-2";
|
||||
locMap["sl_CS"] = "ISO8859-2";
|
||||
locMap["sl_SI"] = "ISO8859-2";
|
||||
locMap["slovak"] = "ISO8859-2";
|
||||
locMap["slovene"] = "ISO8859-2";
|
||||
locMap["sr_SP"] = "ISO8859-2";
|
||||
|
||||
locMap["eo"] = "ISO8859-3";
|
||||
|
||||
locMap["ee"] = "ISO8859-4";
|
||||
locMap["ee_EE"] = "ISO8859-4";
|
||||
|
||||
locMap["mk"] = "ISO8859-5";
|
||||
locMap["mk_MK"] = "ISO8859-5";
|
||||
locMap["sp"] = "ISO8859-5";
|
||||
locMap["sp_YU"] = "ISO8859-5";
|
||||
|
||||
locMap["ar_AA"] = "ISO8859-6";
|
||||
locMap["ar_SA"] = "ISO8859-6";
|
||||
locMap["arabic"] = "ISO8859-6";
|
||||
|
||||
locMap["el"] = "ISO8859-7";
|
||||
locMap["el_GR"] = "ISO8859-7";
|
||||
locMap["greek"] = "ISO8859-7";
|
||||
|
||||
locMap["hebrew"] = "ISO8859-8";
|
||||
locMap["he"] = "ISO8859-8";
|
||||
locMap["he_IL"] = "ISO8859-8";
|
||||
locMap["iw"] = "ISO8859-8";
|
||||
locMap["iw_IL"] = "ISO8859-8";
|
||||
|
||||
locMap["tr"] = "ISO8859-9";
|
||||
locMap["tr_TR"] = "ISO8859-9";
|
||||
locMap["turkish"] = "ISO8859-9";
|
||||
|
||||
locMap["lt"] = "ISO8859-13";
|
||||
locMap["lt_LT"] = "ISO8859-13";
|
||||
locMap["lv"] = "ISO8859-13";
|
||||
locMap["lv_LV"] = "ISO8859-13";
|
||||
|
||||
locMap["et"] = "ISO8859-15";
|
||||
locMap["et_EE"] = "ISO8859-15";
|
||||
locMap["br_FR"] = "ISO8859-15";
|
||||
locMap["ca_ES"] = "ISO8859-15";
|
||||
locMap["de"] = "ISO8859-15";
|
||||
locMap["de_AT"] = "ISO8859-15";
|
||||
locMap["de_BE"] = "ISO8859-15";
|
||||
locMap["de_DE"] = "ISO8859-15";
|
||||
locMap["de_LU"] = "ISO8859-15";
|
||||
locMap["en_IE"] = "ISO8859-15";
|
||||
locMap["es"] = "ISO8859-15";
|
||||
locMap["es_ES"] = "ISO8859-15";
|
||||
locMap["eu_ES"] = "ISO8859-15";
|
||||
locMap["fi"] = "ISO8859-15";
|
||||
locMap["fi_FI"] = "ISO8859-15";
|
||||
locMap["finnish"] = "ISO8859-15";
|
||||
locMap["fr"] = "ISO8859-15";
|
||||
locMap["fr_FR"] = "ISO8859-15";
|
||||
locMap["fr_BE"] = "ISO8859-15";
|
||||
locMap["fr_LU"] = "ISO8859-15";
|
||||
locMap["french"] = "ISO8859-15";
|
||||
locMap["ga_IE"] = "ISO8859-15";
|
||||
locMap["gl_ES"] = "ISO8859-15";
|
||||
locMap["it"] = "ISO8859-15";
|
||||
locMap["it_IT"] = "ISO8859-15";
|
||||
locMap["oc_FR"] = "ISO8859-15";
|
||||
locMap["nl"] = "ISO8859-15";
|
||||
locMap["nl_BE"] = "ISO8859-15";
|
||||
locMap["nl_NL"] = "ISO8859-15";
|
||||
locMap["pt"] = "ISO8859-15";
|
||||
locMap["pt_PT"] = "ISO8859-15";
|
||||
locMap["sv_FI"] = "ISO8859-15";
|
||||
locMap["wa_BE"] = "ISO8859-15";
|
||||
|
||||
locMap["uk"] = "KOI8-U";
|
||||
locMap["uk_UA"] = "KOI8-U";
|
||||
locMap["ru_YA"] = "KOI8-U";
|
||||
locMap["ukrainian"] = "KOI8-U";
|
||||
locMap["ru_RU"] = "KOI8-U";
|
||||
|
||||
locMap["be"] = "KOI8-R";
|
||||
locMap["be_BY"] = "KOI8-R";
|
||||
locMap["bg"] = "KOI8-R";
|
||||
locMap["bg_BG"] = "KOI8-R";
|
||||
locMap["bulgarian"] = "KOI8-R";
|
||||
locMap["ba_RU"] = "KOI8-R";
|
||||
locMap["ky"] = "KOI8-R";
|
||||
locMap["ky_KG"] = "KOI8-R";
|
||||
locMap["kk"] = "KOI8-R";
|
||||
locMap["kk_KZ"] = "KOI8-R";
|
||||
|
||||
QLocale locale(qApp->Settings()->GetLocale());
|
||||
return locMap.value(locale.name().toStdString(), "ISO8859-1");
|
||||
QMap <QString, QString> locMap = LocaleMap();
|
||||
return locMap.value(QLocale(qApp->Settings()->GetLocale()).name(), "ISO8859-1").toStdString();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,41 @@
|
|||
#include "../vmisc/vabstractapplication.h"
|
||||
#include "../ifc/exception/vexception.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
QMap<QString, QStringList> QtCodecs()
|
||||
{
|
||||
return QMap<QString, QStringList>
|
||||
{
|
||||
{"ANSI_874", {"ANSI_874", "CP874", "windows-874", "MS874", "x-windows-874", "TIS-620", "IBM1162",
|
||||
"x-IBM874"}}, // Latin/Thai
|
||||
{"ANSI_932", {"ANSI_932", "CP932", "SHIFT-JIS", "SHIFT_JIS", "CSSHIFTJIS", "CSWINDOWS31J", "MS_KANJI",
|
||||
"X-MS-CP932", "X-SJIS", "EUCJP", "EUC-JP", "CSEUCPKDFMTJAPANESE", "X-EUC", "X-EUC-JP", "IBM-943",
|
||||
"JIS7"}}, // Japanese
|
||||
{"ANSI_936", {"ANSI_936", "GBK", "CP936", "MS936", "Windows-936", "GB2312",
|
||||
"CHINESE"}}, // Chinese PRC GBK (XGB) simplified
|
||||
{"ANSI_949", {"ANSI_949", "Windows-949", "MS949", "CP949"}}, // Korean
|
||||
{"ANSI_950", {"ANSI_950", "BIG5", "windows-950-2000", "csBig5", "windows-950", "x-windows-950", "x-big5",
|
||||
"ms950"}}, // Chinese Big5 (Taiwan, Hong Kong SAR)
|
||||
{"ANSI_1250", {"ANSI_1250", "CP1250", "windows-1250", "ibm-1250_P100-1995",
|
||||
"ibm-1250"}}, //Central Europe and Eastern Europe
|
||||
{"ANSI_1251", {"ANSI_1251", "CP1251", "windows-1251", "ANSI1251", "ibm-5347_P100-1998",
|
||||
"ibm-5347"}}, // Cyrillic script
|
||||
{"ANSI_1252", {"ANSI_1252", "CP1252", "windows-1252", "LATIN1", "ISO-8859-1", "CP819", "CSISO", "IBM819",
|
||||
"ISO_8859-1", "APPLE ROMAN", "ISO8859-1", "ISO8859-15", "ISO-IR-100", "L1",
|
||||
"IBM 850", "850"}}, // Western Europe
|
||||
{"ANSI_1253", {"ANSI_1253", "CP1253", "windows-1253"}}, // Greek
|
||||
{"ANSI_1254", {"ANSI_1254", "CP1254", "windows-1254"}}, // Turkish
|
||||
{"ANSI_1255", {"ANSI_1255", "CP1255", "windows-1255"}}, // Hebrew
|
||||
{"ANSI_1256", {"ANSI_1256", "CP1256", "windows-1256", "x-windows-1256S"}}, // Arabic
|
||||
{"ANSI_1257", {"ANSI_1257", "CP1257", "windows-1257"}}, // Baltic
|
||||
{"ANSI_1258", {"ANSI_1258", "CP1258", "windows-1258"}}, // Vietnamese
|
||||
{"UTF-8", {"UTF-8", "UTF8", "UTF8-BIT"}},
|
||||
{"UTF-16", {"UTF-16", "UTF16", "UTF16-BIT"}},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
DRW_TextCodec::DRW_TextCodec()
|
||||
: version(DRW::AC1021),
|
||||
cp(),
|
||||
|
@ -58,17 +93,17 @@ void DRW_TextCodec::setCodePage(const std::string *c, bool dxfFormat){
|
|||
{ //DXF older than 2007 are write in win codepages
|
||||
cp = "ANSI_1252";
|
||||
}
|
||||
conv = QTextCodec::codecForName(cp.c_str());
|
||||
conv = DRW_TextCodec::CodecForName(QString::fromStdString(cp));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dxfFormat)
|
||||
{
|
||||
conv = QTextCodec::codecForName("UTF-8");
|
||||
conv = DRW_TextCodec::CodecForName(QString::fromStdString("UTF-8"));
|
||||
}
|
||||
else
|
||||
{
|
||||
conv = QTextCodec::codecForName("UTF-16");
|
||||
conv = DRW_TextCodec::CodecForName(QString::fromStdString("UTF-16"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,9 +113,61 @@ void DRW_TextCodec::setCodePage(const std::string *c, bool dxfFormat){
|
|||
.arg(cp.c_str());
|
||||
qApp->IsPedantic() ? throw VException(errorMsg) :
|
||||
qWarning() << VAbstractApplication::patternMessageSignature + errorMsg;
|
||||
|
||||
if (version < DRW::AC1021 && cp == "UTF-8")
|
||||
{
|
||||
cp = "ANSI_1252";
|
||||
conv = DRW_TextCodec::CodecForName(QString::fromStdString(cp)); // Fallback to latin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QMap<QString, QStringList> DRW_TextCodec::DXFCodePageMap()
|
||||
{
|
||||
return QMap<QString, QStringList>
|
||||
{
|
||||
{"ANSI_874", {"ANSI_874", "CP874", "ISO8859-11", "TIS-620"}}, // Latin/Thai
|
||||
{"ANSI_932", {"ANSI_932", "SHIFT-JIS", "SHIFT_JIS", "CSSHIFTJIS", "CSWINDOWS31J", "MS_KANJI", "X-MS-CP932",
|
||||
"X-SJIS", "EUCJP", "EUC-JP", "CSEUCPKDFMTJAPANESE", "X-EUC", "X-EUC-JP", "CP932",
|
||||
"JIS7"}}, // Japanese
|
||||
{"ANSI_936", {"ANSI_936", "GBK", "GB2312", "CHINESE", "CN-GB", "CSGB2312", "CSGB231280", "CSISO58BG231280",
|
||||
"GB_2312-80", "GB231280", "GB2312-80", "ISO-IR-58", "GB18030"}}, // Chinese PRC GBK (XGB) simplified
|
||||
{"ANSI_949", {"ANSI_949", "EUCKR"}}, // Korean
|
||||
{"ANSI_950", {"ANSI_950", "BIG5", "CN-BIG5", "CSBIG5", "X-X-BIG5",
|
||||
"BIG5-HKSCS"}}, // Chinese Big5 (Taiwan, Hong Kong SAR)
|
||||
{"ANSI_1250", {"ANSI_1250", "CP1250", "ISO8859-2"}}, //Central Europe and Eastern Europe
|
||||
{"ANSI_1251", {"ANSI_1251", "CP1251", "ISO8859-5", "KOI8-R", "KOI8-U", "IBM 866"}}, // Cyrillic script
|
||||
{"ANSI_1252", {"ANSI_1252", "CP1252", "LATIN1", "ISO-8859-1", "CP819", "CSISO", "IBM819", "ISO_8859-1",
|
||||
"APPLE ROMAN", "ISO8859-1", "ISO8859-15", "ISO-IR-100", "L1", "IBM 850"}}, // Western Europe
|
||||
{"ANSI_1253", {"ANSI_1253", "CP1253", "ISO8859-7"}}, // Greek
|
||||
{"ANSI_1254", {"ANSI_1254", "CP1254", "ISO8859-9", "iso8859-3"}}, // Turkish
|
||||
{"ANSI_1255", {"ANSI_1255", "CP1255", "ISO8859-8"}}, // Hebrew
|
||||
{"ANSI_1256", {"ANSI_1256", "CP1256", "ISO8859-6"}}, // Arabic
|
||||
{"ANSI_1257", {"ANSI_1257", "CP1257", "ISO8859-4", "ISO8859-10", "ISO8859-13"}}, // Baltic
|
||||
{"ANSI_1258", {"ANSI_1258", "CP1258"}}, // Vietnamese
|
||||
{"UTF-8", {"UTF-8", "UTF8", "UTF8-BIT"}},
|
||||
{"UTF-16", {"UTF-16", "UTF16", "UTF16-BIT"}},
|
||||
};
|
||||
}
|
||||
|
||||
QTextCodec *DRW_TextCodec::CodecForName(const QString &name)
|
||||
{
|
||||
QMap<QString, QStringList> knownCodecs = QtCodecs();
|
||||
if (knownCodecs.contains(name))
|
||||
{
|
||||
QStringList aliases = knownCodecs.value(name);
|
||||
for (auto &alias : aliases)
|
||||
{
|
||||
if (QTextCodec *codec = QTextCodec::codecForName(alias.toLatin1()))
|
||||
{
|
||||
return codec;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string DRW_TextCodec::toUtf8(const std::string &s) {
|
||||
if (conv == nullptr)
|
||||
{
|
||||
|
@ -103,73 +190,18 @@ std::string DRW_TextCodec::fromUtf8(const std::string &s) {
|
|||
|
||||
std::string DRW_TextCodec::correctCodePage(const std::string& s) {
|
||||
//stringstream cause crash in OS/X, bug#3597944
|
||||
std::string cp=s;
|
||||
transform(cp.begin(), cp.end(), cp.begin(), toupper);
|
||||
//Latin/Thai
|
||||
if (cp=="ANSI_874" || cp=="CP874" || cp=="ISO8859-11" || cp=="TIS-620") {
|
||||
return "ANSI_874";
|
||||
//Central Europe and Eastern Europe
|
||||
} else if (cp=="ANSI_1250" || cp=="CP1250" || cp=="ISO8859-2") {
|
||||
return "ANSI_1250";
|
||||
//Cyrillic script
|
||||
} else if (cp=="ANSI_1251" || cp=="CP1251" || cp=="ISO8859-5" || cp=="KOI8-R" ||
|
||||
cp=="KOI8-U" || cp=="IBM 866") {
|
||||
return "ANSI_1251";
|
||||
//Western Europe
|
||||
} else if (cp=="ANSI_1252" || cp=="CP1252" || cp=="LATIN1" || cp=="ISO-8859-1" ||
|
||||
cp=="CP819" || cp=="CSISO" || cp=="IBM819" || cp=="ISO_8859-1" || cp=="APPLE ROMAN" ||
|
||||
cp=="ISO8859-1" || cp=="ISO8859-15" || cp=="ISO-IR-100" || cp=="L1" || cp=="IBM 850") {
|
||||
return "ANSI_1252";
|
||||
//Greek
|
||||
} else if (cp=="ANSI_1253" || cp=="CP1253" || cp=="iso8859-7") {
|
||||
return "ANSI_1253";
|
||||
//Turkish
|
||||
} else if (cp=="ANSI_1254" || cp=="CP1254" || cp=="iso8859-9" || cp=="iso8859-3") {
|
||||
return "ANSI_1254";
|
||||
//Hebrew
|
||||
} else if (cp=="ANSI_1255" || cp=="CP1255" || cp=="iso8859-8") {
|
||||
return "ANSI_1255";
|
||||
//Arabic
|
||||
} else if (cp=="ANSI_1256" || cp=="CP1256" || cp=="ISO8859-6") {
|
||||
return "ANSI_1256";
|
||||
//Baltic
|
||||
} else if (cp=="ANSI_1257" || cp=="CP1257" || cp=="ISO8859-4" || cp=="ISO8859-10" || cp=="ISO8859-13") {
|
||||
return "ANSI_1257";
|
||||
//Vietnamese
|
||||
} else if (cp=="ANSI_1258" || cp=="CP1258") {
|
||||
return "ANSI_1258";
|
||||
QString cp = QString::fromStdString(s);
|
||||
cp = cp.toUpper();
|
||||
QMap<QString, QStringList> codeMap = DRW_TextCodec::DXFCodePageMap();
|
||||
|
||||
//Japanese
|
||||
} else if (cp=="ANSI_932" || cp=="SHIFT-JIS" || cp=="SHIFT_JIS" || cp=="CSSHIFTJIS" ||
|
||||
cp=="CSWINDOWS31J" || cp=="MS_KANJI" || cp=="X-MS-CP932" || cp=="X-SJIS" ||
|
||||
cp=="EUCJP" || cp=="EUC-JP" || cp=="CSEUCPKDFMTJAPANESE" || cp=="X-EUC" ||
|
||||
cp=="X-EUC-JP" || cp=="JIS7") {
|
||||
return "ANSI_932";
|
||||
//Chinese PRC GBK (XGB) simplified
|
||||
} else if (cp=="ANSI_936" || cp=="GBK" || cp=="GB2312" || cp=="CHINESE" || cp=="CN-GB" ||
|
||||
cp=="CSGB2312" || cp=="CSGB231280" || cp=="CSISO58BG231280" ||
|
||||
cp=="GB_2312-80" || cp=="GB231280" || cp=="GB2312-80" ||
|
||||
cp=="ISO-IR-58" || cp=="GB18030") {
|
||||
return "ANSI_936";
|
||||
//Korean
|
||||
} else if (cp=="ANSI_949" || cp=="EUCKR") {
|
||||
return "ANSI_949";
|
||||
//Chinese Big5 (Taiwan, Hong Kong SAR)
|
||||
} else if (cp=="ANSI_950" || cp=="BIG5" || cp=="CN-BIG5" || cp=="CSBIG5" ||
|
||||
cp=="X-X-BIG5" || cp=="BIG5-HKSCS") {
|
||||
return "ANSI_950";
|
||||
|
||||
//celtic
|
||||
/* } else if (cp=="ISO8859-14") {
|
||||
return "ISO8859-14";
|
||||
} else if (cp=="TSCII") {
|
||||
return "TSCII"; //tamil
|
||||
}*/
|
||||
|
||||
} else if (cp=="UTF-8" || cp=="UTF8" || cp=="UTF8-BIT") {
|
||||
return "UTF-8";
|
||||
} else if (cp=="UTF-16" || cp=="UTF16" || cp=="UTF16-BIT") {
|
||||
return "UTF-16";
|
||||
auto i = codeMap.constBegin();
|
||||
while (i != codeMap.constEnd())
|
||||
{
|
||||
if (i.value().contains(cp))
|
||||
{
|
||||
return i.key().toStdString();
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
return "ANSI_1252";
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QtGlobal>
|
||||
|
||||
class QTextCodec;
|
||||
class QStringList;
|
||||
|
||||
class DRW_TextCodec
|
||||
{
|
||||
|
@ -19,6 +20,9 @@ public:
|
|||
void setCodePage(const std::string &c, bool dxfFormat){setCodePage(&c, dxfFormat);}
|
||||
std::string getCodePage() const {return cp;}
|
||||
|
||||
static QMap<QString, QStringList> DXFCodePageMap();
|
||||
static QTextCodec* CodecForName(const QString &name);
|
||||
|
||||
private:
|
||||
std::string correctCodePage(const std::string& s);
|
||||
|
||||
|
|
|
@ -241,27 +241,28 @@ void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int h
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QStringList SupportedLocales()
|
||||
{
|
||||
const QStringList locales = QStringList() << QStringLiteral("ru_RU")
|
||||
<< QStringLiteral("uk_UA")
|
||||
<< QStringLiteral("de_DE")
|
||||
<< QStringLiteral("cs_CZ")
|
||||
<< QStringLiteral("he_IL")
|
||||
<< QStringLiteral("fr_FR")
|
||||
<< QStringLiteral("it_IT")
|
||||
<< QStringLiteral("nl_NL")
|
||||
<< QStringLiteral("id_ID")
|
||||
<< QStringLiteral("es_ES")
|
||||
<< QStringLiteral("fi_FI")
|
||||
<< QStringLiteral("en_US")
|
||||
<< QStringLiteral("en_CA")
|
||||
<< QStringLiteral("en_IN")
|
||||
<< QStringLiteral("ro_RO")
|
||||
<< QStringLiteral("zh_CN")
|
||||
<< QStringLiteral("pt_BR")
|
||||
<< QStringLiteral("el_GR")
|
||||
<< QStringLiteral("pl_PL");
|
||||
|
||||
return locales;
|
||||
return QStringList
|
||||
{
|
||||
"ru_RU",
|
||||
"uk_UA",
|
||||
"de_DE",
|
||||
"cs_CZ",
|
||||
"he_IL",
|
||||
"fr_FR",
|
||||
"it_IT",
|
||||
"nl_NL",
|
||||
"id_ID",
|
||||
"es_ES",
|
||||
"fi_FI",
|
||||
"en_US",
|
||||
"en_CA",
|
||||
"en_IN",
|
||||
"ro_RO",
|
||||
"zh_CN",
|
||||
"pt_BR",
|
||||
"el_GR",
|
||||
"pl_PL"
|
||||
};
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -52,6 +52,7 @@ DEFINES += SRCDIR=\\\"$$PWD/\\\"
|
|||
|
||||
SOURCES += \
|
||||
qttestmainlambda.cpp \
|
||||
tst_dxf.cpp \
|
||||
tst_vdomdocument.cpp \
|
||||
tst_vposter.cpp \
|
||||
tst_vspline.cpp \
|
||||
|
@ -79,6 +80,7 @@ SOURCES += \
|
|||
*msvc*:SOURCES += stable.cpp
|
||||
|
||||
HEADERS += \
|
||||
tst_dxf.h \
|
||||
tst_vdomdocument.h \
|
||||
tst_vposter.h \
|
||||
tst_vspline.h \
|
||||
|
@ -211,6 +213,15 @@ DEPENDPATH += $$PWD/../../libs/vgeometry
|
|||
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/vgeometry.lib
|
||||
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/libvgeometry.a
|
||||
|
||||
# VDxf static library
|
||||
unix|win32: LIBS += -L$$OUT_PWD/../../libs/vdxf/$${DESTDIR}/ -lvdxf
|
||||
|
||||
INCLUDEPATH += $$PWD/../../libs/vdxf
|
||||
DEPENDPATH += $$PWD/../../libs/vdxf
|
||||
|
||||
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vdxf/$${DESTDIR}/vdxf.lib
|
||||
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vdxf/$${DESTDIR}/libvdxf.a
|
||||
|
||||
# QMuParser library
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "tst_vtranslatevars.h"
|
||||
#include "tst_vtooluniondetails.h"
|
||||
#include "tst_vdomdocument.h"
|
||||
#include "tst_dxf.h"
|
||||
|
||||
#include "../vmisc/def.h"
|
||||
#include "../qmuparser/qmudef.h"
|
||||
|
@ -94,6 +95,7 @@ int main(int argc, char** argv)
|
|||
ASSERT_TEST(new TST_ReadVal());
|
||||
ASSERT_TEST(new TST_VTranslateVars());
|
||||
ASSERT_TEST(new TST_VToolUnionDetails());
|
||||
ASSERT_TEST(new TST_DXF());
|
||||
|
||||
return status;
|
||||
}
|
||||
|
|
118
src/test/ValentinaTest/tst_dxf.cpp
Normal file
118
src/test/ValentinaTest/tst_dxf.cpp
Normal file
|
@ -0,0 +1,118 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file tst_dxf.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 15 1, 2020
|
||||
**
|
||||
** @brief
|
||||
** @copyright
|
||||
** This source code is part of the Valentina project, a pattern making
|
||||
** program, whose allow create and modeling patterns of clothing.
|
||||
** Copyright (C) 2020 Valentina project
|
||||
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||
**
|
||||
** Valentina is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** Valentina is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
#include "tst_dxf.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
#include "../vmisc/def.h"
|
||||
#include "../vdxf/dxfdef.h"
|
||||
#include "../vdxf/libdxfrw/intern/drw_textcodec.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QStringList AvailableCodecs()
|
||||
{
|
||||
QList<QByteArray> codecs = QTextCodec::availableCodecs();
|
||||
QSet<QString> uniqueNames;
|
||||
for(auto &codec: codecs)
|
||||
{
|
||||
uniqueNames.insert(codec);
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
return QStringList(uniqueNames.begin(), uniqueNames.end());
|
||||
#else
|
||||
return QStringList(uniqueNames.toList());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
TST_DXF::TST_DXF(QObject *parent)
|
||||
:QObject(parent)
|
||||
{}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_DXF::initTestCase()
|
||||
{
|
||||
QTextStream ts(stdout);
|
||||
ts << QStringLiteral("Available codecs:\n%2.").arg(AvailableCodecs().join(", "))<< endl;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_DXF::TestCodecPage_data()
|
||||
{
|
||||
QTest::addColumn<QString>("locale");
|
||||
|
||||
QStringList locales = SupportedLocales();
|
||||
|
||||
for (auto & locale : locales)
|
||||
{
|
||||
QTest::newRow(locale.toLatin1()) << locale;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TST_DXF::TestCodecPage()
|
||||
{
|
||||
QFETCH(QString, locale);
|
||||
|
||||
static QMap <QString, QString> locMap = LocaleMap();
|
||||
locMap.insert("en", "ISO8859-1");
|
||||
locMap.insert("en_US", "ISO8859-1");
|
||||
locMap.insert("en_CA", "ISO8859-1");
|
||||
locMap.insert("en_IN", "ISO8859-1");
|
||||
|
||||
QString language = QLocale(locale).name();
|
||||
QVERIFY (locMap.contains(language));
|
||||
|
||||
QString codePage = locMap.value(language);
|
||||
codePage = codePage.toUpper();
|
||||
QMap<QString, QStringList> codeMap = DRW_TextCodec::DXFCodePageMap();
|
||||
|
||||
QString dxfCodePage;
|
||||
|
||||
auto i = codeMap.constBegin();
|
||||
while (i != codeMap.constEnd())
|
||||
{
|
||||
if (i.value().contains(codePage))
|
||||
{
|
||||
dxfCodePage = i.key();
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
QVERIFY (not dxfCodePage.isEmpty());
|
||||
|
||||
QTextCodec *codec = DRW_TextCodec::CodecForName(dxfCodePage);
|
||||
|
||||
QVERIFY2(codec != nullptr, qUtf8Printable(QStringLiteral("No codec for dxf codepage %1 found.")
|
||||
.arg(dxfCodePage)));
|
||||
}
|
49
src/test/ValentinaTest/tst_dxf.h
Normal file
49
src/test/ValentinaTest/tst_dxf.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file tst_dxf.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 15 1, 2020
|
||||
**
|
||||
** @brief
|
||||
** @copyright
|
||||
** This source code is part of the Valentina project, a pattern making
|
||||
** program, whose allow create and modeling patterns of clothing.
|
||||
** Copyright (C) 2020 Valentina project
|
||||
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||
**
|
||||
** Valentina is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** Valentina is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
#ifndef TST_DXF_H
|
||||
#define TST_DXF_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class TST_DXF :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TST_DXF(QObject *parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void TestCodecPage_data();
|
||||
void TestCodecPage();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(TST_DXF)
|
||||
};
|
||||
|
||||
#endif // TST_DXF_H
|
Loading…
Reference in New Issue
Block a user