1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <com/sun/star/text/WritingMode2.hpp>
21 #include <drawingml/textparagraph.hxx>
22 #include <oox/drawingml/drawingmltypes.hxx>
23 #include <drawingml/textcharacterproperties.hxx>
24 #include <svtools/unitconv.hxx>
26 #include <rtl/ustring.hxx>
27 #include <sal/log.hxx>
28 #include <oox/mathml/importutils.hxx>
29 #include <oox/helper/propertyset.hxx>
30 #include <com/sun/star/text/XText.hpp>
31 #include <com/sun/star/text/XTextCursor.hpp>
32 #include <com/sun/star/text/ControlCharacter.hpp>
33 #include <oox/token/properties.hxx>
35 using namespace ::com::sun::star
;
36 using namespace ::com::sun::star::text
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::beans
;
40 namespace oox::drawingml
{
42 TextParagraph::TextParagraph()
43 : mbHasProperties( false )
47 TextParagraph::~TextParagraph()
51 TextCharacterProperties
TextParagraph::getCharacterStyle (
52 const TextCharacterProperties
& rTextStyleProperties
,
53 const TextListStyle
& rMasterTextListStyle
,
54 const TextListStyle
& rTextListStyle
) const
56 const TextParagraphProperties
* pMasterTextParagraphStyle
= getParagraphStyle(rMasterTextListStyle
);
57 const TextParagraphProperties
* pTextParagraphStyle
= getParagraphStyle(rTextListStyle
);
59 TextCharacterProperties aTextCharacterStyle
;
60 if (pMasterTextParagraphStyle
)
61 aTextCharacterStyle
.assignUsed(pMasterTextParagraphStyle
->getTextCharacterProperties());
62 aTextCharacterStyle
.assignUsed(rTextStyleProperties
);
63 if (pTextParagraphStyle
)
64 aTextCharacterStyle
.assignUsed(pTextParagraphStyle
->getTextCharacterProperties());
65 aTextCharacterStyle
.assignUsed(maProperties
.getTextCharacterProperties());
66 return aTextCharacterStyle
;
69 TextParagraphProperties
* TextParagraph::getParagraphStyle(
70 const TextListStyle
& rTextListStyle
) const
72 sal_Int16 nLevel
= maProperties
.getLevel();
74 SAL_INFO("oox", "TextParagraph::getParagraphStyle - level " << nLevel
);
76 const TextParagraphPropertiesArray
& rListStyle
= rTextListStyle
.getListStyle();
77 if (nLevel
>= static_cast< sal_Int16
>(rListStyle
.size()))
79 const TextParagraphProperties
* pTextParagraphStyle
= nullptr;
80 if (!rListStyle
.empty())
81 pTextParagraphStyle
= &rListStyle
[nLevel
];
83 return const_cast<TextParagraphProperties
*>(pTextParagraphStyle
);
86 void TextParagraph::insertAt(
87 const ::oox::core::XmlFilterBase
& rFilterBase
,
88 const Reference
< XText
> &xText
,
89 const Reference
< XTextCursor
> &xAt
,
90 const TextCharacterProperties
& rTextStyleProperties
,
91 const TextListStyle
& rMasterTextListStyle
,
92 const TextListStyle
& rTextListStyle
, bool bFirst
,
93 float nDefaultCharHeight
) const
96 sal_Int32 nParagraphSize
= 0;
97 TextCharacterProperties aTextCharacterStyle
98 = getCharacterStyle(rTextStyleProperties
, rMasterTextListStyle
, rTextListStyle
);
102 xText
->insertControlCharacter( xAt
, ControlCharacter::APPEND_PARAGRAPH
, false );
103 xAt
->gotoEnd( true );
106 sal_Int32 nCharHeight
= 0;
107 sal_Int32 nCharHeightFirst
= 0;
108 if ( maRuns
.empty() )
110 PropertySet
aPropSet( xAt
);
112 TextCharacterProperties
aTextCharacterProps( aTextCharacterStyle
);
113 aTextCharacterProps
.assignUsed( maEndProperties
);
114 if ( aTextCharacterProps
.moHeight
.has_value() )
115 nCharHeight
= nCharHeightFirst
= aTextCharacterProps
.moHeight
.value();
116 aTextCharacterProps
.pushToPropSet( aPropSet
, rFilterBase
);
120 for( TextRunVector::const_iterator aIt
= maRuns
.begin(), aEnd
= maRuns
.end(); aIt
!= aEnd
; ++aIt
)
122 sal_Int32 nLen
= (*aIt
)->getText().getLength();
123 // n#759180: Force use, maEndProperties for the last segment
124 // This is currently applied to only empty runs
125 if( !nLen
&& ( ( aIt
+ 1 ) == aEnd
) )
126 (*aIt
)->getTextCharacterProperties().assignUsed( maEndProperties
);
127 sal_Int32 nCharHeightCurrent
= (*aIt
)->insertAt( rFilterBase
, xText
, xAt
, aTextCharacterStyle
, nDefaultCharHeight
);
128 if(aIt
== maRuns
.begin())
129 nCharHeightFirst
= nCharHeightCurrent
;
130 nCharHeight
= std::max
< sal_Int32
>( nCharHeight
, nCharHeightCurrent
);
131 nParagraphSize
+= nLen
;
134 xAt
->gotoEnd( true );
136 PropertyMap aioBulletList
;
137 Reference
< XPropertySet
> xProps( xAt
, UNO_QUERY
);
139 TextListStyle aCombinedTextStyle
;
140 aCombinedTextStyle
.apply(rMasterTextListStyle
);
141 aCombinedTextStyle
.apply(rTextListStyle
);
142 TextParagraphProperties
* pTextParagraphStyle
= getParagraphStyle(aCombinedTextStyle
);
143 if ( pTextParagraphStyle
)
145 TextParagraphProperties aParaProp
;
146 aParaProp
.apply( *pTextParagraphStyle
);
147 aParaProp
.apply( maProperties
);
149 // bullets have same color as following texts by default
150 if( !aioBulletList
.hasProperty( PROP_BulletColor
) && !maRuns
.empty()
151 && (*maRuns
.begin())->getTextCharacterProperties().maFillProperties
.moFillType
.has_value() )
152 aioBulletList
.setProperty( PROP_BulletColor
, (*maRuns
.begin())->getTextCharacterProperties().maFillProperties
.getBestSolidColor().getColor( rFilterBase
.getGraphicHelper() ));
153 if( !aioBulletList
.hasProperty( PROP_BulletColor
) && aTextCharacterStyle
.maFillProperties
.moFillType
.has_value() )
154 aioBulletList
.setProperty( PROP_BulletColor
, aTextCharacterStyle
.maFillProperties
.getBestSolidColor().getColor( rFilterBase
.getGraphicHelper() ));
155 if( !aioBulletList
.hasProperty( PROP_GraphicSize
) && !maRuns
.empty()
156 && aParaProp
.getBulletList().maGraphic
.hasValue())
158 tools::Long nFirstCharHeightMm
= TransformMetric(nCharHeightFirst
> 0 ? nCharHeightFirst
: 1200, FieldUnit::POINT
, FieldUnit::MM
);
159 float fBulletSizeRel
= 1.f
;
160 double fBulletAspectRatio
= 1.0;
162 if( aParaProp
.getBulletList().mnSize
.hasValue() )
163 fBulletSizeRel
= aParaProp
.getBulletList().mnSize
.get
<sal_Int16
>() / 100.f
;
165 if( aParaProp
.getBulletList().mnAspectRatio
.hasValue() )
166 fBulletAspectRatio
= aParaProp
.getBulletList().mnAspectRatio
.get
<double>();
168 css::awt::Size aBulletSize
;
169 if( fBulletAspectRatio
!= 1.0 )
171 aBulletSize
.Height
= std::lround(fBulletSizeRel
* nFirstCharHeightMm
* OOX_BULLET_LIST_SCALE_FACTOR
);
172 aBulletSize
.Width
= aBulletSize
.Height
* fBulletAspectRatio
;
175 aBulletSize
.Width
= aBulletSize
.Height
= std::lround(fBulletSizeRel
* nFirstCharHeightMm
* OOX_BULLET_LIST_SCALE_FACTOR
);
177 aioBulletList
.setProperty( PROP_GraphicSize
, aBulletSize
);
180 // If the shape is Stacked then set Stacked into the TextParagraphProperties
181 Reference
<XPropertySet
> xProps2(xText
, UNO_QUERY
);
182 sal_Int16 nWritingMode
= xProps2
->getPropertyValue(u
"WritingMode"_ustr
).get
<sal_Int16
>();
183 if (nWritingMode
== text::WritingMode2::STACKED
)
185 aParaProp
.getTextParagraphPropertyMap().setProperty(PROP_WritingMode
, nWritingMode
);
188 float fCharacterSize
= nCharHeight
> 0 ? GetFontHeight ( nCharHeight
) : pTextParagraphStyle
->getCharHeightPoints( 12 );
189 aParaProp
.pushToPropSet( &rFilterBase
, xProps
, aioBulletList
, &pTextParagraphStyle
->getBulletList(), true, fCharacterSize
, true );
192 // empty paragraphs do not have bullets in ppt
193 if ( !nParagraphSize
)
195 xProps
->setPropertyValue( u
"NumberingLevel"_ustr
, Any( static_cast< sal_Int16
>( -1 ) ) );
198 // FIXME this is causing a lot of disruption (ie does not work). I wonder what to do -- Hub
199 // Reference< XTextRange > xEnd( xAt, UNO_QUERY );
200 // Reference< XPropertySet > xProps2( xEnd, UNO_QUERY );
201 // mpEndProperties->pushToPropSet( xProps2 );
205 SAL_INFO("oox", "exception in TextParagraph::insertAt");
209 formulaimport::XmlStreamBuilder
& TextParagraph::GetMathXml()
213 m_pMathXml
.reset(new formulaimport::XmlStreamBuilder
);
218 bool TextParagraph::hasVisualRunProperties() const
220 for ( auto& pTextRun
: getRuns() )
222 if ( pTextRun
->hasVisualRunProperties() )
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */