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 #ifndef OOX_DRAWINGNML__TEXTSPACING_HXX 29 #define OOX_DRAWINGNML__TEXTSPACING_HXX 30 31 #include <rtl/ustring.hxx> 32 33 #include <com/sun/star/style/LineSpacing.hpp> 34 #include <com/sun/star/style/LineSpacingMode.hpp> 35 36 namespace oox { namespace drawingml { 37 38 39 /** carries a CT_TextSpacing */ 40 class TextSpacing 41 { 42 public: 43 enum { 44 POINTS = 0, 45 PERCENT 46 }; 47 TextSpacing() 48 : nUnit( POINTS ), nValue( 0 ), bHasValue( sal_False ) 49 { 50 } 51 TextSpacing( sal_Int32 nPoints ) : nUnit( POINTS ), nValue( nPoints ), bHasValue( sal_True ){}; 52 ::com::sun::star::style::LineSpacing toLineSpacing() const 53 { 54 ::com::sun::star::style::LineSpacing aSpacing; 55 aSpacing.Mode = ( nUnit == PERCENT 56 ? ::com::sun::star::style::LineSpacingMode::PROP 57 : ::com::sun::star::style::LineSpacingMode::MINIMUM ); 58 aSpacing.Height = static_cast< sal_Int16 >( nUnit == PERCENT ? nValue / 1000 : nValue ); 59 return aSpacing; 60 } 61 sal_Int32 toMargin( float fFontSize ) const 62 { 63 if ( nUnit == PERCENT ) 64 { 65 double fMargin = ( fFontSize * 2540 + 36 ) / 72; 66 fMargin *= nValue; 67 fMargin /= 100000; 68 return static_cast< sal_Int32 >( fMargin ); 69 } 70 else 71 return nValue; 72 } 73 sal_Int32 nUnit; 74 sal_Int32 nValue; 75 sal_Bool bHasValue; 76 }; 77 78 } } 79 80 #endif 81 82