Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / drawingml / textbodycontext.cxx
blob8ee91760a5e61422c32a73cd3836a5f3f1d9d6e7
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/token/namespaces.hxx>
29 #include <oox/token/tokens.hxx>
31 #include <oox/mathml/import.hxx>
33 using namespace ::oox::core;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::text;
36 using namespace ::com::sun::star::xml::sax;
38 namespace oox { namespace drawingml {
40 // CT_TextParagraph
41 class TextParagraphContext : public ContextHandler2
43 public:
44 TextParagraphContext( ContextHandler2Helper& rParent, TextParagraph& rPara );
46 virtual ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs ) override;
48 protected:
49 TextParagraph& mrParagraph;
52 TextParagraphContext::TextParagraphContext( ContextHandler2Helper& rParent, TextParagraph& rPara )
53 : ContextHandler2( rParent )
54 , mrParagraph( rPara )
56 mbEnableTrimSpace = false;
59 ContextHandlerRef TextParagraphContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
61 // EG_TextRun
62 switch( aElementToken )
64 case A_TOKEN( r ): // "CT_RegularTextRun" Regular Text Run.
65 case W_TOKEN( r ):
67 TextRunPtr pRun( new TextRun );
68 mrParagraph.addRun( pRun );
69 return new RegularTextRunContext( *this, pRun );
71 case A_TOKEN( br ): // "CT_TextLineBreak" Soft return line break (vertical tab).
73 TextRunPtr pRun( new TextRun );
74 pRun->setLineBreak();
75 mrParagraph.addRun( pRun );
76 return new RegularTextRunContext( *this, pRun );
78 case A_TOKEN( fld ): // "CT_TextField" Text Field.
80 std::shared_ptr< TextField > pField( new TextField );
81 mrParagraph.addRun( pField );
82 return new TextFieldContext( *this, rAttribs, *pField );
84 case A_TOKEN( pPr ):
85 case W_TOKEN( pPr ):
86 return new TextParagraphPropertiesContext( *this, rAttribs, mrParagraph.getProperties() );
87 case A_TOKEN( endParaRPr ):
88 return new TextCharacterPropertiesContext( *this, rAttribs, mrParagraph.getEndProperties() );
89 case W_TOKEN( sdt ):
90 case W_TOKEN( sdtContent ):
91 return this;
92 case W_TOKEN( del ):
93 break;
94 case W_TOKEN( ins ):
95 return this;
96 break;
97 case OOX_TOKEN(a14, m):
98 return CreateLazyMathBufferingContext(*this, mrParagraph);
99 break;
100 default:
101 SAL_WARN("oox", "TextParagraphContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
104 return nullptr;
107 RegularTextRunContext::RegularTextRunContext( ContextHandler2Helper& rParent, TextRunPtr const & pRunPtr )
108 : ContextHandler2( rParent )
109 , mpRunPtr( pRunPtr )
110 , mbIsInText( false )
114 void RegularTextRunContext::onEndElement( )
116 switch( getCurrentElement() )
118 case A_TOKEN( t ):
119 case W_TOKEN( t ):
121 mbIsInText = false;
122 break;
124 case A_TOKEN( r ):
125 break;
129 void RegularTextRunContext::onCharacters( const OUString& aChars )
131 if( mbIsInText )
133 mpRunPtr->getText() += aChars;
137 ContextHandlerRef RegularTextRunContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs)
139 switch( aElementToken )
141 case A_TOKEN( rPr ): // "CT_TextCharPropertyBag" The text char properties of this text run.
142 case W_TOKEN( rPr ):
143 return new TextCharacterPropertiesContext( *this, rAttribs, mpRunPtr->getTextCharacterProperties() );
144 case A_TOKEN( t ): // "xsd:string" minOccurs="1" The actual text string.
145 case W_TOKEN( t ):
146 mbIsInText = true;
147 break;
148 case W_TOKEN( drawing ):
149 break;
150 default:
151 SAL_WARN("oox", "RegularTextRunContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
152 break;
155 return this;
158 TextBodyContext::TextBodyContext( ContextHandler2Helper& rParent, TextBody& rTextBody )
159 : ContextHandler2( rParent )
160 , mrTextBody( rTextBody )
164 ContextHandlerRef TextBodyContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
166 switch( aElementToken )
168 case A_TOKEN( bodyPr ): // CT_TextBodyPropertyBag
169 return new TextBodyPropertiesContext( *this, rAttribs, mrTextBody.getTextProperties() );
170 case A_TOKEN( lstStyle ): // CT_TextListStyle
171 return new TextListStyleContext( *this, mrTextBody.getTextListStyle() );
172 case A_TOKEN( p ): // CT_TextParagraph
173 case W_TOKEN( p ):
174 return new TextParagraphContext( *this, mrTextBody.addParagraph() );
175 case W_TOKEN( sdt ):
176 case W_TOKEN( sdtContent ):
177 return this;
178 case W_TOKEN( sdtPr ):
179 case W_TOKEN( sdtEndPr ):
180 break;
181 case W_TOKEN( tbl ):
182 break;
183 default:
184 SAL_WARN("oox", "TextBodyContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken));
187 return nullptr;
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */