diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /include/oox/vml | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/oox/vml')
-rw-r--r-- | include/oox/vml/vmldrawing.hxx | 208 | ||||
-rw-r--r-- | include/oox/vml/vmldrawingfragment.hxx | 69 | ||||
-rw-r--r-- | include/oox/vml/vmlformatting.hxx | 271 | ||||
-rw-r--r-- | include/oox/vml/vmlinputstream.hxx | 97 | ||||
-rw-r--r-- | include/oox/vml/vmlshape.hxx | 456 | ||||
-rw-r--r-- | include/oox/vml/vmlshapecontainer.hxx | 146 | ||||
-rw-r--r-- | include/oox/vml/vmlshapecontext.hxx | 191 | ||||
-rw-r--r-- | include/oox/vml/vmltextbox.hxx | 115 | ||||
-rw-r--r-- | include/oox/vml/vmltextboxcontext.hxx | 88 |
9 files changed, 1641 insertions, 0 deletions
diff --git a/include/oox/vml/vmldrawing.hxx b/include/oox/vml/vmldrawing.hxx new file mode 100644 index 000000000..9181b7356 --- /dev/null +++ b/include/oox/vml/vmldrawing.hxx @@ -0,0 +1,208 @@ +/* -*- 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_VML_VMLDRAWING_HXX +#define INCLUDED_OOX_VML_VMLDRAWING_HXX + +#include <map> +#include <memory> +#include <vector> + +#include <com/sun/star/uno/Reference.hxx> +#include <oox/dllapi.h> +#include <oox/ole/oleobjecthelper.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +namespace com::sun::star { + namespace awt { struct Rectangle; } + namespace drawing { class XDrawPage; } + namespace drawing { class XShape; } + namespace drawing { class XShapes; } +} + +namespace oox { + namespace core { class XmlFilterBase; } + namespace ole { class EmbeddedControl; } + namespace ole { class EmbeddedForm; } + namespace vml { class ShapeContainer; } +} + +namespace oox { +namespace vml { + +class ShapeBase; + + +/** Enumerates different types of VML drawings. */ +enum DrawingType +{ + VMLDRAWING_WORD, ///< Word: One shape per drawing. + VMLDRAWING_EXCEL, ///< Excel: OLE objects are part of VML. + VMLDRAWING_POWERPOINT ///< PowerPoint: OLE objects are part of DrawingML. +}; + + +/** Contains information about an OLE object embedded in a draw page. */ +struct OOX_DLLPUBLIC OleObjectInfo : public ::oox::ole::OleObjectInfo +{ + OUString maShapeId; ///< Shape identifier for shape lookup. + OUString maName; ///< Programmatical name of the OLE object. + bool mbAutoLoad; + const bool mbDmlShape; ///< True = DrawingML shape (PowerPoint), false = VML shape (Excel/Word). + + explicit OleObjectInfo( bool bDmlShape = false ); + + /** Sets the string representation of the passed numeric shape identifier. */ + void setShapeId( sal_Int32 nShapeId ); +}; + +// =========================================/=================================== + +/** Contains information about a form control embedded in a draw page. */ +struct OOX_DLLPUBLIC ControlInfo +{ + OUString maShapeId; ///< Shape identifier for shape lookup. + OUString maFragmentPath; ///< Path to the fragment describing the form control properties. + OUString maName; ///< Programmatical name of the form control. + bool mbTextContentShape; ///< Whether this control shape will be imported to Writer or not (has AnchorType property or not). + + explicit ControlInfo(); + + /** Sets the string representation of the passed numeric shape identifier. */ + void setShapeId( sal_Int32 nShapeId ); +}; + + +/** Represents the collection of VML shapes for a complete draw page. */ +class OOX_DLLPUBLIC Drawing +{ +public: + explicit Drawing( + ::oox::core::XmlFilterBase& rFilter, + const css::uno::Reference< css::drawing::XDrawPage >& rxDrawPage, + DrawingType eType ); + + virtual ~Drawing(); + + /** Returns the filter object that imports/exports this VML drawing. */ + ::oox::core::XmlFilterBase& getFilter() const { return mrFilter; } + /** Returns the application type containing the drawing. */ + DrawingType getType() const { return meType; } + /** Returns read/write access to the container of shapes and templates. */ + ShapeContainer& getShapes() { return *mxShapes; } + /** Returns read access to the container of shapes and templates. */ + const ShapeContainer& getShapes() const { return *mxShapes; } + /** Returns the form object used to process ActiveX form controls. */ + ::oox::ole::EmbeddedForm& getControlForm() const; + + /** Registers a block of shape identifiers reserved by this drawing. Block + size is 1024, shape identifiers are one-based (block 1 => 1025-2048). */ + void registerBlockId( sal_Int32 nBlockId ); + /** Registers the passed embedded OLE object. The related shape will then + load the OLE object data from the specified fragment. */ + void registerOleObject( const OleObjectInfo& rOleObject ); + /** Registers the passed embedded form control. The related shape will then + load the control properties from the specified fragment. */ + void registerControl( const ControlInfo& rControl ); + + /** Final processing after import of the fragment. */ + void finalizeFragmentImport(); + + /** Creates and inserts all UNO shapes into the draw page. The virtual + function notifyXShapeInserted() will be called for each new shape. */ + void convertAndInsert() const; + + /** Returns the local shape index from the passed global shape identifier. */ + sal_Int32 getLocalShapeIndex( const OUString& rShapeId ) const; + /** Returns the registered info structure for an OLE object, if extant. */ + const OleObjectInfo* getOleObjectInfo( const OUString& rShapeId ) const; + /** Returns the registered info structure for a form control, if extant. */ + const ControlInfo* getControlInfo( const OUString& rShapeId ) const; + + /** Creates a new UNO shape object, inserts it into the passed UNO shape + container, and sets the shape position and size. */ + css::uno::Reference< css::drawing::XShape > + createAndInsertXShape( + const OUString& rService, + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const css::awt::Rectangle& rShapeRect ) const; + + /** Creates a new UNO shape object for a form control, inserts the control + model into the form, and the shape into the passed UNO shape container. */ + css::uno::Reference< css::drawing::XShape > + createAndInsertXControlShape( + const ::oox::ole::EmbeddedControl& rControl, + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const css::awt::Rectangle& rShapeRect, + sal_Int32& rnCtrlIndex ) const; + + /** Derived classes may disable conversion of specific shapes. */ + virtual bool isShapeSupported( const ShapeBase& rShape ) const; + + /** Derived classes may return additional base names for automatic shape + name creation. */ + virtual OUString getShapeBaseName( const ShapeBase& rShape ) const; + + /** Derived classes may calculate the shape rectangle from a non-standard + anchor information string. */ + virtual bool convertClientAnchor( + css::awt::Rectangle& orShapeRect, + const OUString& rShapeAnchor ) const; + + /** Derived classes create a UNO shape according to the passed shape model. + Called for shape models that specify being under host control. */ + virtual css::uno::Reference< css::drawing::XShape > + createAndInsertClientXShape( + const ShapeBase& rShape, + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const css::awt::Rectangle& rShapeRect ) const; + + /** Derived classes may want to know that a UNO shape has been inserted. + Will be called from the convertAndInsert() implementation. + @param bGroupChild True = inserted into a group shape, + false = inserted directly into this drawing. */ + virtual void notifyXShapeInserted( + const css::uno::Reference< css::drawing::XShape >& rxShape, + const css::awt::Rectangle& rShapeRect, + const ShapeBase& rShape, bool bGroupChild ); + +private: + typedef ::std::vector< sal_Int32 > BlockIdVector; + typedef ::std::map< OUString, OleObjectInfo > OleObjectInfoMap; + typedef ::std::map< OUString, ControlInfo > ControlInfoMap; + + ::oox::core::XmlFilterBase& mrFilter; ///< Filter object that imports/exports the VML drawing. + css::uno::Reference< css::drawing::XDrawPage > + mxDrawPage; ///< UNO draw page used to insert the shapes. + mutable std::unique_ptr<::oox::ole::EmbeddedForm> mxCtrlForm; ///< The control form used to process embedded controls. + mutable BlockIdVector maBlockIds; ///< Block identifiers used by this drawing. + std::unique_ptr<ShapeContainer> mxShapes; ///< All shapes and shape templates. + OleObjectInfoMap maOleObjects; ///< Info about all embedded OLE objects, mapped by shape id. + ControlInfoMap maControls; ///< Info about all embedded form controls, mapped by control name. + const DrawingType meType; ///< Application type containing the drawing. +}; + + +} // namespace vml +} // namespace oox + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/vml/vmldrawingfragment.hxx b/include/oox/vml/vmldrawingfragment.hxx new file mode 100644 index 000000000..be20dc2f8 --- /dev/null +++ b/include/oox/vml/vmldrawingfragment.hxx @@ -0,0 +1,69 @@ +/* -*- 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_VML_VMLDRAWINGFRAGMENT_HXX +#define INCLUDED_OOX_VML_VMLDRAWINGFRAGMENT_HXX + +#include <com/sun/star/uno/Reference.hxx> +#include <oox/core/contexthandler.hxx> +#include <oox/core/fragmenthandler2.hxx> +#include <oox/dllapi.h> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +namespace com::sun::star { + namespace io { class XInputStream; } +} + +namespace oox { class AttributeList; } +namespace oox::core { class XmlFilterBase; } + +namespace oox { +namespace vml { + +class Drawing; + + +class OOX_DLLPUBLIC DrawingFragment : public ::oox::core::FragmentHandler2 +{ +public: + explicit DrawingFragment( + ::oox::core::XmlFilterBase& rFilter, + const OUString& rFragmentPath, + Drawing& rDrawing ); + + virtual css::uno::Reference< css::io::XInputStream > + openFragmentStream() const override; + + virtual ::oox::core::ContextHandlerRef + onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; + + virtual void finalizeImport() override; + +private: + Drawing& mrDrawing; +}; + + +} // namespace vml +} // namespace oox + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/vml/vmlformatting.hxx b/include/oox/vml/vmlformatting.hxx new file mode 100644 index 000000000..f4b6d88c5 --- /dev/null +++ b/include/oox/vml/vmlformatting.hxx @@ -0,0 +1,271 @@ +/* -*- 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_VML_VMLFORMATTING_HXX +#define INCLUDED_OOX_VML_VMLFORMATTING_HXX + +#include <utility> +#include <vector> + +#include <com/sun/star/drawing/PolygonFlags.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <oox/dllapi.h> +#include <oox/helper/helper.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +namespace com::sun::star { + namespace awt { struct Point; } + namespace drawing { class XShape; } +} + +namespace oox { + class GraphicHelper; + namespace drawingml { class Color; } + namespace drawingml { class ShapePropertyMap; } +} + +namespace oox { +namespace vml { + + +typedef ::std::pair< sal_Int32, sal_Int32 > Int32Pair; +typedef ::std::pair< double, double > DoublePair; + + +namespace ConversionHelper +{ + /** Returns two values contained in rValue separated by cSep. + */ + OOX_DLLPUBLIC bool separatePair( + OUString& orValue1, OUString& orValue2, + const OUString& rValue, sal_Unicode cSep ); + + /** Returns the boolean value from the passed string of a VML attribute. + Supported values: 'f', 't', 'false', 'true'. False for anything else. + */ + OOX_DLLPUBLIC bool decodeBool( const OUString& rValue ); + + /** Converts the passed VML percentage measure string to a normalized + floating-point value. + + @param rValue The VML percentage value. This is a floating-point value + with optional following '%' or 'f' sign. If the sign is missing, the + floating point value will be returned unmodified. If the '%' sign + is present, the value will be divided by 100. If the 'f' sign is present, + the value will be divided by 65536. + */ + OOX_DLLPUBLIC double decodePercent( + const OUString& rValue, + double fDefValue ); + + /** Converts the passed VML rotation value to degrees. + See DffPropertyReader::Fix16ToAngle(): in VML, positive rotation + angles are clockwise, we have them as counter-clockwise. + Additionally, VML type is 0..360, our is 0..36000. + + @param rValue The VML rotation value. This is a floating-point value + with optional 'fd' suffix. If the suffix is missing, the floating + point value will be returned unmodified. If the 'fd' suffix is + present, the value will be divided by 65536. + */ + OOX_DLLPUBLIC sal_Int32 decodeRotation( const OUString& rValue ); + + /** Converts the passed VML measure string to EMU (English Metric Units). + + @param rGraphicHelper The graphic helper needed to perform pixel + conversion according to the current output device. + + @param rValue The VML measure value. This is a floating-point value + with optional measure string following the value. + + @param nRefValue Reference value needed for percentage measure. + + @param bPixelX Set to true if the value is oriented horizontally (e.g. + X coordinates, widths). Set to false if the value is oriented + vertically (e.g. Y coordinates, heights). This is needed because + output devices may specify different width and height for a pixel. + + @param bDefaultAsPixel Set to true if omitted measure unit means + pixel. Set to false if omitted measure unit means EMU. + */ + OOX_DLLPUBLIC sal_Int64 decodeMeasureToEmu( + const GraphicHelper& rGraphicHelper, + const OUString& rValue, + sal_Int32 nRefValue, + bool bPixelX, + bool bDefaultAsPixel ); + + /** Converts the passed VML measure string to 1/100 mm. + + @param rGraphicHelper See above. + @param rValue See above. + @param nRefValue See above. + @param bPixelX See above. + @param bDefaultAsPixel See above. + */ + OOX_DLLPUBLIC sal_Int32 decodeMeasureToHmm( + const GraphicHelper& rGraphicHelper, + const OUString& rValue, + sal_Int32 nRefValue, + bool bPixelX, + bool bDefaultAsPixel ); + + /** Converts VML color attributes to a DrawingML color. + + @param roVmlColor The VML string representation of the color. If + existing, this can be a 3-digit or 6-digit hexadecimal RGB value + with leading '#' character, a predefined color name (e.g. 'black', + 'red', etc.), the index into an application defined color palette + in brackets with leading color name (e.g. 'red [9]' or + 'windowColor [64]'), or a color modifier used in one-color + gradients (e.g. 'fill darken(128)' or 'fill lighten(0)'). + + @param roVmlOpacity The opacity of the color. If existing, this should + be a floating-point value in the range [0.0;1.0]. + + @param nDefaultRgb Default RGB color used if the parameter roVmlColor + is empty. + + @param nPrimaryRgb If set to something else than API_RGB_TRANSPARENT, + specifies the color to be used to resolve the color modifiers used + in one-color gradients. + + @return The resulting DrawingML color. + */ + OOX_DLLPUBLIC ::oox::drawingml::Color decodeColor( + const GraphicHelper& rGraphicHelper, + const OptValue< OUString >& roVmlColor, + const OptValue< double >& roVmlOpacity, + ::Color nDefaultRgb, + ::Color nPrimaryRgb = API_RGB_TRANSPARENT ); + + /** Converts VML path string into point and flag vectors. + + @param rPoints The point vector to fill with coordinates. + + @param rFlags The flag vector to fill. PolygonFlags_NORMAL indicates + a corresponding plain shape coordinate in rPoints and + PolygonFlags_CONTROL indicates a bezier curve control point. + + @param rPath The VML path string. + + @param rGraphicHelper See above. + */ + OOX_DLLPUBLIC void decodeVmlPath( + ::std::vector< ::std::vector< css::awt::Point > >& rPoints, + ::std::vector< ::std::vector< css::drawing::PolygonFlags > >& rFlags, + const OUString& rPath ); +} + + +/** The stroke arrow model structure contains all properties for a line end arrow. */ +struct StrokeArrowModel +{ + OptValue< sal_Int32 > moArrowType; + OptValue< sal_Int32 > moArrowWidth; + OptValue< sal_Int32 > moArrowLength; + + void assignUsed( const StrokeArrowModel& rSource ); +}; + + +/** The stroke model structure contains all shape border properties. */ +struct StrokeModel +{ + OptValue< bool > moStroked; ///< Shape border line on/off. + StrokeArrowModel maStartArrow; ///< Start line arrow style. + StrokeArrowModel maEndArrow; ///< End line arrow style. + OptValue< OUString > moColor; ///< Solid line color. + OptValue< double > moOpacity; ///< Solid line color opacity. + OptValue< OUString > moWeight; ///< Line width. + OptValue< OUString > moDashStyle; ///< Line dash (predefined or manually). + OptValue< sal_Int32 > moLineStyle; ///< Line style (single, double, ...). + OptValue< sal_Int32 > moEndCap; ///< Type of line end cap. + OptValue< sal_Int32 > moJoinStyle; ///< Type of line join. + + void assignUsed( const StrokeModel& rSource ); + + /** Writes the properties to the passed property map. */ + void pushToPropMap( + ::oox::drawingml::ShapePropertyMap& rPropMap, + const GraphicHelper& rGraphicHelper ) const; +}; + + +/** The fill model structure contains all shape fill properties. */ +struct OOX_DLLPUBLIC FillModel +{ + OptValue< bool > moFilled; ///< Shape fill on/off. + OptValue< OUString > moColor; ///< Solid fill color. + OptValue< double > moOpacity; ///< Solid fill color opacity. + OptValue< OUString > moColor2; ///< End color of gradient. + OptValue< double > moOpacity2; ///< End color opacity of gradient. + OptValue< sal_Int32 > moType; ///< Fill type. + OptValue< sal_Int32 > moAngle; ///< Gradient rotation angle. + OptValue< double > moFocus; ///< Linear gradient focus of second color. + OptValue< DoublePair > moFocusPos; ///< Rectangular gradient focus position of second color. + OptValue< DoublePair > moFocusSize; ///< Rectangular gradient focus size of second color. + OptValue< OUString > moBitmapPath; ///< Path to fill bitmap fragment. + OptValue< bool > moRotate; ///< True = rotate gradient/bitmap with shape. + + void assignUsed( const FillModel& rSource ); + + /** Writes the properties to the passed property map. */ + void pushToPropMap( + ::oox::drawingml::ShapePropertyMap& rPropMap, + const GraphicHelper& rGraphicHelper ) const; +}; + + +/** The shadow model structure contains all shape shadow properties. */ +struct OOX_DLLPUBLIC ShadowModel +{ + bool mbHasShadow; ///< Is a v:shadow element seen? + OptValue<bool> moShadowOn; ///< Is the element turned on? + OptValue<OUString> moColor; ///< Specifies the color of the shadow. + OptValue<OUString> moOffset; ///< Specifies the shadow's offset from the shape's location. + OptValue<double> moOpacity; ///< Specifies the opacity of the shadow. + + ShadowModel(); + + /** Writes the properties to the passed property map. */ + void pushToPropMap(oox::drawingml::ShapePropertyMap& rPropMap, const GraphicHelper& rGraphicHelper) const; +}; + +/** The shadow model structure contains all shape textpath properties. */ +struct TextpathModel +{ + OptValue<OUString> moString; ///< Specifies the string of the textpath. + OptValue<OUString> moStyle; ///< Specifies the style of the textpath. + OptValue<bool> moTrim; ///< Specifies whether extra space is removed above and below the text + + TextpathModel(); + + /** Writes the properties to the passed property map. */ + void pushToPropMap(oox::drawingml::ShapePropertyMap& rPropMap, const css::uno::Reference<css::drawing::XShape>& xShape, + const GraphicHelper& rGraphicHelper) const; +}; + +} // namespace vml +} // namespace oox + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/vml/vmlinputstream.hxx b/include/oox/vml/vmlinputstream.hxx new file mode 100644 index 000000000..ca2fb68db --- /dev/null +++ b/include/oox/vml/vmlinputstream.hxx @@ -0,0 +1,97 @@ +/* -*- 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_VML_VMLINPUTSTREAM_HXX +#define INCLUDED_OOX_VML_VMLINPUTSTREAM_HXX + +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <cppuhelper/implbase.hxx> +#include <rtl/string.hxx> +#include <sal/types.h> + +namespace com::sun::star { + namespace io { class XTextInputStream2; } + namespace uno { class XComponentContext; } +} + +namespace oox { +namespace vml { + + +/** An input stream class for VML streams, implementing the UNO interface + com.sun.star.io.XInputStream needed by the Expat XML parsers. + + This stream reads the data from the input stream passed to the constructor, + and parses all XML elements for features unsupported by the current Expat + XML parser: + + 1) All elements that have the form '<![inst]>' where 'inst' is any string + not containing the characters '<' and '>' are stripped from the input + stream. + + 2) Multiple occurrences of the same attribute in an element but the last + are removed. + + 3) Line breaks represented by a single <br> element (without matching + </br> element) are replaced by a literal LF character. + */ +class InputStream final : public ::cppu::WeakImplHelper< css::io::XInputStream > +{ +public: + explicit InputStream( + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Reference< css::io::XInputStream >& rxInStrm ); + virtual ~InputStream() override; + + virtual sal_Int32 SAL_CALL readBytes( css::uno::Sequence< sal_Int8 >& rData, sal_Int32 nBytesToRead ) override; + virtual sal_Int32 SAL_CALL readSomeBytes( css::uno::Sequence< sal_Int8 >& rData, sal_Int32 nMaxBytesToRead ) override; + virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) override; + virtual sal_Int32 SAL_CALL available() override; + virtual void SAL_CALL closeInput() override; + +private: + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + void updateBuffer(); + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + OString readToElementBegin(); + /// @throws css::io::IOException + /// @throws css::uno::RuntimeException + OString readToElementEnd(); + +private: + css::uno::Reference< css::io::XTextInputStream2 > + mxTextStrm; + css::uno::Sequence< sal_Unicode > maOpeningBracket; + css::uno::Sequence< sal_Unicode > maClosingBracket; + OString maBuffer; + sal_Int32 mnBufferPos; +}; + + +} // namespace vml +} // namespace oox + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/vml/vmlshape.hxx b/include/oox/vml/vmlshape.hxx new file mode 100644 index 000000000..9812bce8c --- /dev/null +++ b/include/oox/vml/vmlshape.hxx @@ -0,0 +1,456 @@ +/* -*- 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_VML_VMLSHAPE_HXX +#define INCLUDED_OOX_VML_VMLSHAPE_HXX + +#include <memory> +#include <vector> + +#include <com/sun/star/awt/Point.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <oox/dllapi.h> +#include <oox/helper/helper.hxx> +#include <oox/vml/vmlformatting.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +namespace com::sun::star { + namespace awt { struct Rectangle; } + namespace drawing { class XShape; } + namespace drawing { class XShapes; } + namespace graphic { class XGraphic; } +} + +namespace oox { +namespace vml { + +class Drawing; +struct ShapeParentAnchor; +class ShapeContainer; +class TextBox; + +const sal_Int32 VML_CLIENTDATA_UNCHECKED = 0; +const sal_Int32 VML_CLIENTDATA_CHECKED = 1; +const sal_Int32 VML_CLIENTDATA_MIXED = 2; + +const sal_Int32 VML_CLIENTDATA_TEXT = 0; +const sal_Int32 VML_CLIENTDATA_INTEGER = 1; +const sal_Int32 VML_CLIENTDATA_NUMBER = 2; +const sal_Int32 VML_CLIENTDATA_REFERENCE = 3; +const sal_Int32 VML_CLIENTDATA_FORMULA = 4; + + +/** The shape model structure contains all properties shared by all types of shapes. */ +struct ShapeTypeModel +{ + OUString maShapeId; ///< Unique identifier of the shape. + OUString maLegacyId; ///< Plaintext identifier of the shape. + OUString maShapeName; ///< Name of the shape, if present. + OptValue< sal_Int32 > moShapeType; ///< Builtin shape type identifier. + + OptValue< Int32Pair > moCoordPos; ///< Top-left position of coordinate system for children scaling. + OptValue< Int32Pair > moCoordSize; ///< Size of coordinate system for children scaling. + OUString maPosition; ///< Position type of the shape. + OUString maZIndex; ///< ZIndex of the shape + OUString maLeft; ///< X position of the shape bounding box (number with unit). + OUString maTop; ///< Y position of the shape bounding box (number with unit). + OUString maWidth; ///< Width of the shape bounding box (number with unit). + OUString maHeight; ///< Height of the shape bounding box (number with unit). + OUString maMarginLeft; ///< X position of the shape bounding box to shape anchor (number with unit). + OUString maMarginTop; ///< Y position of the shape bounding box to shape anchor (number with unit). + OUString maPositionHorizontalRelative; ///< The X position is relative to this. + OUString maPositionVerticalRelative; ///< The Y position is relative to this. + OUString maPositionHorizontal; ///< The X position orientation (default: absolute). + OUString maPositionVertical; ///< The Y position orientation. + OUString maWidthPercent; ///< The width in percents of the WidthRelative + OUString maHeightPercent; ///< The height in percents of the HeightRelative + OUString maWidthRelative; ///< To what the width is relative + OUString maHeightRelative; ///< To what the height is relative + OUString maRotation; ///< Rotation of the shape, in degrees. + OUString maFlip; ///< Flip type of the shape (can be "x" or "y"). + bool mbAutoHeight; ///< If true, the height value is a minimum value (mostly used for textboxes) + bool mbVisible; ///< Visible or Hidden + OUString maWrapStyle; ///< Wrapping mode for text. + OUString maArcsize; ///< round rectangles arc size + OUString maEditAs; ///< Edit As type (e.g. "canvas" etc) + OUString maAdjustments; ///< Shape adjustment values + + StrokeModel maStrokeModel; ///< Border line formatting. + FillModel maFillModel; ///< Shape fill formatting. + ShadowModel maShadowModel; ///< Shape shadow formatting. + TextpathModel maTextpathModel; ///< Shape textpath formatting. + + OptValue< OUString > moGraphicPath; ///< Path to a graphic for this shape. + OptValue< OUString > moGraphicTitle; ///< Title of the graphic. + OptValue< OUString > moWrapAnchorX; ///< The base object from which our horizontal positioning should be calculated. + OptValue< OUString > moWrapAnchorY; ///< The base object from which our vertical positioning should be calculated. + OptValue< OUString > moWrapType; ///< How to wrap the text around the object + OptValue< OUString > moWrapSide; ///< On which side to wrap the text around the object + OUString maVTextAnchor; ///< How the text inside the shape is anchored vertically. + OUString maWrapDistanceLeft; ///< Distance from the left side of the shape to the text that wraps around it. + OUString maWrapDistanceRight; ///< Distance from the right side of the shape to the text that wraps around it. + OUString maWrapDistanceTop; ///< Distance from the top of the shape to the text that wraps around it. + OUString maWrapDistanceBottom; ///< Distance from the bottom of the shape to the text that wraps around it. + OptValue<OUString> moCropBottom; ///< Specifies the how much to crop the image from the bottom up as a fraction of picture size. + OptValue<OUString> moCropLeft; ///< Specifies how much to crop the image from the left in as a fraction of picture size. + OptValue<OUString> moCropRight; ///< Specifies how much to crop the image from the right in as a fraction of picture size. + OptValue<OUString> moCropTop; ///< Specifies how much to crop the image from the top down as a fraction of picture size. + OUString maLayoutFlowAlt; ///< Specifies the alternate layout flow for text in textboxes. + + explicit ShapeTypeModel(); + + void assignUsed( const ShapeTypeModel& rSource ); +}; + + +/** A shape template contains all formatting properties of shapes and can serve + as templates for several shapes in a drawing. */ +class SAL_DLLPUBLIC_RTTI ShapeType +{ +public: + explicit ShapeType( Drawing& rDrawing ); + virtual ~ShapeType(); + + /** Returns read/write access to the shape template model structure. */ + ShapeTypeModel& getTypeModel() { return maTypeModel; } + /** Returns read access to the shape template model structure. */ + const ShapeTypeModel& getTypeModel() const { return maTypeModel; } + + /** Returns the shape identifier (which is unique through the containing drawing). */ + const OUString& getShapeId() const { return maTypeModel.maShapeId; } + /** Returns the application defined shape type. */ + sal_Int32 getShapeType() const; + /** Returns the fragment path to the embedded graphic used by this shape. */ + OUString getGraphicPath() const; + + const Drawing& getDrawing() const { return mrDrawing; } + +protected: + /** Returns the coordinate system of this shape. */ + css::awt::Rectangle getCoordSystem() const; + /** Returns the absolute shape rectangle according to the passed anchor. */ + css::awt::Rectangle getRectangle( const ShapeParentAnchor* pParentAnchor ) const; + /** Returns the absolute shape rectangle. */ + virtual css::awt::Rectangle getAbsRectangle() const; + /** Returns the rectangle relative to the parent coordinate system. */ + virtual css::awt::Rectangle getRelRectangle() const; + +protected: + Drawing& mrDrawing; ///< The VML drawing page that contains this shape. + ShapeTypeModel maTypeModel; ///< The model structure containing shape type data. +}; + + +/** Excel specific shape client data (such as cell anchor). */ +struct ClientData +{ + OUString maAnchor; ///< Cell anchor as comma-separated string. + OUString maFmlaMacro; ///< Link to macro associated to the control. + OUString maFmlaPict; ///< Target cell range of picture links. + OUString maFmlaLink; ///< Link to value cell associated to the control. + OUString maFmlaRange; ///< Link to cell range used as data source for the control. + OUString maFmlaGroup; ///< Link to value cell associated to a group of option buttons. + sal_Int32 mnObjType; ///< Type of the shape. + sal_Int32 mnTextHAlign; ///< Horizontal text alignment. + sal_Int32 mnTextVAlign; ///< Vertical text alignment. + sal_Int32 mnCol; ///< Column index for spreadsheet cell note. + sal_Int32 mnRow; ///< Row index for spreadsheet cell note. + sal_Int32 mnChecked; ///< State for checkboxes and option buttons. + sal_Int32 mnDropStyle; ///< Drop down box style (read-only or editable). + sal_Int32 mnDropLines; ///< Number of lines in drop down box. + sal_Int32 mnVal; ///< Current value of spin buttons and scroll bars. + sal_Int32 mnMin; ///< Minimum value of spin buttons and scroll bars. + sal_Int32 mnMax; ///< Maximum value of spin buttons and scroll bars. + sal_Int32 mnInc; ///< Small increment of spin buttons and scroll bars. + sal_Int32 mnPage; ///< Large increment of spin buttons and scroll bars. + sal_Int32 mnSelType; ///< Listbox selection type. + sal_Int32 mnVTEdit; ///< Data type of the textbox. + bool mbPrintObject; ///< True = print the object. + bool mbVisible; ///< True = cell note is visible. + bool mbDde; ///< True = object is linked through DDE. + bool mbNo3D; ///< True = flat style, false = 3D style. + bool mbNo3D2; ///< True = flat style, false = 3D style (listboxes and dropdowns). + bool mbMultiLine; ///< True = textbox allows line breaks. + bool mbVScroll; ///< True = textbox has a vertical scrollbar. + bool mbSecretEdit; ///< True = textbox is a password edit field. + + explicit ClientData(); +}; + + +struct ShapeModel +{ + typedef ::std::vector< css::awt::Point > PointVector; + + OUString maType; ///< Shape template with default properties. + PointVector maPoints; ///< Points for the polyline shape. + std::unique_ptr<TextBox> mxTextBox; ///< Text contents and properties. + std::unique_ptr<ClientData> mxClientData; ///< Excel specific client data. + OUString maLegacyDiagramPath;///< Legacy Diagram Fragment Path + OUString maFrom; ///< Start point for line shape. + OUString maTo; ///< End point for line shape. + OUString maControl1; ///< Bezier control point 1 + OUString maControl2; ///< Bezier control point 2 + OUString maVmlPath; ///< VML path for this shape + bool mbIsSignatureLine; ///< Shape is a signature line + OUString maSignatureId; ///< ID of the signature + OUString maSignatureLineSuggestedSignerName; + OUString maSignatureLineSuggestedSignerTitle; + OUString maSignatureLineSuggestedSignerEmail; + OUString maSignatureLineSigningInstructions; + bool mbSignatureLineShowSignDate; + bool mbSignatureLineCanAddComment; + + explicit ShapeModel(); + ~ShapeModel(); + + /** Creates and returns a new shape textbox structure. */ + TextBox& createTextBox(ShapeTypeModel& rModel); + /** Creates and returns a new shape client data structure. */ + ClientData& createClientData(); +}; + + +/** A shape object that is part of a drawing. May inherit properties from a + shape template. */ +class OOX_DLLPUBLIC ShapeBase : public ShapeType +{ +public: + /** Returns read/write access to the shape model structure. */ + ShapeModel& getShapeModel() { return maShapeModel; } + /** Returns read access to the shape model structure. */ + const ShapeModel& getShapeModel() const { return maShapeModel; } + + /** Returns read access to the shape textbox. */ + const TextBox* getTextBox() const { return maShapeModel.mxTextBox.get(); } + /** Returns read access to the shape client data structure. */ + const ClientData* getClientData() const { return maShapeModel.mxClientData.get(); } + + /** Final processing after import of the drawing fragment. */ + virtual void finalizeFragmentImport(); + + /** Returns the real shape name if existing, or a generated shape name. */ + OUString getShapeName() const; + + /** Returns the shape template with the passed identifier from the child shapes. */ + virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const; + /** Returns the shape with the passed identifier from the child shapes. */ + virtual const ShapeBase* getChildById( const OUString& rShapeId ) const; + + /** Creates the corresponding XShape and inserts it into the passed container. */ + css::uno::Reference< css::drawing::XShape > + convertAndInsert( + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const ShapeParentAnchor* pParentAnchor = nullptr ) const; + + /** Converts position and formatting into the passed existing XShape. */ + void convertFormatting( + const css::uno::Reference< css::drawing::XShape >& rxShape ) const; + + void setContainer(ShapeContainer* pContainer); + ShapeContainer* getContainer() const; + +protected: + explicit ShapeBase( Drawing& rDrawing ); + + /** Derived classes create the corresponding XShape and insert it into the passed container. */ + virtual css::uno::Reference< css::drawing::XShape > + implConvertAndInsert( + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const css::awt::Rectangle& rShapeRect ) const = 0; + + /** Calculates the final shape rectangle according to the passed anchor, + if present, otherwise according to the own anchor settings. */ + css::awt::Rectangle calcShapeRectangle( + const ShapeParentAnchor* pParentAnchor ) const; + + /** Converts common shape properties such as formatting attributes. */ + void convertShapeProperties( + const css::uno::Reference< css::drawing::XShape >& rxShape ) const; + +protected: + ShapeModel maShapeModel; ///< The model structure containing shape data. + ShapeContainer* mpContainer = nullptr; +}; + + +/** A simple shape object based on a specific UNO shape service. */ +class SimpleShape : public ShapeBase +{ +public: + explicit SimpleShape( Drawing& rDrawing, const OUString& rService ); + + void setService( const OUString& aService ) { maService = aService; } + +protected: + /** Creates the corresponding XShape and inserts it into the passed container. */ + virtual css::uno::Reference< css::drawing::XShape > + implConvertAndInsert( + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const css::awt::Rectangle& rShapeRect ) const override; + /** Used by both RectangleShape and ComplexShape. */ + css::uno::Reference<css::drawing::XShape>createEmbeddedPictureObject( + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const css::awt::Rectangle& rShapeRect, OUString const & rGraphicPath ) const; + + css::uno::Reference<css::drawing::XShape>createPictureObject( + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const css::awt::Rectangle& rShapeRect, + css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) const; + +private: + OUString maService; ///< Name of the UNO shape service. +}; + + +/** A rectangular shape object. */ +class RectangleShape final : public SimpleShape +{ +public: + explicit RectangleShape( Drawing& rDrawing ); +private: + /** Creates the corresponding XShape and inserts it into the passed container. */ + virtual css::uno::Reference<css::drawing::XShape> + implConvertAndInsert( + const css::uno::Reference<css::drawing::XShapes>& rxShapes, + const css::awt::Rectangle& rShapeRect) const override; +}; + + +/** An oval shape object. */ +class EllipseShape final : public SimpleShape +{ +public: + explicit EllipseShape( Drawing& rDrawing ); +}; + + +/** A polygon shape object. */ +class PolyLineShape final : public SimpleShape +{ +public: + explicit PolyLineShape( Drawing& rDrawing ); + +private: + /** Creates the corresponding XShape and inserts it into the passed container. */ + virtual css::uno::Reference< css::drawing::XShape > + implConvertAndInsert( + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const css::awt::Rectangle& rShapeRect ) const override; +}; + +/** A Line shape object. */ +class LineShape final : public SimpleShape +{ +public: + explicit LineShape( Drawing& rDrawing ); + +private: + /** Returns the absolute shape rectangle. */ + virtual css::awt::Rectangle getAbsRectangle() const override; + /** Returns the rectangle relative to the parent coordinate system. */ + virtual css::awt::Rectangle getRelRectangle() const override; +}; + +/** Bezier shape object that supports to, from, control1 and control2 + attribute or path attribute specification */ +class BezierShape final : public SimpleShape +{ +public: + explicit BezierShape( Drawing& rDrawing ); + +private: + /** Creates the corresponding XShape and inserts it into the passed container. */ + virtual css::uno::Reference< css::drawing::XShape > + implConvertAndInsert( + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const css::awt::Rectangle& rShapeRect ) const override; +}; + + +/** A shape object with custom geometry. */ +class CustomShape : public SimpleShape +{ +public: + explicit CustomShape( Drawing& rDrawing ); + +protected: + /** Creates the corresponding XShape and inserts it into the passed container. */ + virtual css::uno::Reference< css::drawing::XShape > + implConvertAndInsert( + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const css::awt::Rectangle& rShapeRect ) const override; +}; + + +/** A complex shape object. This can be a picture shape, a custom shape, an OLE + object, or an ActiveX form control. */ +class ComplexShape final : public CustomShape +{ +public: + explicit ComplexShape( Drawing& rDrawing ); + +private: + /** Creates the corresponding XShape and inserts it into the passed container. */ + virtual css::uno::Reference< css::drawing::XShape > + implConvertAndInsert( + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const css::awt::Rectangle& rShapeRect ) const override; +}; + + +/** A group shape that extends the basic shape by a container of child shapes. */ +class GroupShape final : public ShapeBase +{ +public: + explicit GroupShape( Drawing& rDrawing ); + virtual ~GroupShape() override; + + /** Returns read/write access to the container of child shapes and templates. */ + ShapeContainer& getChildren() { return *mxChildren; } + /** Returns read access to the container of child shapes and templates. */ + const ShapeContainer& getChildren() const { return *mxChildren; } + + /** Final processing after import of the drawing fragment. */ + virtual void finalizeFragmentImport() override; + + /** Returns the shape template with the passed identifier from the child shapes. */ + virtual const ShapeType* getChildTypeById( const OUString& rShapeId ) const override; + /** Returns the shape with the passed identifier from the child shapes. */ + virtual const ShapeBase* getChildById( const OUString& rShapeId ) const override; + +private: + /** Creates the corresponding XShape and inserts it into the passed container. */ + virtual css::uno::Reference< css::drawing::XShape > + implConvertAndInsert( + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const css::awt::Rectangle& rShapeRect ) const override; + +private: + std::unique_ptr<ShapeContainer> mxChildren; ///< Shapes and templates that are part of this group. +}; + + +} // namespace vml +} // namespace oox + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/vml/vmlshapecontainer.hxx b/include/oox/vml/vmlshapecontainer.hxx new file mode 100644 index 000000000..8a33ef436 --- /dev/null +++ b/include/oox/vml/vmlshapecontainer.hxx @@ -0,0 +1,146 @@ +/* -*- 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_VML_VMLSHAPECONTAINER_HXX +#define INCLUDED_OOX_VML_VMLSHAPECONTAINER_HXX + +#include <cstddef> +#include <functional> +#include <memory> +#include <stack> + +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <oox/helper/refmap.hxx> +#include <oox/helper/refvector.hxx> +#include <rtl/ustring.hxx> + +namespace com::sun::star { + namespace drawing { class XShapes; } +} + +namespace oox { +namespace vml { + +class Drawing; +class ShapeType; +class ShapeBase; + + +struct ShapeParentAnchor +{ + css::awt::Rectangle maShapeRect; + css::awt::Rectangle maCoordSys; +}; + + +/** Container that holds a list of shapes and shape templates. */ +class ShapeContainer +{ +public: + explicit ShapeContainer( Drawing& rDrawing ); + ~ShapeContainer(); + + /** Returns the drawing this shape container is part of. */ + Drawing& getDrawing() { return mrDrawing; } + + /** Creates and returns a new shape template object. */ + std::shared_ptr<ShapeType> createShapeType(); + /** Creates and returns a new shape object of the specified type. */ + template< typename ShapeT > + std::shared_ptr<ShapeT> createShape(); + + /** Final processing after import of the drawing fragment. */ + void finalizeFragmentImport(); + + /** Returns true, if this container does not contain any shapes. */ + bool empty() const { return maShapes.empty(); } + + /** Returns the shape template with the passed identifier. + Searches in all group shapes too. */ + const ShapeType* getShapeTypeById( const OUString& rShapeId ) const; + /** Returns the shape with the passed identifier. + Searches in all group shapes too. */ + const ShapeBase* getShapeById( const OUString& rShapeId ) const; + + /** Searches for a shape by using the passed functor that takes a constant + reference of a ShapeBase object. */ + template< typename Functor > + const ShapeBase* findShape( const Functor& rFunctor ) const; + + /** + (Word only) Returns the last shape in the collection, if it is after the last + mark from pushMark(), and removes it. + */ + std::shared_ptr< ShapeBase > takeLastShape(); + /** + Adds a recursion mark to the stack. It is possible that a shape contains <w:txbxContent> + which contains another shape, and writerfilter needs to know which shape is from the inner + ooxml context and which from the outer ooxml context, while it is necessary to keep + at least shape types across such blocks. Therefore this function marks beginning + of each shape xml block, and takeLastShape() returns only shapes from this block. + */ + void pushMark(); + /** + Removes a recursion mark. + */ + void popMark(); + + /** Creates and inserts all UNO shapes into the passed container. */ + void convertAndInsert( + const css::uno::Reference< css::drawing::XShapes >& rxShapes, + const ShapeParentAnchor* pParentAnchor = nullptr ) const; + +private: + typedef RefVector< ShapeType > ShapeTypeVector; + typedef RefVector< ShapeBase > ShapeVector; + typedef RefMap< OUString, ShapeType > ShapeTypeMap; + typedef RefMap< OUString, ShapeBase > ShapeMap; + + Drawing& mrDrawing; ///< The VML drawing page that contains this shape. + ShapeTypeVector maTypes; ///< All shape templates. + ShapeVector maShapes; ///< All shape definitions. + ShapeTypeMap maTypesById; ///< All shape templates mapped by identifier. + ShapeMap maShapesById; ///< All shape definitions mapped by identifier. + std::stack< size_t > markStack; ///< Recursion marks from pushMark()/popMark(). +}; + + +template< typename ShapeT > +std::shared_ptr<ShapeT> ShapeContainer::createShape() +{ + auto xShape = std::make_shared<ShapeT>( mrDrawing ); + xShape->setContainer(this); + maShapes.push_back( xShape ); + return xShape; +} + +template< typename Functor > +const ShapeBase* ShapeContainer::findShape( const Functor& rFunctor ) const +{ + return maShapes.findIf( rFunctor ).get(); +} + + +} // namespace vml +} // namespace oox + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/vml/vmlshapecontext.hxx b/include/oox/vml/vmlshapecontext.hxx new file mode 100644 index 000000000..c07bcf12e --- /dev/null +++ b/include/oox/vml/vmlshapecontext.hxx @@ -0,0 +1,191 @@ +/* -*- 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_VML_VMLSHAPECONTEXT_HXX +#define INCLUDED_OOX_VML_VMLSHAPECONTEXT_HXX + +#include <oox/core/contexthandler.hxx> +#include <oox/core/contexthandler2.hxx> +#include <oox/helper/helper.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +namespace oox { class AttributeList; } + +namespace oox { +namespace vml { + +class Drawing; + +struct ShapeTypeModel; +class ShapeType; + +struct ClientData; +struct ShapeModel; +class ShapeBase; +class GroupShape; +class RectangleShape; + +class ShapeContainer; + + +class ShapeLayoutContext final : public ::oox::core::ContextHandler2 +{ +public: + explicit ShapeLayoutContext( + ::oox::core::ContextHandler2Helper const & rParent, + Drawing& rDrawing ); + + virtual ::oox::core::ContextHandlerRef + onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; + +private: + Drawing& mrDrawing; +}; + + +class ClientDataContext final : public ::oox::core::ContextHandler2 +{ +public: + explicit ClientDataContext( + ::oox::core::ContextHandler2Helper const & rParent, + ClientData& rClientData, + const AttributeList& rAttribs ); + + virtual ::oox::core::ContextHandlerRef + onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; + virtual void onCharacters( const OUString& rChars ) override; + virtual void onEndElement() override; + +private: + ClientData& mrClientData; + OUString maElementText; +}; + + +class ShapeContextBase : public ::oox::core::ContextHandler2 +{ +public: + static ::oox::core::ContextHandlerRef + createShapeContext( + ::oox::core::ContextHandler2Helper const & rParent, + ShapeContainer& rShapes, + sal_Int32 nElement, + const AttributeList& rAttribs ); + +protected: + explicit ShapeContextBase( ::oox::core::ContextHandler2Helper const & rParent ); +}; + + +class ShapeTypeContext : public ShapeContextBase +{ +public: + explicit ShapeTypeContext( + ::oox::core::ContextHandler2Helper const & rParent, + std::shared_ptr<ShapeType> const& pShapeType, + const AttributeList& rAttribs ); + + virtual ::oox::core::ContextHandlerRef + onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; + +private: + /** Processes the 'style' attribute. */ + void setStyle( const OUString& rStyle ); + + /** Resolve a relation identifier to a fragment path. */ + OptValue< OUString > decodeFragmentPath( const AttributeList& rAttribs, sal_Int32 nToken ) const; + +private: + std::shared_ptr<ShapeType> m_pShapeType; + ShapeTypeModel& mrTypeModel; +}; + + +class ShapeContext : public ShapeTypeContext +{ +public: + explicit ShapeContext(::oox::core::ContextHandler2Helper const& rParent, + const std::shared_ptr<ShapeBase>& pShape, const AttributeList& rAttribs); + + virtual ::oox::core::ContextHandlerRef + onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; + +private: + /** Processes the 'points' attribute. */ + void setPoints( const OUString& rPoints ); + /** Processes the 'from' attribute. */ + void setFrom( const OUString& rPoints ); + /** Processes the 'to' attribute. */ + void setTo( const OUString& rPoints ); + /** Processes the 'control1' attribute. */ + void setControl1( const OUString& rPoints ); + /** Processes the 'control2' attribute. */ + void setControl2( const OUString& rPoints ); + /** Processes the 'path' attribute. */ + void setVmlPath( const OUString& rPath ); + +private: + ShapeBase& mrShape; + ShapeModel& mrShapeModel; +}; + + +class GroupShapeContext final : public ShapeContext +{ +public: + explicit GroupShapeContext(::oox::core::ContextHandler2Helper const& rParent, + const std::shared_ptr<GroupShape>& pShape, + const AttributeList& rAttribs); + + virtual ::oox::core::ContextHandlerRef + onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; + +private: + ShapeContainer& mrShapes; +}; + + +class RectangleShapeContext final : public ShapeContext +{ +public: + explicit RectangleShapeContext(::oox::core::ContextHandler2Helper const& rParent, + const AttributeList& rAttribs, + const std::shared_ptr<RectangleShape>& pShape); + + virtual ::oox::core::ContextHandlerRef + onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; +}; + +class ControlShapeContext final : public ShapeContextBase +{ +public: + explicit ControlShapeContext( + ::oox::core::ContextHandler2Helper const & rParent, + ShapeContainer& rShapes, + const AttributeList& rAttribs ); +}; + + +} // namespace vml +} // namespace oox + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/vml/vmltextbox.hxx b/include/oox/vml/vmltextbox.hxx new file mode 100644 index 000000000..7f7710bcb --- /dev/null +++ b/include/oox/vml/vmltextbox.hxx @@ -0,0 +1,115 @@ +/* -*- 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_VML_VMLTEXTBOX_HXX +#define INCLUDED_OOX_VML_VMLTEXTBOX_HXX + +#include <cstddef> +#include <vector> + +#include <com/sun/star/uno/Reference.hxx> +#include <oox/dllapi.h> +#include <oox/helper/helper.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +namespace com::sun::star { + namespace drawing { class XShape; } +} + +namespace oox { +namespace vml { + +struct ShapeTypeModel; + + +/// A text paragraph in a textbox. +struct TextParagraphModel +{ + OptValue<OUString> moParaAdjust; ///< Paragraph adjust (left, center, right, etc.) + OptValue<OUString> moParaStyleName; +}; + +/** Font settings for a text portion in a textbox. */ +struct OOX_DLLPUBLIC TextFontModel +{ + OptValue< OUString > moName; ///< Font name. + OptValue< OUString > moNameAsian; ///< Asian font name. + OptValue< OUString > moNameComplex; ///< Complex font name. + OptValue< OUString > moColor; ///< Font color, HTML encoded, sort of. + OptValue< sal_Int32 > monSize; ///< Font size in twips. + OptValue< sal_Int32 > monUnderline; ///< Single or double underline. + OptValue< sal_Int32 > monEscapement; ///< Subscript or superscript. + OptValue< bool > mobBold; + OptValue< bool > mobItalic; + OptValue< bool > mobStrikeout; + OptValue<sal_Int32> monSpacing; + + explicit TextFontModel(); +}; + + +/** A text portion in a textbox with the same formatting for all characters. */ +struct TextPortionModel +{ + TextParagraphModel maParagraph; + TextFontModel maFont; + OUString maText; + + explicit TextPortionModel( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText ); +}; + + +/** The textbox contains all text contents and properties. */ +class OOX_DLLPUBLIC TextBox +{ +public: + explicit TextBox(ShapeTypeModel& rTypeModel); + + /** Appends a new text portion to the textbox. */ + void appendPortion( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText ); + + /** Returns the current number of text portions. */ + size_t getPortionCount() const { return maPortions.size(); } + /** Returns the font settings of the first text portion. */ + const TextFontModel* getFirstFont() const; + /** Returns the entire text of all text portions. */ + OUString getText() const; + void convert(const css::uno::Reference<css::drawing::XShape>& xShape) const; + + ShapeTypeModel& mrTypeModel; + /// Text distance from the border (inset attribute of v:textbox), valid only if set. + bool borderDistanceSet; + int borderDistanceLeft, borderDistanceTop, borderDistanceRight, borderDistanceBottom; + OUString maLayoutFlow; + OUString msNextTextbox; + +private: + typedef ::std::vector< TextPortionModel > PortionVector; + + PortionVector maPortions; +}; + + +} // namespace vml +} // namespace oox + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/vml/vmltextboxcontext.hxx b/include/oox/vml/vmltextboxcontext.hxx new file mode 100644 index 000000000..d5c3dde86 --- /dev/null +++ b/include/oox/vml/vmltextboxcontext.hxx @@ -0,0 +1,88 @@ +/* -*- 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_VML_VMLTEXTBOXCONTEXT_HXX +#define INCLUDED_OOX_VML_VMLTEXTBOXCONTEXT_HXX + +#include <cstddef> + +#include <oox/core/contexthandler.hxx> +#include <oox/core/contexthandler2.hxx> +#include <oox/vml/vmltextbox.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +namespace oox { + class AttributeList; + class GraphicHelper; + +namespace vml { + + +class TextPortionContext final : public ::oox::core::ContextHandler2 +{ +public: + explicit TextPortionContext( + ::oox::core::ContextHandler2Helper const & rParent, + TextBox& rTextBox, + TextParagraphModel const & rParagraph, + const TextFontModel& rParentFont, + sal_Int32 nElement, + const AttributeList& rAttribs ); + + virtual ::oox::core::ContextHandlerRef + onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; + virtual void onCharacters( const OUString& rChars ) override; + virtual void onStartElement(const AttributeList& rAttribs) override; + virtual void onEndElement() override; + +private: + TextBox& mrTextBox; + TextParagraphModel maParagraph; + TextFontModel maFont; + size_t mnInitialPortions; +}; + + +class TextBoxContext final : public ::oox::core::ContextHandler2 +{ +public: + explicit TextBoxContext( + ::oox::core::ContextHandler2Helper const & rParent, + TextBox& rTextBox, + const AttributeList& rAttribs, + const GraphicHelper& graphicHelper ); + + virtual ::oox::core::ContextHandlerRef + onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; + virtual void onStartElement(const AttributeList& rAttribs) override; + virtual void onEndElement() override; + +private: + TextBox& mrTextBox; + TextParagraphModel maParagraph; +}; + + +} // namespace vml +} // namespace oox + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |