LibreOffice Module xmloff (master) 1
XMLClipPropertyHandler.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
27
28using namespace ::com::sun::star;
29using namespace ::com::sun::star::uno;
30using namespace ::com::sun::star::text;
31using namespace ::xmloff::token;
32
33
34
35
37 m_bODF11( bODF11 )
38{
39}
40
42{
43 // nothing to do
44}
45
47 const Any& r1,
48 const Any& r2 ) const
49{
50 GraphicCrop aCrop1, aCrop2;
51 r1 >>= aCrop1;
52 r2 >>= aCrop2;
53
54 return aCrop1.Top == aCrop2.Top &&
55 aCrop1.Bottom == aCrop2.Bottom &&
56 aCrop1.Left == aCrop2.Left &&
57 aCrop1.Right == aCrop2.Right;
58}
59
60bool XMLClipPropertyHandler::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
61{
62 bool bRet = false;
63 sal_Int32 nLen = rStrImpValue.getLength();
64 if( nLen > 6 &&
65 rStrImpValue.startsWith( GetXMLToken(XML_RECT)) &&
66 rStrImpValue[4] == '(' &&
67 rStrImpValue[nLen-1] == ')' )
68 {
69 GraphicCrop aCrop;
70 OUString sTmp( rStrImpValue.copy( 5, nLen-6 ) );
71
72 bool bHasComma = sTmp.indexOf( ',' ) != -1;
73 SvXMLTokenEnumerator aTokenEnum( sTmp, bHasComma ? ',' : ' ' );
74
75 sal_uInt16 nPos = 0;
76 std::u16string_view aToken;
77 while( aTokenEnum.getNextToken( aToken ) )
78 {
79 sal_Int32 nVal = 0;
80 if( !IsXMLToken(aToken, XML_AUTO) &&
81 !rUnitConverter.convertMeasureToCore( nVal, aToken ) )
82 break;
83
84 // fdo#80009 such nonsense could be written via WW8 import fdo#77454
85 if (abs(nVal) > 400000)
86 {
87 SAL_INFO("xmloff.style", "ignoring excessive clip " << OUString(aToken));
88 nVal = 0;
89 }
90
91 switch( nPos )
92 {
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;
97 }
98 nPos++;
99 }
100
101 bRet = (4 == nPos );
102 if( bRet )
103 rValue <<= aCrop;
104 }
105
106 return bRet;
107}
108
109bool XMLClipPropertyHandler::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
110{
111 bool bRet = false;
112 OUStringBuffer aOut(30);
113 GraphicCrop aCrop;
114
115 if( rValue >>= aCrop )
116 {
117 aOut.append( GetXMLToken(XML_RECT) + "(" );
118 rUnitConverter.convertMeasureToXML( aOut, aCrop.Top );
119 if( !m_bODF11 )
120 aOut.append( ',' );
121 aOut.append( ' ' );
122 rUnitConverter.convertMeasureToXML( aOut, aCrop.Right );
123 if( !m_bODF11 )
124 aOut.append( ',' );
125 aOut.append( ' ' );
126 rUnitConverter.convertMeasureToXML( aOut, aCrop.Bottom );
127 if( !m_bODF11 )
128 aOut.append( ',' );
129 aOut.append( ' ' );
130 rUnitConverter.convertMeasureToXML( aOut, aCrop.Left );
131 aOut.append( ')' );
132 rStrExpValue = aOut.makeStringAndClear();
133
134 bRet = true;
135 }
136
137 return bRet;
138}
139
140/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool getNextToken(std::u16string_view &rToken)
Definition: xmluconv.cxx:529
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:83
bool convertMeasureToCore(sal_Int32 &rValue, std::u16string_view rString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32) const
convert string to measure with meCoreMeasureUnit, using optional min and max values
Definition: xmluconv.cxx:188
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
convert measure to string: from meCoreMeasureUnit to meXMLMeasureUnit
Definition: xmluconv.cxx:208
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
virtual ~XMLClipPropertyHandler() override
virtual bool equals(const css::uno::Any &r1, const css::uno::Any &r2) const override
Compares two Any's in case of the given XML-data-type.
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
sal_uInt16 nPos
#define SAL_INFO(area, stream)
Handling of tokens in XML:
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3541
SwNodeOffset abs(const SwNodeOffset &a)