1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10*63bba73cSAndrew Rist *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19*63bba73cSAndrew Rist *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include "XMLClipPropertyHandler.hxx"
27cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
28cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
29cdf0e10cSrcweir #include <com/sun/star/text/GraphicCrop.hpp>
30cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
31cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir using ::rtl::OUString;
34cdf0e10cSrcweir using ::rtl::OUStringBuffer;
35cdf0e10cSrcweir
36cdf0e10cSrcweir using namespace ::com::sun::star;
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir using namespace ::com::sun::star::text;
39cdf0e10cSrcweir using namespace ::xmloff::token;
40cdf0e10cSrcweir
41cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
42cdf0e10cSrcweir //
43cdf0e10cSrcweir // class XMLMeasurePropHdl
44cdf0e10cSrcweir //
45cdf0e10cSrcweir
XMLClipPropertyHandler(sal_Bool bODF11)46cdf0e10cSrcweir XMLClipPropertyHandler::XMLClipPropertyHandler( sal_Bool bODF11 ) :
47cdf0e10cSrcweir m_bODF11( bODF11 )
48cdf0e10cSrcweir {
49cdf0e10cSrcweir }
50cdf0e10cSrcweir
~XMLClipPropertyHandler()51cdf0e10cSrcweir XMLClipPropertyHandler::~XMLClipPropertyHandler()
52cdf0e10cSrcweir {
53cdf0e10cSrcweir // nothing to do
54cdf0e10cSrcweir }
55cdf0e10cSrcweir
equals(const Any & r1,const Any & r2) const56cdf0e10cSrcweir bool XMLClipPropertyHandler::equals(
57cdf0e10cSrcweir const Any& r1,
58cdf0e10cSrcweir const Any& r2 ) const
59cdf0e10cSrcweir {
60cdf0e10cSrcweir GraphicCrop aCrop1, aCrop2;
61cdf0e10cSrcweir r1 >>= aCrop1;
62cdf0e10cSrcweir r2 >>= aCrop2;
63cdf0e10cSrcweir
64cdf0e10cSrcweir return aCrop1.Top == aCrop2.Top &&
65cdf0e10cSrcweir aCrop1.Bottom == aCrop2.Bottom &&
66cdf0e10cSrcweir aCrop1.Left == aCrop2.Left &&
67cdf0e10cSrcweir aCrop1.Right == aCrop2.Right;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter & rUnitConverter) const70cdf0e10cSrcweir sal_Bool XMLClipPropertyHandler::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
71cdf0e10cSrcweir {
72cdf0e10cSrcweir sal_Bool bRet = sal_False;
73cdf0e10cSrcweir sal_Int32 nLen = rStrImpValue.getLength();
74cdf0e10cSrcweir if( nLen > 6 &&
75cdf0e10cSrcweir 0 == rStrImpValue.compareTo( GetXMLToken(XML_RECT), 4 ) &&
76cdf0e10cSrcweir rStrImpValue[4] == '(' &&
77cdf0e10cSrcweir rStrImpValue[nLen-1] == ')' )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir GraphicCrop aCrop;
80cdf0e10cSrcweir OUString sTmp( rStrImpValue.copy( 5, nLen-6 ) );
81cdf0e10cSrcweir
82cdf0e10cSrcweir sal_Bool bHasComma = sTmp.indexOf( ',' ) != -1;
83cdf0e10cSrcweir SvXMLTokenEnumerator aTokenEnum( sTmp, bHasComma ? ',' : ' ' );
84cdf0e10cSrcweir
85cdf0e10cSrcweir sal_uInt16 nPos = 0;
86cdf0e10cSrcweir OUString aToken;
87cdf0e10cSrcweir while( aTokenEnum.getNextToken( aToken ) )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir sal_Int32 nVal = 0;
90cdf0e10cSrcweir if( !IsXMLToken(aToken, XML_AUTO) &&
91cdf0e10cSrcweir !rUnitConverter.convertMeasure( nVal, aToken ) )
92cdf0e10cSrcweir break;
93cdf0e10cSrcweir
94cdf0e10cSrcweir switch( nPos )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir case 0: aCrop.Top = nVal; break;
97cdf0e10cSrcweir case 1: aCrop.Right = nVal; break;
98cdf0e10cSrcweir case 2: aCrop.Bottom = nVal; break;
99cdf0e10cSrcweir case 3: aCrop.Left = nVal; break;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir nPos++;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
104cdf0e10cSrcweir bRet = (4 == nPos );
105cdf0e10cSrcweir if( bRet )
106cdf0e10cSrcweir rValue <<= aCrop;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
109cdf0e10cSrcweir return bRet;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter & rUnitConverter) const112cdf0e10cSrcweir sal_Bool XMLClipPropertyHandler::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
113cdf0e10cSrcweir {
114cdf0e10cSrcweir sal_Bool bRet = sal_False;
115cdf0e10cSrcweir OUStringBuffer aOut(30);
116cdf0e10cSrcweir GraphicCrop aCrop;
117cdf0e10cSrcweir
118cdf0e10cSrcweir if( rValue >>= aCrop )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir aOut.append( GetXMLToken(XML_RECT) );
121cdf0e10cSrcweir aOut.append( (sal_Unicode)'(' );
122cdf0e10cSrcweir rUnitConverter.convertMeasure( aOut, aCrop.Top );
123cdf0e10cSrcweir if( !m_bODF11 )
124cdf0e10cSrcweir aOut.append( (sal_Unicode)',' );
125cdf0e10cSrcweir aOut.append( (sal_Unicode)' ' );
126cdf0e10cSrcweir rUnitConverter.convertMeasure( aOut, aCrop.Right );
127cdf0e10cSrcweir if( !m_bODF11 )
128cdf0e10cSrcweir aOut.append( (sal_Unicode)',' );
129cdf0e10cSrcweir aOut.append( (sal_Unicode)' ' );
130cdf0e10cSrcweir rUnitConverter.convertMeasure( aOut, aCrop.Bottom );
131cdf0e10cSrcweir if( !m_bODF11 )
132cdf0e10cSrcweir aOut.append( (sal_Unicode)',' );
133cdf0e10cSrcweir aOut.append( (sal_Unicode)' ' );
134cdf0e10cSrcweir rUnitConverter.convertMeasure( aOut, aCrop.Left );
135cdf0e10cSrcweir aOut.append( (sal_Unicode)')' );
136cdf0e10cSrcweir rStrExpValue = aOut.makeStringAndClear();
137cdf0e10cSrcweir
138cdf0e10cSrcweir bRet = sal_True;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141cdf0e10cSrcweir return bRet;
142cdf0e10cSrcweir }
143