Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
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"
28 : :
29 : : using ::rtl::OUString;
30 : : using namespace ::oox::core;
31 : : using namespace ::com::sun::star::uno;
32 : : using namespace ::com::sun::star::text;
33 : : using namespace ::com::sun::star::xml::sax;
34 : :
35 : : namespace oox { namespace drawingml {
36 : :
37 : : // --------------------------------------------------------------------
38 : :
39 : : // CT_TextParagraph
40 [ - + ]: 396 : class TextParagraphContext : public ContextHandler
41 : : {
42 : : public:
43 : : TextParagraphContext( ContextHandler& rParent, TextParagraph& rPara );
44 : :
45 : : virtual void SAL_CALL endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException);
46 : : virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException);
47 : :
48 : : protected:
49 : : TextParagraph& mrParagraph;
50 : : };
51 : :
52 : : // --------------------------------------------------------------------
53 : 198 : TextParagraphContext::TextParagraphContext( ContextHandler& rParent, TextParagraph& rPara )
54 : : : ContextHandler( rParent )
55 : 198 : , mrParagraph( rPara )
56 : : {
57 : 198 : }
58 : :
59 : : // --------------------------------------------------------------------
60 : 198 : void TextParagraphContext::endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException)
61 : : {
62 : : if( aElementToken == (A_TOKEN( p )) )
63 : : {
64 : : }
65 : 198 : }
66 : :
67 : : // --------------------------------------------------------------------
68 : :
69 : 438 : Reference< XFastContextHandler > TextParagraphContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
70 : : {
71 : 438 : Reference< XFastContextHandler > xRet;
72 : :
73 : : // EG_TextRun
74 [ + + + + : 438 : switch( aElementToken )
+ - ]
75 : : {
76 : : case A_TOKEN( r ): // "CT_RegularTextRun" Regular Text Run.
77 : : {
78 [ + - ][ + - ]: 144 : TextRunPtr pRun( new TextRun );
[ + - ]
79 [ + - ]: 144 : mrParagraph.addRun( pRun );
80 [ + - ][ + - ]: 144 : xRet.set( new RegularTextRunContext( *this, pRun ) );
[ + - ][ + - ]
[ + - ]
81 [ + - ]: 144 : break;
82 : : }
83 : : case A_TOKEN( br ): // "CT_TextLineBreak" Soft return line break (vertical tab).
84 : : {
85 [ + - ][ + - ]: 6 : TextRunPtr pRun( new TextRun );
[ + - ]
86 : 6 : pRun->setLineBreak();
87 [ + - ]: 6 : mrParagraph.addRun( pRun );
88 [ + - ][ + - ]: 6 : xRet.set( new RegularTextRunContext( *this, pRun ) );
[ + - ][ + - ]
[ + - ]
89 [ + - ]: 6 : break;
90 : : }
91 : : case A_TOKEN( fld ): // "CT_TextField" Text Field.
92 : : {
93 [ + - ][ + - ]: 33 : TextFieldPtr pField( new TextField );
[ + - ]
94 [ + - ][ + - ]: 33 : mrParagraph.addRun( pField );
[ + - ]
95 [ + - ][ + - ]: 33 : xRet.set( new TextFieldContext( *this, xAttribs, *pField ) );
[ + - ]
96 [ + - ]: 33 : break;
97 : : }
98 : : case A_TOKEN( pPr ):
99 [ + - ][ + - ]: 111 : xRet.set( new TextParagraphPropertiesContext( *this, xAttribs, mrParagraph.getProperties() ) );
[ + - ]
100 : 111 : break;
101 : : case A_TOKEN( endParaRPr ):
102 [ + - ][ + - ]: 144 : xRet.set( new TextCharacterPropertiesContext( *this, xAttribs, mrParagraph.getEndProperties() ) );
[ + - ]
103 : 144 : break;
104 : : }
105 : :
106 : 438 : return xRet;
107 : : }
108 : : // --------------------------------------------------------------------
109 : :
110 : 150 : RegularTextRunContext::RegularTextRunContext( ContextHandler& rParent, TextRunPtr pRunPtr )
111 : : : ContextHandler( rParent )
112 : : , mpRunPtr( pRunPtr )
113 [ + - ]: 150 : , mbIsInText( false )
114 : : {
115 : 150 : }
116 : :
117 : : // --------------------------------------------------------------------
118 : :
119 : 294 : void RegularTextRunContext::endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException)
120 : : {
121 [ + + + ]: 294 : switch( aElementToken )
122 : : {
123 : : case A_TOKEN( t ):
124 : : {
125 : 144 : mbIsInText = false;
126 : 144 : break;
127 : : }
128 : : case A_TOKEN( r ):
129 : : {
130 : 144 : break;
131 : : }
132 : :
133 : : }
134 : 294 : }
135 : :
136 : : // --------------------------------------------------------------------
137 : :
138 : 150 : void RegularTextRunContext::characters( const OUString& aChars ) throw (SAXException, RuntimeException)
139 : : {
140 [ + - ]: 150 : if( mbIsInText )
141 : : {
142 : 150 : mpRunPtr->getText() += aChars;
143 : : }
144 : 150 : }
145 : :
146 : : // --------------------------------------------------------------------
147 : :
148 : 294 : Reference< XFastContextHandler > RegularTextRunContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs) throw (SAXException, RuntimeException)
149 : : {
150 : 294 : Reference< XFastContextHandler > xRet( this );
151 : :
152 [ + + - ]: 294 : switch( aElementToken )
153 : : {
154 : : case A_TOKEN( rPr ): // "CT_TextCharPropertyBag" The text char properties of this text run.
155 [ + - ][ + - ]: 150 : xRet.set( new TextCharacterPropertiesContext( *this, xAttribs, mpRunPtr->getTextCharacterProperties() ) );
[ + - ]
156 : 150 : break;
157 : : case A_TOKEN( t ): // "xsd:string" minOccurs="1" The actual text string.
158 : 144 : mbIsInText = true;
159 : 144 : break;
160 : : }
161 : :
162 : 294 : return xRet;
163 : : }
164 : :
165 : : // --------------------------------------------------------------------
166 : :
167 : 132 : TextBodyContext::TextBodyContext( ContextHandler& rParent, TextBody& rTextBody )
168 : : : ContextHandler( rParent )
169 : 132 : , mrTextBody( rTextBody )
170 : : {
171 : 132 : }
172 : :
173 : : // --------------------------------------------------------------------
174 : :
175 : 132 : void TextBodyContext::endFastElement( sal_Int32 ) throw (SAXException, RuntimeException)
176 : : {
177 : 132 : }
178 : :
179 : : // --------------------------------------------------------------------
180 : :
181 : 435 : Reference< XFastContextHandler > TextBodyContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
182 : : {
183 : 435 : Reference< XFastContextHandler > xRet;
184 : :
185 [ + + + - ]: 435 : switch( aElementToken )
186 : : {
187 : : case A_TOKEN( bodyPr ): // CT_TextBodyPropertyBag
188 [ + - ][ + - ]: 132 : xRet.set( new TextBodyPropertiesContext( *this, xAttribs, mrTextBody.getTextProperties() ) );
[ + - ]
189 : 132 : break;
190 : : case A_TOKEN( lstStyle ): // CT_TextListStyle
191 [ + - ][ + - ]: 105 : xRet.set( new TextListStyleContext( *this, mrTextBody.getTextListStyle() ) );
[ + - ]
192 : 105 : break;
193 : : case A_TOKEN( p ): // CT_TextParagraph
194 [ + - ][ + - ]: 198 : xRet.set( new TextParagraphContext( *this, mrTextBody.addParagraph() ) );
[ + - ][ + - ]
195 : 198 : break;
196 : : }
197 : :
198 : 435 : return xRet;
199 : : }
200 : :
201 : : // --------------------------------------------------------------------
202 : :
203 [ + - ][ + - ]: 285 : } }
204 : :
205 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|