Line data Source code
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 :
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>
26 :
27 : using namespace ::com::sun::star;
28 : using namespace ::com::sun::star::uno;
29 : using namespace ::com::sun::star::text;
30 : using namespace ::xmloff::token;
31 :
32 :
33 : // class XMLMeasurePropHdl
34 :
35 :
36 9020 : XMLClipPropertyHandler::XMLClipPropertyHandler( bool bODF11 ) :
37 9020 : m_bODF11( bODF11 )
38 : {
39 9020 : }
40 :
41 18004 : XMLClipPropertyHandler::~XMLClipPropertyHandler()
42 : {
43 : // nothing to do
44 18004 : }
45 :
46 1 : bool XMLClipPropertyHandler::equals(
47 : const Any& r1,
48 : const Any& r2 ) const
49 : {
50 1 : GraphicCrop aCrop1, aCrop2;
51 1 : r1 >>= aCrop1;
52 1 : r2 >>= aCrop2;
53 :
54 2 : return aCrop1.Top == aCrop2.Top &&
55 2 : aCrop1.Bottom == aCrop2.Bottom &&
56 3 : aCrop1.Left == aCrop2.Left &&
57 2 : aCrop1.Right == aCrop2.Right;
58 : }
59 :
60 19 : bool XMLClipPropertyHandler::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
61 : {
62 19 : bool bRet = false;
63 19 : sal_Int32 nLen = rStrImpValue.getLength();
64 38 : if( nLen > 6 &&
65 38 : rStrImpValue.startsWith( GetXMLToken(XML_RECT)) &&
66 57 : rStrImpValue[4] == '(' &&
67 19 : rStrImpValue[nLen-1] == ')' )
68 : {
69 19 : GraphicCrop aCrop;
70 19 : OUString sTmp( rStrImpValue.copy( 5, nLen-6 ) );
71 :
72 19 : bool bHasComma = sTmp.indexOf( ',' ) != -1;
73 19 : SvXMLTokenEnumerator aTokenEnum( sTmp, bHasComma ? ',' : ' ' );
74 :
75 19 : sal_uInt16 nPos = 0;
76 38 : OUString aToken;
77 114 : while( aTokenEnum.getNextToken( aToken ) )
78 : {
79 76 : sal_Int32 nVal = 0;
80 152 : if( !IsXMLToken(aToken, XML_AUTO) &&
81 76 : !rUnitConverter.convertMeasureToCore( nVal, aToken ) )
82 0 : break;
83 :
84 76 : switch( nPos )
85 : {
86 19 : case 0: aCrop.Top = nVal; break;
87 19 : case 1: aCrop.Right = nVal; break;
88 19 : case 2: aCrop.Bottom = nVal; break;
89 19 : case 3: aCrop.Left = nVal; break;
90 : }
91 76 : nPos++;
92 : }
93 :
94 19 : bRet = (4 == nPos );
95 19 : if( bRet )
96 38 : rValue <<= aCrop;
97 : }
98 :
99 19 : return bRet;
100 : }
101 :
102 1 : bool XMLClipPropertyHandler::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
103 : {
104 1 : bool bRet = false;
105 1 : OUStringBuffer aOut(30);
106 1 : GraphicCrop aCrop;
107 :
108 1 : if( rValue >>= aCrop )
109 : {
110 1 : aOut.append( GetXMLToken(XML_RECT) );
111 1 : aOut.append( '(' );
112 1 : rUnitConverter.convertMeasureToXML( aOut, aCrop.Top );
113 1 : if( !m_bODF11 )
114 1 : aOut.append( ',' );
115 1 : aOut.append( ' ' );
116 1 : rUnitConverter.convertMeasureToXML( aOut, aCrop.Right );
117 1 : if( !m_bODF11 )
118 1 : aOut.append( ',' );
119 1 : aOut.append( ' ' );
120 1 : rUnitConverter.convertMeasureToXML( aOut, aCrop.Bottom );
121 1 : if( !m_bODF11 )
122 1 : aOut.append( ',' );
123 1 : aOut.append( ' ' );
124 1 : rUnitConverter.convertMeasureToXML( aOut, aCrop.Left );
125 1 : aOut.append( ')' );
126 1 : rStrExpValue = aOut.makeStringAndClear();
127 :
128 1 : bRet = true;
129 : }
130 :
131 1 : return bRet;
132 : }
133 :
134 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|