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