diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-01-24 21:25:24 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-01-25 08:41:42 +0100 |
commit | 83f3706bf489a3ed37880353ca5ea90638c38fe7 (patch) | |
tree | efdbf6dcef1227d61cc1ddc746c49f98dd352d04 /oox | |
parent | b8c725cf871b56f74a74dc5d9b193331f98b3f4a (diff) |
oox: turn on clang-format for WpsContext
This had manual consistent formatting. Recently it was broken, so bring
back consisency by using clang-format.
Change-Id: I742f9a4f328a7455f2e2c7dde4e3cb2624eb9178
Reviewed-on: https://gerrit.libreoffice.org/66885
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/shape/WpsContext.cxx | 319 | ||||
-rw-r--r-- | oox/source/shape/WpsContext.hxx | 9 |
2 files changed, 176 insertions, 152 deletions
diff --git a/oox/source/shape/WpsContext.cxx b/oox/source/shape/WpsContext.cxx index 069c6386462d..19b413f5c329 100644 --- a/oox/source/shape/WpsContext.cxx +++ b/oox/source/shape/WpsContext.cxx @@ -34,196 +34,221 @@ namespace oox { namespace shape { - -WpsContext::WpsContext(ContextHandler2Helper const& rParent, uno::Reference<drawing::XShape> xShape, const drawingml::ShapePtr& pMasterShapePtr, const drawingml::ShapePtr& pShapePtr ) - : ShapeContext( rParent, pMasterShapePtr, pShapePtr ), - mxShape(std::move(xShape)) +WpsContext::WpsContext(ContextHandler2Helper const& rParent, uno::Reference<drawing::XShape> xShape, + const drawingml::ShapePtr& pMasterShapePtr, + const drawingml::ShapePtr& pShapePtr) + : ShapeContext(rParent, pMasterShapePtr, pShapePtr) + , mxShape(std::move(xShape)) { mpShapePtr->setWps(true); } WpsContext::~WpsContext() = default; -oox::core::ContextHandlerRef WpsContext::onCreateContext(sal_Int32 nElementToken, const oox::AttributeList& rAttribs) +oox::core::ContextHandlerRef WpsContext::onCreateContext(sal_Int32 nElementToken, + const oox::AttributeList& rAttribs) { switch (getBaseToken(nElementToken)) { - case XML_wsp: - break; - case XML_cNvCnPr: - break; - case XML_bodyPr: - if (mxShape.is()) - { - uno::Reference<lang::XServiceInfo> xServiceInfo(mxShape, uno::UNO_QUERY); - uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY); - OptValue<OUString> oVert = rAttribs.getString(XML_vert); - if (oVert.has() && oVert.get() == "vert270") + case XML_wsp: + break; + case XML_cNvCnPr: + break; + case XML_bodyPr: + if (mxShape.is()) { - if (xServiceInfo->supportsService("com.sun.star.text.TextFrame")) + uno::Reference<lang::XServiceInfo> xServiceInfo(mxShape, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY); + OptValue<OUString> oVert = rAttribs.getString(XML_vert); + if (oVert.has() && oVert.get() == "vert270") { - // No support for this in core, work around by char rotation, as we do so for table cells already. - uno::Reference<text::XText> xText(mxShape, uno::UNO_QUERY); - uno::Reference<text::XTextCursor> xTextCursor = xText->createTextCursor(); - xTextCursor->gotoStart(false); - xTextCursor->gotoEnd(true); - uno::Reference<beans::XPropertyState> xPropertyState(xTextCursor, uno::UNO_QUERY); - beans::PropertyState aState = xPropertyState->getPropertyState("CharRotation"); - if (aState == beans::PropertyState_DEFAULT_VALUE) + if (xServiceInfo->supportsService("com.sun.star.text.TextFrame")) { - uno::Reference<beans::XPropertySet> xTextCursorPropertySet(xTextCursor, uno::UNO_QUERY); - xTextCursorPropertySet->setPropertyValue("CharRotation", uno::makeAny(sal_Int16(900))); + // No support for this in core, work around by char rotation, as we do so for table cells already. + uno::Reference<text::XText> xText(mxShape, uno::UNO_QUERY); + uno::Reference<text::XTextCursor> xTextCursor = xText->createTextCursor(); + xTextCursor->gotoStart(false); + xTextCursor->gotoEnd(true); + uno::Reference<beans::XPropertyState> xPropertyState(xTextCursor, + uno::UNO_QUERY); + beans::PropertyState aState + = xPropertyState->getPropertyState("CharRotation"); + if (aState == beans::PropertyState_DEFAULT_VALUE) + { + uno::Reference<beans::XPropertySet> xTextCursorPropertySet( + xTextCursor, uno::UNO_QUERY); + xTextCursorPropertySet->setPropertyValue("CharRotation", + uno::makeAny(sal_Int16(900))); + } + } + else + { + // Get the existing rotation of the shape. + drawing::HomogenMatrix3 aMatrix; + xPropertySet->getPropertyValue("Transformation") >>= aMatrix; + basegfx::B2DHomMatrix aTransformation; + aTransformation.set(0, 0, aMatrix.Line1.Column1); + aTransformation.set(0, 1, aMatrix.Line1.Column2); + aTransformation.set(0, 2, aMatrix.Line1.Column3); + aTransformation.set(1, 0, aMatrix.Line1.Column1); + aTransformation.set(1, 1, aMatrix.Line2.Column2); + aTransformation.set(1, 2, aMatrix.Line3.Column3); + aTransformation.set(2, 0, aMatrix.Line1.Column1); + aTransformation.set(2, 1, aMatrix.Line2.Column2); + aTransformation.set(2, 2, aMatrix.Line3.Column3); + basegfx::B2DTuple aScale; + basegfx::B2DTuple aTranslate; + double fRotate = 0; + double fShearX = 0; + aTransformation.decompose(aScale, aTranslate, fRotate, fShearX); + + // If the text is not rotated the way the shape wants it already, set the angle. + const sal_Int32 nRotation = -270; + if (static_cast<long>(basegfx::rad2deg(fRotate)) + != NormAngle36000(static_cast<long>(nRotation) * 100) / 100) + { + comphelper::SequenceAsHashMap aCustomShapeGeometry( + xPropertySet->getPropertyValue("CustomShapeGeometry")); + aCustomShapeGeometry["TextPreRotateAngle"] <<= nRotation; + xPropertySet->setPropertyValue( + "CustomShapeGeometry", + uno::makeAny(aCustomShapeGeometry.getAsConstPropertyValueList())); + } } } - else - { - // Get the existing rotation of the shape. - drawing::HomogenMatrix3 aMatrix; - xPropertySet->getPropertyValue("Transformation") >>= aMatrix; - basegfx::B2DHomMatrix aTransformation; - aTransformation.set(0, 0, aMatrix.Line1.Column1); - aTransformation.set(0, 1, aMatrix.Line1.Column2); - aTransformation.set(0, 2, aMatrix.Line1.Column3); - aTransformation.set(1, 0, aMatrix.Line1.Column1); - aTransformation.set(1, 1, aMatrix.Line2.Column2); - aTransformation.set(1, 2, aMatrix.Line3.Column3); - aTransformation.set(2, 0, aMatrix.Line1.Column1); - aTransformation.set(2, 1, aMatrix.Line2.Column2); - aTransformation.set(2, 2, aMatrix.Line3.Column3); - basegfx::B2DTuple aScale; - basegfx::B2DTuple aTranslate; - double fRotate = 0; - double fShearX = 0; - aTransformation.decompose(aScale, aTranslate, fRotate, fShearX); - // If the text is not rotated the way the shape wants it already, set the angle. - const sal_Int32 nRotation = -270; - if (static_cast<long>(basegfx::rad2deg(fRotate)) != NormAngle36000(static_cast<long>(nRotation) * 100) / 100) + if (xServiceInfo.is()) + { + // Handle inset attributes for Writer textframes. + sal_Int32 aInsets[] = { XML_lIns, XML_tIns, XML_rIns, XML_bIns }; + boost::optional<sal_Int32> oInsets[4]; + for (std::size_t i = 0; i < SAL_N_ELEMENTS(aInsets); ++i) { - comphelper::SequenceAsHashMap aCustomShapeGeometry(xPropertySet->getPropertyValue("CustomShapeGeometry")); - aCustomShapeGeometry["TextPreRotateAngle"] <<= nRotation; - xPropertySet->setPropertyValue("CustomShapeGeometry", uno::makeAny(aCustomShapeGeometry.getAsConstPropertyValueList())); + OptValue<OUString> oValue = rAttribs.getString(aInsets[i]); + if (oValue.has()) + oInsets[i] = oox::drawingml::GetCoordinate(oValue.get()); + else + // Defaults from the spec: left/right: 91440 EMU, top/bottom: 45720 EMU + oInsets[i] + = (aInsets[i] == XML_lIns || aInsets[i] == XML_rIns) ? 254 : 127; } + const OUString aShapeProps[] + = { OUString("TextLeftDistance"), OUString("TextUpperDistance"), + OUString("TextRightDistance"), OUString("TextLowerDistance") }; + for (std::size_t i = 0; i < SAL_N_ELEMENTS(aShapeProps); ++i) + if (oInsets[i]) + xPropertySet->setPropertyValue(aShapeProps[i], + uno::makeAny(*oInsets[i])); } - } - if (xServiceInfo.is()) - { - // Handle inset attributes for Writer textframes. - sal_Int32 aInsets[] = { XML_lIns, XML_tIns, XML_rIns, XML_bIns }; - boost::optional<sal_Int32> oInsets[4]; - for (std::size_t i = 0; i < SAL_N_ELEMENTS(aInsets); ++i) + // Handle text vertical adjustment inside a text frame + if (rAttribs.hasAttribute(XML_anchor)) { - OptValue<OUString> oValue = rAttribs.getString(aInsets[i]); - if (oValue.has()) - oInsets[i] = oox::drawingml::GetCoordinate(oValue.get()); - else - // Defaults from the spec: left/right: 91440 EMU, top/bottom: 45720 EMU - oInsets[i] = (aInsets[i] == XML_lIns || aInsets[i] == XML_rIns) ? 254 : 127; + drawing::TextVerticalAdjust eAdjust + = drawingml::GetTextVerticalAdjust(rAttribs.getToken(XML_anchor, XML_t)); + xPropertySet->setPropertyValue("TextVerticalAdjust", uno::makeAny(eAdjust)); } - const OUString aShapeProps[] = { OUString("TextLeftDistance"), OUString("TextUpperDistance"), OUString("TextRightDistance"), OUString("TextLowerDistance") }; - for (std::size_t i = 0; i < SAL_N_ELEMENTS(aShapeProps); ++i) - if (oInsets[i]) - xPropertySet->setPropertyValue(aShapeProps[i], uno::makeAny(*oInsets[i])); - } - // Handle text vertical adjustment inside a text frame - if (rAttribs.hasAttribute(XML_anchor)) - { - drawing::TextVerticalAdjust eAdjust = drawingml::GetTextVerticalAdjust(rAttribs.getToken(XML_anchor, XML_t)); - xPropertySet->setPropertyValue("TextVerticalAdjust", uno::makeAny(eAdjust)); + // Apply character color of the shape to the shape's textbox. + uno::Reference<text::XText> xText(mxShape, uno::UNO_QUERY); + uno::Reference<text::XTextCursor> xTextCursor = xText->createTextCursor(); + xTextCursor->gotoStart(false); + xTextCursor->gotoEnd(true); + const uno::Reference<beans::XPropertyState> xPropertyState(xTextCursor, + uno::UNO_QUERY); + const beans::PropertyState ePropertyState + = xPropertyState->getPropertyState("CharColor"); + if (ePropertyState == beans::PropertyState_DEFAULT_VALUE) + { + uno::Reference<beans::XPropertySet> xTextBoxPropertySet(xTextCursor, + uno::UNO_QUERY); + xTextBoxPropertySet->setPropertyValue( + "CharColor", xPropertySet->getPropertyValue("CharColor")); + } + return this; } - - // Apply character color of the shape to the shape's textbox. - uno::Reference<text::XText> xText(mxShape, uno::UNO_QUERY); - uno::Reference<text::XTextCursor> xTextCursor = xText->createTextCursor(); - xTextCursor->gotoStart(false); - xTextCursor->gotoEnd(true); - const uno::Reference<beans::XPropertyState> xPropertyState(xTextCursor, uno::UNO_QUERY); - const beans::PropertyState ePropertyState = xPropertyState->getPropertyState("CharColor"); - if (ePropertyState == beans::PropertyState_DEFAULT_VALUE) + break; + case XML_noAutofit: + case XML_spAutoFit: + { + uno::Reference<lang::XServiceInfo> xServiceInfo(mxShape, uno::UNO_QUERY); + // We can't use oox::drawingml::TextBodyPropertiesContext here, as this + // is a child context of bodyPr, so the shape is already sent: we need + // to alter the XShape directly. + uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY); + if (xPropertySet.is()) { - uno::Reference<beans::XPropertySet> xTextBoxPropertySet(xTextCursor, uno::UNO_QUERY); - xTextBoxPropertySet->setPropertyValue("CharColor", xPropertySet->getPropertyValue("CharColor")); + if (xServiceInfo->supportsService("com.sun.star.text.TextFrame")) + xPropertySet->setPropertyValue( + "FrameIsAutomaticHeight", + uno::makeAny(getBaseToken(nElementToken) == XML_spAutoFit)); + else + xPropertySet->setPropertyValue( + "TextAutoGrowHeight", + uno::makeAny(getBaseToken(nElementToken) == XML_spAutoFit)); } - return this; } break; - case XML_noAutofit: - case XML_spAutoFit: - { - uno::Reference<lang::XServiceInfo> xServiceInfo(mxShape, uno::UNO_QUERY); - // We can't use oox::drawingml::TextBodyPropertiesContext here, as this - // is a child context of bodyPr, so the shape is already sent: we need - // to alter the XShape directly. - uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY); - if (xPropertySet.is()) - { - if (xServiceInfo->supportsService("com.sun.star.text.TextFrame")) - xPropertySet->setPropertyValue("FrameIsAutomaticHeight", uno::makeAny(getBaseToken(nElementToken) == XML_spAutoFit)); - else - xPropertySet->setPropertyValue("TextAutoGrowHeight", uno::makeAny(getBaseToken(nElementToken) == XML_spAutoFit)); - } - } - break; - case XML_prstTxWarp: - if (rAttribs.hasAttribute(XML_prst)) + case XML_prstTxWarp: + if (rAttribs.hasAttribute(XML_prst)) + { + uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY); + if (xPropertySet.is()) + { + oox::OptValue<OUString> presetShapeName = rAttribs.getString(XML_prst); + const OUString& preset = presetShapeName.get(); + comphelper::SequenceAsHashMap aCustomShapeGeometry( + xPropertySet->getPropertyValue("CustomShapeGeometry")); + aCustomShapeGeometry["PresetTextWarp"] <<= preset; + xPropertySet->setPropertyValue( + "CustomShapeGeometry", + uno::makeAny(aCustomShapeGeometry.getAsConstPropertyValueList())); + } + } + break; + case XML_txbx: { - uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY); - if (xPropertySet.is()) + mpShapePtr->getCustomShapeProperties()->setShapeTypeOverride(true); + mpShapePtr->setTextBox(true); + //in case if the textbox is linked, save the attributes + //for further processing. + if (rAttribs.hasAttribute(XML_id)) { - oox::OptValue<OUString> presetShapeName = rAttribs.getString(XML_prst); - const OUString& preset = presetShapeName.get(); - comphelper::SequenceAsHashMap aCustomShapeGeometry(xPropertySet->getPropertyValue("CustomShapeGeometry")); - aCustomShapeGeometry["PresetTextWarp"] <<= preset; - xPropertySet->setPropertyValue("CustomShapeGeometry", uno::makeAny(aCustomShapeGeometry.getAsConstPropertyValueList())); + OptValue<OUString> id = rAttribs.getString(XML_id); + if (id.has()) + { + oox::drawingml::LinkedTxbxAttr linkedTxtBoxAttr; + linkedTxtBoxAttr.id = id.get().toInt32(); + mpShapePtr->setTxbxHasLinkedTxtBox(true); + mpShapePtr->setLinkedTxbxAttributes(linkedTxtBoxAttr); + } } + return this; } break; - case XML_txbx: - { - mpShapePtr->getCustomShapeProperties()->setShapeTypeOverride(true); - mpShapePtr->setTextBox(true); - //in case if the textbox is linked, save the attributes - //for further processing. - if (rAttribs.hasAttribute(XML_id)) + case XML_linkedTxbx: { + //in case if the textbox is linked, save the attributes + //for further processing. + mpShapePtr->getCustomShapeProperties()->setShapeTypeOverride(true); + mpShapePtr->setTextBox(true); OptValue<OUString> id = rAttribs.getString(XML_id); - if (id.has()) + OptValue<OUString> seq = rAttribs.getString(XML_seq); + if (id.has() && seq.has()) { - oox::drawingml::LinkedTxbxAttr linkedTxtBoxAttr ; + oox::drawingml::LinkedTxbxAttr linkedTxtBoxAttr; linkedTxtBoxAttr.id = id.get().toInt32(); + linkedTxtBoxAttr.seq = seq.get().toInt32(); mpShapePtr->setTxbxHasLinkedTxtBox(true); mpShapePtr->setLinkedTxbxAttributes(linkedTxtBoxAttr); } } - return this; - } - break; - case XML_linkedTxbx: - { - //in case if the textbox is linked, save the attributes - //for further processing. - mpShapePtr->getCustomShapeProperties()->setShapeTypeOverride(true); - mpShapePtr->setTextBox(true); - OptValue<OUString> id = rAttribs.getString(XML_id); - OptValue<OUString> seq = rAttribs.getString(XML_seq); - if (id.has() && seq.has()) - { - oox::drawingml::LinkedTxbxAttr linkedTxtBoxAttr ; - linkedTxtBoxAttr.id = id.get().toInt32(); - linkedTxtBoxAttr.seq = seq.get().toInt32(); - mpShapePtr->setTxbxHasLinkedTxtBox(true); - mpShapePtr->setLinkedTxbxAttributes(linkedTxtBoxAttr); - } - } - break; - default: - return ShapeContext::onCreateContext(nElementToken, rAttribs); + break; + default: + return ShapeContext::onCreateContext(nElementToken, rAttribs); } return nullptr; } - } } diff --git a/oox/source/shape/WpsContext.hxx b/oox/source/shape/WpsContext.hxx index 45715606b874..c5a6565a58fc 100644 --- a/oox/source/shape/WpsContext.hxx +++ b/oox/source/shape/WpsContext.hxx @@ -32,23 +32,22 @@ namespace oox { namespace shape { - /// Wps is the drawingML equivalent of v:shape. class WpsContext final : public oox::drawingml::ShapeContext { public: WpsContext(oox::core::ContextHandler2Helper const& rParent, css::uno::Reference<css::drawing::XShape> xShape, - oox::drawingml::ShapePtr const & pMasterShapePtr, - oox::drawingml::ShapePtr const & pShapePtr); + oox::drawingml::ShapePtr const& pMasterShapePtr, + oox::drawingml::ShapePtr const& pShapePtr); ~WpsContext() override; - oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElementToken, const oox::AttributeList& rAttribs) override; + oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElementToken, + const oox::AttributeList& rAttribs) override; private: css::uno::Reference<css::drawing::XShape> mxShape; }; - } } |