bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / style / XMLClipPropertyHandler.cxx
blobbdcc4fe0e8cc28ef7b759b91a345bf59b94d1154
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "XMLClipPropertyHandler.hxx"
21 #include <com/sun/star/uno/Any.hxx>
22 #include <rtl/ustrbuf.hxx>
23 #include <com/sun/star/text/GraphicCrop.hpp>
24 #include <xmloff/xmluconv.hxx>
25 #include <xmloff/xmltoken.hxx>
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::text;
31 using namespace ::xmloff::token;
33 ///////////////////////////////////////////////////////////////////////////////
35 // class XMLMeasurePropHdl
38 XMLClipPropertyHandler::XMLClipPropertyHandler( sal_Bool bODF11 ) :
39 m_bODF11( bODF11 )
43 XMLClipPropertyHandler::~XMLClipPropertyHandler()
45 // nothing to do
48 bool XMLClipPropertyHandler::equals(
49 const Any& r1,
50 const Any& r2 ) const
52 GraphicCrop aCrop1, aCrop2;
53 r1 >>= aCrop1;
54 r2 >>= aCrop2;
56 return aCrop1.Top == aCrop2.Top &&
57 aCrop1.Bottom == aCrop2.Bottom &&
58 aCrop1.Left == aCrop2.Left &&
59 aCrop1.Right == aCrop2.Right;
62 sal_Bool XMLClipPropertyHandler::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
64 sal_Bool bRet = sal_False;
65 sal_Int32 nLen = rStrImpValue.getLength();
66 if( nLen > 6 &&
67 rStrImpValue.startsWith( GetXMLToken(XML_RECT)) &&
68 rStrImpValue[4] == '(' &&
69 rStrImpValue[nLen-1] == ')' )
71 GraphicCrop aCrop;
72 OUString sTmp( rStrImpValue.copy( 5, nLen-6 ) );
74 sal_Bool bHasComma = sTmp.indexOf( ',' ) != -1;
75 SvXMLTokenEnumerator aTokenEnum( sTmp, bHasComma ? ',' : ' ' );
77 sal_uInt16 nPos = 0;
78 OUString aToken;
79 while( aTokenEnum.getNextToken( aToken ) )
81 sal_Int32 nVal = 0;
82 if( !IsXMLToken(aToken, XML_AUTO) &&
83 !rUnitConverter.convertMeasureToCore( nVal, aToken ) )
84 break;
86 switch( nPos )
88 case 0: aCrop.Top = nVal; break;
89 case 1: aCrop.Right = nVal; break;
90 case 2: aCrop.Bottom = nVal; break;
91 case 3: aCrop.Left = nVal; break;
93 nPos++;
96 bRet = (4 == nPos );
97 if( bRet )
98 rValue <<= aCrop;
101 return bRet;
104 sal_Bool XMLClipPropertyHandler::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
106 sal_Bool bRet = sal_False;
107 OUStringBuffer aOut(30);
108 GraphicCrop aCrop;
110 if( rValue >>= aCrop )
112 aOut.append( GetXMLToken(XML_RECT) );
113 aOut.append( (sal_Unicode)'(' );
114 rUnitConverter.convertMeasureToXML( aOut, aCrop.Top );
115 if( !m_bODF11 )
116 aOut.append( (sal_Unicode)',' );
117 aOut.append( (sal_Unicode)' ' );
118 rUnitConverter.convertMeasureToXML( aOut, aCrop.Right );
119 if( !m_bODF11 )
120 aOut.append( (sal_Unicode)',' );
121 aOut.append( (sal_Unicode)' ' );
122 rUnitConverter.convertMeasureToXML( aOut, aCrop.Bottom );
123 if( !m_bODF11 )
124 aOut.append( (sal_Unicode)',' );
125 aOut.append( (sal_Unicode)' ' );
126 rUnitConverter.convertMeasureToXML( aOut, aCrop.Left );
127 aOut.append( (sal_Unicode)')' );
128 rStrExpValue = aOut.makeStringAndClear();
130 bRet = sal_True;
133 return bRet;
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */