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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_xmloff.hxx" 26 27 #include <com/sun/star/drawing/ColorMode.hpp> 28 #include <com/sun/star/text/HorizontalAdjust.hpp> 29 #include <com/sun/star/text/WritingMode2.hpp> 30 31 #include <tools/debug.hxx> 32 33 #include <xmloff/prhdlfac.hxx> 34 #include <xmloff/xmltypes.hxx> 35 #include <xmloff/xmltoken.hxx> 36 #include "xmlbahdl.hxx" 37 #include <xmloff/NamedBoolPropertyHdl.hxx> 38 #include <xmloff/XMLConstantsPropertyHandler.hxx> 39 #include "cdouthdl.hxx" 40 #include "csmaphdl.hxx" 41 #include "fonthdl.hxx" 42 #include "kernihdl.hxx" 43 #include <postuhdl.hxx> 44 #include "shadwhdl.hxx" 45 #include "shdwdhdl.hxx" 46 #include "undlihdl.hxx" 47 #include "weighhdl.hxx" 48 #include "breakhdl.hxx" 49 #include <adjushdl.hxx> 50 #include <escphdl.hxx> 51 #include <chrhghdl.hxx> 52 #include <chrlohdl.hxx> 53 #include <lspachdl.hxx> 54 #include <bordrhdl.hxx> 55 #include <tabsthdl.hxx> 56 #include <xmloff/EnumPropertyHdl.hxx> 57 #include "AttributeContainerHandler.hxx" 58 #include "durationhdl.hxx" 59 #include "XMLRectangleMembersHandler.hxx" 60 #include "DrawAspectHdl.hxx" 61 62 using namespace ::com::sun::star; 63 using namespace ::xmloff::token; 64 65 SvXMLEnumMapEntry aXML_ColorMode_EnumMap[] = 66 { 67 { XML_GREYSCALE, drawing::ColorMode_GREYS }, 68 { XML_MONO, drawing::ColorMode_MONO }, 69 { XML_WATERMARK, drawing::ColorMode_WATERMARK }, 70 { XML_STANDARD, drawing::ColorMode_STANDARD }, 71 { XML_TOKEN_INVALID, 0 } 72 }; 73 74 SvXMLEnumMapEntry __READONLY_DATA aXML_HorizontalAdjust_Enum[] = 75 { 76 { XML_LEFT, text::HorizontalAdjust_LEFT }, 77 { XML_CENTER, text::HorizontalAdjust_CENTER }, 78 { XML_RIGHT, text::HorizontalAdjust_RIGHT }, 79 { XML_TOKEN_INVALID, 0 } 80 }; 81 82 // aXML_WritingDirection_Enum is used with and without 'page' 83 // attribute, so you'll find uses of aXML_WritingDirection_Enum 84 // directly, as well as &(aXML_WritingDirection_Enum[1]) 85 SvXMLEnumMapEntry __READONLY_DATA aXML_WritingDirection_Enum[] = 86 { 87 // aXML_WritingDirection_Enum 88 { XML_PAGE, text::WritingMode2::PAGE }, 89 90 // &(aXML_WritingDirection_Enum[1]) 91 { XML_LR_TB, text::WritingMode2::LR_TB }, 92 { XML_RL_TB, text::WritingMode2::RL_TB }, 93 { XML_TB_RL, text::WritingMode2::TB_RL }, 94 { XML_TB_LR, text::WritingMode2::TB_LR }, 95 96 // alternative names of the above, as accepted by XSL 97 { XML_LR, text::WritingMode2::LR_TB }, 98 { XML_RL, text::WritingMode2::RL_TB }, 99 { XML_TB, text::WritingMode2::TB_RL }, 100 101 { XML_TOKEN_INVALID, 0 } 102 }; 103 104 105 /////////////////////////////////////////////////////////////////////////// 106 // 107 // Dtor 108 // 109 XMLPropertyHandlerFactory::~XMLPropertyHandlerFactory() 110 { 111 for( CacheMap::iterator pPos = maHandlerCache.begin(); pPos != maHandlerCache.end(); pPos++ ) 112 delete pPos->second; 113 } 114 115 /////////////////////////////////////////////////////////////////////////// 116 // 117 // Interface 118 // 119 const XMLPropertyHandler* XMLPropertyHandlerFactory::GetPropertyHandler( sal_Int32 nType ) const 120 { 121 DBG_ASSERT( (nType & ~((sal_uInt32)MID_FLAG_MASK)) == 0, 122 "GetPropertyHandler called with flags in type" ); 123 return GetBasicHandler( nType ); 124 } 125 126 /////////////////////////////////////////////////////////////////////////// 127 // 128 // Helper-methods to create and cache PropertyHandler 129 // 130 XMLPropertyHandler* XMLPropertyHandlerFactory::GetHdlCache( sal_Int32 nType ) const 131 { 132 XMLPropertyHandler* pRet = NULL; 133 134 if( maHandlerCache.find( nType ) != maHandlerCache.end() ) 135 pRet = maHandlerCache.find( nType )->second; 136 137 return pRet; 138 } 139 140 void XMLPropertyHandlerFactory::PutHdlCache( sal_Int32 nType, const XMLPropertyHandler* pHdl ) const 141 { 142 // Don't be wondered about the following construct. The sense is to be able to provide a const- 143 // method as class-interface. 144 ((XMLPropertyHandlerFactory*)this)->maHandlerCache[ nType ] = (XMLPropertyHandler*)pHdl; 145 } 146 147 const XMLPropertyHandler* XMLPropertyHandlerFactory::GetBasicHandler( sal_Int32 nType ) const 148 { 149 const XMLPropertyHandler* pPropHdl = GetHdlCache( nType ); 150 151 if( !pPropHdl ) 152 { 153 pPropHdl = CreatePropertyHandler( nType ); 154 155 if( pPropHdl ) 156 PutHdlCache( nType, pPropHdl ); 157 } 158 159 return pPropHdl; 160 } 161 162 const XMLPropertyHandler* XMLPropertyHandlerFactory::CreatePropertyHandler( sal_Int32 nType ) 163 { 164 XMLPropertyHandler* pPropHdl = NULL; 165 166 switch( nType ) 167 { 168 case XML_TYPE_BOOL : 169 pPropHdl = new XMLBoolPropHdl; 170 break; 171 case XML_TYPE_MEASURE : 172 pPropHdl = new XMLMeasurePropHdl( 4 ); 173 break; 174 case XML_TYPE_MEASURE8 : 175 pPropHdl = new XMLMeasurePropHdl( 1 ); 176 break; 177 case XML_TYPE_MEASURE16: 178 pPropHdl = new XMLMeasurePropHdl( 2 ); 179 break; 180 case XML_TYPE_PERCENT : 181 pPropHdl = new XMLPercentPropHdl( 4 ); 182 break; 183 case XML_TYPE_PERCENT8 : 184 pPropHdl = new XMLPercentPropHdl( 1 ); 185 break; 186 case XML_TYPE_PERCENT16 : 187 pPropHdl = new XMLPercentPropHdl( 2 ); 188 break; 189 case XML_TYPE_DOUBLE_PERCENT : 190 pPropHdl = new XMLDoublePercentPropHdl(); 191 break; 192 case XML_TYPE_NEG_PERCENT : 193 pPropHdl = new XMLNegPercentPropHdl( 4 ); 194 break; 195 case XML_TYPE_NEG_PERCENT8 : 196 pPropHdl = new XMLNegPercentPropHdl( 1 ); 197 break; 198 case XML_TYPE_NEG_PERCENT16 : 199 pPropHdl = new XMLNegPercentPropHdl( 2 ); 200 break; 201 case XML_TYPE_MEASURE_PX : 202 pPropHdl = new XMLMeasurePxPropHdl( 4 ); 203 break; 204 case XML_TYPE_STRING : 205 pPropHdl = new XMLStringPropHdl; 206 break; 207 case XML_TYPE_COLOR : 208 pPropHdl = new XMLColorPropHdl; 209 break; 210 case XML_TYPE_NUMBER : 211 pPropHdl = new XMLNumberPropHdl( 4 ); 212 break; 213 case XML_TYPE_NUMBER8 : 214 pPropHdl = new XMLNumberPropHdl( 1 ); 215 break; 216 case XML_TYPE_NUMBER16: 217 pPropHdl = new XMLNumberPropHdl( 2 ); 218 break; 219 case XML_TYPE_NUMBER_NONE : 220 pPropHdl = new XMLNumberNonePropHdl; 221 break; 222 case XML_TYPE_NUMBER8_NONE : 223 pPropHdl = new XMLNumberNonePropHdl( 1 ); 224 break; 225 case XML_TYPE_NUMBER16_NONE : 226 pPropHdl = new XMLNumberNonePropHdl( 2 ); 227 break; 228 case XML_TYPE_DOUBLE : 229 pPropHdl = new XMLDoublePropHdl; 230 break; 231 case XML_TYPE_NBOOL : 232 pPropHdl = new XMLNBoolPropHdl; 233 break; 234 case XML_TYPE_COLORTRANSPARENT : 235 pPropHdl = new XMLColorTransparentPropHdl; 236 break; 237 case XML_TYPE_ISTRANSPARENT : 238 pPropHdl = new XMLIsTransparentPropHdl; 239 break; 240 case XML_TYPE_COLORAUTO : 241 pPropHdl = new XMLColorAutoPropHdl; 242 break; 243 case XML_TYPE_ISAUTOCOLOR : 244 pPropHdl = new XMLIsAutoColorPropHdl; 245 break; 246 case XML_TYPE_BUILDIN_CMP_ONLY : 247 pPropHdl = new XMLCompareOnlyPropHdl; 248 break; 249 250 case XML_TYPE_RECTANGLE_LEFT : 251 case XML_TYPE_RECTANGLE_TOP : 252 case XML_TYPE_RECTANGLE_WIDTH : 253 case XML_TYPE_RECTANGLE_HEIGHT : 254 pPropHdl = new XMLRectangleMembersHdl( nType ); 255 break; 256 257 case XML_TYPE_TEXT_CROSSEDOUT_TYPE: 258 pPropHdl = new XMLCrossedOutTypePropHdl ; 259 break; 260 case XML_TYPE_TEXT_CROSSEDOUT_STYLE: 261 pPropHdl = new XMLCrossedOutStylePropHdl ; 262 break; 263 case XML_TYPE_TEXT_CROSSEDOUT_WIDTH: 264 pPropHdl = new XMLCrossedOutWidthPropHdl ; 265 break; 266 case XML_TYPE_TEXT_CROSSEDOUT_TEXT: 267 pPropHdl = new XMLCrossedOutTextPropHdl ; 268 break; 269 case XML_TYPE_TEXT_BOOLCROSSEDOUT: 270 pPropHdl = new XMLNamedBoolPropertyHdl( 271 GetXMLToken(XML_SOLID), 272 GetXMLToken(XML_NONE) ); 273 break; 274 case XML_TYPE_TEXT_ESCAPEMENT: 275 pPropHdl = new XMLEscapementPropHdl; 276 break; 277 case XML_TYPE_TEXT_ESCAPEMENT_HEIGHT: 278 pPropHdl = new XMLEscapementHeightPropHdl; 279 break; 280 case XML_TYPE_TEXT_CASEMAP: 281 pPropHdl = new XMLCaseMapPropHdl; 282 break; 283 case XML_TYPE_TEXT_CASEMAP_VAR: 284 pPropHdl = new XMLCaseMapVariantHdl; 285 break; 286 case XML_TYPE_TEXT_FONTFAMILYNAME: 287 pPropHdl = new XMLFontFamilyNamePropHdl; 288 break; 289 case XML_TYPE_TEXT_FONTFAMILY: 290 pPropHdl = new XMLFontFamilyPropHdl; 291 break; 292 case XML_TYPE_TEXT_FONTENCODING: 293 pPropHdl = new XMLFontEncodingPropHdl; 294 break; 295 case XML_TYPE_TEXT_FONTPITCH: 296 pPropHdl = new XMLFontPitchPropHdl; 297 break; 298 case XML_TYPE_TEXT_KERNING: 299 pPropHdl = new XMLKerningPropHdl; 300 break; 301 case XML_TYPE_TEXT_POSTURE: 302 pPropHdl = new XMLPosturePropHdl; 303 break; 304 case XML_TYPE_TEXT_SHADOWED: 305 pPropHdl = new XMLShadowedPropHdl; 306 break; 307 case XML_TYPE_TEXT_UNDERLINE_TYPE: 308 pPropHdl = new XMLUnderlineTypePropHdl; 309 break; 310 case XML_TYPE_TEXT_UNDERLINE_STYLE: 311 pPropHdl = new XMLUnderlineStylePropHdl; 312 break; 313 case XML_TYPE_TEXT_UNDERLINE_WIDTH: 314 pPropHdl = new XMLUnderlineWidthPropHdl; 315 break; 316 case XML_TYPE_TEXT_UNDERLINE_COLOR: 317 pPropHdl = new XMLColorTransparentPropHdl( XML_FONT_COLOR ); 318 break; 319 case XML_TYPE_TEXT_UNDERLINE_HASCOLOR: 320 pPropHdl = new XMLIsTransparentPropHdl( XML_FONT_COLOR, 321 sal_False ); 322 break; 323 case XML_TYPE_TEXT_OVERLINE_TYPE: 324 pPropHdl = new XMLUnderlineTypePropHdl; 325 break; 326 case XML_TYPE_TEXT_OVERLINE_STYLE: 327 pPropHdl = new XMLUnderlineStylePropHdl; 328 break; 329 case XML_TYPE_TEXT_OVERLINE_WIDTH: 330 pPropHdl = new XMLUnderlineWidthPropHdl; 331 break; 332 case XML_TYPE_TEXT_OVERLINE_COLOR: 333 pPropHdl = new XMLColorTransparentPropHdl( XML_FONT_COLOR ); 334 break; 335 case XML_TYPE_TEXT_OVERLINE_HASCOLOR: 336 pPropHdl = new XMLIsTransparentPropHdl( XML_FONT_COLOR, 337 sal_False ); 338 break; 339 case XML_TYPE_TEXT_WEIGHT: 340 pPropHdl = new XMLFontWeightPropHdl; 341 break; 342 case XML_TYPE_TEXT_SPLIT: 343 pPropHdl = new XMLNamedBoolPropertyHdl( 344 GetXMLToken(XML_AUTO), 345 GetXMLToken(XML_ALWAYS) ); 346 break; 347 case XML_TYPE_TEXT_BREAKBEFORE: 348 pPropHdl = new XMLFmtBreakBeforePropHdl; 349 break; 350 case XML_TYPE_TEXT_BREAKAFTER: 351 pPropHdl = new XMLFmtBreakAfterPropHdl; 352 break; 353 case XML_TYPE_TEXT_SHADOW: 354 pPropHdl = new XMLShadowPropHdl; 355 break; 356 case XML_TYPE_TEXT_ADJUST: 357 pPropHdl = new XMLParaAdjustPropHdl; 358 break; 359 case XML_TYPE_TEXT_ADJUSTLAST: 360 pPropHdl = new XMLLastLineAdjustPropHdl; 361 break; 362 case XML_TYPE_CHAR_HEIGHT: 363 pPropHdl = new XMLCharHeightHdl; 364 break; 365 case XML_TYPE_CHAR_HEIGHT_PROP: 366 pPropHdl = new XMLCharHeightPropHdl; 367 break; 368 case XML_TYPE_CHAR_HEIGHT_DIFF: 369 pPropHdl = new XMLCharHeightDiffHdl; 370 break; 371 case XML_TYPE_CHAR_LANGUAGE: 372 pPropHdl = new XMLCharLanguageHdl; 373 break; 374 case XML_TYPE_CHAR_COUNTRY: 375 pPropHdl = new XMLCharCountryHdl; 376 break; 377 case XML_TYPE_LINE_SPACE_FIXED: 378 pPropHdl = new XMLLineHeightHdl; 379 break; 380 case XML_TYPE_LINE_SPACE_MINIMUM: 381 pPropHdl = new XMLLineHeightAtLeastHdl; 382 break; 383 case XML_TYPE_LINE_SPACE_DISTANCE: 384 pPropHdl = new XMLLineSpacingHdl; 385 break; 386 case XML_TYPE_BORDER_WIDTH: 387 pPropHdl = new XMLBorderWidthHdl; 388 break; 389 case XML_TYPE_BORDER: 390 pPropHdl = new XMLBorderHdl; 391 break; 392 case XML_TYPE_TEXT_TABSTOP: 393 pPropHdl = new XMLTabStopPropHdl; 394 break; 395 case XML_TYPE_ATTRIBUTE_CONTAINER: 396 pPropHdl = new XMLAttributeContainerHandler; 397 break; 398 case XML_TYPE_COLOR_MODE: 399 pPropHdl = new XMLEnumPropertyHdl( aXML_ColorMode_EnumMap, 400 ::getCppuType((const drawing::ColorMode*)0) ); 401 break; 402 case XML_TYPE_DURATION16_MS: 403 pPropHdl = new XMLDurationMS16PropHdl_Impl; 404 break; 405 case XML_TYPE_TEXT_HORIZONTAL_ADJUST: 406 pPropHdl = new XMLEnumPropertyHdl( 407 aXML_HorizontalAdjust_Enum, 408 ::getCppuType((const text::HorizontalAdjust*)0) ); 409 break; 410 case XML_TYPE_TEXT_DRAW_ASPECT: 411 pPropHdl = new DrawAspectHdl; 412 break; 413 case XML_TYPE_TEXT_WRITING_MODE: 414 pPropHdl = new XMLConstantsPropertyHandler( 415 &(aXML_WritingDirection_Enum[1]), 416 XML_LR_TB); 417 break; 418 case XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT: 419 pPropHdl = new XMLConstantsPropertyHandler( 420 aXML_WritingDirection_Enum, 421 XML_PAGE); 422 break; 423 case XML_TYPE_TEXT_HIDDEN_AS_DISPLAY: 424 pPropHdl = new XMLNamedBoolPropertyHdl( 425 GetXMLToken(XML_NONE), 426 GetXMLToken(XML_TRUE) ); 427 break; 428 case XML_TYPE_STYLENAME : 429 pPropHdl = new XMLStyleNamePropHdl; 430 break; 431 case XML_TYPE_NUMBER_NO_ZERO: 432 pPropHdl = new XMLNumberWithoutZeroPropHdl( 4 ); 433 break; 434 case XML_TYPE_NUMBER8_NO_ZERO: 435 pPropHdl = new XMLNumberWithoutZeroPropHdl( 1 ); 436 break; 437 case XML_TYPE_NUMBER16_NO_ZERO: 438 pPropHdl = new XMLNumberWithoutZeroPropHdl( 2 ); 439 break; 440 case XML_TYPE_NUMBER16_AUTO: 441 pPropHdl = new XMLNumberWithAutoInsteadZeroPropHdl(); 442 break; 443 } 444 445 return pPropHdl; 446 } 447