1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/log.hxx>
24 #include <com/sun/star/text/GraphicCrop.hpp>
25 #include <xmloff/xmluconv.hxx>
26 #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
;
36 XMLClipPropertyHandler::XMLClipPropertyHandler( bool bODF11
) :
41 XMLClipPropertyHandler::~XMLClipPropertyHandler()
46 bool XMLClipPropertyHandler::equals(
50 GraphicCrop aCrop1
, aCrop2
;
54 return aCrop1
.Top
== aCrop2
.Top
&&
55 aCrop1
.Bottom
== aCrop2
.Bottom
&&
56 aCrop1
.Left
== aCrop2
.Left
&&
57 aCrop1
.Right
== aCrop2
.Right
;
60 bool XMLClipPropertyHandler::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
63 sal_Int32 nLen
= rStrImpValue
.getLength();
65 rStrImpValue
.startsWith( GetXMLToken(XML_RECT
)) &&
66 rStrImpValue
[4] == '(' &&
67 rStrImpValue
[nLen
-1] == ')' )
70 OUString
sTmp( rStrImpValue
.copy( 5, nLen
-6 ) );
72 bool bHasComma
= sTmp
.indexOf( ',' ) != -1;
73 SvXMLTokenEnumerator
aTokenEnum( sTmp
, bHasComma
? ',' : ' ' );
76 std::u16string_view aToken
;
77 while( aTokenEnum
.getNextToken( aToken
) )
80 if( !IsXMLToken(aToken
, XML_AUTO
) &&
81 !rUnitConverter
.convertMeasureToCore( nVal
, aToken
) )
84 // fdo#80009 such nonsense could be written via WW8 import fdo#77454
85 if (abs(nVal
) > 400000)
87 SAL_INFO("xmloff.style", "ignoring excessive clip " << OUString(aToken
));
93 case 0: aCrop
.Top
= nVal
; break;
94 case 1: aCrop
.Right
= nVal
; break;
95 case 2: aCrop
.Bottom
= nVal
; break;
96 case 3: aCrop
.Left
= nVal
; break;
109 bool XMLClipPropertyHandler::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
112 OUStringBuffer
aOut(30);
115 if( rValue
>>= aCrop
)
117 aOut
.append( GetXMLToken(XML_RECT
) + "(" );
118 rUnitConverter
.convertMeasureToXML( aOut
, aCrop
.Top
);
122 rUnitConverter
.convertMeasureToXML( aOut
, aCrop
.Right
);
126 rUnitConverter
.convertMeasureToXML( aOut
, aCrop
.Bottom
);
130 rUnitConverter
.convertMeasureToXML( aOut
, aCrop
.Left
);
132 rStrExpValue
= aOut
.makeStringAndClear();
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */