Skip to content

Commit

Permalink
OoxmlFormat - convert border in vml shape
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaSubbotina committed Apr 6, 2018
1 parent b04f44e commit 4b8bc2c
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 87 deletions.
86 changes: 85 additions & 1 deletion ASCOfficePPTXFile/ASCOfficeDrawingConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@

const double g_emu_koef = 25.4 * 36000 / 72.0;

using namespace NSGuidesVML;

void DUMP_MESSAGE_TO_FILE(const char* strMessage)
{
Expand Down Expand Up @@ -853,6 +852,10 @@ bool CElementProps::CopyProperty(ASC_VARIANT& oDst, const ASC_VARIANT& oSrc)
}
return true;
}

namespace NSBinPptxRW
{

CDrawingConverter::CElement::CElement()
{
m_pElement = NULL;
Expand Down Expand Up @@ -2864,6 +2867,8 @@ void CDrawingConverter::doc_LoadShape(PPTX::Logic::SpTreeElem *elem, XmlUtils::C
CheckPenShape(elem, oNodeShape, pPPTShape);

CheckBrushShape(elem, oNodeShape, pPPTShape);

CheckBorderShape(elem, oNodeShape, pPPTShape);
}
}

Expand Down Expand Up @@ -3914,6 +3919,84 @@ void CDrawingConverter::SendMainProps(const std::wstring& strMainProps, std::wst
*pMainProps = new std::wstring();
**pMainProps = strMainProps;
}
void CDrawingConverter::CheckBorderShape(PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape)
{
if (!oElem) return;

PPTX::Logic::Shape* pShape = dynamic_cast<PPTX::Logic::Shape*> (oElem->GetElem().operator ->());
PPTX::Logic::Pic* pPicture = dynamic_cast<PPTX::Logic::Pic*> (oElem->GetElem().operator ->());

PPTX::Logic::SpPr *pSpPr = NULL;

if (pShape) pSpPr = &pShape->spPr;
if (pPicture) pSpPr = &pPicture->spPr;

if (!pSpPr) return;

if ( (pSpPr->ln.IsInit()) && (pSpPr->ln->Fill.m_type != PPTX::Logic::UniFill::noFill) )
return; //дублирование обрамлением линией

nullable_string sColorBorder;
oNode.ReadAttributeBase(L"o:borderleftcolor", sColorBorder);

XmlUtils::CXmlNode oNodeBorder = oNode.ReadNode(L"w10:borderleft");

if (oNodeBorder.IsValid())
{
pSpPr->ln.Init();
nullable_int nWidthBorder;
oNode.ReadAttributeBase(L"width", nWidthBorder);

nullable_string sTypeBorder;
oNode.ReadAttributeBase(L"type", sTypeBorder);

if (sTypeBorder.IsInit())
{
SimpleTypes::CBorderType<> borderType;
borderType.FromString(sTypeBorder.get());

if (borderType.GetValue() > 0 &&
borderType.GetValue() < 6)
{
pSpPr->ln->prstDash.Init();
pSpPr->ln->prstDash->val = new PPTX::Limit::PrstDashVal();
switch(borderType.GetValue())
{
case SimpleTypes::bordertypeDash: pSpPr->ln->prstDash->val->SetBYTECode(3); break;
case SimpleTypes::bordertypeDashDotDot: pSpPr->ln->prstDash->val->SetBYTECode(5); break;
case SimpleTypes::bordertypeDashDotStroked: pSpPr->ln->prstDash->val->SetBYTECode(1); break;
case SimpleTypes::bordertypeDashedSmall: pSpPr->ln->prstDash->val->SetBYTECode(0); break;
case SimpleTypes::bordertypeDot: pSpPr->ln->prstDash->val->SetBYTECode(2); break;
case SimpleTypes::bordertypeDotDash: pSpPr->ln->prstDash->val->SetBYTECode(1); break;
}
}

}
if (nWidthBorder.IsInit())
{
pSpPr->ln->w = *nWidthBorder * g_emu_koef;//pt to emu
}
if (sColorBorder.IsInit())
{
PPTX::Logic::SolidFill* pSolid = new PPTX::Logic::SolidFill();
pSolid->m_namespace = L"a";
pSolid->Color.Color = new PPTX::Logic::SrgbClr();

if (std::wstring::npos != sColorBorder->find(L"#"))
{
pSolid->Color.Color->SetHexString(sColorBorder->substr(1));
}
else
{
//"red", L"black" , .. to color
}

pSpPr->ln->Fill.m_type = PPTX::Logic::UniFill::solidFill;
pSpPr->ln->Fill.Fill = pSolid;

}
}
}

void CDrawingConverter::CheckBrushShape(PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape)
{
Expand Down Expand Up @@ -5572,3 +5655,4 @@ void CDrawingConverter::SetFontManager(CFontManager* pFontManager)
m_pBinaryWriter->m_pCommon->m_pMediaManager->SetFontManager(pFontManager);
}
}
}
1 change: 1 addition & 0 deletions ASCOfficePPTXFile/ASCOfficeDrawingConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ namespace NSBinPptxRW

