Commit bc7a0692 authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

X2t добавлен Txt File Converter

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62352 954022d7-b5bf-4e40-9824-e11837661b57
parent 8bfb976f
...@@ -55,7 +55,7 @@ namespace BinXlsxRW{ ...@@ -55,7 +55,7 @@ namespace BinXlsxRW{
sMediaPath = pathMediaDir.GetPath(); sMediaPath = pathMediaDir.GetPath();
} }
bool CXlsxSerializer::loadFromFile(const CString& sSrcFileName, const CString& sDstPath, CString& sXMLOptions, CString& sMediaDir) bool CXlsxSerializer::loadFromFile(const CString& sSrcFileName, const CString& sDstPath, const CString& sXMLOptions, CString& sMediaDir)
{ {
NSBinPptxRW::CDrawingConverter oOfficeDrawingConverter; NSBinPptxRW::CDrawingConverter oOfficeDrawingConverter;
oOfficeDrawingConverter.SetMediaDstPath(sMediaDir); oOfficeDrawingConverter.SetMediaDstPath(sMediaDir);
......
...@@ -28,7 +28,7 @@ namespace BinXlsxRW { ...@@ -28,7 +28,7 @@ namespace BinXlsxRW {
void CreateXlsxFolders(CString& sXmlOptions, CString sDstPath, CString& sMediaPath); void CreateXlsxFolders(CString& sXmlOptions, CString sDstPath, CString& sMediaPath);
bool loadFromFile(const CString& sSrcFileName, const CString& sDstPath, CString& sXMLOptions, CString& sMediaDir); bool loadFromFile(const CString& sSrcFileName, const CString& sDstPath, const CString& sXMLOptions, CString& sMediaDir);
bool saveToFile(const CString& sSrcFileName, const CString& sDstPath, CString& sXMLOptions); bool saveToFile(const CString& sSrcFileName, const CString& sDstPath, CString& sXMLOptions);
bool loadChart(CString& sChartPath, NSBinPptxRW::CBinaryFileWriter& oBufferedStream, long& lDataSize); bool loadChart(CString& sChartPath, NSBinPptxRW::CBinaryFileWriter& oBufferedStream, long& lDataSize);
......
...@@ -18,7 +18,7 @@ LIBS += -lxml2 ...@@ -18,7 +18,7 @@ LIBS += -lxml2
INCLUDEPATH += \ INCLUDEPATH += \
/usr/include/libxml2 /usr/include/libxml2
SOURCES += RtfFormatLib.cpp \ SOURCES += \
../source/DestinationCommand.cpp \ ../source/DestinationCommand.cpp \
../source/RtfBookmark.cpp \ ../source/RtfBookmark.cpp \
../source/RtfChar.cpp \ ../source/RtfChar.cpp \
...@@ -38,9 +38,10 @@ SOURCES += RtfFormatLib.cpp \ ...@@ -38,9 +38,10 @@ SOURCES += RtfFormatLib.cpp \
../source/Reader/OOXShapeReader.cpp \ ../source/Reader/OOXShapeReader.cpp \
../source/Reader/OOXTableReader.cpp \ ../source/Reader/OOXTableReader.cpp \
../source/Writer/OOXDocumentWriter.cpp \ ../source/Writer/OOXDocumentWriter.cpp \
../source/Writer/OOXWriter.cpp ../source/Writer/OOXWriter.cpp \
../source/ConvertationManager.cpp
HEADERS += RtfFormatLib.h \ HEADERS += \
../source/Basic.h \ ../source/Basic.h \
../source/ConvertationManager.h \ ../source/ConvertationManager.h \
../source/DestinationCommand.h \ ../source/DestinationCommand.h \
......
#include "ConvertationManager.h"
#pragma once
#include "RtfReader.h"
#include "RtfDocument.h"
#include "RtfWriter.h"
#include "Writer/OOXWriter.h"
#include "Reader/OOXReader.h"
const double g_cdMaxReadRtfPercent = 0.70;
const double g_cdMaxWriteRtfPercent = 0.30;
const double g_cdMaxReadOoxPercent = 0.70;
const double g_cdMaxWriteOoxPercent = 0.30;
//#define MEMORY_SAFE_CONVERTATION
HRESULT RtfConvertationManager::ConvertRtfToOOX( std::wstring sSrcFileName, std::wstring sDstPath )
{
m_bParseFirstItem = true;
RtfDocument oDocument;
oDocument.m_oProperty.SetDefaultRtf();
RtfReader oReader( oDocument, sSrcFileName );
OOXWriter oWriter( oDocument, sDstPath );
if (m_sTempFolder.length()< 1)
m_sTempFolder = FileSystem::Directory::GetTempPath();
oReader.m_sTempFolder = FileSystem::Directory::CreateDirectoryWithUniqueName(m_sTempFolder);
oWriter.m_sTempFolder = FileSystem::Directory::CreateDirectoryWithUniqueName(m_sTempFolder);
m_poRtfReader = &oReader;
m_poOOXWriter = &oWriter;
m_poRtfReader->m_convertationManager = this;
bool succes = oReader.Load( );
//сохранение будет поэлементое в обработчике OnCompleteItemRtf
//надо только завершить
if( true == m_bParseFirstItem )
{
m_bParseFirstItem = false;
oWriter.SaveByItemStart( );
}
m_poOOXWriter->SaveByItem();
oWriter.SaveByItemEnd( );
FileSystem::Directory::DeleteDirectory(oReader.m_sTempFolder);
FileSystem::Directory::DeleteDirectory(oWriter.m_sTempFolder);
if( true == succes )
return S_OK;
else
return S_FALSE;
}
HRESULT RtfConvertationManager::ConvertOOXToRtf( std::wstring sDstFileName, std::wstring sSrcPath )
{
m_bParseFirstItem = true;
RtfDocument oDocument;
oDocument.m_oProperty.SetDefaultOOX();
OOXReader oReader( oDocument, sSrcPath );
RtfWriter oWriter( oDocument, sDstFileName, sSrcPath );
if (m_sTempFolder.length() < 1)
m_sTempFolder = FileSystem::Directory::GetTempPath();
oReader.m_sTempFolder = FileSystem::Directory::CreateDirectoryWithUniqueName(m_sTempFolder);
oWriter.m_sTempFolder = FileSystem::Directory::CreateDirectoryWithUniqueName(m_sTempFolder);
m_poOOXReader = &oReader;
m_poRtfWriter = &oWriter;
m_poOOXReader->m_convertationManager = this;
bool succes = oReader.Parse( );
if( true == succes)
{
succes = oWriter.Save( );
}
FileSystem::Directory::DeleteDirectory(oReader.m_sTempFolder);
FileSystem::Directory::DeleteDirectory(oWriter.m_sTempFolder);
if( true == succes) return S_OK;
return S_FALSE;
}
void RtfConvertationManager::OnCompleteItemRtf()
{
if( true == m_bParseFirstItem )
{
m_bParseFirstItem = false;
m_poOOXWriter->SaveByItemStart( );
}
m_poOOXWriter->SaveByItem();
}
void RtfConvertationManager::OnCompleteItemOOX()
{
if( true == m_bParseFirstItem )
{
m_bParseFirstItem = false;
m_poRtfWriter->SaveByItemStart( );
}
m_poRtfWriter->SaveByItem( );
}
#pragma once #pragma once
#include "RtfReader.h"
#include "RtfDocument.h"
#include "RtfWriter.h"
#include "Writer/OOXWriter.h"
#include "Reader/OOXReader.h"
#include <string>
const double g_cdMaxReadRtfPercent = 0.70; class OOXWriter;
const double g_cdMaxWriteRtfPercent = 0.30; class OOXReader;
const double g_cdMaxReadOoxPercent = 0.70; class RtfWriter;
const double g_cdMaxWriteOoxPercent = 0.30; class RtfReader;
//#define MEMORY_SAFE_CONVERTATION class RtfConvertationManager
class ConvertationManager
{ {
public: public:
CString m_sTempFolder; std::wstring m_sTempFolder;
ConvertationManager( )
{
}
HRESULT ConvertRtfToOOX( std::wstring sSrcFileName, std::wstring sDstPath, CString sXMLOptions )
{
m_bParseFirstItem = true;
RtfDocument oDocument;
oDocument.m_oProperty.SetDefaultRtf();
RtfReader oReader( oDocument, sSrcFileName );
OOXWriter oWriter( oDocument, sDstPath );
if (m_sTempFolder.GetLength() < 1)
m_sTempFolder = FileSystem::Directory::GetTempPath();
oReader.m_sTempFolder = FileSystem::Directory::CreateDirectoryWithUniqueName(m_sTempFolder);
oWriter.m_sTempFolder = FileSystem::Directory::CreateDirectoryWithUniqueName(m_sTempFolder);
m_poRtfReader = &oReader;
m_poOOXWriter = &oWriter;
m_poRtfReader->m_convertationManager = this; RtfConvertationManager( )
{
m_poOOXWriter = NULL;
m_poOOXReader = NULL;
bool succes = oReader.Load( ); m_poRtfWriter = NULL;
m_poRtfReader = NULL;
}
//сохранение будет поэлементое в обработчике OnCompleteItemRtf long ConvertRtfToOOX( std::wstring sSrcFileName, std::wstring sDstPath);
//надо только завершить
if( true == m_bParseFirstItem )
{
m_bParseFirstItem = false;
oWriter.SaveByItemStart( );
}
m_poOOXWriter->SaveByItem();
oWriter.SaveByItemEnd( );
FileSystem::Directory::DeleteDirectory(oReader.m_sTempFolder);
FileSystem::Directory::DeleteDirectory(oWriter.m_sTempFolder);
if( true == succes ) long ConvertOOXToRtf( std::wstring sDstFileName, std::wstring sSrcPath);
return S_OK;
else
return S_FALSE;
}
HRESULT ConvertOOXToRtf( std::wstring sDstFileName, std::wstring sSrcPath, CString sXMLOptions )
{
m_bParseFirstItem = true;
RtfDocument oDocument; void OnCompleteItemRtf();
oDocument.m_oProperty.SetDefaultOOX(); void OnCompleteItemOOX();
private:
OOXReader oReader( oDocument, sSrcPath ); OOXWriter* m_poOOXWriter;
RtfWriter oWriter( oDocument, sDstFileName, sSrcPath ); OOXReader* m_poOOXReader;
if (m_sTempFolder.GetLength() < 1)
m_sTempFolder = FileSystem::Directory::GetTempPath();
oReader.m_sTempFolder = FileSystem::Directory::CreateDirectoryWithUniqueName(m_sTempFolder);
oWriter.m_sTempFolder = FileSystem::Directory::CreateDirectoryWithUniqueName(m_sTempFolder);
m_poOOXReader = &oReader;
m_poRtfWriter = &oWriter;
m_poOOXReader->m_convertationManager = this;
bool succes = oReader.Parse( );
if( true == succes)
{
succes = oWriter.Save( );
}
FileSystem::Directory::DeleteDirectory(oReader.m_sTempFolder); RtfWriter* m_poRtfWriter;
FileSystem::Directory::DeleteDirectory(oWriter.m_sTempFolder); RtfReader* m_poRtfReader;
if( true == succes) return S_OK; bool m_bParseFirstItem;
return S_FALSE;
}
void OnCompleteItemRtf()
{
if( true == m_bParseFirstItem )
{
m_bParseFirstItem = false;
m_poOOXWriter->SaveByItemStart( );
}
m_poOOXWriter->SaveByItem();
}
void OnCompleteItemOOX()
{
if( true == m_bParseFirstItem )
{
m_bParseFirstItem = false;
m_poRtfWriter->SaveByItemStart( );
}
m_poRtfWriter->SaveByItem( );
}
private:
OOXWriter* m_poOOXWriter;
OOXReader* m_poOOXReader;
RtfWriter* m_poRtfWriter;
RtfReader* m_poRtfReader;
bool m_bParseFirstItem;
}; };
...@@ -1216,7 +1216,7 @@ void ParagraphPropDestination::AddItem( RtfParagraphPtr oItem, RtfReader& oReade ...@@ -1216,7 +1216,7 @@ void ParagraphPropDestination::AddItem( RtfParagraphPtr oItem, RtfReader& oReade
if (oReader.m_convertationManager) if (oReader.m_convertationManager)
{ {
oReader.m_convertationManager->OnCompleteItemRtf(); oReader.m_convertationManager->OnCompleteItemRtf();
} }
} }
//добавляем параграф //добавляем параграф
......
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
#include "../RtfField.h" #include "../RtfField.h"
#include "../../../../Common/DocxFormat/Source/DocxFormat/Docx.h" #include "../../../../Common/DocxFormat/Source/DocxFormat/Docx.h"
class ConvertationManager; class RtfConvertationManager;
class OOXReader class OOXReader
{ {
public: public:
ConvertationManager * m_convertationManager; RtfConvertationManager *m_convertationManager;
CString m_sPath; CString m_sPath;
int m_nCurItap; //для определение вложенности таблицы int m_nCurItap; //для определение вложенности таблицы
...@@ -47,4 +47,4 @@ private: ...@@ -47,4 +47,4 @@ private:
void ParseColorTable( RtfDocument& oDocument ); void ParseColorTable( RtfDocument& oDocument );
CString GetFolder ( CString sDocPath ); CString GetFolder ( CString sDocPath );
RtfDocument & m_oDocument; RtfDocument & m_oDocument;
}; };
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "RtfProperty.h" #include "RtfProperty.h"
#include "RtfDocument.h" #include "RtfDocument.h"
class ConvertationManager; class RtfConvertationManager;
class RtfReader class RtfReader
{ {
...@@ -11,7 +11,7 @@ public: ...@@ -11,7 +11,7 @@ public:
class ReaderState; class ReaderState;
typedef boost::shared_ptr<ReaderState> ReaderStatePtr; typedef boost::shared_ptr<ReaderState> ReaderStatePtr;
ConvertationManager *m_convertationManager; RtfConvertationManager *m_convertationManager;
class ReaderState class ReaderState
{ {
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
class RtfDocument; class RtfDocument;
//[ event_source(native)]
class RtfWriter class RtfWriter
{ {
public: public:
...@@ -48,4 +47,4 @@ private: ...@@ -48,4 +47,4 @@ private:
CString CreateRtfStart(); CString CreateRtfStart();
CString CreateRtfEnd( ); CString CreateRtfEnd( );
}; };
\ No newline at end of file
#-------------------------------------------------
#
# Project created by QtCreator 2015-04-29T13:41:59
#
#-------------------------------------------------
QT -= core gui
TARGET = TxtXmlFormatLib
TEMPLATE = lib
CONFIG += staticlib
QMAKE_CXXFLAGS += -std=c++11 -Wall -Wno-ignored-qualifiers
DEFINES += UNICODE \
_UNICODE \
LINUX \
_LINUX_QT \
_USE_LIBXML2_READER_ \
_USE_XMLLITE_READER_ \
USE_LITE_READER \
BUILD_CONFIG_FULL_VERSION \
DONT_WRITE_EMBEDDED_FONTS
INCLUDEPATH += \
../../../../DesktopEditor/freetype-2.5.2/include
INCLUDEPATH += /usr/include/libxml2
HEADERS += \
../Source/TxtXmlEvent.h \
../Source/TxtXmlFile.h \
../Source/Common/Encoding.h \
../Source/Common/precompiled_utility.h \
../Source/Common/StlUtils.h \
../Source/Common/ToString.h \
../Source/Common/Utility.h \
../Source/Docx2Txt/Converter.h \
../Source/Txt2Docx/Converter.h \
../Source/TxtFormat/File.h \
../Source/TxtFormat/TxtFile.h \
../Source/TxtFormat/TxtFormat.h
SOURCES += \
../Source/TxtXmlFile.cpp \
../Source/Common/Encoding.cpp \
../Source/Common/ToString.cpp \
../Source/Docx2Txt/Converter.cpp \
../Source/Txt2Docx/Converter.cpp \
../Source/TxtFormat/File.cpp \
../Source/TxtFormat/TxtFile.cpp
unix {
target.path = /usr/lib
INSTALLS += target
}
...@@ -4,11 +4,13 @@ ...@@ -4,11 +4,13 @@
#include "Encoding.h" #include "Encoding.h"
#include "Utility.h" #include "Utility.h"
#ifdef _WIN32 #if defined (_WIN32) || defined (_WIN64)
#include <windows.h> #include <windows.h>
#else
#include <iconv.h>
#endif #endif
#include "../../../../Base/unicode_util.h" #include "../../../Common/DocxFormat/Source/Base/unicode_util.h"
const std::wstring Encoding::ansi2unicode(const std::string& line) const std::wstring Encoding::ansi2unicode(const std::string& line)
...@@ -16,25 +18,53 @@ const std::wstring Encoding::ansi2unicode(const std::string& line) ...@@ -16,25 +18,53 @@ const std::wstring Encoding::ansi2unicode(const std::string& line)
return std::wstring(line.begin(), line.end());//cp2unicode(line, CP_ACP); return std::wstring(line.begin(), line.end());//cp2unicode(line, CP_ACP);
} }
const std::wstring Encoding::cp2unicode(const std::string& sline, const unsigned int codePage) const std::wstring Encoding::cp2unicode(const std::string& sline, const unsigned int nCodepage)
{ {
#ifdef _WIN32 #if defined (_WIN32) || defined (_WIN64)
const int nSize = MultiByteToWideChar(codePage, 0, sline.c_str(), sline.size(), NULL, 0); const int nSize = MultiByteToWideChar(codePage, 0, sline.c_str(), sline.size(), NULL, 0);
wchar_t *sTemp = new wchar_t[nSize]; wchar_t *sTemp = new wchar_t[nSize];
if (!sTemp) if (!sTemp)
return std::wstring(); return std::wstring();
int size = MultiByteToWideChar(codePage, 0, sline.c_str(), sline.size(), sTemp, nSize); int size = MultiByteToWideChar(nCodepage, 0, sline.c_str(), sline.size(), sTemp, nSize);
std::wstring sResult(sTemp, size); std::wstring sResult(sTemp, size);
delete []sTemp; delete []sTemp;
return sResult; return sResult;
#elif __linux__
return std::wstring();
#else #else
return std::wstring(); bool ansi = true;
size_t insize = sline.length();
std::wstring w_out;
w_out.reserve(insize);
char *inptr = (char*)sline.c_str();
char* outptr = (char*)w_out.c_str();
if (nCodepage > 0)
{
std::string sCodepage = "CP" + std::to_string(nCodepage);
iconv_t ic= iconv_open("WCHAR_T", sCodepage.c_str());
if (ic != (iconv_t) -1)
{
size_t nconv = 0, avail = (insize) * sizeof(wchar_t);
nconv = iconv (ic, &inptr, &insize, &outptr, &avail);
if (nconv == 0)
{
ansi = false;
}
iconv_close(ic);
}
}
if (ansi)
w_out = std::wstring(sline.begin(), sline.end());
return w_out;
#endif #endif
} }
...@@ -43,145 +73,171 @@ const std::wstring Encoding::utf82unicode(const std::string& line) ...@@ -43,145 +73,171 @@ const std::wstring Encoding::utf82unicode(const std::string& line)
{ {
if (sizeof(wchar_t) == 2)//utf8 -> utf16 if (sizeof(wchar_t) == 2)//utf8 -> utf16
{ {
unsigned __int32 nLength = line.length(); unsigned int nLength = line.length();
UTF16 *pStrUtf16 = new UTF16 [nLength+1]; UTF16 *pStrUtf16 = new UTF16 [nLength+1];
memset ((void *) pStrUtf16, 0, sizeof (UTF16) * (nLength+1)); memset ((void *) pStrUtf16, 0, sizeof (UTF16) * (nLength+1));
UTF8 *pStrUtf8 = (UTF8 *) &line[0]; UTF8 *pStrUtf8 = (UTF8 *) &line[0];
// this values will be modificated // this values will be modificated
const UTF8 *pStrUtf8_Conv = pStrUtf8; const UTF8 *pStrUtf8_Conv = pStrUtf8;
UTF16 *pStrUtf16_Conv = pStrUtf16; UTF16 *pStrUtf16_Conv = pStrUtf16;
ConversionResult eUnicodeConversionResult = ConvertUTF8toUTF16 (&pStrUtf8_Conv, &pStrUtf8[nLength] ConversionResult eUnicodeConversionResult = ConvertUTF8toUTF16 (&pStrUtf8_Conv, &pStrUtf8[nLength]
, &pStrUtf16_Conv, &pStrUtf16 [nLength] , &pStrUtf16_Conv, &pStrUtf16 [nLength]
, strictConversion); , strictConversion);
if (conversionOK != eUnicodeConversionResult) if (conversionOK != eUnicodeConversionResult)
{ {
delete [] pStrUtf16; delete [] pStrUtf16;
return std::wstring(); return std::wstring();
} }
std::wstring utf16Str ((wchar_t *) pStrUtf16); std::wstring utf16Str ((wchar_t *) pStrUtf16);
delete [] pStrUtf16; delete [] pStrUtf16;
return utf16Str; return utf16Str;
} }
else //utf8 -> utf32 else //utf8 -> utf32
{ {
unsigned __int32 nLength = line.length(); unsigned int nLength = line.length();
UTF32 *pStrUtf32 = new UTF32 [nLength+1]; UTF32 *pStrUtf32 = new UTF32 [nLength+1];
memset ((void *) pStrUtf32, 0, sizeof (UTF32) * (nLength+1)); memset ((void *) pStrUtf32, 0, sizeof (UTF32) * (nLength+1));
UTF8 *pStrUtf8 = (UTF8 *) &line[0]; UTF8 *pStrUtf8 = (UTF8 *) &line[0];
// this values will be modificated // this values will be modificated
const UTF8 *pStrUtf8_Conv = pStrUtf8; const UTF8 *pStrUtf8_Conv = pStrUtf8;
UTF32 *pStrUtf32_Conv = pStrUtf32; UTF32 *pStrUtf32_Conv = pStrUtf32;
ConversionResult eUnicodeConversionResult = ConvertUTF8toUTF32 (&pStrUtf8_Conv, &pStrUtf8[nLength] ConversionResult eUnicodeConversionResult = ConvertUTF8toUTF32 (&pStrUtf8_Conv, &pStrUtf8[nLength]
, &pStrUtf32_Conv, &pStrUtf32 [nLength] , &pStrUtf32_Conv, &pStrUtf32 [nLength]
, strictConversion); , strictConversion);
if (conversionOK != eUnicodeConversionResult) if (conversionOK != eUnicodeConversionResult)
{ {
delete [] pStrUtf32; delete [] pStrUtf32;
return std::wstring(); return std::wstring();
} }
std::wstring utf32Str ((wchar_t *) pStrUtf32); std::wstring utf32Str ((wchar_t *) pStrUtf32);
delete [] pStrUtf32; delete [] pStrUtf32;
return utf32Str; return utf32Str;
} }
} }
const std::string Encoding::unicode2ansi(const std::wstring& line) const std::string Encoding::unicode2ansi(const std::wstring& line)
{ {
return unicode2cp(line, CP_ACP); return std::string(line.begin(), line.end());
} }
const std::string Encoding::unicode2utf8(const std::wstring& line) const std::string Encoding::unicode2utf8(const std::wstring& line)
{ {
if (sizeof(wchar_t) == 2) if (sizeof(wchar_t) == 2)
{ {
UTF16 *pStrUtf16 = (UTF16 *) &line[0]; UTF16 *pStrUtf16 = (UTF16 *) &line[0];
unsigned __int32 nLength = line.length(); unsigned int nLength = line.length();
unsigned __int32 nDstLength = 4*nLength + 1; unsigned int nDstLength = 4*nLength + 1;
UTF8 *pStrUtf8 = new UTF8 [nDstLength]; UTF8 *pStrUtf8 = new UTF8 [nDstLength];
memset ((void *) pStrUtf8, 0, sizeof (UTF8) * (nDstLength)); memset ((void *) pStrUtf8, 0, sizeof (UTF8) * (nDstLength));
// this values will be modificated // this values will be modificated
const UTF16 *pStrUtf16_Conv = pStrUtf16; const UTF16 *pStrUtf16_Conv = pStrUtf16;
UTF8 *pStrUtf8_Conv = pStrUtf8; UTF8 *pStrUtf8_Conv = pStrUtf8;
ConversionResult eUnicodeConversionResult = ConvertUTF16toUTF8 (&pStrUtf16_Conv, &pStrUtf16[nLength] ConversionResult eUnicodeConversionResult = ConvertUTF16toUTF8 (&pStrUtf16_Conv, &pStrUtf16[nLength]
, &pStrUtf8_Conv , &pStrUtf8 [nDstLength] , &pStrUtf8_Conv , &pStrUtf8 [nDstLength]
, strictConversion); , strictConversion);
if (conversionOK != eUnicodeConversionResult) if (conversionOK != eUnicodeConversionResult)
{ {
delete [] pStrUtf8; delete [] pStrUtf8;
return std::string(); return std::string();
} }
std::string utf8Str ((char *) pStrUtf8); std::string utf8Str ((char *) pStrUtf8);
delete [] pStrUtf8; delete [] pStrUtf8;
return utf8Str; return utf8Str;
} }
else //utf32 -> utf8 else //utf32 -> utf8
{ {
UTF32 *pStrUtf32 = (UTF32 *) &line[0]; UTF32 *pStrUtf32 = (UTF32 *) &line[0];
unsigned __int32 nLength = line.length(); unsigned int nLength = line.length();
unsigned __int32 nDstLength = 4*nLength + 1; unsigned int nDstLength = 4*nLength + 1;
UTF8 *pStrUtf8 = new UTF8 [nDstLength]; UTF8 *pStrUtf8 = new UTF8 [nDstLength];
memset ((void *) pStrUtf8, 0, sizeof (UTF8) * (nDstLength)); memset ((void *) pStrUtf8, 0, sizeof (UTF8) * (nDstLength));
// this values will be modificated // this values will be modificated
const UTF32 *pStrUtf32_Conv = pStrUtf32; const UTF32 *pStrUtf32_Conv = pStrUtf32;
UTF8 *pStrUtf8_Conv = pStrUtf8; UTF8 *pStrUtf8_Conv = pStrUtf8;
ConversionResult eUnicodeConversionResult = ConvertUTF32toUTF8 (&pStrUtf32_Conv, &pStrUtf32[nLength] ConversionResult eUnicodeConversionResult = ConvertUTF32toUTF8 (&pStrUtf32_Conv, &pStrUtf32[nLength]
, &pStrUtf8_Conv , &pStrUtf8 [nDstLength] , &pStrUtf8_Conv , &pStrUtf8 [nDstLength]
, strictConversion); , strictConversion);
if (conversionOK != eUnicodeConversionResult) if (conversionOK != eUnicodeConversionResult)
{ {
delete [] pStrUtf8; delete [] pStrUtf8;
return std::string(); return std::string();
} }
std::string utf8Str ((char *) pStrUtf8); std::string utf8Str ((char *) pStrUtf8);
delete [] pStrUtf8; delete [] pStrUtf8;
return utf8Str; return utf8Str;
} }
} }
const std::string Encoding::unicode2cp(const std::wstring& sLine, const unsigned int codePage) const std::string Encoding::unicode2cp(const std::wstring& sLine, const unsigned int nCodepage)
{ {
#ifdef _WIN32 #if defined (_WIN32) || defined (_WIN64)
const int nSize = WideCharToMultiByte(codePage, 0, sLine.c_str(), sLine.length(), NULL, 0, NULL, NULL); const int nSize = WideCharToMultiByte(codePage, 0, sLine.c_str(), sLine.length(), NULL, 0, NULL, NULL);
char *sTemp = new char[nSize]; char *sTemp = new char[nSize];
if (!sTemp) if (!sTemp)
return std::string(); return std::string();
int size = WideCharToMultiByte(codePage, 0, sLine.c_str(), sLine.length(), sTemp, nSize, NULL, NULL); int size = WideCharToMultiByte(nCodepage, 0, sLine.c_str(), sLine.length(), sTemp, nSize, NULL, NULL);
std::string sResult(sTemp, size); std::string sResult(sTemp, size);
delete []sTemp; delete []sTemp;
return sResult; return sResult;
#elif __linux__
return std::string();
#else #else
return std::string(); std::string out;
bool ansi = true;
size_t insize = sLine.length();
out.reserve(insize);
char *inptr = (char*)sLine.c_str();
char* outptr = (char*)out.c_str();
if (nCodepage > 0)
{
std::string sCodepage = "CP" + std::to_string(nCodepage);
iconv_t ic= iconv_open(sCodepage.c_str(), "WCHAR_T");
if (ic != (iconv_t) -1)
{
size_t nconv = 0, avail = insize * sizeof(wchar_t);
nconv = iconv (ic, &inptr, &insize, &outptr, &avail);
if (nconv == 0) ansi = false;
iconv_close(ic);
}
}
if (ansi)
out = std::string(sLine.begin(), sLine.end());
return out;
#endif #endif
} }
...@@ -7,33 +7,49 @@ ...@@ -7,33 +7,49 @@
namespace StlUtils namespace StlUtils
{ {
static inline std::wstring IntToWideString(int value, int radix = 10) static inline std::wstring IntToWideString(int value)
{ {
wchar_t strValue[256]; #if defined(_WIN32) || defined(_WIN64)
wchar_t strValue[256];
_itow_s(value, strValue, 256, radix); _itow_s(value, strValue, 256, radix);
return std::wstring(strValue); return std::wstring(strValue);
#else
return std::to_wstring(value);
#endif
} }
static inline std::wstring DoubleToWideString(double value) static inline std::wstring DoubleToWideString(double value)
{ {
wchar_t strValue[256]; #if defined(_WIN32) || defined(_WIN64)
wchar_t strValue[256];
swprintf_s(strValue, 256, L"%f", value); swprintf_s(strValue, 256, L"%f", value);
return std::wstring(strValue); return std::wstring(strValue);
} #else
return std::to_wstring(value);
#endif
}
static inline std::string IntToString(int value, int radix = 10) static inline std::string IntToString(int value)
{ {
char strValue[256]; #if defined(_WIN32) || defined(_WIN64)
char strValue[256];
_itoa_s(value, strValue, 256, radix); _itoa_s(value, strValue, 256, radix);
return std::string(strValue); return std::string(strValue);
#else
return std::to_string(value);
#endif
} }
static inline std::string DoubleToString(double value) static inline std::string DoubleToString(double value)
{ {
char strValue[256]; #if defined(_WIN32) || defined(_WIN64)
char strValue[256];
sprintf_s(strValue, 256, "%f", value); sprintf_s(strValue, 256, "%f", value);
return std::string(strValue); return std::string(strValue);
} #else
return std::to_string(value);
#endif
}
static int ToInteger(const std::string& strValue) static int ToInteger(const std::string& strValue)
{ {
...@@ -42,8 +58,12 @@ namespace StlUtils ...@@ -42,8 +58,12 @@ namespace StlUtils
static int ToInteger(const std::wstring& strValue) static int ToInteger(const std::wstring& strValue)
{ {
return _wtoi(strValue.c_str()); #if defined(_WIN32) || defined(_WIN64)
} return _wtoi(strValue.c_str());
#else
return std::stoi(strValue);
#endif
}
static double ToDouble(const std::string& strValue) static double ToDouble(const std::string& strValue)
{ {
...@@ -52,8 +72,12 @@ namespace StlUtils ...@@ -52,8 +72,12 @@ namespace StlUtils
static double ToDouble(const std::wstring& strValue) static double ToDouble(const std::wstring& strValue)
{ {
return _wtof(strValue.c_str()); #if defined(_WIN32) || defined(_WIN64)
} return _wtof(strValue.c_str());
#else
return std::stod(strValue);
#endif
}
} }
#endif // ASC_STL_UTILS_INCLUDE_H_ #endif // ASC_STL_UTILS_INCLUDE_H_
\ No newline at end of file
#pragma once #pragma once
#ifndef UTILITY_UTILITY_INCLUDE_H_
#define UTILITY_UTILITY_INCLUDE_H_
#include "../../../../Common/DocxFormat/Source/XML/stringcommon.h" #include "../../../../Common/DocxFormat/Source/XML/stringcommon.h"
...@@ -10,7 +8,7 @@ template<typename Out, typename In> ...@@ -10,7 +8,7 @@ template<typename Out, typename In>
static const std::vector<Out> _transform(const std::vector<In>& lines, const Out(*func)(const In&)) static const std::vector<Out> _transform(const std::vector<In>& lines, const Out(*func)(const In&))
{ {
std::vector<Out> result; std::vector<Out> result;
for (std::vector<In>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter) for (typename std::vector<In>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter)
{ {
result.push_back(func(*iter)); result.push_back(func(*iter));
} }
...@@ -22,7 +20,7 @@ template<typename Out, typename In> ...@@ -22,7 +20,7 @@ template<typename Out, typename In>
static const std::list<Out> _transform(const std::list<In>& lines, const Out(*func)(const In&)) static const std::list<Out> _transform(const std::list<In>& lines, const Out(*func)(const In&))
{ {
std::list<Out> result; std::list<Out> result;
for (std::list<In>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter) for (typename std::list<In>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter)
{ {
result.push_back(func(*iter)); result.push_back(func(*iter));
} }
...@@ -32,12 +30,11 @@ static const std::list<Out> _transform(const std::list<In>& lines, const Out(*fu ...@@ -32,12 +30,11 @@ static const std::list<Out> _transform(const std::list<In>& lines, const Out(*fu
template<typename Out, typename In, typename In2> template<typename Out, typename In, typename In2>
static const std::list<Out> _transform2(const std::list<In>& lines, const int codepage, const Out(*func)(const In&, const In2 codePage)) static const std::list<Out> _transform2(const std::list<In>& lines, const int codepage, const Out(*func)(const In&, const In2 codePage))
{ {
std::list<Out> result; std::list<Out> result;
for (std::list<In>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter) for (typename std::list<In>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter)
{ {
result.push_back(func(*iter, codepage)); result.push_back(func(*iter, codepage));
} }
return result; return result;
} }
#endif // UTILITY_UTILITY_INCLUDE_H_
\ No newline at end of file
...@@ -32,10 +32,10 @@ namespace Docx2Txt ...@@ -32,10 +32,10 @@ namespace Docx2Txt
void convert(TxtXml::ITxtXmlEvent& Event); void convert(TxtXml::ITxtXmlEvent& Event);
void writeUtf8 (const boost::filesystem::wpath& path) const; void writeUtf8 (const std::wstring& path) const;
void writeUnicode (const boost::filesystem::wpath& path) const; void writeUnicode (const std::wstring& path) const;
void writeBigEndian (const boost::filesystem::wpath& path) const; void writeBigEndian (const std::wstring& path) const;
void writeAnsi (const boost::filesystem::wpath& path) const; void writeAnsi (const std::wstring& path) const;
Txt::File m_outputFile; Txt::File m_outputFile;
OOX::CDocx m_inputFile; OOX::CDocx m_inputFile;
...@@ -77,33 +77,33 @@ namespace Docx2Txt ...@@ -77,33 +77,33 @@ namespace Docx2Txt
return converter_->convert(Event); return converter_->convert(Event);
} }
void Converter::read(const boost::filesystem::wpath& path) void Converter::read(const std::wstring& path)
{ {
BOOL res = converter_->m_inputFile.Read(std_string2string(path.string())); BOOL res = converter_->m_inputFile.Read(std_string2string(path));
return; return;
} }
void Converter::write(const boost::filesystem::wpath& path) void Converter::write(const std::wstring& path)
{ {
return converter_->m_outputFile.write(path); return converter_->m_outputFile.write(path);
} }
void Converter::writeUtf8(const boost::filesystem::wpath& path) const void Converter::writeUtf8(const std::wstring& path) const
{ {
return converter_->writeUtf8(path); return converter_->writeUtf8(path);
} }
void Converter::writeUnicode(const boost::filesystem::wpath& path) const void Converter::writeUnicode(const std::wstring& path) const
{ {
return converter_->writeUnicode(path); return converter_->writeUnicode(path);
} }
void Converter::writeBigEndian(const boost::filesystem::wpath& path) const void Converter::writeBigEndian(const std::wstring path) const
{ {
return converter_->writeBigEndian(path); return converter_->writeBigEndian(path);
} }
void Converter::writeAnsi(const boost::filesystem::wpath& path) const void Converter::writeAnsi(const std::wstring path) const
{ {
return converter_->writeAnsi(path); return converter_->writeAnsi(path);
} }
...@@ -183,25 +183,25 @@ namespace Docx2Txt ...@@ -183,25 +183,25 @@ namespace Docx2Txt
} }
void Converter_Impl::writeUtf8(const boost::filesystem::wpath& path) const void Converter_Impl::writeUtf8(const std::wstring& path) const
{ {
m_outputFile.writeUtf8(path); m_outputFile.writeUtf8(path);
} }
void Converter_Impl::writeUnicode(const boost::filesystem::wpath& path) const void Converter_Impl::writeUnicode(const std::wstring& path) const
{ {
m_outputFile.writeUnicode(path); m_outputFile.writeUnicode(path);
} }
void Converter_Impl::writeBigEndian(const boost::filesystem::wpath& path) const void Converter_Impl::writeBigEndian(const std::wstring& path) const
{ {
m_outputFile.writeBigEndian(path); m_outputFile.writeBigEndian(path);
} }
void Converter_Impl::writeAnsi(const boost::filesystem::wpath& path) const void Converter_Impl::writeAnsi(const std::wstring& path) const
{ {
m_outputFile.writeAnsi(path); m_outputFile.writeAnsi(path);
} }
...@@ -559,4 +559,4 @@ namespace Docx2Txt ...@@ -559,4 +559,4 @@ namespace Docx2Txt
return result; return result;
} }
} // namespace Docx2Txt } // namespace Docx2Txt
\ No newline at end of file
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#ifndef DOCX_2_TXT_CONVERTER_INCLUDE_H_ #ifndef DOCX_2_TXT_CONVERTER_INCLUDE_H_
#define DOCX_2_TXT_CONVERTER_INCLUDE_H_ #define DOCX_2_TXT_CONVERTER_INCLUDE_H_
#include <boost/filesystem.hpp>
#include <vector> #include <vector>
#include <string> #include <string>
...@@ -22,13 +21,13 @@ namespace Docx2Txt ...@@ -22,13 +21,13 @@ namespace Docx2Txt
void convert(TxtXml::ITxtXmlEvent& Event); void convert(TxtXml::ITxtXmlEvent& Event);
void read (const boost::filesystem::wpath& path); void read (const std::wstring& path);
void write (const boost::filesystem::wpath& path); void write (const std::wstring& path);
void writeUtf8 (const boost::filesystem::wpath& path) const; void writeUtf8 (const std::wstring& path) const;
void writeUnicode (const boost::filesystem::wpath& path) const; void writeUnicode (const std::wstring& path) const;
void writeBigEndian (const boost::filesystem::wpath& path) const; void writeBigEndian (const std::wstring& path) const;
void writeAnsi (const boost::filesystem::wpath& path) const; void writeAnsi (const std::wstring& path) const;
private: private:
Converter_Impl * converter_; Converter_Impl * converter_;
...@@ -38,4 +37,4 @@ namespace Docx2Txt ...@@ -38,4 +37,4 @@ namespace Docx2Txt
} // namespace Docx2Txt } // namespace Docx2Txt
#endif // DOCX_2_TXT_CONVERTER_INCLUDE_H_ #endif // DOCX_2_TXT_CONVERTER_INCLUDE_H_
\ No newline at end of file
#include "Converter.h" #include "Converter.h"
//#include <boost/foreach.hpp>
//#include "../Common/AbstractConverter.h"
#include "../../../../Common/DocxFormat/Source/DocxFormat/Docx.h" #include "../../../../Common/DocxFormat/Source/DocxFormat/Docx.h"
#include "../TxtFormat/TxtFormat.h" #include "../TxtFormat/TxtFormat.h"
#include "../TxtXmlEvent.h" #include "../TxtXmlEvent.h"
...@@ -34,12 +32,12 @@ namespace Txt2Docx ...@@ -34,12 +32,12 @@ namespace Txt2Docx
return converter_->convert(Event); return converter_->convert(Event);
} }
void Converter::read(const boost::filesystem::wpath& path) void Converter::read(const std::wstring& path)
{ {
return converter_->m_inputFile.read(path); return converter_->m_inputFile.read(path);
} }
void Converter::write(/*const boost::filesystem::wpath& path*/XmlUtils::CStringWriter & stringWriter) void Converter::write(/*const std::wstring& path*/XmlUtils::CStringWriter & stringWriter)
{ {
for (long i=0;i < converter_->m_outputFile.m_arrItems.size(); i++) for (long i=0;i < converter_->m_outputFile.m_arrItems.size(); i++)
{ {
...@@ -123,7 +121,10 @@ namespace Txt2Docx ...@@ -123,7 +121,10 @@ namespace Txt2Docx
} }
if(line->length() > 0) if(line->length() > 0)
temp->AddText(std_string2string(*line));//, rPr); {
CString s = std_string2string(*line);
temp->AddText(s);//, rPr);
}
pDocument->m_arrItems.push_back(temp); pDocument->m_arrItems.push_back(temp);
...@@ -135,4 +136,4 @@ namespace Txt2Docx ...@@ -135,4 +136,4 @@ namespace Txt2Docx
} }
Event.Progress(0, 900000); Event.Progress(0, 900000);
} }
} // namespace Txt2Docx } // namespace Txt2Docx
\ No newline at end of file
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#ifndef TXT_2_DOCX_CONVERTER_INCLUDE_H_ #ifndef TXT_2_DOCX_CONVERTER_INCLUDE_H_
#define TXT_2_DOCX_CONVERTER_INCLUDE_H_ #define TXT_2_DOCX_CONVERTER_INCLUDE_H_
#include <boost/filesystem.hpp>
#include "../../../../Common/DocxFormat/Source/XML/Utils.h" #include "../../../../Common/DocxFormat/Source/XML/Utils.h"
namespace TxtXml namespace TxtXml
...@@ -21,8 +20,8 @@ namespace Txt2Docx ...@@ -21,8 +20,8 @@ namespace Txt2Docx
~Converter (); ~Converter ();
void convert(TxtXml::ITxtXmlEvent& Event); void convert(TxtXml::ITxtXmlEvent& Event);
void read (const boost::filesystem::wpath& path); void read (const std::wstring& path);
void write (XmlUtils::CStringWriter & stringWriter/*const boost::filesystem::wpath& path*/); void write (XmlUtils::CStringWriter & stringWriter/*const std::wstring& path*/);
private: private:
Converter_Impl * converter_; Converter_Impl * converter_;
...@@ -30,4 +29,4 @@ namespace Txt2Docx ...@@ -30,4 +29,4 @@ namespace Txt2Docx
} // namespace Txt2Docx } // namespace Txt2Docx
#endif // TXT_2_DOCX_CONVERTER_INCLUDE_H_ #endif // TXT_2_DOCX_CONVERTER_INCLUDE_H_
\ No newline at end of file
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
#include "../Common/Utility.h" #include "../Common/Utility.h"
#include "TxtFile.h" #include "TxtFile.h"
#include "../../../DesktopEditor/common/File.h"
namespace Txt namespace Txt
{ {
...@@ -12,14 +15,14 @@ namespace Txt ...@@ -12,14 +15,14 @@ namespace Txt
{ {
m_listContent.clear(); m_listContent.clear();
} }
void File::read(const boost::filesystem::wpath& filename, int code_page) // void File::read(const std::wstring& filename, int code_page) //
{ {
m_listContent.clear(); m_listContent.clear();
if (filename.empty()) if (filename.empty())
return; return;
TxtFile file(std_string2string(filename.string())); TxtFile file(std_string2string(filename));
std::list<std::string> codePageContent = file.readAnsiOrCodePage(); std::list<std::string> codePageContent = file.readAnsiOrCodePage();
m_listContentSize = file.getLinesCount(); m_listContentSize = file.getLinesCount();
...@@ -30,14 +33,14 @@ namespace Txt ...@@ -30,14 +33,14 @@ namespace Txt
} }
codePageContent.clear(); codePageContent.clear();
} }
void File::read(const boost::filesystem::wpath& filename) void File::read(const std::wstring& filename)
{ {
m_listContent.clear(); m_listContent.clear();
if (filename.empty()) if (filename.empty())
return; return;
TxtFile file(std_string2string(filename.string())); TxtFile file(std_string2string(filename));
// //
...@@ -69,15 +72,15 @@ namespace Txt ...@@ -69,15 +72,15 @@ namespace Txt
} }
void File::write(const boost::filesystem::wpath& filename) const void File::write(const std::wstring& filename) const
{ {
TxtFile file(std_string2string(filename.string())); TxtFile file(std_string2string(filename));
file.writeUtf8(_transform(m_listContent, Encoding::unicode2utf8)); file.writeUtf8(_transform(m_listContent, Encoding::unicode2utf8));
} }
void File::writeCodePage(const boost::filesystem::wpath& filename, int code_page) const void File::writeCodePage(const std::wstring& filename, int code_page) const
{ {
TxtFile file(std_string2string(filename.string())); TxtFile file(std_string2string(filename));
std::list<std::string> result; std::list<std::string> result;
for (std::list<std::wstring>::const_iterator iter = m_listContent.begin(); iter != m_listContent.end(); ++iter) for (std::list<std::wstring>::const_iterator iter = m_listContent.begin(); iter != m_listContent.end(); ++iter)
...@@ -88,39 +91,40 @@ namespace Txt ...@@ -88,39 +91,40 @@ namespace Txt
file.writeAnsiOrCodePage(result); file.writeAnsiOrCodePage(result);
} }
void File::writeUtf8(const boost::filesystem::wpath& filename) const void File::writeUtf8(const std::wstring& filename) const
{ {
TxtFile file(std_string2string(filename.string())); TxtFile file(std_string2string(filename));
file.writeUtf8(_transform(m_listContent, Encoding::unicode2utf8)); file.writeUtf8(_transform(m_listContent, Encoding::unicode2utf8));
} }
void File::writeUnicode(const boost::filesystem::wpath& filename) const void File::writeUnicode(const std::wstring& filename) const
{ {
TxtFile file(std_string2string(filename.string())); TxtFile file(std_string2string(filename));
file.writeUnicode(m_listContent); file.writeUnicode(m_listContent);
} }
void File::writeBigEndian(const boost::filesystem::wpath& filename) const void File::writeBigEndian(const std::wstring& filename) const
{ {
TxtFile file(std_string2string(filename.string())); OOX::CPath path (filename);
TxtFile file(path);
file.writeBigEndian(m_listContent); file.writeBigEndian(m_listContent);
} }
void File::writeAnsi(const boost::filesystem::wpath& filename) const void File::writeAnsi(const std::wstring& filename) const
{ {
TxtFile file(std_string2string(filename.string())); TxtFile file(std_string2string(filename));
file.writeAnsiOrCodePage(_transform(m_listContent, Encoding::unicode2ansi)); file.writeAnsiOrCodePage(_transform(m_listContent, Encoding::unicode2ansi));
} }
const bool File::isValid(const boost::filesystem::wpath& filename) const const bool File::isValid(const std::wstring& filename) const
{ {
if (filename.empty()) if (filename.empty())
return true; return true;
return boost::filesystem::exists(filename); return NSFile::CFileBinary::Exists(filename);
} }
void File::correctUnicode(std::list<std::wstring>& input) void File::correctUnicode(std::list<std::wstring>& input)
{ {
...@@ -152,4 +156,4 @@ namespace Txt ...@@ -152,4 +156,4 @@ namespace Txt
return result; return result;
} }
} // namespace Txt } // namespace Txt
\ No newline at end of file
...@@ -2,12 +2,8 @@ ...@@ -2,12 +2,8 @@
#ifndef TXT_FILE_INCLUDE_H_ #ifndef TXT_FILE_INCLUDE_H_
#define TXT_FILE_INCLUDE_H_ #define TXT_FILE_INCLUDE_H_
//#include <vector>
#include <list> #include <list>
#include <string> #include <string>
#include <boost/filesystem.hpp>
//#include "property.h"
namespace Txt namespace Txt
{ {
...@@ -17,18 +13,18 @@ namespace Txt ...@@ -17,18 +13,18 @@ namespace Txt
File(); File();
~File(); ~File();
void read (const boost::filesystem::wpath& filename); void read (const std::wstring& filename);
void read (const boost::filesystem::wpath& filename, int code_page); void read (const std::wstring& filename, int code_page);
void write (const boost::filesystem::wpath& filename) const; void write (const std::wstring& filename) const;
void writeCodePage (const boost::filesystem::wpath& filename, int code_page) const; void writeCodePage (const std::wstring& filename, int code_page) const;
void writeUtf8 (const boost::filesystem::wpath& filename) const; void writeUtf8 (const std::wstring& filename) const;
void writeUnicode (const boost::filesystem::wpath& filename) const; void writeUnicode (const std::wstring& filename) const;
void writeBigEndian (const boost::filesystem::wpath& filename) const; void writeBigEndian (const std::wstring& filename) const;
void writeAnsi (const boost::filesystem::wpath& filename) const; void writeAnsi (const std::wstring& filename) const;
const bool isValid (const boost::filesystem::wpath& filename) const; const bool isValid (const std::wstring& filename) const;
std::list<std::wstring> m_listContent; //unicode ( utf8) std::list<std::wstring> m_listContent; //unicode ( utf8)
int m_listContentSize; // int m_listContentSize; //
...@@ -39,4 +35,4 @@ namespace Txt ...@@ -39,4 +35,4 @@ namespace Txt
}; };
} // namespace Txt } // namespace Txt
#endif // TXT_FILE_INCLUDE_H_ #endif // TXT_FILE_INCLUDE_H_
\ No newline at end of file
...@@ -10,29 +10,29 @@ static const std::string BadSymbols = "\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\ ...@@ -10,29 +10,29 @@ static const std::string BadSymbols = "\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\
static std::wstring convertUtf16ToWString(UTF16 * Data, int nLength) static std::wstring convertUtf16ToWString(UTF16 * Data, int nLength)
{ {
UTF32 *pStrUtf32 = new UTF32 [nLength + 1]; UTF32 *pStrUtf32 = new UTF32 [nLength + 1];
memset ((void *) pStrUtf32, 0, sizeof (UTF32) * (nLength + 1)); memset ((void *) pStrUtf32, 0, sizeof (UTF32) * (nLength + 1));
// this values will be modificated // this values will be modificated
const UTF16 *pStrUtf16_Conv = Data; const UTF16 *pStrUtf16_Conv = Data;
UTF32 *pStrUtf32_Conv = pStrUtf32; UTF32 *pStrUtf32_Conv = pStrUtf32;
ConversionResult eUnicodeConversionResult = ConversionResult eUnicodeConversionResult =
ConvertUTF16toUTF32 (&pStrUtf16_Conv, ConvertUTF16toUTF32 (&pStrUtf16_Conv,
&Data[nLength] &Data[nLength]
, &pStrUtf32_Conv , &pStrUtf32_Conv
, &pStrUtf32 [nLength] , &pStrUtf32 [nLength]
, strictConversion); , strictConversion);
if (conversionOK != eUnicodeConversionResult) if (conversionOK != eUnicodeConversionResult)
{ {
delete [] pStrUtf32; delete [] pStrUtf32;
return std::wstring(); return std::wstring();
} }
std::wstring wstr ((wchar_t *) pStrUtf32); std::wstring wstr ((wchar_t *) pStrUtf32);
delete [] pStrUtf32; delete [] pStrUtf32;
return wstr; return wstr;
} }
...@@ -231,7 +231,7 @@ const std::list<std::string> TxtFile::readUtf8() ...@@ -231,7 +231,7 @@ const std::list<std::string> TxtFile::readUtf8()
void TxtFile::writeAnsiOrCodePage(const std::list<std::string>& content) // === writeUtf8withoutPref void TxtFile::writeAnsiOrCodePage(const std::list<std::string>& content) // === writeUtf8withoutPref
{ {
CFile file; CFile file;
if (file.CreateFileW(m_path.GetPath()) == S_OK) if (file.CreateFile(m_path.GetPath()) == S_OK)
{ {
BYTE endLine[2] = {0x0d, 0x0a}; BYTE endLine[2] = {0x0d, 0x0a};
for (std::list<std::string>::const_iterator iter = content.begin(); iter != content.end(); ++iter) for (std::list<std::string>::const_iterator iter = content.begin(); iter != content.end(); ++iter)
...@@ -247,7 +247,7 @@ void TxtFile::writeAnsiOrCodePage(const std::list<std::string>& content) // === ...@@ -247,7 +247,7 @@ void TxtFile::writeAnsiOrCodePage(const std::list<std::string>& content) // ===
void TxtFile::writeUnicode(const std::list<std::wstring>& content) void TxtFile::writeUnicode(const std::list<std::wstring>& content)
{ {
CFile file; CFile file;
if (file.CreateFileW(m_path.GetPath()) == S_OK) if (file.CreateFile(m_path.GetPath()) == S_OK)
{ {
BYTE Header[2] = {0xff, 0xfe}; BYTE Header[2] = {0xff, 0xfe};
BYTE EndLine[4] = {0x0d, 0x00, 0x0a, 0x00}; BYTE EndLine[4] = {0x0d, 0x00, 0x0a, 0x00};
...@@ -277,7 +277,7 @@ void TxtFile::writeUnicode(const std::list<std::wstring>& content) ...@@ -277,7 +277,7 @@ void TxtFile::writeUnicode(const std::list<std::wstring>& content)
void TxtFile::writeBigEndian(const std::list<std::wstring>& content) void TxtFile::writeBigEndian(const std::list<std::wstring>& content)
{ {
CFile file; CFile file;
if (file.CreateFileW(m_path.GetPath()) == S_OK) if (file.CreateFile(m_path.GetPath()) == S_OK)
{ {
BYTE Header[2] = {0xfe, 0xff}; BYTE Header[2] = {0xfe, 0xff};
BYTE EndLine[4] = {0x00, 0x0d, 0x00, 0x0a}; BYTE EndLine[4] = {0x00, 0x0d, 0x00, 0x0a};
...@@ -313,7 +313,7 @@ void TxtFile::writeBigEndian(const std::list<std::wstring>& content) ...@@ -313,7 +313,7 @@ void TxtFile::writeBigEndian(const std::list<std::wstring>& content)
void TxtFile::writeUtf8(const std::list<std::string>& content) void TxtFile::writeUtf8(const std::list<std::string>& content)
{ {
CFile file; CFile file;
if (file.CreateFileW(m_path.GetPath()) == S_OK) if (file.CreateFile(m_path.GetPath()) == S_OK)
{ {
BYTE Header[3] = {0xef ,0xbb , 0xbf}; BYTE Header[3] = {0xef ,0xbb , 0xbf};
BYTE EndLine[2] = {0x0d ,0x0a}; BYTE EndLine[2] = {0x0d ,0x0a};
......
#include <string> #include <string>
#include <boost/filesystem.hpp>
#include "TxtXmlFile.h" #include "TxtXmlFile.h"
...@@ -23,7 +22,7 @@ namespace BinDocxRW ...@@ -23,7 +22,7 @@ namespace BinDocxRW
#include "../../../ASCOfficeUtils/ASCOfficeUtilsLib/OfficeUtils.h" #include "../../../ASCOfficeUtils/ASCOfficeUtilsLib/OfficeUtils.h"
#include "../../../Common/OfficeDefines.h" #include "../../../Common/OfficeDefines.h"
#include "../../../common/docxformat/source/systemutility/file.h" #include "../../../Common/DocxFormat/Source/SystemUtility/File.h"
#include "../../../DesktopEditor/common/Path.h" #include "../../../DesktopEditor/common/Path.h"
#include "../../../ASCOfficeDocxFile2/DocWrapper/FontProcessor.h" #include "../../../ASCOfficeDocxFile2/DocWrapper/FontProcessor.h"
...@@ -38,13 +37,13 @@ CTxtXmlFile::CTxtXmlFile() ...@@ -38,13 +37,13 @@ CTxtXmlFile::CTxtXmlFile()
bool CTxtXmlFile::Progress(long ID, long Percent) bool CTxtXmlFile::Progress(long ID, long Percent)
{ {
SHORT res = 0; SHORT res = 0;
m_lPercent = Percent; m_lPercent = Percent;
//OnProgressEx(ID, Percent, &res); todooo out event //OnProgressEx(ID, Percent, &res); todooo out event
return (res != 0); return (res != 0);
} }
static int ParseTxtOptions(static CString & sXmlOptions) static int ParseTxtOptions(const std::wstring & sXmlOptions)
{ {
int encoding = -1; int encoding = -1;
...@@ -78,7 +77,7 @@ static int ParseTxtOptions(static CString & sXmlOptions) ...@@ -78,7 +77,7 @@ static int ParseTxtOptions(static CString & sXmlOptions)
} }
HRESULT CTxtXmlFile::txt_LoadFromFile(CString sSrcFileName, CString sDstPath, CString sXMLOptions) HRESULT CTxtXmlFile::txt_LoadFromFile(const std::wstring & sSrcFileName, const std::wstring & sDstPath, const std::wstring & sXMLOptions)
{ {
// xml - // xml -
//HRESULT hr = xml_LoadFromFile(sSrcFileName, sDstPath, sXMLOptions); //HRESULT hr = xml_LoadFromFile(sSrcFileName, sDstPath, sXMLOptions);
...@@ -87,14 +86,10 @@ HRESULT CTxtXmlFile::txt_LoadFromFile(CString sSrcFileName, CString sDstPath, CS ...@@ -87,14 +86,10 @@ HRESULT CTxtXmlFile::txt_LoadFromFile(CString sSrcFileName, CString sDstPath, CS
//As Text //As Text
const boost::filesystem::wpath txtFile = string2std_string(sSrcFileName); Writers::FileWriter *pDocxWriter = new Writers::FileWriter(sDstPath, _T(""), 1, false, NULL, _T(""));
const boost::filesystem::wpath docxPath = string2std_string(sDstPath);
const boost::filesystem::wpath origin = docxPath/L"Origin";
Writers::FileWriter *pDocxWriter = new Writers::FileWriter(sDstPath, _T(""), 1, false, NULL, _T(""));
if (pDocxWriter == NULL) return S_FALSE; if (pDocxWriter == NULL) return S_FALSE;
CreateDocxEmpty(sDstPath, pDocxWriter); CreateDocxEmpty(std_string2string(sDstPath), pDocxWriter);
try try
{ {
...@@ -102,7 +97,7 @@ HRESULT CTxtXmlFile::txt_LoadFromFile(CString sSrcFileName, CString sDstPath, CS ...@@ -102,7 +97,7 @@ HRESULT CTxtXmlFile::txt_LoadFromFile(CString sSrcFileName, CString sDstPath, CS
Progress(0, 0); Progress(0, 0);
Txt2Docx::Converter converter( encoding); Txt2Docx::Converter converter( encoding);
converter.read(txtFile); converter.read(sSrcFileName);
Progress(0, 100000); Progress(0, 100000);
converter.convert(*this); converter.convert(*this);
converter.write(pDocxWriter->m_oDocumentWriter.m_oContent); converter.write(pDocxWriter->m_oDocumentWriter.m_oContent);
...@@ -122,35 +117,32 @@ HRESULT CTxtXmlFile::txt_LoadFromFile(CString sSrcFileName, CString sDstPath, CS ...@@ -122,35 +117,32 @@ HRESULT CTxtXmlFile::txt_LoadFromFile(CString sSrcFileName, CString sDstPath, CS
} }
HRESULT CTxtXmlFile::txt_SaveToFile(CString sDstFileName, CString sSrcPath, CString sXMLOptions) HRESULT CTxtXmlFile::txt_SaveToFile(const std::wstring & sDstFileName, const std::wstring & sSrcPath, const std::wstring & sXMLOptions)
{ {
const boost::filesystem::wpath txtFile = string2std_string(sDstFileName);
const boost::filesystem::wpath docxPath = string2std_string(sSrcPath);
try try
{ {
Progress(0, 0); Progress(0, 0);
Docx2Txt::Converter converter; Docx2Txt::Converter converter;
converter.read(docxPath); converter.read(sSrcPath);
Progress(0, 100000); Progress(0, 100000);
converter.convert(*this); converter.convert(*this);
int encoding = ParseTxtOptions(sXMLOptions); int encoding = ParseTxtOptions(sXMLOptions);
if (encoding == EncodingType::Utf8) if (encoding == EncodingType::Utf8)
converter.writeUtf8(txtFile); converter.writeUtf8(sDstFileName);
else if (encoding == EncodingType::Unicode) else if (encoding == EncodingType::Unicode)
converter.writeUnicode(txtFile); converter.writeUnicode(sDstFileName);
else if (encoding == EncodingType::Ansi) else if (encoding == EncodingType::Ansi)
converter.writeAnsi(txtFile); converter.writeAnsi(sDstFileName);
else if (encoding == EncodingType::BigEndian) else if (encoding == EncodingType::BigEndian)
converter.writeBigEndian(txtFile); converter.writeBigEndian(sDstFileName);
else if (encoding > 0) //code page else if (encoding > 0) //code page
{ {
converter.write(txtFile); converter.write(sDstFileName);
} }
else //auto define else //auto define
converter.write(txtFile); converter.write(sDstFileName);
Progress(0, 1000000); Progress(0, 1000000);
} }
......
#pragma once #pragma once
#include "TxtXmlEvent.h" #include "TxtXmlEvent.h"
#include "../../../Common/DocxFormat/Source/XML/stringcommon.h"
#include <string>
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#else
#include "../../../DesktopEditor/common/ASCVariant.h"
#endif
namespace Writers namespace Writers
{ {
...@@ -13,8 +20,8 @@ class CTxtXmlFile : public TxtXml::ITxtXmlEvent ...@@ -13,8 +20,8 @@ class CTxtXmlFile : public TxtXml::ITxtXmlEvent
public: public:
virtual bool Progress(long ID, long Percent); virtual bool Progress(long ID, long Percent);
HRESULT txt_LoadFromFile(CString sSrcFileName, CString sDstPath, CString sXMLOptions); HRESULT txt_LoadFromFile(const std::wstring & sSrcFileName, const std::wstring & sDstPath, const std::wstring & sXMLOptions);
HRESULT txt_SaveToFile (CString sDstFileName, CString sSrcPath, CString sXMLOptions); HRESULT txt_SaveToFile (const std::wstring & sDstFileName, const std::wstring & sSrcPath, const std::wstring & sXMLOptions);
//HRESULT xml_LoadFromFile(CString sSrcFileName, CString sDstPath, CString sXMLOptions); //HRESULT xml_LoadFromFile(CString sSrcFileName, CString sDstPath, CString sXMLOptions);
//HRESULT xml_SaveToFile (CString sDstFileName, CString sSrcPath, CString sXMLOptions); //HRESULT xml_SaveToFile (CString sDstFileName, CString sSrcPath, CString sXMLOptions);
...@@ -24,4 +31,4 @@ public: ...@@ -24,4 +31,4 @@ public:
private: private:
void CreateDocxEmpty(CString path, Writers::FileWriter * DocxWriter) ; void CreateDocxEmpty(CString path, Writers::FileWriter * DocxWriter) ;
}; };
\ No newline at end of file
...@@ -15,8 +15,7 @@ DEFINES += _LINUX LINUX UNICODE _UNICODE _USE_LIBXML2_READER_ _LINUX_QT _USE_XML ...@@ -15,8 +15,7 @@ DEFINES += _LINUX LINUX UNICODE _UNICODE _USE_LIBXML2_READER_ _LINUX_QT _USE_XML
LIBS += -lxml2 LIBS += -lxml2
INCLUDEPATH += \ INCLUDEPATH += /usr/include/libxml2
/usr/include/libxml2
SOURCES += docxformatlib.cpp \ SOURCES += docxformatlib.cpp \
../Source/Common/Align.cpp \ ../Source/Common/Align.cpp \
......
#include <windows.h>
#ifndef _OFFICEDEFINES_H_ #ifndef _OFFICEDEFINES_H_
#define _OFFICEDEFINES_H_ #define _OFFICEDEFINES_H_
...@@ -50,4 +48,5 @@ const int c_nSaveModeNone = 0; ...@@ -50,4 +48,5 @@ const int c_nSaveModeNone = 0;
const int c_nSaveModeStart = 1; const int c_nSaveModeStart = 1;
const int c_nSaveModeContinue = 2; const int c_nSaveModeContinue = 2;
const int c_nSaveModeCommit = 4; const int c_nSaveModeCommit = 4;
#endif //_OFFICEDEFINES_H_ #endif //_OFFICEDEFINES_H_
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
#include "../../Common/DocxFormat/Source/Base/ASCString.h" // TODO: move ASCString to DecktopEditor/commmon directory #include "../../Common/DocxFormat/Source/Base/ASCString.h" // TODO: move ASCString to DecktopEditor/commmon directory
// VARIANT // VARIANT
#ifndef _WIN32 #if !defined(_WIN32) && !defined(_WIN64)
// 0 == FALSE, -1 == TRUE // 0 == FALSE, -1 == TRUE
typedef short VARIANT_BOOL; typedef short VARIANT_BOOL;
......
...@@ -73,7 +73,7 @@ namespace SerializeCommon ...@@ -73,7 +73,7 @@ namespace SerializeCommon
return sSourcePath.Left(nIndex + 1) + sTargetExt; return sSourcePath.Left(nIndex + 1) + sTargetExt;
return sSourcePath; return sSourcePath;
} }
void ReadFileType(CString& sXMLOptions, BYTE& result, UINT& nCodePage, WCHAR& wcDelimiter, BYTE& cSaveFileType) void ReadFileType(const CString& sXMLOptions, BYTE& result, UINT& nCodePage, WCHAR& wcDelimiter, BYTE& cSaveFileType)
{ {
result = BinXlsxRW::c_oFileTypes::XLSX; result = BinXlsxRW::c_oFileTypes::XLSX;
nCodePage = CP_UTF8; nCodePage = CP_UTF8;
......
...@@ -47,7 +47,7 @@ namespace SerializeCommon ...@@ -47,7 +47,7 @@ namespace SerializeCommon
aReplies.clear(); aReplies.clear();
} }
}; };
void ReadFileType(CString& sXMLOptions, BYTE& result, UINT& nCodePage, WCHAR& wcDelimiter, BYTE& saveFileType); void ReadFileType(const CString& sXMLOptions, BYTE& result, UINT& nCodePage, WCHAR& wcDelimiter, BYTE& saveFileType);
} }
#endif //SERIALIZER_COMMON #endif //SERIALIZER_COMMON
...@@ -3023,7 +3023,7 @@ namespace BinXlsxRW { ...@@ -3023,7 +3023,7 @@ namespace BinXlsxRW {
public: BinaryFileReader() public: BinaryFileReader()
{ {
} }
int ReadFile(CString sSrcFileName, CString sDstPath, NSBinPptxRW::CDrawingConverter* pOfficeDrawingConverter, CString& sXMLOptions) int ReadFile(const CString& sSrcFileName, CString sDstPath, NSBinPptxRW::CDrawingConverter* pOfficeDrawingConverter, const CString& sXMLOptions)
{ {
bool bResultOk = false; bool bResultOk = false;
NSFile::CFileBinary oFile; NSFile::CFileBinary oFile;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment