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/xls/richstringcontext.hxx"
25 
26 #include "oox/xls/stylesfragment.hxx"
27 
28 namespace oox {
29 namespace xls {
30 
31 // ============================================================================
32 
33 using ::oox::core::ContextHandlerRef;
34 using ::rtl::OUString;
35 
36 // ============================================================================
37 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)38 ContextHandlerRef RichStringContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
39 {
40     if( isRootElement() )
41     {
42         switch( nElement )
43         {
44             case XLS_TOKEN( t ):
45                 mxPortion = mxString->importText( rAttribs );
46                 return this;    // collect text in onCharacters()
47             case XLS_TOKEN( r ):
48                 mxPortion = mxString->importRun( rAttribs );
49                 return this;
50             case XLS_TOKEN( rPh ):
51                 mxPhonetic = mxString->importPhoneticRun( rAttribs );
52                 return this;
53             case XLS_TOKEN( phoneticPr ):
54                 mxString->importPhoneticPr( rAttribs );
55             break;
56         }
57     }
58     else switch( getCurrentElement() )
59     {
60         case XLS_TOKEN( r ):
61             switch( nElement )
62             {
63                 case XLS_TOKEN( rPr ):
64                     if( mxPortion.get() )
65                         return new FontContext( *this, mxPortion->createFont() );
66                 break;
67 
68                 case XLS_TOKEN( t ):
69                     return this;    // collect portion text in onCharacters()
70             }
71         break;
72 
73         case XLS_TOKEN( rPh ):
74             switch( nElement )
75             {
76                 case XLS_TOKEN( t ):
77                     return this;    // collect phonetic text in onCharacters()
78             }
79         break;
80     }
81     return 0;
82 }
83 
onCharacters(const OUString & rChars)84 void RichStringContext::onCharacters( const OUString& rChars )
85 {
86     if( isCurrentElement( XLS_TOKEN( t ) ) ) switch( getParentElement() )
87     {
88         case XLS_TOKEN( rPh ):
89             if( mxPhonetic.get() )
90                 mxPhonetic->setText( rChars );
91         break;
92         default:
93             if( mxPortion.get() )
94                 mxPortion->setText( rChars );
95     }
96 }
97 
98 // ============================================================================
99 
100 } // namespace xls
101 } // namespace oox
102