void CheckBrushShape (PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape);
void CheckPenShape (PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape);
void CheckBorderShape (PPTX::Logic::SpTreeElem* oElem, XmlUtils::CXmlNode& oNode, CPPTShape* pPPTShape);

void LoadCoordSize (XmlUtils::CXmlNode& oNode, ::CShapePtr pShape);
void LoadCoordPos (XmlUtils::CXmlNode& oNode, ::CShapePtr pShape);
Expand Down
64 changes: 31 additions & 33 deletions ASCOfficePPTXFile/Editor/Converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

namespace PPTX2EditorAdvanced
{
using namespace NSBinPptxRW;

DWORD Convert(NSBinPptxRW::CBinaryFileWriter& oBinaryWriter, PPTX::Document& oFolder, const std::wstring& strSourceDirectory, const std::wstring& strDstFile, bool bIsNoBase64)
{
// сначала соберем все объекты для конвертации и сформируем main-таблицы
Expand Down Expand Up @@ -74,8 +72,8 @@ namespace PPTX2EditorAdvanced
continue;
}

oBinaryWriter.m_pCommon->m_oRels.push_back (_masterSlideInfo());
_masterSlideInfo& oMasterInfo = oBinaryWriter.m_pCommon->m_oRels[oBinaryWriter.m_pCommon->m_oRels.size() - 1];
oBinaryWriter.m_pCommon->m_oRels.push_back (NSBinPptxRW::_masterSlideInfo());
NSBinPptxRW::_masterSlideInfo& oMasterInfo = oBinaryWriter.m_pCommon->m_oRels[oBinaryWriter.m_pCommon->m_oRels.size() - 1];

// записываем mainMaster
LONG lCountSM = (LONG)_slideMasters.size();
Expand Down Expand Up @@ -232,7 +230,7 @@ namespace PPTX2EditorAdvanced

if (bIsNoBase64)
{
std::wstring strPrefix = L"PPTY;v"+std::to_wstring(g_nFormatVersionNoBase64)+L";0;";
std::wstring strPrefix = L"PPTY;v"+std::to_wstring(NSBinPptxRW::g_nFormatVersionNoBase64)+L";0;";
oBinaryWriter.WriteStringUtf8(strPrefix);
}
_UINT32 nStartPos = oBinaryWriter.GetPosition();
Expand All @@ -242,56 +240,56 @@ namespace PPTX2EditorAdvanced
oBinaryWriter.WriteReserved(5 * 30);

// Main
oBinaryWriter.StartMainRecord(NSMainTables::Main);
oBinaryWriter.WriteULONG(NSSerFormat::Signature);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::Main);
oBinaryWriter.WriteULONG(NSBinPptxRW::NSSerFormat::Signature);
oBinaryWriter.WriteULONG(0);

