xref: /AOO41X/main/xmloff/source/style/VisAreaContext.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 
27 
28 
29 
30 // INCLUDE ---------------------------------------------------------------
31 #include "xmloff/VisAreaContext.hxx"
32 #include <xmloff/xmltoken.hxx>
33 #include "xmloff/xmlnmspe.hxx"
34 #include <xmloff/nmspmap.hxx>
35 #include <xmloff/xmluconv.hxx>
36 #include <xmloff/xmlimp.hxx>
37 #include <tools/gen.hxx>
38 
39 using namespace com::sun::star;
40 using namespace ::xmloff::token;
41 
42 //------------------------------------------------------------------
43 
XMLVisAreaContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,Rectangle & rRect,const MapUnit aMapUnit)44 XMLVisAreaContext::XMLVisAreaContext( SvXMLImport& rImport,
45                                               sal_uInt16 nPrfx,
46                                               const rtl::OUString& rLName,
47                                             const uno::Reference<xml::sax::XAttributeList>& xAttrList,
48                                             Rectangle& rRect, const MapUnit aMapUnit ) :
49     SvXMLImportContext( rImport, nPrfx, rLName )
50 {
51     awt::Rectangle rAwtRect( rRect.getX(), rRect.getY(), rRect.getWidth(), rRect.getHeight() );
52     process( xAttrList, rAwtRect, (sal_Int16)aMapUnit );
53 
54     rRect.setX( rAwtRect.X );
55     rRect.setY( rAwtRect.Y );
56     rRect.setWidth( rAwtRect.Width );
57     rRect.setHeight( rAwtRect.Height );
58 }
59 
XMLVisAreaContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,::com::sun::star::awt::Rectangle & rRect,const sal_Int16 nMeasureUnit)60 XMLVisAreaContext::XMLVisAreaContext( SvXMLImport& rImport,
61                                          sal_uInt16 nPrfx,
62                                               const rtl::OUString& rLName,
63                                             const uno::Reference<xml::sax::XAttributeList>& xAttrList,
64                                             ::com::sun::star::awt::Rectangle& rRect, const sal_Int16 nMeasureUnit ) :
65     SvXMLImportContext( rImport, nPrfx, rLName )
66 {
67     process( xAttrList, rRect, nMeasureUnit );
68 }
69 
~XMLVisAreaContext()70 XMLVisAreaContext::~XMLVisAreaContext()
71 {
72 }
73 
process(const uno::Reference<xml::sax::XAttributeList> & xAttrList,awt::Rectangle & rRect,const sal_Int16 nMeasureUnit)74 void XMLVisAreaContext::process( const uno::Reference< xml::sax::XAttributeList>& xAttrList, awt::Rectangle& rRect, const sal_Int16 nMeasureUnit )
75 {
76     MapUnit aMapUnit = (MapUnit)nMeasureUnit;
77 
78     sal_Int32 nX(0);
79     sal_Int32 nY(0);
80     sal_Int32 nWidth(0);
81     sal_Int32 nHeight(0);
82     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
83     for( sal_Int16 i=0; i < nAttrCount; i++ )
84     {
85         rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
86         rtl::OUString aLocalName;
87         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
88                                             sAttrName, &aLocalName );
89         rtl::OUString sValue = xAttrList->getValueByIndex( i );
90 
91         if (nPrefix == XML_NAMESPACE_OFFICE)
92         {
93             if (IsXMLToken( aLocalName, XML_X ))
94             {
95                 SvXMLUnitConverter::convertMeasure(nX, sValue, aMapUnit);
96                 rRect.X = nX;
97             }
98             else if (IsXMLToken( aLocalName, XML_Y ))
99             {
100                 SvXMLUnitConverter::convertMeasure(nY, sValue, aMapUnit);
101                 rRect.Y = nY;
102             }
103             else if (IsXMLToken( aLocalName, XML_WIDTH ))
104             {
105                 SvXMLUnitConverter::convertMeasure(nWidth, sValue, aMapUnit);
106                 rRect.Width = nWidth;
107             }
108             else if (IsXMLToken( aLocalName, XML_HEIGHT ))
109             {
110                 SvXMLUnitConverter::convertMeasure(nHeight, sValue, aMapUnit);
111                 rRect.Height = nHeight;
112             }
113         }
114     }
115 }
116 
CreateChildContext(sal_uInt16 nPrefix,const rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)117 SvXMLImportContext *XMLVisAreaContext::CreateChildContext( sal_uInt16 nPrefix,
118                                      const rtl::OUString& rLocalName,
119                                      const ::com::sun::star::uno::Reference<
120                                         ::com::sun::star::xml::sax::XAttributeList>& )
121 {
122     // here is no context
123     SvXMLImportContext *pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
124 
125     return pContext;
126 }
127 
EndElement()128 void XMLVisAreaContext::EndElement()
129 {
130 }
131