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 "oox/drawingml/textbodycontext.hxx"
21 #include "oox/drawingml/textbodypropertiescontext.hxx"
22 #include "oox/drawingml/textparagraph.hxx"
23 #include "oox/drawingml/textparagraphpropertiescontext.hxx"
24 #include "oox/drawingml/textcharacterpropertiescontext.hxx"
25 #include "oox/drawingml/textliststylecontext.hxx"
26 #include "oox/drawingml/textfield.hxx"
27 #include "oox/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
{
36 // --------------------------------------------------------------------
39 class TextParagraphContext
: public ContextHandler
42 TextParagraphContext( ContextHandler
& rParent
, TextParagraph
& rPara
);
44 virtual void SAL_CALL
endFastElement( sal_Int32 aElementToken
) throw (SAXException
, RuntimeException
);
45 virtual Reference
< XFastContextHandler
> SAL_CALL
createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& xAttribs
) throw (SAXException
, RuntimeException
);
48 TextParagraph
& mrParagraph
;
51 // --------------------------------------------------------------------
52 TextParagraphContext::TextParagraphContext( ContextHandler
& rParent
, TextParagraph
& rPara
)
53 : ContextHandler( rParent
)
54 , mrParagraph( rPara
)
58 // --------------------------------------------------------------------
59 void TextParagraphContext::endFastElement( sal_Int32 aElementToken
) throw (SAXException
, RuntimeException
)
61 if( aElementToken
== (A_TOKEN( p
)) )
66 // --------------------------------------------------------------------
68 Reference
< XFastContextHandler
> TextParagraphContext::createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& xAttribs
) throw (SAXException
, RuntimeException
)
70 Reference
< XFastContextHandler
> xRet
;
73 switch( aElementToken
)
75 case A_TOKEN( r
): // "CT_RegularTextRun" Regular Text Run.
77 TextRunPtr
pRun( new TextRun
);
78 mrParagraph
.addRun( pRun
);
79 xRet
.set( new RegularTextRunContext( *this, pRun
) );
82 case A_TOKEN( br
): // "CT_TextLineBreak" Soft return line break (vertical tab).
84 TextRunPtr
pRun( new TextRun
);
86 mrParagraph
.addRun( pRun
);
87 xRet
.set( new RegularTextRunContext( *this, pRun
) );
90 case A_TOKEN( fld
): // "CT_TextField" Text Field.
92 TextFieldPtr
pField( new TextField
);
93 mrParagraph
.addRun( pField
);
94 xRet
.set( new TextFieldContext( *this, xAttribs
, *pField
) );
98 xRet
.set( new TextParagraphPropertiesContext( *this, xAttribs
, mrParagraph
.getProperties() ) );
100 case A_TOKEN( endParaRPr
):
101 xRet
.set( new TextCharacterPropertiesContext( *this, xAttribs
, mrParagraph
.getEndProperties() ) );
107 // --------------------------------------------------------------------
109 RegularTextRunContext::RegularTextRunContext( ContextHandler
& rParent
, TextRunPtr pRunPtr
)
110 : ContextHandler( rParent
)
111 , mpRunPtr( pRunPtr
)
112 , mbIsInText( false )
116 // --------------------------------------------------------------------
118 void RegularTextRunContext::endFastElement( sal_Int32 aElementToken
) throw (SAXException
, RuntimeException
)
120 switch( aElementToken
)
135 // --------------------------------------------------------------------
137 void RegularTextRunContext::characters( const OUString
& aChars
) throw (SAXException
, RuntimeException
)
141 mpRunPtr
->getText() += aChars
;
145 // --------------------------------------------------------------------
147 Reference
< XFastContextHandler
> RegularTextRunContext::createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& xAttribs
) throw (SAXException
, RuntimeException
)
149 Reference
< XFastContextHandler
> xRet( this );
151 switch( aElementToken
)
153 case A_TOKEN( rPr
): // "CT_TextCharPropertyBag" The text char properties of this text run.
154 xRet
.set( new TextCharacterPropertiesContext( *this, xAttribs
, mpRunPtr
->getTextCharacterProperties() ) );
156 case A_TOKEN( t
): // "xsd:string" minOccurs="1" The actual text string.
164 // --------------------------------------------------------------------
166 TextBodyContext::TextBodyContext( ContextHandler
& rParent
, TextBody
& rTextBody
)
167 : ContextHandler( rParent
)
168 , mrTextBody( rTextBody
)
172 // --------------------------------------------------------------------
174 void TextBodyContext::endFastElement( sal_Int32
) throw (SAXException
, RuntimeException
)
178 // --------------------------------------------------------------------
180 Reference
< XFastContextHandler
> TextBodyContext::createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& xAttribs
) throw (SAXException
, RuntimeException
)
182 Reference
< XFastContextHandler
> xRet
;
184 switch( aElementToken
)
186 case A_TOKEN( bodyPr
): // CT_TextBodyPropertyBag
187 xRet
.set( new TextBodyPropertiesContext( *this, xAttribs
, mrTextBody
.getTextProperties() ) );
189 case A_TOKEN( lstStyle
): // CT_TextListStyle
190 xRet
.set( new TextListStyleContext( *this, mrTextBody
.getTextListStyle() ) );
192 case A_TOKEN( p
): // CT_TextParagraph
193 xRet
.set( new TextParagraphContext( *this, mrTextBody
.addParagraph() ) );
200 // --------------------------------------------------------------------
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */