LCOV - code coverage report
Current view: top level - oox/source/shape - WpsContext.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 56 0.0 %
Date: 2014-04-14 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          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           0 : WpsContext::WpsContext(ContextHandler2Helper& rParent, uno::Reference<drawing::XShape> xShape)
      24             :     : ContextHandler2(rParent),
      25           0 :       mxShape(xShape)
      26             : {
      27           0 :     mpShape.reset(new oox::drawingml::Shape("com.sun.star.drawing.CustomShape"));
      28           0 :     mpShape->setWps(true);
      29           0 : }
      30             : 
      31           0 : WpsContext::~WpsContext()
      32             : {
      33           0 : }
      34             : 
      35           0 : oox::drawingml::ShapePtr WpsContext::getShape()
      36             : {
      37           0 :     return mpShape;
      38             : }
      39             : 
      40           0 : oox::core::ContextHandlerRef WpsContext::onCreateContext(sal_Int32 nElementToken, const oox::AttributeList& rAttribs)
      41             : {
      42           0 :     switch (getBaseToken(nElementToken))
      43             :     {
      44             :     case XML_wsp:
      45           0 :         break;
      46             :     case XML_cNvCnPr:
      47           0 :         break;
      48             :     case XML_cNvSpPr:
      49           0 :         break;
      50             :     case XML_spPr:
      51           0 :         return new oox::drawingml::ShapePropertiesContext(*this, *mpShape);
      52             :         break;
      53             :     case XML_style:
      54           0 :         return new oox::drawingml::ShapeStyleContext(*this, *mpShape);
      55             :         break;
      56             :     case XML_bodyPr:
      57           0 :         if (mxShape.is())
      58             :         {
      59           0 :             OptValue<OUString> oVert = rAttribs.getString(XML_vert);
      60           0 :             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           0 :                 uno::Reference<text::XText> xText(mxShape, uno::UNO_QUERY);
      64           0 :                 uno::Reference<text::XTextCursor> xTextCursor = xText->createTextCursor();
      65           0 :                 xTextCursor->gotoStart(false);
      66           0 :                 xTextCursor->gotoEnd(true);
      67           0 :                 uno::Reference<beans::XPropertyState> xPropertyState(xTextCursor, uno::UNO_QUERY);
      68           0 :                 beans::PropertyState aState = xPropertyState->getPropertyState("CharRotation");
      69           0 :                 if (aState == beans::PropertyState_DEFAULT_VALUE)
      70             :                 {
      71           0 :                     uno::Reference<beans::XPropertySet> xPropertySet(xTextCursor, uno::UNO_QUERY);
      72           0 :                     xPropertySet->setPropertyValue("CharRotation", uno::makeAny(sal_Int16(900)));
      73           0 :                 }
      74             :             }
      75             : 
      76             :             // Handle inset attributes for Writer textframes.
      77           0 :             sal_Int32 aInsets[] = { XML_lIns, XML_tIns, XML_rIns, XML_bIns };
      78           0 :             boost::optional<sal_Int32> oInsets[4];
      79           0 :             for (size_t i = 0; i < SAL_N_ELEMENTS(aInsets); ++i)
      80             :             {
      81           0 :                 OptValue<OUString> oValue = rAttribs.getString(aInsets[i]);
      82           0 :                 if (oValue.has())
      83           0 :                     oInsets[i] = oox::drawingml::GetCoordinate(oValue.get());
      84           0 :             }
      85           0 :             OUString aProps[] = { OUString("LeftBorderDistance"), OUString("TopBorderDistance"), OUString("RightBorderDistance"), OUString("BottomBorderDistance") };
      86           0 :             uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY);
      87           0 :             for (size_t i = 0; i < SAL_N_ELEMENTS(aProps); ++i)
      88           0 :                 if (oInsets[i])
      89           0 :                     xPropertySet->setPropertyValue(aProps[i], uno::makeAny(*oInsets[i]));
      90             : 
      91             :             // Handle text vertical adjustment inside a text frame
      92           0 :             if (rAttribs.hasAttribute(XML_anchor))
      93             :             {
      94           0 :                 drawing::TextVerticalAdjust eAdjust = drawingml::GetTextVerticalAdjust(rAttribs.getToken(XML_anchor, XML_t));
      95           0 :                 xPropertySet->setPropertyValue("TextVerticalAdjust", uno::makeAny(eAdjust));
      96             :             }
      97           0 :             return this;
      98             :         }
      99           0 :         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           0 :         uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY);
     107           0 :         if (xPropertySet.is())
     108           0 :             xPropertySet->setPropertyValue("FrameIsAutomaticHeight", uno::makeAny(getBaseToken(nElementToken) == XML_spAutoFit));
     109             :     }
     110           0 :     break;
     111             :     case XML_txbx:
     112           0 :         mpShape->getCustomShapeProperties()->setShapeTypeOverride(true);
     113           0 :         mpShape->setServiceName("com.sun.star.text.TextFrame");
     114           0 :         break;
     115             :     default:
     116             :         SAL_WARN("oox", "WpsContext::createFastChildContext: unhandled element: " << getBaseToken(nElementToken));
     117           0 :         break;
     118             :     }
     119           0 :     return 0;
     120             : }
     121             : 
     122             : }
     123           0 : }
     124             : 
     125             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10