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 
34 using namespace ::com::sun::star::text;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::beans;
37 
38 namespace oox::drawingml {
39 
41  : mbHasProperties( false )
42 {
43 }
44 
46 {
47 }
48 
50  const TextCharacterProperties& rTextStyleProperties,
51  const TextListStyle& rTextListStyle) const
52 {
53  const TextParagraphProperties* pTextParagraphStyle = getParagraphStyle(rTextListStyle);
54 
55  TextCharacterProperties aTextCharacterStyle;
56  if (pTextParagraphStyle)
57  aTextCharacterStyle.assignUsed(pTextParagraphStyle->getTextCharacterProperties());
58  aTextCharacterStyle.assignUsed(rTextStyleProperties);
59  aTextCharacterStyle.assignUsed(maProperties.getTextCharacterProperties());
60  return aTextCharacterStyle;
61 }
62 
64  const TextListStyle& rTextListStyle) const
65 {
66  sal_Int16 nLevel = maProperties.getLevel();
67 
68  SAL_INFO("oox", "TextParagraph::getParagraphStyle - level " << nLevel);
69 
70  const TextParagraphPropertiesArray& rListStyle = rTextListStyle.getListStyle();
71  if (nLevel >= static_cast< sal_Int16 >(rListStyle.size()))
72  nLevel = 0;
73  const TextParagraphProperties* pTextParagraphStyle = nullptr;
74  if (!rListStyle.empty())
75  pTextParagraphStyle = &rListStyle[nLevel];
76 
77  return const_cast<TextParagraphProperties*>(pTextParagraphStyle);
78 }
79 
81  const ::oox::core::XmlFilterBase& rFilterBase,
82  const Reference < XText > &xText,
83  const Reference < XTextCursor > &xAt,
84  const TextCharacterProperties& rTextStyleProperties,
85  const TextListStyle& rTextListStyle, bool bFirst, float nDefaultCharHeight) const
86 {
87  try {
88  sal_Int32 nParagraphSize = 0;
89  TextCharacterProperties aTextCharacterStyle = getCharacterStyle(rTextStyleProperties, rTextListStyle);
90 
91  if( !bFirst )
92  {
93  xText->insertControlCharacter( xAt, ControlCharacter::APPEND_PARAGRAPH, false );
94  xAt->gotoEnd( true );
95  }
96 
97  sal_Int32 nCharHeight = 0;
98  sal_Int32 nCharHeightFirst = 0;
99  if ( maRuns.empty() )
100  {
101  PropertySet aPropSet( xAt );
102 
103  TextCharacterProperties aTextCharacterProps( aTextCharacterStyle );
104  aTextCharacterProps.assignUsed( maEndProperties );
105  if ( aTextCharacterProps.moHeight.has() )
106  nCharHeight = nCharHeightFirst = aTextCharacterProps.moHeight.get();
107  aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
108  }
109  else
110  {
111  for( TextRunVector::const_iterator aIt = maRuns.begin(), aEnd = maRuns.end(); aIt != aEnd; ++aIt )
112  {
113  sal_Int32 nLen = (*aIt)->getText().getLength();
114  // n#759180: Force use, maEndProperties for the last segment
115  // This is currently applied to only empty runs
116  if( !nLen && ( ( aIt + 1 ) == aEnd ) )
117  (*aIt)->getTextCharacterProperties().assignUsed( maEndProperties );
118  sal_Int32 nCharHeightCurrent = (*aIt)->insertAt( rFilterBase, xText, xAt, aTextCharacterStyle, nDefaultCharHeight );
119  if(aIt == maRuns.begin())
120  nCharHeightFirst = nCharHeightCurrent;
121  nCharHeight = std::max< sal_Int32 >( nCharHeight, nCharHeightCurrent);
122  nParagraphSize += nLen;
123  }
124  }
125  xAt->gotoEnd( true );
126 
127  PropertyMap aioBulletList;
128  Reference< XPropertySet > xProps( xAt, UNO_QUERY);
129 
130  TextParagraphProperties* pTextParagraphStyle = getParagraphStyle(rTextListStyle);
131  if ( pTextParagraphStyle )
132  {
133  TextParagraphProperties aParaProp;
134  aParaProp.apply( *pTextParagraphStyle );
135  aParaProp.apply( maProperties );
136 
137  // bullets have same color as following texts by default
138  if( !aioBulletList.hasProperty( PROP_BulletColor ) && !maRuns.empty()
139  && (*maRuns.begin())->getTextCharacterProperties().maFillProperties.moFillType.has() )
140  aioBulletList.setProperty( PROP_BulletColor, (*maRuns.begin())->getTextCharacterProperties().maFillProperties.getBestSolidColor().getColor( rFilterBase.getGraphicHelper() ));
141  if( !aioBulletList.hasProperty( PROP_BulletColor ) && aTextCharacterStyle.maFillProperties.moFillType.has() )
142  aioBulletList.setProperty( PROP_BulletColor, aTextCharacterStyle.maFillProperties.getBestSolidColor().getColor( rFilterBase.getGraphicHelper() ));
143  if( !aioBulletList.hasProperty( PROP_GraphicSize ) && !maRuns.empty()
144  && aParaProp.getBulletList().maGraphic.hasValue())
145  {
146  tools::Long nFirstCharHeightMm = TransformMetric(nCharHeightFirst > 0 ? nCharHeightFirst : 1200, FieldUnit::POINT, FieldUnit::MM);
147  float fBulletSizeRel = 1.f;
148  double fBulletAspectRatio = 1.0;
149 
150  if( aParaProp.getBulletList().mnSize.hasValue() )
151  fBulletSizeRel = aParaProp.getBulletList().mnSize.get<sal_Int16>() / 100.f;
152 
153  if( aParaProp.getBulletList().mnAspectRatio.hasValue() )
154  fBulletAspectRatio = aParaProp.getBulletList().mnAspectRatio.get<double>();
155 
156  css::awt::Size aBulletSize;
157  if( fBulletAspectRatio != 1.0 )
158  {
159  aBulletSize.Height = std::lround(fBulletSizeRel * nFirstCharHeightMm * OOX_BULLET_LIST_SCALE_FACTOR);
160  aBulletSize.Width = aBulletSize.Height * fBulletAspectRatio;
161  }
162  else
163  aBulletSize.Width = aBulletSize.Height = std::lround(fBulletSizeRel * nFirstCharHeightMm * OOX_BULLET_LIST_SCALE_FACTOR);
164 
165  aioBulletList.setProperty( PROP_GraphicSize, aBulletSize);
166  }
167 
168  float fCharacterSize = nCharHeight > 0 ? GetFontHeight ( nCharHeight ) : pTextParagraphStyle->getCharHeightPoints( 12 );
169  aParaProp.pushToPropSet( &rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), true, fCharacterSize, true );
170  }
171 
172  // empty paragraphs do not have bullets in ppt
173  if ( !nParagraphSize )
174  {
175  xProps->setPropertyValue( "NumberingLevel", Any( static_cast< sal_Int16 >( -1 ) ) );
176  }
177 
178 // FIXME this is causing a lot of disruption (ie does not work). I wonder what to do -- Hub
179 // Reference< XTextRange > xEnd( xAt, UNO_QUERY );
180 // Reference< XPropertySet > xProps2( xEnd, UNO_QUERY );
181 // mpEndProperties->pushToPropSet( xProps2 );
182  }
183  catch( Exception & )
184  {
185  SAL_INFO("oox", "exception in TextParagraph::insertAt");
186  }
187 }
188 
190 {
191  if (!m_pMathXml)
192  {
194  }
195  return *m_pMathXml;
196 }
197 
199 {
200  for ( auto& pTextRun : getRuns() )
201  {
202  if ( pTextRun->hasVisualRunProperties() )
203  return true;
204  }
205  return false;
206 }
207 
208 }
209 
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
This class is used for creating XmlStream.
bool hasVisualRunProperties() const
Returns whether textparagraph had a rPr tag in it that alters it visually.
std::unique_ptr< formulaimport::XmlStreamBuilder > m_pMathXml
OptValue< sal_Int32 > moFillType
long Long
TextCharacterProperties getCharacterStyle(const TextCharacterProperties &rTextStyleProperties, const TextListStyle &rTextListStyle) const
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:70
Color getBestSolidColor() const
Tries to resolve current settings to a solid color, e.g.
tools::Long TransformMetric(tools::Long nVal, FieldUnit aOld, FieldUnit aNew)
float getCharHeightPoints(float fDefault) const
Returns the largest character size of this paragraph.
TextParagraphProperties maProperties
std::array< TextParagraphProperties, NUM_TEXT_LIST_STYLE_ENTRIES > TextParagraphPropertiesArray
const Type & get() const
Definition: helper.hxx:185
#define OOX_BULLET_LIST_SCALE_FACTOR
float GetFontHeight(sal_Int32 nHeight)
bool hasProperty(sal_Int32 nPropId) const
Returns true, if the map contains a property with the passed identifier.
::Color getColor(const GraphicHelper &rGraphicHelper,::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
Definition: color.cxx:481
void apply(const TextParagraphProperties &rSourceProps)
A wrapper for a UNO property set.
Definition: propertyset.hxx:57
formulaimport::XmlStreamBuilder & GetMathXml()
#define SAL_INFO(area, stream)
const TextParagraphPropertiesArray & getListStyle() const
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
void assignUsed(const TextCharacterProperties &rSourceProps)
Overwrites all members that are explicitly set in rSourceProps.
void(* f)(TrueTypeTable *)
TextCharacterProperties maEndProperties
TextCharacterProperties & getTextCharacterProperties()
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 &rTextListStyle, bool bFirst, float nDefaultCharHeight) const
bool has() const
Definition: helper.hxx:181
TextParagraphProperties * getParagraphStyle(const TextListStyle &rTextListStyle) const
void pushToPropSet(PropertySet &rPropSet, const ::oox::core::XmlFilterBase &rFilter) const
Writes the properties to the passed property set.