1 #include "vbafont.hxx" 2 #include <com/sun/star/awt/FontUnderline.hpp> 3 #include <ooo/vba/word/WdUnderline.hpp> 4 #include <hash_map> 5 #include <ooo/vba/word/WdColorIndex.hpp> 6 7 using namespace ::ooo::vba; 8 using namespace ::com::sun::star; 9 10 const uno::Any aLongAnyTrue( sal_Int16(-1) ); 11 const uno::Any aLongAnyFalse( sal_Int16( 0 ) ); 12 13 struct MapPair 14 { 15 sal_Int32 nMSOConst; 16 sal_Int32 nOOOConst; 17 }; 18 19 static MapPair UnderLineTable[] = { 20 { word::WdUnderline::wdUnderlineNone, com::sun::star::awt::FontUnderline::NONE }, 21 { word::WdUnderline::wdUnderlineSingle, com::sun::star::awt::FontUnderline::SINGLE }, 22 { word::WdUnderline::wdUnderlineWords, com::sun::star::awt::FontUnderline::SINGLE }, 23 { word::WdUnderline::wdUnderlineDouble, com::sun::star::awt::FontUnderline::DOUBLE }, 24 { word::WdUnderline::wdUnderlineDotted, com::sun::star::awt::FontUnderline::DOTTED }, 25 { word::WdUnderline::wdUnderlineThick, com::sun::star::awt::FontUnderline::BOLDDASH }, 26 { word::WdUnderline::wdUnderlineDash, com::sun::star::awt::FontUnderline::DASH }, 27 { word::WdUnderline::wdUnderlineDotDash, com::sun::star::awt::FontUnderline::DASHDOT }, 28 { word::WdUnderline::wdUnderlineDotDotDash, com::sun::star::awt::FontUnderline::DASHDOTDOT }, 29 { word::WdUnderline::wdUnderlineWavy, com::sun::star::awt::FontUnderline::WAVE }, 30 { word::WdUnderline::wdUnderlineDottedHeavy, com::sun::star::awt::FontUnderline::BOLDDOTTED }, 31 { word::WdUnderline::wdUnderlineDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASH }, 32 { word::WdUnderline::wdUnderlineDotDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASHDOT }, 33 { word::WdUnderline::wdUnderlineDotDotDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASHDOTDOT }, 34 { word::WdUnderline::wdUnderlineWavyHeavy, com::sun::star::awt::FontUnderline::BOLDWAVE }, 35 { word::WdUnderline::wdUnderlineDashLong, com::sun::star::awt::FontUnderline::LONGDASH }, 36 { word::WdUnderline::wdUnderlineWavyDouble, com::sun::star::awt::FontUnderline::DOUBLEWAVE }, 37 { word::WdUnderline::wdUnderlineDashLongHeavy, com::sun::star::awt::FontUnderline::BOLDLONGDASH }, 38 }; 39 40 typedef std::hash_map< sal_Int32, sal_Int32 > ConstToConst; 41 class UnderLineMapper 42 { 43 ConstToConst MSO2OOO; 44 ConstToConst OOO2MSO; 45 private: 46 UnderLineMapper() 47 { 48 sal_Int32 nLen = sizeof( UnderLineTable )/ sizeof( UnderLineTable[0] ); 49 50 for ( sal_Int32 index=0; index<nLen; ++index ) 51 { 52 MSO2OOO[ UnderLineTable[ index ].nMSOConst ] = UnderLineTable[ index ].nOOOConst; 53 OOO2MSO[ UnderLineTable[ index ].nOOOConst ] = UnderLineTable[ index ].nMSOConst; 54 } 55 } 56 public: 57 static rtl::OUString propName() 58 { 59 static rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("CharUnderline") ); 60 return sPropName; 61 } 62 63 static UnderLineMapper& instance() 64 { 65 static UnderLineMapper theMapper; 66 return theMapper; 67 } 68 69 sal_Int32 getOOOFromMSO( sal_Int32 nMSOConst ) throw( lang::IllegalArgumentException ) 70 { 71 ConstToConst::iterator it = MSO2OOO.find( nMSOConst ); 72 if ( it == MSO2OOO.end() ) 73 throw lang::IllegalArgumentException(); 74 return it->second; 75 } 76 sal_Int32 getMSOFromOOO( sal_Int32 nOOOConst ) throw( lang::IllegalArgumentException ) 77 { 78 ConstToConst::iterator it = OOO2MSO.find( nOOOConst ); 79 if ( it == OOO2MSO.end() ) 80 throw lang::IllegalArgumentException(); 81 return it->second; 82 } 83 }; 84 85 SwVbaFont::SwVbaFont( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xPalette, uno::Reference< css::beans::XPropertySet > xPropertySet ) throw ( css::uno::RuntimeException ) : SwVbaFont_BASE( xParent, xContext, xPalette, xPropertySet ) 86 { 87 } 88 89 uno::Any SAL_CALL 90 SwVbaFont::getUnderline() throw (uno::RuntimeException) 91 { 92 sal_Int32 nOOVal = 0; 93 mxFont->getPropertyValue( UnderLineMapper::propName() ) >>= nOOVal; 94 return uno::makeAny( UnderLineMapper::instance().getMSOFromOOO( nOOVal ) ); 95 } 96 97 void SAL_CALL 98 SwVbaFont::setUnderline( const uno::Any& _underline ) throw (uno::RuntimeException) 99 { 100 sal_Int32 nMSOVal = 0; 101 102 if ( _underline >>= nMSOVal ) 103 { 104 sal_Int32 nOOVal = UnderLineMapper::instance().getOOOFromMSO( nMSOVal ); 105 mxFont->setPropertyValue( UnderLineMapper::propName(), uno::makeAny( nOOVal ) ); 106 } 107 } 108 109 rtl::OUString& 110 SwVbaFont::getServiceImplName() 111 { 112 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaFont") ); 113 return sImplName; 114 } 115 116 void SAL_CALL 117 SwVbaFont::setColorIndex( const uno::Any& _colorindex ) throw( uno::RuntimeException ) 118 { 119 sal_Int32 nIndex = 0; 120 _colorindex >>= nIndex; 121 return setColor( OORGBToXLRGB(mxPalette->getByIndex( nIndex )) ); 122 } 123 124 uno::Any SAL_CALL 125 SwVbaFont::getColorIndex() throw ( uno::RuntimeException ) 126 { 127 sal_Int32 nColor = 0; 128 129 XLRGBToOORGB( getColor() ) >>= nColor; 130 sal_Int32 nElems = mxPalette->getCount(); 131 sal_Int32 nIndex = 0; 132 for ( sal_Int32 count=0; count<nElems; ++count ) 133 { 134 sal_Int32 nPaletteColor = 0; 135 mxPalette->getByIndex( count ) >>= nPaletteColor; 136 if ( nPaletteColor == nColor ) 137 { 138 nIndex = count; 139 break; 140 } 141 } 142 return uno::makeAny( nIndex ); 143 } 144 uno::Any SAL_CALL 145 SwVbaFont::getSubscript() throw ( uno::RuntimeException ) 146 { 147 sal_Bool bRes = sal_False; 148 SwVbaFont_BASE::getSubscript() >>= bRes; 149 if ( bRes ) 150 return aLongAnyTrue; 151 return aLongAnyFalse; 152 } 153 154 uno::Any SAL_CALL 155 SwVbaFont::getSuperscript() throw ( uno::RuntimeException ) 156 { 157 sal_Bool bRes = sal_False; 158 SwVbaFont_BASE::getSuperscript() >>= bRes; 159 if ( bRes ) 160 return aLongAnyTrue; 161 return aLongAnyFalse; 162 } 163 164 uno::Any SAL_CALL 165 SwVbaFont::getBold() throw (uno::RuntimeException) 166 { 167 sal_Bool bRes = sal_False; 168 SwVbaFont_BASE::getBold() >>= bRes; 169 if ( bRes ) 170 return aLongAnyTrue; 171 return aLongAnyFalse; 172 } 173 174 uno::Any SAL_CALL 175 SwVbaFont::getItalic() throw (uno::RuntimeException) 176 { 177 sal_Bool bRes = sal_False; 178 SwVbaFont_BASE::getItalic() >>= bRes; 179 if ( bRes ) 180 return aLongAnyTrue; 181 return aLongAnyFalse; 182 } 183 184 uno::Any SAL_CALL 185 SwVbaFont::getStrikethrough() throw (css::uno::RuntimeException) 186 { 187 sal_Bool bRes = sal_False; 188 SwVbaFont_BASE::getStrikethrough() >>= bRes; 189 if ( bRes ) 190 return aLongAnyTrue; 191 return aLongAnyFalse; 192 } 193 194 uno::Any SAL_CALL 195 SwVbaFont::getShadow() throw (uno::RuntimeException) 196 { 197 sal_Bool bRes = sal_False; 198 SwVbaFont_BASE::getShadow() >>= bRes; 199 if ( bRes ) 200 return aLongAnyTrue; 201 return aLongAnyFalse; 202 } 203 204 uno::Sequence< rtl::OUString > 205 SwVbaFont::getServiceNames() 206 { 207 static uno::Sequence< rtl::OUString > aServiceNames; 208 if ( aServiceNames.getLength() == 0 ) 209 { 210 aServiceNames.realloc( 1 ); 211 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Font" ) ); 212 } 213 return aServiceNames; 214 } 215 216 217