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 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmluconv.hxx>
28 #include <rtl/ustrbuf.hxx>
29 #include <com/sun/star/uno/Any.hxx>
30 #include "XMLBitmapRepeatOffsetPropertyHandler.hxx"
31
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using ::rtl::OUString;
35 using ::rtl::OUStringBuffer;
36
37
38 using ::xmloff::token::GetXMLToken;
39 using ::xmloff::token::XML_VERTICAL;
40 using ::xmloff::token::XML_HORIZONTAL;
41
42
XMLBitmapRepeatOffsetPropertyHandler(sal_Bool bX)43 XMLBitmapRepeatOffsetPropertyHandler::XMLBitmapRepeatOffsetPropertyHandler( sal_Bool bX )
44 : mbX( bX ),
45 msVertical( GetXMLToken(XML_VERTICAL) ),
46 msHorizontal( GetXMLToken(XML_HORIZONTAL) )
47 {
48 }
49
~XMLBitmapRepeatOffsetPropertyHandler()50 XMLBitmapRepeatOffsetPropertyHandler::~XMLBitmapRepeatOffsetPropertyHandler()
51 {
52 }
53
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter &) const54 sal_Bool XMLBitmapRepeatOffsetPropertyHandler::importXML(
55 const OUString& rStrImpValue,
56 Any& rValue,
57 const SvXMLUnitConverter& ) const
58 {
59 SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
60 OUString aToken;
61 if( aTokenEnum.getNextToken( aToken ) )
62 {
63 sal_Int32 nValue;
64 if( SvXMLUnitConverter::convertPercent( nValue, aToken ) )
65 {
66 if( aTokenEnum.getNextToken( aToken ) )
67 {
68 if( ( mbX && ( aToken == msHorizontal ) ) || ( !mbX && ( aToken == msVertical ) ) )
69 {
70 rValue <<= nValue;
71 return sal_True;
72 }
73 }
74 }
75 }
76
77 return sal_False;
78
79 }
80
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter &) const81 sal_Bool XMLBitmapRepeatOffsetPropertyHandler::exportXML(
82 OUString& rStrExpValue,
83 const Any& rValue,
84 const SvXMLUnitConverter& ) const
85 {
86 OUStringBuffer aOut;
87
88 sal_Int32 nValue = 0;
89 if( rValue >>= nValue )
90 {
91 SvXMLUnitConverter::convertPercent( aOut, nValue );
92 aOut.append( sal_Unicode( ' ' ) );
93 aOut.append( mbX ? msHorizontal : msVertical );
94 rStrExpValue = aOut.makeStringAndClear();
95
96 return sal_True;
97 }
98
99 return sal_False;
100 }
101
102