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