// App
smart_ptr<PPTX::App> app = oFolder.Get(OOX::FileTypes::App).smart_dynamic_cast<PPTX::App>();
if (app.is_init())
{
oBinaryWriter.StartMainRecord(NSMainTables::App);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::App);
app->toPPTY(&oBinaryWriter);
}

// Core
smart_ptr<PPTX::Core> core = oFolder.Get(OOX::FileTypes::Core).smart_dynamic_cast<PPTX::Core>();
if (core.is_init())
{
oBinaryWriter.StartMainRecord(NSMainTables::Core);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::Core);
core->toPPTY(&oBinaryWriter);
}

// PresProps
smart_ptr<PPTX::PresProps> presProps = presentation->Get(OOX::Presentation::FileTypes::PresProps).smart_dynamic_cast<PPTX::PresProps>();
if (presProps.is_init())
{
oBinaryWriter.StartMainRecord(NSMainTables::PresProps);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::PresProps);
presProps->toPPTY(&oBinaryWriter);
}

// ViewProps
smart_ptr<PPTX::ViewProps> viewProps = presentation->Get(OOX::Presentation::FileTypes::ViewProps).smart_dynamic_cast<PPTX::ViewProps>();
if (viewProps.is_init())
{
oBinaryWriter.StartMainRecord(NSMainTables::ViewProps);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::ViewProps);
viewProps->toPPTY(&oBinaryWriter);
}

// TableStyles
smart_ptr<PPTX::TableStyles> tablestyles = presentation->Get(OOX::Presentation::FileTypes::TableStyles).smart_dynamic_cast<PPTX::TableStyles>();
if (tablestyles.is_init())
{
oBinaryWriter.StartMainRecord(NSMainTables::TableStyles);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::TableStyles);
tablestyles->toPPTY(&oBinaryWriter);
}

// Presentation
oBinaryWriter.StartMainRecord(NSMainTables::Presentation);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::Presentation);
presentation->toPPTY(&oBinaryWriter);

// themes
oBinaryWriter.StartMainRecord(NSMainTables::Themes);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::Themes);

ULONG nCountThemes = 0;
for (size_t i = 0; i < _themes.size(); ++i)
Expand All @@ -307,7 +305,7 @@ namespace PPTX2EditorAdvanced
}

// slidemasters
oBinaryWriter.StartMainRecord(NSMainTables::SlideMasters);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::SlideMasters);

ULONG nCountSM = 0;
for (size_t i = 0; i < _slideMasters.size(); ++i)
Expand All @@ -324,7 +322,7 @@ namespace PPTX2EditorAdvanced
}

// slidelayouts
oBinaryWriter.StartMainRecord(NSMainTables::SlideLayouts);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::SlideLayouts);

ULONG nCountL = 0;
for (size_t i = 0; i < _layouts.size(); ++i)
Expand All @@ -341,7 +339,7 @@ namespace PPTX2EditorAdvanced
}

// slides
oBinaryWriter.StartMainRecord(NSMainTables::Slides);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::Slides);

ULONG nCountS = 0;
for (size_t i = 0; i < _slides.size(); ++i)
Expand All @@ -358,7 +356,7 @@ namespace PPTX2EditorAdvanced
}

// notes
oBinaryWriter.StartMainRecord(NSMainTables::NotesSlides);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::NotesSlides);
ULONG nCountN = (ULONG)_notes.size();
oBinaryWriter.WriteULONG(nCountN);
for (ULONG i = 0; i < nCountN; ++i)
Expand All @@ -367,7 +365,7 @@ namespace PPTX2EditorAdvanced
}

// notesmasters
oBinaryWriter.StartMainRecord(NSMainTables::NotesMasters);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::NotesMasters);
ULONG nCountNM = (ULONG)_notesMasters.size();
oBinaryWriter.WriteULONG(nCountNM);
for (ULONG i = 0; i < nCountNM; ++i)
Expand All @@ -376,8 +374,8 @@ namespace PPTX2EditorAdvanced
}

// ImageMap ---------------------------------------
oBinaryWriter.StartMainRecord(NSMainTables::ImageMap);
oBinaryWriter.StartRecord(NSMainTables::ImageMap);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::ImageMap);
oBinaryWriter.StartRecord(NSBinPptxRW::NSMainTables::ImageMap);
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);

