Compare commits

...

1 Commits

Author SHA1 Message Date
7959642072 OdfFormatWriter - convert user shapes from chart 2019-01-23 14:00:52 +03:00
7 changed files with 100 additions and 20 deletions

View File

@ -36,6 +36,7 @@
#include "../utils.h"
#include "../../../Common/DocxFormat/Source/DocxFormat/Diagram/DiagramDrawing.h"
#include "../../../Common/DocxFormat/Source/DocxFormat/ChartDrawing.h"
#include "../../../Common/DocxFormat/Source/XlsxFormat/Chart/Chart.h"
#include "../../../ASCOfficePPTXFile/PPTXFormat/Slide.h"
#include "../../../ASCOfficePPTXFile/PPTXFormat/Logic/SpTreeElem.h"
@ -424,8 +425,10 @@ void OoxConverter::convert(PPTX::Logic::ChartRec *oox_chart)
if (!oox_chart) return;
if( !oox_chart->id_data.IsInit()) return;
_CP_OPT(double) width, height;
_CP_OPT(double) width, height, x, y, zero(0);
odf_context()->drawing_context()->get_size (width, height);
odf_context()->drawing_context()->get_position (x, y);
smart_ptr<OOX::File> oFile = find_file_by_id (oox_chart->id_data->get());
if (oFile.IsInit())
@ -435,6 +438,25 @@ void OoxConverter::convert(PPTX::Logic::ChartRec *oox_chart)
if (pChart)
{
oox_current_child_document = dynamic_cast<OOX::IFileContainer*>(pChart);
OOX::CChartDrawing* pChartDrawing = NULL;
if ((pChart->m_oChartSpace.m_userShapes) && (pChart->m_oChartSpace.m_userShapes->m_id))
{
oFile = find_file_by_id (*pChart->m_oChartSpace.m_userShapes->m_id);
pChartDrawing = dynamic_cast<OOX::CChartDrawing*>(oFile.operator->());
}
if ((pChartDrawing) && (false == pChartDrawing->m_arrItems.empty()))
{
odf_context()->drawing_context()->start_group();
odf_context()->drawing_context()->set_group_size (width, height, width, height);
odf_context()->drawing_context()->set_group_position (x, y, 0, 0);
odf_context()->drawing_context()->start_drawing();
odf_context()->drawing_context()->set_position (zero, zero);
odf_context()->drawing_context()->set_size (width, height);
}
odf_context()->drawing_context()->start_object(odf_context()->get_next_name_object());
{
odf_context()->start_chart();
@ -446,10 +468,59 @@ void OoxConverter::convert(PPTX::Logic::ChartRec *oox_chart)
odf_context()->end_chart();
}
odf_context()->drawing_context()->end_object();
if ((pChartDrawing) && (false == pChartDrawing->m_arrItems.empty()))
{
odf_context()->drawing_context()->end_drawing();
oox_current_child_document = dynamic_cast<OOX::IFileContainer*>(pChartDrawing);
for (size_t i = 0; i < pChartDrawing->m_arrItems.size(); i++)
{
convert(pChartDrawing->m_arrItems[i], 0, 0, width.get_value_or(0), height.get_value_or(0));
}
odf_context()->drawing_context()->end_group();
}
oox_current_child_document = NULL;
}
}
}
void OoxConverter::convert(OOX::CSizeAnchor *sz_anchor, double x0, double y0, double width, double height)
{
if (!sz_anchor) return;
_CP_OPT(double) x, y, cx, cy;
if (sz_anchor->m_oFrom.IsInit())
{
if (sz_anchor->m_oFrom->m_oX.IsInit()) x = *sz_anchor->m_oFrom->m_oX * width + x0;
if (sz_anchor->m_oFrom->m_oY.IsInit()) y = *sz_anchor->m_oFrom->m_oY * height + y0;
}
OOX::CRelSizeAnchor *relAnchor = dynamic_cast<OOX::CRelSizeAnchor*>(sz_anchor);
OOX::CAbsSizeAnchor *absAnchor = dynamic_cast<OOX::CAbsSizeAnchor*>(sz_anchor);
if ((relAnchor) && (relAnchor->m_oTo.IsInit() && sz_anchor->m_oFrom.IsInit()))
{
if (relAnchor->m_oTo->m_oX.IsInit()) cx = (*relAnchor->m_oTo->m_oX - *sz_anchor->m_oFrom->m_oX) * width;
if (relAnchor->m_oTo->m_oY.IsInit()) cy = (*relAnchor->m_oTo->m_oY - *sz_anchor->m_oFrom->m_oY) * height;
}
if ((absAnchor) && (absAnchor->m_oExt.IsInit()))
{
if (absAnchor->m_oExt->m_oCx.IsInit()) cx = *absAnchor->m_oExt->m_oCx * width;
if (absAnchor->m_oExt->m_oCy.IsInit()) cy = *absAnchor->m_oExt->m_oCy * height;
}
odf_context()->drawing_context()->start_drawing();
odf_context()->drawing_context()->set_position (x, y);
odf_context()->drawing_context()->set_size (cx, cy);
convert(sz_anchor->m_oElement.GetPointer());
odf_context()->drawing_context()->end_drawing();
}
void OoxConverter::convert(PPTX::Logic::CNvGrpSpPr *oox_cnvGrpSpPr)
{
if (!oox_cnvGrpSpPr) return;

View File

@ -231,6 +231,7 @@ namespace OOX
class CT_TextLanguageID;
class CTextProperties;
}
class CSizeAnchor;
namespace Vml
{
class CShapeType;
@ -524,6 +525,8 @@ public:
void convert(OOX::Spreadsheet::CT_ExternalData *external_data);
void convert(OOX::Spreadsheet::CT_NumData *num_data, bool categories, bool label);
void convert(OOX::Spreadsheet::CT_StrData *str_data, bool categories, bool label);
void convert(OOX::CSizeAnchor *sz_anchor, double x0, double y0, double width, double height);
//.vml............................................................................................................................
void convert(OOX::Vml::CShapeType *vml_shape_type);

View File

@ -110,10 +110,10 @@ smart_ptr<OOX::File> XlsxConverter::find_file_by_id(const std::wstring & sId)
{
smart_ptr<OOX::File> oFile;
if (xlsx_current_container)
oFile = xlsx_current_container->Find(sId);
else if (oox_current_child_document)
if (oox_current_child_document)
oFile = oox_current_child_document->Find(sId);
else if (xlsx_current_container)
oFile = xlsx_current_container->Find(sId);
return oFile;
}
@ -122,17 +122,17 @@ std::wstring XlsxConverter::find_link_by_id (const std::wstring & sId, int type)
smart_ptr<OOX::File> oFile;
std::wstring ref;
if (xlsx_current_container)
{
oFile = xlsx_current_container->Find(sId);
ref = OoxConverter::find_link_by(oFile, type);
}
if (!ref.empty()) return ref;
if (oox_current_child_document)
{
oFile = oox_current_child_document->Find(sId);
ref = OoxConverter::find_link_by(oFile, type);
}
if (!ref.empty()) return ref;
if (xlsx_current_container)
{
oFile = xlsx_current_container->Find(sId);
ref = OoxConverter::find_link_by(oFile, type);
}
return ref;
}

