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/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
{
41 class TextParagraphContext
: public ContextHandler2
44 TextParagraphContext( ContextHandler2Helper
& rParent
, TextParagraph
& rPara
);
46 virtual ContextHandlerRef
onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
) override
;
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
)
62 switch( aElementToken
)
64 case A_TOKEN( r
): // "CT_RegularTextRun" Regular Text Run.
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
);
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
);
86 return new TextParagraphPropertiesContext( *this, rAttribs
, mrParagraph
.getProperties() );
87 case A_TOKEN( endParaRPr
):
88 return new TextCharacterPropertiesContext( *this, rAttribs
, mrParagraph
.getEndProperties() );
90 case W_TOKEN( sdtContent
):
97 case OOX_TOKEN(a14
, m
):
98 return CreateLazyMathBufferingContext(*this, mrParagraph
);
101 SAL_WARN("oox", "TextParagraphContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken
));
107 RegularTextRunContext::RegularTextRunContext( ContextHandler2Helper
& rParent
, TextRunPtr
const & pRunPtr
)
108 : ContextHandler2( rParent
)
109 , mpRunPtr( pRunPtr
)
110 , mbIsInText( false )
114 void RegularTextRunContext::onEndElement( )
116 switch( getCurrentElement() )
129 void RegularTextRunContext::onCharacters( const OUString
& aChars
)
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.
143 return new TextCharacterPropertiesContext( *this, rAttribs
, mpRunPtr
->getTextCharacterProperties() );
144 case A_TOKEN( t
): // "xsd:string" minOccurs="1" The actual text string.
148 case W_TOKEN( drawing
):
151 SAL_WARN("oox", "RegularTextRunContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken
));
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
174 return new TextParagraphContext( *this, mrTextBody
.addParagraph() );
176 case W_TOKEN( sdtContent
):
178 case W_TOKEN( sdtPr
):
179 case W_TOKEN( sdtEndPr
):
184 SAL_WARN("oox", "TextBodyContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken
));
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */