/src/libreoffice/xmloff/source/text/XMLTextShapeImportHelper.cxx
Line | Count | Source |
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 | | #include <comphelper/configuration.hxx> |
23 | | |
24 | | #include <sax/tools/converter.hxx> |
25 | | |
26 | | #include <xmloff/xmlimp.hxx> |
27 | | #include <xmloff/xmlimppr.hxx> |
28 | | #include <xmloff/txtimp.hxx> |
29 | | #include <xmloff/xmluconv.hxx> |
30 | | #include <xmloff/xmlnamespace.hxx> |
31 | | #include "XMLAnchorTypePropHdl.hxx" |
32 | | #include <com/sun/star/beans/XPropertySet.hpp> |
33 | | #include <com/sun/star/drawing/XDrawPageSupplier.hpp> |
34 | | #include <com/sun/star/drawing/XShapes.hpp> |
35 | | #include <com/sun/star/frame/XModel.hpp> |
36 | | #include <xmloff/XMLTextShapeImportHelper.hxx> |
37 | | |
38 | | |
39 | | using namespace ::com::sun::star::uno; |
40 | | using namespace ::com::sun::star::drawing; |
41 | | using namespace ::com::sun::star::beans; |
42 | | using namespace ::com::sun::star::text; |
43 | | using namespace ::com::sun::star::container; |
44 | | using namespace ::com::sun::star::xml::sax; |
45 | | using namespace ::xmloff::token; |
46 | | |
47 | | constexpr OUStringLiteral gsAnchorType(u"AnchorType"); |
48 | | constexpr OUStringLiteral gsAnchorPageNo(u"AnchorPageNo"); |
49 | | constexpr OUStringLiteral gsVertOrientPosition(u"VertOrientPosition"); |
50 | | |
51 | | XMLTextShapeImportHelper::XMLTextShapeImportHelper( |
52 | | SvXMLImport& rImp ) : |
53 | 9.28k | XMLShapeImportHelper( rImp, rImp.GetModel(), |
54 | 9.28k | XMLTextImportHelper::CreateShapeExtPropMapper(rImp) ), |
55 | 9.28k | m_rImport( rImp ) |
56 | 9.28k | { |
57 | 9.28k | Reference < XDrawPageSupplier > xDPS( rImp.GetModel(), UNO_QUERY ); |
58 | 9.28k | if( xDPS.is() ) |
59 | 9.28k | { |
60 | 9.28k | Reference < XShapes > xShapes = xDPS->getDrawPage(); |
61 | 9.28k | pushGroupForPostProcessing( xShapes ); |
62 | 9.28k | } |
63 | | |
64 | 9.28k | } |
65 | | |
66 | | XMLTextShapeImportHelper::~XMLTextShapeImportHelper() |
67 | 9.28k | { |
68 | 9.28k | popGroupAndPostProcess(); |
69 | 9.28k | } |
70 | | |
71 | | void XMLTextShapeImportHelper::addShape( |
72 | | Reference< XShape >& rShape, |
73 | | const Reference< XFastAttributeList >& xAttrList, |
74 | | Reference< XShapes >& rShapes ) |
75 | 5.97k | { |
76 | 5.97k | if( rShapes.is() ) |
77 | 0 | { |
78 | | // It's a group shape or 3DScene , so we have to call the base class method. |
79 | 0 | XMLShapeImportHelper::addShape( rShape, xAttrList, rShapes ); |
80 | 0 | return; |
81 | 0 | } |
82 | | |
83 | 5.97k | TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH; |
84 | 5.97k | sal_Int16 nPage = 0; |
85 | 5.97k | sal_Int32 nY = 0; |
86 | | |
87 | 5.97k | rtl::Reference < XMLTextImportHelper > xTxtImport = |
88 | 5.97k | m_rImport.GetTextImport(); |
89 | | |
90 | 5.97k | for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) |
91 | 19.9k | { |
92 | 19.9k | switch( aIter.getToken() ) |
93 | 19.9k | { |
94 | 3.30k | case XML_ELEMENT(TEXT, XML_ANCHOR_TYPE): |
95 | 3.30k | { |
96 | 3.30k | TextContentAnchorType eNew; |
97 | | // OD 2004-06-01 #i26791# - allow all anchor types |
98 | 3.30k | if ( XMLAnchorTypePropHdl::convert( aIter.toView(), eNew ) ) |
99 | 1.38k | { |
100 | 1.38k | eAnchorType = eNew; |
101 | 1.38k | } |
102 | 3.30k | } |
103 | 3.30k | break; |
104 | 2 | case XML_ELEMENT(TEXT, XML_ANCHOR_PAGE_NUMBER): |
105 | 2 | { |
106 | 2 | sal_Int32 nTmp; |
107 | 2 | sal_Int32 nMax = !comphelper::IsFuzzing() ? SHRT_MAX : 100; |
108 | 2 | if (::sax::Converter::convertNumber(nTmp, aIter.toView(), 1, nMax)) |
109 | 2 | nPage = static_cast<sal_Int16>(nTmp); |
110 | 2 | } |
111 | 2 | break; |
112 | 0 | case XML_ELEMENT(SVG, XML_Y): |
113 | 854 | case XML_ELEMENT(SVG_COMPAT, XML_Y): |
114 | 854 | m_rImport.GetMM100UnitConverter().convertMeasureToCore( nY, aIter.toView() ); |
115 | 854 | break; |
116 | 19.9k | } |
117 | 19.9k | } |
118 | | |
119 | 5.97k | Reference < XPropertySet > xPropSet( rShape, UNO_QUERY ); |
120 | | |
121 | | // anchor type |
122 | 5.97k | xPropSet->setPropertyValue( gsAnchorType, Any(eAnchorType) ); |
123 | | |
124 | | // page number must be set before the frame is inserted |
125 | 5.97k | switch( eAnchorType ) |
126 | 5.97k | { |
127 | 2 | case TextContentAnchorType_AT_PAGE: |
128 | | // only set positive page numbers |
129 | 2 | if ( nPage > 0 ) |
130 | 2 | { |
131 | 2 | xPropSet->setPropertyValue( gsAnchorPageNo, Any(nPage) ); |
132 | 2 | } |
133 | 2 | break; |
134 | 5.97k | default: |
135 | 5.97k | break; |
136 | 5.97k | } |
137 | | |
138 | 5.97k | Reference < XTextContent > xTxtCntnt( rShape, UNO_QUERY ); |
139 | 5.97k | xTxtImport->InsertTextContent( xTxtCntnt ); |
140 | | |
141 | 5.97k | switch( eAnchorType ) |
142 | 5.97k | { |
143 | 467 | case TextContentAnchorType_AS_CHARACTER: |
144 | 467 | xPropSet->setPropertyValue( gsVertOrientPosition, Any(nY) ); |
145 | 467 | break; |
146 | 3.59k | default: |
147 | 3.59k | break; |
148 | 5.97k | } |
149 | 5.97k | } |
150 | | |
151 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |