LibreOffice Module xmloff (master)  1
XMLTextShapeImportHelper.cxx
Go to the documentation of this file.
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  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <com/sun/star/text/XTextContent.hpp>
21 #include <com/sun/star/text/TextContentAnchorType.hpp>
22 
23 #include <sax/tools/converter.hxx>
24 
25 #include <xmloff/xmlimp.hxx>
26 #include <xmloff/txtimp.hxx>
27 #include <xmloff/xmluconv.hxx>
28 #include <xmloff/namespacemap.hxx>
29 #include "XMLAnchorTypePropHdl.hxx"
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
32 #include <com/sun/star/drawing/XShapes.hpp>
33 #include <com/sun/star/frame/XModel.hpp>
35 
36 
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::drawing;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::text;
41 using namespace ::com::sun::star::container;
42 using namespace ::com::sun::star::xml::sax;
43 
44 const OUStringLiteral gsAnchorType(u"AnchorType");
45 const OUStringLiteral gsAnchorPageNo(u"AnchorPageNo");
46 const OUStringLiteral gsVertOrientPosition(u"VertOrientPosition");
47 
49  SvXMLImport& rImp ) :
50  XMLShapeImportHelper( rImp, rImp.GetModel(),
51  XMLTextImportHelper::CreateShapeExtPropMapper(rImp) ),
52  rImport( rImp )
53 {
54  Reference < XDrawPageSupplier > xDPS( rImp.GetModel(), UNO_QUERY );
55  if( xDPS.is() )
56  {
57  Reference < XShapes > xShapes = xDPS->getDrawPage();
58  pushGroupForPostProcessing( xShapes );
59  }
60 
61 }
62 
64 {
66 }
67 
69  Reference< XShape >& rShape,
70  const Reference< XAttributeList >& xAttrList,
71  Reference< XShapes >& rShapes )
72 {
73  if( rShapes.is() )
74  {
75  // It's a group shape or 3DScene , so we have to call the base class method.
76  XMLShapeImportHelper::addShape( rShape, xAttrList, rShapes );
77  return;
78  }
79 
80  TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
81  sal_Int16 nPage = 0;
82  sal_Int32 nY = 0;
83 
86  const SvXMLTokenMap& rTokenMap =
87  xTxtImport->GetTextFrameAttrTokenMap();
88 
89  sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
90  for( sal_Int16 i=0; i < nAttrCount; i++ )
91  {
92  const OUString& rAttrName = xAttrList->getNameByIndex( i );
93  const OUString& rValue = xAttrList->getValueByIndex( i );
94 
95  OUString aLocalName;
96  sal_uInt16 nPrefix =
98  &aLocalName );
99  switch( rTokenMap.Get( nPrefix, aLocalName ) )
100  {
102  {
103  TextContentAnchorType eNew;
104  // OD 2004-06-01 #i26791# - allow all anchor types
105  if ( XMLAnchorTypePropHdl::convert( rValue, eNew ) )
106  {
107  eAnchorType = eNew;
108  }
109  }
110  break;
112  {
113  sal_Int32 nTmp;
114  if (::sax::Converter::convertNumber(nTmp, rValue, 1, SHRT_MAX))
115  nPage = static_cast<sal_Int16>(nTmp);
116  }
117  break;
120  break;
121  }
122  }
123 
124  Reference < XPropertySet > xPropSet( rShape, UNO_QUERY );
125 
126  // anchor type
127  xPropSet->setPropertyValue( gsAnchorType, Any(eAnchorType) );
128 
129  Reference < XTextContent > xTxtCntnt( rShape, UNO_QUERY );
130  xTxtImport->InsertTextContent( xTxtCntnt );
131 
132  // page number (must be set after the frame is inserted, because it
133  // will be overwritten then inserting the frame.
134  switch( eAnchorType )
135  {
136  case TextContentAnchorType_AT_PAGE:
137  // only set positive page numbers
138  if ( nPage > 0 )
139  {
140  xPropSet->setPropertyValue( gsAnchorPageNo, Any(nPage) );
141  }
142  break;
143  case TextContentAnchorType_AS_CHARACTER:
144  xPropSet->setPropertyValue( gsVertOrientPosition, Any(nY) );
145  break;
146  default:
147  break;
148  }
149 }
150 
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~XMLTextShapeImportHelper() override
const OUStringLiteral gsVertOrientPosition(u"VertOrientPosition")
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:402
static bool convert(const OUString &rStrImpValue, css::text::TextContentAnchorType &rType)
Definition: txtprhdl.cxx:632
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
Definition: xmlimp.hxx:600
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
void pushGroupForPostProcessing(css::uno::Reference< css::drawing::XShapes > &rShapes)
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
bool convertMeasureToCore(sal_Int32 &rValue, const OUString &rString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32) const
convert string to measure with meCoreMeasureUnit, using optional min and max values ...
Definition: xmluconv.cxx:171
XMLTextShapeImportHelper(SvXMLImport &rImp)
virtual void addShape(css::uno::Reference< css::drawing::XShape > &rShape, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > &rShapes)
this function is called whenever the implementation classes like to add this new shape to the given X...
int i
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:99
const OUStringLiteral gsAnchorType(u"AnchorType")
virtual void addShape(css::uno::Reference< css::drawing::XShape > &rShape, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > &rShapes) override
this function is called whenever the implementation classes like to add this new shape to the given X...
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlimp.hxx:404
const css::uno::Reference< css::frame::XModel > & GetModel() const
Definition: xmlimp.hxx:408
const OUStringLiteral gsAnchorPageNo(u"AnchorPageNo")
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)