Commit 2367cee3 authored by ElenaSubbotina's avatar ElenaSubbotina

PptxFormat - fix user file with wrong rels

parent 288d8930
......@@ -1735,13 +1735,16 @@ void CDrawingConverter::doc_LoadDiagram(PPTX::Logic::SpTreeElem *result, XmlUtil
OOX::CPath pathDiagramDrawing = pathDiagramData.GetDirectory() + FILE_SEPARATOR_STR + L"drawing" + strId + L".xml";
if (NSFile::CFileBinary::Exists(pathDiagramDrawing.GetPath()))
{
oFileDrawing = smart_ptr<OOX::File>(dynamic_cast<OOX::File*>(new OOX::CDiagramDrawing(pathDiagramDrawing)));
if (oFileDrawing.IsInit())
pDiagramDrawing = dynamic_cast<OOX::CDiagramDrawing*>(oFileDrawing.operator->());
}
}
}
if (pDiagramDrawing)
if ((pDiagramDrawing) && (pDiagramDrawing->m_oShapeTree.IsInit()))
{
result->InitElem(new PPTX::Logic::SpTree(*pDiagramDrawing->m_oShapeTree));
//to correct write blipFill rId to binary
......
......@@ -263,48 +263,68 @@ namespace PPTX2EditorAdvanced
// themes
oBinaryWriter.StartMainRecord(NSMainTables::Themes);
ULONG nCountThemes = (ULONG)_themes.size();
ULONG nCountThemes = 0;
for (size_t i = 0; i < _themes.size(); ++i)
{
if (_themes[i].IsInit()) nCountThemes++;
}
oBinaryWriter.WriteULONG(nCountThemes);
for (ULONG i = 0; i < nCountThemes; ++i)
for (size_t i = 0; i < _themes.size(); ++i)
{
if (_themes[i].IsInit() == false) continue;
_themes[i]->toPPTY(&oBinaryWriter);
}
// slidemasters
oBinaryWriter.StartMainRecord(NSMainTables::SlideMasters);
ULONG nCountSM = (ULONG)_slideMasters.size();
ULONG nCountSM = 0;
for (size_t i = 0; i < _slideMasters.size(); ++i)
{
if (_slideMasters[i].IsInit()) nCountSM++;
}
oBinaryWriter.WriteULONG(nCountSM);
for (ULONG i = 0; i < nCountSM; ++i)
for (size_t i = 0; i < _slideMasters.size(); ++i)
{
if (_slideMasters[i].IsInit() == false) continue;
_slideMasters[i]->toPPTY(&oBinaryWriter);
}
// slidelayouts
oBinaryWriter.StartMainRecord(NSMainTables::SlideLayouts);
ULONG nCountL = 0;
for (ULONG i = 0; i < _layouts.size(); ++i)
ULONG nCountL = 0;
for (size_t i = 0; i < _layouts.size(); ++i)
{
if (_layouts[i].IsInit())nCountL++;
}
oBinaryWriter.WriteULONG(nCountL);
for (ULONG i = 0; i < _layouts.size(); ++i)
{
if (_layouts[i].IsInit() == false)
for (size_t i = 0; i < _layouts.size(); ++i)
{
continue;
//непонятки с 42 шаблоном в FY10_September_Partner_Call.pptx
}
if (_layouts[i].IsInit() == false) continue; //непонятки с 42 шаблоном в FY10_September_Partner_Call.pptx
_layouts[i]->toPPTY(&oBinaryWriter);
}
// slides
oBinaryWriter.StartMainRecord(NSMainTables::Slides);
ULONG nCountS = (ULONG)_slides.size();
ULONG nCountS = 0;
for (size_t i = 0; i < _slides.size(); ++i)
{
if (_slides[i].IsInit()) nCountS++;
}
oBinaryWriter.WriteULONG(nCountS);
for (ULONG i = 0; i < nCountS; ++i)
for (size_t i = 0; i < _slides.size(); ++i)
{
if (_slides[i].IsInit() == false ) continue;
_slides[i]->toPPTY(&oBinaryWriter);
}
......
......@@ -81,7 +81,7 @@ namespace PPTX
for (size_t i = 0; i < nCount; ++i)
{
const OOX::Rels::CRelationShip* pRelation = rels.m_arrRelations[i];
OOX::Rels::CRelationShip* pRelation = rels.m_arrRelations[i];
OOX::CPath normPath = path / pRelation->Target();
std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = map.find(normPath);
......@@ -114,6 +114,9 @@ namespace PPTX
smart_ptr<OOX::File> file = PPTX::FileFactory::CreateFilePPTX(path, *pRelation, map);
if (file.IsInit() == false)
continue;
map.add(normPath, file);
Add(pRelation->rId(), file);
......@@ -223,7 +226,7 @@ namespace PPTX
size_t nCount = rels.m_arrRelations.size();
for (size_t i = 0; i < nCount; ++i)
{
const OOX::Rels::CRelationShip* pRelation = rels.m_arrRelations[i];
OOX::Rels::CRelationShip* pRelation = rels.m_arrRelations[i];
smart_ptr<OOX::File> _file = PPTX::FileFactory::CreateFilePPTX_OnlyMedia(path, *pRelation);
Add(pRelation->rId(), _file);
......
......@@ -30,13 +30,13 @@
*
*/
#include "FileFactory.h"
#include "../../Common/DocxFormat/Source/DocxFormat/File.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Rels.h"
#include "../../Common/DocxFormat/Source/DocxFormat/FileTypes.h"
#include "FileTypes.h"
#include "FileFactory.h"
#include "App.h"
#include "Core.h"
#include "Theme.h"
......@@ -69,12 +69,76 @@
#include "FileMap.h"
#include "../../DesktopEditor/common/Directory.h"
namespace PPTX
{
const smart_ptr<OOX::File> FileFactory::CreateFilePPTX(const OOX::CPath& path, const OOX::Rels::CRelationShip& relation, FileMap& map)
static std::wstring arDefDirectories [8][2] = //in ppt Directory
{
{L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide", L"slides"},
{L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout", L"slideLayouts"},
{L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster", L"slideMasters"},
{L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide", L"notesSlides"},
{L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster", L"notesMasters"},
{L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/handoutMaster", L"handoutMasters"},
{L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", L"comments"},
{L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/commentAuthors", L""}
};
static std::wstring FindFileInDirectory(std::wstring directory, std::wstring filename)
{
if (directory.empty()) return L"";
if (directory[directory.length() - 1] == FILE_SEPARATOR_CHAR)
directory.substr(0, directory.length() - 1);
CArray<std::wstring> arrFiles = NSDirectory::GetFiles(directory, true);
for (int i = 0 ; i < arrFiles.GetCount(); i++)
{
if (std::wstring::npos != arrFiles[i].find(filename))
{
return arrFiles[i].substr(directory.length() + 1);
}
}
return L"";
}
const smart_ptr<OOX::File> FileFactory::CreateFilePPTX(const OOX::CPath& path, OOX::Rels::CRelationShip& relation, FileMap& map)
{
OOX::CPath filename = path / relation.Filename();
if (NSFile::CFileBinary::Exists(filename.GetPath()) == false)
{//file_1_ (1).pptx
std::wstring strDefDirectory;
for (int i = 0; i < 8; i++)
{
if (relation.Type() == arDefDirectories[i][0])
{
strDefDirectory = arDefDirectories[i][1];
break;
}
}
OOX::CPath new_filename = strDefDirectory + FILE_SEPARATOR_STR + relation.Filename().GetFilename();
filename = path / new_filename;
if (NSFile::CFileBinary::Exists(filename.GetPath()) == false)
{
new_filename = FindFileInDirectory(path.GetPath(), relation.Filename().GetFilename()); // find true path by filename
filename = path / new_filename;
if (NSFile::CFileBinary::Exists(filename.GetPath()) == false)
return smart_ptr<OOX::File>(NULL);
}
relation = OOX::Rels::CRelationShip( relation.rId(), relation.Type(), new_filename);
}
if (relation.Type() == OOX::Presentation::FileTypes::App)
return smart_ptr<OOX::File>(new PPTX::App(filename, map));
else if (relation.Type() == OOX::Presentation::FileTypes::Core)
......@@ -138,7 +202,7 @@ namespace PPTX
return smart_ptr<OOX::File>(new OOX::UnknowTypeFile());
}
const smart_ptr<OOX::File> FileFactory::CreateFilePPTX_OnlyMedia(const OOX::CPath& path, const OOX::Rels::CRelationShip& relation)
const smart_ptr<OOX::File> FileFactory::CreateFilePPTX_OnlyMedia(const OOX::CPath& path, OOX::Rels::CRelationShip& relation)
{
bool bIsDownload = false;
std::wstring strFile = relation.Filename().GetPath();
......
......@@ -30,9 +30,6 @@
*
*/
#pragma once
#ifndef PPTX_FILE_FACTORY_INCLUDE_H_
#define PPTX_FILE_FACTORY_INCLUDE_H_
#include "../../Common/DocxFormat/Source/DocxFormat/File.h"
namespace OOX {namespace Rels {class CRelationShip;}}
......@@ -44,9 +41,7 @@ namespace PPTX
class FileFactory
{
public:
static const smart_ptr<OOX::File> CreateFilePPTX(const OOX::CPath& path, const OOX::Rels::CRelationShip& relation, FileMap& map);
static const smart_ptr<OOX::File> CreateFilePPTX_OnlyMedia(const OOX::CPath& path, const OOX::Rels::CRelationShip& relation);
static const smart_ptr<OOX::File> CreateFilePPTX(const OOX::CPath& path, OOX::Rels::CRelationShip& relation, FileMap& map);
static const smart_ptr<OOX::File> CreateFilePPTX_OnlyMedia(const OOX::CPath& path, OOX::Rels::CRelationShip& relation);
};
} // namespace PPTX
#endif // PPTX_FILE_FACTORY_INCLUDE_H_
\ No newline at end of file
......@@ -33,7 +33,7 @@
#ifndef PPTXOOX_FILE_TYPES_INCLUDE_H_
#define PPTXOOX_FILE_TYPES_INCLUDE_H_
#include "../../../Common/DocxFormat/Source/DocxFormat/FileType.h"
#include "../../Common/DocxFormat/Source/DocxFormat/FileType.h"
namespace OOX
{
......
......@@ -121,10 +121,12 @@ namespace PPTX
theme_= (FileContainer::Get(OOX::Presentation::FileTypes::ThemePPTX)).smart_dynamic_cast<PPTX::Theme>();
if (theme_.IsInit())
{
theme_->SetColorMap(clrMap);
tableStyles_ = (theme_->presentation->Get(OOX::Presentation::FileTypes::TableStyles)).smart_dynamic_cast<PPTX::TableStyles>();
}
}
virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const
{
......
......@@ -407,16 +407,22 @@ namespace PPTX
Layout = FileContainer::Get(OOX::Presentation::FileTypes::SlideLayout).smart_dynamic_cast<PPTX::SlideLayout>();//boost::shared_dynamic_cast<PPTX::SlideLayout, PPTX::File>(FileContainer::get(OOX::Presentation::FileTypes::SlideLayout));
Note = FileContainer::Get(OOX::Presentation::FileTypes::NotesSlide).smart_dynamic_cast<PPTX::NotesSlide>();
comments = FileContainer::Get(OOX::Presentation::FileTypes::SlideComments).smart_dynamic_cast<PPTX::Comments>();
if (Layout.IsInit())
{
Master = Layout->Master;
theme = Layout->theme;
if (theme.IsInit())
{
tableStyles_= theme->presentation->Get(OOX::Presentation::FileTypes::TableStyles).smart_dynamic_cast<PPTX::TableStyles>();//boost::shared_dynamic_cast<PPTX::TableStyles, PPTX::File>(Theme->Presentation->get(OOX::Presentation::FileTypes::TableStyles));
}
if (IsExist(OOX::Presentation::FileTypes::VmlDrawing))
{
Vml = FileContainer::Get(OOX::Presentation::FileTypes::VmlDrawing).smart_dynamic_cast<OOX::CVmlDrawing>();//boost::shared_dynamic_cast<PPTX::VmlDrawing, PPTX::File>(FileContainer::get(OOX::Presentation::FileTypes::VmlDrawing));
}
}
}
std::wstring GetVmlXmlBySpid(const std::wstring& spid)
{
......
......@@ -478,12 +478,14 @@ namespace PPTX
Master = pFile.smart_dynamic_cast<PPTX::SlideMaster>();
if (Master.IsInit())
{
theme = Master->theme;
if (theme.IsInit())
{
tableStyles = theme->presentation->Get(OOX::Presentation::FileTypes::TableStyles).smart_dynamic_cast<PPTX::TableStyles>();
}
}
if (IsExist(OOX::Presentation::FileTypes::VmlDrawing))
{
Vml = FileContainer::Get(OOX::Presentation::FileTypes::VmlDrawing).smart_dynamic_cast<OOX::CVmlDrawing>();//boost::shared_dynamic_cast<PPTX::VmlDrawing, PPTX::File>(FileContainer::get(OOX::Presentation::FileTypes::VmlDrawing));
......
......@@ -516,9 +516,11 @@ namespace PPTX
theme = (FileContainer::Get(OOX::Presentation::FileTypes::ThemePPTX)).smart_dynamic_cast<PPTX::Theme>();
if (theme.IsInit())
{
theme->SetColorMap(clrMap);
//Theme->Master.reset((PPTX::WrapperFile*)this);
tableStyles = (theme->presentation->Get(OOX::Presentation::FileTypes::TableStyles)).smart_dynamic_cast<PPTX::TableStyles>();
}
if (IsExist(OOX::Presentation::FileTypes::VmlDrawing))
{
......
......@@ -53,7 +53,8 @@ namespace OOX
FileType(const WCHAR* defaultDirectory, const WCHAR* defaultFileName,
const std::wstring& overrideType,
const std::wstring& relationType, bool bEnumerated = false, bool bEnumeratedGlobal = false ) : m_defaultDirectory(defaultDirectory),
const std::wstring& relationType, bool bEnumerated = false, bool bEnumeratedGlobal = false )
: m_defaultDirectory(defaultDirectory),
m_defaultFileName(defaultFileName),
m_overrideType(overrideType),
m_relationType(relationType),
......
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