1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLClipPropertyHandler.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "XMLClipPropertyHandler.hxx"
34 #include <com/sun/star/uno/Any.hxx>
35 #include <rtl/ustrbuf.hxx>
36 #include <com/sun/star/text/GraphicCrop.hpp>
37 #include <xmloff/xmluconv.hxx>
38 #include <xmlkywd.hxx>
39 #include <xmloff/xmltoken.hxx>
41 using ::rtl::OUString
;
42 using ::rtl::OUStringBuffer
;
44 using namespace ::com::sun::star
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::text
;
47 using namespace ::xmloff::token
;
49 ///////////////////////////////////////////////////////////////////////////////
51 // class XMLMeasurePropHdl
54 XMLClipPropertyHandler::XMLClipPropertyHandler( sal_Bool bODF11
) :
59 XMLClipPropertyHandler::~XMLClipPropertyHandler()
64 bool XMLClipPropertyHandler::equals(
68 GraphicCrop aCrop1
, aCrop2
;
72 return aCrop1
.Top
== aCrop2
.Top
&&
73 aCrop1
.Bottom
== aCrop2
.Bottom
&&
74 aCrop1
.Left
== aCrop2
.Left
&&
75 aCrop1
.Right
== aCrop2
.Right
;
78 sal_Bool
XMLClipPropertyHandler::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
80 sal_Bool bRet
= sal_False
;
81 sal_Int32 nLen
= rStrImpValue
.getLength();
83 0 == rStrImpValue
.compareToAscii( sXML_rect
, 4 ) &&
84 rStrImpValue
[4] == '(' &&
85 rStrImpValue
[nLen
-1] == ')' )
88 OUString
sTmp( rStrImpValue
.copy( 5, nLen
-6 ) );
90 sal_Bool bHasComma
= sTmp
.indexOf( ',' ) != -1;
91 SvXMLTokenEnumerator
aTokenEnum( sTmp
, bHasComma
? ',' : ' ' );
95 while( aTokenEnum
.getNextToken( aToken
) )
98 if( !IsXMLToken(aToken
, XML_AUTO
) &&
99 !rUnitConverter
.convertMeasure( nVal
, aToken
) )
104 case 0: aCrop
.Top
= nVal
; break;
105 case 1: aCrop
.Right
= nVal
; break;
106 case 2: aCrop
.Bottom
= nVal
; break;
107 case 3: aCrop
.Left
= nVal
; break;
120 sal_Bool
XMLClipPropertyHandler::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
122 sal_Bool bRet
= sal_False
;
123 OUStringBuffer
aOut(30);
126 if( rValue
>>= aCrop
)
128 aOut
.append( GetXMLToken(XML_RECT
) );
129 aOut
.append( (sal_Unicode
)'(' );
130 rUnitConverter
.convertMeasure( aOut
, aCrop
.Top
);
132 aOut
.append( (sal_Unicode
)',' );
133 aOut
.append( (sal_Unicode
)' ' );
134 rUnitConverter
.convertMeasure( aOut
, aCrop
.Right
);
136 aOut
.append( (sal_Unicode
)',' );
137 aOut
.append( (sal_Unicode
)' ' );
138 rUnitConverter
.convertMeasure( aOut
, aCrop
.Bottom
);
140 aOut
.append( (sal_Unicode
)',' );
141 aOut
.append( (sal_Unicode
)' ' );
142 rUnitConverter
.convertMeasure( aOut
, aCrop
.Left
);
143 aOut
.append( (sal_Unicode
)')' );
144 rStrExpValue
= aOut
.makeStringAndClear();