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