bump product version to 6.3.0.0.beta1
[LibreOffice.git] / oox / source / drawingml / textbodycontext.cxx
blobcbd1e420ee5a7d45f4d10d9d0f6e2f6335b6c708
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/textbodycontext.hxx>
21 #include <drawingml/textbodypropertiescontext.hxx>
22 #include <drawingml/textparagraph.hxx>
23 #include <drawingml/textparagraphpropertiescontext.hxx>
24 #include <drawingml/textcharacterpropertiescontext.hxx>
25 #include <drawingml/textliststylecontext.hxx>
26 #include <drawingml/textfield.hxx>
27 #include <drawingml/textfieldcontext.hxx>
28 #include <oox/drawingml/shape.hxx>
29 #include <oox/token/namespaces.hxx>
30 #include <oox/token/tokens.hxx>
32 #include <oox/mathml/import.hxx>
34 #include <sal/log.hxx>
36 using namespace ::oox::core;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::text;
39 using namespace ::com::sun::star::xml::sax;
41 namespace oox { namespace drawingml {
43 // CT_TextParagraph
44 class TextParagraphContext : public ContextHandler2
46 public:
47 TextParagraphContext( ContextHandler2Helper const & rParent, TextParagraph& rPara );
49 virtual ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs ) override;
51 protected:
52 TextParagraph& mrParagraph;
55 TextParagraphContext::TextParagraphContext( ContextHandler2Helper const & rParent, TextParagraph& rPara )
56 : ContextHandler2( rParent )
57 , mrParagraph( rPara )
59 mbEnableTrimSpace = false;
62 ContextHandlerRef TextParagraphContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
64 // EG_TextRun
65 switch( aElementToken )
67 case A_TOKEN( r ): // "CT_RegularTextRun" Regular Text Run.
68 case W_TOKEN( r ):
70 TextRunPtr pRun( new TextRun );
71 mrParagraph.addRun( pRun );
72 return new RegularTextRunContext( *this, pRun );
74 case A_TOKEN( br ): // "CT_TextLineBreak" Soft return line break (vertical tab).
76 TextRunPtr pRun( new TextRun );
77 pRun->setLineBreak();
78 mrParagraph.addRun( pRun );
79 return new RegularTextRunContext( *this, pRun );
81 case A_TOKEN( fld ): // "CT_TextField" Text Field.
83 std::shared_ptr< TextField > pField( new TextField );
84 mrParagraph.addRun( pField );
85 return new TextFieldContext( *this, rAttribs, *pField );
87 case A_TOKEN( pPr ):
88 case W_TOKEN( pPr ):
89 return new TextParagraphPropertiesContext( *this, rAttribs, mrParagraph.getProperties() );
90 case A_TOKEN( endParaRPr ):
91 return new TextCharacterPropertiesContext( *this, rAttribs, mrParagraph.getEndProperties() );
92 case W_TOKEN( sdt ):
93 case W_TOKEN( sdtContent ):
94 return this;
95 case W_TOKEN( del ):
96 break;
97 case W_TOKEN( ins ):
98 return this;
99 break;
100 case OOX_TOKEN(a14, m):
101 return CreateLazyMathBufferingContext(*this, mrParagraph);
102 break;
103 default:
104 SAL_WARN("oox", "TextParagraphContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
107 return nullptr;
110 RegularTextRunContext::RegularTextRunContext( ContextHandler2Helper const & rParent, TextRunPtr const & pRunPtr )
111 : ContextHandler2( rParent )
112 , mpRunPtr( pRunPtr )
113 , mbIsInText( false )
117 void RegularTextRunContext::onEndElement( )
119 switch( getCurrentElement() )
121 case A_TOKEN( t ):
122 case W_TOKEN( t ):
124 mbIsInText = false;
125 break;
127 case A_TOKEN( r ):
128 break;
132 void RegularTextRunContext::onCharacters( const OUString& aChars )
134 if( mbIsInText )
136 mpRunPtr->getText() += aChars;
140 ContextHandlerRef RegularTextRunContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs)
142 switch( aElementToken )
144 case A_TOKEN( rPr ): // "CT_TextCharPropertyBag" The text char properties of this text run.
145 case W_TOKEN( rPr ):
146 return new TextCharacterPropertiesContext( *this, rAttribs, mpRunPtr->getTextCharacterProperties() );
147 case A_TOKEN( t ): // "xsd:string" minOccurs="1" The actual text string.
148 case W_TOKEN( t ):
149 mbIsInText = true;
150 break;
151 case W_TOKEN( drawing ):
152 break;
153 default:
154 SAL_WARN("oox", "RegularTextRunContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
155 break;
158 return this;
161 TextBodyContext::TextBodyContext( ContextHandler2Helper const & rParent, TextBody& rTextBody )
162 : ContextHandler2( rParent )
163 , mrTextBody( rTextBody )
167 TextBodyContext::TextBodyContext(ContextHandler2Helper const& rParent, const ShapePtr& pShapePtr)
168 : TextBodyContext(rParent, *pShapePtr->getTextBody())
170 mpShapePtr = pShapePtr;
173 ContextHandlerRef TextBodyContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
175 switch( aElementToken )
177 case A_TOKEN( bodyPr ): // CT_TextBodyPropertyBag
178 if ( mpShapePtr )
179 return new TextBodyPropertiesContext( *this, rAttribs, mpShapePtr );
180 else
181 return new TextBodyPropertiesContext( *this, rAttribs, mrTextBody.getTextProperties() );
182 case A_TOKEN( lstStyle ): // CT_TextListStyle
183 return new TextListStyleContext( *this, mrTextBody.getTextListStyle() );
184 case A_TOKEN( p ): // CT_TextParagraph
185 case W_TOKEN( p ):
186 return new TextParagraphContext( *this, mrTextBody.addParagraph() );
187 case W_TOKEN( sdt ):
188 case W_TOKEN( sdtContent ):
189 return this;
190 case W_TOKEN( sdtPr ):
191 case W_TOKEN( sdtEndPr ):
192 break;
193 case W_TOKEN( tbl ):
194 break;
195 default:
196 SAL_WARN("oox", "TextBodyContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
199 return nullptr;
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */