Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "XMLClipPropertyHandler.hxx"
30 : : #include <com/sun/star/uno/Any.hxx>
31 : : #include <rtl/ustrbuf.hxx>
32 : : #include <com/sun/star/text/GraphicCrop.hpp>
33 : : #include <xmloff/xmluconv.hxx>
34 : : #include <xmloff/xmltoken.hxx>
35 : :
36 : : using ::rtl::OUString;
37 : : using ::rtl::OUStringBuffer;
38 : :
39 : : using namespace ::com::sun::star;
40 : : using namespace ::com::sun::star::uno;
41 : : using namespace ::com::sun::star::text;
42 : : using namespace ::xmloff::token;
43 : :
44 : : ///////////////////////////////////////////////////////////////////////////////
45 : : //
46 : : // class XMLMeasurePropHdl
47 : : //
48 : :
49 : 3012 : XMLClipPropertyHandler::XMLClipPropertyHandler( sal_Bool bODF11 ) :
50 : 3012 : m_bODF11( bODF11 )
51 : : {
52 : 3012 : }
53 : :
54 : 2992 : XMLClipPropertyHandler::~XMLClipPropertyHandler()
55 : : {
56 : : // nothing to do
57 [ - + ]: 5984 : }
58 : :
59 : 0 : bool XMLClipPropertyHandler::equals(
60 : : const Any& r1,
61 : : const Any& r2 ) const
62 : : {
63 : 0 : GraphicCrop aCrop1, aCrop2;
64 [ # # ]: 0 : r1 >>= aCrop1;
65 [ # # ]: 0 : r2 >>= aCrop2;
66 : :
67 : : return aCrop1.Top == aCrop2.Top &&
68 : : aCrop1.Bottom == aCrop2.Bottom &&
69 : : aCrop1.Left == aCrop2.Left &&
70 [ # # ][ # # ]: 0 : aCrop1.Right == aCrop2.Right;
[ # # ][ # # ]
71 : : }
72 : :
73 : 12 : sal_Bool XMLClipPropertyHandler::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
74 : : {
75 : 12 : sal_Bool bRet = sal_False;
76 : 12 : sal_Int32 nLen = rStrImpValue.getLength();
77 [ + - ][ + - : 48 : if( nLen > 6 &&
+ - + - +
- ]
78 : 12 : 0 == rStrImpValue.compareTo( GetXMLToken(XML_RECT), 4 ) &&
79 : 12 : rStrImpValue[4] == '(' &&
80 : 12 : rStrImpValue[nLen-1] == ')' )
81 : : {
82 : 12 : GraphicCrop aCrop;
83 : 12 : OUString sTmp( rStrImpValue.copy( 5, nLen-6 ) );
84 : :
85 : 12 : sal_Bool bHasComma = sTmp.indexOf( ',' ) != -1;
86 [ + - ][ + + ]: 12 : SvXMLTokenEnumerator aTokenEnum( sTmp, bHasComma ? ',' : ' ' );
87 : :
88 : 12 : sal_uInt16 nPos = 0;
89 : 12 : OUString aToken;
90 [ + - ][ + + ]: 60 : while( aTokenEnum.getNextToken( aToken ) )
91 : : {
92 : 48 : sal_Int32 nVal = 0;
93 [ + - ][ + - ]: 96 : if( !IsXMLToken(aToken, XML_AUTO) &&
[ - + ][ + - ]
94 [ + - ]: 48 : !rUnitConverter.convertMeasureToCore( nVal, aToken ) )
95 : : break;
96 : :
97 [ + + + + : 48 : switch( nPos )
- ]
98 : : {
99 : 12 : case 0: aCrop.Top = nVal; break;
100 : 12 : case 1: aCrop.Right = nVal; break;
101 : 12 : case 2: aCrop.Bottom = nVal; break;
102 : 12 : case 3: aCrop.Left = nVal; break;
103 : : }
104 : 48 : nPos++;
105 : : }
106 : :
107 : 12 : bRet = (4 == nPos );
108 [ + - ]: 12 : if( bRet )
109 [ + - ]: 12 : rValue <<= aCrop;
110 : : }
111 : :
112 : 12 : return bRet;
113 : : }
114 : :
115 : 0 : sal_Bool XMLClipPropertyHandler::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
116 : : {
117 : 0 : sal_Bool bRet = sal_False;
118 : 0 : OUStringBuffer aOut(30);
119 : 0 : GraphicCrop aCrop;
120 : :
121 [ # # ][ # # ]: 0 : if( rValue >>= aCrop )
122 : : {
123 [ # # ][ # # ]: 0 : aOut.append( GetXMLToken(XML_RECT) );
124 [ # # ]: 0 : aOut.append( (sal_Unicode)'(' );
125 [ # # ]: 0 : rUnitConverter.convertMeasureToXML( aOut, aCrop.Top );
126 [ # # ]: 0 : if( !m_bODF11 )
127 [ # # ]: 0 : aOut.append( (sal_Unicode)',' );
128 [ # # ]: 0 : aOut.append( (sal_Unicode)' ' );
129 [ # # ]: 0 : rUnitConverter.convertMeasureToXML( aOut, aCrop.Right );
130 [ # # ]: 0 : if( !m_bODF11 )
131 [ # # ]: 0 : aOut.append( (sal_Unicode)',' );
132 [ # # ]: 0 : aOut.append( (sal_Unicode)' ' );
133 [ # # ]: 0 : rUnitConverter.convertMeasureToXML( aOut, aCrop.Bottom );
134 [ # # ]: 0 : if( !m_bODF11 )
135 [ # # ]: 0 : aOut.append( (sal_Unicode)',' );
136 [ # # ]: 0 : aOut.append( (sal_Unicode)' ' );
137 [ # # ]: 0 : rUnitConverter.convertMeasureToXML( aOut, aCrop.Left );
138 [ # # ]: 0 : aOut.append( (sal_Unicode)')' );
139 [ # # ]: 0 : rStrExpValue = aOut.makeStringAndClear();
140 : :
141 : 0 : bRet = sal_True;
142 : : }
143 : :
144 : 0 : return bRet;
145 : : }
146 : :
147 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|