1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include "oox/drawingml/textparagraph.hxx"
25 #include "oox/drawingml/drawingmltypes.hxx"
26
27 #include <rtl/ustring.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
33 using ::rtl::OUString;
34 using namespace ::com::sun::star::text;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::frame;
38
39 namespace oox { namespace drawingml {
40
TextParagraph()41 TextParagraph::TextParagraph()
42 {
43 }
44
~TextParagraph()45 TextParagraph::~TextParagraph()
46 {
47 }
48
lcl_getBulletclr(Color & bulletClr,const TextRunVector & rRuns)49 void lcl_getBulletclr(Color& bulletClr,
50 const TextRunVector& rRuns)
51 {
52 // color of closest text in runs
53 if (rRuns.begin() != rRuns.end() && ((*rRuns.begin())->getTextCharacterProperties()).maCharColor.isUsed())
54 {
55 bulletClr = ((*rRuns.begin())->getTextCharacterProperties()).maCharColor;
56 }
57 }
58
insertAt(const::oox::core::XmlFilterBase & rFilterBase,const Reference<XText> & xText,const Reference<XTextCursor> & xAt,const TextCharacterProperties & rTextStyleProperties,const TextListStyle & rTextListStyle,bool bFirst) const59 void TextParagraph::insertAt(
60 const ::oox::core::XmlFilterBase& rFilterBase,
61 const Reference < XText > &xText,
62 const Reference < XTextCursor > &xAt,
63 const TextCharacterProperties& rTextStyleProperties,
64 const TextListStyle& rTextListStyle, bool bFirst) const
65 {
66 try {
67 sal_Int32 nParagraphSize = 0;
68 Reference< XTextRange > xStart( xAt, UNO_QUERY );
69
70 sal_Int16 nLevel = maProperties.getLevel();
71 const TextParagraphPropertiesVector& rListStyle = rTextListStyle.getListStyle();
72 if ( nLevel >= static_cast< sal_Int16 >( rListStyle.size() ) )
73 nLevel = 0;
74 TextParagraphPropertiesPtr pTextParagraphStyle;
75 if ( rListStyle.size() )
76 pTextParagraphStyle = rListStyle[ nLevel ];
77
78 TextCharacterProperties aTextCharacterStyle( rTextStyleProperties );
79 if ( pTextParagraphStyle.get() )
80 aTextCharacterStyle.assignUsed( pTextParagraphStyle->getTextCharacterProperties() );
81 aTextCharacterStyle.assignUsed( maProperties.getTextCharacterProperties() );
82
83 if( !bFirst )
84 {
85 xText->insertControlCharacter( xStart, ControlCharacter::APPEND_PARAGRAPH, sal_False );
86 xAt->gotoEnd( sal_True );
87 }
88 if ( maRuns.begin() == maRuns.end() )
89 {
90 PropertySet aPropSet( xStart );
91
92 TextCharacterProperties aTextCharacterProps( aTextCharacterStyle );
93 aTextCharacterProps.assignUsed( maEndProperties );
94 aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
95 }
96 else
97 {
98 for( TextRunVector::const_iterator aIt = maRuns.begin(), aEnd = maRuns.end(); aIt != aEnd; ++aIt )
99 {
100 (*aIt)->insertAt( rFilterBase, xText, xAt, aTextCharacterStyle );
101 nParagraphSize += (*aIt)->getText().getLength();
102 }
103 }
104 xAt->gotoEnd( sal_True );
105
106 PropertyMap aioBulletList;
107 Reference< XPropertySet > xProps( xStart, UNO_QUERY);
108 float fCharacterSize = 18;
109 if ( pTextParagraphStyle.get() )
110 {
111 pTextParagraphStyle->pushToPropSet( rFilterBase, xProps, aioBulletList, NULL, sal_False, fCharacterSize );
112 fCharacterSize = pTextParagraphStyle->getCharHeightPoints( 18 );
113 }
114
115 // bullet color inherits from closest text
116 if (maProperties.getBulletList().maBulletColorPtr && !(maProperties.getBulletList().maBulletColorPtr)->isUsed())
117 {
118 Color bulletClr;
119 lcl_getBulletclr(bulletClr, maRuns);
120 (maProperties.getBulletList().maBulletColorPtr)->assignIfUsed(bulletClr);
121 }
122
123 maProperties.pushToPropSet( rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), sal_True, fCharacterSize );
124
125 // empty paragraphs do not have bullets in ppt
126 if ( !nParagraphSize )
127 {
128 const OUString sNumberingLevel( CREATE_OUSTRING( "NumberingLevel" ) );
129 xProps->setPropertyValue( sNumberingLevel, Any( static_cast< sal_Int16 >( -1 ) ) );
130 }
131
132 // FIXME this is causing a lot of dispruption (ie does not work). I wonder what to do -- Hub
133 // Reference< XTextRange > xEnd( xAt, UNO_QUERY );
134 // Reference< XPropertySet > xProps2( xEnd, UNO_QUERY );
135 // mpEndProperties->pushToPropSet( xProps2 );
136 }
137 catch( Exception & )
138 {
139 OSL_TRACE("OOX: exception in TextParagraph::insertAt");
140 }
141 }
142
143
144 } }
145
146