Commit be45d169 authored by ElenaSubbotina's avatar ElenaSubbotina

small refactoring writing vba in doct, xlst

parent 03267ba2
...@@ -36,26 +36,10 @@ namespace BinDocxRW { ...@@ -36,26 +36,10 @@ namespace BinDocxRW {
int Binary_VbaProjectTableReader::Read() int Binary_VbaProjectTableReader::Read()
{ {
return ReadTable(&Binary_VbaProjectTableReader::ReadContent, this);
}
int Binary_VbaProjectTableReader::ReadContent(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
if ( c_oSerVbaProjectTypes::Name == type )
{
std::wstring file_name = m_oBufferedStream.GetString4(length);
OOX::CPath inputPath = m_oBufferedStream.m_strFolder + FILE_SEPARATOR_STR + L"media" + FILE_SEPARATOR_STR + file_name;
OOX::CPath outputPath = m_oFileWriter.m_oDocumentWriter.m_sDir + FILE_SEPARATOR_STR + L"word" + FILE_SEPARATOR_STR + L"vbaProject.bin";
NSFile::CFileBinary::Copy(inputPath.GetPath(), outputPath.GetPath());
m_oFileWriter.m_pVbaProject = new OOX::VbaProject(); m_oFileWriter.m_pVbaProject = new OOX::VbaProject();
m_oFileWriter.m_pVbaProject->set_filename(outputPath.GetPath()); m_oFileWriter.m_pVbaProject->fromPPTY(&m_oBufferedStream);
}
else return c_oSerConstants::ReadOk;
res = c_oSerConstants::ReadUnknown;
return res;
} }
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
Binary_HdrFtrTableReader::Binary_HdrFtrTableReader(NSBinPptxRW::CBinaryFileReader& poBufferedStream, Writers::FileWriter& oFileWriter, CComments* pComments):Binary_CommonReader(poBufferedStream),m_oFileWriter(oFileWriter),m_oHeaderFooterWriter(oFileWriter.m_oHeaderFooterWriter),m_pComments(pComments) Binary_HdrFtrTableReader::Binary_HdrFtrTableReader(NSBinPptxRW::CBinaryFileReader& poBufferedStream, Writers::FileWriter& oFileWriter, CComments* pComments):Binary_CommonReader(poBufferedStream),m_oFileWriter(oFileWriter),m_oHeaderFooterWriter(oFileWriter.m_oHeaderFooterWriter),m_pComments(pComments)
......
...@@ -285,8 +285,7 @@ public: ...@@ -285,8 +285,7 @@ public:
} }
int Read (); int Read ();
int ReadContent (BYTE type, long length, void* poResult); };
};
class Binary_HdrFtrTableReader : public Binary_CommonReader<Binary_HdrFtrTableReader> class Binary_HdrFtrTableReader : public Binary_CommonReader<Binary_HdrFtrTableReader>
{ {
......
...@@ -3027,25 +3027,12 @@ namespace BinDocxRW ...@@ -3027,25 +3027,12 @@ namespace BinDocxRW
} }
pOfficeDrawingConverter->SetRels(oldRels); pOfficeDrawingConverter->SetRels(oldRels);
} }
void WriteVbaProjectContent(OOX::VbaProject& oVbaProject)
{
std::wstring file_name = oVbaProject.filename().GetFilename();
m_oBcw.m_oStream.WriteBYTE(c_oSerVbaProjectTypes::Name);
m_oBcw.m_oStream.WriteStringW(file_name);
//... todooo write parsing vba project
//write vbaData.... todooo
//copy file bin
oVbaProject.copy_to(m_oBcw.m_oStream.m_pCommon->m_pImageManager->m_strDstMedia);
}
void WriteVbaProject(OOX::VbaProject& oVbaProject) void WriteVbaProject(OOX::VbaProject& oVbaProject)
{ {
int nStart = m_oBcw.WriteItemWithLengthStart(); m_oBcw.m_oStream.StartRecord(0);
WriteVbaProjectContent(oVbaProject); oVbaProject.toPPTY(&m_oBcw.m_oStream);
m_oBcw.WriteItemWithLengthEnd(nStart); m_oBcw.m_oStream.EndRecord();
} }
void Write(std::vector<OOX::WritingElement*>& aElems) void Write(std::vector<OOX::WritingElement*>& aElems)
{ {
......
...@@ -93,6 +93,8 @@ bool BinDocxRW::CDocxSerializer::saveToFile(const std::wstring& sSrcFileName, co ...@@ -93,6 +93,8 @@ bool BinDocxRW::CDocxSerializer::saveToFile(const std::wstring& sSrcFileName, co
oDrawingConverter.SetFontDir(m_sFontDir); oDrawingConverter.SetFontDir(m_sFontDir);
oDrawingConverter.SetFontPicker(pFontPicker); oDrawingConverter.SetFontPicker(pFontPicker);
oDrawingConverter.SetMainDocument(this); oDrawingConverter.SetMainDocument(this);
oDrawingConverter.SetDstPath(pathMain.GetDirectory() + FILE_SEPARATOR_STR + L"word");
oDrawingConverter.SetMediaDstPath(pathMedia.GetPath()); oDrawingConverter.SetMediaDstPath(pathMedia.GetPath());
m_pParamsWriter = new ParamsWriter(&oBufferedStream, &fp, &oDrawingConverter, pEmbeddedFontsManager); m_pParamsWriter = new ParamsWriter(&oBufferedStream, &fp, &oDrawingConverter, pEmbeddedFontsManager);
...@@ -264,6 +266,8 @@ bool BinDocxRW::CDocxSerializer::loadFromFile(const std::wstring& sSrcFileName, ...@@ -264,6 +266,8 @@ bool BinDocxRW::CDocxSerializer::loadFromFile(const std::wstring& sSrcFileName,
if (NULL != pData) if (NULL != pData)
{ {
oDrawingConverter.SetMainDocument(this); oDrawingConverter.SetMainDocument(this);
oDrawingConverter.SetDstPath(sDstPath + FILE_SEPARATOR_STR + L"word");
oDrawingConverter.SetMediaDstPath(sMediaPath); oDrawingConverter.SetMediaDstPath(sMediaPath);
oDrawingConverter.SetEmbedDstPath(sEmbedPath); oDrawingConverter.SetEmbedDstPath(sEmbedPath);
...@@ -273,7 +277,7 @@ bool BinDocxRW::CDocxSerializer::loadFromFile(const std::wstring& sSrcFileName, ...@@ -273,7 +277,7 @@ bool BinDocxRW::CDocxSerializer::loadFromFile(const std::wstring& sSrcFileName,
std::wstring strFileInDir = NSSystemPath::GetDirectoryName(sSrcFileName); std::wstring strFileInDir = NSSystemPath::GetDirectoryName(sSrcFileName);
std::wstring sFileInDir = strFileInDir.c_str(); std::wstring sFileInDir = strFileInDir.c_str();
oDrawingConverter.SetSourceFileDir(sFileInDir); oDrawingConverter.SetSrcPath(sFileInDir);
BinaryFileReader oBinaryFileReader(sFileInDir, oBufferedStream, *m_pCurFileWriter); BinaryFileReader oBinaryFileReader(sFileInDir, oBufferedStream, *m_pCurFileWriter);
oBinaryFileReader.ReadFile(); oBinaryFileReader.ReadFile();
......
...@@ -86,15 +86,16 @@ namespace BinXlsxRW{ ...@@ -86,15 +86,16 @@ namespace BinXlsxRW{
} }
bool CXlsxSerializer::loadFromFile(const std::wstring& sSrcFileName, const std::wstring& sDstPath, const std::wstring& sXMLOptions, const std::wstring& sMediaDir, const std::wstring& sEmbedDir) bool CXlsxSerializer::loadFromFile(const std::wstring& sSrcFileName, const std::wstring& sDstPath, const std::wstring& sXMLOptions, const std::wstring& sMediaDir, const std::wstring& sEmbedDir)
{ {
std::wstring strFileInDir = NSSystemPath::GetDirectoryName(sSrcFileName);
NSBinPptxRW::CDrawingConverter oDrawingConverter; NSBinPptxRW::CDrawingConverter oDrawingConverter;
oDrawingConverter.SetDstPath(sDstPath + FILE_SEPARATOR_STR + L"xl");
oDrawingConverter.SetSrcPath(strFileInDir, 2);
oDrawingConverter.SetMediaDstPath(sMediaDir); oDrawingConverter.SetMediaDstPath(sMediaDir);
oDrawingConverter.SetEmbedDstPath(sEmbedDir); oDrawingConverter.SetEmbedDstPath(sEmbedDir);
std::wstring strFileInDir = NSSystemPath::GetDirectoryName(sSrcFileName);
oDrawingConverter.SetSourceFileDir(strFileInDir, 2);
BinXlsxRW::BinaryFileReader oBinaryFileReader; BinXlsxRW::BinaryFileReader oBinaryFileReader;
oBinaryFileReader.ReadFile(sSrcFileName, sDstPath, &oDrawingConverter, sXMLOptions); oBinaryFileReader.ReadFile(sSrcFileName, sDstPath, &oDrawingConverter, sXMLOptions);
return true; return true;
......
...@@ -913,20 +913,29 @@ HRESULT CDrawingConverter::SetMainDocument(BinDocxRW::CDocxSerializer* pDocument ...@@ -913,20 +913,29 @@ HRESULT CDrawingConverter::SetMainDocument(BinDocxRW::CDocxSerializer* pDocument
return S_OK; return S_OK;
} }
HRESULT CDrawingConverter::SetMediaDstPath(const std::wstring& bsMediaPath) void CDrawingConverter::SetSrcPath(const std::wstring& sPath, int nDocType)
{ {
m_pBinaryWriter->m_pCommon->m_pImageManager->m_strDstMedia = (std::wstring)bsMediaPath; m_pReader->m_pRels->m_pManager = m_pImageManager;
m_pImageManager->SetDstMedia(m_pBinaryWriter->m_pCommon->m_pImageManager->m_strDstMedia); m_pReader->m_strFolder = sPath;
NSDirectory::CreateDirectory(bsMediaPath); m_pImageManager->m_nDocumentType = nDocType;
return S_OK; }
void CDrawingConverter::SetDstPath(const std::wstring& sPath)
{
m_pImageManager->SetDstFolder(sPath);
} }
HRESULT CDrawingConverter::SetEmbedDstPath(const std::wstring& bsEmbedPath) void CDrawingConverter::SetMediaDstPath(const std::wstring& sPath)
{ {
m_pImageManager->SetDstEmbed(bsEmbedPath); m_pBinaryWriter->m_pCommon->m_pImageManager->m_strDstMedia = sPath;
m_pImageManager->SetDstMedia(sPath);
NSDirectory::CreateDirectory(bsEmbedPath); NSDirectory::CreateDirectory(sPath);
return S_OK; }
void CDrawingConverter::SetEmbedDstPath(const std::wstring& sPath)
{
m_pImageManager->SetDstEmbed(sPath);
NSDirectory::CreateDirectory(sPath);
} }
HRESULT CDrawingConverter::AddShapeType(const std::wstring& bsXml) HRESULT CDrawingConverter::AddShapeType(const std::wstring& bsXml)
{ {
...@@ -5274,14 +5283,6 @@ OOX::CContentTypes* CDrawingConverter::GetContentTypes() ...@@ -5274,14 +5283,6 @@ OOX::CContentTypes* CDrawingConverter::GetContentTypes()
//return m_pReader->mm_strContentTypes; //return m_pReader->mm_strContentTypes;
} }
void CDrawingConverter::SetSourceFileDir(std::wstring path, int nDocType)
{
m_pReader->m_pRels->m_pManager = m_pImageManager;
m_pReader->m_strFolder = path;
m_pImageManager->m_nDocumentType = nDocType;
}
void CDrawingConverter::Clear() void CDrawingConverter::Clear()
{ {
for (std::map<std::wstring, CShape*>::iterator pPair = m_mapShapeTypes.begin(); pPair != m_mapShapeTypes.end(); ++pPair) for (std::map<std::wstring, CShape*>::iterator pPair = m_mapShapeTypes.begin(); pPair != m_mapShapeTypes.end(); ++pPair)
......
...@@ -215,8 +215,12 @@ namespace NSBinPptxRW ...@@ -215,8 +215,12 @@ namespace NSBinPptxRW
smart_ptr<OOX::IFileContainer> GetRels(); smart_ptr<OOX::IFileContainer> GetRels();
HRESULT SetMainDocument (BinDocxRW::CDocxSerializer* pDocument); HRESULT SetMainDocument (BinDocxRW::CDocxSerializer* pDocument);
HRESULT SetMediaDstPath (const std::wstring& sMediaPath);
HRESULT SetEmbedDstPath (const std::wstring& sEmbedPath); void SetSrcPath (const std::wstring& sPath, int nDocType = 1/*XMLWRITER_DOC_TYPE_DOCX*/);
void SetDstPath (const std::wstring& sPath);
void SetMediaDstPath (const std::wstring& sMediaPath);
void SetEmbedDstPath (const std::wstring& sEmbedPath);
HRESULT AddShapeType (const std::wstring& sXml); HRESULT AddShapeType (const std::wstring& sXml);
HRESULT AddObject (const std::wstring& sXml, std::wstring** pMainProps); HRESULT AddObject (const std::wstring& sXml, std::wstring** pMainProps);
...@@ -255,8 +259,6 @@ namespace NSBinPptxRW ...@@ -255,8 +259,6 @@ namespace NSBinPptxRW
void SetDocumentChartsCount (int val); void SetDocumentChartsCount (int val);
int GetDocumentChartsCount (); int GetDocumentChartsCount ();
void SetSourceFileDir (std::wstring path, int nDocType = 1/*XMLWRITER_DOC_TYPE_DOCX*/);
OOX::CContentTypes* GetContentTypes(); OOX::CContentTypes* GetContentTypes();
protected: protected:
nullable<PPTX::Logic::Xfrm> m_oxfrm_override; nullable<PPTX::Logic::Xfrm> m_oxfrm_override;
......
...@@ -346,7 +346,10 @@ namespace PPTX ...@@ -346,7 +346,10 @@ namespace PPTX
pReader->m_pRels = new NSBinPptxRW::CRelsGenerator(); pReader->m_pRels = new NSBinPptxRW::CRelsGenerator();
oDrawingConverter.SetMainDocument(&oDocxSerializer); oDrawingConverter.SetMainDocument(&oDocxSerializer);
oDrawingConverter.SetSourceFileDir(pReader->m_strFolder, 1);
oDrawingConverter.SetDstPath(sDstEmbeddedTemp + FILE_SEPARATOR_STR + L"word");
oDrawingConverter.SetSrcPath(pReader->m_strFolder, 1);
oDrawingConverter.SetMediaDstPath(sMediaPath); oDrawingConverter.SetMediaDstPath(sMediaPath);
oDrawingConverter.SetEmbedDstPath(sEmbedPath); oDrawingConverter.SetEmbedDstPath(sEmbedPath);
...@@ -434,7 +437,9 @@ namespace PPTX ...@@ -434,7 +437,9 @@ namespace PPTX
oDrawingConverter.m_pReader = pReader; oDrawingConverter.m_pReader = pReader;
pReader->m_pRels = new NSBinPptxRW::CRelsGenerator(); pReader->m_pRels = new NSBinPptxRW::CRelsGenerator();
oDrawingConverter.SetSourceFileDir(pReader->m_strFolder, 2); oDrawingConverter.SetDstPath(sDstEmbeddedTemp + FILE_SEPARATOR_STR + L"xl");
oDrawingConverter.SetSrcPath(pReader->m_strFolder, 2);
oDrawingConverter.SetMediaDstPath(sMediaPath); oDrawingConverter.SetMediaDstPath(sMediaPath);
oDrawingConverter.SetEmbedDstPath(sEmbedPath); oDrawingConverter.SetEmbedDstPath(sEmbedPath);
......
...@@ -469,8 +469,8 @@ namespace PPTX ...@@ -469,8 +469,8 @@ namespace PPTX
bool m_bMacroEnabled; bool m_bMacroEnabled;
smart_ptr<OOX::VbaProject> m_pVbaProject; smart_ptr<OOX::VbaProject> m_pVbaProject;
void SetClrMap(Logic::ClrMap map) {m_clrMap = map;}; void SetClrMap(Logic::ClrMap map) {m_clrMap = map;}
void SetClrScheme(nsTheme::ClrScheme scheme) {m_clrScheme = scheme;}; void SetClrScheme(nsTheme::ClrScheme scheme) {m_clrScheme = scheme;}
DWORD GetRGBAFromMap(const std::wstring& str)const DWORD GetRGBAFromMap(const std::wstring& str)const
{ {
......
This diff is collapsed.
This diff is collapsed.
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