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 <xmloff/xmlnamespace.hxx>
30 #include "XMLAnchorTypePropHdl.hxx"
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
33 #include <com/sun/star/drawing/XShapes.hpp>
34 #include <com/sun/star/frame/XModel.hpp>
36 
37 
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::drawing;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::text;
42 using namespace ::com::sun::star::container;
43 using namespace ::com::sun::star::xml::sax;
44 using namespace ::xmloff::token;
45 
46 constexpr OUStringLiteral gsAnchorType(u"AnchorType");
47 constexpr OUStringLiteral gsAnchorPageNo(u"AnchorPageNo");
48 constexpr OUStringLiteral gsVertOrientPosition(u"VertOrientPosition");
49 
51  SvXMLImport& rImp ) :
52  XMLShapeImportHelper( rImp, rImp.GetModel(),
53  XMLTextImportHelper::CreateShapeExtPropMapper(rImp) ),
54  rImport( rImp )
55 {
56  Reference < XDrawPageSupplier > xDPS( rImp.GetModel(), UNO_QUERY );
57  if( xDPS.is() )
58  {
59  Reference < XShapes > xShapes = xDPS->getDrawPage();
60  pushGroupForPostProcessing( xShapes );
61  }
62 
63 }
64 
66 {
68 }
69 
71  Reference< XShape >& rShape,
72  const Reference< XFastAttributeList >& xAttrList,
73  Reference< XShapes >& rShapes )
74 {
75  if( rShapes.is() )
76  {
77  // It's a group shape or 3DScene , so we have to call the base class method.
78  XMLShapeImportHelper::addShape( rShape, xAttrList, rShapes );
79  return;
80  }
81 
82  TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
83  sal_Int16 nPage = 0;
84  sal_Int32 nY = 0;
85 
88 
89  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
90  {
91  switch( aIter.getToken() )
92  {
94  {
95  TextContentAnchorType eNew;
96  // OD 2004-06-01 #i26791# - allow all anchor types
97  if ( XMLAnchorTypePropHdl::convert( aIter.toView(), eNew ) )
98  {
99  eAnchorType = eNew;
100  }
101  }
102  break;
104  {
105  sal_Int32 nTmp;
106  if (::sax::Converter::convertNumber(nTmp, aIter.toView(), 1, SHRT_MAX))
107  nPage = static_cast<sal_Int16>(nTmp);
108  }
109  break;
110  case XML_ELEMENT(SVG, XML_Y):
111  case XML_ELEMENT(SVG_COMPAT, XML_Y):
112  rImport.GetMM100UnitConverter().convertMeasureToCore( nY, aIter.toString() );
113  break;
114  }
115  }
116 
117  Reference < XPropertySet > xPropSet( rShape, UNO_QUERY );
118 
119  // anchor type
120  xPropSet->setPropertyValue( gsAnchorType, Any(eAnchorType) );
121 
122  Reference < XTextContent > xTxtCntnt( rShape, UNO_QUERY );
123  xTxtImport->InsertTextContent( xTxtCntnt );
124 
125  // page number (must be set after the frame is inserted, because it
126  // will be overwritten then inserting the frame.
127  switch( eAnchorType )
128  {
129  case TextContentAnchorType_AT_PAGE:
130  // only set positive page numbers
131  if ( nPage > 0 )
132  {
133  xPropSet->setPropertyValue( gsAnchorPageNo, Any(nPage) );
134  }
135  break;
136  case TextContentAnchorType_AS_CHARACTER:
137  xPropSet->setPropertyValue( gsVertOrientPosition, Any(nY) );
138  break;
139  default:
140  break;
141  }
142 }
143 
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral gsAnchorType(u"AnchorType")
virtual ~XMLTextShapeImportHelper() override
bool convertMeasureToCore(sal_Int32 &rValue, std::u16string_view 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
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
Definition: xmlimp.hxx:595
void pushGroupForPostProcessing(css::uno::Reference< css::drawing::XShapes > &rShapes)
XMLTextShapeImportHelper(SvXMLImport &rImp)
virtual void addShape(css::uno::Reference< css::drawing::XShape > &rShape, const css::uno::Reference< css::xml::sax::XFastAttributeList > &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...
static bool convert(std::string_view rStrImpValue, css::text::TextContentAnchorType &rType)
Definition: txtprhdl.cxx:634
constexpr OUStringLiteral gsAnchorPageNo(u"AnchorPageNo")
Handling of tokens in XML:
virtual void addShape(css::uno::Reference< css::drawing::XShape > &rShape, const css::uno::Reference< css::xml::sax::XFastAttributeList > &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...
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:96
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlimp.hxx:395
const css::uno::Reference< css::frame::XModel > & GetModel() const
Definition: xmlimp.hxx:399
constexpr OUStringLiteral gsVertOrientPosition(u"VertOrientPosition")
TEXT
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)