1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 */ 9 10 #pragma once 11 12 #include <stack> 13 #include <vector> 14 15 #include <dmapper/GraphicZOrderHelper.hxx> 16 #include <tools/ref.hxx> 17 18 namespace com::sun::star 19 { 20 namespace beans 21 { 22 class XPropertySet; 23 struct PropertyValue; 24 } 25 namespace drawing 26 { 27 class XShape; 28 class XShapes; 29 } 30 namespace lang 31 { 32 class XComponent; 33 } 34 } 35 36 namespace writerfilter::rtftok 37 { 38 class RTFDocumentImpl; 39 class RTFShape; 40 41 /// Handles the import of drawings using RTF markup. 42 class RTFSdrImport final : public virtual SvRefBase 43 { 44 public: 45 RTFSdrImport(RTFDocumentImpl& rDocument, 46 css::uno::Reference<css::lang::XComponent> const& xDstDoc); 47 ~RTFSdrImport() override; 48 49 enum ShapeOrPict 50 { 51 SHAPE, 52 PICT 53 }; 54 void resolve(RTFShape& rShape, bool bClose, ShapeOrPict shapeOrPict); 55 void close(); 56 void append(std::u16string_view aKey, const OUString& aValue); 57 /// Append property on the current parent. 58 void appendGroupProperty(std::u16string_view aKey, const OUString& aValue); 59 void resolveDhgt(css::uno::Reference<css::beans::XPropertySet> const& xPropertySet, 60 sal_Int32 nZOrder, bool bOldStyle); 61 /// Set line color and line width on the shape, using the relevant API depending on if the shape is a text frame or not. 62 static void 63 resolveLineColorAndWidth(bool bTextFrame, 64 const css::uno::Reference<css::beans::XPropertySet>& xPropertySet, 65 css::uno::Any const& rLineColor, css::uno::Any const& rLineWidth); 66 static void resolveFLine(css::uno::Reference<css::beans::XPropertySet> const& xPropertySet, 67 sal_Int32 nFLine); 68 /** 69 * These are the default in Word, but not in Writer. 70 * 71 * @param bNew if the frame is new-style or old-style. 72 */ 73 static std::vector<css::beans::PropertyValue> getTextFrameDefaults(bool bNew); 74 /// Push a new group shape to the parent stack. 75 void pushParent(css::uno::Reference<css::drawing::XShapes> const& xParent); 76 /// Pop the current group shape from the parent stack. 77 void popParent(); getCurrentShape() const78 css::uno::Reference<css::drawing::XShape> const& getCurrentShape() const { return m_xShape; } isFakePict() const79 bool isFakePict() const { return m_bFakePict; } 80 81 private: 82 void createShape(const OUString& rService, css::uno::Reference<css::drawing::XShape>& xShape, 83 css::uno::Reference<css::beans::XPropertySet>& xPropertySet); 84 void applyProperty(css::uno::Reference<css::drawing::XShape> const& xShape, 85 std::u16string_view aKey, const OUString& aValue) const; 86 int initShape(css::uno::Reference<css::drawing::XShape>& o_xShape, 87 css::uno::Reference<css::beans::XPropertySet>& o_xPropSet, bool& o_rIsCustomShape, 88 RTFShape const& rShape, bool bClose, ShapeOrPict shapeOrPict); 89 90 RTFDocumentImpl& m_rImport; 91 std::stack<css::uno::Reference<css::drawing::XShapes>> m_aParents; 92 css::uno::Reference<css::drawing::XShape> m_xShape; 93 /// If m_xShape is imported as a Writer text frame (instead of a drawinglayer rectangle). 94 bool m_bTextFrame; 95 /// If m_xShape is imported as a Writer text graphic object (instead of a drawinglayer shape). 96 bool m_bTextGraphicObject; 97 /// if inside \pict, but actually it's a shape (not a picture) 98 bool m_bFakePict; 99 std::stack<writerfilter::dmapper::GraphicZOrderHelper> m_aGraphicZOrderHelpers; 100 }; 101 } // namespace writerfilter::rtftok 102 103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 104