Line data Source code
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 : #include "WpsContext.hxx"
11 : #include <oox/drawingml/shapepropertiescontext.hxx>
12 : #include <oox/drawingml/shapestylecontext.hxx>
13 : #include <com/sun/star/beans/XPropertyState.hpp>
14 : #include <oox/drawingml/drawingmltypes.hxx>
15 :
16 : using namespace com::sun::star;
17 :
18 : namespace oox
19 : {
20 : namespace shape
21 : {
22 :
23 873 : WpsContext::WpsContext(ContextHandler2Helper& rParent, uno::Reference<drawing::XShape> xShape)
24 : : ContextHandler2(rParent),
25 873 : mxShape(xShape)
26 : {
27 873 : mpShape.reset(new oox::drawingml::Shape("com.sun.star.drawing.CustomShape"));
28 873 : mpShape->setWps(true);
29 873 : }
30 :
31 1746 : WpsContext::~WpsContext()
32 : {
33 1746 : }
34 :
35 600 : oox::drawingml::ShapePtr WpsContext::getShape()
36 : {
37 600 : return mpShape;
38 : }
39 :
40 3156 : oox::core::ContextHandlerRef WpsContext::onCreateContext(sal_Int32 nElementToken, const oox::AttributeList& rAttribs)
41 : {
42 3156 : switch (getBaseToken(nElementToken))
43 : {
44 : case XML_wsp:
45 600 : break;
46 : case XML_cNvCnPr:
47 102 : break;
48 : case XML_cNvSpPr:
49 498 : break;
50 : case XML_spPr:
51 600 : return new oox::drawingml::ShapePropertiesContext(*this, *mpShape);
52 : break;
53 : case XML_style:
54 187 : return new oox::drawingml::ShapeStyleContext(*this, *mpShape);
55 : break;
56 : case XML_bodyPr:
57 585 : if (mxShape.is())
58 : {
59 273 : OptValue<OUString> oVert = rAttribs.getString(XML_vert);
60 273 : if (oVert.has() && oVert.get() == "vert270")
61 : {
62 : // No support for this in core, work around by char rotation, as we do so for table cells already.
63 4 : uno::Reference<text::XText> xText(mxShape, uno::UNO_QUERY);
64 8 : uno::Reference<text::XTextCursor> xTextCursor = xText->createTextCursor();
65 4 : xTextCursor->gotoStart(false);
66 4 : xTextCursor->gotoEnd(true);
67 8 : uno::Reference<beans::XPropertyState> xPropertyState(xTextCursor, uno::UNO_QUERY);
68 4 : beans::PropertyState aState = xPropertyState->getPropertyState("CharRotation");
69 4 : if (aState == beans::PropertyState_DEFAULT_VALUE)
70 : {
71 4 : uno::Reference<beans::XPropertySet> xPropertySet(xTextCursor, uno::UNO_QUERY);
72 4 : xPropertySet->setPropertyValue("CharRotation", uno::makeAny(sal_Int16(900)));
73 4 : }
74 : }
75 :
76 : // Handle inset attributes for Writer textframes.
77 273 : sal_Int32 aInsets[] = { XML_lIns, XML_tIns, XML_rIns, XML_bIns };
78 546 : boost::optional<sal_Int32> oInsets[4];
79 1365 : for (size_t i = 0; i < SAL_N_ELEMENTS(aInsets); ++i)
80 : {
81 1092 : OptValue<OUString> oValue = rAttribs.getString(aInsets[i]);
82 1092 : if (oValue.has())
83 888 : oInsets[i] = oox::drawingml::GetCoordinate(oValue.get());
84 1092 : }
85 546 : OUString aProps[] = { OUString("LeftBorderDistance"), OUString("TopBorderDistance"), OUString("RightBorderDistance"), OUString("BottomBorderDistance") };
86 546 : uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY);
87 1365 : for (size_t i = 0; i < SAL_N_ELEMENTS(aProps); ++i)
88 1092 : if (oInsets[i])
89 888 : xPropertySet->setPropertyValue(aProps[i], uno::makeAny(*oInsets[i]));
90 :
91 : // Handle text vertical adjustment inside a text frame
92 273 : if (rAttribs.hasAttribute(XML_anchor))
93 : {
94 271 : drawing::TextVerticalAdjust eAdjust = drawingml::GetTextVerticalAdjust(rAttribs.getToken(XML_anchor, XML_t));
95 271 : xPropertySet->setPropertyValue("TextVerticalAdjust", uno::makeAny(eAdjust));
96 : }
97 546 : return this;
98 : }
99 312 : break;
100 : case XML_noAutofit:
101 : case XML_spAutoFit:
102 : {
103 : // We can't use oox::drawingml::TextBodyPropertiesContext here, as this
104 : // is a child context of bodyPr, so the shape is already sent: we need
105 : // to alter the XShape directly.
106 242 : uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY);
107 242 : if (xPropertySet.is())
108 242 : xPropertySet->setPropertyValue("FrameIsAutomaticHeight", uno::makeAny(getBaseToken(nElementToken) == XML_spAutoFit));
109 : }
110 242 : break;
111 : case XML_txbx:
112 288 : mpShape->getCustomShapeProperties()->setShapeTypeOverride(true);
113 288 : mpShape->setServiceName("com.sun.star.text.TextFrame");
114 288 : break;
115 : default:
116 : SAL_WARN("oox", "WpsContext::createFastChildContext: unhandled element: " << getBaseToken(nElementToken));
117 54 : break;
118 : }
119 2096 : return 0;
120 : }
121 :
122 : }
123 177 : }
124 :
125 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|