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"
29 using namespace ::oox::core
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::text
;
32 using namespace ::com::sun::star::xml::sax
;
34 namespace oox
{ namespace drawingml
{
37 class TextParagraphContext
: public ContextHandler2
40 TextParagraphContext( ContextHandler2Helper
& rParent
, TextParagraph
& rPara
);
42 virtual ContextHandlerRef
onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
) SAL_OVERRIDE
;
45 TextParagraph
& mrParagraph
;
48 TextParagraphContext::TextParagraphContext( ContextHandler2Helper
& rParent
, TextParagraph
& rPara
)
49 : ContextHandler2( rParent
)
50 , mrParagraph( rPara
)
52 mbEnableTrimSpace
= false;
55 ContextHandlerRef
TextParagraphContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
58 switch( aElementToken
)
60 case A_TOKEN( r
): // "CT_RegularTextRun" Regular Text Run.
63 TextRunPtr
pRun( new TextRun
);
64 mrParagraph
.addRun( pRun
);
65 return new RegularTextRunContext( *this, pRun
);
67 case A_TOKEN( br
): // "CT_TextLineBreak" Soft return line break (vertical tab).
69 TextRunPtr
pRun( new TextRun
);
71 mrParagraph
.addRun( pRun
);
72 return new RegularTextRunContext( *this, pRun
);
74 case A_TOKEN( fld
): // "CT_TextField" Text Field.
76 TextFieldPtr
pField( new TextField
);
77 mrParagraph
.addRun( pField
);
78 return new TextFieldContext( *this, rAttribs
, *pField
);
82 return new TextParagraphPropertiesContext( *this, rAttribs
, mrParagraph
.getProperties() );
83 case A_TOKEN( endParaRPr
):
84 return new TextCharacterPropertiesContext( *this, rAttribs
, mrParagraph
.getEndProperties() );
86 case W_TOKEN( sdtContent
):
94 SAL_WARN("oox", "TextParagraphContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken
));
100 RegularTextRunContext::RegularTextRunContext( ContextHandler2Helper
& rParent
, TextRunPtr pRunPtr
)
101 : ContextHandler2( rParent
)
102 , mpRunPtr( pRunPtr
)
103 , mbIsInText( false )
107 void RegularTextRunContext::onEndElement( )
109 switch( getCurrentElement() )
122 void RegularTextRunContext::onCharacters( const OUString
& aChars
)
126 mpRunPtr
->getText() += aChars
;
130 ContextHandlerRef
RegularTextRunContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
132 switch( aElementToken
)
134 case A_TOKEN( rPr
): // "CT_TextCharPropertyBag" The text char properties of this text run.
136 return new TextCharacterPropertiesContext( *this, rAttribs
, mpRunPtr
->getTextCharacterProperties() );
137 case A_TOKEN( t
): // "xsd:string" minOccurs="1" The actual text string.
141 case W_TOKEN( drawing
):
144 SAL_WARN("oox", "RegularTextRunContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken
));
151 TextBodyContext::TextBodyContext( ContextHandler2Helper
& rParent
, TextBody
& rTextBody
)
152 : ContextHandler2( rParent
)
153 , mrTextBody( rTextBody
)
157 ContextHandlerRef
TextBodyContext::onCreateContext( sal_Int32 aElementToken
, const AttributeList
& rAttribs
)
159 switch( aElementToken
)
161 case A_TOKEN( bodyPr
): // CT_TextBodyPropertyBag
162 return new TextBodyPropertiesContext( *this, rAttribs
, mrTextBody
.getTextProperties() );
163 case A_TOKEN( lstStyle
): // CT_TextListStyle
164 return new TextListStyleContext( *this, mrTextBody
.getTextListStyle() );
165 case A_TOKEN( p
): // CT_TextParagraph
167 return new TextParagraphContext( *this, mrTextBody
.addParagraph() );
169 case W_TOKEN( sdtContent
):
171 case W_TOKEN( sdtPr
):
172 case W_TOKEN( sdtEndPr
):
177 SAL_WARN("oox", "TextBodyContext::onCreateContext: unhandled element: " << getBaseToken(aElementToken
));
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */