LibreOffice Module oox (master) 1
textbody.cxx
Go to the documentation of this file.
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
21#include <com/sun/star/beans/XPropertySet.hpp>
24#include <oox/token/properties.hxx>
25
26using namespace ::com::sun::star::uno;
27using namespace ::com::sun::star::text;
28using namespace ::com::sun::star::beans;
29
30namespace oox::drawingml {
31
33 : mbHasNoninheritedBodyProperties( false )
34{
35}
36
38 : mbHasNoninheritedBodyProperties( false )
39{
40 if( pBody ) {
41 maTextProperties = pBody->maTextProperties;
42 maTextListStyle = pBody->maTextListStyle;
43 }
44}
45
47{
48 auto xPara = std::make_shared<TextParagraph>();
49 maParagraphs.push_back( xPara );
50 return *xPara;
51}
52
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
59{
60 TextListStyle aMasterTextStyle(*pMasterTextListStylePtr);
61
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)
66 {
67 paragraph->insertAt(rFilterBase, xText, xAt, rTextStyleProperties, aMasterTextStyle,
68 maTextListStyle, (nIndex == 0), nCharHeight, getTextProperties().mnFontScale);
69 ++nIndex;
70 }
71}
72
74{
75 if (maParagraphs.empty())
76 return true;
77 if ( maParagraphs.size() > 1 )
78 return false;
79
80 const TextRunVector& rRuns = maParagraphs[0]->getRuns();
81 if ( rRuns.empty() )
82 return true;
83 if ( rRuns.size() > 1 )
84 return false;
85
86 return rRuns[0]->getText().isEmpty();
87}
88
89OUString TextBody::toString() const
90{
91 if (!isEmpty())
92 {
93 const TextRunVector& rRuns = maParagraphs.front()->getRuns();
94 if(!rRuns.empty())
95 return rRuns.front()->getText();
96 }
97 return OUString();
98}
99
101{
102 for ( auto& pTextParagraph : getParagraphs() )
103 {
104 if ( pTextParagraph->hasVisualRunProperties() )
105 return true;
106 }
107 return false;
108}
109
111{
112 for ( auto& pTextParagraph : getParagraphs() )
113 {
114 if ( pTextParagraph->hasProperties() )
115 return true;
116 }
117 return false;
118}
119
121 const ::oox::core::XmlFilterBase& rFilterBase,
122 const Reference < XText > & xText,
123 const TextCharacterProperties& rTextStyleProperties,
124 const TextListStylePtr& pMasterTextListStylePtr) const
125{
126 assert(isEmpty());
127
128 if (maParagraphs.empty())
129 return;
130
131 // Apply character properties
132 PropertySet aPropSet(xText);
133 TextCharacterProperties aTextCharacterProps(maParagraphs[0]->getCharacterStyle(
134 rTextStyleProperties, *pMasterTextListStylePtr, maTextListStyle));
135 aTextCharacterProps.pushToPropSet(aPropSet, rFilterBase);
136
137 // Apply paragraph properties
138 TextListStyle aCombinedTextStyle;
139 aCombinedTextStyle.apply(*pMasterTextListStylePtr);
140 aCombinedTextStyle.apply(maTextListStyle);
141
142 TextParagraphProperties* pTextParagraphStyle = maParagraphs[0]->getParagraphStyle(aCombinedTextStyle);
143 if (pTextParagraphStyle)
144 {
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, getTextProperties().mnFontScale, true);
153 }
154}
155
156}
157
158/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:72
A wrapper for a UNO property set.
Definition: propertyset.hxx:58
const TextParagraphVector & getParagraphs() const
Definition: textbody.hxx:47
bool isEmpty() const
Definition: textbody.cxx:73
TextListStyle maTextListStyle
Definition: textbody.hxx:96
void insertAt(const ::oox::core::XmlFilterBase &rFilterBase, const css::uno::Reference< css::text::XText > &xText, const css::uno::Reference< css::text::XTextCursor > &xAt, const TextCharacterProperties &rTextStyleProperties, const TextListStylePtr &pMasterTextListStyle) const
insert the text body at the text cursor
Definition: textbody.cxx:53
TextParagraph & addParagraph()
Definition: textbody.cxx:46
TextParagraphVector maParagraphs
Definition: textbody.hxx:92
void ApplyStyleEmpty(const ::oox::core::XmlFilterBase &rFilterBase, const css::uno::Reference< css::text::XText > &xText, const TextCharacterProperties &rTextStyleProperties, const TextListStylePtr &pMasterTextListStylePtr) const
Definition: textbody.cxx:120
bool hasVisualRunProperties() const
Returns whether the textbody had a rPr tag in it that alters it visually.
Definition: textbody.cxx:100
OUString toString() const
Definition: textbody.cxx:89
TextBodyProperties maTextProperties
Definition: textbody.hxx:93
const TextBodyProperties & getTextProperties() const
Definition: textbody.hxx:53
bool hasParagraphProperties() const
Returns whether the textbody had a pPr tag in it.
Definition: textbody.cxx:110
void apply(const TextListStyle &rTextListStyle)
void apply(const TextParagraphProperties &rSourceProps)
sal_Int32 nIndex
@ paragraph
std::shared_ptr< TextListStyle > TextListStylePtr
std::shared_ptr< TextBody > TextBodyPtr
sal_Int32 mnFontScale
Normal autofit: font scale (default: 100%).
void pushToPropSet(PropertySet &rPropSet, const ::oox::core::XmlFilterBase &rFilter) const
Writes the properties to the passed property set.
constexpr OUStringLiteral PROP_LeftMargin