std::map<std::wstring, NSShapeImageGen::CMediaInfo>* pIMaps = &oBinaryWriter.m_pCommon->m_pMediaManager->m_mapMediaFiles;
Expand All @@ -396,8 +394,8 @@ namespace PPTX2EditorAdvanced
// ------------------------------------------------

// FontMap ----------------------------------------
oBinaryWriter.StartMainRecord(NSMainTables::FontMap);
oBinaryWriter.StartRecord(NSMainTables::FontMap);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::FontMap);
oBinaryWriter.StartRecord(NSBinPptxRW::NSMainTables::FontMap);
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);

std::map<std::wstring, std::wstring>* pFMaps = &oBinaryWriter.m_pCommon->m_pNativePicker->m_mapPicks;
Expand All @@ -417,8 +415,8 @@ namespace PPTX2EditorAdvanced
if (TRUE)
{
// SlideRels --------------------------------------
oBinaryWriter.StartMainRecord(NSMainTables::SlideRels);
oBinaryWriter.StartRecord(NSMainTables::SlideRels);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::SlideRels);
oBinaryWriter.StartRecord(NSBinPptxRW::NSMainTables::SlideRels);
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);

size_t _s_rels = oBinaryWriter.m_pCommon->m_oSlide_Layout_Rels.size();
Expand All @@ -432,8 +430,8 @@ namespace PPTX2EditorAdvanced
// ------------------------------------------------

// SlideNotesRels --------------------------------------
oBinaryWriter.StartMainRecord(NSMainTables::SlideNotesRels);
oBinaryWriter.StartRecord(NSMainTables::SlideNotesRels);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::SlideNotesRels);
oBinaryWriter.StartRecord(NSBinPptxRW::NSMainTables::SlideNotesRels);
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);

_s_rels = oBinaryWriter.m_pCommon->m_oSlide_Notes_Rels.size();
Expand All @@ -447,8 +445,8 @@ namespace PPTX2EditorAdvanced
// ------------------------------------------------

// ThemeRels --------------------------------------
oBinaryWriter.StartMainRecord(NSMainTables::ThemeRels);
oBinaryWriter.StartRecord(NSMainTables::ThemeRels);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::ThemeRels);
oBinaryWriter.StartRecord(NSBinPptxRW::NSMainTables::ThemeRels);

std::vector <NSBinPptxRW::_masterSlideInfo>& th_rels = oBinaryWriter.m_pCommon->m_oRels;
oBinaryWriter.WriteULONG((ULONG)th_rels.size());
Expand Down Expand Up @@ -486,8 +484,8 @@ namespace PPTX2EditorAdvanced
// ------------------------------------------------

// NoteRels --------------------------------------
oBinaryWriter.StartMainRecord(NSMainTables::NotesRels);
oBinaryWriter.StartRecord(NSMainTables::NotesRels);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::NotesRels);
oBinaryWriter.StartRecord(NSBinPptxRW::NSMainTables::NotesRels);
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);

_s_rels = oBinaryWriter.m_pCommon->m_oNote_Rels.size();
Expand All @@ -501,8 +499,8 @@ namespace PPTX2EditorAdvanced
// ------------------------------------------------

// NoteRels --------------------------------------
oBinaryWriter.StartMainRecord(NSMainTables::NotesMastersRels);
oBinaryWriter.StartRecord(NSMainTables::NotesMastersRels);
oBinaryWriter.StartMainRecord(NSBinPptxRW::NSMainTables::NotesMastersRels);
oBinaryWriter.StartRecord(NSBinPptxRW::NSMainTables::NotesMastersRels);
oBinaryWriter.WriteBYTE(NSBinPptxRW::g_nodeAttributeStart);

_s_rels = oBinaryWriter.m_pCommon->m_oNotesMasters_Rels.size();
Expand Down
Loading

0 comments on commit 4b8bc2c

Please sign in to comment.