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 <osl/diagnose.h>
25 
26 #include "oox/drawingml/table/tablestyletextstylecontext.hxx"
27 #include "oox/drawingml/colorchoicecontext.hxx"
28 #include "oox/helper/attributelist.hxx"
29 
30 using namespace ::oox::core;
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::xml::sax;
34 using ::rtl::OUString;
35 
36 namespace oox { namespace drawingml { namespace table {
37 
TableStyleTextStyleContext(ContextHandler & rParent,const Reference<XFastAttributeList> & xAttribs,TableStylePart & rTableStylePart)38 TableStyleTextStyleContext::TableStyleTextStyleContext( ContextHandler& rParent,
39 	const Reference< XFastAttributeList >& xAttribs, TableStylePart& rTableStylePart )
40 : ContextHandler( rParent )
41 , mrTableStylePart( rTableStylePart )
42 {
43 	sal_Int32 nB = xAttribs->getOptionalValueToken( XML_b, XML_def );
44 	if ( nB == XML_on )
45 		mrTableStylePart.getTextBoldStyle() = ::boost::optional< sal_Bool >( sal_True );
46 	else if ( nB == XML_off )
47 		mrTableStylePart.getTextBoldStyle() = ::boost::optional< sal_Bool >( sal_False );
48 
49 	sal_Int32 nI = xAttribs->getOptionalValueToken( XML_i, XML_def );
50 	if ( nI == XML_on )
51 		mrTableStylePart.getTextItalicStyle() = ::boost::optional< sal_Bool >( sal_True );
52 	else if ( nI == XML_off )
53 		mrTableStylePart.getTextItalicStyle() = ::boost::optional< sal_Bool >( sal_False );
54 }
55 
~TableStyleTextStyleContext()56 TableStyleTextStyleContext::~TableStyleTextStyleContext()
57 {
58 }
59 
60 // CT_TableStyleTextStyle
61 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
createFastChildContext(::sal_Int32 aElementToken,const uno::Reference<xml::sax::XFastAttributeList> & xAttribs)62 TableStyleTextStyleContext::createFastChildContext( ::sal_Int32 aElementToken, const uno::Reference< xml::sax::XFastAttributeList >& xAttribs )
63 	throw ( xml::sax::SAXException, uno::RuntimeException)
64 {
65 	uno::Reference< xml::sax::XFastContextHandler > xRet;
66     AttributeList aAttribs( xAttribs );
67 
68 	switch( aElementToken )
69 	{
70 		// EG_ThemeableFontStyles (choice)
71 		case A_TOKEN( font ):		// CT_FontCollection
72 			xRet.set( this );
73 			break;
74 		case A_TOKEN( ea ):				// CT_TextFont
75             mrTableStylePart.getAsianFont().setAttributes( aAttribs );
76             return 0;
77 		case A_TOKEN( cs ):				// CT_TextFont
78             mrTableStylePart.getComplexFont().setAttributes( aAttribs );
79             return 0;
80 		case A_TOKEN( sym ):			// CT_TextFont
81             mrTableStylePart.getSymbolFont().setAttributes( aAttribs );
82             return 0;
83 		case A_TOKEN( latin ):			// CT_TextFont
84             mrTableStylePart.getLatinFont().setAttributes( aAttribs );
85             return 0;
86 
87 		case A_TOKEN( fontRef ):	// CT_FontReference
88             {
89                 ShapeStyleRef& rFontStyle = mrTableStylePart.getStyleRefs()[ XML_fontRef ];
90                 rFontStyle.mnThemedIdx = aAttribs.getToken( XML_idx, XML_none );
91                 xRet.set( new ColorContext( *this, rFontStyle.maPhClr ) );
92             }
93 			break;
94 
95 		case A_TOKEN( extLst ):		// CT_OfficeArtExtensionList
96 			break;
97 	}
98 	if( !xRet.is() )
99         xRet.set( new ColorValueContext( *this, mrTableStylePart.getTextColor() ) );
100 
101 	return xRet;
102 }
103 
104 } } }
105