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/textbody.hxx"
21 #include <com/sun/star/text/XText.hpp>
22 #include <com/sun/star/text/XTextCursor.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include "drawingml/textparagraph.hxx"
25 #include "oox/helper/propertyset.hxx"
26 #include <oox/token/properties.hxx>
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::text
;
30 using namespace ::com::sun::star::beans
;
31 using namespace ::com::sun::star::frame
;
33 namespace oox
{ namespace drawingml
{
39 TextBody::TextBody( TextBodyPtr pBody
)
42 maTextProperties
= pBody
->maTextProperties
;
43 maTextListStyle
= pBody
->maTextListStyle
;
51 TextParagraph
& TextBody::addParagraph()
53 std::shared_ptr
< TextParagraph
> xPara( new TextParagraph
);
54 maParagraphs
.push_back( xPara
);
58 void TextBody::insertAt(
59 const ::oox::core::XmlFilterBase
& rFilterBase
,
60 const Reference
< XText
> & xText
,
61 const Reference
< XTextCursor
> & xAt
,
62 const TextCharacterProperties
& rTextStyleProperties
,
63 const TextListStylePtr
& pMasterTextListStylePtr
) const
65 TextListStyle aCombinedTextStyle
;
66 aCombinedTextStyle
.apply( *pMasterTextListStylePtr
);
67 aCombinedTextStyle
.apply( maTextListStyle
);
69 Reference
<css::beans::XPropertySet
> xPropertySet(xAt
, UNO_QUERY
);
70 float nCharHeight
= xPropertySet
->getPropertyValue("CharHeight").get
<float>();
71 for( TextParagraphVector::const_iterator aBeg
= maParagraphs
.begin(), aIt
= aBeg
, aEnd
= maParagraphs
.end(); aIt
!= aEnd
; ++aIt
)
72 (*aIt
)->insertAt( rFilterBase
, xText
, xAt
, rTextStyleProperties
, aCombinedTextStyle
, aIt
== aBeg
, nCharHeight
);
75 bool TextBody::isEmpty() const
77 if ( maParagraphs
.size() <= 0 )
79 if ( maParagraphs
.size() > 1 )
82 const TextRunVector aRuns
= maParagraphs
[0]->getRuns();
83 if ( aRuns
.size() <= 0 )
85 if ( aRuns
.size() > 1 )
88 return aRuns
[0]->getText().getLength() <= 0;
91 void TextBody::ApplyStyleEmpty(
92 const ::oox::core::XmlFilterBase
& rFilterBase
,
93 const Reference
< XText
> & xText
,
94 const TextCharacterProperties
& rTextStyleProperties
,
95 const TextListStylePtr
& pMasterTextListStylePtr
) const
99 // Apply character properties
100 TextListStyle aCombinedTextStyle
;
101 aCombinedTextStyle
.apply( *pMasterTextListStylePtr
);
102 aCombinedTextStyle
.apply( maTextListStyle
);
104 PropertySet
aPropSet(xText
);
105 TextCharacterProperties
aTextCharacterProps(maParagraphs
[0]->getCharacterStyle(rTextStyleProperties
, aCombinedTextStyle
));
106 aTextCharacterProps
.pushToPropSet(aPropSet
, rFilterBase
);
108 // Apply paragraph properties
109 TextParagraphPropertiesPtr pTextParagraphStyle
= maParagraphs
[0]->getParagraphStyle(aCombinedTextStyle
);
110 if (pTextParagraphStyle
.get())
112 Reference
< XPropertySet
> xProps(xText
, UNO_QUERY
);
113 PropertyMap aioBulletList
;
114 aioBulletList
.setProperty
< sal_Int32
>(PROP_LeftMargin
, 0); // Init bullets left margin to 0 (no bullets).
115 float nCharHeight
= xProps
->getPropertyValue("CharHeight").get
<float>();
116 TextParagraphProperties aParaProp
;
117 aParaProp
.apply(*pTextParagraphStyle
);
118 aParaProp
.pushToPropSet(&rFilterBase
, xProps
, aioBulletList
, &pTextParagraphStyle
->getBulletList(), true, nCharHeight
, true);
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */