/src/libreoffice/oox/source/drawingml/textbody.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <drawingml/textbody.hxx> |
21 | | #include <com/sun/star/beans/XPropertySet.hpp> |
22 | | #include <com/sun/star/style/XStyle.hpp> |
23 | | #include <drawingml/textparagraph.hxx> |
24 | | #include <oox/helper/propertyset.hxx> |
25 | | #include <oox/token/properties.hxx> |
26 | | |
27 | | using namespace ::com::sun::star::uno; |
28 | | using namespace ::com::sun::star::text; |
29 | | using namespace ::com::sun::star::beans; |
30 | | |
31 | | namespace oox::drawingml { |
32 | | |
33 | | TextBody::TextBody() |
34 | 12.1k | : mbHasNoninheritedBodyProperties( false ) |
35 | 12.1k | { |
36 | 12.1k | } |
37 | | |
38 | | TextBody::TextBody( const TextBodyPtr& pBody ) |
39 | 91.1k | : mbHasNoninheritedBodyProperties( false ) |
40 | 91.1k | { |
41 | 91.1k | if( pBody ) { |
42 | 24.8k | maTextProperties = pBody->maTextProperties; |
43 | 24.8k | maTextListStyle = pBody->maTextListStyle; |
44 | 24.8k | } |
45 | 91.1k | } |
46 | | |
47 | | TextParagraph& TextBody::addParagraph() |
48 | 167k | { |
49 | 167k | auto xPara = std::make_shared<TextParagraph>(); |
50 | 167k | maParagraphs.push_back( xPara ); |
51 | 167k | return *xPara; |
52 | 167k | } |
53 | | |
54 | | void TextBody::insertAt( |
55 | | const ::oox::core::XmlFilterBase& rFilterBase, |
56 | | const Reference < XText > & xText, |
57 | | const Reference < XTextCursor > & xAt, |
58 | | const TextCharacterProperties& rTextStyleProperties, |
59 | | const TextListStylePtr& pMasterTextListStylePtr ) const |
60 | 47.1k | { |
61 | 47.1k | Reference<css::beans::XPropertySet> xPropertySet(xAt, UNO_QUERY); |
62 | 47.1k | float nCharHeight = xPropertySet->getPropertyValue(u"CharHeight"_ustr).get<float>(); |
63 | 47.1k | size_t nIndex = 0; |
64 | 47.1k | for (auto const& paragraph : maParagraphs) |
65 | 65.4k | { |
66 | 65.4k | paragraph->insertAt(rFilterBase, xText, xAt, rTextStyleProperties, *pMasterTextListStylePtr, |
67 | 65.4k | maTextListStyle, (nIndex == 0), nCharHeight); |
68 | 65.4k | ++nIndex; |
69 | 65.4k | } |
70 | 47.1k | } |
71 | | |
72 | | bool TextBody::isEmpty() const |
73 | 96.9k | { |
74 | 96.9k | if (maParagraphs.empty()) |
75 | 0 | return true; |
76 | 96.9k | if ( maParagraphs.size() > 1 ) |
77 | 8.92k | return false; |
78 | | |
79 | 87.9k | const TextRunVector& rRuns = maParagraphs[0]->getRuns(); |
80 | 87.9k | if ( rRuns.empty() ) |
81 | 43.8k | return true; |
82 | 44.1k | if ( rRuns.size() > 1 ) |
83 | 73 | return false; |
84 | | |
85 | 44.0k | return rRuns[0]->getText().isEmpty(); |
86 | 44.1k | } |
87 | | |
88 | | OUString TextBody::toString() const |
89 | 357 | { |
90 | 357 | if (!isEmpty()) |
91 | 357 | { |
92 | 357 | const TextRunVector& rRuns = maParagraphs.front()->getRuns(); |
93 | 357 | if(!rRuns.empty()) |
94 | 357 | return rRuns.front()->getText(); |
95 | 357 | } |
96 | 0 | return OUString(); |
97 | 357 | } |
98 | | |
99 | | OUString TextBody::firstParatoString() const |
100 | 0 | { |
101 | 0 | OUStringBuffer aRet; |
102 | 0 | if (!isEmpty()) |
103 | 0 | { |
104 | 0 | const TextRunVector& rRuns = maParagraphs.front()->getRuns(); |
105 | 0 | for (TextRunVector::const_iterator aRIt = rRuns.begin(), aREnd = rRuns.end(); aRIt != aREnd; ++aRIt) |
106 | 0 | { |
107 | 0 | const TextRun& rTextRun = **aRIt; |
108 | 0 | aRet.append(rTextRun.getText()); |
109 | 0 | } |
110 | 0 | } |
111 | 0 | return aRet.makeStringAndClear(); |
112 | 0 | } |
113 | | |
114 | | bool TextBody::hasVisualRunProperties() const |
115 | 24 | { |
116 | 24 | for ( auto& pTextParagraph : getParagraphs() ) |
117 | 24 | { |
118 | 24 | if ( pTextParagraph->hasVisualRunProperties() ) |
119 | 24 | return true; |
120 | 24 | } |
121 | 0 | return false; |
122 | 24 | } |
123 | | |
124 | | bool TextBody::hasParagraphProperties() const |
125 | 0 | { |
126 | 0 | for ( auto& pTextParagraph : getParagraphs() ) |
127 | 0 | { |
128 | 0 | if ( pTextParagraph->hasProperties() ) |
129 | 0 | return true; |
130 | 0 | } |
131 | 0 | return false; |
132 | 0 | } |
133 | | |
134 | | void TextBody::ApplyStyleEmpty( |
135 | | const ::oox::core::XmlFilterBase& rFilterBase, |
136 | | const Reference < XText > & xText, |
137 | | const TextCharacterProperties& rTextStyleProperties, |
138 | | const TextListStylePtr& pMasterTextListStylePtr) const |
139 | 293 | { |
140 | 293 | assert(isEmpty()); |
141 | | |
142 | 293 | if (maParagraphs.empty()) |
143 | 0 | return; |
144 | | |
145 | | // Apply character properties |
146 | 293 | PropertySet aPropSet(xText); |
147 | 293 | TextCharacterProperties aTextCharacterProps(maParagraphs[0]->getCharacterStyle( |
148 | 293 | rTextStyleProperties, *pMasterTextListStylePtr, maTextListStyle)); |
149 | 293 | aTextCharacterProps.pushToPropSet(aPropSet, rFilterBase); |
150 | | |
151 | | // Apply paragraph properties |
152 | 293 | TextListStyle aCombinedTextStyle; |
153 | 293 | aCombinedTextStyle.apply(*pMasterTextListStylePtr); |
154 | 293 | aCombinedTextStyle.apply(maTextListStyle); |
155 | | |
156 | 293 | TextParagraphProperties* pTextParagraphStyle = maParagraphs[0]->getParagraphStyle(aCombinedTextStyle); |
157 | 293 | if (pTextParagraphStyle) |
158 | 293 | { |
159 | 293 | Reference< XPropertySet > xProps(xText, UNO_QUERY); |
160 | 293 | PropertyMap aioBulletList; |
161 | 293 | aioBulletList.setProperty< sal_Int32 >(PROP_LeftMargin, 0); // Init bullets left margin to 0 (no bullets). |
162 | 293 | float nCharHeight = xProps->getPropertyValue(u"CharHeight"_ustr).get<float>(); |
163 | 293 | TextParagraphProperties aParaProp; |
164 | 293 | aParaProp.apply(*pTextParagraphStyle); |
165 | 293 | aParaProp.pushToPropSet(&rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), |
166 | 293 | true, nCharHeight, true); |
167 | 293 | } |
168 | 293 | } |
169 | | |
170 | | void TextBody::ApplyMasterTextStyle( |
171 | | const ::oox::core::XmlFilterBase& rFilterBase, |
172 | | const css::uno::Reference< css::style::XStyle >& aXStyle, |
173 | | const TextCharacterProperties& rTextStyleProperties, |
174 | | const TextListStylePtr& pMasterTextListStylePtr, size_t nLevel) const |
175 | 63.8k | { |
176 | 63.8k | assert(!isEmpty()); |
177 | | |
178 | 63.8k | if (maParagraphs.empty() || maParagraphs.size() <= nLevel) |
179 | 35.5k | return; |
180 | | |
181 | | // Apply character properties |
182 | 28.2k | PropertySet aPropSet(aXStyle); |
183 | 28.2k | TextCharacterProperties aTextCharacterProps(maParagraphs[nLevel]->getCharacterStyle( |
184 | 28.2k | rTextStyleProperties, *pMasterTextListStylePtr, maTextListStyle)); |
185 | 28.2k | aTextCharacterProps.pushToPropSet(aPropSet, rFilterBase); |
186 | | |
187 | | // Apply paragraph properties |
188 | 28.2k | TextListStyle aCombinedTextStyle; |
189 | 28.2k | aCombinedTextStyle.apply(*pMasterTextListStylePtr); |
190 | 28.2k | aCombinedTextStyle.apply(maTextListStyle); |
191 | | |
192 | 28.2k | TextParagraphProperties* pTextParagraphStyle = maParagraphs[nLevel]->getParagraphStyle(aCombinedTextStyle); |
193 | 28.2k | if (pTextParagraphStyle) |
194 | 28.2k | { |
195 | 28.2k | Reference< XPropertySet > xProps(aXStyle, UNO_QUERY_THROW); |
196 | 28.2k | PropertyMap aioBulletList; |
197 | 28.2k | aioBulletList.setProperty< sal_Int32 >(PROP_LeftMargin, 0); // Init bullets left margin to 0 (no bullets). |
198 | 28.2k | float nCharHeight = xProps->getPropertyValue(u"CharHeight"_ustr).get<float>(); |
199 | 28.2k | TextParagraphProperties aParaProp; |
200 | 28.2k | aParaProp.apply(*pTextParagraphStyle); |
201 | 28.2k | aParaProp.pushToPropSet(&rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), |
202 | 28.2k | true, nCharHeight, true); |
203 | 28.2k | } |
204 | 28.2k | } |
205 | | |
206 | | } |
207 | | |
208 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |