PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/libreoffice-3.6.0.2/oox/source/drawingml/textparagraphpropertiescontext.cxx

#
C++ | 283 lines | 189 code | 40 blank | 54 comment | 19 complexity | 55cd4aa7f389db9eb8f396df1284683e MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, AGPL-1.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-3.0, LGPL-3.0
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /*************************************************************************
  3. *
  4. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5. *
  6. * Copyright 2000, 2010 Oracle and/or its affiliates.
  7. *
  8. * OpenOffice.org - a multi-platform office productivity suite
  9. *
  10. * This file is part of OpenOffice.org.
  11. *
  12. * OpenOffice.org is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Lesser General Public License version 3
  14. * only, as published by the Free Software Foundation.
  15. *
  16. * OpenOffice.org is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License version 3 for more details
  20. * (a copy is included in the LICENSE file that accompanied this code).
  21. *
  22. * You should have received a copy of the GNU Lesser General Public License
  23. * version 3 along with OpenOffice.org. If not, see
  24. * <http://www.openoffice.org/license.html>
  25. * for a copy of the LGPLv3 License.
  26. *
  27. ************************************************************************/
  28. #include "oox/drawingml/textparagraphpropertiescontext.hxx"
  29. #include <com/sun/star/text/WritingMode.hpp>
  30. #include <com/sun/star/awt/FontDescriptor.hpp>
  31. #include "oox/drawingml/colorchoicecontext.hxx"
  32. #include "oox/drawingml/textcharacterpropertiescontext.hxx"
  33. #include "oox/drawingml/fillproperties.hxx"
  34. #include "oox/helper/attributelist.hxx"
  35. #include "textspacingcontext.hxx"
  36. #include "texttabstoplistcontext.hxx"
  37. using ::rtl::OUString;
  38. using namespace ::oox::core;
  39. using ::com::sun::star::awt::FontDescriptor;
  40. using namespace ::com::sun::star::uno;
  41. using namespace ::com::sun::star::xml::sax;
  42. using namespace ::com::sun::star::style;
  43. using namespace ::com::sun::star::text;
  44. namespace oox { namespace drawingml {
  45. // CT_TextParagraphProperties
  46. TextParagraphPropertiesContext::TextParagraphPropertiesContext( ContextHandler& rParent,
  47. const Reference< XFastAttributeList >& xAttribs,
  48. TextParagraphProperties& rTextParagraphProperties )
  49. : ContextHandler( rParent )
  50. , mrTextParagraphProperties( rTextParagraphProperties )
  51. , mrSpaceBefore( rTextParagraphProperties.getParaTopMargin() )
  52. , mrSpaceAfter( rTextParagraphProperties.getParaBottomMargin() )
  53. , mrBulletList( rTextParagraphProperties.getBulletList() )
  54. {
  55. OUString sValue;
  56. AttributeList attribs( xAttribs );
  57. PropertyMap& rPropertyMap( mrTextParagraphProperties.getTextParagraphPropertyMap() );
  58. // ST_TextAlignType
  59. rPropertyMap[ PROP_ParaAdjust ] <<= GetParaAdjust( xAttribs->getOptionalValueToken( XML_algn, XML_l ) );
  60. // TODO see to do the same with RubyAdjust
  61. // ST_Coordinate32
  62. // sValue = xAttribs->getOptionalValue( XML_defTabSz ); SJ: we need to be able to set the default tab size for each text object,
  63. // this is possible at the moment only for the whole document.
  64. // sal_Int32 nDefTabSize = ( sValue.getLength() == 0 ? 0 : GetCoordinate( sValue ) );
  65. // TODO
  66. // bool bEaLineBrk = attribs.getBool( XML_eaLnBrk, true );
  67. if ( xAttribs->hasAttribute( XML_latinLnBrk ) )
  68. {
  69. bool bLatinLineBrk = attribs.getBool( XML_latinLnBrk, true );
  70. rPropertyMap[ PROP_ParaIsHyphenation ] <<= bLatinLineBrk;
  71. }
  72. // TODO see what to do with Asian hyphenation
  73. // ST_TextFontAlignType
  74. // TODO
  75. // sal_Int32 nFontAlign = xAttribs->getOptionalValueToken( XML_fontAlgn, XML_base );
  76. if ( xAttribs->hasAttribute( XML_hangingPunct ) )
  77. {
  78. bool bHangingPunct = attribs.getBool( XML_hangingPunct, false );
  79. rPropertyMap[ PROP_ParaIsHangingPunctuation ] <<= bHangingPunct;
  80. }
  81. // ST_Coordinate
  82. if ( xAttribs->hasAttribute( XML_indent ) )
  83. {
  84. sValue = xAttribs->getOptionalValue( XML_indent );
  85. mrTextParagraphProperties.getFirstLineIndentation() = boost::optional< sal_Int32 >( sValue.isEmpty() ? 0 : GetCoordinate( sValue ) );
  86. }
  87. // ST_TextIndentLevelType
  88. // -1 is an invalid value and denote the lack of level
  89. sal_Int32 nLevel = attribs.getInteger( XML_lvl, 0 );
  90. if( nLevel > 8 || nLevel < 0 )
  91. {
  92. nLevel = 0;
  93. }
  94. mrTextParagraphProperties.setLevel( static_cast< sal_Int16 >( nLevel ) );
  95. char name[] = "Outline X";
  96. name[8] = static_cast<char>( '1' + nLevel );
  97. const OUString sStyleNameValue( rtl::OUString::createFromAscii( name ) );
  98. mrBulletList.setStyleName( sStyleNameValue );
  99. // ST_TextMargin
  100. // ParaLeftMargin
  101. if ( xAttribs->hasAttribute( XML_marL ) )
  102. {
  103. sValue = xAttribs->getOptionalValue( XML_marL );
  104. mrTextParagraphProperties.getParaLeftMargin() = boost::optional< sal_Int32 >( sValue.isEmpty() ? 0 : GetCoordinate( sValue ) );
  105. }
  106. // ParaRightMargin
  107. if ( xAttribs->hasAttribute( XML_marR ) )
  108. {
  109. sValue = xAttribs->getOptionalValue( XML_marR );
  110. sal_Int32 nMarR = sValue.isEmpty() ? 0 : GetCoordinate( sValue ) ;
  111. rPropertyMap[ PROP_ParaRightMargin ] <<= nMarR;
  112. }
  113. if ( xAttribs->hasAttribute( XML_rtl ) )
  114. {
  115. bool bRtl = attribs.getBool( XML_rtl, false );
  116. rPropertyMap[ PROP_TextWritingMode ] <<= ( bRtl ? WritingMode_RL_TB : WritingMode_LR_TB );
  117. }
  118. }
  119. TextParagraphPropertiesContext::~TextParagraphPropertiesContext()
  120. {
  121. PropertyMap& rPropertyMap( mrTextParagraphProperties.getTextParagraphPropertyMap() );
  122. if ( maLineSpacing.bHasValue )
  123. rPropertyMap[ PROP_ParaLineSpacing ] <<= maLineSpacing.toLineSpacing();
  124. else
  125. rPropertyMap[ PROP_ParaLineSpacing ] <<= ::com::sun::star::style::LineSpacing( ::com::sun::star::style::LineSpacingMode::PROP, 100 );
  126. ::std::list< TabStop >::size_type nTabCount = maTabList.size();
  127. if( nTabCount != 0 )
  128. {
  129. Sequence< TabStop > aSeq( nTabCount );
  130. TabStop * aArray = aSeq.getArray();
  131. OSL_ENSURE( aArray != NULL, "sequence array is NULL" );
  132. ::std::copy( maTabList.begin(), maTabList.end(), aArray );
  133. rPropertyMap[ PROP_ParaTabStops ] <<= aSeq;
  134. }
  135. if ( mxBlipProps.get() && mxBlipProps->mxGraphic.is() )
  136. mrBulletList.setGraphic( mxBlipProps->mxGraphic );
  137. if( mrBulletList.is() )
  138. rPropertyMap[ PROP_IsNumbering ] <<= sal_True;
  139. sal_Int16 nLevel = mrTextParagraphProperties.getLevel();
  140. rPropertyMap[ PROP_NumberingLevel ] <<= nLevel;
  141. rPropertyMap[ PROP_NumberingIsNumber ] <<= sal_True;
  142. }
  143. // --------------------------------------------------------------------
  144. void TextParagraphPropertiesContext::endFastElement( sal_Int32 ) throw (SAXException, RuntimeException)
  145. {
  146. }
  147. // --------------------------------------------------------------------
  148. Reference< XFastContextHandler > TextParagraphPropertiesContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& rXAttributes ) throw (SAXException, RuntimeException)
  149. {
  150. AttributeList aAttribs( rXAttributes );
  151. Reference< XFastContextHandler > xRet;
  152. switch( aElementToken )
  153. {
  154. case A_TOKEN( lnSpc ): // CT_TextSpacing
  155. xRet.set( new TextSpacingContext( *this, maLineSpacing ) );
  156. break;
  157. case A_TOKEN( spcBef ): // CT_TextSpacing
  158. xRet.set( new TextSpacingContext( *this, mrSpaceBefore ) );
  159. break;
  160. case A_TOKEN( spcAft ): // CT_TextSpacing
  161. xRet.set( new TextSpacingContext( *this, mrSpaceAfter ) );
  162. break;
  163. // EG_TextBulletColor
  164. case A_TOKEN( buClrTx ): // CT_TextBulletColorFollowText ???
  165. mrBulletList.mbBulletColorFollowText <<= sal_True;
  166. break;
  167. case A_TOKEN( buClr ): // CT_Color
  168. xRet.set( new ColorContext( *this, *mrBulletList.maBulletColorPtr ) );
  169. break;
  170. // EG_TextBulletSize
  171. case A_TOKEN( buSzTx ): // CT_TextBulletSizeFollowText
  172. mrBulletList.setBulletSize(100);
  173. break;
  174. case A_TOKEN( buSzPct ): // CT_TextBulletSizePercent
  175. mrBulletList.setBulletSize( static_cast<sal_Int16>( GetPercent( rXAttributes->getOptionalValue( XML_val ) ) / 1000 ) );
  176. break;
  177. case A_TOKEN( buSzPts ): // CT_TextBulletSizePoint
  178. mrBulletList.setBulletSize(0);
  179. mrBulletList.setFontSize( static_cast<sal_Int16>(GetTextSize( rXAttributes->getOptionalValue( XML_val ) ) ) );
  180. break;
  181. // EG_TextBulletTypeface
  182. case A_TOKEN( buFontTx ): // CT_TextBulletTypefaceFollowText
  183. mrBulletList.mbBulletFontFollowText <<= sal_True;
  184. break;
  185. case A_TOKEN( buFont ): // CT_TextFont
  186. mrBulletList.maBulletFont.setAttributes( aAttribs );
  187. break;
  188. // EG_TextBullet
  189. case A_TOKEN( buNone ): // CT_TextNoBullet
  190. mrBulletList.setNone();
  191. break;
  192. case A_TOKEN( buAutoNum ): // CT_TextAutonumberBullet
  193. {
  194. AttributeList attribs( rXAttributes );
  195. try {
  196. sal_Int32 nType = rXAttributes->getValueToken( XML_type );
  197. sal_Int32 nStartAt = attribs.getInteger( XML_startAt, 1 );
  198. if( nStartAt > 32767 )
  199. {
  200. nStartAt = 32767;
  201. }
  202. else if( nStartAt < 1 )
  203. {
  204. nStartAt = 1;
  205. }
  206. mrBulletList.setStartAt( nStartAt );
  207. mrBulletList.setType( nType );
  208. }
  209. catch(SAXException& /* e */ )
  210. {
  211. OSL_TRACE("OOX: SAXException in XML_buAutoNum");
  212. }
  213. break;
  214. }
  215. case A_TOKEN( buChar ): // CT_TextCharBullet
  216. try {
  217. mrBulletList.setBulletChar( rXAttributes->getValue( XML_char ) );
  218. }
  219. catch(SAXException& /* e */)
  220. {
  221. OSL_TRACE("OOX: SAXException in XML_buChar");
  222. }
  223. break;
  224. case A_TOKEN( buBlip ): // CT_TextBlipBullet
  225. {
  226. mxBlipProps.reset( new BlipFillProperties );
  227. xRet.set( new BlipFillContext( *this, rXAttributes, *mxBlipProps ) );
  228. }
  229. break;
  230. case A_TOKEN( tabLst ): // CT_TextTabStopList
  231. xRet.set( new TextTabStopListContext( *this, maTabList ) );
  232. break;
  233. case A_TOKEN( defRPr ): // CT_TextCharacterProperties
  234. xRet.set( new TextCharacterPropertiesContext( *this, rXAttributes, mrTextParagraphProperties.getTextCharacterProperties() ) );
  235. break;
  236. }
  237. if ( !xRet.is() )
  238. xRet.set( this );
  239. return xRet;
  240. }
  241. // --------------------------------------------------------------------
  242. } }
  243. /* vim:set shiftwidth=4 softtabstop=4 expandtab: */