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