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
24
25#include <xmloff/xmlimp.hxx>
26#include <xmloff/txtimp.hxx>
27#include <xmloff/xmluconv.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
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::drawing;
40using namespace ::com::sun::star::beans;
41using namespace ::com::sun::star::text;
42using namespace ::com::sun::star::container;
43using namespace ::com::sun::star::xml::sax;
44using namespace ::xmloff::token;
45
46constexpr OUStringLiteral gsAnchorType(u"AnchorType");
47constexpr OUStringLiteral gsAnchorPageNo(u"AnchorPageNo");
48constexpr 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();
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.toView() );
113 break;
114 }
115 }
116
117 Reference < XPropertySet > xPropSet( rShape, UNO_QUERY );
118
119 // anchor type
120 xPropSet->setPropertyValue( gsAnchorType, Any(eAnchorType) );
121
122 // page number must be set before the frame is inserted
123 switch( eAnchorType )
124 {
125 case TextContentAnchorType_AT_PAGE:
126 // only set positive page numbers
127 if ( nPage > 0 )
128 {
129 xPropSet->setPropertyValue( gsAnchorPageNo, Any(nPage) );
130 }
131 break;
132 default:
133 break;
134 }
135
136 Reference < XTextContent > xTxtCntnt( rShape, UNO_QUERY );
137 xTxtImport->InsertTextContent( xTxtCntnt );
138
139 switch( eAnchorType )
140 {
141 case TextContentAnchorType_AS_CHARACTER:
142 xPropSet->setPropertyValue( gsVertOrientPosition, Any(nY) );
143 break;
144 default:
145 break;
146 }
147}
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral gsAnchorType(u"AnchorType")
constexpr OUStringLiteral gsVertOrientPosition(u"VertOrientPosition")
constexpr OUStringLiteral gsAnchorPageNo(u"AnchorPageNo")
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlimp.hxx:400
const css::uno::Reference< css::frame::XModel > & GetModel() const
Definition: xmlimp.hxx:404
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
Definition: xmlimp.hxx:601
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:186
static bool convert(std::string_view rStrImpValue, css::text::TextContentAnchorType &rType)
Definition: txtprhdl.cxx:651
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...
void pushGroupForPostProcessing(css::uno::Reference< css::drawing::XShapes > &rShapes)
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...
XMLTextShapeImportHelper(SvXMLImport &rImp)
virtual ~XMLTextShapeImportHelper() override
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
@ XML_ANCHOR_PAGE_NUMBER
Definition: xmltoken.hxx:247
TEXT
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97