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 <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()
44 TextParagraph::~TextParagraph()
48 TextCharacterProperties
TextParagraph::getCharacterStyle (
49 const TextCharacterProperties
& rTextStyleProperties
,
50 const TextListStyle
& rTextListStyle
) const
52 TextParagraphPropertiesPtr pTextParagraphStyle
= getParagraphStyle(rTextListStyle
);
54 TextCharacterProperties aTextCharacterStyle
;
55 if (pTextParagraphStyle
)
56 aTextCharacterStyle
.assignUsed(pTextParagraphStyle
->getTextCharacterProperties());
57 aTextCharacterStyle
.assignUsed(rTextStyleProperties
);
58 aTextCharacterStyle
.assignUsed(maProperties
.getTextCharacterProperties());
59 return aTextCharacterStyle
;
62 TextParagraphPropertiesPtr
TextParagraph::getParagraphStyle(
63 const TextListStyle
& rTextListStyle
) const
65 sal_Int16 nLevel
= maProperties
.getLevel();
67 SAL_INFO("oox", "TextParagraph::getParagraphStyle - level " << nLevel
);
69 const TextParagraphPropertiesVector
& rListStyle
= rTextListStyle
.getListStyle();
70 if (nLevel
>= static_cast< sal_Int16
>(rListStyle
.size()))
72 TextParagraphPropertiesPtr pTextParagraphStyle
;
73 if (!rListStyle
.empty())
74 pTextParagraphStyle
= rListStyle
[nLevel
];
76 return pTextParagraphStyle
;
79 void TextParagraph::insertAt(
80 const ::oox::core::XmlFilterBase
& rFilterBase
,
81 const Reference
< XText
> &xText
,
82 const Reference
< XTextCursor
> &xAt
,
83 const TextCharacterProperties
& rTextStyleProperties
,
84 const TextListStyle
& rTextListStyle
, bool bFirst
, float nDefaultCharHeight
) const
87 sal_Int32 nParagraphSize
= 0;
88 TextCharacterProperties aTextCharacterStyle
= getCharacterStyle(rTextStyleProperties
, rTextListStyle
);
92 xText
->insertControlCharacter( xAt
, ControlCharacter::APPEND_PARAGRAPH
, false );
96 sal_Int32 nCharHeight
= 0;
97 sal_Int32 nCharHeightFirst
= 0;
100 PropertySet
aPropSet( xAt
);
102 TextCharacterProperties
aTextCharacterProps( aTextCharacterStyle
);
103 aTextCharacterProps
.assignUsed( maEndProperties
);
104 if ( aTextCharacterProps
.moHeight
.has() )
105 nCharHeight
= nCharHeightFirst
= aTextCharacterProps
.moHeight
.get();
106 aTextCharacterProps
.pushToPropSet( aPropSet
, rFilterBase
);
110 for( TextRunVector::const_iterator aIt
= maRuns
.begin(), aEnd
= maRuns
.end(); aIt
!= aEnd
; ++aIt
)
112 sal_Int32 nLen
= (*aIt
)->getText().getLength();
113 // n#759180: Force use, maEndProperties for the last segment
114 // This is currently applied to only empty runs
115 if( !nLen
&& ( ( aIt
+ 1 ) == aEnd
) )
116 (*aIt
)->getTextCharacterProperties().assignUsed( maEndProperties
);
117 sal_Int32 nCharHeightCurrent
= (*aIt
)->insertAt( rFilterBase
, xText
, xAt
, aTextCharacterStyle
, nDefaultCharHeight
);
118 if(aIt
== maRuns
.begin())
119 nCharHeightFirst
= nCharHeightCurrent
;
120 nCharHeight
= std::max
< sal_Int32
>( nCharHeight
, nCharHeightCurrent
);
121 nParagraphSize
+= nLen
;
124 xAt
->gotoEnd( true );
126 PropertyMap aioBulletList
;
127 Reference
< XPropertySet
> xProps( xAt
, UNO_QUERY
);
129 TextParagraphPropertiesPtr pTextParagraphStyle
= getParagraphStyle(rTextListStyle
);
130 if ( pTextParagraphStyle
)
132 TextParagraphProperties aParaProp
;
133 aParaProp
.apply( *pTextParagraphStyle
);
134 aParaProp
.apply( maProperties
);
136 // bullets have same color as following texts by default
137 if( !aioBulletList
.hasProperty( PROP_BulletColor
) && !maRuns
.empty()
138 && (*maRuns
.begin())->getTextCharacterProperties().maFillProperties
.moFillType
.has() )
139 aioBulletList
.setProperty( PROP_BulletColor
, (*maRuns
.begin())->getTextCharacterProperties().maFillProperties
.getBestSolidColor().getColor( rFilterBase
.getGraphicHelper() ));
140 if( !aioBulletList
.hasProperty( PROP_BulletColor
) && aTextCharacterStyle
.maFillProperties
.moFillType
.has() )
141 aioBulletList
.setProperty( PROP_BulletColor
, aTextCharacterStyle
.maFillProperties
.getBestSolidColor().getColor( rFilterBase
.getGraphicHelper() ));
142 if( !aioBulletList
.hasProperty( PROP_GraphicSize
) && !maRuns
.empty()
143 && aParaProp
.getBulletList().maGraphic
.hasValue())
145 tools::Long nFirstCharHeightMm
= TransformMetric(nCharHeightFirst
> 0 ? nCharHeightFirst
: 1200, FieldUnit::POINT
, FieldUnit::MM
);
146 float fBulletSizeRel
= 1.f
;
147 double fBulletAspectRatio
= 1.0;
149 if( aParaProp
.getBulletList().mnSize
.hasValue() )
150 fBulletSizeRel
= aParaProp
.getBulletList().mnSize
.get
<sal_Int16
>() / 100.f
;
152 if( aParaProp
.getBulletList().mnAspectRatio
.hasValue() )
153 fBulletAspectRatio
= aParaProp
.getBulletList().mnAspectRatio
.get
<double>();
155 css::awt::Size aBulletSize
;
156 if( fBulletAspectRatio
!= 1.0 )
158 aBulletSize
.Height
= std::lround(fBulletSizeRel
* nFirstCharHeightMm
* OOX_BULLET_LIST_SCALE_FACTOR
);
159 aBulletSize
.Width
= aBulletSize
.Height
* fBulletAspectRatio
;
162 aBulletSize
.Width
= aBulletSize
.Height
= std::lround(fBulletSizeRel
* nFirstCharHeightMm
* OOX_BULLET_LIST_SCALE_FACTOR
);
164 aioBulletList
.setProperty( PROP_GraphicSize
, aBulletSize
);
167 float fCharacterSize
= nCharHeight
> 0 ? GetFontHeight ( nCharHeight
) : pTextParagraphStyle
->getCharHeightPoints( 12 );
168 aParaProp
.pushToPropSet( &rFilterBase
, xProps
, aioBulletList
, &pTextParagraphStyle
->getBulletList(), true, fCharacterSize
, true );
171 // empty paragraphs do not have bullets in ppt
172 if ( !nParagraphSize
)
174 xProps
->setPropertyValue( "NumberingLevel", Any( static_cast< sal_Int16
>( -1 ) ) );
177 // FIXME this is causing a lot of disruption (ie does not work). I wonder what to do -- Hub
178 // Reference< XTextRange > xEnd( xAt, UNO_QUERY );
179 // Reference< XPropertySet > xProps2( xEnd, UNO_QUERY );
180 // mpEndProperties->pushToPropSet( xProps2 );
184 SAL_INFO("oox", "exception in TextParagraph::insertAt");
188 formulaimport::XmlStreamBuilder
& TextParagraph::GetMathXml()
192 m_pMathXml
.reset(new formulaimport::XmlStreamBuilder
);
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */