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, float nDefaultCharHeight) const
91{
92 try {
93 sal_Int32 nParagraphSize = 0;
94 TextCharacterProperties aTextCharacterStyle
95 = getCharacterStyle(rTextStyleProperties, rMasterTextListStyle, rTextListStyle);
96
97 if( !bFirst )
98 {
99 xText->insertControlCharacter( xAt, ControlCharacter::APPEND_PARAGRAPH, false );
100 xAt->gotoEnd( true );
101 }
102
103 sal_Int32 nCharHeight = 0;
104 sal_Int32 nCharHeightFirst = 0;
105 if ( maRuns.empty() )
106 {
107 PropertySet aPropSet( xAt );
108
109 TextCharacterProperties aTextCharacterProps( aTextCharacterStyle );
110 aTextCharacterProps.assignUsed( maEndProperties );
111 if ( aTextCharacterProps.moHeight.has_value() )
112 nCharHeight = nCharHeightFirst = aTextCharacterProps.moHeight.value();
113 aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
114 }
115 else
116 {
117 for( TextRunVector::const_iterator aIt = maRuns.begin(), aEnd = maRuns.end(); aIt != aEnd; ++aIt )
118 {
119 sal_Int32 nLen = (*aIt)->getText().getLength();
120 // n#759180: Force use, maEndProperties for the last segment
121 // This is currently applied to only empty runs
122 if( !nLen && ( ( aIt + 1 ) == aEnd ) )
123 (*aIt)->getTextCharacterProperties().assignUsed( maEndProperties );
124 sal_Int32 nCharHeightCurrent = (*aIt)->insertAt( rFilterBase, xText, xAt, aTextCharacterStyle, nDefaultCharHeight );
125 if(aIt == maRuns.begin())
126 nCharHeightFirst = nCharHeightCurrent;
127 nCharHeight = std::max< sal_Int32 >( nCharHeight, nCharHeightCurrent);
128 nParagraphSize += nLen;
129 }
130 }
131 xAt->gotoEnd( true );
132
133 PropertyMap aioBulletList;
134 Reference< XPropertySet > xProps( xAt, UNO_QUERY);
135
136 TextListStyle aCombinedTextStyle;
137 aCombinedTextStyle.apply(rMasterTextListStyle);
138 aCombinedTextStyle.apply(rTextListStyle);
139 TextParagraphProperties* pTextParagraphStyle = getParagraphStyle(aCombinedTextStyle);
140 if ( pTextParagraphStyle )
141 {
142 TextParagraphProperties aParaProp;
143 aParaProp.apply( *pTextParagraphStyle );
144 aParaProp.apply( maProperties );
145
146 // bullets have same color as following texts by default
147 if( !aioBulletList.hasProperty( PROP_BulletColor ) && !maRuns.empty()
148 && (*maRuns.begin())->getTextCharacterProperties().maFillProperties.moFillType.has_value() )
149 aioBulletList.setProperty( PROP_BulletColor, (*maRuns.begin())->getTextCharacterProperties().maFillProperties.getBestSolidColor().getColor( rFilterBase.getGraphicHelper() ));
150 if( !aioBulletList.hasProperty( PROP_BulletColor ) && aTextCharacterStyle.maFillProperties.moFillType.has_value() )
151 aioBulletList.setProperty( PROP_BulletColor, aTextCharacterStyle.maFillProperties.getBestSolidColor().getColor( rFilterBase.getGraphicHelper() ));
152 if( !aioBulletList.hasProperty( PROP_GraphicSize ) && !maRuns.empty()
153 && aParaProp.getBulletList().maGraphic.hasValue())
154 {
155 tools::Long nFirstCharHeightMm = TransformMetric(nCharHeightFirst > 0 ? nCharHeightFirst : 1200, FieldUnit::POINT, FieldUnit::MM);
156 float fBulletSizeRel = 1.f;
157 double fBulletAspectRatio = 1.0;
158
159 if( aParaProp.getBulletList().mnSize.hasValue() )
160 fBulletSizeRel = aParaProp.getBulletList().mnSize.get<sal_Int16>() / 100.f;
161
162 if( aParaProp.getBulletList().mnAspectRatio.hasValue() )
163 fBulletAspectRatio = aParaProp.getBulletList().mnAspectRatio.get<double>();
164
165 css::awt::Size aBulletSize;
166 if( fBulletAspectRatio != 1.0 )
167 {
168 aBulletSize.Height = std::lround(fBulletSizeRel * nFirstCharHeightMm * OOX_BULLET_LIST_SCALE_FACTOR);
169 aBulletSize.Width = aBulletSize.Height * fBulletAspectRatio;
170 }
171 else
172 aBulletSize.Width = aBulletSize.Height = std::lround(fBulletSizeRel * nFirstCharHeightMm * OOX_BULLET_LIST_SCALE_FACTOR);
173
174 aioBulletList.setProperty( PROP_GraphicSize, aBulletSize);
175 }
176
177 float fCharacterSize = nCharHeight > 0 ? GetFontHeight ( nCharHeight ) : pTextParagraphStyle->getCharHeightPoints( 12 );
178 aParaProp.pushToPropSet( &rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), true, fCharacterSize, true );
179 }
180
181 // empty paragraphs do not have bullets in ppt
182 if ( !nParagraphSize )
183 {
184 xProps->setPropertyValue( "NumberingLevel", Any( static_cast< sal_Int16 >( -1 ) ) );
185 }
186
187// FIXME this is causing a lot of disruption (ie does not work). I wonder what to do -- Hub
188// Reference< XTextRange > xEnd( xAt, UNO_QUERY );
189// Reference< XPropertySet > xProps2( xEnd, UNO_QUERY );
190// mpEndProperties->pushToPropSet( xProps2 );
191 }
192 catch( Exception & )
193 {
194 SAL_INFO("oox", "exception in TextParagraph::insertAt");
195 }
196}
197
199{
200 if (!m_pMathXml)
201 {
203 }
204 return *m_pMathXml;
205}
206
208{
209 for ( auto& pTextRun : getRuns() )
210 {
211 if ( pTextRun->hasVisualRunProperties() )
212 return true;
213 }
214 return false;
215}
216
217}
218
219/* 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:531
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)