1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
{
44 class TextParagraphContext
: public ContextHandler2
47 TextParagraphContext( ContextHandler2Helper
const & rParent
, TextParagraph
& rPara
);
49 virtual ContextHandlerRef
onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
) override
;
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
)
65 switch( aElementToken
)
67 case A_TOKEN( r
): // "CT_RegularTextRun" Regular Text Run.
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
);
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
);
89 return new TextParagraphPropertiesContext( *this, rAttribs
, mrParagraph
.getProperties() );
90 case A_TOKEN( endParaRPr
):
91 return new TextCharacterPropertiesContext( *this, rAttribs
, mrParagraph
.getEndProperties() );
93 case W_TOKEN( sdtContent
):
100 case OOX_TOKEN(a14
, m
):
101 return CreateLazyMathBufferingContext(*this, mrParagraph
);
104 SAL_WARN("oox", "TextParagraphContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken
));
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() )
132 void RegularTextRunContext::onCharacters( const OUString
& aChars
)
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.
146 return new TextCharacterPropertiesContext( *this, rAttribs
, mpRunPtr
->getTextCharacterProperties() );
147 case A_TOKEN( t
): // "xsd:string" minOccurs="1" The actual text string.
151 case W_TOKEN( drawing
):
154 SAL_WARN("oox", "RegularTextRunContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken
));
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
179 return new TextBodyPropertiesContext( *this, rAttribs
, mpShapePtr
);
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
186 return new TextParagraphContext( *this, mrTextBody
.addParagraph() );
188 case W_TOKEN( sdtContent
):
190 case W_TOKEN( sdtPr
):
191 case W_TOKEN( sdtEndPr
):
196 SAL_WARN("oox", "TextBodyContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken
));
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */