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/beans/XPropertySet.hpp>
22 #include <drawingml/textparagraph.hxx>
23 #include <oox/helper/propertyset.hxx>
24 #include <oox/token/properties.hxx>
26 using namespace ::com::sun::star::uno
;
27 using namespace ::com::sun::star::text
;
28 using namespace ::com::sun::star::beans
;
30 namespace oox::drawingml
{
36 TextBody::TextBody( const TextBodyPtr
& pBody
)
39 maTextProperties
= pBody
->maTextProperties
;
40 maTextListStyle
= pBody
->maTextListStyle
;
44 TextParagraph
& TextBody::addParagraph()
46 auto xPara
= std::make_shared
<TextParagraph
>();
47 maParagraphs
.push_back( xPara
);
51 void TextBody::appendParagraph(std::shared_ptr
<TextParagraph
> pTextParagraph
)
53 maParagraphs
.push_back(pTextParagraph
);
56 void TextBody::insertAt(
57 const ::oox::core::XmlFilterBase
& rFilterBase
,
58 const Reference
< XText
> & xText
,
59 const Reference
< XTextCursor
> & xAt
,
60 const TextCharacterProperties
& rTextStyleProperties
,
61 const TextListStylePtr
& pMasterTextListStylePtr
) const
63 TextListStyle aCombinedTextStyle
;
64 aCombinedTextStyle
.apply( *pMasterTextListStylePtr
);
65 aCombinedTextStyle
.apply( maTextListStyle
);
67 Reference
<css::beans::XPropertySet
> xPropertySet(xAt
, UNO_QUERY
);
68 float nCharHeight
= xPropertySet
->getPropertyValue("CharHeight").get
<float>();
70 for (auto const& paragraph
: maParagraphs
)
72 paragraph
->insertAt( rFilterBase
, xText
, xAt
, rTextStyleProperties
, aCombinedTextStyle
, (nIndex
== 0), nCharHeight
);
77 bool TextBody::isEmpty() const
79 if (maParagraphs
.empty())
81 if ( maParagraphs
.size() > 1 )
84 const TextRunVector aRuns
= maParagraphs
[0]->getRuns();
87 if ( aRuns
.size() > 1 )
90 return aRuns
[0]->getText().getLength() <= 0;
93 OUString
TextBody::toString() const
96 return maParagraphs
.front()->getRuns().front()->getText();
101 void TextBody::ApplyStyleEmpty(
102 const ::oox::core::XmlFilterBase
& rFilterBase
,
103 const Reference
< XText
> & xText
,
104 const TextCharacterProperties
& rTextStyleProperties
,
105 const TextListStylePtr
& pMasterTextListStylePtr
) const
109 if (maParagraphs
.empty())
112 // Apply character properties
113 TextListStyle aCombinedTextStyle
;
114 aCombinedTextStyle
.apply( *pMasterTextListStylePtr
);
115 aCombinedTextStyle
.apply( maTextListStyle
);
117 PropertySet
aPropSet(xText
);
118 TextCharacterProperties
aTextCharacterProps(maParagraphs
[0]->getCharacterStyle(rTextStyleProperties
, aCombinedTextStyle
));
119 aTextCharacterProps
.pushToPropSet(aPropSet
, rFilterBase
);
121 // Apply paragraph properties
122 TextParagraphPropertiesPtr pTextParagraphStyle
= maParagraphs
[0]->getParagraphStyle(aCombinedTextStyle
);
123 if (pTextParagraphStyle
)
125 Reference
< XPropertySet
> xProps(xText
, UNO_QUERY
);
126 PropertyMap aioBulletList
;
127 aioBulletList
.setProperty
< sal_Int32
>(PROP_LeftMargin
, 0); // Init bullets left margin to 0 (no bullets).
128 float nCharHeight
= xProps
->getPropertyValue("CharHeight").get
<float>();
129 TextParagraphProperties aParaProp
;
130 aParaProp
.apply(*pTextParagraphStyle
);
131 aParaProp
.pushToPropSet(&rFilterBase
, xProps
, aioBulletList
, &pTextParagraphStyle
->getBulletList(), true, nCharHeight
, true);
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */