nss: upgrade to release 3.73
[LibreOffice.git] / oox / source / drawingml / textbody.cxx
blob1abe31db984ed71cc5b0432c65627e0dc67d585c
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()
36 TextBody::TextBody( const TextBodyPtr& pBody )
38 if( 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 );
48 return *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>();
69 size_t nIndex = 0;
70 for (auto const& paragraph : maParagraphs)
72 paragraph->insertAt( rFilterBase, xText, xAt, rTextStyleProperties, aCombinedTextStyle, (nIndex == 0), nCharHeight );
73 ++nIndex;
77 bool TextBody::isEmpty() const
79 if (maParagraphs.empty())
80 return true;
81 if ( maParagraphs.size() > 1 )
82 return false;
84 const TextRunVector aRuns = maParagraphs[0]->getRuns();
85 if ( aRuns.empty() )
86 return true;
87 if ( aRuns.size() > 1 )
88 return false;
90 return aRuns[0]->getText().getLength() <= 0;
93 OUString TextBody::toString() const
95 if (!isEmpty())
96 return maParagraphs.front()->getRuns().front()->getText();
97 else
98 return OUString();
101 void TextBody::ApplyStyleEmpty(
102 const ::oox::core::XmlFilterBase& rFilterBase,
103 const Reference < XText > & xText,
104 const TextCharacterProperties& rTextStyleProperties,
105 const TextListStylePtr& pMasterTextListStylePtr) const
107 assert(isEmpty());
109 if (maParagraphs.empty())
110 return;
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: */