diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /include/oox/export | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/oox/export')
-rw-r--r-- | include/oox/export/DMLPresetShapeExport.hxx | 140 | ||||
-rw-r--r-- | include/oox/export/chartexport.hxx | 279 | ||||
-rw-r--r-- | include/oox/export/drawingml.hxx | 382 | ||||
-rw-r--r-- | include/oox/export/shapes.hxx | 213 | ||||
-rw-r--r-- | include/oox/export/utils.hxx | 80 | ||||
-rw-r--r-- | include/oox/export/vmlexport.hxx | 209 |
6 files changed, 1303 insertions, 0 deletions
diff --git a/include/oox/export/DMLPresetShapeExport.hxx b/include/oox/export/DMLPresetShapeExport.hxx new file mode 100644 index 000000000..1f650f558 --- /dev/null +++ b/include/oox/export/DMLPresetShapeExport.hxx @@ -0,0 +1,140 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* +* This file is part of the LibreOffice project. +* +* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#ifndef INCLUDED_OOX_EXPORT_DMLPRESETSHAPEXPORT_HXX +#define INCLUDED_OOX_EXPORT_DMLPRESETSHAPEXPORT_HXX + +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <rtl/ustring.hxx> +#include <sal/types.h> + +#include <string_view> + +#include <oox/export/drawingml.hxx> + +namespace com::sun::star::beans +{ +struct PropertyValue; +} + +namespace com::sun::star::drawing +{ +class XShape; +struct EnhancedCustomShapeAdjustmentValue; +} + +namespace oox::core +{ +class XmlFilterBase; +} + +namespace oox::drawingml +{ +/// Class for exporting the custom shapes to OOXML preset ones, if possible. +/// This functionality needed for keeping the information for the office programs +/// about the shape type, and geometry data. Before these shapes were exported +/// with custom geometry, and they kept their geometry but has no information +/// about the shape itself. This lead to lost textbox size/position/padding for +/// example. +class DMLPresetShapeExporter +{ +private: + // the shape to export + css::uno::Reference<css::drawing::XShape> m_xShape; + // the DMLwriter + DrawingML* m_pDMLexporter; + // the type of the custom shape (diamond/rectangle/circle/triangle...) + OUString m_sPresetShapeType; + // True if the shape has points where its geometry can be modified + bool m_bHasHandleValues; + // The first the x the second the y coordinate, of flipping + std::pair<bool, bool> m_bIsFlipped; + + // Custom Shape Geometry information for export: + + // The adjusting values stored in this sequence: + css::uno::Sequence<css::drawing::EnhancedCustomShapeAdjustmentValue> m_AdjustmentValues; + // Shapes what have adjusting points, the range of these points + // and the index of the value stored in this sequence: + css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>> m_HandleValues; + + //TODO: + //css::awt::Rectangle m_ViewBox; + //css::uno::Sequence<css::beans::PropertyValue> m_Path; + //css::uno::Sequence<OUString> m_Equations; + +public: + DMLPresetShapeExporter() = delete; + ~DMLPresetShapeExporter(); + + DMLPresetShapeExporter(DrawingML* pDMLExporter, + css::uno::Reference<css::drawing::XShape> xShape); + + // Writes the preset shape to the xml + bool WriteShape(); + +private: + struct AdjustmentPointValueBase + { + std::optional<double> nMaxVal; + std::optional<double> nMinVal; + std::optional<double> nCurrVal; + }; + + typedef AdjustmentPointValueBase RadiusAdjustmentValue; + typedef AdjustmentPointValueBase AngleAdjustmentValue; + typedef AdjustmentPointValueBase XAdjustmentValue; + typedef AdjustmentPointValueBase YAdjustmentValue; + + // Returns true, if the shape has adjusting points + bool HasHandleValue() const; + + // Returns true if the shape flipped. + bool IsXFlipped() const { return m_bIsFlipped.first; }; + bool IsYFlipped() const { return m_bIsFlipped.second; }; + + // Returns with the shape type, like triangle for example + const OUString& GetShapeType() const; + // Returns with the handle points + const css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>>& + GetHandleValues() const; + // Returns with the adjustment values + const css::uno::Sequence<css::drawing::EnhancedCustomShapeAdjustmentValue>& + GetAdjustmentValues() const; + // Returns with the raw value of the given property of the shape geometry. + css::uno::Any GetHandleValueOfModificationPoint(sal_Int32 nPoint, std::u16string_view sType); + // Returns with the appropriate value of the handle point. + RadiusAdjustmentValue GetAdjustmentPointRadiusValue(sal_Int32 nPoint); + AngleAdjustmentValue GetAdjustmentPointAngleValue(sal_Int32 nPoint); + XAdjustmentValue GetAdjustmentPointXValue(sal_Int32 nPoint); + YAdjustmentValue GetAdjustmentPointYValue(sal_Int32 nPoint); + + // Writes one adjustment point. + bool WriteAV(const OUString& sValName, const OUString& sVal); + // Opens/Closes the AVlist tag. + bool StartAVListWriting(); + bool EndAVListWriting(); + + // Finds the given value in the sequence + static css::uno::Any FindHandleValue(css::uno::Sequence<css::beans::PropertyValue> aValues, + std::u16string_view sKey); + // Writes and converts the adjustment points from sdr to ooxml ones per shape type. + bool WriteShapeWithAVlist(); + +}; // end of DMLPresetShapeExporter class + +} // end of namespace oox::drawingml + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/export/chartexport.hxx b/include/oox/export/chartexport.hxx new file mode 100644 index 000000000..6a40254f6 --- /dev/null +++ b/include/oox/export/chartexport.hxx @@ -0,0 +1,279 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_OOX_EXPORT_CHARTEXPORT_HXX +#define INCLUDED_OOX_EXPORT_CHARTEXPORT_HXX + +#include <set> +#include <vector> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <oox/dllapi.h> +#include <oox/export/drawingml.hxx> +#include <oox/export/shapes.hxx> +#include <oox/export/utils.hxx> +#include <oox/token/tokens.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <sax/fshelper.hxx> + +namespace com::sun::star { + namespace beans { + class XPropertySet; + } + namespace chart { + class XDiagram; + class XChartDocument; + } + namespace chart2 { + struct RelativePosition; + struct RelativeSize; + class XDiagram; + class XChartDocument; + class XDataSeries; + class XChartType; + namespace data + { + class XDataSequence; + class XLabeledDataSequence; + } + } + namespace drawing { + class XShape; + } + namespace frame { + class XModel; + } +} + +namespace oox { +namespace core { + class XmlFilterBase; +}} + +namespace oox::drawingml { + +enum AxesType +{ + AXIS_PRIMARY_X = 1, + AXIS_PRIMARY_Y = 2, + AXIS_PRIMARY_Z = 3, + AXIS_SECONDARY_X = 4, + AXIS_SECONDARY_Y = 5 +}; + +struct AxisIdPair{ + AxesType nAxisType; + sal_Int32 nAxisId; + sal_Int32 nCrossAx; + + AxisIdPair(AxesType nType, sal_Int32 nId, sal_Int32 nAx) + : nAxisType(nType) + , nAxisId(nId) + , nCrossAx(nAx) + {} +}; + +/** + A helper container class to collect the chart data point labels and the address + of the cell[range] from which the labels are sourced if that is the case. This + is then used to write the label texts under the extension tag <c15:datalabelsRange>. + + @since LibreOffice 7.3.0 + */ +class DataLabelsRange +{ +public: + + /// type of the internal container that stores the indexed label text. + typedef std::map<sal_Int32, OUString> LabelsRangeMap; + + /// Returns whether the container is empty or not. + bool empty() const; + /// Returns the count of labels stored. + size_t count() const; + /// Indicates whether the container has a label with index specified by nIndex. + bool hasLabel(sal_Int32 nIndex) const; + /// Returns the address of the cell[range] from which label contents are sourced. + const OUString & getRange() const; + + /// Sets the address of the cell[range] from which label contents are sourced. + void setRange(const OUString& rRange); + /// Adds a new indexed label text. + void setLabel(sal_Int32 nIndex, const OUString& rText); + + LabelsRangeMap::const_iterator begin() const; + LabelsRangeMap::const_iterator end() const; + +private: + OUString maRange; + LabelsRangeMap maLabels; +}; + + +class OOX_DLLPUBLIC ChartExport final : public DrawingML { + +public: + // first: data sequence for label, second: data sequence for values. + typedef ::std::vector< AxisIdPair > AxisVector; + +private: + sal_Int32 mnXmlNamespace; + sal_Int32 mnSeriesCount; + css::uno::Reference< css::frame::XModel > mxChartModel; + css::uno::Reference< css::chart::XDiagram > mxDiagram; + css::uno::Reference< css::chart2::XDiagram > mxNewDiagram; + std::shared_ptr<URLTransformer> mpURLTransformer; + + // members filled by InitRangeSegmentationProperties (retrieved from DataProvider) + bool mbHasCategoryLabels; //if the categories are only automatically generated this will be false + + //css::uno::Reference< css::drawing::XShapes > mxAdditionalShapes; + css::uno::Reference< css::chart2::data::XDataSequence > mxCategoriesValues; + + AxisVector maAxes; + bool mbHasZAxis; + bool mbIs3DChart; + bool mbStacked; + bool mbPercent; + bool mbHasDateCategories; + + std::set<sal_Int32> maExportedAxis; + +private: + sal_Int32 getChartType(); + + css::uno::Sequence< css::uno::Sequence< rtl::OUString > > getSplitCategoriesList(const OUString& rRange); + + OUString parseFormula( const OUString& rRange ); + void InitPlotArea(); + + void ExportContent_(); + void exportChartSpace( const css::uno::Reference< + css::chart::XChartDocument >& rChartDoc, + bool bIncludeTable ); + void exportChart( const css::uno::Reference< + css::chart::XChartDocument >& rChartDoc ); + void exportExternalData( const css::uno::Reference< + css::chart::XChartDocument >& rChartDoc ); + void exportLegend( const css::uno::Reference< + css::chart::XChartDocument >& rChartDoc ); + void exportTitle( const css::uno::Reference< css::drawing::XShape >& xShape, + const OUString* pSubText = nullptr ); + void exportPlotArea( const css::uno::Reference< + css::chart::XChartDocument >& rChartDoc ); + void exportAdditionalShapes( const css::uno::Reference<css::chart::XChartDocument >& rChartDoc ); + void exportFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); + void exportSolidFill(const css::uno::Reference<css::beans::XPropertySet>& xPropSet); + void exportGradientFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); + void exportBitmapFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); + void exportHatch(const css::uno::Reference<css::beans::XPropertySet>& xPropSet); + void exportDataTable( ); + + void exportAreaChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); + void exportBarChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); + void exportBubbleChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); + void exportDoughnutChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); + void exportLineChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); + void exportPieChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); + void exportRadarChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); + void exportScatterChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); + void exportScatterChartSeries( const css::uno::Reference< css::chart2::XChartType >& xChartType, + const css::uno::Sequence<css::uno::Reference<css::chart2::XDataSeries>>* pSeries); + void exportStockChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); + void exportSurfaceChart( const css::uno::Reference< css::chart2::XChartType >& xChartType ); + void exportHiLowLines(); + void exportUpDownBars(const css::uno::Reference< css::chart2::XChartType >& xChartType ); + + void exportAllSeries(const css::uno::Reference<css::chart2::XChartType>& xChartType, bool& rPrimaryAxes); + void exportSeries(const css::uno::Reference< css::chart2::XChartType >& xChartType, + const css::uno::Sequence<css::uno::Reference<css::chart2::XDataSeries> >& rSeriesSeq, bool& rPrimaryAxes); + + void exportVaryColors(const css::uno::Reference<css::chart2::XChartType>& xChartType); + void exportCandleStickSeries( + const css::uno::Sequence< + css::uno::Reference< + css::chart2::XDataSeries > > & aSeriesSeq, + bool& rPrimaryAxes ); + void exportSeriesText( + const css::uno::Reference< css::chart2::data::XDataSequence >& xValueSeq ); + void exportSeriesCategory( + const css::uno::Reference< css::chart2::data::XDataSequence >& xValueSeq, sal_Int32 nValueType = XML_cat ); + void exportSeriesValues( + const css::uno::Reference< css::chart2::data::XDataSequence >& xValueSeq, sal_Int32 nValueType = XML_val ); + void exportShapeProps( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); + void exportDataPoints( + const css::uno::Reference< css::beans::XPropertySet >& xSeriesProperties, + sal_Int32 nSeriesLength, sal_Int32 eChartType ); + void exportDataLabels( const css::uno::Reference<css::chart2::XDataSeries>& xSeries, sal_Int32 nSeriesLength, + sal_Int32 eChartType, DataLabelsRange& rDLblsRange ); + void exportGrouping( bool isBar = false ); + void exportTrendlines( const css::uno::Reference< css::chart2::XDataSeries >& xSeries ); + void exportMarker( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); + void exportSmooth(); + void exportFirstSliceAng(); + + void exportErrorBar(const css::uno::Reference< css::beans::XPropertySet >& xErrorBarProps, + bool bYError); + + void exportManualLayout(const css::chart2::RelativePosition& rPos, const css::chart2::RelativeSize& rSize, const bool bIsExcludingDiagramPositioning); + + void exportAxes( ); + void exportAxis(const AxisIdPair& rAxisIdPair); + void _exportAxis( + const css::uno::Reference< css::beans::XPropertySet >& xAxisProp, + const css::uno::Reference< css::drawing::XShape >& xAxisTitle, + const css::uno::Reference< css::beans::XPropertySet >& xMajorGrid, + const css::uno::Reference< css::beans::XPropertySet >& xMinorGrid, + sal_Int32 nAxisType, + const char* sAxisPos, + const AxisIdPair& rAxisIdPair ); + void exportAxesId(bool bPrimaryAxes, bool bCheckCombinedAxes = false); + void exportView3D(); + bool isDeep3dChart(); + + void exportMissingValueTreatment(const css::uno::Reference<css::beans::XPropertySet>& xPropSet); + + OUString getNumberFormatCode(sal_Int32 nKey) const; + +public: + + ChartExport( sal_Int32 nXmlNamespace, ::sax_fastparser::FSHelperPtr pFS, css::uno::Reference< css::frame::XModel > const & xModel, + ::oox::core::XmlFilterBase* pFB, DocumentType eDocumentType ); + virtual ~ChartExport() {} + + void SetURLTranslator(const std::shared_ptr<URLTransformer>& pTransformer); + + const css::uno::Reference< css::frame::XModel >& getModel() const { return mxChartModel; } + + void WriteChartObj( const css::uno::Reference< css::drawing::XShape >& xShape, sal_Int32 nID, sal_Int32 nChartCount ); + void exportTextProps(const css::uno::Reference< css::beans::XPropertySet >& xPropSet); + + void ExportContent(); + void InitRangeSegmentationProperties( + const css::uno::Reference< + css::chart2::XChartDocument > & xChartDoc ); +}; + +} + +#endif // INCLUDED_OOX_EXPORT_CHARTEXPORT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx new file mode 100644 index 000000000..8b57523a5 --- /dev/null +++ b/include/oox/export/drawingml.hxx @@ -0,0 +1,382 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_OOX_EXPORT_DRAWINGML_HXX +#define INCLUDED_OOX_EXPORT_DRAWINGML_HXX + +#include <map> +#include <stack> +#include <string_view> +#include <unordered_map> +#include <vector> + +#include <com/sun/star/beans/PropertyState.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/style/ParagraphAdjust.hpp> +#include <com/sun/star/drawing/Hatch.hpp> +#include <com/sun/star/i18n/ScriptType.hpp> +#include <oox/dllapi.h> +#include <oox/drawingml/drawingmltypes.hxx> +#include <oox/token/tokens.hxx> +#include <oox/export/utils.hxx> +#include <rtl/string.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <sax/fshelper.hxx> +#include <svx/msdffdef.hxx> +#include <vcl/checksum.hxx> +#include <vcl/graph.hxx> +#include <tools/gen.hxx> +#include <tools/color.hxx> +#include <vcl/mapmod.hxx> +#include <svx/EnhancedCustomShape2d.hxx> + +class Graphic; +class SdrObjCustomShape; +enum class SvxDateFormat; +enum class SvxTimeFormat; + +namespace com::sun::star { +namespace awt { + struct FontDescriptor; + struct Gradient; +} +namespace beans { + struct PropertyValue; + class XPropertySet; + class XPropertyState; +} +namespace drawing { + class XShape; + struct EnhancedCustomShapeParameterPair; + struct EnhancedCustomShapeParameter; +} +namespace graphic { + class XGraphic; +} +namespace style { + struct LineSpacing; +} +namespace text { + class XTextContent; + class XTextRange; + class XTextFrame; +} +namespace io { + class XOutputStream; +} +namespace uno { + class XInterface; +} +namespace frame { + class XModel; +} +} + +struct EscherConnectorListEntry; +class OutlinerParaObject; +namespace tools { class Rectangle; } + +namespace tools { + class PolyPolygon; +} + +namespace oox { +namespace core { + class XmlFilterBase; +} + +namespace drawingml { + +class OOX_DLLPUBLIC URLTransformer +{ +public: + virtual ~URLTransformer(); + + virtual OUString getTransformedString(const OUString& rURL) const; + + virtual bool isExternalURL(const OUString& rURL) const; +}; + +// Our rotation is counter-clockwise and is in 100ths of a degree. +// drawingML rotation is clockwise and is in 60000ths of a degree. +inline sal_Int32 ExportRotateClockwisify(Degree100 input) +{ + return ((21600000 - input.get() * 600) % 21600000); +} + +/// Interface to be implemented by the parent exporter that knows how to handle shape text. +class OOX_DLLPUBLIC DMLTextExport +{ +public: + virtual void WriteOutliner(const OutlinerParaObject& rParaObj) = 0; + /// Write the contents of the textbox that is associated to this shape. + virtual void WriteTextBox(css::uno::Reference<css::drawing::XShape> xShape) = 0; + /// Get textbox which belongs to the shape. + virtual css::uno::Reference<css::text::XTextFrame> GetUnoTextFrame( + css::uno::Reference<css::drawing::XShape> xShape) = 0; +protected: + DMLTextExport() {} + virtual ~DMLTextExport() {} +}; + +class OOX_DLLPUBLIC DrawingML +{ + +private: + static std::stack<sal_Int32> mnImageCounter; + static std::stack<sal_Int32> mnWdpImageCounter; + static std::stack<std::map<OUString, OUString>> maWdpCache; + static sal_Int32 mnDrawingMLCount; + static sal_Int32 mnVmlCount; + static std::stack<std::unordered_map<BitmapChecksum, OUString>> maExportGraphics; + + /// To specify where write eg. the images to (like 'ppt', or 'word' - according to the OPC). + DocumentType meDocumentType; + /// Parent exporter, used for text callback. + DMLTextExport* mpTextExport; + + +protected: + css::uno::Any mAny; + ::sax_fastparser::FSHelperPtr mpFS; + ::oox::core::XmlFilterBase* mpFB; + /// If set, this is the parent of the currently handled shape. + css::uno::Reference<css::drawing::XShape> m_xParent; + bool mbIsBackgroundDark; + + /// True when exporting presentation placeholder shape. + bool mbPlaceholder; + + bool GetProperty( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, const OUString& aName ); + bool GetPropertyAndState( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, + const css::uno::Reference< css::beans::XPropertyState >& rXPropState, + const OUString& aName, css::beans::PropertyState& eState ); + OUString GetFieldValue( const css::uno::Reference< css::text::XTextRange >& rRun, bool& bIsURLField ); + /** Gets OOXML datetime field type from LO Date format + + @param eDate LO Date format + */ + static OUString GetDatetimeTypeFromDate(SvxDateFormat eDate); + /** Gets OOXML datetime field type from LO Time format + + @param eTime LO Time format + */ + static OUString GetDatetimeTypeFromTime(SvxTimeFormat eTime); + /** Gets OOXML datetime field type from combination of LO Time and Date formats + + @param eDate LO Date format + @param eTime LO Time format + */ + static OUString GetDatetimeTypeFromDateTime(SvxDateFormat eDate, SvxTimeFormat eTime); + + /// Output the media (including copying a video from vnd.sun.star.Package: to the output if necessary). + void WriteMediaNonVisualProperties(const css::uno::Reference<css::drawing::XShape>& xShape); + + void WriteStyleProperties( sal_Int32 nTokenId, const css::uno::Sequence< css::beans::PropertyValue >& aProperties ); + + const char* GetComponentDir() const; + const char* GetRelationCompPrefix() const; + + static bool EqualGradients( css::awt::Gradient aGradient1, css::awt::Gradient aGradient2 ); + bool IsFontworkShape(const css::uno::Reference< css::beans::XPropertySet >& rXShapePropSet); + + void WriteGlowEffect(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet); + void WriteSoftEdgeEffect(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet); + void WriteCustomGeometryPoint(const css::drawing::EnhancedCustomShapeParameterPair& rParamPair, + const EnhancedCustomShape2d& rCustomShape2d, + const bool bReplaceGeoWidth, const bool bReplaceGeoHeight); + bool WriteCustomGeometrySegment( + const sal_Int16 eCommand, const sal_Int32 nCount, + const css::uno::Sequence<css::drawing::EnhancedCustomShapeParameterPair>& rPairs, + sal_Int32& rnPairIndex, double& rfCurrentX, double& rfCurrentY, bool& rbCurrentValid, + const EnhancedCustomShape2d& rCustomShape2d, + const bool bReplaceGeoWidth, const bool bReplaceGeoHeight); + +public: + DrawingML( ::sax_fastparser::FSHelperPtr pFS, ::oox::core::XmlFilterBase* pFB, DocumentType eDocumentType = DOCUMENT_PPTX, DMLTextExport* pTextExport = nullptr ) + : meDocumentType( eDocumentType ), mpTextExport(pTextExport), mpFS( pFS ), mpFB( pFB ), mbIsBackgroundDark( false ), mbPlaceholder(false) {} + void SetFS( ::sax_fastparser::FSHelperPtr pFS ) { mpFS = pFS; } + const ::sax_fastparser::FSHelperPtr& GetFS() const { return mpFS; } + ::oox::core::XmlFilterBase* GetFB() { return mpFB; } + DocumentType GetDocumentType() const { return meDocumentType; } + /// The application-specific text exporter callback, if there is one. + DMLTextExport* GetTextExport() { return mpTextExport; } + + void SetBackgroundDark(bool bIsDark) { mbIsBackgroundDark = bIsDark; } + /// If bRelPathToMedia is true add "../" to image folder path while adding the image relationship + OUString WriteImage( const Graphic &rGraphic , bool bRelPathToMedia = false ); + + void WriteColor( ::Color nColor, sal_Int32 nAlpha = MAX_PERCENT ); + void WriteColor( const OUString& sColorSchemeName, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT ); + void WriteColor( const ::Color nColor, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT ); + void WriteColorTransformations( const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT ); + void WriteGradientStop(sal_uInt16 nStop, ::Color nColor, sal_Int32 nAlpha = MAX_PERCENT); + void WriteLineArrow( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, bool bLineStart ); + void WriteConnectorConnections( sal_uInt32 nStartGlueId, sal_Int32 nEndGlueId, sal_Int32 nStartID, sal_Int32 nEndID ); + + bool WriteCharColor(const css::uno::Reference<css::beans::XPropertySet>& xPropertySet); + bool WriteFillColor(const css::uno::Reference<css::beans::XPropertySet>& xPropertySet); + + void WriteSolidFill( ::Color nColor, sal_Int32 nAlpha = MAX_PERCENT ); + void WriteSolidFill( const OUString& sSchemeName, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT ); + void WriteSolidFill( const ::Color nColor, const css::uno::Sequence< css::beans::PropertyValue >& aTransformations, sal_Int32 nAlpha = MAX_PERCENT ); + void WriteSolidFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet ); + void WriteGradientFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet ); + + void WriteGradientFill( css::awt::Gradient rGradient, css::awt::Gradient rTransparenceGradient, + const css::uno::Reference<css::beans::XPropertySet>& rXPropSet = css::uno::Reference<css::beans::XPropertySet>()); + + void WriteGrabBagGradientFill( const css::uno::Sequence< css::beans::PropertyValue >& aGradientStops, css::awt::Gradient rGradient); + + void WriteBlipOrNormalFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, + const OUString& rURLPropName ); + void WriteBlipFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, + const OUString& sURLPropName ); + void WriteBlipFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, + const OUString& sURLPropName, sal_Int32 nXmlNamespace ); + + void WriteXGraphicBlipFill(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet, + css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, + sal_Int32 nXmlNamespace, bool bWriteMode, bool bRelPathToMedia = false); + + void WritePattFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet ); + void WritePattFill(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet, + const css::drawing::Hatch& rHatch); + + void WriteGraphicCropProperties(css::uno::Reference<css::beans::XPropertySet> const & rxPropertySet, + Size const & rOriginalSize, MapMode const & rMapMode); + + void WriteSrcRectXGraphic(css::uno::Reference<css::beans::XPropertySet> const & rxPropertySet, + css::uno::Reference<css::graphic::XGraphic> const & rxGraphic); + + void WriteOutline( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, + css::uno::Reference< css::frame::XModel> const & xModel = nullptr ); + + void WriteXGraphicStretch(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet, + css::uno::Reference<css::graphic::XGraphic> const & rxGraphic); + + void WriteXGraphicTile(css::uno::Reference<css::beans::XPropertySet> const& rXPropSet, + css::uno::Reference<css::graphic::XGraphic> const& rxGraphic); + + void WriteLinespacing(const css::style::LineSpacing& rLineSpacing, float fFirstCharHeight); + + OUString WriteXGraphicBlip(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet, + css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, + bool bRelPathToMedia); + + void WriteImageBrightnessContrastTransparence(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet); + + void WriteXGraphicBlipMode(css::uno::Reference<css::beans::XPropertySet> const & rXPropSet, + css::uno::Reference<css::graphic::XGraphic> const & rxGraphic); + + void WriteShapeTransformation(const css::uno::Reference< css::drawing::XShape >& rXShape, + sal_Int32 nXmlNamespace, bool bFlipH = false, bool bFlipV = false, bool bSuppressRotation = false, bool bSuppressFlipping = false, bool bFlippedBeforeRotation = false); + void WriteTransformation(const css::uno::Reference< css::drawing::XShape >& xShape, const tools::Rectangle& rRectangle, + sal_Int32 nXmlNamespace, bool bFlipH = false, bool bFlipV = false, sal_Int32 nRotation = 0, bool bIsGroupShape = false); + + void WriteText( const css::uno::Reference< css::uno::XInterface >& rXIface, bool bBodyPr, bool bText = true, sal_Int32 nXmlNamespace = 0, bool bWritePropertiesAsLstStyles = false); + + /** Populates the lstStyle with the shape's text run and paragraph properties */ + void WriteLstStyles(const css::uno::Reference<css::text::XTextContent>& rParagraph, + bool& rbOverridingCharHeight, sal_Int32& rnCharHeight, + const css::uno::Reference<css::beans::XPropertySet>& rXShapePropSet); + void WriteParagraph( const css::uno::Reference< css::text::XTextContent >& rParagraph, + bool& rbOverridingCharHeight, sal_Int32& rnCharHeight, const css::uno::Reference< css::beans::XPropertySet >& rXShapePropSet); + /** Writes paragraph properties + + @returns true if any paragraph properties were written + */ + bool WriteParagraphProperties(const css::uno::Reference< css::text::XTextContent >& rParagraph, const css::uno::Reference<css::beans::XPropertySet>& rXShapePropSet, float fFirstCharHeight, sal_Int32 nElement); + void WriteParagraphNumbering(const css::uno::Reference< css::beans::XPropertySet >& rXPropSet, float fFirstCharHeight, + sal_Int16 nLevel ); + void WriteParagraphTabStops(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet); + void WriteRun( const css::uno::Reference< css::text::XTextRange >& rRun, + bool& rbOverridingCharHeight, sal_Int32& rnCharHeight, + const css::uno::Reference< css::beans::XPropertySet >& rXShapePropSet); + void WriteRunProperties( const css::uno::Reference< css::beans::XPropertySet >& rRun, bool bIsField, sal_Int32 nElement, bool bCheckDirect, + bool& rbOverridingCharHeight, sal_Int32& rnCharHeight, + sal_Int16 nScriptType = css::i18n::ScriptType::LATIN, + const css::uno::Reference< css::beans::XPropertySet >& rXShapePropSet = {}); + + void WritePresetShape( const OString& pShape , std::vector< std::pair<sal_Int32,sal_Int32>> & rAvList ); + void WritePresetShape( const OString& pShape ); + void WritePresetShape( const OString& pShape, MSO_SPT eShapeType, bool bPredefinedHandlesUsed, const css::beans::PropertyValue& rProp ); + bool WriteCustomGeometry( + const css::uno::Reference<css::drawing::XShape>& rXShape, + const SdrObjCustomShape& rSdrObjCustomShape); + void WriteEmptyCustomGeometry(); + void WritePolyPolygon(const css::uno::Reference<css::drawing::XShape>& rXShape, + const bool bClosed); + void WriteFill( const css::uno::Reference< css::beans::XPropertySet >& xPropSet ); + void WriteShapeStyle( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet ); + void WriteShapeEffects( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet ); + void WriteShapeEffect( std::u16string_view sName, const css::uno::Sequence< css::beans::PropertyValue >& aEffectProps ); + /** Populates scene3d tag + @param rXPropSet Prop set + @param bIsText True if the 3D effects are for a text body, false if it is for a shape + */ + void Write3DEffects(const css::uno::Reference<css::beans::XPropertySet>& rXPropSet, bool bIsText); + void WriteArtisticEffect( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet ); + OString WriteWdpPicture( const OUString& rFileId, const css::uno::Sequence< sal_Int8 >& rPictureData ); + void WriteDiagram(const css::uno::Reference<css::drawing::XShape>& rXShape, int nDiagramId); + void writeDiagramRels(const css::uno::Sequence<css::uno::Sequence<css::uno::Any>>& xRelSeq, + const css::uno::Reference<css::io::XOutputStream>& xOutStream, + std::u16string_view sGrabBagProperyName, int nDiagramId); + static void WriteFromTo(const css::uno::Reference<css::drawing::XShape>& rXShape, const css::awt::Size& aPageSize, + const sax_fastparser::FSHelperPtr& pDrawing); + + static bool IsGroupShape( const css::uno::Reference< css::drawing::XShape >& rXShape ); + sal_Int32 getBulletMarginIndentation (const css::uno::Reference< css::beans::XPropertySet >& rXPropSet,sal_Int16 nLevel, std::u16string_view propName); + + static void ResetMlCounters(); + + static void PushExportGraphics(); + static void PopExportGraphics(); + + static sal_Int32 getNewDrawingUniqueId() { return ++mnDrawingMLCount; } + static sal_Int32 getNewVMLUniqueId() { return ++mnVmlCount; } + + // A Helper to decide the script type for given text in order to call WriteRunProperties. + static sal_Int16 GetScriptType(const OUString& rStr); + + static sal_Unicode SubstituteBullet( sal_Unicode cBulletId, css::awt::FontDescriptor& rFontDesc ); + + static ::Color ColorWithIntensity( sal_uInt32 nColor, sal_uInt32 nIntensity ); + + static const char* GetAlignment( css::style::ParagraphAdjust nAlignment ); + + sax_fastparser::FSHelperPtr CreateOutputStream ( + const OUString& sFullStream, + std::u16string_view sRelativeStream, + const css::uno::Reference< css::io::XOutputStream >& xParentRelation, + const char* sContentType, + const char* sRelationshipType, + OUString* pRelationshipId ); + +}; + +} +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/export/shapes.hxx b/include/oox/export/shapes.hxx new file mode 100644 index 000000000..646d462e8 --- /dev/null +++ b/include/oox/export/shapes.hxx @@ -0,0 +1,213 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_OOX_EXPORT_SHAPES_HXX +#define INCLUDED_OOX_EXPORT_SHAPES_HXX + +#include <cstddef> +#include <memory> +#include <string_view> +#include <unordered_map> + +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/table/BorderLine2.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <oox/dllapi.h> +#include <oox/export/drawingml.hxx> +#include <oox/export/utils.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <sax/fshelper.hxx> +#include <tools/fract.hxx> +#include <vcl/mapmod.hxx> + +namespace com::sun::star { +namespace beans { + class XPropertySet; +} +namespace drawing { + class XShape; +} + +namespace embed { + class XEmbeddedObject; +} +namespace io { + class XInputStream; +} +namespace uno { + class XComponentContext; + class XInterface; +} +} + +namespace oox::core { + class XmlFilterBase; +} + +class Graphic; + +namespace oox { + +OOX_DLLPUBLIC css::uno::Reference<css::io::XInputStream> GetOLEObjectStream( + css::uno::Reference<css::uno::XComponentContext> const& xContext, + css::uno::Reference<css::embed::XEmbeddedObject> const& xObj, + std::u16string_view i_rProgID, + OUString & o_rMediaType, + OUString & o_rRelationType, + OUString & o_rSuffix, + const char *& o_rpProgID); + +} + +namespace oox::drawingml { + +class OOX_DLLPUBLIC ShapeExport : public DrawingML { + +private: + int m_nEmbeddedObjects; + +public: + typedef std::unordered_map< css::uno::Reference< css::drawing::XShape>, sal_Int32> ShapeHashMap; + +protected: + sal_Int32 mnShapeIdMax; + bool mbUserShapes; // for chart's embedded usershapes + + void WriteGraphicObjectShapePart( const css::uno::Reference< css::drawing::XShape >& xShape, const Graphic *pGraphic=nullptr ); + + OUString GetShapeName(const css::uno::Reference< css::drawing::XShape >& xShape); + +private: + sal_Int32 mnXmlNamespace; + MapMode maMapModeSrc, maMapModeDest; + std::shared_ptr<URLTransformer> mpURLTransformer; + + css::awt::Size MapSize( const css::awt::Size& ) const; + + ShapeHashMap maShapeMap; + ShapeHashMap* mpShapeMap; + +public: + + ShapeExport( sal_Int32 nXmlNamespace, ::sax_fastparser::FSHelperPtr pFS, + ShapeHashMap* pShapeMap, ::oox::core::XmlFilterBase* pFB, + DocumentType eDocumentType = DOCUMENT_PPTX, + DMLTextExport* pTextExport = nullptr, + bool bUserShapes = false ); + virtual ~ShapeExport() {} + + void SetURLTranslator(const std::shared_ptr<URLTransformer>& pTransformer); + + static bool NonEmptyText( const css::uno::Reference< css::uno::XInterface >& xIface ); + + ShapeExport& + WritePolyPolygonShape( const css::uno::Reference< css::drawing::XShape >& xShape, bool bClosed ); + ShapeExport& + WriteClosedPolyPolygonShape( const css::uno::Reference< css::drawing::XShape >& xShape ); + ShapeExport& + WriteConnectorShape( const css::uno::Reference< css::drawing::XShape >& xShape ); + ShapeExport& + WriteCustomShape( const css::uno::Reference< css::drawing::XShape >& xShape ); + ShapeExport& + WriteEllipseShape( const css::uno::Reference< css::drawing::XShape >& xShape ); + ShapeExport& + WriteGraphicObjectShape( const css::uno::Reference< css::drawing::XShape >& xShape ); + ShapeExport& + WriteGroupShape( const css::uno::Reference< css::drawing::XShape >& xShape ); + ShapeExport& + WriteLineShape( const css::uno::Reference< css::drawing::XShape >& xShape ); + ShapeExport& + WriteNonVisualDrawingProperties( const css::uno::Reference< css::drawing::XShape >& xShape, const char* sName ); + virtual ShapeExport& + WriteNonVisualProperties( const css::uno::Reference< css::drawing::XShape >& xShape ); + ShapeExport& + WriteOpenPolyPolygonShape( const css::uno::Reference< css::drawing::XShape >& xShape ); + ShapeExport& + WriteRectangleShape( const css::uno::Reference< css::drawing::XShape >& xShape ); + + /** + * Write the DrawingML for a particular shape. + * + * <p>This is the member function you want. It performs the type lookup and + * invokes the appropriate corresponding Write*() method for the specific + * type.</p> + * + * <p>To write an XShape, XShape::getShapeType() is called to determine + * the shape type, and the corresponding method in this table is + * invoked:</p> + * + * <table> + * <tr><th>Shape Type</th><th>Method</th></tr> + * <tr><td><tt>com.sun.star.drawing.ClosedBezierShape</tt></td> <td>ShapeExport::WriteClosedPolyPolygonShape</td></tr> + * <tr><td><tt>com.sun.star.drawing.CustomShape</tt></td> <td>ShapeExport::WriteCustomShape</td></tr> + * <tr><td><tt>com.sun.star.drawing.EllipseShape</tt></td> <td>ShapeExport::WriteEllipseShape</td></tr> + * <tr><td><tt>com.sun.star.drawing.GraphicObjectShape</tt></td> <td>ShapeExport::WriteGraphicObjectShape</td></tr> + * <tr><td><tt>com.sun.star.drawing.LineShape</tt></td> <td>ShapeExport::WriteLineShape</td></tr> + * <tr><td><tt>com.sun.star.drawing.OpenBezierShape</tt></td> <td>ShapeExport::WriteOpenPolyPolygonShape</td></tr> + * <tr><td><tt>com.sun.star.drawing.PolyPolygonShape</tt></td> <td>ShapeExport::WriteClosedPolyPolygonShape</td></tr> + * <tr><td><tt>com.sun.star.drawing.PolyLineShape</tt></td> <td>ShapeExport::WriteOpenPolyPolygonShape</td></tr> + * <tr><td><tt>com.sun.star.drawing.RectangleShape</tt></td> <td>ShapeExport::WriteRectangleShape</td></tr> + * <tr><td><tt>com.sun.star.drawing.TableShape</tt></td> <td>ShapeExport::WriteTableShape</td></tr> + * <tr><td><tt>com.sun.star.drawing.TextShape</tt></td> <td>ShapeExport::WriteTextShape</td></tr> + * <tr><td><tt>com.sun.star.presentation.DateTimeShape</tt></td> <td>ShapeExport::WriteTextShape</td></tr> + * <tr><td><tt>com.sun.star.presentation.FooterShape</tt></td> <td>ShapeExport::WriteTextShape</td></tr> + * <tr><td><tt>com.sun.star.presentation.HeaderShape</tt></td> <td>ShapeExport::WriteTextShape</td></tr> + * <tr><td><tt>com.sun.star.presentation.NotesShape</tt></td> <td>ShapeExport::WriteTextShape</td></tr> + * <tr><td><tt>com.sun.star.presentation.OutlinerShape</tt></td> <td>ShapeExport::WriteTextShape</td></tr> + * <tr><td><tt>com.sun.star.presentation.SlideNumberShape</tt></td><td>ShapeExport::WriteTextShape</td></tr> + * <tr><td><tt>com.sun.star.presentation.TitleTextShape</tt></td> <td>ShapeExport::WriteTextShape</td></tr> + * </table> + * + * <p>If the shape type is not recognized, then + * <tt>ShapeExport::WriteUnknownShape</tt> is called.</p> + * + * @param xShape The shape to export as DrawingML. + * @return <tt>*this</tt> + */ + ShapeExport& WriteShape( const css::uno::Reference< css::drawing::XShape >& xShape ); + ShapeExport& WriteTextBox( const css::uno::Reference< css::uno::XInterface >& xIface, sal_Int32 nXmlNamespace, bool bWritePropertiesAsLstStyles = false ); + virtual ShapeExport& + WriteTextShape( const css::uno::Reference< css::drawing::XShape >& xShape ); + ShapeExport& + WriteTableShape( const css::uno::Reference< css::drawing::XShape >& xShape ); + void WriteMathShape(css::uno::Reference<css::drawing::XShape> const& xShape); + ShapeExport& + WriteOLE2Shape( const css::uno::Reference< css::drawing::XShape >& xShape ); + virtual ShapeExport& + WriteUnknownShape( const css::uno::Reference< css::drawing::XShape >& xShape ); + + void WriteTable( const css::uno::Reference< css::drawing::XShape >& rXShape ); + + void WriteTableCellProperties(const css::uno::Reference< css::beans::XPropertySet >& rXPropSet); + + void WriteBorderLine(const sal_Int32 XML_line, const css::table::BorderLine2& rBorderLine); + void WriteTableCellBorders(const css::uno::Reference< css::beans::XPropertySet >& rXPropSet); + + sal_Int32 GetNewShapeID( const css::uno::Reference< css::drawing::XShape >& rShape ); + sal_Int32 GetNewShapeID( const css::uno::Reference< css::drawing::XShape >& rShape, ::oox::core::XmlFilterBase* pFB ); + sal_Int32 GetShapeID( const css::uno::Reference< css::drawing::XShape >& rShape ); + static sal_Int32 GetShapeID( const css::uno::Reference< css::drawing::XShape >& rShape, ShapeHashMap* pShapeMap ); +}; + +} + +#endif // INCLUDED_OOX_EXPORT_SHAPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/export/utils.hxx b/include/oox/export/utils.hxx new file mode 100644 index 000000000..00fd953a0 --- /dev/null +++ b/include/oox/export/utils.hxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_OOX_EXPORT_UTILS_HXX +#define INCLUDED_OOX_EXPORT_UTILS_HXX + +#include <sal/config.h> + +#include <o3tl/unit_conversion.hxx> +#include <rtl/string.hxx> +#include <sal/types.h> + +#include <cmath> + +inline OString I32SHEX(sal_Int32 x) +{ + OString aStr = OString::number(x, 16); + while (aStr.getLength() < 6) + aStr = "0" + aStr; + return aStr; +} + +/** + * @return const char* literal "true" for true value, or literal "false" + * for false value. + */ +static constexpr const char* ToPsz(bool b) +{ + return b ? "true" : "false"; +} + +/** + * @return literal "1" for true value, or literal "0" for false value. + */ +static constexpr const char* ToPsz10(bool b) +{ + // xlsx seems to use "1" or "0" for boolean values. I wonder it ever uses + // the "true" "false" variant. + return b ? "1" : "0"; +} + +static constexpr sal_Int64 PPTtoEMU( sal_Int32 nPPT ) +{ + return o3tl::convert(nPPT, o3tl::Length::master, o3tl::Length::emu); +} + +static constexpr sal_Int64 TwipsToEMU( sal_Int32 nTwips ) +{ + return o3tl::convert(nTwips, o3tl::Length::twip, o3tl::Length::emu); +} + +template <typename T> +OString write1000thOfAPercent(T number) +{ + return OString::number( lround(number * 1000.0) ); +} + +namespace oox::drawingml { + enum DocumentType { DOCUMENT_DOCX, DOCUMENT_PPTX, DOCUMENT_XLSX }; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/export/vmlexport.hxx b/include/oox/export/vmlexport.hxx new file mode 100644 index 000000000..fa54f27aa --- /dev/null +++ b/include/oox/export/vmlexport.hxx @@ -0,0 +1,209 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_OOX_EXPORT_VMLEXPORT_HXX +#define INCLUDED_OOX_EXPORT_VMLEXPORT_HXX + +#include <sal/config.h> + +#include <string_view> + +#include <com/sun/star/uno/Reference.hxx> +#include <editeng/outlobj.hxx> +#include <filter/msfilter/escherex.hxx> +#include <oox/dllapi.h> +#include <rtl/strbuf.hxx> +#include <rtl/string.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <sax/fshelper.hxx> +#include <vcl/checksum.hxx> +#include <rtl/ref.hxx> + +namespace com::sun::star { + namespace drawing { + class XShape; + } +} + +namespace oox::drawingml { + class DrawingML; +} + + +namespace sax_fastparser { + class FastAttributeList; +} + +class Point; +namespace tools { class Rectangle; } +class SdrObject; + +namespace oox::vml { + +/// Interface to be implemented by the parent exporter that knows how to handle shape text. +class OOX_DLLPUBLIC VMLTextExport +{ +public: + virtual void WriteOutliner(const OutlinerParaObject& rParaObj) = 0; + virtual oox::drawingml::DrawingML& GetDrawingML() = 0; + /// Write the contents of the textbox that is associated to this shape in VML format. + virtual void WriteVMLTextBox(css::uno::Reference<css::drawing::XShape> xShape) = 0; +protected: + VMLTextExport() {} + virtual ~VMLTextExport() {} +}; + +class OOX_DLLPUBLIC VMLExport : public EscherEx +{ + /// Fast serializer to output the data + ::sax_fastparser::FSHelperPtr m_pSerializer; + + /// Parent exporter, used for text callback. + VMLTextExport* m_pTextExport; + + /// Anchoring - Writer specific properties + sal_Int16 m_eHOri, m_eVOri, m_eHRel, m_eVRel; + rtl::Reference<sax_fastparser::FastAttributeList> m_pWrapAttrList; + bool m_bInline; // css::text::TextContentAnchorType_AS_CHARACTER + bool m_IsFollowingTextFlow = false; + + /// The object we're exporting. + const SdrObject* m_pSdrObject; + + /// Fill the shape attributes as they come. + rtl::Reference<::sax_fastparser::FastAttributeList> m_pShapeAttrList; + + /// Remember the shape type. + sal_uInt32 m_nShapeType; + + /// Remember the shape flags. + ShapeFlag m_nShapeFlags; + + /// Remember style, the most important shape attribute ;-) + OStringBuffer m_ShapeStyle; + + /// style for textbox + OStringBuffer m_TextboxStyle; + + /// Remember the generated shape id. + OString m_sShapeId; + + /// Remember which shape types we had already written. + std::vector<bool> m_aShapeTypeWritten; + + /// It seems useless to write out an XML_ID attribute next to XML_id which defines the actual shape id + bool m_bSkipwzName; + + /// Use '#' mark for type attribute (check Type Attribute of VML shape in OOXML documentation) + bool m_bUseHashMarkForType; + + /** There is a shapeid generation mechanism in EscherEx, but it does not seem to work + * so override the existing behavior to get actually unique ids. + */ + bool m_bOverrideShapeIdGeneration; + + /// Prefix for overridden shape id generation (used if m_bOverrideShapeIdGeneration is true) + OString m_sShapeIDPrefix; + + /// Counter for generating shape ids (used if m_bOverrideShapeIdGeneration is true) + sal_uInt64 m_nShapeIDCounter; + +public: + VMLExport( ::sax_fastparser::FSHelperPtr const & pSerializer, VMLTextExport* pTextExport = nullptr); + virtual ~VMLExport() override; + + const ::sax_fastparser::FSHelperPtr& + GetFS() const { return m_pSerializer; } + + void SetFS(const ::sax_fastparser::FSHelperPtr& pSerializer); + + /// Export the sdr object as VML. + /// + /// Call this when you need to export the object as VML. + OString const & AddSdrObject( const SdrObject& rObj, + bool const bIsFollowingTextFlow = false, + sal_Int16 eHOri = -1, sal_Int16 eVOri = -1, sal_Int16 eHRel = -1, + sal_Int16 eVRel = -1, + sax_fastparser::FastAttributeList* pWrapAttrList = nullptr, + const bool bOOxmlExport = false ); + OString const & AddInlineSdrObject( const SdrObject& rObj, const bool bOOxmlExport ); + virtual void AddSdrObjectVMLObject( const SdrObject& rObj) override; + static bool IsWaterMarkShape(std::u16string_view rStr); + + void SetSkipwzName(bool bSkipwzName) { m_bSkipwzName = bSkipwzName; } + void SetHashMarkForType(bool bUseHashMarkForType) { m_bUseHashMarkForType = bUseHashMarkForType; } + void OverrideShapeIDGen(bool bOverrideShapeIdGeneration, + const OString& sShapeIDPrefix = OString()); + static OString GetVMLShapeTypeDefinition(std::string_view sShapeID, const bool bIsPictureFrame); + +protected: + /// Add an attribute to the generated <v:shape/> element. + /// + /// This should be called from within StartShape() to ensure that the + /// added attribute is preserved. + void AddShapeAttribute( sal_Int32 nAttribute, const OString& sValue ); + + using EscherEx::StartShape; + using EscherEx::EndShape; + + /// Override shape ID generation when m_bOverrideShapeIdGeneration is set to true + virtual sal_uInt32 GenerateShapeId() override; + + /// Start the shape for which we just collected the information. + /// + /// Returns the element's tag number, -1 means we wrote nothing. + virtual sal_Int32 StartShape(); + + /// End the shape. + /// + /// The parameter is just what we got from StartShape(). + virtual void EndShape( sal_Int32 nShapeElement ); + virtual void Commit( EscherPropertyContainer& rProps, const tools::Rectangle& rRect ) override; + +private: + + virtual void OpenContainer( sal_uInt16 nEscherContainer, int nRecInstance = 0 ) override; + virtual void CloseContainer() override; + + virtual sal_uInt32 EnterGroup( const OUString& rShapeName, const tools::Rectangle* pBoundRect ) override; + virtual void LeaveGroup() override; + + virtual void AddShape( sal_uInt32 nShapeType, ShapeFlag nShapeFlags, sal_uInt32 nShapeId = 0 ) override; + +private: + /// Create an OString representing the id from a numerical id. + OString ShapeIdString( sal_uInt32 nId ); + + /// Add flip X and\or flip Y + void AddFlipXY( ); + + /// Add starting and ending point of a line to the m_pShapeAttrList. + void AddLineDimensions( const tools::Rectangle& rRectangle ); + + /// Add position and size to the OStringBuffer. + void AddRectangleDimensions( OStringBuffer& rBuffer, const tools::Rectangle& rRectangle, bool rbAbsolutePos = true ); +}; + + +} // namespace oox::vml + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |