From d489167f9537ed27872eec663b9de050480ea5d1 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 9 Jun 2014 08:27:40 +0000 Subject: [PATCH] EgtExchange 1.5f3 : - migliorata conversione testi da Codepage diverse e da codifica Unicode di Autocad. --- EgtExchange.rc | Bin 11478 -> 11478 bytes EgtExchange.vcxproj | 1 + EgtExchange.vcxproj.filters | 3 ++ ImportDxf.cpp | 11 +++++- ImportDxf.h | 2 + ImportDxfEnts.cpp | 31 ++++++++++++---- ImportDxfHeader.cpp | 72 ++++++++++++++++++++++++++++++++++++ 7 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 ImportDxfHeader.cpp diff --git a/EgtExchange.rc b/EgtExchange.rc index 74866d3f3d989ef6218effe6810ba5be7123bc4b..fe3b3ab4ade071889ad88937c13ed362db6d5298 100644 GIT binary patch delta 102 zcmcZ>c`b6oH#SD&&4O|VnIc`b6oH#SD2&4O|VnI + diff --git a/EgtExchange.vcxproj.filters b/EgtExchange.vcxproj.filters index 57137e1..f3def4d 100644 --- a/EgtExchange.vcxproj.filters +++ b/EgtExchange.vcxproj.filters @@ -74,6 +74,9 @@ File di origine + + File di origine + diff --git a/ImportDxf.cpp b/ImportDxf.cpp index 70063f7..d8620ec 100644 --- a/ImportDxf.cpp +++ b/ImportDxf.cpp @@ -39,6 +39,7 @@ ImportDxf::ImportDxf( void) m_nCurrCode = CODE_NULL ; m_nIdBlocksParent = GDB_ID_NULL ; m_nIdCurrBlock = GDB_ID_NULL ; + m_nCodePage = 1252 ; } //---------------------------------------------------------------------------- @@ -80,6 +81,9 @@ ImportDxf::Import( const string& sFile, IGeomDB* pGDB, int nIdGroup, double dSca if ( ! CreateBlocksParent()) return false ; + // imposto la codepage di default ( 1252 = ANSI Latin 1) + m_nCodePage = 1252 ; + // ciclo di lettura bool bOk = true ; bool bFileEnd = false ; @@ -88,8 +92,13 @@ ImportDxf::Import( const string& sFile, IGeomDB* pGDB, int nIdGroup, double dSca // leggo intestazione sezione, per avere il tipo bool bOkLoc = GetSectionName( sSectName, bFileEnd) ; if ( bOkLoc && ! bFileEnd) { + // se sezione header + if ( sSectName == "HEADER") { + if ( ! ReadHeader( bFileEnd)) + bOkLoc = false ; + } // se sezione tavole - if ( sSectName == "TABLES") { + else if ( sSectName == "TABLES") { if ( ! ReadTables( bFileEnd)) bOkLoc = false ; } diff --git a/ImportDxf.h b/ImportDxf.h index db83472..4fc3b16 100644 --- a/ImportDxf.h +++ b/ImportDxf.h @@ -51,6 +51,7 @@ class ImportDxf : public IImportDxf bool EraseEmptyLayers( void) ; int GetGroupId( const std::string& sName) ; bool BlockReading( void) ; + bool ReadHeader( bool& bFileEnd) ; bool ReadTables( bool& bFileEnd) ; bool GetTableName( std::string& sTabName, bool& bSectEnd, bool& bFileEnd) ; bool SkipTable( bool& bFileEnd) ; @@ -122,6 +123,7 @@ class ImportDxf : public IImportDxf bool m_bUnGet ; int m_nCurrCode ; std::string m_sCurrItem ; + int m_nCodePage ; NameMap m_nmLayer ; StyleMap m_smStyle ; int m_nIdBlocksParent ; diff --git a/ImportDxfEnts.cpp b/ImportDxfEnts.cpp index d5f652a..2b9b8d8 100644 --- a/ImportDxfEnts.cpp +++ b/ImportDxfEnts.cpp @@ -27,7 +27,7 @@ #include "/EgtDev/Include/EgkSurfTriMesh.h" #include "/EgtDev/Include/EgkExtText.h" #include "/EgtDev/Include/EGkGdbIterator.h" -#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EGnStringEncoder.h" #include using namespace std ; @@ -2131,10 +2131,25 @@ ImportDxf::ReadText( bool& bFileEnd) bool ImportDxf::AdjustText( string& sText) { - // per gradi, più o meno e diametro con codici Unicode - ReplaceString( sText, "\\U+00B0", LPSTR( WtoA( L"°"))) ; - ReplaceString( sText, "\\U+00B1", LPSTR( WtoA( L"±"))) ; - ReplaceString( sText, "\\U+2205", LPSTR( WtoA( L"Ø"))) ; + // se non è testo UTF-8, tento di convertirlo secondo codepage dichiarata nel DXF + if ( ! IsTextUtf8( sText.c_str())) { + sText = LPSTR( WtoA( LPWSTR( AtoW( sText.c_str(), m_nCodePage)))) ; + } + + // converto la codifica Unicode di AutoCad ( "\\U+NNNN") + size_t nPos ; + while ( ( nPos = sText.find( "\\U+")) != string::npos) { + string sCode = (( sText.size() > nPos + 3) ? sText.substr( nPos+3, 4) : "") ; + unsigned int nCode = 127 ; + sscanf_s( sCode.c_str(), "%x", &nCode) ; + // converto diametro in O maiuscolo barrato + if ( nCode == 8709) + nCode = 216 ; + string sVal ; + if ( ! SetCodePoint( nCode, sVal)) + sVal = "\7F" ; // carattere di errore 127 + ReplaceString( sText, "\\U+" + sCode, sVal) ; + } // se non ci sono "%%" posso uscire if ( sText.find( "%%") == string::npos) @@ -2325,11 +2340,11 @@ ImportDxf::AdjustMText( string& sText, double dTextMaxWidth, double dW) return false ; // elimino \L \k - sText = tr1::regex_replace( sText, tr1::regex( "\\\\[LlOoKk]"), string("")) ; + sText = tr1::regex_replace( sText, tr1::regex( "\\\\[LlOoKk]"), string( "")) ; // elimino \p...; \T...; - sText = tr1::regex_replace( sText, tr1::regex( "\\\\[pQHWFfACT][^;]*;"), string("")) ; + sText = tr1::regex_replace( sText, tr1::regex( "\\\\[pQHWFfACT][^;]*;"), string( "")) ; // trasformo \Sxxx; in xxx - sText = tr1::regex_replace( sText, tr1::regex( "\\\\[S]([^;]*);"), string("$1")) ; + sText = tr1::regex_replace( sText, tr1::regex( "\\\\[S]([^;]*);"), string( "$1")) ; // traformo "\~" in ' ' ReplaceString( sText, "\\~", " ") ; // trasformo "\P" in "\n" diff --git a/ImportDxfHeader.cpp b/ImportDxfHeader.cpp new file mode 100644 index 0000000..3b200f4 --- /dev/null +++ b/ImportDxfHeader.cpp @@ -0,0 +1,72 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : ImportDxfHeader.cpp Data : 08.06.14 Versione : 1.5f3 +// Contenuto : Implementazione di ImportDxf : gestione header. +// +// +// +// Modifiche : 08.06.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "ImportDxf.h" +#include "DxfConst.h" +#include "DllMain.h" +#include "/EgtDev/Include/EGnStringUtils.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +bool +ImportDxf::ReadHeader( bool& bFileEnd) +{ + // ciclo di lettura + bool bOk = true ; + bool bSectEnd = false ; + bool bCodePage = false ; + bFileEnd = false ; + int nCode = CODE_NULL ; + do { + // leggo un Item + nCode = ReadNextItem() ; + if ( nCode == CODE_NULL) { + bFileEnd = true ; + return false ; + } + switch ( nCode) { + case 0 : + if ( m_sCurrItem == "SECTION") { + UngetItem() ; + bSectEnd = true ; + } + else if ( m_sCurrItem == "ENDSEC") { + bSectEnd = true ; + } + else if ( m_sCurrItem == "EOF") { + bSectEnd = true ; + bFileEnd = true ; + } + break ; + case 3 : + if ( bCodePage) { + string sCodePage = m_sCurrItem ; + ReplaceString( sCodePage, "ANSI_", "") ; + ReplaceString( sCodePage, "DOS", "") ; + int nVal ; + if ( FromString( sCodePage, nVal) && nVal >= 111 && nVal <= 28606) + m_nCodePage = nVal ; + } + break ; + case 9 : + if ( m_sCurrItem == "$DWGCODEPAGE") + bCodePage = true ; + break ; + } + } while ( ! bSectEnd) ; + + return bOk ; +}