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 "oox/drawingml/textparagraph.hxx"
21 #include "oox/drawingml/drawingmltypes.hxx"
22 #include "oox/drawingml/textcharacterproperties.hxx"
24 #include <rtl/ustring.hxx>
25 #include "oox/helper/propertyset.hxx"
26 #include <com/sun/star/text/XText.hpp>
27 #include <com/sun/star/text/XTextCursor.hpp>
28 #include <com/sun/star/text/ControlCharacter.hpp>
30 using namespace ::com::sun::star::text
;
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::beans
;
33 using namespace ::com::sun::star::frame
;
35 namespace oox
{ namespace drawingml
{
37 TextParagraph::TextParagraph()
41 TextParagraph::~TextParagraph()
45 void TextParagraph::insertAt(
46 const ::oox::core::XmlFilterBase
& rFilterBase
,
47 const Reference
< XText
> &xText
,
48 const Reference
< XTextCursor
> &xAt
,
49 const TextCharacterProperties
& rTextStyleProperties
,
50 const TextListStyle
& rTextListStyle
, bool bFirst
) const
53 sal_Int32 nParagraphSize
= 0;
54 Reference
< XTextRange
> xStart( xAt
, UNO_QUERY
);
56 sal_Int16 nLevel
= maProperties
.getLevel();
58 SAL_INFO("oox", "TextParagraph::insertAt() - level " << nLevel
);
60 const TextParagraphPropertiesVector
& rListStyle
= rTextListStyle
.getListStyle();
61 if ( nLevel
>= static_cast< sal_Int16
>( rListStyle
.size() ) )
63 TextParagraphPropertiesPtr pTextParagraphStyle
;
64 if ( rListStyle
.size() )
65 pTextParagraphStyle
= rListStyle
[ nLevel
];
67 TextCharacterProperties aTextCharacterStyle
;
68 if ( pTextParagraphStyle
.get() )
69 aTextCharacterStyle
.assignUsed( pTextParagraphStyle
->getTextCharacterProperties() );
70 aTextCharacterStyle
.assignUsed( rTextStyleProperties
);
71 aTextCharacterStyle
.assignUsed( maProperties
.getTextCharacterProperties() );
75 xText
->insertControlCharacter( xStart
, ControlCharacter::APPEND_PARAGRAPH
, sal_False
);
76 xAt
->gotoEnd( sal_True
);
79 sal_Int32 nCharHeight
= 0;
80 if ( maRuns
.begin() == maRuns
.end() )
82 PropertySet
aPropSet( xStart
);
84 TextCharacterProperties
aTextCharacterProps( aTextCharacterStyle
);
85 aTextCharacterProps
.assignUsed( maEndProperties
);
86 if ( aTextCharacterProps
.moHeight
.has() )
87 nCharHeight
= aTextCharacterProps
.moHeight
.get();
88 aTextCharacterProps
.pushToPropSet( aPropSet
, rFilterBase
);
92 for( TextRunVector::const_iterator aIt
= maRuns
.begin(), aEnd
= maRuns
.end(); aIt
!= aEnd
; ++aIt
)
94 sal_Int32 nLen
= (*aIt
)->getText().getLength();
95 // n#759180: Force use, maEndProperties for the last segment
96 // This is currently applied to only empty runs
97 if( !nLen
&& ( ( aIt
+ 1 ) == aEnd
) )
98 (*aIt
)->getTextCharacterProperties().assignUsed( maEndProperties
);
99 nCharHeight
= std::max
< sal_Int32
>( nCharHeight
, (*aIt
)->insertAt( rFilterBase
, xText
, xAt
, aTextCharacterStyle
) );
100 nParagraphSize
+= nLen
;
103 xAt
->gotoEnd( sal_True
);
105 PropertyMap aioBulletList
;
106 Reference
< XPropertySet
> xProps( xStart
, UNO_QUERY
);
107 float fCharacterSize
= nCharHeight
> 0 ? GetFontHeight( nCharHeight
) : 18;
108 if ( pTextParagraphStyle
.get() )
110 TextParagraphProperties aParaProp
;
111 aParaProp
.apply( *pTextParagraphStyle
);
112 aParaProp
.apply( maProperties
);
113 fCharacterSize
= pTextParagraphStyle
->getCharHeightPoints( fCharacterSize
);
115 // bullets have same color as following texts by default
116 if( !aioBulletList
.hasProperty( PROP_BulletColor
) && maRuns
.size() > 0
117 && (*maRuns
.begin())->getTextCharacterProperties().maCharColor
.isUsed() )
118 aioBulletList
[ PROP_BulletColor
] <<= (*maRuns
.begin())->getTextCharacterProperties().maCharColor
.getColor( rFilterBase
.getGraphicHelper() );
120 aParaProp
.pushToPropSet( &rFilterBase
, xProps
, aioBulletList
, &pTextParagraphStyle
->getBulletList(), sal_True
, fCharacterSize
, true );
123 // empty paragraphs do not have bullets in ppt
124 if ( !nParagraphSize
)
126 const OUString
sNumberingLevel( "NumberingLevel" );
127 xProps
->setPropertyValue( sNumberingLevel
, Any( static_cast< sal_Int16
>( -1 ) ) );
130 // FIXME this is causing a lot of dispruption (ie does not work). I wonder what to do -- Hub
131 // Reference< XTextRange > xEnd( xAt, UNO_QUERY );
132 // Reference< XPropertySet > xProps2( xEnd, UNO_QUERY );
133 // mpEndProperties->pushToPropSet( xProps2 );
137 SAL_INFO("oox", "exception in TextParagraph::insertAt");
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */