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 : * 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/nmspmap.hxx>
29 : #include "XMLAnchorTypePropHdl.hxx"
30 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
31 : #include <com/sun/star/drawing/XShapes.hpp>
32 : #include "xmloff/XMLTextShapeImportHelper.hxx"
33 :
34 : using ::rtl::OUString;
35 : using ::rtl::OUStringBuffer;
36 :
37 : using namespace ::com::sun::star::uno;
38 : using namespace ::com::sun::star::frame;
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 :
45 34 : XMLTextShapeImportHelper::XMLTextShapeImportHelper(
46 : SvXMLImport& rImp ) :
47 34 : XMLShapeImportHelper( rImp, rImp.GetModel(),
48 : XMLTextImportHelper::CreateShapeExtPropMapper(rImp) ),
49 : rImport( rImp ),
50 : sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType")),
51 : sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo")),
52 68 : sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition"))
53 : {
54 34 : Reference < XDrawPageSupplier > xDPS( rImp.GetModel(), UNO_QUERY );
55 34 : if( xDPS.is() )
56 : {
57 34 : Reference < XShapes > xShapes( xDPS->getDrawPage(), UNO_QUERY );
58 34 : pushGroupForSorting( xShapes );
59 34 : }
60 :
61 34 : }
62 :
63 68 : XMLTextShapeImportHelper::~XMLTextShapeImportHelper()
64 : {
65 34 : popGroupAndSort();
66 34 : }
67 :
68 1 : void XMLTextShapeImportHelper::addShape(
69 : Reference< XShape >& rShape,
70 : const Reference< XAttributeList >& xAttrList,
71 : Reference< XShapes >& rShapes )
72 : {
73 1 : if( rShapes.is() )
74 : {
75 : // It's a group shape or 3DScene , so we have to call the base class method.
76 0 : XMLShapeImportHelper::addShape( rShape, xAttrList, rShapes );
77 1 : return;
78 : }
79 :
80 1 : TextContentAnchorType eAnchorType = TextContentAnchorType_AT_PARAGRAPH;
81 1 : sal_Int16 nPage = 0;
82 1 : sal_Int32 nY = 0;
83 :
84 : UniReference < XMLTextImportHelper > xTxtImport =
85 1 : rImport.GetTextImport();
86 : const SvXMLTokenMap& rTokenMap =
87 1 : xTxtImport->GetTextFrameAttrTokenMap();
88 :
89 1 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
90 9 : for( sal_Int16 i=0; i < nAttrCount; i++ )
91 : {
92 8 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
93 8 : const OUString& rValue = xAttrList->getValueByIndex( i );
94 :
95 8 : OUString aLocalName;
96 : sal_uInt16 nPrefix =
97 8 : rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName,
98 8 : &aLocalName );
99 8 : switch( rTokenMap.Get( nPrefix, aLocalName ) )
100 : {
101 : case XML_TOK_TEXT_FRAME_ANCHOR_TYPE:
102 : {
103 : TextContentAnchorType eNew;
104 : // OD 2004-06-01 #i26791# - allow all anchor types
105 1 : if ( XMLAnchorTypePropHdl::convert( rValue, eNew ) )
106 : {
107 1 : eAnchorType = eNew;
108 : }
109 : }
110 1 : break;
111 : case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER:
112 : {
113 : sal_Int32 nTmp;
114 0 : if (::sax::Converter::convertNumber(nTmp, rValue, 1, SHRT_MAX))
115 0 : nPage = (sal_Int16)nTmp;
116 : }
117 0 : break;
118 : case XML_TOK_TEXT_FRAME_Y:
119 1 : rImport.GetMM100UnitConverter().convertMeasureToCore( nY, rValue );
120 1 : break;
121 : }
122 8 : }
123 :
124 1 : Reference < XPropertySet > xPropSet( rShape, UNO_QUERY );
125 1 : Any aAny;
126 :
127 : // anchor type
128 1 : aAny <<= eAnchorType;
129 1 : xPropSet->setPropertyValue( sAnchorType, aAny );
130 :
131 1 : Reference < XTextContent > xTxtCntnt( rShape, UNO_QUERY );
132 1 : xTxtImport->InsertTextContent( xTxtCntnt );
133 :
134 : // page number (must be set after the frame is inserted, because it
135 : // will be overwritten then inserting the frame.
136 1 : switch( eAnchorType )
137 : {
138 : case TextContentAnchorType_AT_PAGE:
139 : // only set positive page numbers
140 0 : if ( nPage > 0 )
141 : {
142 0 : aAny <<= nPage;
143 0 : xPropSet->setPropertyValue( sAnchorPageNo, aAny );
144 : }
145 0 : break;
146 : case TextContentAnchorType_AS_CHARACTER:
147 0 : aAny <<= nY;
148 0 : xPropSet->setPropertyValue( sVertOrientPosition, aAny );
149 0 : break;
150 : default:
151 1 : break;
152 1 : }
153 : }
154 :
155 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|