xref: /trunk/main/xmloff/source/style/chrhghdl.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 
31 
32 #include <chrhghdl.hxx>
33 #include <xmloff/xmluconv.hxx>
34 #include "xmlehelp.hxx"
35 #include <rtl/ustrbuf.hxx>
36 #include <com/sun/star/uno/Any.hxx>
37 
38 using ::rtl::OUString;
39 using ::rtl::OUStringBuffer;
40 
41 using namespace ::com::sun::star;
42 
43 // this is a copy of defines in svx/inc/escpitem.hxx
44 #define DFLT_ESC_PROP    58
45 #define DFLT_ESC_AUTO_SUPER 101
46 #define DFLT_ESC_AUTO_SUB  -101
47 
48 ///////////////////////////////////////////////////////////////////////////////
49 //
50 // class XMLEscapementPropHdl
51 //
52 
53 XMLCharHeightHdl::~XMLCharHeightHdl()
54 {
55     // nothing to do
56 }
57 
58 sal_Bool XMLCharHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
59 {
60     double fSize;
61 
62     if( rStrImpValue.indexOf( sal_Unicode('%') ) == -1 )
63     {
64         MapUnit eSrcUnit = SvXMLExportHelper::GetUnitFromString( rStrImpValue, MAP_POINT );
65         if( SvXMLUnitConverter::convertDouble( fSize, rStrImpValue, eSrcUnit, MAP_POINT ))
66         {
67             rValue <<= (float)fSize;
68             return sal_True;
69         }
70     }
71 
72     return sal_False;
73 }
74 
75 sal_Bool XMLCharHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
76 {
77     OUStringBuffer aOut;
78 
79     float fSize = 0;
80     if( rValue >>= fSize )
81     {
82         SvXMLUnitConverter::convertDouble( aOut, (double)fSize, sal_True, MAP_POINT, MAP_POINT );
83         aOut.append( sal_Unicode('p'));
84         aOut.append( sal_Unicode('t'));
85     }
86 
87     rStrExpValue = aOut.makeStringAndClear();
88     return rStrExpValue.getLength() != 0;
89 }
90 
91 ///////////////////////////////////////////////////////////////////////////////
92 //
93 // class XMLEscapementHeightPropHdl
94 //
95 
96 XMLCharHeightPropHdl::~XMLCharHeightPropHdl()
97 {
98     // nothing to do
99 }
100 
101 sal_Bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
102 {
103     sal_Int32 nPrc = 100;
104 
105     if( rStrImpValue.indexOf( sal_Unicode('%') ) != -1 )
106     {
107         if( SvXMLUnitConverter::convertPercent( nPrc, rStrImpValue ) )
108         {
109             rValue <<= (sal_Int16)nPrc;
110             return sal_True;
111         }
112     }
113 
114     return sal_False;
115 }
116 
117 sal_Bool XMLCharHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
118 {
119     OUStringBuffer aOut( rStrExpValue );
120 
121     sal_Int16 nValue = sal_Int16();
122     if( rValue >>= nValue )
123     {
124         SvXMLUnitConverter::convertPercent( aOut, nValue );
125     }
126 
127     rStrExpValue = aOut.makeStringAndClear();
128     return rStrExpValue.getLength() != 0;
129 }
130 
131 ///////////////////////////////////////////////////////////////////////////////
132 //
133 // class XMLEscapementPropHdl
134 //
135 
136 XMLCharHeightDiffHdl::~XMLCharHeightDiffHdl()
137 {
138     // nothing to do
139 }
140 
141 sal_Bool XMLCharHeightDiffHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
142 {
143     sal_Int32 nRel = 0;
144 
145     if( SvXMLUnitConverter::convertMeasure( nRel, rStrImpValue, MAP_POINT ) )
146     {
147         rValue <<= (float)nRel;
148         return sal_True;
149     }
150 
151     return sal_False;
152 }
153 
154 sal_Bool XMLCharHeightDiffHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
155 {
156     OUStringBuffer aOut;
157 
158     float nRel = 0;
159     if( (rValue >>= nRel) && (nRel != 0) )
160     {
161         SvXMLUnitConverter::convertMeasure( aOut, (sal_Int32)nRel, MAP_POINT, MAP_POINT );
162         rStrExpValue = aOut.makeStringAndClear();
163     }
164 
165     return rStrExpValue.getLength() != 0;
166 }
167 
168