LibreOffice Module oox (master) 1
textparagraph.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
23#include <svtools/unitconv.hxx>
24
25#include <rtl/ustring.hxx>
26#include <sal/log.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>
33
34using namespace ::com::sun::star::text;
35using namespace ::com::sun::star::uno;
36using namespace ::com::sun::star::beans;
37
38namespace oox::drawingml {
39
41 : mbHasProperties( false )
42{
43}
44
46{
47}
48
50 const TextCharacterProperties& rTextStyleProperties,
51 const TextListStyle& rMasterTextListStyle,
52 const TextListStyle& rTextListStyle) const
53{
54 const TextParagraphProperties* pMasterTextParagraphStyle = getParagraphStyle(rMasterTextListStyle);
55 const TextParagraphProperties* pTextParagraphStyle = getParagraphStyle(rTextListStyle);
56
57 TextCharacterProperties aTextCharacterStyle;
58 if (pMasterTextParagraphStyle)
59 aTextCharacterStyle.assignUsed(pMasterTextParagraphStyle->getTextCharacterProperties());
60 aTextCharacterStyle.assignUsed(rTextStyleProperties);
61 if (pTextParagraphStyle)
62 aTextCharacterStyle.assignUsed(pTextParagraphStyle->getTextCharacterProperties());
64 return aTextCharacterStyle;
65}
66
68 const TextListStyle& rTextListStyle) const
69{
70 sal_Int16 nLevel = maProperties.getLevel();
71
72 SAL_INFO("oox", "TextParagraph::getParagraphStyle - level " << nLevel);
73
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];
80
81 return const_cast<TextParagraphProperties*>(pTextParagraphStyle);
82}
83
85 const ::oox::core::XmlFilterBase& rFilterBase,
86 const Reference < XText > &xText,
88 const TextCharacterProperties& rTextStyleProperties,
89 const TextListStyle& rMasterTextListStyle,
90 const TextListStyle& rTextListStyle, bool bFirst,
91 float nDefaultCharHeight) const
92{
93 try {
94 sal_Int32 nParagraphSize = 0;
95 TextCharacterProperties aTextCharacterStyle
96 = getCharacterStyle(rTextStyleProperties, rMasterTextListStyle, rTextListStyle);
97
98 if( !bFirst )
99 {
100 xText->insertControlCharacter( xAt, ControlCharacter::APPEND_PARAGRAPH, false );
101 xAt->gotoEnd( true );
102 }
103
104 sal_Int32 nCharHeight = 0;
105 sal_Int32 nCharHeightFirst = 0;
106 if ( maRuns.empty() )
107 {
108 PropertySet aPropSet( xAt );
109
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 );
115 }
116 else
117 {
118 for( TextRunVector::const_iterator aIt = maRuns.begin(), aEnd = maRuns.end(); aIt != aEnd; ++aIt )
119 {
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;
130 }
131 }
132 xAt->gotoEnd( true );
133
134 PropertyMap aioBulletList;
135 Reference< XPropertySet > xProps( xAt, UNO_QUERY);
136
137 TextListStyle aCombinedTextStyle;
138 aCombinedTextStyle.apply(rMasterTextListStyle);
139 aCombinedTextStyle.apply(rTextListStyle);
140 TextParagraphProperties* pTextParagraphStyle = getParagraphStyle(aCombinedTextStyle);
141 if ( pTextParagraphStyle )
142 {
143 TextParagraphProperties aParaProp;
144 aParaProp.apply( *pTextParagraphStyle );
145 aParaProp.apply( maProperties );
146
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())
155 {
156 tools::Long nFirstCharHeightMm = TransformMetric(nCharHeightFirst > 0 ? nCharHeightFirst : 1200, FieldUnit::POINT, FieldUnit::MM);
157 float fBulletSizeRel = 1.f;
158 double fBulletAspectRatio = 1.0;
159
160 if( aParaProp.getBulletList().mnSize.hasValue() )
161 fBulletSizeRel = aParaProp.getBulletList().mnSize.get<sal_Int16>() / 100.f;
162
163 if( aParaProp.getBulletList().mnAspectRatio.hasValue() )
164 fBulletAspectRatio = aParaProp.getBulletList().mnAspectRatio.get<double>();
165
166 css::awt::Size aBulletSize;
167 if( fBulletAspectRatio != 1.0 )
168 {
169 aBulletSize.Height = std::lround(fBulletSizeRel * nFirstCharHeightMm * OOX_BULLET_LIST_SCALE_FACTOR);
170 aBulletSize.Width = aBulletSize.Height * fBulletAspectRatio;
171 }
172 else
173 aBulletSize.Width = aBulletSize.Height = std::lround(fBulletSizeRel * nFirstCharHeightMm * OOX_BULLET_LIST_SCALE_FACTOR);
174
175 aioBulletList.setProperty( PROP_GraphicSize, aBulletSize);
176 }
177
178 float fCharacterSize = nCharHeight > 0 ? GetFontHeight ( nCharHeight ) : pTextParagraphStyle->getCharHeightPoints( 12 );
179 aParaProp.pushToPropSet( &rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), true, fCharacterSize, true );
180 }
181
182 // empty paragraphs do not have bullets in ppt
183 if ( !nParagraphSize )
184 {
185 xProps->setPropertyValue( "NumberingLevel", Any( static_cast< sal_Int16 >( -1 ) ) );
186 }
187
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 );
192 }
193 catch( Exception & )
194 {
195 SAL_INFO("oox", "exception in TextParagraph::insertAt");
196 }
197}
198
200{
201 if (!m_pMathXml)
202 {
204 }
205 return *m_pMathXml;
206}
207
209{
210 for ( auto& pTextRun : getRuns() )
211 {
212 if ( pTextRun->hasVisualRunProperties() )
213 return true;
214 }
215 return false;
216}
217
218}
219
220/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
bool hasProperty(sal_Int32 nPropId) const
Returns true, if the map contains a property with the passed identifier.
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:72
A wrapper for a UNO property set.
Definition: propertyset.hxx:58
::Color getColor(const GraphicHelper &rGraphicHelper, ::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
Definition: color.cxx:644
void apply(const TextListStyle &rTextListStyle)
const TextParagraphPropertiesArray & getListStyle() const
float getCharHeightPoints(float fDefault) const
Returns the largest character size of this paragraph.
void apply(const TextParagraphProperties &rSourceProps)
TextCharacterProperties & getTextCharacterProperties()
void pushToPropSet(const ::oox::core::XmlFilterBase *pFilterBase, const css::uno::Reference< css::beans::XPropertySet > &xPropSet, PropertyMap &rioBulletList, const BulletList *pMasterBuList, bool bApplyBulletList, float fFontSize, bool bPushDefaultValues=false) const
TextParagraphProperties maProperties
TextCharacterProperties maEndProperties
bool hasVisualRunProperties() const
Returns whether textparagraph had a rPr tag in it that alters it visually.
TextCharacterProperties getCharacterStyle(const TextCharacterProperties &rTextStyleProperties, const TextListStyle &rMasterTextListStyle, const TextListStyle &rTextListStyle) const
std::unique_ptr< formulaimport::XmlStreamBuilder > m_pMathXml
void insertAt(const ::oox::core::XmlFilterBase &rFilterBase, const css::uno::Reference< css::text::XText > &xText, const css::uno::Reference< css::text::XTextCursor > &xAt, const TextCharacterProperties &rTextStyleProperties, const TextListStyle &rMasterTextListStyle, const TextListStyle &rTextListStyle, bool bFirst, float nDefaultCharHeight) const
TextParagraphProperties * getParagraphStyle(const TextListStyle &rTextListStyle) const
formulaimport::XmlStreamBuilder & GetMathXml()
This class is used for creating XmlStream.
#define SAL_INFO(area, stream)
@ Exception
float GetFontHeight(sal_Int32 nHeight)
std::array< TextParagraphProperties, NUM_TEXT_LIST_STYLE_ENTRIES > TextParagraphPropertiesArray
long Long
Color getBestSolidColor() const
Tries to resolve current settings to a solid color, e.g.
std::optional< sal_Int32 > moFillType
void pushToPropSet(PropertySet &rPropSet, const ::oox::core::XmlFilterBase &rFilter) const
Writes the properties to the passed property set.
void assignUsed(const TextCharacterProperties &rSourceProps)
Overwrites all members that are explicitly set in rSourceProps.
#define OOX_BULLET_LIST_SCALE_FACTOR
SVT_DLLPUBLIC tools::Long TransformMetric(tools::Long nVal, FieldUnit aOld, FieldUnit aNew)