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

Rtf->Docx

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62010 954022d7-b5bf-4e40-9824-e11837661b57
parent ce0e05ad
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
//#include <stdio.h>
//#include <stdlib.h>
//#include <ctype.h>
#include "RtfToken.h"
#include "Utils.h"
......@@ -36,20 +36,21 @@ public:
void SetSource( CString sPath )
{
Clear();
HANDLE hSrc = CreateFile((LPCWSTR)sPath, // file to open
GENERIC_READ, // open for reading
FILE_SHARE_READ| FILE_SHARE_WRITE, // share for reading
NULL, // default security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
__int64 totalFileSize;
GetFileSizeEx(hSrc,(LARGE_INTEGER *)&totalFileSize);
CFile srcFile;
if (srcFile.OpenFile(sPath) != S_OK) return;
__int64 totalFileSize = srcFile.GetFileSize();
m_nSizeAbs = (long)totalFileSize;
m_aBuffer = new unsigned char[m_nSizeAbs];
DWORD dwBytesRead = 0;
ReadFile(hSrc, m_aBuffer, m_nSizeAbs, &dwBytesRead, NULL);
RELEASEHANDLE( hSrc );
srcFile.ReadFile(m_aBuffer, m_nSizeAbs);
dwBytesRead = srcFile.GetPosition();
srcFile.CloseFile();
}
void getBytes( int nCount, byte** pbData )
{
......
......@@ -88,15 +88,15 @@ public:
static DataType GetPictureType( CString sFilename )
{
BYTE pBuffer[ 16 ];
DWORD dwBytesRead;
DWORD dwBytesRead = 0;
HANDLE hFile;
hFile = ::CreateFile(sFilename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (INVALID_HANDLE_VALUE == hFile)
return dt_none;
CFile file;
if (file.OpenFile(sFilename) != S_OK) return dt_none;
::ReadFile(hFile, pBuffer, 16, &dwBytesRead, NULL);
::CloseHandle(hFile);
file.ReadFile(pBuffer, 16);
dwBytesRead = file.GetPosition();
file.CloseFile();
//jpeg
// Hex: FF D8 FF
......
......@@ -762,20 +762,27 @@ CString RtfSectionProperty::SaveFile( TextItemContainerPtr oTarget, RenderParame
sRootName = _T("w:ftr");
sContent.AppendFormat( _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n") );
sContent.AppendFormat( _T("<%ls xmlns:ve=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\">"), sRootName );
RenderParameter oNewParameter = oRenderParameter;
OOXRelsWriterPtr oNewRelsWr = OOXRelsWriterPtr( new OOXRelsWriter( sFilename, *poRtfDocument ) );
poOOXWriter->m_oCustomRelsWriter.push_back( oNewRelsWr );
oNewParameter.poRels = oNewRelsWr.get();
sContent.Append( oTarget->RenderToOOX(oNewParameter) );
sContent.AppendFormat( _T("</%ls>"), sRootName );
CStringA sContentUTF = Convert::UnicodeToUtf8( sContent );
CString sFilePath = poOOXWriter->m_sTargetFolder + _T("\\") +poOOXWriter->m_sDocumentFolder+ _T("\\")+sFilename;
CString sFilePath = poOOXWriter->m_sTargetFolder + FILE_SEPARATOR_STR + poOOXWriter->m_sDocumentFolder+ FILE_SEPARATOR_STR + sFilename;
DWORD dwBytesWritten = 0;
HANDLE hFile = ::CreateFile(sFilePath,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
::WriteFile(hFile, sContentUTF, sContentUTF.GetLength(), &dwBytesWritten, NULL);
CloseHandle( hFile );
CFile file;
if (file.CreateFileW(sFilePath) == S_OK)
{
file.WriteFile(sContentUTF.GetBuffer(), sContentUTF.GetLength());
file.CloseFile();
}
CString sContentTarget = _T("/") + poOOXWriter->m_sDocumentFolder + _T("/") + sFilename;
CString srID;
......
......@@ -110,26 +110,6 @@ bool RtfWriter::SaveByItem()
}
//
m_oDocument.RemoveItem( 0 );
////
//HANDLE hFile = ::CreateFile(m_sTempFile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0);
//DWORD dwBytesRead = 1;
//BYTE byteBuffer[ 4096 ];
//while( 0 != dwBytesRead )
//{
// ::ReadFile(hFile,byteBuffer ,4096, &dwBytesRead, NULL);
// m_oFileWriter->Write( (BYTE*)&byteBuffer, dwBytesRead );
//}
//CloseHandle( hFile );
////
//CStringA sRtfExt = "\\sect";
//m_oFileWriter->Write( (BYTE*)(LPCSTR)sRtfExt, sRtfExt.GetLength() );
////
//BSTR bstrFileName = m_sTempFile.AllocSysString();
//m_oTempFileWriter = new NFileWriter::CBufferedFileWriter( bstrFileName );
//SysFreeString( bstrFileName );
}
//
if( m_oDocument.GetCount() > 0 && m_oDocument[0]->GetCount() > 0 )
......@@ -183,23 +163,6 @@ bool RtfWriter::SaveByItemEnd()
m_oDocument.RemoveItem( 0 );
}
////
//HANDLE hFile = ::CreateFile(m_sTempFile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0);
//DWORD dwBytesRead = 1;
//BYTE byteBuffer[ 4096 ];
//while( 0 != dwBytesRead )
//{
// ::ReadFile(hFile,byteBuffer ,4096, &dwBytesRead, NULL);
// m_oFileWriter->Write( (BYTE*)&byteBuffer, dwBytesRead );
//}
//CloseHandle( hFile );
////
//sRtf = CreateRtfEnd();
//RtfInternalEncoder::Decode( sRtf, *m_oFileWriter );
////m_oFileWriter->Write( (BYTE*)(LPCSTR)sRtf, sRtf.GetLength() );
//RELEASEOBJECT( m_oFileWriter );
//
try
{
......@@ -215,32 +178,38 @@ bool RtfWriter::SaveByItemEnd()
for( int i = 0 ; i < (int)m_aTempFiles.size() && i < (int)m_aTempFilesSectPr.size(); i++ )
{
//
HANDLE hFile = ::CreateFile( m_aTempFilesSectPr[i], GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
if( INVALID_HANDLE_VALUE != hFile )
CFile file;
if (file.OpenFile(m_aTempFilesSectPr[i]) == S_OK)
{
DWORD dwBytesRead = 1;
BYTE byteBuffer[ 4096 ];
while( 0 != dwBytesRead )
{
::ReadFile( hFile, byteBuffer, 4096, &dwBytesRead, NULL);
dwBytesRead = file.GetPosition();
file.ReadFile( byteBuffer, 4096);
dwBytesRead = file.GetPosition() - dwBytesRead;
oTargetFileWriter.Write( byteBuffer, dwBytesRead );
}
CloseHandle( hFile );
file.CloseFile();
}
//
hFile = ::CreateFile( m_aTempFiles[i], GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
if( INVALID_HANDLE_VALUE != hFile )
if (file.OpenFile(m_aTempFiles[i]) == S_OK)
{
DWORD dwBytesRead = 1;
BYTE byteBuffer[ 4096 ];
while( 0 != dwBytesRead )
{
::ReadFile( hFile, byteBuffer, 4096, &dwBytesRead, NULL);
dwBytesRead = file.GetPosition();
file.ReadFile(byteBuffer, 4096);
dwBytesRead = file.GetPosition() - dwBytesRead;
oTargetFileWriter.Write( byteBuffer, dwBytesRead );
}
CloseHandle( hFile );
file.CloseFile();
}
}
......
......@@ -266,161 +266,121 @@ public:
{
return (int)(pt * 20);
}
static float Twip2pt(int pt)
{
return (float)(pt / 20.0);
}
static int pt2HalfPt(float pt)
{
return (int)(pt * 2);
}
static int Twips2Emu(int pt)
{
return (int)(pt * 635);
}
static int Emu2Twips(int pt)
{
return (int)(pt / 635);
}
static float Emu2Pt(int emu)
{
return (float)(1.0 * emu / (635 * 20.0));
}
static void WriteDataToFileBinary(CString& sFilename, byte* pbData, int nLength)
{
if( NULL == pbData )
return;
CFile file;
if (file.CreateFileW(sFilename) != S_OK) return;
static float Twip2pt(int pt)
{
return (float)(pt / 20.0);
}
static int pt2HalfPt(float pt)
{
return (int)(pt * 2);
}
static int Twips2Emu(int pt)
{
return (int)(pt * 635);
}
static int Emu2Twips(int pt)
{
return (int)(pt / 635);
}
static float Emu2Pt(int emu)
{
return (float)(1.0 * emu / (635 * 20.0));
}
static void WriteDataToFileBinary(CString& sFilename, byte* pbData, int nLength)
{
if( NULL == pbData )
return;
DWORD dwBytesWritten;
file.WriteFile(pbData ,nLength);
file.CloseFile();
}
static void WriteDataToFile(CString& sFilename, CString& sData)
{
CFile file;
CFile file;
if (file.CreateFileW(sFilename) != S_OK) return;
if (file.CreateFileW(sFilename) != S_OK) return;
DWORD dwBytesWritten;
file.WriteFile(pbData ,nLength);
file.CloseFile();
}
static void WriteDataToFile(CString& sFilename, CString& sData)
{
CFile file;
TCHAR * buf = sData.GetBuffer();
int nLengthText = sData.GetLength();
int nLengthData = nLengthText/2;
BYTE * buf2 = new BYTE[ nLengthData];
BYTE nByte=0;
for( int i=0; i < nLengthData ; i++ )
{
nByte = ToByte( buf[2 * i] ) << 4;
nByte |= ToByte( buf[2 * i + 1] );
buf2[i] = nByte;
}
file.WriteFile(buf2 ,nLengthData);
sData.ReleaseBuffer();
delete[] buf2;
file.CloseFile();
if (file.CreateFileW(sFilename) != S_OK) return;
}
static void WriteDataToBinary( CString sData, BYTE** ppData, long& nSize)
TCHAR * buf = sData.GetBuffer();
int nLengthText = sData.GetLength();
int nLengthData = nLengthText/2;
BYTE * buf2 = new BYTE[ nLengthData];
BYTE nByte=0;
for( int i=0; i < nLengthData ; i++ )
{
TCHAR * buf = sData.GetBuffer();
int nLengthText = sData.GetLength();
nSize = nLengthText/2;
BYTE * buf2 = new BYTE[ nSize];
(*ppData) = buf2;
BYTE nByte=0;
for( int i=0; i < nSize ; i++ )
{
nByte = ToByte(buf[ 2*i])<<4;
nByte |= ToByte(buf[ 2*i+1]);
buf2[i] = nByte;
}
sData.ReleaseBuffer();
nByte = ToByte( buf[2 * i] ) << 4;
nByte |= ToByte( buf[2 * i + 1] );
buf2[i] = nByte;
}
static void ReadDataFromFile(CString sName, CString& sData)
{
HANDLE hFile = ::CreateFile(sName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0);
DWORD dwBytesRead = 0;
BYTE byteBuffer[ BUF_SIZE ];
file.WriteFile(buf2 ,nLengthData);
sData.ReleaseBuffer();
delete[] buf2;
file.CloseFile();
::ReadFile(hFile,byteBuffer ,BUF_SIZE, &dwBytesRead, NULL);
while( 0 != dwBytesRead )
{
for( int i = 0; i < (int)dwBytesRead; i++ )
{
int n1 =(byteBuffer[i]&0xF0) >> 4;
int n2 = byteBuffer[i]&0x0F;
sData.AppendFormat( _T("%x"), n1);
sData.AppendFormat( _T("%x"), n2);
}
::ReadFile(hFile,byteBuffer ,BUF_SIZE, &dwBytesRead, NULL);
}
CloseHandle( hFile );
}
static CString DecodeHex( CString sText )
{
CString sHexText;
for( int i = 0; i < sText.GetLength(); i++ )
{
TBYTE byteChar = sText[i];
sHexText.AppendFormat( _T("%x"), byteChar );
}
return sHexText;
}
static CString EncodeHex( CString sHexText )
{
CString sText;
for( int i = 0; i < sHexText.GetLength() -1 ; i+=2 )
{
int byte1 = ToByte( sHexText[i] );
int byte2 = ToByte(sHexText[i + 1] );
int cChar = (byte1 << 4) + byte2;
sText.AppendFormat( _T("%c"), cChar );
}
return sText;
}
static byte ToByte( TCHAR cChar )
}
static void WriteDataToBinary( CString sData, BYTE** ppData, long& nSize)
{
TCHAR * buf = sData.GetBuffer();
int nLengthText = sData.GetLength();
nSize = nLengthText/2;
BYTE * buf2 = new BYTE[ nSize];
(*ppData) = buf2;
BYTE nByte=0;
for( int i=0; i < nSize ; i++ )
{
return (byte)(cChar > 'F' ? cChar - 0x57 : cChar > '9' ? cChar - 0x37 : cChar - 0x30);
nByte = ToByte(buf[ 2*i])<<4;
nByte |= ToByte(buf[ 2*i+1]);
buf2[i] = nByte;
}
static bool IsAlpha( int nChar )
sData.ReleaseBuffer();
}
static CString DecodeHex( CString sText )
{
CString sHexText;
for( int i = 0; i < sText.GetLength(); i++ )
{
return ( nChar >= 'a' && nChar <= 'z' || nChar >= 'A' && nChar <= 'Z' );
TBYTE byteChar = sText[i];
sHexText.AppendFormat( _T("%x"), byteChar );
}
static bool IsDigit( int nChar )
return sHexText;
}
static CString EncodeHex( CString sHexText )
{
CString sText;
for( int i = 0; i < sHexText.GetLength() -1 ; i+=2 )
{
return nChar >= '0' && nChar <= '9';
int byte1 = ToByte( sHexText[i] );
int byte2 = ToByte(sHexText[i + 1] );
int cChar = (byte1 << 4) + byte2;
sText.AppendFormat( _T("%c"), cChar );
}
return sText;
}
static byte ToByte( TCHAR cChar )
{
return (byte)(cChar > 'F' ? cChar - 0x57 : cChar > '9' ? cChar - 0x37 : cChar - 0x30);
}
static bool IsAlpha( int nChar )
{
return ( nChar >= 'a' && nChar <= 'z' || nChar >= 'A' && nChar <= 'Z' );
}
static bool IsDigit( int nChar )
{
return nChar >= '0' && nChar <= '9';
}
static CString Preserve( CString sText )
{
CString sResult = sText;
//
sResult.Trim();
//
while( sResult.Replace( _T(" "), _T(" ") ) > 0 )
;
return sResult;
}
static int GetFolderSize( CString sFolder )
{
HANDLE Handle;
WIN32_FIND_DATA FindData;
DWORDLONG Result=0;
int nCount = 0;
Handle = FindFirstFile(( sFolder + _T("\\*.*") ), &FindData);
if (Handle == INVALID_HANDLE_VALUE)
return 0;
do
{
if(( CString( FindData.cFileName) != _T("."))&&(CString(FindData.cFileName) != _T("..")))
nCount++;
}
while(FindNextFile(Handle, &FindData) != 0);
FindClose(Handle);
return nCount;
}
{
CString sResult = sText;
//
sResult.Trim();
//
while( sResult.Replace( _T(" "), _T(" ") ) > 0 )
;
return sResult;
}
static int CharsetToCodepage( int nCharset )
{
CHARSETINFO Info;
......@@ -534,13 +494,18 @@ public:
private:
static void DecodeFromFile( CString& sFilename, NFileWriter::CBufferedFileWriter& oFileWriter )
{
HANDLE hFile = ::CreateFile( sFilename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, 0);
CFile file;
if (file.OpenFile(sFilename) != S_OK) return;
DWORD dwBytesRead = 0;
BYTE byteBuffer[ BUF_SIZE ];
char aLookup[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
::ReadFile(hFile,byteBuffer ,BUF_SIZE, &dwBytesRead, NULL);
file.ReadFile(byteBuffer ,BUF_SIZE);
dwBytesRead = file.GetPosition();
while( 0 != dwBytesRead )
{
for( int i = 0; i < (int)dwBytesRead; i++ )
......@@ -551,8 +516,10 @@ private:
oFileWriter.Write( &byteFirst, 1 );
oFileWriter.Write( &byteSecond, 1 );
}
::ReadFile( hFile, byteBuffer, BUF_SIZE, &dwBytesRead, NULL );
dwBytesRead = file.GetPosition();
file.ReadFile(byteBuffer ,BUF_SIZE);
dwBytesRead = file.GetPosition() - dwBytesRead;
}
CloseHandle( hFile );
file.CloseFile();
}
};
......@@ -25,25 +25,18 @@ public:
}
bool Save(CString sFolder)
{
HANDLE hFile = ::CreateFile(sFolder + _T("\\[Content_Types].xml"),
GENERIC_WRITE,
0,
0,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
//ATLASSERT( INVALID_HANDLE_VALUE != hFile );
CFile file;
if( INVALID_HANDLE_VALUE != hFile )
{
DWORD dwBytesWritten;
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
::WriteFile( hFile, sXmlUTF, sXmlUTF.GetLength(), &dwBytesWritten, NULL );
CloseHandle( hFile );
return true;
}
return false;
if (file.CreateFileW(sFolder + FILE_SEPARATOR_STR + _T("[Content_Types].xml")) != S_OK) return false;
DWORD dwBytesWritten;
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );//todooo UTF32 !!!
file.WriteFile( sXmlUTF.GetBuffer(), sXmlUTF.GetLength());
file.CloseFile();
return true;
}
private:
......
......@@ -32,44 +32,27 @@ public:
}
bool Save( CString sFolder)
{
//if( false == m_sContent.IsEmpty() )
//{
// m_oWriter.m_oRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"), _T("docProps/app.xml") );
// m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.extended-properties+xml"), _T("/docProps/app.xml") );
CString pathDocProps = sFolder + FILE_SEPARATOR_STR + _T("docProps");
FileSystem::Directory::CreateDirectoryW(pathDocProps) ;
if( false == m_sContent.IsEmpty() )
{
m_oWriter.m_oRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"), _T("docProps/app.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.extended-properties+xml"), _T("/docProps/app.xml") );
// CreateDirectory(sFolder + _T("\\docProps"), NULL) ;
// HANDLE hFile = ::CreateFile(sFolder + _T("\\docProps\\app.xml"),
// GENERIC_WRITE,
// 0,
// 0,
// CREATE_ALWAYS,
// FILE_ATTRIBUTE_NORMAL,
// 0);
// //ATLASSERT( INVALID_HANDLE_VALUE != hFile );
CFile file;
if (file.CreateFileW(pathDocProps + FILE_SEPARATOR_STR + _T("app.xml"))) return false;
// if( INVALID_HANDLE_VALUE != hFile )
// {
// DWORD dwBytesWritten;
// CString sXml = CreateXml();
// CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
// ::WriteFile(hFile, sXmlUTF, sXmlUTF.GetLength(), &dwBytesWritten, NULL);
// CloseHandle( hFile );
// return true;
// }
//}
//else
//{
//CreateDirectory(sFolder + _T("\\docProps"), NULL) ;
//if( true == RtfUtility:: SaveResourceToFile( IDR_APP, L"XML", sFolder + _T("\\docProps\\app.xml") ) )
//{
// m_oWriter.m_oRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"), _T("docProps/app.xml") );
// m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.extended-properties+xml"), _T("/docProps/app.xml") );
//}
//else
//{
// RemoveDirectory( sFolder + _T("\\docProps") );
//}
//}
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
file.WriteFile(sXmlUTF.GetBuffer(), sXmlUTF.GetLength());
file.CloseFile();
return true;
}
else
{
//todooo - default app !!!
}
return false;
}
bool IsEmpty()
......
......@@ -30,43 +30,26 @@ public:
}
bool Save( CString sFolder)
{
CString pathDocProps = sFolder + FILE_SEPARATOR_STR + _T("docProps");
FileSystem::Directory::CreateDirectoryW(pathDocProps) ;
if( false == m_sFileXml.IsEmpty() )
{
m_oWriter.m_oRels.AddRelationship( _T("http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"), _T("docProps/core.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-package.core-properties+xml"), _T("/docProps/core.xml") );
//CreateDirectory(sFolder + _T("\\docProps"),NULL) ;
//HANDLE hFile = ::CreateFile(sFolder + _T("\\docProps\\core.xml"),
// GENERIC_WRITE,
// 0,
// 0,
// CREATE_ALWAYS,
// FILE_ATTRIBUTE_NORMAL,
// 0);
////ATLASSERT( INVALID_HANDLE_VALUE != hFile );
//if( INVALID_HANDLE_VALUE != hFile )
//{
// DWORD dwBytesWritten;
// CString sXml = CreateXml();
// CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
// ::WriteFile(hFile, sXmlUTF, sXmlUTF.GetLength(), &dwBytesWritten, NULL);
// CloseHandle( hFile );
// return true;
//}
CFile file;
if (file.CreateFileW(pathDocProps + FILE_SEPARATOR_STR + _T("core.xml"))) return false;
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
file.WriteFile(sXmlUTF.GetBuffer(), sXmlUTF.GetLength());
file.CloseFile();
return true;
}
else
{
//FileSystem::Directory::CreateDirectory(sFolder + _T("\\docProps"), NULL) ;
//if( true == RtfUtility:: SaveResourceToFile( IDR_CORE, L"XML", sFolder + _T("\\docProps\\core.xml") ) )
//{
// m_oWriter.m_oRels.AddRelationship( _T("http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"), _T("docProps/core.xml") );
// m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-package.core-properties+xml"), _T("/docProps/core.xml") );
//}
//else
//{
// RemoveDirectory( sFolder + _T("\\docProps") );
//}
//todooo - default core !!!
}
return false;
}
......
......@@ -27,10 +27,12 @@ public:
bool SaveByItemStart( CString sFolder )
{
CreateDirectory( sFolder + _T("\\word"), NULL);
CString pathWord = sFolder + FILE_SEPARATOR_STR + _T("word");
FileSystem::Directory::CreateDirectoryW(pathWord) ;
try
{
CString sFilename = sFolder + _T("\\word\\document.xml");
CString sFilename = pathWord + FILE_SEPARATOR_STR + _T("document.xml");
m_oFileWriter = new NFileWriter::CBufferedFileWriter( sFilename );
}
catch(...)
......
......@@ -18,37 +18,27 @@ public:
}
bool Save( CString sFolder )
{
CString pathWord = sFolder + FILE_SEPARATOR_STR + _T("word");
FileSystem::Directory::CreateDirectoryW(pathWord) ;
if( false == m_sFileXml.IsEmpty() )
{
HANDLE hFile = ::CreateFile(sFolder + _T("\\word\\fontTable.xml"),
GENERIC_WRITE,
0,
0,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
//ATLASSERT( INVALID_HANDLE_VALUE != hFile );
CFile file;
if (file.CreateFileW(pathWord + FILE_SEPARATOR_STR + _T("fontTable.xml"))) return false;
if( INVALID_HANDLE_VALUE != hFile )
{
m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"), _T("fontTable.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"), _T("/word/fontTable.xml") );
m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"), _T("fontTable.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"), _T("/word/fontTable.xml") );
DWORD dwBytesWritten;
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
::WriteFile(hFile, sXmlUTF, sXmlUTF.GetLength(), &dwBytesWritten, NULL);
CloseHandle( hFile );
return true;
}
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
file.WriteFile(sXmlUTF.GetBuffer(), sXmlUTF.GetLength());
file.CloseFile();
return true;
}
else
{
//if( true == RtfUtility:: SaveResourceToFile( IDR_FONT_TABLE, L"XML", sFolder + _T("\\word\\fontTable.xml") ) )
//{
// m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"), _T("fontTable.xml") );
// m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"), _T("/word/fontTable.xml") );
//}
//todooo - default fontTable !!!
}
return false;
}
......
......@@ -38,25 +38,20 @@ public:
}
bool Save( CString sFolder )
{
if( false == m_sFootnotes.IsEmpty() )
{
HANDLE hFile = ::CreateFile(sFolder + _T("\\footnotes.xml"), GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
//ATLASSERT( INVALID_HANDLE_VALUE != hFile );
if( m_sFootnotes.IsEmpty() ) return false;
if( INVALID_HANDLE_VALUE != hFile )
{
m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"), _T("footnotes.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"), _T("/word/footnotes.xml") );
CFile file;
if (file.CreateFileW(sFolder + FILE_SEPARATOR_STR + _T("footnotes.xml"))) return false;
m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"), _T("footnotes.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"), _T("/word/footnotes.xml") );
DWORD dwBytesWritten;
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
::WriteFile(hFile, sXmlUTF, sXmlUTF.GetLength(), &dwBytesWritten, NULL);
CloseHandle( hFile );
return true;
}
}
return false;
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
file.WriteFile(sXmlUTF.GetBuffer(), sXmlUTF.GetLength());
file.CloseFile();
return true;
}
private:
RtfDocument& m_oDocument;
......@@ -110,24 +105,19 @@ public:
}
bool Save( CString sFolder )
{
if( false == m_sEndnotes.IsEmpty() )
{
HANDLE hFile = ::CreateFile(sFolder + _T("\\endnotes.xml"), GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
//ATLASSERT( INVALID_HANDLE_VALUE != hFile );
if( m_sEndnotes.IsEmpty() ) return false;
if( INVALID_HANDLE_VALUE != hFile )
{
m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes"), _T("endnotes.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml"), _T("/word/endnotes.xml") );
CFile file;
if (file.CreateFileW(sFolder + FILE_SEPARATOR_STR + _T("endnotes.xml"))) return false;
DWORD dwBytesWritten;
CStringA sXml = CreateXml();
::WriteFile(hFile,sXml ,sXml.GetLength(), &dwBytesWritten, NULL);
CloseHandle(hFile);
return true;
}
}
return false;
m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes"), _T("endnotes.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml"), _T("/word/endnotes.xml") );
CStringA sXml = CreateXml();
file.WriteFile(sXml.GetBuffer(), sXml.GetLength());
file.CloseFile();
return true;
}
private:
RtfDocument& m_oDocument;
......
......@@ -49,24 +49,19 @@ public:
bool Save( CString sFolder )
{
if( m_aTargets.size() > 0 )
{
CreateDirectory(sFolder + _T("\\_rels"),NULL) ;
if( m_aTargets.size() < 1 )return false;
CString pathRels = sFolder + FILE_SEPARATOR_STR + _T("_rels");
FileSystem::Directory::CreateDirectoryW(pathRels) ;
HANDLE hFile = ::CreateFile(sFolder + _T("\\_rels\\") + m_sFileName + _T(".rels"), GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
//ATLASSERT( INVALID_HANDLE_VALUE != hFile );
CFile file;
if (file.CreateFileW(pathRels + FILE_SEPARATOR_STR + _T(".rels"))) return false;
if( INVALID_HANDLE_VALUE != hFile )
{
DWORD dwBytesWritten;
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
::WriteFile(hFile, sXmlUTF, sXmlUTF.GetLength(), &dwBytesWritten, NULL);
CloseHandle( hFile );
return true;
}
}
return false;
DWORD dwBytesWritten;
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
file.WriteFile(sXmlUTF.GetBuffer(), sXmlUTF.GetLength());
file.CloseFile();
}
};
typedef boost::shared_ptr<OOXRelsWriter> OOXRelsWriterPtr;
\ No newline at end of file
......@@ -8,15 +8,15 @@ private:
OOXWriter& m_oWriter;
CString CreateXml()
{
CString sResult;
sResult.Append( _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>") );
sResult.Append( _T("\n") );
sResult.Append( _T("<w:settings xmlns:w = \"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:m = \"http://schemas.openxmlformats.org/officeDocument/2006/math\">") );
sResult.Append( m_sFileXml );
sResult.Append( _T("</w:settings>") );
return sResult;
}
{
CString sResult;
sResult.Append( _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>") );
sResult.Append( _T("\n") );
sResult.Append( _T("<w:settings xmlns:w = \"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:m = \"http://schemas.openxmlformats.org/officeDocument/2006/math\">") );
sResult.Append( m_sFileXml );
sResult.Append( _T("</w:settings>") );
return sResult;
}
public:
OOXRelsWriterPtr m_oRelsWriter;
......@@ -31,11 +31,15 @@ public:
}
bool Save( CString sFolder )
{
CString pathWord = sFolder + FILE_SEPARATOR_STR + _T("word");
if( false == m_sFileXml.IsEmpty() )
{
// xml
CString sXml = CreateXml();
//todoooo
//// xml
//CString sFilename = sFolder + _T("\\word\\settings.xml");
//if( true == RtfUtility:: SaveResourceToFile( IDR_SETTINGS, L"XML", sFilename ) )
......
......@@ -21,38 +21,28 @@ public:
}
bool Save( CString sFolder )
{
//if( false == m_sFileXml.IsEmpty() )
//{
// HANDLE hFile = ::CreateFile(sFolder + _T("\\word\\styles.xml"),
// GENERIC_WRITE,
// 0,
// 0,
// CREATE_ALWAYS,
// FILE_ATTRIBUTE_NORMAL,
// 0);
// //ATLASSERT( INVALID_HANDLE_VALUE != hFile );
CString pathWord = sFolder + FILE_SEPARATOR_STR + _T("word");
if( false == m_sFileXml.IsEmpty() )
{
CFile file;
if (file.CreateFileW(pathWord + FILE_SEPARATOR_STR + _T("styles.xml"))) return false;
// if( INVALID_HANDLE_VALUE != hFile )
// {
// m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"), _T("styles.xml") );
// m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"), _T("/word/styles.xml") );
m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"), _T("styles.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"), _T("/word/styles.xml") );
// DWORD dwBytesWritten;
// CString sXml = CreateXml();
// CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
// ::WriteFile(hFile, sXmlUTF, sXmlUTF.GetLength(), &dwBytesWritten, NULL);
// CloseHandle( hFile );
// return true;
// }
//}
//else
//{
// if( true == RtfUtility:: SaveResourceToFile( IDR_STYLES, L"XML", sFolder + _T("\\word\\styles.xml") ) )
// {
// m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"), _T("styles.xml") );
// m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"), _T("/word/styles.xml") );
// }
//}
DWORD dwBytesWritten;
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
file.WriteFile(sXmlUTF.GetBuffer(), sXmlUTF.GetLength());
file.CloseFile();
return true;
}
else
{
//todooo default style !!
}
return false;
}
private:
......
......@@ -12,8 +12,12 @@ public:
}
bool Save( CString sFolder ) //todo
{
//CreateDirectory(sFolder + _T("\\word"), NULL);
//CreateDirectory(sFolder + _T("\\word\\theme"),NULL);
CString pathWord = sFolder + FILE_SEPARATOR_STR + _T("word");
FileSystem::Directory::CreateDirectoryW(pathWord) ;
FileSystem::Directory::CreateDirectoryW(pathWord + FILE_SEPARATOR_STR + _T("theme")) ;
//todooo default theme !!!!!
//
//if( true == RtfUtility:: SaveResourceToFile( IDR_THEME, L"XML", sFolder + _T("\\word\\theme\\theme1.xml") ) )
//{
......
......@@ -59,37 +59,37 @@ bool OOXWriter::Save()
}
bool OOXWriter::SaveByItemStart()
{
//((OOXFootnoteWriter*)m_poFootnoteWriter)->Save(m_sTargetFolder + _T("\\") + m_sDocumentFolder);
//((OOXEndnoteWriter*)m_poEndnoteWriter)->Save(m_sTargetFolder + _T("\\") + m_sDocumentFolder);
((OOXFootnoteWriter*)m_poFootnoteWriter)->Save(m_sTargetFolder + FILE_SEPARATOR_STR + m_sDocumentFolder);
((OOXEndnoteWriter*)m_poEndnoteWriter)->Save(m_sTargetFolder + FILE_SEPARATOR_STR + m_sDocumentFolder);
//if( m_oFootnoteSep->GetCount() )
//{
// oNewParam = oRenderParameter;
// oNewParam.poRels = &poFootnoteWriter->m_oRelsWriter;
// oNewParam.nType = RENDER_TO_OOX_PARAM_UNKNOWN;
// poFootnoteWriter->AddFootnote( _T("separator"), -1, m_oFootnoteSep->RenderToOOX(oNewParam) );
//}
//if( m_oFootnoteCon->GetCount() )
//{
// oNewParam = oRenderParameter;
// oNewParam.poRels = &poFootnoteWriter->m_oRelsWriter;
// oNewParam.nType = RENDER_TO_OOX_PARAM_UNKNOWN;
// poFootnoteWriter->AddFootnote( _T("continuationSeparator"), 0, m_oFootnoteCon->RenderToOOX( oNewParam ) );
//}
//if( m_oEndnoteSep->GetCount() )
//{
// oNewParam = oRenderParameter;
// oNewParam.poRels = &poEndnoteWriter->m_oRelsWriter;
// oNewParam.nType = RENDER_TO_OOX_PARAM_UNKNOWN;
// poEndnoteWriter->AddEndnote( _T("separator"), -1, m_oEndnoteSep->RenderToOOX(oNewParam) );
//}
//if( m_oEndnoteCon->GetCount() )
//{
// oNewParam = oRenderParameter;
// oNewParam.poRels = &poEndnoteWriter->m_oRelsWriter;
// oNewParam.nType = RENDER_TO_OOX_PARAM_UNKNOWN;
// poEndnoteWriter->AddEndnote( _T("continuationSeparator"), 0, m_oEndnoteSep->RenderToOOX(oNewParam) );
//}
if( m_oFootnoteSep->GetCount() )
{
oNewParam = oRenderParameter;
oNewParam.poRels = &poFootnoteWriter->m_oRelsWriter;
oNewParam.nType = RENDER_TO_OOX_PARAM_UNKNOWN;
poFootnoteWriter->AddFootnote( _T("separator"), -1, m_oFootnoteSep->RenderToOOX(oNewParam) );
}
if( m_oFootnoteCon->GetCount() )
{
oNewParam = oRenderParameter;
oNewParam.poRels = &poFootnoteWriter->m_oRelsWriter;
oNewParam.nType = RENDER_TO_OOX_PARAM_UNKNOWN;
poFootnoteWriter->AddFootnote( _T("continuationSeparator"), 0, m_oFootnoteCon->RenderToOOX( oNewParam ) );
}
if( m_oEndnoteSep->GetCount() )
{
oNewParam = oRenderParameter;
oNewParam.poRels = &poEndnoteWriter->m_oRelsWriter;
oNewParam.nType = RENDER_TO_OOX_PARAM_UNKNOWN;
poEndnoteWriter->AddEndnote( _T("separator"), -1, m_oEndnoteSep->RenderToOOX(oNewParam) );
}
if( m_oEndnoteCon->GetCount() )
{
oNewParam = oRenderParameter;
oNewParam.poRels = &poEndnoteWriter->m_oRelsWriter;
oNewParam.nType = RENDER_TO_OOX_PARAM_UNKNOWN;
poEndnoteWriter->AddEndnote( _T("continuationSeparator"), 0, m_oEndnoteSep->RenderToOOX(oNewParam) );
}
return ((OOXDocumentWriter*)m_poDocumentWriter)->SaveByItemStart( m_sTargetFolder );
}
......@@ -137,8 +137,8 @@ bool OOXWriter::SaveByItemEnd()
((OOXDocumentWriter*)m_poDocumentWriter)->SaveByItemEnd();
((OOXFootnoteWriter*)m_poFootnoteWriter)->Save(m_sTargetFolder + _T("\\") + m_sDocumentFolder);
((OOXEndnoteWriter*)m_poEndnoteWriter)->Save(m_sTargetFolder + _T("\\") + m_sDocumentFolder);
((OOXFootnoteWriter*)m_poFootnoteWriter)->Save(m_sTargetFolder + FILE_SEPARATOR_STR + m_sDocumentFolder);
((OOXEndnoteWriter*)m_poEndnoteWriter)->Save(m_sTargetFolder + FILE_SEPARATOR_STR + m_sDocumentFolder);
((OOXNumberingWriter*)m_poNumberingWriter)->Save(m_sTargetFolder);
((OOXStylesWriter*)m_poStylesWriter)->Save(m_sTargetFolder);
((OOXFontTableWriter*)m_poFontTableWriter)->Save(m_sTargetFolder);
......@@ -149,8 +149,8 @@ bool OOXWriter::SaveByItemEnd()
bool nResult = true;
nResult &= m_oContentTypes.Save(m_sTargetFolder);
nResult &= m_oRels.Save(m_sTargetFolder);
nResult &= m_oDocRels.Save(m_sTargetFolder + _T("\\") + m_sDocumentFolder);
nResult &= m_oDocRels.Save(m_sTargetFolder + FILE_SEPARATOR_STR + m_sDocumentFolder);
for( int i = 0; i < (int)m_oCustomRelsWriter.size(); i++ )
m_oCustomRelsWriter[i]->Save(m_sTargetFolder + _T("\\") + m_sDocumentFolder);
m_oCustomRelsWriter[i]->Save(m_sTargetFolder + FILE_SEPARATOR_STR + m_sDocumentFolder);
return nResult;
}
\ No newline at end of file
......@@ -2,6 +2,6 @@
//1
//0
//1
//45
#define INTVER 1,0,1,45
#define STRVER "1,0,1,45\0"
//47
#define INTVER 1,0,1,47
#define STRVER "1,0,1,47\0"
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