1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "oox/drawingml/textbodycontext.hxx"
25 #include "oox/drawingml/textbodypropertiescontext.hxx"
26 #include "oox/drawingml/textparagraph.hxx"
27 #include "oox/drawingml/textparagraphpropertiescontext.hxx"
28 #include "oox/drawingml/textcharacterpropertiescontext.hxx"
29 #include "oox/drawingml/textliststylecontext.hxx"
30 #include "oox/drawingml/textfield.hxx"
31 #include "oox/drawingml/textfieldcontext.hxx"
32 
33 using ::rtl::OUString;
34 using namespace ::oox::core;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::text;
37 using namespace ::com::sun::star::xml::sax;
38 
39 namespace oox { namespace drawingml {
40 
41 // --------------------------------------------------------------------
42 
43 // CT_TextParagraph
44 class TextParagraphContext : public ContextHandler
45 {
46 public:
47     TextParagraphContext( ContextHandler& rParent, TextParagraph& rPara );
48 
49 	virtual void SAL_CALL endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException);
50 	virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException);
51 
52 protected:
53 	TextParagraph& mrParagraph;
54 };
55 
56 // --------------------------------------------------------------------
TextParagraphContext(ContextHandler & rParent,TextParagraph & rPara)57 TextParagraphContext::TextParagraphContext( ContextHandler& rParent, TextParagraph& rPara )
58 : ContextHandler( rParent )
59 , mrParagraph( rPara )
60 {
61 }
62 
63 // --------------------------------------------------------------------
endFastElement(sal_Int32 aElementToken)64 void TextParagraphContext::endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException)
65 {
66 	if( aElementToken == (A_TOKEN( p )) )
67 	{
68 	}
69 }
70 
71 // --------------------------------------------------------------------
72 
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)73 Reference< XFastContextHandler > TextParagraphContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
74 {
75 	Reference< XFastContextHandler > xRet;
76 
77 	// EG_TextRun
78 	switch( aElementToken )
79 	{
80 	case A_TOKEN( r ):		// "CT_RegularTextRun" Regular Text Run.
81 	{
82         TextRunPtr pRun( new TextRun );
83 		mrParagraph.addRun( pRun );
84         xRet.set( new RegularTextRunContext( *this, pRun ) );
85 		break;
86 	}
87 	case A_TOKEN( br ):	// "CT_TextLineBreak" Soft return line break (vertical tab).
88 	{
89         TextRunPtr pRun( new TextRun );
90 		pRun->setLineBreak();
91 		mrParagraph.addRun( pRun );
92         xRet.set( new RegularTextRunContext( *this, pRun ) );
93 		break;
94 	}
95 	case A_TOKEN( fld ):	// "CT_TextField" Text Field.
96 	{
97         TextFieldPtr pField( new TextField );
98 		mrParagraph.addRun( pField );
99         xRet.set( new TextFieldContext( *this, xAttribs, *pField ) );
100 		break;
101 	}
102 	case A_TOKEN( pPr ):
103         xRet.set( new TextParagraphPropertiesContext( *this, xAttribs, mrParagraph.getProperties() ) );
104 		break;
105 	case A_TOKEN( endParaRPr ):
106         xRet.set( new TextCharacterPropertiesContext( *this, xAttribs, mrParagraph.getEndProperties() ) );
107 		break;
108 	}
109 
110 	return xRet;
111 }
112 // --------------------------------------------------------------------
113 
RegularTextRunContext(ContextHandler & rParent,TextRunPtr pRunPtr)114 RegularTextRunContext::RegularTextRunContext( ContextHandler& rParent, TextRunPtr pRunPtr )
115 : ContextHandler( rParent )
116 , mpRunPtr( pRunPtr )
117 , mbIsInText( false )
118 {
119 }
120 
121 // --------------------------------------------------------------------
122 
endFastElement(sal_Int32 aElementToken)123 void RegularTextRunContext::endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException)
124 {
125 	switch( aElementToken )
126 	{
127 	case A_TOKEN( t ):
128 	{
129 		mbIsInText = false;
130 		break;
131 	}
132 	case A_TOKEN( r ):
133 	{
134 		break;
135 	}
136 
137 	}
138 }
139 
140 // --------------------------------------------------------------------
141 
characters(const OUString & aChars)142 void RegularTextRunContext::characters( const OUString& aChars ) throw (SAXException, RuntimeException)
143 {
144 	if( mbIsInText )
145 	{
146         mpRunPtr->getText() += aChars;
147 	}
148 }
149 
150 // --------------------------------------------------------------------
151 
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)152 Reference< XFastContextHandler > RegularTextRunContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs) throw (SAXException, RuntimeException)
153 {
154 	Reference< XFastContextHandler > xRet( this );
155 
156 	switch( aElementToken )
157 	{
158 	case A_TOKEN( rPr ):	// "CT_TextCharPropertyBag" The text char properties of this text run.
159         xRet.set( new TextCharacterPropertiesContext( *this, xAttribs, mpRunPtr->getTextCharacterProperties() ) );
160 		break;
161 	case A_TOKEN( t ):		// "xsd:string" minOccurs="1" The actual text string.
162 		mbIsInText = true;
163 		break;
164 	}
165 
166 	return xRet;
167 }
168 
169 // --------------------------------------------------------------------
170 
TextBodyContext(ContextHandler & rParent,TextBody & rTextBody)171 TextBodyContext::TextBodyContext( ContextHandler& rParent, TextBody& rTextBody )
172 : ContextHandler( rParent )
173 , mrTextBody( rTextBody )
174 {
175 }
176 
177 // --------------------------------------------------------------------
178 
endFastElement(sal_Int32)179 void TextBodyContext::endFastElement( sal_Int32 ) throw (SAXException, RuntimeException)
180 {
181 }
182 
183 // --------------------------------------------------------------------
184 
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)185 Reference< XFastContextHandler > TextBodyContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
186 {
187 	Reference< XFastContextHandler > xRet;
188 
189 	switch( aElementToken )
190 	{
191 	case A_TOKEN( bodyPr ):		// CT_TextBodyPropertyBag
192         xRet.set( new TextBodyPropertiesContext( *this, xAttribs, mrTextBody.getTextProperties() ) );
193 		break;
194 	case A_TOKEN( lstStyle ):	// CT_TextListStyle
195         xRet.set( new TextListStyleContext( *this, mrTextBody.getTextListStyle() ) );
196 		break;
197 	case A_TOKEN( p ):			// CT_TextParagraph
198         xRet.set( new TextParagraphContext( *this, mrTextBody.addParagraph() ) );
199 		break;
200 	}
201 
202 	return xRet;
203 }
204 
205 // --------------------------------------------------------------------
206 
207 } }
208 
209