View File

@ -180,17 +180,22 @@ namespace PPTX
return;
NSBinPptxRW::CDrawingConverter oDrawingConverter;
NSBinPptxRW::CBinaryFileWriter* pOldWriter = oDrawingConverter.m_pBinaryWriter;
oDrawingConverter.m_pBinaryWriter = pWriter;
smart_ptr<OOX::IFileContainer> oldRels = oDrawingConverter.GetRels();
NSBinPptxRW::CBinaryFileWriter *pOldDrawingWriter = oDrawingConverter.m_pBinaryWriter;
BinDocxRW::CDocxSerializer *pOldMainDocument = pWriter->m_pMainDocument;
pWriter->m_pMainDocument = NULL;
oDrawingConverter.m_pBinaryWriter = pWriter;
smart_ptr<OOX::IFileContainer> oldRels = oDrawingConverter.GetRels();
oDrawingConverter.SetRels(pChart.smart_dynamic_cast<OOX::IFileContainer>());
BinXlsxRW::BinaryChartWriter oBinaryChartWriter(*pWriter, &oDrawingConverter);
oBinaryChartWriter.WriteCT_ChartSpace(*pChart);
oDrawingConverter.SetRels(oldRels);
oDrawingConverter.m_pBinaryWriter = pOldWriter;
oDrawingConverter.m_pBinaryWriter = pOldDrawingWriter;
pWriter->m_pMainDocument = pOldMainDocument;
}
std::wstring ChartRec::toXML() const
{

View File

@ -33,6 +33,7 @@
#include "IFileContainer.h"
#include "../../../../ASCOfficePPTXFile/PPTXFormat/Logic/SpTreeElem.h"
#include "../XlsxFormat/WritingElement.h"
namespace OOX
{

View File

@ -351,22 +351,22 @@ namespace OOX
if(comment->m_dLeftMM.IsInit())
{
SimpleTypes::CPoint oPoint; oPoint.FromMm(comment->m_dLeftMM.get());
sStyle += L"margin-left:" + OOX::Spreadsheet::SpreadsheetCommon::WriteDouble(oPoint.ToPoints()) + L"pt;";
sStyle += L"margin-left:" + XmlUtils::DoubleToString(oPoint.ToPoints()) + L"pt;";
}
if(comment->m_dTopMM.IsInit())
{
SimpleTypes::CPoint oPoint; oPoint.FromMm(comment->m_dTopMM.get());
sStyle += L"margin-top:" + OOX::Spreadsheet::SpreadsheetCommon::WriteDouble(oPoint.ToPoints()) + L"pt;";
sStyle += L"margin-top:" + XmlUtils::DoubleToString(oPoint.ToPoints()) + L"pt;";
}
if(comment->m_dWidthMM.IsInit())
{
SimpleTypes::CPoint oPoint; oPoint.FromMm(comment->m_dWidthMM.get());
sStyle += L"width:" + OOX::Spreadsheet::SpreadsheetCommon::WriteDouble(oPoint.ToPoints()) + L"pt;";
sStyle += L"width:" + XmlUtils::DoubleToString(oPoint.ToPoints()) + L"pt;";
}
if(comment->m_dHeightMM.IsInit())
{
SimpleTypes::CPoint oPoint; oPoint.FromMm(comment->m_dHeightMM.get());
sStyle += L"height:" + OOX::Spreadsheet::SpreadsheetCommon::WriteDouble(oPoint.ToPoints()) + L"pt;";
sStyle += L"height:" + XmlUtils::DoubleToString(oPoint.ToPoints()) + L"pt;";
}
std::wstring sClientData = L"<x:ClientData ObjectType=\"Note\">";

View File

@ -49,7 +49,7 @@ namespace Spreadsheet
// writer.WriteString(end);
#define WritingStringCommonDouble(start, val, end) \
writer.WriteString(start); \
writer.WriteString(OOX::Spreadsheet::SpreadsheetCommon::WriteDouble(val)); \
writer.WriteString(XmlUtils::DoubleToString(val)); \
writer.WriteString(end);