Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / oox / source / drawingml / textparagraph.cxx
blobe33cbb690ee9ef47d9c13e3949089520f6fa167d
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>
23 #include <svtools/unitconv.hxx>
25 #include <rtl/ustring.hxx>
26 #include <sal/log.hxx>
27 #include <oox/mathml/importutils.hxx>
28 #include <oox/helper/propertyset.hxx>
29 #include <com/sun/star/text/XText.hpp>
30 #include <com/sun/star/text/XTextCursor.hpp>
31 #include <com/sun/star/text/ControlCharacter.hpp>
32 #include <oox/token/properties.hxx>
34 using namespace ::com::sun::star::text;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::beans;
38 namespace oox::drawingml {
40 TextParagraph::TextParagraph()
41 : mbHasProperties( false )
45 TextParagraph::~TextParagraph()
49 TextCharacterProperties TextParagraph::getCharacterStyle (
50 const TextCharacterProperties& rTextStyleProperties,
51 const TextListStyle& rMasterTextListStyle,
52 const TextListStyle& rTextListStyle) const
54 const TextParagraphProperties* pMasterTextParagraphStyle = getParagraphStyle(rMasterTextListStyle);
55 const TextParagraphProperties* pTextParagraphStyle = getParagraphStyle(rTextListStyle);
57 TextCharacterProperties aTextCharacterStyle;
58 if (pMasterTextParagraphStyle)
59 aTextCharacterStyle.assignUsed(pMasterTextParagraphStyle->getTextCharacterProperties());
60 aTextCharacterStyle.assignUsed(rTextStyleProperties);
61 if (pTextParagraphStyle)
62 aTextCharacterStyle.assignUsed(pTextParagraphStyle->getTextCharacterProperties());
63 aTextCharacterStyle.assignUsed(maProperties.getTextCharacterProperties());
64 return aTextCharacterStyle;
67 TextParagraphProperties* TextParagraph::getParagraphStyle(
68 const TextListStyle& rTextListStyle) const
70 sal_Int16 nLevel = maProperties.getLevel();
72 SAL_INFO("oox", "TextParagraph::getParagraphStyle - level " << nLevel);
74 const TextParagraphPropertiesArray& rListStyle = rTextListStyle.getListStyle();
75 if (nLevel >= static_cast< sal_Int16 >(rListStyle.size()))
76 nLevel = 0;
77 const TextParagraphProperties* pTextParagraphStyle = nullptr;
78 if (!rListStyle.empty())
79 pTextParagraphStyle = &rListStyle[nLevel];
81 return const_cast<TextParagraphProperties*>(pTextParagraphStyle);
84 void TextParagraph::insertAt(
85 const ::oox::core::XmlFilterBase& rFilterBase,
86 const Reference < XText > &xText,
87 const Reference < XTextCursor > &xAt,
88 const TextCharacterProperties& rTextStyleProperties,
89 const TextListStyle& rMasterTextListStyle,
90 const TextListStyle& rTextListStyle, bool bFirst,
91 float nDefaultCharHeight) const
93 try {
94 sal_Int32 nParagraphSize = 0;
95 TextCharacterProperties aTextCharacterStyle
96 = getCharacterStyle(rTextStyleProperties, rMasterTextListStyle, rTextListStyle);
98 if( !bFirst )
100 xText->insertControlCharacter( xAt, ControlCharacter::APPEND_PARAGRAPH, false );
101 xAt->gotoEnd( true );
104 sal_Int32 nCharHeight = 0;
105 sal_Int32 nCharHeightFirst = 0;
106 if ( maRuns.empty() )
108 PropertySet aPropSet( xAt );
110 TextCharacterProperties aTextCharacterProps( aTextCharacterStyle );
111 aTextCharacterProps.assignUsed( maEndProperties );
112 if ( aTextCharacterProps.moHeight.has_value() )
113 nCharHeight = nCharHeightFirst = aTextCharacterProps.moHeight.value();
114 aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
116 else
118 for( TextRunVector::const_iterator aIt = maRuns.begin(), aEnd = maRuns.end(); aIt != aEnd; ++aIt )
120 sal_Int32 nLen = (*aIt)->getText().getLength();
121 // n#759180: Force use, maEndProperties for the last segment
122 // This is currently applied to only empty runs
123 if( !nLen && ( ( aIt + 1 ) == aEnd ) )
124 (*aIt)->getTextCharacterProperties().assignUsed( maEndProperties );
125 sal_Int32 nCharHeightCurrent = (*aIt)->insertAt( rFilterBase, xText, xAt, aTextCharacterStyle, nDefaultCharHeight );
126 if(aIt == maRuns.begin())
127 nCharHeightFirst = nCharHeightCurrent;
128 nCharHeight = std::max< sal_Int32 >( nCharHeight, nCharHeightCurrent);
129 nParagraphSize += nLen;
132 xAt->gotoEnd( true );
134 PropertyMap aioBulletList;
135 Reference< XPropertySet > xProps( xAt, UNO_QUERY);
137 TextListStyle aCombinedTextStyle;
138 aCombinedTextStyle.apply(rMasterTextListStyle);
139 aCombinedTextStyle.apply(rTextListStyle);
140 TextParagraphProperties* pTextParagraphStyle = getParagraphStyle(aCombinedTextStyle);
141 if ( pTextParagraphStyle )
143 TextParagraphProperties aParaProp;
144 aParaProp.apply( *pTextParagraphStyle );
145 aParaProp.apply( maProperties );
147 // bullets have same color as following texts by default
148 if( !aioBulletList.hasProperty( PROP_BulletColor ) && !maRuns.empty()
149 && (*maRuns.begin())->getTextCharacterProperties().maFillProperties.moFillType.has_value() )
150 aioBulletList.setProperty( PROP_BulletColor, (*maRuns.begin())->getTextCharacterProperties().maFillProperties.getBestSolidColor().getColor( rFilterBase.getGraphicHelper() ));
151 if( !aioBulletList.hasProperty( PROP_BulletColor ) && aTextCharacterStyle.maFillProperties.moFillType.has_value() )
152 aioBulletList.setProperty( PROP_BulletColor, aTextCharacterStyle.maFillProperties.getBestSolidColor().getColor( rFilterBase.getGraphicHelper() ));
153 if( !aioBulletList.hasProperty( PROP_GraphicSize ) && !maRuns.empty()
154 && aParaProp.getBulletList().maGraphic.hasValue())
156 tools::Long nFirstCharHeightMm = TransformMetric(nCharHeightFirst > 0 ? nCharHeightFirst : 1200, FieldUnit::POINT, FieldUnit::MM);
157 float fBulletSizeRel = 1.f;
158 double fBulletAspectRatio = 1.0;
160 if( aParaProp.getBulletList().mnSize.hasValue() )
161 fBulletSizeRel = aParaProp.getBulletList().mnSize.get<sal_Int16>() / 100.f;
163 if( aParaProp.getBulletList().mnAspectRatio.hasValue() )
164 fBulletAspectRatio = aParaProp.getBulletList().mnAspectRatio.get<double>();
166 css::awt::Size aBulletSize;
167 if( fBulletAspectRatio != 1.0 )
169 aBulletSize.Height = std::lround(fBulletSizeRel * nFirstCharHeightMm * OOX_BULLET_LIST_SCALE_FACTOR);
170 aBulletSize.Width = aBulletSize.Height * fBulletAspectRatio;
172 else
173 aBulletSize.Width = aBulletSize.Height = std::lround(fBulletSizeRel * nFirstCharHeightMm * OOX_BULLET_LIST_SCALE_FACTOR);
175 aioBulletList.setProperty( PROP_GraphicSize, aBulletSize);
178 float fCharacterSize = nCharHeight > 0 ? GetFontHeight ( nCharHeight ) : pTextParagraphStyle->getCharHeightPoints( 12 );
179 aParaProp.pushToPropSet( &rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), true, fCharacterSize, true );
182 // empty paragraphs do not have bullets in ppt
183 if ( !nParagraphSize )
185 xProps->setPropertyValue( "NumberingLevel", Any( static_cast< sal_Int16 >( -1 ) ) );
188 // FIXME this is causing a lot of disruption (ie does not work). I wonder what to do -- Hub
189 // Reference< XTextRange > xEnd( xAt, UNO_QUERY );
190 // Reference< XPropertySet > xProps2( xEnd, UNO_QUERY );
191 // mpEndProperties->pushToPropSet( xProps2 );
193 catch( Exception & )
195 SAL_INFO("oox", "exception in TextParagraph::insertAt");
199 formulaimport::XmlStreamBuilder & TextParagraph::GetMathXml()
201 if (!m_pMathXml)
203 m_pMathXml.reset(new formulaimport::XmlStreamBuilder);
205 return *m_pMathXml;
208 bool TextParagraph::hasVisualRunProperties() const
210 for ( auto& pTextRun : getRuns() )
212 if ( pTextRun->hasVisualRunProperties() )
213 return true;
215 return false;
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */