Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / oox / source / drawingml / textbody.cxx
blob266ff44b22f9337ff2230b381800d7ba8b605779
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 {
32 TextBody::TextBody()
33 : mbHasNoninheritedBodyProperties( false )
37 TextBody::TextBody( const TextBodyPtr& pBody )
38 : mbHasNoninheritedBodyProperties( false )
40 if( pBody ) {
41 maTextProperties = pBody->maTextProperties;
42 maTextListStyle = pBody->maTextListStyle;
46 TextParagraph& TextBody::addParagraph()
48 auto xPara = std::make_shared<TextParagraph>();
49 maParagraphs.push_back( xPara );
50 return *xPara;
53 void TextBody::insertAt(
54 const ::oox::core::XmlFilterBase& rFilterBase,
55 const Reference < XText > & xText,
56 const Reference < XTextCursor > & xAt,
57 const TextCharacterProperties& rTextStyleProperties,
58 const TextListStylePtr& pMasterTextListStylePtr ) const
60 TextListStyle aMasterTextStyle(*pMasterTextListStylePtr);
62 Reference<css::beans::XPropertySet> xPropertySet(xAt, UNO_QUERY);
63 float nCharHeight = xPropertySet->getPropertyValue("CharHeight").get<float>();
64 size_t nIndex = 0;
65 for (auto const& paragraph : maParagraphs)
67 paragraph->insertAt(rFilterBase, xText, xAt, rTextStyleProperties, aMasterTextStyle,
68 maTextListStyle, (nIndex == 0), nCharHeight);
69 ++nIndex;
73 bool TextBody::isEmpty() const
75 if (maParagraphs.empty())
76 return true;
77 if ( maParagraphs.size() > 1 )
78 return false;
80 const TextRunVector& rRuns = maParagraphs[0]->getRuns();
81 if ( rRuns.empty() )
82 return true;
83 if ( rRuns.size() > 1 )
84 return false;
86 return rRuns[0]->getText().isEmpty();
89 OUString TextBody::toString() const
91 if (!isEmpty())
93 const TextRunVector& rRuns = maParagraphs.front()->getRuns();
94 if(!rRuns.empty())
95 return rRuns.front()->getText();
97 return OUString();
100 bool TextBody::hasVisualRunProperties() const
102 for ( auto& pTextParagraph : getParagraphs() )
104 if ( pTextParagraph->hasVisualRunProperties() )
105 return true;
107 return false;
110 bool TextBody::hasParagraphProperties() const
112 for ( auto& pTextParagraph : getParagraphs() )
114 if ( pTextParagraph->hasProperties() )
115 return true;
117 return false;
120 void TextBody::ApplyStyleEmpty(
121 const ::oox::core::XmlFilterBase& rFilterBase,
122 const Reference < XText > & xText,
123 const TextCharacterProperties& rTextStyleProperties,
124 const TextListStylePtr& pMasterTextListStylePtr) const
126 assert(isEmpty());
128 if (maParagraphs.empty())
129 return;
131 // Apply character properties
132 PropertySet aPropSet(xText);
133 TextCharacterProperties aTextCharacterProps(maParagraphs[0]->getCharacterStyle(
134 rTextStyleProperties, *pMasterTextListStylePtr, maTextListStyle));
135 aTextCharacterProps.pushToPropSet(aPropSet, rFilterBase);
137 // Apply paragraph properties
138 TextListStyle aCombinedTextStyle;
139 aCombinedTextStyle.apply(*pMasterTextListStylePtr);
140 aCombinedTextStyle.apply(maTextListStyle);
142 TextParagraphProperties* pTextParagraphStyle = maParagraphs[0]->getParagraphStyle(aCombinedTextStyle);
143 if (pTextParagraphStyle)
145 Reference< XPropertySet > xProps(xText, UNO_QUERY);
146 PropertyMap aioBulletList;
147 aioBulletList.setProperty< sal_Int32 >(PROP_LeftMargin, 0); // Init bullets left margin to 0 (no bullets).
148 float nCharHeight = xProps->getPropertyValue("CharHeight").get<float>();
149 TextParagraphProperties aParaProp;
150 aParaProp.apply(*pTextParagraphStyle);
151 aParaProp.pushToPropSet(&rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(),
152 true, nCharHeight, true);
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */