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
;
32 namespace oox
{ namespace drawingml
{
38 TextBody::TextBody( const TextBodyPtr
& pBody
)
41 maTextProperties
= pBody
->maTextProperties
;
42 maTextListStyle
= pBody
->maTextListStyle
;
50 TextParagraph
& TextBody::addParagraph()
52 std::shared_ptr
< TextParagraph
> xPara( new TextParagraph
);
53 maParagraphs
.push_back( xPara
);
57 void TextBody::appendParagraph(std::shared_ptr
<TextParagraph
> pTextParagraph
)
59 maParagraphs
.push_back(pTextParagraph
);
62 void TextBody::insertAt(
63 const ::oox::core::XmlFilterBase
& rFilterBase
,
64 const Reference
< XText
> & xText
,
65 const Reference
< XTextCursor
> & xAt
,
66 const TextCharacterProperties
& rTextStyleProperties
,
67 const TextListStylePtr
& pMasterTextListStylePtr
) const
69 TextListStyle aCombinedTextStyle
;
70 aCombinedTextStyle
.apply( *pMasterTextListStylePtr
);
71 aCombinedTextStyle
.apply( maTextListStyle
);
73 Reference
<css::beans::XPropertySet
> xPropertySet(xAt
, UNO_QUERY
);
74 float nCharHeight
= xPropertySet
->getPropertyValue("CharHeight").get
<float>();
76 for (auto const& paragraph
: maParagraphs
)
78 paragraph
->insertAt( rFilterBase
, xText
, xAt
, rTextStyleProperties
, aCombinedTextStyle
, (nIndex
== 0), nCharHeight
);
83 bool TextBody::isEmpty() const
85 if (maParagraphs
.empty())
87 if ( maParagraphs
.size() > 1 )
90 const TextRunVector aRuns
= maParagraphs
[0]->getRuns();
93 if ( aRuns
.size() > 1 )
96 return aRuns
[0]->getText().getLength() <= 0;
99 OUString
TextBody::toString() const
102 return maParagraphs
.front()->getRuns().front()->getText();
107 void TextBody::ApplyStyleEmpty(
108 const ::oox::core::XmlFilterBase
& rFilterBase
,
109 const Reference
< XText
> & xText
,
110 const TextCharacterProperties
& rTextStyleProperties
,
111 const TextListStylePtr
& pMasterTextListStylePtr
) const
115 if (maParagraphs
.empty())
118 // Apply character properties
119 TextListStyle aCombinedTextStyle
;
120 aCombinedTextStyle
.apply( *pMasterTextListStylePtr
);
121 aCombinedTextStyle
.apply( maTextListStyle
);
123 PropertySet
aPropSet(xText
);
124 TextCharacterProperties
aTextCharacterProps(maParagraphs
[0]->getCharacterStyle(rTextStyleProperties
, aCombinedTextStyle
));
125 aTextCharacterProps
.pushToPropSet(aPropSet
, rFilterBase
);
127 // Apply paragraph properties
128 TextParagraphPropertiesPtr pTextParagraphStyle
= maParagraphs
[0]->getParagraphStyle(aCombinedTextStyle
);
129 if (pTextParagraphStyle
.get())
131 Reference
< XPropertySet
> xProps(xText
, UNO_QUERY
);
132 PropertyMap aioBulletList
;
133 aioBulletList
.setProperty
< sal_Int32
>(PROP_LeftMargin
, 0); // Init bullets left margin to 0 (no bullets).
134 float nCharHeight
= xProps
->getPropertyValue("CharHeight").get
<float>();
135 TextParagraphProperties aParaProp
;
136 aParaProp
.apply(*pTextParagraphStyle
);
137 aParaProp
.pushToPropSet(&rFilterBase
, xProps
, aioBulletList
, &pTextParagraphStyle
->getBulletList(), true, nCharHeight
, true);
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */