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_starmath.hxx" 26 27 /*todo: Change characters and tcharacters to accumulate the characters together 28 into one string, xml parser hands them to us line by line rather than all in 29 one go*/ 30 31 #include <com/sun/star/xml/sax/XErrorHandler.hpp> 32 #include <com/sun/star/xml/sax/XEntityResolver.hpp> 33 #include <com/sun/star/xml/sax/InputSource.hpp> 34 #include <com/sun/star/xml/sax/XDTDHandler.hpp> 35 #include <com/sun/star/xml/sax/XParser.hpp> 36 #include <com/sun/star/io/XActiveDataSource.hpp> 37 #include <com/sun/star/io/XActiveDataControl.hpp> 38 #include <com/sun/star/document/XDocumentProperties.hpp> 39 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> 40 #include <com/sun/star/packages/zip/ZipIOException.hpp> 41 #include <com/sun/star/task/XStatusIndicatorFactory.hpp> 42 #include <com/sun/star/beans/PropertyAttribute.hpp> 43 #include <com/sun/star/container/XNameAccess.hpp> 44 #include <com/sun/star/embed/ElementModes.hpp> 45 #include <com/sun/star/uno/Any.h> 46 47 #include <rtl/math.hxx> 48 #include <sfx2/frame.hxx> 49 #include <sfx2/docfile.hxx> 50 #include <tools/debug.hxx> 51 #include <tools/urlobj.hxx> 52 #include <svtools/sfxecode.hxx> 53 #include <unotools/saveopt.hxx> 54 #include <svl/stritem.hxx> 55 #include <svl/itemprop.hxx> 56 #include <unotools/processfactory.hxx> 57 #include <unotools/streamwrap.hxx> 58 #include <xmloff/xmlnmspe.hxx> 59 #include <xmloff/xmltoken.hxx> 60 #include <xmloff/nmspmap.hxx> 61 #include <xmloff/attrlist.hxx> 62 #include <xmloff/xmluconv.hxx> 63 #include <xmloff/xmlmetai.hxx> 64 #include <osl/mutex.hxx> 65 #include <comphelper/genericpropertyset.hxx> 66 67 #include <memory> 68 69 #include "mathmlimport.hxx" 70 #include <starmath.hrc> 71 #include <unomodel.hxx> 72 #include <document.hxx> 73 #include <utility.hxx> 74 75 using namespace ::com::sun::star::beans; 76 using namespace ::com::sun::star::container; 77 using namespace ::com::sun::star::document; 78 using namespace ::com::sun::star::lang; 79 using namespace ::com::sun::star::uno; 80 using namespace ::com::sun::star; 81 using namespace ::xmloff::token; 82 83 using ::rtl::OUString; 84 using ::rtl::OUStringBuffer; 85 86 #define IMPORT_SVC_NAME RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.XMLImportFilter") 87 88 #undef WANTEXCEPT 89 90 //////////////////////////////////////////////////////////// 91 92 sal_uLong SmXMLImportWrapper::Import(SfxMedium &rMedium) 93 { 94 sal_uLong nError = ERRCODE_SFX_DOLOADFAILED; 95 96 uno::Reference<lang::XMultiServiceFactory> xServiceFactory( 97 utl::getProcessServiceFactory()); 98 DBG_ASSERT(xServiceFactory.is(), "XMLReader::Read: got no service manager"); 99 if ( !xServiceFactory.is() ) 100 return nError; 101 102 //Make a model component from our SmModel 103 uno::Reference< lang::XComponent > xModelComp( xModel, uno::UNO_QUERY ); 104 DBG_ASSERT( xModelComp.is(), "XMLReader::Read: got no model" ); 105 106 // try to get an XStatusIndicator from the Medium 107 uno::Reference<task::XStatusIndicator> xStatusIndicator; 108 109 sal_Bool bEmbedded = sal_False; 110 uno::Reference <lang::XUnoTunnel> xTunnel; 111 xTunnel = uno::Reference <lang::XUnoTunnel> (xModel,uno::UNO_QUERY); 112 SmModel *pModel = reinterpret_cast<SmModel *> 113 (xTunnel->getSomething(SmModel::getUnoTunnelId())); 114 115 SmDocShell *pDocShell = pModel ? 116 static_cast<SmDocShell*>(pModel->GetObjectShell()) : 0; 117 if (pDocShell) 118 { 119 // if (pDocShell->GetMedium()) 120 { 121 DBG_ASSERT( pDocShell->GetMedium() == &rMedium, 122 "different SfxMedium found" ); 123 124 SfxItemSet* pSet = rMedium.GetItemSet(); 125 if (pSet) 126 { 127 const SfxUnoAnyItem* pItem = static_cast<const SfxUnoAnyItem*>( 128 pSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL) ); 129 if (pItem) 130 pItem->GetValue() >>= xStatusIndicator; 131 } 132 } 133 134 if ( SFX_CREATE_MODE_EMBEDDED == pDocShell->GetCreateMode() ) 135 bEmbedded = sal_True; 136 } 137 138 comphelper::PropertyMapEntry aInfoMap[] = 139 { 140 { "PrivateData", sizeof("PrivateData")-1, 0, 141 &::getCppuType( (Reference<XInterface> *)0 ), 142 beans::PropertyAttribute::MAYBEVOID, 0 }, 143 { "BaseURI", sizeof("BaseURI")-1, 0, 144 &::getCppuType( (OUString *)0 ), 145 beans::PropertyAttribute::MAYBEVOID, 0 }, 146 { "StreamRelPath", sizeof("StreamRelPath")-1, 0, 147 &::getCppuType( (OUString *)0 ), 148 beans::PropertyAttribute::MAYBEVOID, 0 }, 149 { "StreamName", sizeof("StreamName")-1, 0, 150 &::getCppuType( (OUString *)0 ), 151 beans::PropertyAttribute::MAYBEVOID, 0 }, 152 { NULL, 0, 0, NULL, 0, 0 } 153 }; 154 uno::Reference< beans::XPropertySet > xInfoSet( 155 comphelper::GenericPropertySet_CreateInstance( 156 new comphelper::PropertySetInfo( aInfoMap ) ) ); 157 158 // Set base URI 159 OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("BaseURI") ); 160 xInfoSet->setPropertyValue( sPropName, makeAny( rMedium.GetBaseURL() ) ); 161 162 sal_Int32 nSteps=3; 163 if ( !(rMedium.IsStorage())) 164 nSteps = 1; 165 166 sal_Int32 nProgressRange(nSteps); 167 if (xStatusIndicator.is()) 168 { 169 xStatusIndicator->start(String(SmResId(STR_STATSTR_READING)), 170 nProgressRange); 171 } 172 173 nSteps=0; 174 if (xStatusIndicator.is()) 175 xStatusIndicator->setValue(nSteps++); 176 177 if ( rMedium.IsStorage()) 178 { 179 // TODO/LATER: handle the case of embedded links gracefully 180 if ( bEmbedded ) // && !rMedium.GetStorage()->IsRoot() ) 181 { 182 OUString aName( RTL_CONSTASCII_USTRINGPARAM( "dummyObjName" ) ); 183 if ( rMedium.GetItemSet() ) 184 { 185 const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>( 186 rMedium.GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) ); 187 if ( pDocHierarchItem ) 188 aName = pDocHierarchItem->GetValue(); 189 } 190 191 if ( aName.getLength() ) 192 { 193 sPropName = OUString(RTL_CONSTASCII_USTRINGPARAM("StreamRelPath")); 194 xInfoSet->setPropertyValue( sPropName, makeAny( aName ) ); 195 } 196 } 197 198 sal_Bool bOASIS = ( SotStorage::GetVersion( rMedium.GetStorage() ) > SOFFICE_FILEFORMAT_60 ); 199 if (xStatusIndicator.is()) 200 xStatusIndicator->setValue(nSteps++); 201 202 sal_uLong nWarn = ReadThroughComponent( 203 rMedium.GetStorage(), xModelComp, "meta.xml", "Meta.xml", 204 xServiceFactory, xInfoSet, 205 (bOASIS ? "com.sun.star.comp.Math.XMLOasisMetaImporter" 206 : "com.sun.star.comp.Math.XMLMetaImporter") ); 207 208 if ( nWarn != ERRCODE_IO_BROKENPACKAGE ) 209 { 210 if (xStatusIndicator.is()) 211 xStatusIndicator->setValue(nSteps++); 212 213 nWarn = ReadThroughComponent( 214 rMedium.GetStorage(), xModelComp, "settings.xml", 0, 215 xServiceFactory, xInfoSet, 216 (bOASIS ? "com.sun.star.comp.Math.XMLOasisSettingsImporter" 217 : "com.sun.star.comp.Math.XMLSettingsImporter" ) ); 218 219 if ( nWarn != ERRCODE_IO_BROKENPACKAGE ) 220 { 221 if (xStatusIndicator.is()) 222 xStatusIndicator->setValue(nSteps++); 223 224 nError = ReadThroughComponent( 225 rMedium.GetStorage(), xModelComp, "content.xml", "Content.xml", 226 xServiceFactory, xInfoSet, "com.sun.star.comp.Math.XMLImporter" ); 227 } 228 else 229 nError = ERRCODE_IO_BROKENPACKAGE; 230 } 231 else 232 nError = ERRCODE_IO_BROKENPACKAGE; 233 } 234 else 235 { 236 Reference<io::XInputStream> xInputStream = 237 new utl::OInputStreamWrapper(rMedium.GetInStream()); 238 239 if (xStatusIndicator.is()) 240 xStatusIndicator->setValue(nSteps++); 241 242 nError = ReadThroughComponent( xInputStream, xModelComp, 243 xServiceFactory, xInfoSet, "com.sun.star.comp.Math.XMLImporter", sal_False ); 244 } 245 246 if (xStatusIndicator.is()) 247 xStatusIndicator->end(); 248 return nError; 249 } 250 251 252 /// read a component (file + filter version) 253 sal_uLong SmXMLImportWrapper::ReadThroughComponent( 254 Reference<io::XInputStream> xInputStream, 255 Reference<XComponent> xModelComponent, 256 Reference<lang::XMultiServiceFactory> & rFactory, 257 Reference<beans::XPropertySet> & rPropSet, 258 const sal_Char* pFilterName, 259 sal_Bool bEncrypted ) 260 { 261 sal_uLong nError = ERRCODE_SFX_DOLOADFAILED; 262 DBG_ASSERT(xInputStream.is(), "input stream missing"); 263 DBG_ASSERT(xModelComponent.is(), "document missing"); 264 DBG_ASSERT(rFactory.is(), "factory missing"); 265 DBG_ASSERT(NULL != pFilterName,"I need a service name for the component!"); 266 267 // prepare ParserInputSrouce 268 xml::sax::InputSource aParserInput; 269 aParserInput.aInputStream = xInputStream; 270 271 // get parser 272 Reference< xml::sax::XParser > xParser( 273 rFactory->createInstance( 274 OUString::createFromAscii("com.sun.star.xml.sax.Parser") ), 275 UNO_QUERY ); 276 DBG_ASSERT( xParser.is(), "Can't create parser" ); 277 if ( !xParser.is() ) 278 return nError; 279 280 Sequence<Any> aArgs( 1 ); 281 aArgs[0] <<= rPropSet; 282 283 // get filter 284 Reference< xml::sax::XDocumentHandler > xFilter( 285 rFactory->createInstanceWithArguments( 286 OUString::createFromAscii(pFilterName), aArgs ), 287 UNO_QUERY ); 288 DBG_ASSERT( xFilter.is(), "Can't instantiate filter component." ); 289 if ( !xFilter.is() ) 290 return nError; 291 292 // connect parser and filter 293 xParser->setDocumentHandler( xFilter ); 294 295 // connect model and filter 296 Reference < XImporter > xImporter( xFilter, UNO_QUERY ); 297 xImporter->setTargetDocument( xModelComponent ); 298 299 // finally, parser the stream 300 try 301 { 302 xParser->parseStream( aParserInput ); 303 304 uno::Reference<lang::XUnoTunnel> xFilterTunnel; 305 xFilterTunnel = uno::Reference<lang::XUnoTunnel> 306 ( xFilter, uno::UNO_QUERY ); 307 SmXMLImport *pFilter = reinterpret_cast< SmXMLImport * >( 308 sal::static_int_cast< sal_uIntPtr >( 309 xFilterTunnel->getSomething( SmXMLImport::getUnoTunnelId() ))); 310 if ( pFilter && pFilter->GetSuccess() ) 311 nError = 0; 312 } 313 catch( xml::sax::SAXParseException& r ) 314 { 315 // sax parser sends wrapped exceptions, 316 // try to find the original one 317 xml::sax::SAXException aSaxEx = *(xml::sax::SAXException*)(&r); 318 sal_Bool bTryChild = sal_True; 319 320 while( bTryChild ) 321 { 322 xml::sax::SAXException aTmp; 323 if ( aSaxEx.WrappedException >>= aTmp ) 324 aSaxEx = aTmp; 325 else 326 bTryChild = sal_False; 327 } 328 329 packages::zip::ZipIOException aBrokenPackage; 330 if ( aSaxEx.WrappedException >>= aBrokenPackage ) 331 return ERRCODE_IO_BROKENPACKAGE; 332 333 if ( bEncrypted ) 334 nError = ERRCODE_SFX_WRONGPASSWORD; 335 } 336 catch( xml::sax::SAXException& r ) 337 { 338 packages::zip::ZipIOException aBrokenPackage; 339 if ( r.WrappedException >>= aBrokenPackage ) 340 return ERRCODE_IO_BROKENPACKAGE; 341 342 if ( bEncrypted ) 343 nError = ERRCODE_SFX_WRONGPASSWORD; 344 } 345 catch( packages::zip::ZipIOException& ) 346 { 347 nError = ERRCODE_IO_BROKENPACKAGE; 348 } 349 catch( io::IOException& ) 350 { 351 } 352 353 return nError; 354 } 355 356 357 sal_uLong SmXMLImportWrapper::ReadThroughComponent( 358 const uno::Reference< embed::XStorage >& xStorage, 359 Reference<XComponent> xModelComponent, 360 const sal_Char* pStreamName, 361 const sal_Char* pCompatibilityStreamName, 362 Reference<lang::XMultiServiceFactory> & rFactory, 363 Reference<beans::XPropertySet> & rPropSet, 364 const sal_Char* pFilterName ) 365 { 366 DBG_ASSERT(xStorage.is(), "Need storage!"); 367 DBG_ASSERT(NULL != pStreamName, "Please, please, give me a name!"); 368 369 // open stream (and set parser input) 370 OUString sStreamName = OUString::createFromAscii(pStreamName); 371 uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY ); 372 if ( !xAccess->hasByName(sStreamName) || !xStorage->isStreamElement(sStreamName) ) 373 { 374 // stream name not found! Then try the compatibility name. 375 // do we even have an alternative name? 376 if ( pCompatibilityStreamName ) 377 sStreamName = OUString::createFromAscii(pCompatibilityStreamName); 378 } 379 380 // get input stream 381 try 382 { 383 uno::Reference < io::XStream > xEventsStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ ); 384 385 // determine if stream is encrypted or not 386 uno::Reference < beans::XPropertySet > xProps( xEventsStream, uno::UNO_QUERY ); 387 Any aAny = xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Encrypted") ) ); 388 sal_Bool bEncrypted = sal_False; 389 if ( aAny.getValueType() == ::getBooleanCppuType() ) 390 aAny >>= bEncrypted; 391 392 // set Base URL 393 if ( rPropSet.is() ) 394 { 395 OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("StreamName") ); 396 rPropSet->setPropertyValue( sPropName, makeAny( sStreamName ) ); 397 } 398 399 400 Reference < io::XInputStream > xStream = xEventsStream->getInputStream(); 401 return ReadThroughComponent( xStream, xModelComponent, rFactory, rPropSet, pFilterName, bEncrypted ); 402 } 403 catch ( packages::WrongPasswordException& ) 404 { 405 return ERRCODE_SFX_WRONGPASSWORD; 406 } 407 catch( packages::zip::ZipIOException& ) 408 { 409 return ERRCODE_IO_BROKENPACKAGE; 410 } 411 catch ( uno::Exception& ) 412 { 413 } 414 415 return ERRCODE_SFX_DOLOADFAILED; 416 } 417 418 //////////////////////////////////////////////////////////// 419 420 SmXMLImport::SmXMLImport( 421 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory, 422 sal_uInt16 nImportFlags) 423 : SvXMLImport( xServiceFactory, nImportFlags ), 424 pPresLayoutElemTokenMap(0), 425 pPresLayoutAttrTokenMap(0), 426 pFencedAttrTokenMap(0), 427 pOperatorAttrTokenMap(0), 428 pAnnotationAttrTokenMap(0), 429 pPresElemTokenMap(0), 430 pPresScriptEmptyElemTokenMap(0), 431 pPresTableElemTokenMap(0), 432 pColorTokenMap(0), 433 bSuccess(sal_False) 434 { 435 } 436 437 const uno::Sequence< sal_Int8 > & SmXMLImport::getUnoTunnelId() throw() 438 { 439 static uno::Sequence< sal_Int8 > * pSeq = 0; 440 if ( !pSeq ) 441 { 442 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 443 if ( !pSeq ) 444 { 445 static uno::Sequence< sal_Int8 > aSeq( 16 ); 446 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); 447 pSeq = &aSeq; 448 } 449 } 450 return *pSeq; 451 } 452 453 OUString SAL_CALL SmXMLImport_getImplementationName() throw() 454 { 455 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Math.XMLImporter" ) ); 456 } 457 458 uno::Sequence< OUString > SAL_CALL SmXMLImport_getSupportedServiceNames() 459 throw() 460 { 461 const OUString aServiceName( IMPORT_SVC_NAME ); 462 const uno::Sequence< OUString > aSeq( &aServiceName, 1 ); 463 return aSeq; 464 } 465 466 uno::Reference< uno::XInterface > SAL_CALL SmXMLImport_createInstance( 467 const uno::Reference< lang::XMultiServiceFactory > & rSMgr) 468 throw( uno::Exception ) 469 { 470 // #110680# 471 // return (cppu::OWeakObject*)new SmXMLImport(IMPORT_ALL); 472 return (cppu::OWeakObject*)new SmXMLImport(rSMgr, IMPORT_ALL); 473 } 474 475 //////////////////////////////////////////////////////////// 476 477 OUString SAL_CALL SmXMLImportMeta_getImplementationName() throw() 478 { 479 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Math.XMLOasisMetaImporter" ) ); 480 } 481 482 uno::Sequence< OUString > SAL_CALL SmXMLImportMeta_getSupportedServiceNames() 483 throw() 484 { 485 const OUString aServiceName( IMPORT_SVC_NAME ); 486 const uno::Sequence< OUString > aSeq( &aServiceName, 1 ); 487 return aSeq; 488 } 489 490 uno::Reference< uno::XInterface > SAL_CALL SmXMLImportMeta_createInstance( 491 const uno::Reference< lang::XMultiServiceFactory > & rSMgr) 492 throw( uno::Exception ) 493 { 494 // #110680# 495 // return (cppu::OWeakObject*)new SmXMLImport( IMPORT_META ); 496 return (cppu::OWeakObject*)new SmXMLImport( rSMgr, IMPORT_META ); 497 } 498 499 //////////////////////////////////////////////////////////// 500 501 OUString SAL_CALL SmXMLImportSettings_getImplementationName() throw() 502 { 503 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Math.XMLOasisSettingsImporter" ) ); 504 } 505 506 uno::Sequence< OUString > SAL_CALL SmXMLImportSettings_getSupportedServiceNames() 507 throw() 508 { 509 const OUString aServiceName( IMPORT_SVC_NAME ); 510 const uno::Sequence< OUString > aSeq( &aServiceName, 1 ); 511 return aSeq; 512 } 513 514 uno::Reference< uno::XInterface > SAL_CALL SmXMLImportSettings_createInstance( 515 const uno::Reference< lang::XMultiServiceFactory > & rSMgr) 516 throw( uno::Exception ) 517 { 518 // #110680# 519 // return (cppu::OWeakObject*)new SmXMLImport( IMPORT_SETTINGS ); 520 return (cppu::OWeakObject*)new SmXMLImport( rSMgr, IMPORT_SETTINGS ); 521 } 522 523 //////////////////////////////////////////////////////////// 524 525 // XServiceInfo 526 // override empty method from parent class 527 rtl::OUString SAL_CALL SmXMLImport::getImplementationName() 528 throw(uno::RuntimeException) 529 { 530 OUString aTxt; 531 switch( getImportFlags() ) 532 { 533 case IMPORT_META: 534 aTxt = SmXMLImportMeta_getImplementationName(); 535 break; 536 case IMPORT_SETTINGS: 537 aTxt = SmXMLImportSettings_getImplementationName(); 538 break; 539 case IMPORT_ALL: 540 default: 541 aTxt = SmXMLImport_getImplementationName(); 542 break; 543 } 544 return aTxt; 545 } 546 547 548 sal_Int64 SAL_CALL SmXMLImport::getSomething( 549 const uno::Sequence< sal_Int8 >&rId ) 550 throw(uno::RuntimeException) 551 { 552 if ( rId.getLength() == 16 && 553 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), 554 rId.getConstArray(), 16 ) ) 555 return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_uIntPtr >(this)); 556 557 return SvXMLImport::getSomething( rId ); 558 } 559 560 void SmXMLImport::endDocument(void) 561 throw(xml::sax::SAXException, uno::RuntimeException) 562 { 563 //Set the resulted tree into the SmDocShell where it belongs 564 SmNode *pTree; 565 if (NULL != (pTree = GetTree())) 566 { 567 uno::Reference <frame::XModel> xModel = GetModel(); 568 uno::Reference <lang::XUnoTunnel> xTunnel; 569 xTunnel = uno::Reference <lang::XUnoTunnel> (xModel,uno::UNO_QUERY); 570 SmModel *pModel = reinterpret_cast<SmModel *> 571 (xTunnel->getSomething(SmModel::getUnoTunnelId())); 572 573 if (pModel) 574 { 575 SmDocShell *pDocShell = 576 static_cast<SmDocShell*>(pModel->GetObjectShell()); 577 pDocShell->SetFormulaTree(pTree); 578 if (0 == aText.Len()) //If we picked up no annotation text 579 { 580 //Make up some editable text 581 aText = pDocShell->GetText(); 582 pTree->CreateTextFromNode(aText); 583 aText.EraseTrailingChars(); 584 if ((aText.GetChar(0) == '{') && 585 (aText.GetChar(aText.Len()-1) == '}')) 586 { 587 aText.Erase(0,1); 588 aText.Erase(aText.Len()-1,1); 589 } 590 } 591 pDocShell->SetText( String() ); 592 593 // Convert symbol names 594 SmParser &rParser = pDocShell->GetParser(); 595 sal_Bool bVal = rParser.IsImportSymbolNames(); 596 rParser.SetImportSymbolNames( sal_True ); 597 SmNode *pTmpTree = rParser.Parse( aText ); 598 aText = rParser.GetText(); 599 delete pTmpTree; 600 rParser.SetImportSymbolNames( bVal ); 601 602 pDocShell->SetText( aText ); 603 } 604 DBG_ASSERT(pModel,"So there *was* a uno problem after all"); 605 606 bSuccess = sal_True; 607 } 608 609 SvXMLImport::endDocument(); 610 } 611 612 //////////////////////////////////////////////////////////// 613 614 class SmXMLImportContext: public SvXMLImportContext 615 { 616 public: 617 SmXMLImportContext( SmXMLImport &rImport, sal_uInt16 nPrfx, 618 const OUString& rLName) 619 : SvXMLImportContext(rImport, nPrfx, rLName) {} 620 621 const SmXMLImport& GetSmImport() const 622 { 623 return (const SmXMLImport&)GetImport(); 624 } 625 626 SmXMLImport& GetSmImport() 627 { 628 return (SmXMLImport&)GetImport(); 629 } 630 631 virtual void TCharacters(const OUString & /*rChars*/); 632 virtual void Characters(const OUString &rChars); 633 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/, const uno::Reference< xml::sax::XAttributeList > & /*xAttrList*/); 634 }; 635 636 void SmXMLImportContext::TCharacters(const OUString & /*rChars*/) 637 { 638 } 639 640 void SmXMLImportContext::Characters(const OUString &rChars) 641 { 642 /* 643 Whitespace occurring within the content of token elements is "trimmed" 644 from the ends (i.e. all whitespace at the beginning and end of the 645 content is removed), and "collapsed" internally (i.e. each sequence of 646 1 or more whitespace characters is replaced with one blank character). 647 */ 648 //collapsing not done yet! 649 const OUString &rChars2 = rChars.trim(); 650 if (rChars2.getLength()) 651 TCharacters(rChars2/*.collapse()*/); 652 } 653 654 SvXMLImportContext * SmXMLImportContext::CreateChildContext(sal_uInt16 /*nPrefix*/, 655 const OUString& /*rLocalName*/, 656 const uno::Reference< xml::sax::XAttributeList > & /*xAttrList*/) 657 { 658 return 0; 659 } 660 661 //////////////////////////////////////////////////////////// 662 663 struct SmXMLContext_Helper 664 { 665 sal_Int8 nIsBold; 666 sal_Int8 nIsItalic; 667 double nFontSize; 668 sal_Bool bFontNodeNeeded; 669 OUString sFontFamily; 670 OUString sColor; 671 672 SmXMLImportContext rContext; 673 674 SmXMLContext_Helper(SmXMLImportContext &rImport) : 675 nIsBold(-1), nIsItalic(-1), nFontSize(0.0), rContext(rImport) {} 676 677 void RetrieveAttrs(const uno::Reference< xml::sax::XAttributeList > &xAttrList ); 678 void ApplyAttrs(); 679 }; 680 681 void SmXMLContext_Helper::RetrieveAttrs(const uno::Reference< 682 xml::sax::XAttributeList > & xAttrList ) 683 { 684 sal_Int8 nOldIsBold=nIsBold; 685 sal_Int8 nOldIsItalic=nIsItalic; 686 double nOldFontSize=nFontSize; 687 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 688 OUString sOldFontFamily = sFontFamily; 689 for (sal_Int16 i=0;i<nAttrCount;i++) 690 { 691 OUString sAttrName = xAttrList->getNameByIndex(i); 692 OUString aLocalName; 693 sal_uInt16 nPrefix = rContext.GetSmImport().GetNamespaceMap(). 694 GetKeyByAttrName(sAttrName,&aLocalName); 695 OUString sValue = xAttrList->getValueByIndex(i); 696 const SvXMLTokenMap &rAttrTokenMap = 697 rContext.GetSmImport().GetPresLayoutAttrTokenMap(); 698 switch(rAttrTokenMap.Get(nPrefix,aLocalName)) 699 { 700 case XML_TOK_FONTWEIGHT: 701 nIsBold = sValue.equals(GetXMLToken(XML_BOLD)); 702 break; 703 case XML_TOK_FONTSTYLE: 704 nIsItalic = sValue.equals(GetXMLToken(XML_ITALIC)); 705 break; 706 case XML_TOK_FONTSIZE: 707 SvXMLUnitConverter::convertDouble(nFontSize,sValue); 708 rContext.GetSmImport().GetMM100UnitConverter(). 709 setXMLMeasureUnit(MAP_POINT); 710 if (-1 == sValue.indexOf(GetXMLToken(XML_UNIT_PT))) 711 { 712 if (-1 == sValue.indexOf('%')) 713 nFontSize=0.0; 714 else 715 { 716 rContext.GetSmImport().GetMM100UnitConverter(). 717 setXMLMeasureUnit(MAP_RELATIVE); 718 } 719 } 720 break; 721 case XML_TOK_FONTFAMILY: 722 sFontFamily = sValue; 723 break; 724 case XML_TOK_COLOR: 725 sColor = sValue; 726 break; 727 default: 728 break; 729 } 730 } 731 732 if ((nOldIsBold!=nIsBold) || (nOldIsItalic!=nIsItalic) || 733 (nOldFontSize!=nFontSize) || (sOldFontFamily!=sFontFamily) 734 || sColor.getLength()) 735 bFontNodeNeeded=sal_True; 736 else 737 bFontNodeNeeded=sal_False; 738 } 739 740 void SmXMLContext_Helper::ApplyAttrs() 741 { 742 SmNodeStack &rNodeStack = rContext.GetSmImport().GetNodeStack(); 743 744 if (bFontNodeNeeded) 745 { 746 SmToken aToken; 747 aToken.cMathChar = '\0'; 748 aToken.nGroup = 0; 749 aToken.nLevel = 5; 750 751 if (nIsBold != -1) 752 { 753 if (nIsBold) 754 aToken.eType = TBOLD; 755 else 756 aToken.eType = TNBOLD; 757 SmStructureNode *pFontNode = static_cast<SmStructureNode *> 758 (new SmFontNode(aToken)); 759 pFontNode->SetSubNodes(0,rNodeStack.Pop()); 760 rNodeStack.Push(pFontNode); 761 } 762 if (nIsItalic != -1) 763 { 764 if (nIsItalic) 765 aToken.eType = TITALIC; 766 else 767 aToken.eType = TNITALIC; 768 SmStructureNode *pFontNode = static_cast<SmStructureNode *> 769 (new SmFontNode(aToken)); 770 pFontNode->SetSubNodes(0,rNodeStack.Pop()); 771 rNodeStack.Push(pFontNode); 772 } 773 if (nFontSize != 0.0) 774 { 775 aToken.eType = TSIZE; 776 SmFontNode *pFontNode = new SmFontNode(aToken); 777 778 if (MAP_RELATIVE == rContext.GetSmImport().GetMM100UnitConverter(). 779 getXMLMeasureUnit()) 780 { 781 if (nFontSize < 100.00) 782 pFontNode->SetSizeParameter(Fraction(100.00/nFontSize), 783 FNTSIZ_DIVIDE); 784 else 785 pFontNode->SetSizeParameter(Fraction(nFontSize/100.00), 786 FNTSIZ_MULTIPLY); 787 } 788 else 789 pFontNode->SetSizeParameter(Fraction(nFontSize),FNTSIZ_ABSOLUT); 790 791 pFontNode->SetSubNodes(0,rNodeStack.Pop()); 792 rNodeStack.Push(pFontNode); 793 } 794 if (sFontFamily.getLength()) 795 { 796 if (sFontFamily.equalsIgnoreAsciiCase(GetXMLToken(XML_FIXED))) 797 aToken.eType = TFIXED; 798 else if (sFontFamily.equalsIgnoreAsciiCase(OUString( 799 RTL_CONSTASCII_USTRINGPARAM("sans")))) 800 aToken.eType = TSANS; 801 else if (sFontFamily.equalsIgnoreAsciiCase(OUString( 802 RTL_CONSTASCII_USTRINGPARAM("serif")))) 803 aToken.eType = TSERIF; 804 else //Just give up, we need to extend our font mechanism to be 805 //more general 806 return; 807 808 aToken.aText = sFontFamily; 809 SmFontNode *pFontNode = new SmFontNode(aToken); 810 pFontNode->SetSubNodes(0,rNodeStack.Pop()); 811 rNodeStack.Push(pFontNode); 812 } 813 if (sColor.getLength()) 814 { 815 //Again we can only handle a small set of colours in 816 //StarMath for now. 817 const SvXMLTokenMap& rTokenMap = 818 rContext.GetSmImport().GetColorTokenMap(); 819 aToken.eType = static_cast<SmTokenType>(rTokenMap.Get( 820 XML_NAMESPACE_MATH, sColor)); 821 if (aToken.eType != -1) 822 { 823 SmFontNode *pFontNode = new SmFontNode(aToken); 824 pFontNode->SetSubNodes(0,rNodeStack.Pop()); 825 rNodeStack.Push(pFontNode); 826 } 827 } 828 829 } 830 } 831 832 //////////////////////////////////////////////////////////// 833 834 class SmXMLDocContext_Impl : public SmXMLImportContext 835 { 836 public: 837 SmXMLDocContext_Impl( SmXMLImport &rImport, sal_uInt16 nPrfx, 838 const OUString& rLName) 839 : SmXMLImportContext(rImport,nPrfx,rLName) {} 840 841 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList); 842 843 void EndElement(); 844 }; 845 846 //////////////////////////////////////////////////////////// 847 848 /*avert thy gaze from the proginator*/ 849 class SmXMLRowContext_Impl : public SmXMLDocContext_Impl 850 { 851 protected: 852 sal_uLong nElementCount; 853 854 public: 855 SmXMLRowContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 856 const OUString& rLName) 857 : SmXMLDocContext_Impl(rImport,nPrefix,rLName) 858 { nElementCount = GetSmImport().GetNodeStack().Count(); } 859 860 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList); 861 862 SvXMLImportContext *StrictCreateChildContext(sal_uInt16 nPrefix, 863 const OUString& rLocalName, 864 const uno::Reference< xml::sax::XAttributeList > &xAttrList); 865 866 void EndElement(); 867 }; 868 869 //////////////////////////////////////////////////////////// 870 871 class SmXMLFracContext_Impl : public SmXMLRowContext_Impl 872 { 873 public: 874 SmXMLFracContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 875 const OUString& rLName) 876 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {} 877 878 void EndElement(); 879 }; 880 881 //////////////////////////////////////////////////////////// 882 883 class SmXMLSqrtContext_Impl : public SmXMLRowContext_Impl 884 { 885 public: 886 SmXMLSqrtContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 887 const OUString& rLName) 888 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {} 889 890 void EndElement(); 891 }; 892 893 //////////////////////////////////////////////////////////// 894 895 class SmXMLRootContext_Impl : public SmXMLRowContext_Impl 896 { 897 public: 898 SmXMLRootContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 899 const OUString& rLName) 900 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {} 901 902 void EndElement(); 903 }; 904 905 //////////////////////////////////////////////////////////// 906 907 class SmXMLStyleContext_Impl : public SmXMLRowContext_Impl 908 { 909 protected: 910 SmXMLContext_Helper aStyleHelper; 911 912 public: 913 /*Right now the style tag is completely ignored*/ 914 SmXMLStyleContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 915 const OUString& rLName) : SmXMLRowContext_Impl(rImport,nPrefix,rLName), 916 aStyleHelper(*this) {} 917 918 void EndElement(); 919 void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList ); 920 }; 921 922 void SmXMLStyleContext_Impl::StartElement(const uno::Reference< 923 xml::sax::XAttributeList > & xAttrList ) 924 { 925 #if 1 926 aStyleHelper.RetrieveAttrs(xAttrList); 927 #else 928 sal_Int8 nOldIsBold=nIsBold; 929 sal_Int8 nOldIsItalic=nIsItalic; 930 double nOldFontSize=nFontSize; 931 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 932 OUString sOldFontFamily = sFontFamily; 933 for (sal_Int16 i=0;i<nAttrCount;i++) 934 { 935 OUString sAttrName = xAttrList->getNameByIndex(i); 936 OUString aLocalName; 937 sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). 938 GetKeyByAttrName(sAttrName,&aLocalName); 939 OUString sValue = xAttrList->getValueByIndex(i); 940 const SvXMLTokenMap &rAttrTokenMap = 941 GetSmImport().GetPresLayoutAttrTokenMap(); 942 switch(rAttrTokenMap.Get(nPrefix,aLocalName)) 943 { 944 case XML_TOK_FONTWEIGHT: 945 nIsBold = sValue.equals(GetXMLToken(XML_BOLD)); 946 break; 947 case XML_TOK_FONTSTYLE: 948 nIsItalic = sValue.equals(GetXMLToken(XML_ITALIC)); 949 break; 950 case XML_TOK_FONTSIZE: 951 SvXMLUnitConverter::convertDouble(nFontSize,sValue); 952 GetSmImport().GetMM100UnitConverter(). 953 setXMLMeasureUnit(MAP_POINT); 954 if (-1 == sValue.indexOf(GetXMLToken(XML_UNIT_PT))) 955 if (-1 == sValue.indexOf('%')) 956 nFontSize=0.0; 957 else 958 { 959 GetSmImport().GetMM100UnitConverter(). 960 setXMLMeasureUnit(MAP_RELATIVE); 961 } 962 break; 963 case XML_TOK_FONTFAMILY: 964 sFontFamily = sValue; 965 break; 966 case XML_TOK_COLOR: 967 sColor = sValue; 968 break; 969 default: 970 break; 971 } 972 } 973 974 if ((nOldIsBold!=nIsBold) || (nOldIsItalic!=nIsItalic) || 975 (nOldFontSize!=nFontSize) || (sOldFontFamily!=sFontFamily) 976 || sColor.getLength()) 977 bFontNodeNeeded=sal_True; 978 else 979 bFontNodeNeeded=sal_False; 980 #endif 981 } 982 983 984 void SmXMLStyleContext_Impl::EndElement() 985 { 986 /* 987 <mstyle> accepts any number of arguments; if this number is not 1, its 988 contents are treated as a single "inferred <mrow>" containing its 989 arguments 990 */ 991 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 992 if (rNodeStack.Count() - nElementCount > 1) 993 SmXMLRowContext_Impl::EndElement(); 994 #if 1 995 aStyleHelper.ApplyAttrs(); 996 #else 997 if (bFontNodeNeeded) 998 { 999 SmToken aToken; 1000 aToken.cMathChar = '\0'; 1001 aToken.nGroup = 0; 1002 aToken.nLevel = 5; 1003 1004 if (nIsBold != -1) 1005 { 1006 if (nIsBold) 1007 aToken.eType = TBOLD; 1008 else 1009 aToken.eType = TNBOLD; 1010 SmStructureNode *pFontNode = static_cast<SmStructureNode *> 1011 (new SmFontNode(aToken)); 1012 pFontNode->SetSubNodes(0,rNodeStack.Pop()); 1013 rNodeStack.Push(pFontNode); 1014 } 1015 if (nIsItalic != -1) 1016 { 1017 if (nIsItalic) 1018 aToken.eType = TITALIC; 1019 else 1020 aToken.eType = TNITALIC; 1021 SmStructureNode *pFontNode = static_cast<SmStructureNode *> 1022 (new SmFontNode(aToken)); 1023 pFontNode->SetSubNodes(0,rNodeStack.Pop()); 1024 rNodeStack.Push(pFontNode); 1025 } 1026 if (nFontSize != 0.0) 1027 { 1028 aToken.eType = TSIZE; 1029 SmFontNode *pFontNode = new SmFontNode(aToken); 1030 1031 if (MAP_RELATIVE == GetSmImport().GetMM100UnitConverter(). 1032 getXMLMeasureUnit()) 1033 { 1034 if (nFontSize < 100.00) 1035 pFontNode->SetSizeParameter(Fraction(100.00/nFontSize), 1036 FNTSIZ_DIVIDE); 1037 else 1038 pFontNode->SetSizeParameter(Fraction(nFontSize/100.00), 1039 FNTSIZ_MULTIPLY); 1040 } 1041 else 1042 pFontNode->SetSizeParameter(Fraction(nFontSize),FNTSIZ_ABSOLUT); 1043 1044 pFontNode->SetSubNodes(0,rNodeStack.Pop()); 1045 rNodeStack.Push(pFontNode); 1046 } 1047 if (sFontFamily.getLength()) 1048 { 1049 if (sFontFamily.equalsIgnoreCase(GetXMLToken(XML_FIXED))) 1050 aToken.eType = TFIXED; 1051 else if (sFontFamily.equalsIgnoreCase(OUString( 1052 RTL_CONSTASCII_USTRINGPARAM("sans")))) 1053 aToken.eType = TSANS; 1054 else if (sFontFamily.equalsIgnoreCase(OUString( 1055 RTL_CONSTASCII_USTRINGPARAM("serif")))) 1056 aToken.eType = TSERIF; 1057 else //Just give up, we need to extend our font mechanism to be 1058 //more general 1059 return; 1060 1061 aToken.aText = sFontFamily; 1062 SmFontNode *pFontNode = new SmFontNode(aToken); 1063 pFontNode->SetSubNodes(0,rNodeStack.Pop()); 1064 rNodeStack.Push(pFontNode); 1065 } 1066 if (sColor.getLength()) 1067 { 1068 //Again we can only handle a small set of colours in 1069 //StarMath for now. 1070 const SvXMLTokenMap& rTokenMap = 1071 GetSmImport().GetColorTokenMap(); 1072 aToken.eType = static_cast<SmTokenType>(rTokenMap.Get( 1073 XML_NAMESPACE_MATH, sColor)); 1074 if (aToken.eType != -1) 1075 { 1076 SmFontNode *pFontNode = new SmFontNode(aToken); 1077 pFontNode->SetSubNodes(0,rNodeStack.Pop()); 1078 rNodeStack.Push(pFontNode); 1079 } 1080 } 1081 1082 } 1083 #endif 1084 } 1085 1086 //////////////////////////////////////////////////////////// 1087 1088 class SmXMLPaddedContext_Impl : public SmXMLRowContext_Impl 1089 { 1090 public: 1091 /*Right now the style tag is completely ignored*/ 1092 SmXMLPaddedContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1093 const OUString& rLName) 1094 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {} 1095 1096 void EndElement(); 1097 }; 1098 1099 void SmXMLPaddedContext_Impl::EndElement() 1100 { 1101 /* 1102 <mpadded> accepts any number of arguments; if this number is not 1, its 1103 contents are treated as a single "inferred <mrow>" containing its 1104 arguments 1105 */ 1106 if (GetSmImport().GetNodeStack().Count() - nElementCount > 1) 1107 SmXMLRowContext_Impl::EndElement(); 1108 } 1109 1110 //////////////////////////////////////////////////////////// 1111 1112 class SmXMLPhantomContext_Impl : public SmXMLRowContext_Impl 1113 { 1114 public: 1115 /*Right now the style tag is completely ignored*/ 1116 SmXMLPhantomContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1117 const OUString& rLName) 1118 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {} 1119 1120 void EndElement(); 1121 }; 1122 1123 void SmXMLPhantomContext_Impl::EndElement() 1124 { 1125 /* 1126 <mphantom> accepts any number of arguments; if this number is not 1, its 1127 contents are treated as a single "inferred <mrow>" containing its 1128 arguments 1129 */ 1130 if (GetSmImport().GetNodeStack().Count() - nElementCount > 1) 1131 SmXMLRowContext_Impl::EndElement(); 1132 1133 SmToken aToken; 1134 aToken.cMathChar = '\0'; 1135 aToken.nGroup = 0; 1136 aToken.nLevel = 5; 1137 aToken.eType = TPHANTOM; 1138 1139 SmStructureNode *pPhantom = static_cast<SmStructureNode *> 1140 (new SmFontNode(aToken)); 1141 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 1142 pPhantom->SetSubNodes(0,rNodeStack.Pop()); 1143 rNodeStack.Push(pPhantom); 1144 } 1145 1146 //////////////////////////////////////////////////////////// 1147 1148 class SmXMLFencedContext_Impl : public SmXMLRowContext_Impl 1149 { 1150 protected: 1151 sal_Unicode cBegin; 1152 sal_Unicode cEnd; 1153 1154 public: 1155 SmXMLFencedContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1156 const OUString& rLName) 1157 : SmXMLRowContext_Impl(rImport,nPrefix,rLName), 1158 cBegin('('), cEnd(')') {} 1159 1160 void StartElement(const uno::Reference< xml::sax::XAttributeList > & xAttrList ); 1161 void EndElement(); 1162 }; 1163 1164 1165 void SmXMLFencedContext_Impl::StartElement(const uno::Reference< 1166 xml::sax::XAttributeList > & xAttrList ) 1167 { 1168 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 1169 for (sal_Int16 i=0;i<nAttrCount;i++) 1170 { 1171 OUString sAttrName = xAttrList->getNameByIndex(i); 1172 OUString aLocalName; 1173 sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). 1174 GetKeyByAttrName(sAttrName,&aLocalName); 1175 OUString sValue = xAttrList->getValueByIndex(i); 1176 const SvXMLTokenMap &rAttrTokenMap = 1177 GetSmImport().GetFencedAttrTokenMap(); 1178 switch(rAttrTokenMap.Get(nPrefix,aLocalName)) 1179 { 1180 //temp, starmath cannot handle multichar brackets (I think) 1181 case XML_TOK_OPEN: 1182 cBegin = sValue[0]; 1183 break; 1184 case XML_TOK_CLOSE: 1185 cEnd = sValue[0]; 1186 break; 1187 default: 1188 /*Go to superclass*/ 1189 break; 1190 } 1191 } 1192 } 1193 1194 1195 void SmXMLFencedContext_Impl::EndElement() 1196 { 1197 SmToken aToken; 1198 aToken.cMathChar = '\0'; 1199 aToken.nGroup = 0; 1200 aToken.aText = ','; 1201 aToken.eType = TLEFT; 1202 aToken.nLevel = 5; 1203 1204 aToken.eType = TLPARENT; 1205 aToken.cMathChar = cBegin; 1206 SmStructureNode *pSNode = new SmBraceNode(aToken); 1207 SmNode *pLeft = new SmMathSymbolNode(aToken); 1208 1209 aToken.cMathChar = cEnd; 1210 aToken.eType = TRPARENT; 1211 SmNode *pRight = new SmMathSymbolNode(aToken); 1212 1213 SmNodeArray aRelationArray; 1214 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 1215 1216 aToken.cMathChar = '\0'; 1217 aToken.aText = ','; 1218 aToken.eType = TIDENT; 1219 1220 sal_uLong i = rNodeStack.Count() - nElementCount; 1221 if (rNodeStack.Count() - nElementCount > 1) 1222 i += rNodeStack.Count() - 1 - nElementCount; 1223 aRelationArray.resize(i); 1224 while (rNodeStack.Count() > nElementCount) 1225 { 1226 aRelationArray[--i] = rNodeStack.Pop(); 1227 if (i > 1 && rNodeStack.Count() > 1) 1228 aRelationArray[--i] = new SmGlyphSpecialNode(aToken); 1229 } 1230 1231 SmToken aDummy; 1232 SmStructureNode *pBody = new SmExpressionNode(aDummy); 1233 pBody->SetSubNodes(aRelationArray); 1234 1235 1236 pSNode->SetSubNodes(pLeft,pBody,pRight); 1237 pSNode->SetScaleMode(SCALE_HEIGHT); 1238 GetSmImport().GetNodeStack().Push(pSNode); 1239 } 1240 1241 1242 //////////////////////////////////////////////////////////// 1243 1244 class SmXMLErrorContext_Impl : public SmXMLRowContext_Impl 1245 { 1246 public: 1247 SmXMLErrorContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1248 const OUString& rLName) 1249 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {} 1250 1251 void EndElement(); 1252 }; 1253 1254 void SmXMLErrorContext_Impl::EndElement() 1255 { 1256 /*Right now the error tag is completely ignored, what 1257 can I do with it in starmath, ?, maybe we need a 1258 report window ourselves, do a test for validity of 1259 the xml input, use merrors, and then generate 1260 the markup inside the merror with a big red colour 1261 of something. For now just throw them all away. 1262 */ 1263 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 1264 while (rNodeStack.Count() > nElementCount) 1265 { 1266 SmNode *pNode = rNodeStack.Pop(); 1267 delete pNode; 1268 } 1269 } 1270 1271 //////////////////////////////////////////////////////////// 1272 1273 class SmXMLNumberContext_Impl : public SmXMLImportContext 1274 { 1275 protected: 1276 SmToken aToken; 1277 1278 public: 1279 SmXMLNumberContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1280 const OUString& rLName) 1281 : SmXMLImportContext(rImport,nPrefix,rLName) 1282 { 1283 aToken.cMathChar = '\0'; 1284 aToken.nGroup = 0; 1285 aToken.nLevel = 5; 1286 aToken.eType = TNUMBER; 1287 } 1288 1289 virtual void TCharacters(const OUString &rChars); 1290 1291 void EndElement(); 1292 }; 1293 1294 void SmXMLNumberContext_Impl::TCharacters(const OUString &rChars) 1295 { 1296 aToken.aText = rChars; 1297 } 1298 1299 void SmXMLNumberContext_Impl::EndElement() 1300 { 1301 GetSmImport().GetNodeStack().Push(new SmTextNode(aToken,FNT_NUMBER)); 1302 } 1303 1304 //////////////////////////////////////////////////////////// 1305 1306 class SmXMLAnnotationContext_Impl : public SmXMLImportContext 1307 { 1308 sal_Bool bIsStarMath; 1309 1310 public: 1311 SmXMLAnnotationContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1312 const OUString& rLName) 1313 : SmXMLImportContext(rImport,nPrefix,rLName), bIsStarMath(sal_False) {} 1314 1315 virtual void Characters(const OUString &rChars); 1316 1317 void StartElement(const uno::Reference<xml::sax::XAttributeList > & xAttrList ); 1318 }; 1319 1320 void SmXMLAnnotationContext_Impl::StartElement(const uno::Reference< 1321 xml::sax::XAttributeList > & xAttrList ) 1322 { 1323 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 1324 for (sal_Int16 i=0;i<nAttrCount;i++) 1325 { 1326 OUString sAttrName = xAttrList->getNameByIndex(i); 1327 OUString aLocalName; 1328 sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). 1329 GetKeyByAttrName(sAttrName,&aLocalName); 1330 1331 OUString sValue = xAttrList->getValueByIndex(i); 1332 const SvXMLTokenMap &rAttrTokenMap = 1333 GetSmImport().GetAnnotationAttrTokenMap(); 1334 switch(rAttrTokenMap.Get(nPrefix,aLocalName)) 1335 { 1336 case XML_TOK_ENCODING: 1337 bIsStarMath= sValue.equals( 1338 OUString(RTL_CONSTASCII_USTRINGPARAM("StarMath 5.0"))); 1339 break; 1340 default: 1341 break; 1342 } 1343 } 1344 } 1345 1346 void SmXMLAnnotationContext_Impl::Characters(const OUString &rChars) 1347 { 1348 if (bIsStarMath) 1349 GetSmImport().GetText().Append(String(rChars)); 1350 } 1351 1352 //////////////////////////////////////////////////////////// 1353 1354 class SmXMLTextContext_Impl : public SmXMLImportContext 1355 { 1356 protected: 1357 SmToken aToken; 1358 1359 public: 1360 SmXMLTextContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1361 const OUString& rLName) 1362 : SmXMLImportContext(rImport,nPrefix,rLName) 1363 { 1364 aToken.cMathChar = '\0'; 1365 aToken.nGroup = 0; 1366 aToken.nLevel = 5; 1367 aToken.eType = TTEXT; 1368 } 1369 1370 virtual void TCharacters(const OUString &rChars); 1371 1372 void EndElement(); 1373 }; 1374 1375 void SmXMLTextContext_Impl::TCharacters(const OUString &rChars) 1376 { 1377 aToken.aText = rChars; 1378 } 1379 1380 void SmXMLTextContext_Impl::EndElement() 1381 { 1382 GetSmImport().GetNodeStack().Push(new SmTextNode(aToken,FNT_TEXT)); 1383 } 1384 1385 //////////////////////////////////////////////////////////// 1386 1387 class SmXMLStringContext_Impl : public SmXMLImportContext 1388 { 1389 protected: 1390 SmToken aToken; 1391 1392 public: 1393 SmXMLStringContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1394 const OUString& rLName) 1395 : SmXMLImportContext(rImport,nPrefix,rLName) 1396 { 1397 aToken.cMathChar = '\0'; 1398 aToken.nGroup = 0; 1399 aToken.nLevel = 5; 1400 aToken.eType = TTEXT; 1401 } 1402 1403 virtual void TCharacters(const OUString &rChars); 1404 1405 void EndElement(); 1406 }; 1407 1408 void SmXMLStringContext_Impl::TCharacters(const OUString &rChars) 1409 { 1410 /* 1411 The content of <ms> elements should be rendered with visible "escaping" of 1412 certain characters in the content, including at least "double quote" 1413 itself, and preferably whitespace other than individual blanks. The intent 1414 is for the viewer to see that the expression is a string literal, and to 1415 see exactly which characters form its content. For example, <ms>double 1416 quote is "</ms> might be rendered as "double quote is \"". 1417 1418 Obviously this isn't fully done here. 1419 */ 1420 aToken.aText.Erase(); 1421 aToken.aText += '\"'; 1422 aToken.aText += String(rChars); 1423 aToken.aText += '\"'; 1424 } 1425 1426 void SmXMLStringContext_Impl::EndElement() 1427 { 1428 GetSmImport().GetNodeStack().Push(new SmTextNode(aToken,FNT_FIXED)); 1429 } 1430 1431 //////////////////////////////////////////////////////////// 1432 1433 class SmXMLIdentifierContext_Impl : public SmXMLImportContext 1434 { 1435 protected: 1436 SmXMLContext_Helper aStyleHelper; 1437 SmToken aToken; 1438 1439 public: 1440 SmXMLIdentifierContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1441 const OUString& rLName) 1442 : SmXMLImportContext(rImport,nPrefix,rLName),aStyleHelper(*this) 1443 { 1444 aToken.cMathChar = '\0'; 1445 aToken.nGroup = 0; 1446 aToken.nLevel = 5; 1447 aToken.eType = TIDENT; 1448 } 1449 1450 void TCharacters(const OUString &rChars); 1451 void StartElement(const uno::Reference< xml::sax::XAttributeList > & xAttrList ) 1452 { 1453 aStyleHelper.RetrieveAttrs(xAttrList); 1454 }; 1455 void EndElement(); 1456 }; 1457 1458 void SmXMLIdentifierContext_Impl::EndElement() 1459 { 1460 SmTextNode *pNode = 0; 1461 //we will handle identifier italic/normal here instead of with a standalone 1462 //font node 1463 if (((aStyleHelper.nIsItalic == -1) && (aToken.aText.Len() > 1)) 1464 || ((aStyleHelper.nIsItalic == 0) && (aToken.aText.Len() == 1))) 1465 { 1466 pNode = new SmTextNode(aToken,FNT_FUNCTION); 1467 pNode->GetFont().SetItalic(ITALIC_NONE); 1468 aStyleHelper.nIsItalic = -1; 1469 } 1470 else 1471 pNode = new SmTextNode(aToken,FNT_VARIABLE); 1472 if (aStyleHelper.bFontNodeNeeded && aStyleHelper.nIsItalic != -1) 1473 { 1474 if (aStyleHelper.nIsItalic) 1475 pNode->GetFont().SetItalic(ITALIC_NORMAL); 1476 else 1477 pNode->GetFont().SetItalic(ITALIC_NONE); 1478 } 1479 1480 if ((-1!=aStyleHelper.nIsBold) || (0.0!=aStyleHelper.nFontSize) || 1481 (aStyleHelper.sFontFamily.getLength()) || 1482 aStyleHelper.sColor.getLength()) 1483 aStyleHelper.bFontNodeNeeded=sal_True; 1484 else 1485 aStyleHelper.bFontNodeNeeded=sal_False; 1486 if (aStyleHelper.bFontNodeNeeded) 1487 aStyleHelper.ApplyAttrs(); 1488 GetSmImport().GetNodeStack().Push(pNode); 1489 } 1490 1491 void SmXMLIdentifierContext_Impl::TCharacters(const OUString &rChars) 1492 { 1493 aToken.aText = rChars; 1494 } 1495 1496 //////////////////////////////////////////////////////////// 1497 1498 class SmXMLOperatorContext_Impl : public SmXMLImportContext 1499 { 1500 sal_Bool bIsStretchy; 1501 1502 protected: 1503 SmToken aToken; 1504 1505 public: 1506 SmXMLOperatorContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1507 const OUString& rLName) 1508 : SmXMLImportContext(rImport,nPrefix,rLName), bIsStretchy(sal_False) 1509 { 1510 aToken.nGroup = 0; 1511 aToken.eType = TSPECIAL; 1512 aToken.nLevel = 5; 1513 } 1514 1515 void TCharacters(const OUString &rChars); 1516 void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList ); 1517 void EndElement(); 1518 }; 1519 1520 void SmXMLOperatorContext_Impl::TCharacters(const OUString &rChars) 1521 { 1522 aToken.cMathChar = rChars[0]; 1523 } 1524 1525 void SmXMLOperatorContext_Impl::EndElement() 1526 { 1527 SmMathSymbolNode *pNode = new SmMathSymbolNode(aToken); 1528 //For stretchy scaling the scaling must be retrieved from this node 1529 //and applied to the expression itself so as to get the expression 1530 //to scale the operator to the height of the expression itself 1531 if (bIsStretchy) 1532 pNode->SetScaleMode(SCALE_HEIGHT); 1533 GetSmImport().GetNodeStack().Push(pNode); 1534 } 1535 1536 1537 1538 void SmXMLOperatorContext_Impl::StartElement(const uno::Reference< 1539 xml::sax::XAttributeList > & xAttrList ) 1540 { 1541 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 1542 for (sal_Int16 i=0;i<nAttrCount;i++) 1543 { 1544 OUString sAttrName = xAttrList->getNameByIndex(i); 1545 OUString aLocalName; 1546 sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). 1547 GetKeyByAttrName(sAttrName,&aLocalName); 1548 1549 OUString sValue = xAttrList->getValueByIndex(i); 1550 const SvXMLTokenMap &rAttrTokenMap = 1551 GetSmImport().GetOperatorAttrTokenMap(); 1552 switch(rAttrTokenMap.Get(nPrefix,aLocalName)) 1553 { 1554 case XML_TOK_STRETCHY: 1555 bIsStretchy = sValue.equals( 1556 GetXMLToken(XML_TRUE)); 1557 break; 1558 default: 1559 break; 1560 } 1561 } 1562 } 1563 1564 1565 //////////////////////////////////////////////////////////// 1566 1567 class SmXMLSpaceContext_Impl : public SmXMLImportContext 1568 { 1569 public: 1570 SmXMLSpaceContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1571 const OUString& rLName) 1572 : SmXMLImportContext(rImport,nPrefix,rLName) {} 1573 1574 void StartElement(const uno::Reference< xml::sax::XAttributeList >& xAttrList ); 1575 }; 1576 1577 void SmXMLSpaceContext_Impl::StartElement( 1578 const uno::Reference<xml::sax::XAttributeList > & /*xAttrList*/ ) 1579 { 1580 SmToken aToken; 1581 aToken.cMathChar = '\0'; 1582 aToken.nGroup = 0; 1583 aToken.eType = TBLANK; 1584 aToken.nLevel = 5; 1585 SmBlankNode *pBlank = new SmBlankNode(aToken); 1586 pBlank->IncreaseBy(aToken); 1587 GetSmImport().GetNodeStack().Push(pBlank); 1588 } 1589 1590 //////////////////////////////////////////////////////////// 1591 1592 class SmXMLSubContext_Impl : public SmXMLRowContext_Impl 1593 { 1594 protected: 1595 void GenericEndElement(SmTokenType eType,SmSubSup aSubSup); 1596 1597 public: 1598 SmXMLSubContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1599 const OUString& rLName) 1600 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {} 1601 1602 void EndElement() 1603 { 1604 GenericEndElement(TRSUB,RSUB); 1605 } 1606 }; 1607 1608 1609 void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup) 1610 { 1611 /*The <msub> element requires exactly 2 arguments.*/ 1612 const bool bNodeCheck = GetSmImport().GetNodeStack().Count() - nElementCount == 2; 1613 DBG_ASSERT( bNodeCheck, "Sub has not two arguments" ); 1614 if (!bNodeCheck) 1615 return; 1616 1617 SmToken aToken; 1618 aToken.cMathChar = '\0'; 1619 aToken.nGroup = 0; 1620 aToken.nLevel = 0; 1621 aToken.eType = eType; 1622 SmSubSupNode *pNode = new SmSubSupNode(aToken); 1623 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 1624 1625 // initialize subnodes array 1626 SmNodeArray aSubNodes; 1627 aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES); 1628 for (sal_uLong i = 1; i < aSubNodes.size(); i++) 1629 aSubNodes[i] = NULL; 1630 1631 aSubNodes[eSubSup+1] = rNodeStack.Pop(); 1632 aSubNodes[0] = rNodeStack.Pop(); 1633 pNode->SetSubNodes(aSubNodes); 1634 rNodeStack.Push(pNode); 1635 } 1636 1637 //////////////////////////////////////////////////////////// 1638 1639 class SmXMLSupContext_Impl : public SmXMLSubContext_Impl 1640 { 1641 public: 1642 SmXMLSupContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1643 const OUString& rLName) 1644 : SmXMLSubContext_Impl(rImport,nPrefix,rLName) {} 1645 1646 void EndElement() 1647 { 1648 GenericEndElement(TRSUP,RSUP); 1649 } 1650 }; 1651 1652 //////////////////////////////////////////////////////////// 1653 1654 class SmXMLSubSupContext_Impl : public SmXMLRowContext_Impl 1655 { 1656 protected: 1657 void GenericEndElement(SmTokenType eType, SmSubSup aSub,SmSubSup aSup); 1658 1659 public: 1660 SmXMLSubSupContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1661 const OUString& rLName) 1662 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {} 1663 1664 void EndElement() 1665 { 1666 GenericEndElement(TRSUB,RSUB,RSUP); 1667 } 1668 }; 1669 1670 void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType, 1671 SmSubSup aSub,SmSubSup aSup) 1672 { 1673 /*The <msub> element requires exactly 3 arguments.*/ 1674 const bool bNodeCheck = GetSmImport().GetNodeStack().Count() - nElementCount == 3; 1675 DBG_ASSERT( bNodeCheck, "SubSup has not three arguments" ); 1676 if (!bNodeCheck) 1677 return; 1678 1679 SmToken aToken; 1680 aToken.cMathChar = '\0'; 1681 aToken.nGroup = 0; 1682 aToken.nLevel = 0; 1683 aToken.eType = eType; 1684 SmSubSupNode *pNode = new SmSubSupNode(aToken); 1685 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 1686 1687 // initialize subnodes array 1688 SmNodeArray aSubNodes; 1689 aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES); 1690 for (sal_uLong i = 1; i < aSubNodes.size(); i++) 1691 aSubNodes[i] = NULL; 1692 1693 aSubNodes[aSup+1] = rNodeStack.Pop(); 1694 aSubNodes[aSub+1] = rNodeStack.Pop(); 1695 aSubNodes[0] = rNodeStack.Pop(); 1696 pNode->SetSubNodes(aSubNodes); 1697 rNodeStack.Push(pNode); 1698 } 1699 1700 //////////////////////////////////////////////////////////// 1701 1702 class SmXMLUnderContext_Impl : public SmXMLSubContext_Impl 1703 { 1704 protected: 1705 sal_Int16 nAttrCount; 1706 1707 public: 1708 SmXMLUnderContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1709 const OUString& rLName) 1710 : SmXMLSubContext_Impl(rImport,nPrefix,rLName) {} 1711 1712 void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList ); 1713 void EndElement(); 1714 void HandleAccent(); 1715 }; 1716 1717 void SmXMLUnderContext_Impl::StartElement(const uno::Reference< 1718 xml::sax::XAttributeList > & xAttrList ) 1719 { 1720 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 1721 } 1722 1723 void SmXMLUnderContext_Impl::HandleAccent() 1724 { 1725 const bool bNodeCheck = GetSmImport().GetNodeStack().Count() - nElementCount == 2; 1726 DBG_ASSERT( bNodeCheck, "Sub has not two arguments" ); 1727 if (!bNodeCheck) 1728 return; 1729 1730 /*Just one special case for the underline thing*/ 1731 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 1732 SmNode *pTest = rNodeStack.Pop(); 1733 SmToken aToken; 1734 aToken.cMathChar = '\0'; 1735 aToken.nGroup = 0; 1736 aToken.nLevel = 0; 1737 aToken.eType = TUNDERLINE; 1738 1739 1740 SmNodeArray aSubNodes; 1741 aSubNodes.resize(2); 1742 1743 SmStructureNode *pNode = new SmAttributNode(aToken); 1744 if ((pTest->GetToken().cMathChar & 0x0FFF) == 0x0332) 1745 { 1746 aSubNodes[0] = new SmRectangleNode(aToken); 1747 delete pTest; 1748 } 1749 else 1750 aSubNodes[0] = pTest; 1751 1752 aSubNodes[1] = rNodeStack.Pop(); 1753 pNode->SetSubNodes(aSubNodes); 1754 pNode->SetScaleMode(SCALE_WIDTH); 1755 rNodeStack.Push(pNode); 1756 } 1757 1758 1759 void SmXMLUnderContext_Impl::EndElement() 1760 { 1761 if (!nAttrCount) 1762 GenericEndElement(TCSUB,CSUB); 1763 else 1764 HandleAccent(); 1765 #if 0 1766 //UnderBrace trick 1767 SmStructureNode *pNode = rNodeStack.Pop(); 1768 if (pNode->GetSubNode(1)->GetToken().cMathChar == (0x0332|0xf000)) 1769 if (pNode->GetSubNode(0)->GetToken().cMathChar == (0x0332|0xf000)) 1770 #endif 1771 } 1772 1773 //////////////////////////////////////////////////////////// 1774 1775 class SmXMLOverContext_Impl : public SmXMLSubContext_Impl 1776 { 1777 protected: 1778 sal_Int16 nAttrCount; 1779 1780 public: 1781 SmXMLOverContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1782 const OUString& rLName) 1783 : SmXMLSubContext_Impl(rImport,nPrefix,rLName), nAttrCount(0) {} 1784 1785 void EndElement(); 1786 void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList ); 1787 void HandleAccent(); 1788 }; 1789 1790 1791 void SmXMLOverContext_Impl::StartElement(const uno::Reference< 1792 xml::sax::XAttributeList > & xAttrList ) 1793 { 1794 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 1795 } 1796 1797 1798 void SmXMLOverContext_Impl::EndElement() 1799 { 1800 if (!nAttrCount) 1801 GenericEndElement(TCSUP,CSUP); 1802 else 1803 HandleAccent(); 1804 } 1805 1806 1807 void SmXMLOverContext_Impl::HandleAccent() 1808 { 1809 const bool bNodeCheck = GetSmImport().GetNodeStack().Count() - nElementCount == 2; 1810 DBG_ASSERT( bNodeCheck, "Sub has not two arguments" ); 1811 if (!bNodeCheck) 1812 return; 1813 1814 SmToken aToken; 1815 aToken.cMathChar = '\0'; 1816 aToken.nGroup = 0; 1817 aToken.nLevel = 0; 1818 aToken.eType = TACUTE; 1819 1820 SmAttributNode *pNode = new SmAttributNode(aToken); 1821 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 1822 1823 SmNodeArray aSubNodes; 1824 aSubNodes.resize(2); 1825 aSubNodes[0] = rNodeStack.Pop(); 1826 aSubNodes[1] = rNodeStack.Pop(); 1827 pNode->SetSubNodes(aSubNodes); 1828 pNode->SetScaleMode(SCALE_WIDTH); 1829 rNodeStack.Push(pNode); 1830 1831 } 1832 1833 //////////////////////////////////////////////////////////// 1834 1835 class SmXMLUnderOverContext_Impl : public SmXMLSubSupContext_Impl 1836 { 1837 public: 1838 SmXMLUnderOverContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1839 const OUString& rLName) 1840 : SmXMLSubSupContext_Impl(rImport,nPrefix,rLName) {} 1841 1842 void EndElement() 1843 { 1844 GenericEndElement(TCSUB,CSUB,CSUP); 1845 } 1846 }; 1847 1848 //////////////////////////////////////////////////////////// 1849 1850 class SmXMLMultiScriptsContext_Impl : public SmXMLSubSupContext_Impl 1851 { 1852 sal_Bool bHasPrescripts; 1853 1854 public: 1855 SmXMLMultiScriptsContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1856 const OUString& rLName) : 1857 SmXMLSubSupContext_Impl(rImport,nPrefix,rLName), 1858 bHasPrescripts(sal_False) {} 1859 1860 void EndElement(); 1861 void MiddleElement(); 1862 SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, 1863 const OUString& rLocalName, 1864 const uno::Reference< xml::sax::XAttributeList > &xAttrList); 1865 }; 1866 1867 //////////////////////////////////////////////////////////// 1868 1869 class SmXMLNoneContext_Impl : public SmXMLImportContext 1870 { 1871 public: 1872 SmXMLNoneContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1873 const OUString& rLName) 1874 : SmXMLImportContext(rImport,nPrefix,rLName) {} 1875 1876 void EndElement(); 1877 }; 1878 1879 1880 void SmXMLNoneContext_Impl::EndElement(void) 1881 { 1882 SmToken aToken; 1883 aToken.cMathChar = '\0'; 1884 aToken.nGroup = 0; 1885 aToken.aText.Erase(); 1886 aToken.nLevel = 5; 1887 aToken.eType = TIDENT; 1888 GetSmImport().GetNodeStack().Push( 1889 new SmTextNode(aToken,FNT_VARIABLE)); 1890 } 1891 1892 //////////////////////////////////////////////////////////// 1893 1894 class SmXMLPrescriptsContext_Impl : public SmXMLImportContext 1895 { 1896 public: 1897 SmXMLPrescriptsContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1898 const OUString& rLName) 1899 : SmXMLImportContext(rImport,nPrefix,rLName) {} 1900 }; 1901 1902 //////////////////////////////////////////////////////////// 1903 1904 class SmXMLTableRowContext_Impl : public SmXMLRowContext_Impl 1905 { 1906 public: 1907 SmXMLTableRowContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1908 const OUString& rLName) : 1909 SmXMLRowContext_Impl(rImport,nPrefix,rLName) 1910 {} 1911 1912 SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, 1913 const OUString& rLocalName, 1914 const uno::Reference< xml::sax::XAttributeList > &xAttrList); 1915 }; 1916 1917 1918 //////////////////////////////////////////////////////////// 1919 1920 class SmXMLTableContext_Impl : public SmXMLTableRowContext_Impl 1921 { 1922 public: 1923 SmXMLTableContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1924 const OUString& rLName) : 1925 SmXMLTableRowContext_Impl(rImport,nPrefix,rLName) 1926 {} 1927 1928 void EndElement(); 1929 SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, 1930 const OUString& rLocalName, 1931 const uno::Reference< xml::sax::XAttributeList > &xAttrList); 1932 }; 1933 1934 1935 //////////////////////////////////////////////////////////// 1936 1937 class SmXMLTableCellContext_Impl : public SmXMLRowContext_Impl 1938 { 1939 public: 1940 SmXMLTableCellContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1941 const OUString& rLName) : 1942 SmXMLRowContext_Impl(rImport,nPrefix,rLName) 1943 {} 1944 }; 1945 1946 //////////////////////////////////////////////////////////// 1947 1948 class SmXMLAlignGroupContext_Impl : public SmXMLRowContext_Impl 1949 { 1950 public: 1951 SmXMLAlignGroupContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1952 const OUString& rLName) : 1953 SmXMLRowContext_Impl(rImport,nPrefix,rLName) 1954 {} 1955 1956 /*Don't do anything with alignment for now*/ 1957 void EndElement() 1958 { 1959 } 1960 }; 1961 1962 //////////////////////////////////////////////////////////// 1963 1964 class SmXMLActionContext_Impl : public SmXMLRowContext_Impl 1965 { 1966 public: 1967 SmXMLActionContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix, 1968 const OUString& rLName) : 1969 SmXMLRowContext_Impl(rImport,nPrefix,rLName) 1970 {} 1971 1972 void EndElement(); 1973 }; 1974 1975 //////////////////////////////////////////////////////////// 1976 1977 // NB: virtually inherit so we can multiply inherit properly 1978 // in SmXMLFlatDocContext_Impl 1979 class SmXMLOfficeContext_Impl : public virtual SvXMLImportContext 1980 { 1981 public: 1982 SmXMLOfficeContext_Impl( SmXMLImport &rImport, sal_uInt16 nPrfx, 1983 const OUString& rLName) 1984 : SvXMLImportContext(rImport,nPrfx,rLName) {} 1985 1986 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList); 1987 }; 1988 1989 SvXMLImportContext *SmXMLOfficeContext_Impl::CreateChildContext(sal_uInt16 nPrefix, 1990 const OUString& rLocalName, 1991 const uno::Reference< xml::sax::XAttributeList > &xAttrList) 1992 { 1993 SvXMLImportContext *pContext = 0; 1994 if ( XML_NAMESPACE_OFFICE == nPrefix && 1995 rLocalName == GetXMLToken(XML_META) ) 1996 { 1997 DBG_WARNING("XML_TOK_DOC_META: should not have come here, maybe document is invalid?"); 1998 } 1999 else if ( XML_NAMESPACE_OFFICE == nPrefix && 2000 rLocalName == GetXMLToken(XML_SETTINGS) ) 2001 { 2002 pContext = new XMLDocumentSettingsContext( GetImport(), 2003 XML_NAMESPACE_OFFICE, rLocalName, 2004 xAttrList ); 2005 } 2006 else 2007 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); 2008 2009 return pContext; 2010 } 2011 2012 //////////////////////////////////////////////////////////// 2013 2014 // context for flat file xml format 2015 class SmXMLFlatDocContext_Impl 2016 : public SmXMLOfficeContext_Impl, public SvXMLMetaDocumentContext 2017 { 2018 public: 2019 SmXMLFlatDocContext_Impl( SmXMLImport& i_rImport, 2020 sal_uInt16 i_nPrefix, const OUString & i_rLName, 2021 const uno::Reference<document::XDocumentProperties>& i_xDocProps, 2022 const uno::Reference<xml::sax::XDocumentHandler>& i_xDocBuilder); 2023 2024 virtual ~SmXMLFlatDocContext_Impl(); 2025 2026 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 i_nPrefix, const OUString& i_rLocalName, const uno::Reference<xml::sax::XAttributeList>& i_xAttrList); 2027 }; 2028 2029 SmXMLFlatDocContext_Impl::SmXMLFlatDocContext_Impl( SmXMLImport& i_rImport, 2030 sal_uInt16 i_nPrefix, const OUString & i_rLName, 2031 const uno::Reference<document::XDocumentProperties>& i_xDocProps, 2032 const uno::Reference<xml::sax::XDocumentHandler>& i_xDocBuilder) : 2033 SvXMLImportContext(i_rImport, i_nPrefix, i_rLName), 2034 SmXMLOfficeContext_Impl(i_rImport, i_nPrefix, i_rLName), 2035 SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName, 2036 i_xDocProps, i_xDocBuilder) 2037 { 2038 } 2039 2040 SmXMLFlatDocContext_Impl::~SmXMLFlatDocContext_Impl() 2041 { 2042 } 2043 2044 SvXMLImportContext *SmXMLFlatDocContext_Impl::CreateChildContext( 2045 sal_uInt16 i_nPrefix, const OUString& i_rLocalName, 2046 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList) 2047 { 2048 // behave like meta base class iff we encounter office:meta 2049 if ( XML_NAMESPACE_OFFICE == i_nPrefix && 2050 i_rLocalName == GetXMLToken(XML_META) ) 2051 { 2052 return SvXMLMetaDocumentContext::CreateChildContext( 2053 i_nPrefix, i_rLocalName, i_xAttrList ); 2054 } 2055 else 2056 { 2057 return SmXMLOfficeContext_Impl::CreateChildContext( 2058 i_nPrefix, i_rLocalName, i_xAttrList ); 2059 } 2060 } 2061 2062 //////////////////////////////////////////////////////////// 2063 2064 static __FAR_DATA SvXMLTokenMapEntry aPresLayoutElemTokenMap[] = 2065 { 2066 { XML_NAMESPACE_MATH, XML_SEMANTICS, XML_TOK_SEMANTICS }, 2067 { XML_NAMESPACE_MATH, XML_MATH, XML_TOK_MATH }, 2068 { XML_NAMESPACE_MATH, XML_MSTYLE, XML_TOK_MSTYLE }, 2069 { XML_NAMESPACE_MATH, XML_MERROR, XML_TOK_MERROR }, 2070 { XML_NAMESPACE_MATH, XML_MPHANTOM, XML_TOK_MPHANTOM }, 2071 { XML_NAMESPACE_MATH, XML_MROW, XML_TOK_MROW }, 2072 { XML_NAMESPACE_MATH, XML_MFRAC, XML_TOK_MFRAC }, 2073 { XML_NAMESPACE_MATH, XML_MSQRT, XML_TOK_MSQRT }, 2074 { XML_NAMESPACE_MATH, XML_MROOT, XML_TOK_MROOT }, 2075 { XML_NAMESPACE_MATH, XML_MSUB, XML_TOK_MSUB }, 2076 { XML_NAMESPACE_MATH, XML_MSUP, XML_TOK_MSUP }, 2077 { XML_NAMESPACE_MATH, XML_MSUBSUP, XML_TOK_MSUBSUP }, 2078 { XML_NAMESPACE_MATH, XML_MUNDER, XML_TOK_MUNDER }, 2079 { XML_NAMESPACE_MATH, XML_MOVER, XML_TOK_MOVER }, 2080 { XML_NAMESPACE_MATH, XML_MUNDEROVER, XML_TOK_MUNDEROVER }, 2081 { XML_NAMESPACE_MATH, XML_MMULTISCRIPTS, XML_TOK_MMULTISCRIPTS }, 2082 { XML_NAMESPACE_MATH, XML_MTABLE, XML_TOK_MTABLE }, 2083 { XML_NAMESPACE_MATH, XML_MACTION, XML_TOK_MACTION }, 2084 { XML_NAMESPACE_MATH, XML_MFENCED, XML_TOK_MFENCED }, 2085 { XML_NAMESPACE_MATH, XML_MPADDED, XML_TOK_MPADDED }, 2086 XML_TOKEN_MAP_END 2087 }; 2088 2089 static __FAR_DATA SvXMLTokenMapEntry aPresLayoutAttrTokenMap[] = 2090 { 2091 { XML_NAMESPACE_MATH, XML_FONTWEIGHT, XML_TOK_FONTWEIGHT }, 2092 { XML_NAMESPACE_MATH, XML_FONTSTYLE, XML_TOK_FONTSTYLE }, 2093 { XML_NAMESPACE_MATH, XML_FONTSIZE, XML_TOK_FONTSIZE }, 2094 { XML_NAMESPACE_MATH, XML_FONTFAMILY, XML_TOK_FONTFAMILY }, 2095 { XML_NAMESPACE_MATH, XML_COLOR, XML_TOK_COLOR }, 2096 XML_TOKEN_MAP_END 2097 }; 2098 2099 static __FAR_DATA SvXMLTokenMapEntry aFencedAttrTokenMap[] = 2100 { 2101 { XML_NAMESPACE_MATH, XML_OPEN, XML_TOK_OPEN }, 2102 { XML_NAMESPACE_MATH, XML_CLOSE, XML_TOK_CLOSE }, 2103 XML_TOKEN_MAP_END 2104 }; 2105 2106 static __FAR_DATA SvXMLTokenMapEntry aOperatorAttrTokenMap[] = 2107 { 2108 { XML_NAMESPACE_MATH, XML_STRETCHY, XML_TOK_STRETCHY }, 2109 XML_TOKEN_MAP_END 2110 }; 2111 2112 static __FAR_DATA SvXMLTokenMapEntry aAnnotationAttrTokenMap[] = 2113 { 2114 { XML_NAMESPACE_MATH, XML_ENCODING, XML_TOK_ENCODING }, 2115 XML_TOKEN_MAP_END 2116 }; 2117 2118 2119 static __FAR_DATA SvXMLTokenMapEntry aPresElemTokenMap[] = 2120 { 2121 { XML_NAMESPACE_MATH, XML_ANNOTATION, XML_TOK_ANNOTATION }, 2122 { XML_NAMESPACE_MATH, XML_MI, XML_TOK_MI }, 2123 { XML_NAMESPACE_MATH, XML_MN, XML_TOK_MN }, 2124 { XML_NAMESPACE_MATH, XML_MO, XML_TOK_MO }, 2125 { XML_NAMESPACE_MATH, XML_MTEXT, XML_TOK_MTEXT }, 2126 { XML_NAMESPACE_MATH, XML_MSPACE,XML_TOK_MSPACE }, 2127 { XML_NAMESPACE_MATH, XML_MS, XML_TOK_MS }, 2128 { XML_NAMESPACE_MATH, XML_MALIGNGROUP, XML_TOK_MALIGNGROUP }, 2129 XML_TOKEN_MAP_END 2130 }; 2131 2132 static __FAR_DATA SvXMLTokenMapEntry aPresScriptEmptyElemTokenMap[] = 2133 { 2134 { XML_NAMESPACE_MATH, XML_MPRESCRIPTS, XML_TOK_MPRESCRIPTS }, 2135 { XML_NAMESPACE_MATH, XML_NONE, XML_TOK_NONE }, 2136 XML_TOKEN_MAP_END 2137 }; 2138 2139 static __FAR_DATA SvXMLTokenMapEntry aPresTableElemTokenMap[] = 2140 { 2141 { XML_NAMESPACE_MATH, XML_MTR, XML_TOK_MTR }, 2142 { XML_NAMESPACE_MATH, XML_MTD, XML_TOK_MTD }, 2143 XML_TOKEN_MAP_END 2144 }; 2145 2146 static __FAR_DATA SvXMLTokenMapEntry aColorTokenMap[] = 2147 { 2148 { XML_NAMESPACE_MATH, XML_BLACK, TBLACK}, 2149 { XML_NAMESPACE_MATH, XML_WHITE, TWHITE}, 2150 { XML_NAMESPACE_MATH, XML_RED, TRED}, 2151 { XML_NAMESPACE_MATH, XML_GREEN, TGREEN}, 2152 { XML_NAMESPACE_MATH, XML_BLUE, TBLUE}, 2153 { XML_NAMESPACE_MATH, XML_AQUA, TCYAN}, 2154 { XML_NAMESPACE_MATH, XML_FUCHSIA, TMAGENTA}, 2155 { XML_NAMESPACE_MATH, XML_YELLOW, TYELLOW}, 2156 XML_TOKEN_MAP_END 2157 }; 2158 2159 2160 //////////////////////////////////////////////////////////// 2161 2162 const SvXMLTokenMap& SmXMLImport::GetPresLayoutElemTokenMap() 2163 { 2164 if (!pPresLayoutElemTokenMap) 2165 pPresLayoutElemTokenMap = new SvXMLTokenMap(aPresLayoutElemTokenMap); 2166 return *pPresLayoutElemTokenMap; 2167 } 2168 2169 const SvXMLTokenMap& SmXMLImport::GetPresLayoutAttrTokenMap() 2170 { 2171 if (!pPresLayoutAttrTokenMap) 2172 pPresLayoutAttrTokenMap = new SvXMLTokenMap(aPresLayoutAttrTokenMap); 2173 return *pPresLayoutAttrTokenMap; 2174 } 2175 2176 2177 const SvXMLTokenMap& SmXMLImport::GetFencedAttrTokenMap() 2178 { 2179 if (!pFencedAttrTokenMap) 2180 pFencedAttrTokenMap = new SvXMLTokenMap(aFencedAttrTokenMap); 2181 return *pFencedAttrTokenMap; 2182 } 2183 2184 const SvXMLTokenMap& SmXMLImport::GetOperatorAttrTokenMap() 2185 { 2186 if (!pOperatorAttrTokenMap) 2187 pOperatorAttrTokenMap = new SvXMLTokenMap(aOperatorAttrTokenMap); 2188 return *pOperatorAttrTokenMap; 2189 } 2190 2191 const SvXMLTokenMap& SmXMLImport::GetAnnotationAttrTokenMap() 2192 { 2193 if (!pAnnotationAttrTokenMap) 2194 pAnnotationAttrTokenMap = new SvXMLTokenMap(aAnnotationAttrTokenMap); 2195 return *pAnnotationAttrTokenMap; 2196 } 2197 2198 const SvXMLTokenMap& SmXMLImport::GetPresElemTokenMap() 2199 { 2200 if (!pPresElemTokenMap) 2201 pPresElemTokenMap = new SvXMLTokenMap(aPresElemTokenMap); 2202 return *pPresElemTokenMap; 2203 } 2204 2205 const SvXMLTokenMap& SmXMLImport::GetPresScriptEmptyElemTokenMap() 2206 { 2207 if (!pPresScriptEmptyElemTokenMap) 2208 pPresScriptEmptyElemTokenMap = new 2209 SvXMLTokenMap(aPresScriptEmptyElemTokenMap); 2210 return *pPresScriptEmptyElemTokenMap; 2211 } 2212 2213 const SvXMLTokenMap& SmXMLImport::GetPresTableElemTokenMap() 2214 { 2215 if (!pPresTableElemTokenMap) 2216 pPresTableElemTokenMap = new SvXMLTokenMap(aPresTableElemTokenMap); 2217 return *pPresTableElemTokenMap; 2218 } 2219 2220 const SvXMLTokenMap& SmXMLImport::GetColorTokenMap() 2221 { 2222 if (!pColorTokenMap) 2223 pColorTokenMap = new SvXMLTokenMap(aColorTokenMap); 2224 return *pColorTokenMap; 2225 } 2226 2227 //////////////////////////////////////////////////////////// 2228 2229 SvXMLImportContext *SmXMLDocContext_Impl::CreateChildContext( 2230 sal_uInt16 nPrefix, 2231 const OUString& rLocalName, 2232 const uno::Reference<xml::sax::XAttributeList>& xAttrList) 2233 { 2234 SvXMLImportContext* pContext = 0L; 2235 2236 const SvXMLTokenMap& rTokenMap = GetSmImport().GetPresLayoutElemTokenMap(); 2237 2238 //sal_uInt32 nTest = rTokenMap.Get(nPrefix, rLocalName); 2239 2240 switch(rTokenMap.Get(nPrefix, rLocalName)) 2241 { 2242 //Consider semantics a dummy except for any starmath annotations 2243 case XML_TOK_SEMANTICS: 2244 pContext = GetSmImport().CreateRowContext(nPrefix,rLocalName, 2245 xAttrList); 2246 break; 2247 /*General Layout Schemata*/ 2248 case XML_TOK_MROW: 2249 pContext = GetSmImport().CreateRowContext(nPrefix,rLocalName, 2250 xAttrList); 2251 break; 2252 case XML_TOK_MFRAC: 2253 pContext = GetSmImport().CreateFracContext(nPrefix,rLocalName, 2254 xAttrList); 2255 break; 2256 case XML_TOK_MSQRT: 2257 pContext = GetSmImport().CreateSqrtContext(nPrefix,rLocalName, 2258 xAttrList); 2259 break; 2260 case XML_TOK_MROOT: 2261 pContext = GetSmImport().CreateRootContext(nPrefix,rLocalName, 2262 xAttrList); 2263 break; 2264 case XML_TOK_MSTYLE: 2265 pContext = GetSmImport().CreateStyleContext(nPrefix,rLocalName, 2266 xAttrList); 2267 break; 2268 case XML_TOK_MERROR: 2269 pContext = GetSmImport().CreateErrorContext(nPrefix,rLocalName, 2270 xAttrList); 2271 break; 2272 case XML_TOK_MPADDED: 2273 pContext = GetSmImport().CreatePaddedContext(nPrefix,rLocalName, 2274 xAttrList); 2275 break; 2276 case XML_TOK_MPHANTOM: 2277 pContext = GetSmImport().CreatePhantomContext(nPrefix,rLocalName, 2278 xAttrList); 2279 break; 2280 case XML_TOK_MFENCED: 2281 pContext = GetSmImport().CreateFencedContext(nPrefix,rLocalName, 2282 xAttrList); 2283 break; 2284 /*Script and Limit Schemata*/ 2285 case XML_TOK_MSUB: 2286 pContext = GetSmImport().CreateSubContext(nPrefix,rLocalName, 2287 xAttrList); 2288 break; 2289 case XML_TOK_MSUP: 2290 pContext = GetSmImport().CreateSupContext(nPrefix,rLocalName, 2291 xAttrList); 2292 break; 2293 case XML_TOK_MSUBSUP: 2294 pContext = GetSmImport().CreateSubSupContext(nPrefix,rLocalName, 2295 xAttrList); 2296 break; 2297 case XML_TOK_MUNDER: 2298 pContext = GetSmImport().CreateUnderContext(nPrefix,rLocalName, 2299 xAttrList); 2300 break; 2301 case XML_TOK_MOVER: 2302 pContext = GetSmImport().CreateOverContext(nPrefix,rLocalName, 2303 xAttrList); 2304 break; 2305 case XML_TOK_MUNDEROVER: 2306 pContext = GetSmImport().CreateUnderOverContext(nPrefix,rLocalName, 2307 xAttrList); 2308 break; 2309 case XML_TOK_MMULTISCRIPTS: 2310 pContext = GetSmImport().CreateMultiScriptsContext(nPrefix, 2311 rLocalName, xAttrList); 2312 break; 2313 case XML_TOK_MTABLE: 2314 pContext = GetSmImport().CreateTableContext(nPrefix, 2315 rLocalName, xAttrList); 2316 break; 2317 case XML_TOK_MACTION: 2318 pContext = GetSmImport().CreateActionContext(nPrefix, 2319 rLocalName, xAttrList); 2320 break; 2321 default: 2322 /*Basically theres an implicit mrow around certain bare 2323 *elements, use a RowContext to see if this is one of 2324 *those ones*/ 2325 SmXMLRowContext_Impl aTempContext(GetSmImport(),nPrefix, 2326 GetXMLToken(XML_MROW)); 2327 2328 pContext = aTempContext.StrictCreateChildContext(nPrefix, 2329 rLocalName, xAttrList); 2330 break; 2331 } 2332 return pContext; 2333 } 2334 2335 void SmXMLDocContext_Impl::EndElement() 2336 { 2337 SmNodeArray ContextArray; 2338 ContextArray.resize(1); 2339 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 2340 2341 for (sal_uLong i=0;i< 1;i++) 2342 ContextArray[i] = rNodeStack.Pop(); 2343 2344 SmToken aDummy; 2345 SmStructureNode *pSNode = new SmLineNode(aDummy); 2346 pSNode->SetSubNodes(ContextArray); 2347 rNodeStack.Push(pSNode); 2348 2349 SmNodeArray LineArray; 2350 sal_uLong n = rNodeStack.Count(); 2351 LineArray.resize(n); 2352 for (sal_uLong j = 0; j < n; j++) 2353 LineArray[n - (j + 1)] = rNodeStack.Pop(); 2354 SmStructureNode *pSNode2 = new SmTableNode(aDummy); 2355 pSNode2->SetSubNodes(LineArray); 2356 rNodeStack.Push(pSNode2); 2357 } 2358 2359 void SmXMLFracContext_Impl::EndElement() 2360 { 2361 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 2362 const bool bNodeCheck = rNodeStack.Count() - nElementCount == 2; 2363 DBG_ASSERT( bNodeCheck, "Fraction (mfrac) tag is missing component" ); 2364 if (!bNodeCheck) 2365 return; 2366 2367 SmToken aToken; 2368 aToken.cMathChar = '\0'; 2369 aToken.nGroup = 0; 2370 aToken.nLevel = 0; 2371 aToken.eType = TOVER; 2372 SmStructureNode *pSNode = new SmBinVerNode(aToken); 2373 SmNode *pOper = new SmRectangleNode(aToken); 2374 SmNode *pSecond = rNodeStack.Pop(); 2375 SmNode *pFirst = rNodeStack.Pop(); 2376 pSNode->SetSubNodes(pFirst,pOper,pSecond); 2377 rNodeStack.Push(pSNode); 2378 } 2379 2380 void SmXMLRootContext_Impl::EndElement() 2381 { 2382 /*The <mroot> element requires exactly 2 arguments.*/ 2383 const bool bNodeCheck = GetSmImport().GetNodeStack().Count() - nElementCount == 2; 2384 DBG_ASSERT( bNodeCheck, "Root tag is missing component" ); 2385 if (!bNodeCheck) 2386 return; 2387 2388 SmToken aToken; 2389 aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font 2390 aToken.nGroup = 0; 2391 aToken.nLevel = 0; 2392 aToken.eType = TNROOT; 2393 SmStructureNode *pSNode = new SmRootNode(aToken); 2394 SmNode *pOper = new SmRootSymbolNode(aToken); 2395 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 2396 SmNode *pIndex = rNodeStack.Pop(); 2397 SmNode *pBase = rNodeStack.Pop(); 2398 pSNode->SetSubNodes(pIndex,pOper,pBase); 2399 rNodeStack.Push(pSNode); 2400 } 2401 2402 void SmXMLSqrtContext_Impl::EndElement() 2403 { 2404 /* 2405 <msqrt> accepts any number of arguments; if this number is not 1, its 2406 contents are treated as a single "inferred <mrow>" containing its 2407 arguments 2408 */ 2409 if (GetSmImport().GetNodeStack().Count() - nElementCount > 1) 2410 SmXMLRowContext_Impl::EndElement(); 2411 2412 SmToken aToken; 2413 aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font 2414 aToken.nGroup = 0; 2415 aToken.nLevel = 0; 2416 aToken.eType = TSQRT; 2417 SmStructureNode *pSNode = new SmRootNode(aToken); 2418 SmNode *pOper = new SmRootSymbolNode(aToken); 2419 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 2420 pSNode->SetSubNodes(0,pOper,rNodeStack.Pop()); 2421 rNodeStack.Push(pSNode); 2422 } 2423 2424 void SmXMLRowContext_Impl::EndElement() 2425 { 2426 SmNodeArray aRelationArray; 2427 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 2428 sal_uLong nSize = rNodeStack.Count()-nElementCount; 2429 2430 if (nSize > 0) 2431 { 2432 aRelationArray.resize(nSize); 2433 for (sal_uLong j=rNodeStack.Count()-nElementCount;j > 0;j--) 2434 aRelationArray[j-1] = rNodeStack.Pop(); 2435 2436 2437 //If the first or last element is an operator with stretchyness 2438 //set then we must create a brace node here from those elements, 2439 //removing the stretchness from the operators and applying it to 2440 //ourselves, and creating the appropriate dummy StarMath none bracket 2441 //to balance the arrangement 2442 if (((aRelationArray[0]->GetScaleMode() == SCALE_HEIGHT) 2443 && (aRelationArray[0]->GetType() == NMATH)) 2444 || ((aRelationArray[nSize-1]->GetScaleMode() == SCALE_HEIGHT) 2445 && (aRelationArray[nSize-1]->GetType() == NMATH))) 2446 { 2447 SmToken aToken; 2448 aToken.cMathChar = '\0'; 2449 aToken.nGroup = 0; 2450 aToken.nLevel = 5; 2451 2452 int nLeft=0,nRight=0; 2453 if ((aRelationArray[0]->GetScaleMode() == SCALE_HEIGHT) 2454 && (aRelationArray[0]->GetType() == NMATH)) 2455 { 2456 aToken = aRelationArray[0]->GetToken(); 2457 nLeft=1; 2458 } 2459 else 2460 aToken.cMathChar = '\0'; 2461 2462 aToken.eType = TLPARENT; 2463 SmNode *pLeft = new SmMathSymbolNode(aToken); 2464 2465 if ((aRelationArray[nSize-1]->GetScaleMode() == SCALE_HEIGHT) 2466 && (aRelationArray[nSize-1]->GetType() == NMATH)) 2467 { 2468 aToken = aRelationArray[nSize-1]->GetToken(); 2469 nRight=1; 2470 } 2471 else 2472 aToken.cMathChar = '\0'; 2473 2474 aToken.eType = TRPARENT; 2475 SmNode *pRight = new SmMathSymbolNode(aToken); 2476 2477 SmNodeArray aRelationArray2; 2478 2479 //!! nSize-nLeft-nRight may be < 0 !! 2480 int nRelArrSize = nSize-nLeft-nRight; 2481 if (nRelArrSize > 0) 2482 { 2483 aRelationArray2.resize(nRelArrSize); 2484 for (int i=0;i < nRelArrSize;i++) 2485 aRelationArray2[i] = aRelationArray[i+nLeft]; 2486 } 2487 2488 SmToken aDummy; 2489 SmStructureNode *pSNode = new SmBraceNode(aToken); 2490 SmStructureNode *pBody = new SmExpressionNode(aDummy); 2491 pBody->SetSubNodes(aRelationArray2); 2492 2493 pSNode->SetSubNodes(pLeft,pBody,pRight); 2494 pSNode->SetScaleMode(SCALE_HEIGHT); 2495 rNodeStack.Push(pSNode); 2496 return; 2497 } 2498 } 2499 else //Multiple newlines result in empty row elements 2500 { 2501 aRelationArray.resize(1); 2502 SmToken aToken; 2503 aToken.cMathChar = '\0'; 2504 aToken.nGroup = 0; 2505 aToken.nLevel = 5; 2506 aToken.eType = TNEWLINE; 2507 aRelationArray[0] = new SmLineNode(aToken); 2508 } 2509 2510 SmToken aDummy; 2511 SmStructureNode *pSNode = new SmExpressionNode(aDummy); 2512 pSNode->SetSubNodes(aRelationArray); 2513 rNodeStack.Push(pSNode); 2514 } 2515 2516 2517 SvXMLImportContext *SmXMLRowContext_Impl::StrictCreateChildContext( 2518 sal_uInt16 nPrefix, 2519 const OUString& rLocalName, 2520 const uno::Reference<xml::sax::XAttributeList>& xAttrList) 2521 { 2522 SvXMLImportContext* pContext = 0L; 2523 2524 const SvXMLTokenMap& rTokenMap = GetSmImport().GetPresElemTokenMap(); 2525 switch(rTokenMap.Get(nPrefix, rLocalName)) 2526 { 2527 /*Note that these should accept malignmark subelements, but do not*/ 2528 case XML_TOK_MN: 2529 pContext = GetSmImport().CreateNumberContext(nPrefix,rLocalName, 2530 xAttrList); 2531 break; 2532 case XML_TOK_MI: 2533 pContext = GetSmImport().CreateIdentifierContext(nPrefix,rLocalName, 2534 xAttrList); 2535 break; 2536 case XML_TOK_MO: 2537 pContext = GetSmImport().CreateOperatorContext(nPrefix,rLocalName, 2538 xAttrList); 2539 break; 2540 case XML_TOK_MTEXT: 2541 pContext = GetSmImport().CreateTextContext(nPrefix,rLocalName, 2542 xAttrList); 2543 break; 2544 case XML_TOK_MSPACE: 2545 pContext = GetSmImport().CreateSpaceContext(nPrefix,rLocalName, 2546 xAttrList); 2547 break; 2548 case XML_TOK_MS: 2549 pContext = GetSmImport().CreateStringContext(nPrefix,rLocalName, 2550 xAttrList); 2551 break; 2552 2553 /*Note: The maligngroup should only be seen when the row 2554 * (or descendants) are in a table*/ 2555 case XML_TOK_MALIGNGROUP: 2556 pContext = GetSmImport().CreateAlignGroupContext(nPrefix,rLocalName, 2557 xAttrList); 2558 break; 2559 2560 case XML_TOK_ANNOTATION: 2561 pContext = GetSmImport().CreateAnnotationContext(nPrefix,rLocalName, 2562 xAttrList); 2563 break; 2564 2565 default: 2566 break; 2567 } 2568 return pContext; 2569 } 2570 2571 2572 SvXMLImportContext *SmXMLRowContext_Impl::CreateChildContext( 2573 sal_uInt16 nPrefix, 2574 const OUString& rLocalName, 2575 const uno::Reference<xml::sax::XAttributeList>& xAttrList) 2576 { 2577 SvXMLImportContext* pContext = StrictCreateChildContext(nPrefix, 2578 rLocalName, xAttrList); 2579 2580 if (!pContext) 2581 { 2582 //Hmm, unrecognized for this level, check to see if its 2583 //an element that can have an implicit schema around it 2584 pContext = SmXMLDocContext_Impl::CreateChildContext(nPrefix, 2585 rLocalName,xAttrList); 2586 } 2587 return pContext; 2588 } 2589 2590 2591 SvXMLImportContext *SmXMLMultiScriptsContext_Impl::CreateChildContext( 2592 sal_uInt16 nPrefix, 2593 const OUString& rLocalName, 2594 const uno::Reference<xml::sax::XAttributeList>& xAttrList) 2595 { 2596 SvXMLImportContext* pContext = 0L; 2597 2598 const SvXMLTokenMap& rTokenMap = GetSmImport(). 2599 GetPresScriptEmptyElemTokenMap(); 2600 switch(rTokenMap.Get(nPrefix, rLocalName)) 2601 { 2602 case XML_TOK_MPRESCRIPTS: 2603 MiddleElement(); 2604 pContext = GetSmImport().CreatePrescriptsContext(nPrefix, 2605 rLocalName, xAttrList); 2606 break; 2607 case XML_TOK_NONE: 2608 pContext = GetSmImport().CreateNoneContext(nPrefix,rLocalName, 2609 xAttrList); 2610 break; 2611 default: 2612 pContext = SmXMLRowContext_Impl::CreateChildContext(nPrefix, 2613 rLocalName,xAttrList); 2614 break; 2615 } 2616 return pContext; 2617 } 2618 2619 void SmXMLMultiScriptsContext_Impl::MiddleElement() 2620 { 2621 bHasPrescripts=sal_True; 2622 2623 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 2624 DBG_ASSERT( rNodeStack.Count() - nElementCount > 0, "Sub has no arguments" ); 2625 if (rNodeStack.Count()-nElementCount > 1) 2626 { 2627 SmToken aToken; 2628 aToken.cMathChar = '\0'; 2629 aToken.nGroup = 0; 2630 aToken.nLevel = 0; 2631 aToken.eType = TRSUB; 2632 sal_uLong nFinalCount = rNodeStack.Count()-nElementCount-1; 2633 2634 SmNodeStack aReverseStack; 2635 while (rNodeStack.Count()-nElementCount) 2636 { 2637 SmNode *pThing = rNodeStack.Pop(); 2638 aReverseStack.Push(pThing); 2639 } 2640 2641 for (sal_uLong nCount=0;nCount < nFinalCount;nCount+=2) 2642 { 2643 SmSubSupNode *pNode = new SmSubSupNode(aToken); 2644 2645 // initialize subnodes array 2646 SmNodeArray aSubNodes; 2647 aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES); 2648 for (sal_uLong i = 1; i < aSubNodes.size(); i++) 2649 aSubNodes[i] = NULL; 2650 2651 /*On each loop the base and its sub sup pair becomes the 2652 base for the next loop to which the next sub sup pair is 2653 attached, i.e. wheels within wheels*/ 2654 //if (nCount == 0) 2655 aSubNodes[0] = aReverseStack.Pop(); 2656 2657 SmNode *pScriptNode = aReverseStack.Pop(); 2658 2659 if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) || 2660 (pScriptNode->GetToken().aText.Len()))) 2661 aSubNodes[RSUB+1] = pScriptNode; 2662 pScriptNode = aReverseStack.Pop(); 2663 if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) || 2664 (pScriptNode->GetToken().aText.Len()))) 2665 aSubNodes[RSUP+1] = pScriptNode; 2666 2667 pNode->SetSubNodes(aSubNodes); 2668 aReverseStack.Push(pNode); 2669 } 2670 rNodeStack.Push(aReverseStack.Pop()); 2671 } 2672 } 2673 2674 2675 void SmXMLTableContext_Impl::EndElement() 2676 { 2677 SmNodeArray aExpressionArray; 2678 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 2679 SmNodeStack aReverseStack; 2680 aExpressionArray.resize(rNodeStack.Count()-nElementCount); 2681 2682 sal_uLong nRows = rNodeStack.Count()-nElementCount; 2683 sal_uInt16 nCols = 0; 2684 2685 SmStructureNode *pArray; 2686 for (sal_uLong i=rNodeStack.Count()-nElementCount;i > 0;i--) 2687 { 2688 pArray = (SmStructureNode *)rNodeStack.Pop(); 2689 if (pArray->GetNumSubNodes() == 0) 2690 { 2691 //This is a little tricky, it is possible that there was 2692 //be elements that were not inside a <mtd> pair, in which 2693 //case they will not be in a row, i.e. they will not have 2694 //SubNodes, so we have to wait until here before we can 2695 //resolve the situation. Implicitsurrounding tags are 2696 //surprisingly difficult to get right within this 2697 //architecture 2698 2699 SmNodeArray aRelationArray; 2700 aRelationArray.resize(1); 2701 aRelationArray[0] = pArray; 2702 SmToken aDummy; 2703 pArray = new SmExpressionNode(aDummy); 2704 pArray->SetSubNodes(aRelationArray); 2705 } 2706 2707 if (pArray->GetNumSubNodes() > nCols) 2708 nCols = pArray->GetNumSubNodes(); 2709 aReverseStack.Push(pArray); 2710 } 2711 aExpressionArray.resize(nCols*nRows); 2712 sal_uLong j=0; 2713 while (aReverseStack.Count()) 2714 { 2715 pArray = (SmStructureNode *)aReverseStack.Pop(); 2716 for (sal_uInt16 i=0;i<pArray->GetNumSubNodes();i++) 2717 aExpressionArray[j++] = pArray->GetSubNode(i); 2718 } 2719 2720 SmToken aToken; 2721 aToken.cMathChar = '\0'; 2722 aToken.nGroup = TRGROUP; 2723 aToken.nLevel = 0; 2724 aToken.eType = TMATRIX; 2725 SmMatrixNode *pSNode = new SmMatrixNode(aToken); 2726 pSNode->SetSubNodes(aExpressionArray); 2727 pSNode->SetRowCol(static_cast<sal_uInt16>(nRows),nCols); 2728 rNodeStack.Push(pSNode); 2729 } 2730 2731 SvXMLImportContext *SmXMLTableRowContext_Impl::CreateChildContext( 2732 sal_uInt16 nPrefix, 2733 const OUString& rLocalName, 2734 const uno::Reference<xml::sax::XAttributeList>& xAttrList) 2735 { 2736 SvXMLImportContext* pContext = 0L; 2737 2738 const SvXMLTokenMap& rTokenMap = GetSmImport(). 2739 GetPresTableElemTokenMap(); 2740 switch(rTokenMap.Get(nPrefix, rLocalName)) 2741 { 2742 case XML_TOK_MTD: 2743 pContext = GetSmImport().CreateTableCellContext(nPrefix, 2744 rLocalName, xAttrList); 2745 break; 2746 default: 2747 pContext = SmXMLRowContext_Impl::CreateChildContext(nPrefix, 2748 rLocalName,xAttrList); 2749 break; 2750 } 2751 return pContext; 2752 } 2753 2754 SvXMLImportContext *SmXMLTableContext_Impl::CreateChildContext( 2755 sal_uInt16 nPrefix, 2756 const OUString& rLocalName, 2757 const uno::Reference<xml::sax::XAttributeList>& xAttrList) 2758 { 2759 SvXMLImportContext* pContext = 0L; 2760 2761 const SvXMLTokenMap& rTokenMap = GetSmImport(). 2762 GetPresTableElemTokenMap(); 2763 switch(rTokenMap.Get(nPrefix, rLocalName)) 2764 { 2765 case XML_TOK_MTR: 2766 pContext = GetSmImport().CreateTableRowContext(nPrefix,rLocalName, 2767 xAttrList); 2768 break; 2769 default: 2770 pContext = SmXMLTableRowContext_Impl::CreateChildContext(nPrefix, 2771 rLocalName,xAttrList); 2772 break; 2773 } 2774 return pContext; 2775 } 2776 2777 void SmXMLMultiScriptsContext_Impl::EndElement() 2778 { 2779 if (!bHasPrescripts) 2780 MiddleElement(); 2781 2782 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 2783 if (rNodeStack.Count()-nElementCount > 1) 2784 { 2785 SmToken aToken; 2786 aToken.cMathChar = '\0'; 2787 aToken.nGroup = 0; 2788 aToken.nLevel = 0; 2789 aToken.eType = TLSUB; 2790 sal_uLong nFinalCount = rNodeStack.Count()-nElementCount-1; 2791 2792 SmNodeStack aReverseStack; 2793 while (rNodeStack.Count()-nElementCount) 2794 aReverseStack.Push(rNodeStack.Pop()); 2795 for (sal_uLong nCount=0;nCount < nFinalCount;nCount+=2) 2796 { 2797 SmSubSupNode *pNode = new SmSubSupNode(aToken); 2798 2799 // initialize subnodes array 2800 SmNodeArray aSubNodes; 2801 aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES); 2802 for (sal_uLong i = 1; i < aSubNodes.size(); i++) 2803 aSubNodes[i] = NULL; 2804 2805 /*On each loop the base and its sub sup pair becomes the 2806 base for the next loop to which the next sub sup pair is 2807 attached, i.e. wheels within wheels*/ 2808 //if (nCount == 0) 2809 aSubNodes[0] = aReverseStack.Pop(); 2810 2811 SmNode *pScriptNode = aReverseStack.Pop(); 2812 if (pScriptNode->GetToken().aText.Len()) 2813 aSubNodes[LSUB+1] = pScriptNode; 2814 pScriptNode = aReverseStack.Pop(); 2815 if (pScriptNode->GetToken().aText.Len()) 2816 aSubNodes[LSUP+1] = pScriptNode; 2817 2818 pNode->SetSubNodes(aSubNodes); 2819 aReverseStack.Push(pNode); 2820 } 2821 rNodeStack.Push(aReverseStack.Pop()); 2822 } 2823 2824 } 2825 void SmXMLActionContext_Impl::EndElement() 2826 { 2827 /*For now we will just assume that the 2828 selected attribute is one, and then just display 2829 that expression alone, i.e. remove all expect the 2830 first pushed one*/ 2831 2832 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack(); 2833 for (sal_uLong i=rNodeStack.Count()-nElementCount;i > 1;i--) 2834 { 2835 delete rNodeStack.Pop(); 2836 } 2837 } 2838 2839 SvXMLImportContext *SmXMLImport::CreateContext(sal_uInt16 nPrefix, 2840 const OUString &rLocalName, 2841 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2842 { 2843 if ( XML_NAMESPACE_OFFICE == nPrefix ) 2844 { 2845 if ( (IsXMLToken(rLocalName, XML_DOCUMENT) || 2846 IsXMLToken(rLocalName, XML_DOCUMENT_META))) 2847 { 2848 uno::Reference<xml::sax::XDocumentHandler> xDocBuilder( 2849 mxServiceFactory->createInstance( 2850 ::rtl::OUString::createFromAscii( 2851 "com.sun.star.xml.dom.SAXDocumentBuilder")), 2852 uno::UNO_QUERY_THROW); 2853 uno::Reference<document::XDocumentPropertiesSupplier> xDPS( 2854 GetModel(), uno::UNO_QUERY_THROW); 2855 return IsXMLToken(rLocalName, XML_DOCUMENT_META) 2856 ? new SvXMLMetaDocumentContext(*this, 2857 XML_NAMESPACE_OFFICE, rLocalName, 2858 xDPS->getDocumentProperties(), xDocBuilder) 2859 // flat OpenDocument file format -- this has not been tested... 2860 : new SmXMLFlatDocContext_Impl( *this, nPrefix, rLocalName, 2861 xDPS->getDocumentProperties(), xDocBuilder); 2862 } 2863 else 2864 { 2865 return new SmXMLOfficeContext_Impl( *this,nPrefix,rLocalName); 2866 } 2867 } 2868 else 2869 return new SmXMLDocContext_Impl(*this,nPrefix,rLocalName); 2870 } 2871 2872 SvXMLImportContext *SmXMLImport::CreateRowContext(sal_uInt16 nPrefix, 2873 const OUString &rLocalName, 2874 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2875 { 2876 return new SmXMLRowContext_Impl(*this,nPrefix,rLocalName); 2877 } 2878 2879 SvXMLImportContext *SmXMLImport::CreateTextContext(sal_uInt16 nPrefix, 2880 const OUString &rLocalName, 2881 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2882 { 2883 return new SmXMLTextContext_Impl(*this,nPrefix,rLocalName); 2884 } 2885 2886 SvXMLImportContext *SmXMLImport::CreateAnnotationContext(sal_uInt16 nPrefix, 2887 const OUString &rLocalName, 2888 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2889 { 2890 return new SmXMLAnnotationContext_Impl(*this,nPrefix,rLocalName); 2891 } 2892 2893 SvXMLImportContext *SmXMLImport::CreateStringContext(sal_uInt16 nPrefix, 2894 const OUString &rLocalName, 2895 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2896 { 2897 return new SmXMLStringContext_Impl(*this,nPrefix,rLocalName); 2898 } 2899 2900 SvXMLImportContext *SmXMLImport::CreateNumberContext(sal_uInt16 nPrefix, 2901 const OUString &rLocalName, 2902 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2903 { 2904 return new SmXMLNumberContext_Impl(*this,nPrefix,rLocalName); 2905 } 2906 2907 SvXMLImportContext *SmXMLImport::CreateIdentifierContext(sal_uInt16 nPrefix, 2908 const OUString &rLocalName, 2909 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2910 { 2911 return new SmXMLIdentifierContext_Impl(*this,nPrefix,rLocalName); 2912 } 2913 2914 SvXMLImportContext *SmXMLImport::CreateOperatorContext(sal_uInt16 nPrefix, 2915 const OUString &rLocalName, 2916 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2917 { 2918 return new SmXMLOperatorContext_Impl(*this,nPrefix,rLocalName); 2919 } 2920 2921 SvXMLImportContext *SmXMLImport::CreateSpaceContext(sal_uInt16 nPrefix, 2922 const OUString &rLocalName, 2923 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2924 { 2925 return new SmXMLSpaceContext_Impl(*this,nPrefix,rLocalName); 2926 } 2927 2928 2929 SvXMLImportContext *SmXMLImport::CreateFracContext(sal_uInt16 nPrefix, 2930 const OUString &rLocalName, 2931 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2932 { 2933 return new SmXMLFracContext_Impl(*this,nPrefix,rLocalName); 2934 } 2935 2936 SvXMLImportContext *SmXMLImport::CreateSqrtContext(sal_uInt16 nPrefix, 2937 const OUString &rLocalName, 2938 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2939 { 2940 return new SmXMLSqrtContext_Impl(*this,nPrefix,rLocalName); 2941 } 2942 2943 SvXMLImportContext *SmXMLImport::CreateRootContext(sal_uInt16 nPrefix, 2944 const OUString &rLocalName, 2945 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2946 { 2947 return new SmXMLRootContext_Impl(*this,nPrefix,rLocalName); 2948 } 2949 2950 SvXMLImportContext *SmXMLImport::CreateStyleContext(sal_uInt16 nPrefix, 2951 const OUString &rLocalName, 2952 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2953 { 2954 return new SmXMLStyleContext_Impl(*this,nPrefix,rLocalName); 2955 } 2956 2957 SvXMLImportContext *SmXMLImport::CreatePaddedContext(sal_uInt16 nPrefix, 2958 const OUString &rLocalName, 2959 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2960 { 2961 return new SmXMLPaddedContext_Impl(*this,nPrefix,rLocalName); 2962 } 2963 2964 SvXMLImportContext *SmXMLImport::CreatePhantomContext(sal_uInt16 nPrefix, 2965 const OUString &rLocalName, 2966 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2967 { 2968 return new SmXMLPhantomContext_Impl(*this,nPrefix,rLocalName); 2969 } 2970 2971 SvXMLImportContext *SmXMLImport::CreateFencedContext(sal_uInt16 nPrefix, 2972 const OUString &rLocalName, 2973 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2974 { 2975 return new SmXMLFencedContext_Impl(*this,nPrefix,rLocalName); 2976 } 2977 2978 SvXMLImportContext *SmXMLImport::CreateErrorContext(sal_uInt16 nPrefix, 2979 const OUString &rLocalName, 2980 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2981 { 2982 return new SmXMLErrorContext_Impl(*this,nPrefix,rLocalName); 2983 } 2984 2985 SvXMLImportContext *SmXMLImport::CreateSubContext(sal_uInt16 nPrefix, 2986 const OUString &rLocalName, 2987 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2988 { 2989 return new SmXMLSubContext_Impl(*this,nPrefix,rLocalName); 2990 } 2991 2992 SvXMLImportContext *SmXMLImport::CreateSubSupContext(sal_uInt16 nPrefix, 2993 const OUString &rLocalName, 2994 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 2995 { 2996 return new SmXMLSubSupContext_Impl(*this,nPrefix,rLocalName); 2997 } 2998 2999 SvXMLImportContext *SmXMLImport::CreateSupContext(sal_uInt16 nPrefix, 3000 const OUString &rLocalName, 3001 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 3002 { 3003 return new SmXMLSupContext_Impl(*this,nPrefix,rLocalName); 3004 } 3005 3006 SvXMLImportContext *SmXMLImport::CreateUnderContext(sal_uInt16 nPrefix, 3007 const OUString &rLocalName, 3008 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 3009 { 3010 return new SmXMLUnderContext_Impl(*this,nPrefix,rLocalName); 3011 } 3012 3013 SvXMLImportContext *SmXMLImport::CreateOverContext(sal_uInt16 nPrefix, 3014 const OUString &rLocalName, 3015 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 3016 { 3017 return new SmXMLOverContext_Impl(*this,nPrefix,rLocalName); 3018 } 3019 3020 SvXMLImportContext *SmXMLImport::CreateUnderOverContext(sal_uInt16 nPrefix, 3021 const OUString &rLocalName, 3022 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 3023 { 3024 return new SmXMLUnderOverContext_Impl(*this,nPrefix,rLocalName); 3025 } 3026 3027 SvXMLImportContext *SmXMLImport::CreateMultiScriptsContext(sal_uInt16 nPrefix, 3028 const OUString &rLocalName, 3029 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 3030 { 3031 return new SmXMLMultiScriptsContext_Impl(*this,nPrefix,rLocalName); 3032 } 3033 3034 SvXMLImportContext *SmXMLImport::CreateTableContext(sal_uInt16 nPrefix, 3035 const OUString &rLocalName, 3036 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 3037 { 3038 return new SmXMLTableContext_Impl(*this,nPrefix,rLocalName); 3039 } 3040 SvXMLImportContext *SmXMLImport::CreateTableRowContext(sal_uInt16 nPrefix, 3041 const OUString &rLocalName, 3042 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 3043 { 3044 return new SmXMLTableRowContext_Impl(*this,nPrefix,rLocalName); 3045 } 3046 SvXMLImportContext *SmXMLImport::CreateTableCellContext(sal_uInt16 nPrefix, 3047 const OUString &rLocalName, 3048 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 3049 { 3050 return new SmXMLTableCellContext_Impl(*this,nPrefix,rLocalName); 3051 } 3052 3053 SvXMLImportContext *SmXMLImport::CreateNoneContext(sal_uInt16 nPrefix, 3054 const OUString &rLocalName, 3055 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 3056 { 3057 return new SmXMLNoneContext_Impl(*this,nPrefix,rLocalName); 3058 } 3059 3060 SvXMLImportContext *SmXMLImport::CreatePrescriptsContext(sal_uInt16 nPrefix, 3061 const OUString &rLocalName, 3062 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 3063 { 3064 return new SmXMLPrescriptsContext_Impl(*this,nPrefix,rLocalName); 3065 } 3066 3067 SvXMLImportContext *SmXMLImport::CreateAlignGroupContext(sal_uInt16 nPrefix, 3068 const OUString &rLocalName, 3069 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 3070 { 3071 return new SmXMLAlignGroupContext_Impl(*this,nPrefix,rLocalName); 3072 } 3073 3074 SvXMLImportContext *SmXMLImport::CreateActionContext(sal_uInt16 nPrefix, 3075 const OUString &rLocalName, 3076 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/) 3077 { 3078 return new SmXMLActionContext_Impl(*this,nPrefix,rLocalName); 3079 } 3080 3081 SmXMLImport::~SmXMLImport() throw () 3082 { 3083 delete pPresLayoutElemTokenMap; 3084 delete pPresElemTokenMap; 3085 delete pPresScriptEmptyElemTokenMap; 3086 delete pPresTableElemTokenMap; 3087 delete pPresLayoutAttrTokenMap; 3088 delete pFencedAttrTokenMap; 3089 delete pColorTokenMap; 3090 delete pOperatorAttrTokenMap; 3091 delete pAnnotationAttrTokenMap; 3092 } 3093 3094 void SmXMLImport::SetViewSettings(const Sequence<PropertyValue>& aViewProps) 3095 { 3096 uno::Reference <frame::XModel> xModel = GetModel(); 3097 if ( !xModel.is() ) 3098 return; 3099 3100 uno::Reference <lang::XUnoTunnel> xTunnel; 3101 xTunnel = uno::Reference <lang::XUnoTunnel> (xModel,uno::UNO_QUERY); 3102 SmModel *pModel = reinterpret_cast<SmModel *> 3103 (xTunnel->getSomething(SmModel::getUnoTunnelId())); 3104 3105 if ( !pModel ) 3106 return; 3107 3108 SmDocShell *pDocShell = 3109 static_cast<SmDocShell*>(pModel->GetObjectShell()); 3110 if ( !pDocShell ) 3111 return; 3112 3113 Rectangle aRect( pDocShell->GetVisArea() ); 3114 3115 sal_Int32 nCount = aViewProps.getLength(); 3116 const PropertyValue *pValue = aViewProps.getConstArray(); 3117 3118 long nTmp = 0; 3119 //sal_Bool bShowDeletes = sal_False, bShowInserts = sal_False, bShowFooter = sal_False, bShowHeader = sal_False; 3120 3121 for (sal_Int32 i = 0; i < nCount ; i++) 3122 { 3123 if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaTop" ) ) ) 3124 { 3125 pValue->Value >>= nTmp; 3126 aRect.setY( nTmp ); 3127 } 3128 else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaLeft" ) ) ) 3129 { 3130 pValue->Value >>= nTmp; 3131 aRect.setX( nTmp ); 3132 } 3133 else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaWidth" ) ) ) 3134 { 3135 pValue->Value >>= nTmp; 3136 Size aSize( aRect.GetSize() ); 3137 aSize.Width() = nTmp; 3138 aRect.SetSize( aSize ); 3139 } 3140 else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaHeight" ) ) ) 3141 { 3142 pValue->Value >>= nTmp; 3143 Size aSize( aRect.GetSize() ); 3144 aSize.Height() = nTmp; 3145 aRect.SetSize( aSize ); 3146 } 3147 pValue++; 3148 } 3149 3150 pDocShell->SetVisArea ( aRect ); 3151 } 3152 3153 void SmXMLImport::SetConfigurationSettings(const Sequence<PropertyValue>& aConfProps) 3154 { 3155 uno::Reference < XPropertySet > xProps ( GetModel(), UNO_QUERY ); 3156 if ( xProps.is() ) 3157 { 3158 Reference < XPropertySetInfo > xInfo ( xProps->getPropertySetInfo() ); 3159 if (xInfo.is() ) 3160 { 3161 sal_Int32 nCount = aConfProps.getLength(); 3162 const PropertyValue* pValues = aConfProps.getConstArray(); 3163 3164 const OUString sFormula ( RTL_CONSTASCII_USTRINGPARAM ( "Formula" ) ); 3165 const OUString sBasicLibraries ( RTL_CONSTASCII_USTRINGPARAM ( "BasicLibraries" ) ); 3166 const OUString sDialogLibraries ( RTL_CONSTASCII_USTRINGPARAM ( "DialogLibraries" ) ); 3167 while ( nCount-- ) 3168 { 3169 if (pValues->Name != sFormula && 3170 pValues->Name != sBasicLibraries && 3171 pValues->Name != sDialogLibraries) 3172 { 3173 try 3174 { 3175 if ( xInfo->hasPropertyByName( pValues->Name ) ) 3176 xProps->setPropertyValue( pValues->Name, pValues->Value ); 3177 } 3178 catch (beans::PropertyVetoException &e) 3179 { 3180 (void) e; 3181 // dealing with read-only properties here. Nothing to do... 3182 } 3183 catch( Exception& e) 3184 { 3185 (void) e; 3186 DBG_ERROR( "SmXMLImport::SetConfigurationSettings: Exception!" ); 3187 } 3188 } 3189 3190 pValues++; 3191 } 3192 } 3193 } 3194 } 3195 3196 3197 //////////////////////////////////////////////////////////// 3198 3199 3200