xref: /AOO41X/main/oox/inc/oox/drawingml/textspacing.hxx (revision e35081216278e1848f1c12af2e117a766f306f4b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef OOX_DRAWINGNML__TEXTSPACING_HXX
25 #define OOX_DRAWINGNML__TEXTSPACING_HXX
26 
27 #include <rtl/ustring.hxx>
28 
29 #include <com/sun/star/style/LineSpacing.hpp>
30 #include <com/sun/star/style/LineSpacingMode.hpp>
31 
32 namespace oox { namespace drawingml {
33 
34 
35     /** carries a CT_TextSpacing */
36     class TextSpacing
37     {
38     public:
39         enum {
40             POINTS = 0,
41             PERCENT
42         };
TextSpacing()43         TextSpacing()
44             : nUnit( POINTS ), nValue( 0 ), bHasValue( sal_False )
45             {
46             }
TextSpacing(sal_Int32 nPoints)47         TextSpacing( sal_Int32 nPoints ) : nUnit( POINTS ), nValue( nPoints ), bHasValue( sal_True ){};
toLineSpacing() const48         ::com::sun::star::style::LineSpacing toLineSpacing() const
49             {
50                 ::com::sun::star::style::LineSpacing aSpacing;
51                 aSpacing.Mode = ( nUnit == PERCENT
52                                                     ? ::com::sun::star::style::LineSpacingMode::PROP
53                                                     :   ::com::sun::star::style::LineSpacingMode::MINIMUM );
54                 aSpacing.Height = static_cast< sal_Int16 >( nUnit == PERCENT ? nValue / 1000 :  nValue );
55                 return aSpacing;
56             }
toMargin(float fFontSize) const57         sal_Int32 toMargin( float fFontSize ) const
58             {
59                 if ( nUnit == PERCENT )
60                 {
61                     double fMargin = ( fFontSize * 2540 + 36 ) / 72;
62                     fMargin *= nValue;
63                     fMargin /= 100000;
64                     return static_cast< sal_Int32 >( fMargin );
65                 }
66                 else
67                     return nValue;
68             }
69         sal_Int32 nUnit;
70         sal_Int32 nValue;
71         sal_Bool  bHasValue;
72     };
73 
74 } }
75 
76 #endif
77 
78