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 
20 #include <drawingml/textbody.hxx>
21 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <oox/token/properties.hxx>
25 
26 using namespace ::com::sun::star::uno;
27 using namespace ::com::sun::star::text;
28 using namespace ::com::sun::star::beans;
29 
30 namespace 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 aCombinedTextStyle;
61  aCombinedTextStyle.apply( *pMasterTextListStylePtr );
62  aCombinedTextStyle.apply( maTextListStyle );
63 
64  Reference<css::beans::XPropertySet> xPropertySet(xAt, UNO_QUERY);
65  float nCharHeight = xPropertySet->getPropertyValue("CharHeight").get<float>();
66  size_t nIndex = 0;
67  for (auto const& paragraph : maParagraphs)
68  {
69  paragraph->insertAt( rFilterBase, xText, xAt, rTextStyleProperties, aCombinedTextStyle, (nIndex == 0), nCharHeight );
70  ++nIndex;
71  }
72 }
73 
74 bool TextBody::isEmpty() const
75 {
76  if (maParagraphs.empty())
77  return true;
78  if ( maParagraphs.size() > 1 )
79  return false;
80 
81  const TextRunVector aRuns = maParagraphs[0]->getRuns();
82  if ( aRuns.empty() )
83  return true;
84  if ( aRuns.size() > 1 )
85  return false;
86 
87  return aRuns[0]->getText().isEmpty();
88 }
89 
90 OUString TextBody::toString() const
91 {
92  if (!isEmpty())
93  return maParagraphs.front()->getRuns().front()->getText();
94  else
95  return OUString();
96 }
97 
99 {
100  for ( auto& pTextParagraph : getParagraphs() )
101  {
102  if ( pTextParagraph->hasVisualRunProperties() )
103  return true;
104  }
105  return false;
106 }
107 
109 {
110  for ( auto& pTextParagraph : getParagraphs() )
111  {
112  if ( pTextParagraph->hasProperties() )
113  return true;
114  }
115  return false;
116 }
117 
119  const ::oox::core::XmlFilterBase& rFilterBase,
120  const Reference < XText > & xText,
121  const TextCharacterProperties& rTextStyleProperties,
122  const TextListStylePtr& pMasterTextListStylePtr) const
123 {
124  assert(isEmpty());
125 
126  if (maParagraphs.empty())
127  return;
128 
129  // Apply character properties
130  TextListStyle aCombinedTextStyle;
131  aCombinedTextStyle.apply( *pMasterTextListStylePtr );
132  aCombinedTextStyle.apply( maTextListStyle );
133 
134  PropertySet aPropSet(xText);
135  TextCharacterProperties aTextCharacterProps(maParagraphs[0]->getCharacterStyle(rTextStyleProperties, aCombinedTextStyle));
136  aTextCharacterProps.pushToPropSet(aPropSet, rFilterBase);
137 
138  // Apply paragraph properties
139  TextParagraphProperties* pTextParagraphStyle = maParagraphs[0]->getParagraphStyle(aCombinedTextStyle);
140  if (pTextParagraphStyle)
141  {
142  Reference< XPropertySet > xProps(xText, UNO_QUERY);
143  PropertyMap aioBulletList;
144  aioBulletList.setProperty< sal_Int32 >(PROP_LeftMargin, 0); // Init bullets left margin to 0 (no bullets).
145  float nCharHeight = xProps->getPropertyValue("CharHeight").get<float>();
146  TextParagraphProperties aParaProp;
147  aParaProp.apply(*pTextParagraphStyle);
148  aParaProp.pushToPropSet(&rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), true, nCharHeight, true);
149  }
150 }
151 
152 }
153 
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
TextParagraphVector maParagraphs
Definition: textbody.hxx:92
sal_Int32 nIndex
TextListStyle maTextListStyle
Definition: textbody.hxx:96
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
bool isEmpty() const
Definition: textbody.cxx:74
void apply(const TextListStyle &rTextListStyle)
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:70
TextBodyProperties maTextProperties
Definition: textbody.hxx:93
bool hasParagraphProperties() const
Returns whether the textbody had a pPr tag in it.
Definition: textbody.cxx:108
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:118
TextParagraph & addParagraph()
Definition: textbody.cxx:46
bool hasVisualRunProperties() const
Returns whether the textbody had a rPr tag in it that alters it visually.
Definition: textbody.cxx:98
void apply(const TextParagraphProperties &rSourceProps)
std::shared_ptr< TextBody > TextBodyPtr
A wrapper for a UNO property set.
Definition: propertyset.hxx:57
std::shared_ptr< TextListStyle > TextListStylePtr
const TextParagraphVector & getParagraphs() const
Definition: textbody.hxx:47
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
OUString toString() const
Definition: textbody.cxx:90
void pushToPropSet(PropertySet &rPropSet, const ::oox::core::XmlFilterBase &rFilter) const
Writes the properties to the passed property set.