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/themeelementscontext.hxx" 25 #include "oox/drawingml/clrschemecontext.hxx" 26 #include "oox/drawingml/lineproperties.hxx" 27 #include "oox/drawingml/linepropertiescontext.hxx" 28 #include "oox/drawingml/fillproperties.hxx" 29 #include "oox/drawingml/fillpropertiesgroupcontext.hxx" 30 #include "oox/drawingml/theme.hxx" 31 #include "oox/helper/attributelist.hxx" 32 33 using ::rtl::OUString; 34 using namespace ::oox::core; 35 using namespace ::com::sun::star::uno; 36 using namespace ::com::sun::star::xml::sax; 37 38 namespace oox { 39 namespace drawingml { 40 41 // ============================================================================ 42 43 class FillStyleListContext : public ContextHandler 44 { 45 public: 46 FillStyleListContext( ContextHandler& rParent, FillStyleList& rFillStyleList ); 47 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs ) throw (SAXException, RuntimeException); 48 49 private: 50 FillStyleList& mrFillStyleList; 51 }; 52 53 FillStyleListContext::FillStyleListContext( ContextHandler& rParent, FillStyleList& rFillStyleList ) : 54 ContextHandler( rParent ), 55 mrFillStyleList( rFillStyleList ) 56 { 57 } 58 59 Reference< XFastContextHandler > FillStyleListContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs ) 60 throw (SAXException, RuntimeException) 61 { 62 switch( nElement ) 63 { 64 case A_TOKEN( noFill ): 65 case A_TOKEN( solidFill ): 66 case A_TOKEN( gradFill ): 67 case A_TOKEN( blipFill ): 68 case A_TOKEN( pattFill ): 69 case A_TOKEN( grpFill ): 70 mrFillStyleList.push_back( FillPropertiesPtr( new FillProperties ) ); 71 return FillPropertiesContext::createFillContext( *this, nElement, xAttribs, *mrFillStyleList.back() ); 72 } 73 return 0; 74 } 75 76 // ============================================================================ 77 78 class LineStyleListContext : public ContextHandler 79 { 80 public: 81 LineStyleListContext( ContextHandler& rParent, LineStyleList& rLineStyleList ); 82 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs ) throw (SAXException, RuntimeException); 83 84 private: 85 LineStyleList& mrLineStyleList; 86 }; 87 88 LineStyleListContext::LineStyleListContext( ContextHandler& rParent, LineStyleList& rLineStyleList ) : 89 ContextHandler( rParent ), 90 mrLineStyleList( rLineStyleList ) 91 { 92 } 93 94 Reference< XFastContextHandler > LineStyleListContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs ) 95 throw (SAXException, RuntimeException) 96 { 97 switch( nElement ) 98 { 99 case A_TOKEN( ln ): 100 mrLineStyleList.push_back( LinePropertiesPtr( new LineProperties ) ); 101 return new LinePropertiesContext( *this, xAttribs, *mrLineStyleList.back() ); 102 } 103 return 0; 104 } 105 106 // ============================================================================ 107 108 class EffectStyleListContext : public ContextHandler 109 { 110 public: 111 EffectStyleListContext( ContextHandler& rParent, EffectStyleList& rEffectStyleList ); 112 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs ) throw (SAXException, RuntimeException); 113 114 private: 115 EffectStyleList& mrEffectStyleList; 116 }; 117 118 EffectStyleListContext::EffectStyleListContext( ContextHandler& rParent, EffectStyleList& rEffectStyleList ) : 119 ContextHandler( rParent ), 120 mrEffectStyleList( rEffectStyleList ) 121 { 122 } 123 124 Reference< XFastContextHandler > EffectStyleListContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& /*xAttribs*/ ) throw (SAXException, RuntimeException) 125 { 126 switch( nElement ) 127 { 128 case A_TOKEN( effectStyle ): 129 mrEffectStyleList.push_back( EffectStyleList::value_type( new PropertyMap ) ); 130 // TODO: import effect styles 131 return 0; 132 } 133 return 0; 134 } 135 136 // ============================================================================ 137 138 class FontSchemeContext : public ContextHandler 139 { 140 public: 141 FontSchemeContext( ContextHandler& rParent, FontScheme& rFontScheme ); 142 virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& Attribs ) throw (SAXException, RuntimeException); 143 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) throw (SAXException, RuntimeException); 144 145 private: 146 FontScheme& mrFontScheme; 147 TextCharacterPropertiesPtr mxCharProps; 148 }; 149 150 FontSchemeContext::FontSchemeContext( ContextHandler& rParent, FontScheme& rFontScheme ) : 151 ContextHandler( rParent ), 152 mrFontScheme( rFontScheme ) 153 { 154 } 155 156 Reference< XFastContextHandler > FontSchemeContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) 157 throw (SAXException, RuntimeException) 158 { 159 AttributeList aAttribs( rxAttribs ); 160 switch( nElement ) 161 { 162 case A_TOKEN( majorFont ): 163 mxCharProps.reset( new TextCharacterProperties ); 164 mrFontScheme[ XML_major ] = mxCharProps; 165 return this; 166 case A_TOKEN( minorFont ): 167 mxCharProps.reset( new TextCharacterProperties ); 168 mrFontScheme[ XML_minor ] = mxCharProps; 169 return this; 170 171 case A_TOKEN( latin ): 172 if( mxCharProps.get() ) 173 mxCharProps->maLatinFont.setAttributes( aAttribs ); 174 break; 175 case A_TOKEN( ea ): 176 if( mxCharProps.get() ) 177 mxCharProps->maAsianFont.setAttributes( aAttribs ); 178 break; 179 case A_TOKEN( cs ): 180 if( mxCharProps.get() ) 181 mxCharProps->maComplexFont.setAttributes( aAttribs ); 182 break; 183 } 184 return 0; 185 } 186 187 void FontSchemeContext::endFastElement( sal_Int32 nElement ) throw (SAXException, RuntimeException) 188 { 189 switch( nElement ) 190 { 191 case A_TOKEN( majorFont ): 192 case A_TOKEN( minorFont ): 193 mxCharProps.reset(); 194 break; 195 } 196 } 197 198 // ============================================================================ 199 200 ThemeElementsContext::ThemeElementsContext( ContextHandler& rParent, Theme& rTheme ) : 201 ContextHandler( rParent ), 202 mrTheme( rTheme ) 203 { 204 } 205 206 Reference< XFastContextHandler > ThemeElementsContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) 207 { 208 // CT_BaseStyles 209 Reference< XFastContextHandler > xRet; 210 switch( nElement ) 211 { 212 case A_TOKEN( clrScheme ): // CT_ColorScheme 213 return new clrSchemeContext( *this, mrTheme.getClrScheme() ); 214 case A_TOKEN( fontScheme ): // CT_FontScheme 215 return new FontSchemeContext( *this, mrTheme.getFontScheme() ); 216 217 case A_TOKEN( fmtScheme ): // CT_StyleMatrix 218 mrTheme.setStyleName( xAttribs->getOptionalValue( XML_name ) ); 219 return this; 220 221 case A_TOKEN( fillStyleLst ): // CT_FillStyleList 222 return new FillStyleListContext( *this, mrTheme.getFillStyleList() ); 223 case A_TOKEN( lnStyleLst ): // CT_LineStyleList 224 return new LineStyleListContext( *this, mrTheme.getLineStyleList() ); 225 case A_TOKEN( effectStyleLst ): // CT_EffectStyleList 226 return new EffectStyleListContext( *this, mrTheme.getEffectStyleList() ); 227 case A_TOKEN( bgFillStyleLst ): // CT_BackgroundFillStyleList 228 return new FillStyleListContext( *this, mrTheme.getBgFillStyleList() ); 229 } 230 return 0; 231 } 232 233 // ============================================================================ 234 235 } // namespace drawingml 236 } // namespace oox 237 238