Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / drawingml / textparagraph.cxx
blob444832be75924bc8853c9c52af18fa9067c40d52
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "drawingml/textparagraph.hxx"
21 #include "oox/drawingml/drawingmltypes.hxx"
22 #include "drawingml/textcharacterproperties.hxx"
24 #include <rtl/ustring.hxx>
25 #include <oox/mathml/importutils.hxx>
26 #include "oox/helper/propertyset.hxx"
27 #include <com/sun/star/text/XText.hpp>
28 #include <com/sun/star/text/XTextCursor.hpp>
29 #include <com/sun/star/text/ControlCharacter.hpp>
30 #include <oox/token/properties.hxx>
32 using namespace ::com::sun::star::text;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::frame;
37 namespace oox { namespace drawingml {
39 TextParagraph::TextParagraph()
43 TextParagraph::~TextParagraph()
47 TextCharacterProperties TextParagraph::getCharacterStyle (
48 const TextCharacterProperties& rTextStyleProperties,
49 const TextListStyle& rTextListStyle) const
51 TextParagraphPropertiesPtr pTextParagraphStyle = getParagraphStyle(rTextListStyle);
53 TextCharacterProperties aTextCharacterStyle;
54 if (pTextParagraphStyle.get())
55 aTextCharacterStyle.assignUsed(pTextParagraphStyle->getTextCharacterProperties());
56 aTextCharacterStyle.assignUsed(rTextStyleProperties);
57 aTextCharacterStyle.assignUsed(maProperties.getTextCharacterProperties());
58 return aTextCharacterStyle;
61 TextParagraphPropertiesPtr TextParagraph::getParagraphStyle(
62 const TextListStyle& rTextListStyle) const
64 sal_Int16 nLevel = maProperties.getLevel();
66 SAL_INFO("oox", "TextParagraph::getParagraphStyle - level " << nLevel);
68 const TextParagraphPropertiesVector& rListStyle = rTextListStyle.getListStyle();
69 if (nLevel >= static_cast< sal_Int16 >(rListStyle.size()))
70 nLevel = 0;
71 TextParagraphPropertiesPtr pTextParagraphStyle = nullptr;
72 if (rListStyle.size())
73 pTextParagraphStyle = rListStyle[nLevel];
75 return pTextParagraphStyle;
78 void TextParagraph::insertAt(
79 const ::oox::core::XmlFilterBase& rFilterBase,
80 const Reference < XText > &xText,
81 const Reference < XTextCursor > &xAt,
82 const TextCharacterProperties& rTextStyleProperties,
83 const TextListStyle& rTextListStyle, bool bFirst, float nDefaultCharHeight) const
85 try {
86 sal_Int32 nParagraphSize = 0;
87 TextCharacterProperties aTextCharacterStyle = getCharacterStyle(rTextStyleProperties, rTextListStyle);
89 if( !bFirst )
91 xText->insertControlCharacter( xAt, ControlCharacter::APPEND_PARAGRAPH, false );
92 xAt->gotoEnd( true );
95 sal_Int32 nCharHeight = 0;
96 if ( maRuns.empty() )
98 PropertySet aPropSet( xAt );
100 TextCharacterProperties aTextCharacterProps( aTextCharacterStyle );
101 aTextCharacterProps.assignUsed( maEndProperties );
102 if ( aTextCharacterProps.moHeight.has() )
103 nCharHeight = aTextCharacterProps.moHeight.get();
104 aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
106 else
108 for( TextRunVector::const_iterator aIt = maRuns.begin(), aEnd = maRuns.end(); aIt != aEnd; ++aIt )
110 sal_Int32 nLen = (*aIt)->getText().getLength();
111 // n#759180: Force use, maEndProperties for the last segment
112 // This is currently applied to only empty runs
113 if( !nLen && ( ( aIt + 1 ) == aEnd ) )
114 (*aIt)->getTextCharacterProperties().assignUsed( maEndProperties );
115 nCharHeight = std::max< sal_Int32 >( nCharHeight, (*aIt)->insertAt( rFilterBase, xText, xAt, aTextCharacterStyle, nDefaultCharHeight ) );
116 nParagraphSize += nLen;
119 xAt->gotoEnd( true );
121 PropertyMap aioBulletList;
122 Reference< XPropertySet > xProps( xAt, UNO_QUERY);
124 TextParagraphPropertiesPtr pTextParagraphStyle = getParagraphStyle(rTextListStyle);
125 if ( pTextParagraphStyle.get() )
127 TextParagraphProperties aParaProp;
128 aParaProp.apply( *pTextParagraphStyle );
129 aParaProp.apply( maProperties );
131 // bullets have same color as following texts by default
132 if( !aioBulletList.hasProperty( PROP_BulletColor ) && maRuns.size() > 0
133 && (*maRuns.begin())->getTextCharacterProperties().maFillProperties.moFillType.has() )
134 aioBulletList.setProperty( PROP_BulletColor, (*maRuns.begin())->getTextCharacterProperties().maFillProperties.getBestSolidColor().getColor( rFilterBase.getGraphicHelper() ));
135 if( !aioBulletList.hasProperty( PROP_BulletColor ) && aTextCharacterStyle.maFillProperties.moFillType.has() )
136 aioBulletList.setProperty( PROP_BulletColor, aTextCharacterStyle.maFillProperties.getBestSolidColor().getColor( rFilterBase.getGraphicHelper() ));
138 float fCharacterSize = nCharHeight > 0 ? GetFontHeight ( nCharHeight ) : pTextParagraphStyle->getCharHeightPoints( 12 );
139 aParaProp.pushToPropSet( &rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), true, fCharacterSize, true );
142 // empty paragraphs do not have bullets in ppt
143 if ( !nParagraphSize )
145 const OUString sNumberingLevel( "NumberingLevel" );
146 xProps->setPropertyValue( sNumberingLevel, Any( static_cast< sal_Int16 >( -1 ) ) );
149 // FIXME this is causing a lot of disruption (ie does not work). I wonder what to do -- Hub
150 // Reference< XTextRange > xEnd( xAt, UNO_QUERY );
151 // Reference< XPropertySet > xProps2( xEnd, UNO_QUERY );
152 // mpEndProperties->pushToPropSet( xProps2 );
154 catch( Exception & )
156 SAL_INFO("oox", "exception in TextParagraph::insertAt");
160 formulaimport::XmlStreamBuilder & TextParagraph::GetMathXml()
162 if (!m_pMathXml)
164 m_pMathXml.reset(new formulaimport::XmlStreamBuilder);
166 return *m_pMathXml;
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */