bump product version to 4.1.6.2
[LibreOffice.git] / starmath / source / mathmlimport.cxx
blob50c06aa67257bae150acae39c60edc47f62d460f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 /*todo: Change characters and tcharacters to accumulate the characters together
22 into one string, xml parser hands them to us line by line rather than all in
23 one go*/
25 #include <com/sun/star/xml/sax/XErrorHandler.hpp>
26 #include <com/sun/star/xml/sax/XEntityResolver.hpp>
27 #include <com/sun/star/xml/sax/InputSource.hpp>
28 #include <com/sun/star/xml/sax/XDTDHandler.hpp>
29 #include <com/sun/star/xml/sax/Parser.hpp>
30 #include <com/sun/star/io/XActiveDataSource.hpp>
31 #include <com/sun/star/io/XActiveDataControl.hpp>
32 #include <com/sun/star/document/XDocumentProperties.hpp>
33 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
34 #include <com/sun/star/packages/zip/ZipIOException.hpp>
35 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
37 #include <com/sun/star/container/XNameAccess.hpp>
38 #include <com/sun/star/embed/ElementModes.hpp>
39 #include <com/sun/star/uno/Any.h>
41 #include <comphelper/componentcontext.hxx>
42 #include <comphelper/genericpropertyset.hxx>
43 #include <comphelper/processfactory.hxx>
44 #include <comphelper/servicehelper.hxx>
45 #include <comphelper/string.hxx>
46 #include <rtl/math.hxx>
47 #include <sfx2/frame.hxx>
48 #include <sfx2/docfile.hxx>
49 #include <osl/diagnose.h>
50 #include <svtools/sfxecode.hxx>
51 #include <unotools/saveopt.hxx>
52 #include <svl/stritem.hxx>
53 #include <svl/itemprop.hxx>
54 #include <unotools/streamwrap.hxx>
55 #include <sax/tools/converter.hxx>
56 #include <xmloff/xmlnmspe.hxx>
57 #include <xmloff/xmltoken.hxx>
58 #include <xmloff/nmspmap.hxx>
59 #include <xmloff/attrlist.hxx>
60 #include <xmloff/xmluconv.hxx>
61 #include <xmloff/xmlmetai.hxx>
62 #include <osl/mutex.hxx>
64 #include <memory>
66 #include "mathmlimport.hxx"
67 #include <starmath.hrc>
68 #include <unomodel.hxx>
69 #include <document.hxx>
70 #include <utility.hxx>
72 using namespace ::com::sun::star::beans;
73 using namespace ::com::sun::star::container;
74 using namespace ::com::sun::star::document;
75 using namespace ::com::sun::star::lang;
76 using namespace ::com::sun::star::uno;
77 using namespace ::com::sun::star;
78 using namespace ::xmloff::token;
81 #define IMPORT_SVC_NAME "com.sun.star.xml.XMLImportFilter"
83 #undef WANTEXCEPT
85 ////////////////////////////////////////////////////////////
87 namespace {
88 template < typename T >
89 T* lcl_popOrZero( ::std::stack<T*> & rStack )
91 if (rStack.empty())
92 return 0;
93 T* pTmp = rStack.top();
94 rStack.pop();
95 return pTmp;
99 sal_uLong SmXMLImportWrapper::Import(SfxMedium &rMedium)
101 sal_uLong nError = ERRCODE_SFX_DOLOADFAILED;
103 uno::Reference<uno::XComponentContext> xContext( comphelper::getProcessComponentContext() );
105 //Make a model component from our SmModel
106 uno::Reference< lang::XComponent > xModelComp( xModel, uno::UNO_QUERY );
107 OSL_ENSURE( xModelComp.is(), "XMLReader::Read: got no model" );
109 // try to get an XStatusIndicator from the Medium
110 uno::Reference<task::XStatusIndicator> xStatusIndicator;
112 sal_Bool bEmbedded = sal_False;
113 uno::Reference <lang::XUnoTunnel> xTunnel;
114 xTunnel = uno::Reference <lang::XUnoTunnel> (xModel,uno::UNO_QUERY);
115 SmModel *pModel = reinterpret_cast<SmModel *>
116 (xTunnel->getSomething(SmModel::getUnoTunnelId()));
118 SmDocShell *pDocShell = pModel ?
119 static_cast<SmDocShell*>(pModel->GetObjectShell()) : 0;
120 if (pDocShell)
122 OSL_ENSURE( pDocShell->GetMedium() == &rMedium,
123 "different SfxMedium found" );
125 SfxItemSet* pSet = rMedium.GetItemSet();
126 if (pSet)
128 const SfxUnoAnyItem* pItem = static_cast<const SfxUnoAnyItem*>(
129 pSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL) );
130 if (pItem)
131 pItem->GetValue() >>= xStatusIndicator;
134 if ( SFX_CREATE_MODE_EMBEDDED == pDocShell->GetCreateMode() )
135 bEmbedded = sal_True;
138 comphelper::PropertyMapEntry aInfoMap[] =
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 }
154 uno::Reference< beans::XPropertySet > xInfoSet(
155 comphelper::GenericPropertySet_CreateInstance(
156 new comphelper::PropertySetInfo( aInfoMap ) ) );
158 // Set base URI
159 OUString sPropName( "BaseURI" );
160 xInfoSet->setPropertyValue( sPropName, makeAny( rMedium.GetBaseURL() ) );
162 sal_Int32 nSteps=3;
163 if ( !(rMedium.IsStorage()))
164 nSteps = 1;
166 sal_Int32 nProgressRange(nSteps);
167 if (xStatusIndicator.is())
169 xStatusIndicator->start(SM_RESSTR(STR_STATSTR_READING), nProgressRange);
172 nSteps=0;
173 if (xStatusIndicator.is())
174 xStatusIndicator->setValue(nSteps++);
176 if ( rMedium.IsStorage())
178 // TODO/LATER: handle the case of embedded links gracefully
179 if ( bEmbedded ) // && !rMedium.GetStorage()->IsRoot() )
181 OUString aName( "dummyObjName" );
182 if ( rMedium.GetItemSet() )
184 const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
185 rMedium.GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
186 if ( pDocHierarchItem )
187 aName = pDocHierarchItem->GetValue();
190 if ( !aName.isEmpty() )
192 sPropName = "StreamRelPath";
193 xInfoSet->setPropertyValue( sPropName, makeAny( aName ) );
197 sal_Bool bOASIS = ( SotStorage::GetVersion( rMedium.GetStorage() ) > SOFFICE_FILEFORMAT_60 );
198 if (xStatusIndicator.is())
199 xStatusIndicator->setValue(nSteps++);
201 sal_uLong nWarn = ReadThroughComponent(
202 rMedium.GetStorage(), xModelComp, "meta.xml", "Meta.xml",
203 xContext, xInfoSet,
204 (bOASIS ? "com.sun.star.comp.Math.XMLOasisMetaImporter"
205 : "com.sun.star.comp.Math.XMLMetaImporter") );
207 if ( nWarn != ERRCODE_IO_BROKENPACKAGE )
209 if (xStatusIndicator.is())
210 xStatusIndicator->setValue(nSteps++);
212 nWarn = ReadThroughComponent(
213 rMedium.GetStorage(), xModelComp, "settings.xml", 0,
214 xContext, xInfoSet,
215 (bOASIS ? "com.sun.star.comp.Math.XMLOasisSettingsImporter"
216 : "com.sun.star.comp.Math.XMLSettingsImporter" ) );
218 if ( nWarn != ERRCODE_IO_BROKENPACKAGE )
220 if (xStatusIndicator.is())
221 xStatusIndicator->setValue(nSteps++);
223 nError = ReadThroughComponent(
224 rMedium.GetStorage(), xModelComp, "content.xml", "Content.xml",
225 xContext, xInfoSet, "com.sun.star.comp.Math.XMLImporter" );
227 else
228 nError = ERRCODE_IO_BROKENPACKAGE;
230 else
231 nError = ERRCODE_IO_BROKENPACKAGE;
233 else
235 Reference<io::XInputStream> xInputStream =
236 new utl::OInputStreamWrapper(rMedium.GetInStream());
238 if (xStatusIndicator.is())
239 xStatusIndicator->setValue(nSteps++);
241 nError = ReadThroughComponent( xInputStream, xModelComp,
242 xContext, xInfoSet, "com.sun.star.comp.Math.XMLImporter", false );
245 if (xStatusIndicator.is())
246 xStatusIndicator->end();
247 return nError;
251 /// read a component (file + filter version)
252 sal_uLong SmXMLImportWrapper::ReadThroughComponent(
253 Reference<io::XInputStream> xInputStream,
254 Reference<XComponent> xModelComponent,
255 Reference<uno::XComponentContext> & rxContext,
256 Reference<beans::XPropertySet> & rPropSet,
257 const sal_Char* pFilterName,
258 sal_Bool bEncrypted )
260 sal_uLong nError = ERRCODE_SFX_DOLOADFAILED;
261 OSL_ENSURE(xInputStream.is(), "input stream missing");
262 OSL_ENSURE(xModelComponent.is(), "document missing");
263 OSL_ENSURE(rxContext.is(), "factory missing");
264 OSL_ENSURE(NULL != pFilterName,"I need a service name for the component!");
266 // prepare ParserInputSrouce
267 xml::sax::InputSource aParserInput;
268 aParserInput.aInputStream = xInputStream;
270 // get parser
271 Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(rxContext);
273 Sequence<Any> aArgs( 1 );
274 aArgs[0] <<= rPropSet;
276 // get filter
277 Reference< xml::sax::XDocumentHandler > xFilter(
278 rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
279 OUString::createFromAscii(pFilterName), aArgs, rxContext),
280 UNO_QUERY );
281 OSL_ENSURE( xFilter.is(), "Can't instantiate filter component." );
282 if ( !xFilter.is() )
283 return nError;
285 // connect parser and filter
286 xParser->setDocumentHandler( xFilter );
288 // connect model and filter
289 Reference < XImporter > xImporter( xFilter, UNO_QUERY );
290 xImporter->setTargetDocument( xModelComponent );
292 // finally, parser the stream
295 xParser->parseStream( aParserInput );
297 uno::Reference<lang::XUnoTunnel> xFilterTunnel;
298 xFilterTunnel = uno::Reference<lang::XUnoTunnel>
299 ( xFilter, uno::UNO_QUERY );
300 SmXMLImport *pFilter = reinterpret_cast< SmXMLImport * >(
301 sal::static_int_cast< sal_uIntPtr >(
302 xFilterTunnel->getSomething( SmXMLImport::getUnoTunnelId() )));
303 if ( pFilter && pFilter->GetSuccess() )
304 nError = 0;
306 catch( xml::sax::SAXParseException& r )
308 // sax parser sends wrapped exceptions,
309 // try to find the original one
310 xml::sax::SAXException aSaxEx = *(xml::sax::SAXException*)(&r);
311 sal_Bool bTryChild = sal_True;
313 while( bTryChild )
315 xml::sax::SAXException aTmp;
316 if ( aSaxEx.WrappedException >>= aTmp )
317 aSaxEx = aTmp;
318 else
319 bTryChild = sal_False;
322 packages::zip::ZipIOException aBrokenPackage;
323 if ( aSaxEx.WrappedException >>= aBrokenPackage )
324 return ERRCODE_IO_BROKENPACKAGE;
326 if ( bEncrypted )
327 nError = ERRCODE_SFX_WRONGPASSWORD;
329 catch( const xml::sax::SAXException& r )
331 packages::zip::ZipIOException aBrokenPackage;
332 if ( r.WrappedException >>= aBrokenPackage )
333 return ERRCODE_IO_BROKENPACKAGE;
335 if ( bEncrypted )
336 nError = ERRCODE_SFX_WRONGPASSWORD;
338 catch( packages::zip::ZipIOException& )
340 nError = ERRCODE_IO_BROKENPACKAGE;
342 catch( io::IOException& )
346 return nError;
350 sal_uLong SmXMLImportWrapper::ReadThroughComponent(
351 const uno::Reference< embed::XStorage >& xStorage,
352 Reference<XComponent> xModelComponent,
353 const sal_Char* pStreamName,
354 const sal_Char* pCompatibilityStreamName,
355 Reference<uno::XComponentContext> & rxContext,
356 Reference<beans::XPropertySet> & rPropSet,
357 const sal_Char* pFilterName )
359 OSL_ENSURE(xStorage.is(), "Need storage!");
360 OSL_ENSURE(NULL != pStreamName, "Please, please, give me a name!");
362 // open stream (and set parser input)
363 OUString sStreamName = OUString::createFromAscii(pStreamName);
364 uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
365 if ( !xAccess->hasByName(sStreamName) || !xStorage->isStreamElement(sStreamName) )
367 // stream name not found! Then try the compatibility name.
368 // do we even have an alternative name?
369 if ( pCompatibilityStreamName )
370 sStreamName = OUString::createFromAscii(pCompatibilityStreamName);
373 // get input stream
376 uno::Reference < io::XStream > xEventsStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
378 // determine if stream is encrypted or not
379 uno::Reference < beans::XPropertySet > xProps( xEventsStream, uno::UNO_QUERY );
380 Any aAny = xProps->getPropertyValue( "Encrypted" );
381 sal_Bool bEncrypted = sal_False;
382 if ( aAny.getValueType() == ::getBooleanCppuType() )
383 aAny >>= bEncrypted;
385 // set Base URL
386 if ( rPropSet.is() )
388 OUString sPropName( "StreamName");
389 rPropSet->setPropertyValue( sPropName, makeAny( sStreamName ) );
393 Reference < io::XInputStream > xStream = xEventsStream->getInputStream();
394 return ReadThroughComponent( xStream, xModelComponent, rxContext, rPropSet, pFilterName, bEncrypted );
396 catch ( packages::WrongPasswordException& )
398 return ERRCODE_SFX_WRONGPASSWORD;
400 catch( packages::zip::ZipIOException& )
402 return ERRCODE_IO_BROKENPACKAGE;
404 catch ( uno::Exception& )
408 return ERRCODE_SFX_DOLOADFAILED;
411 ////////////////////////////////////////////////////////////
413 SmXMLImport::SmXMLImport(
414 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext,
415 sal_uInt16 nImportFlags)
416 : SvXMLImport( xContext, nImportFlags ),
417 pPresLayoutElemTokenMap(0),
418 pPresLayoutAttrTokenMap(0),
419 pFencedAttrTokenMap(0),
420 pOperatorAttrTokenMap(0),
421 pAnnotationAttrTokenMap(0),
422 pPresElemTokenMap(0),
423 pPresScriptEmptyElemTokenMap(0),
424 pPresTableElemTokenMap(0),
425 pColorTokenMap(0),
426 bSuccess(sal_False)
430 namespace
432 class theSmXMLImportUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSmXMLImportUnoTunnelId> {};
435 const uno::Sequence< sal_Int8 > & SmXMLImport::getUnoTunnelId() throw()
437 return theSmXMLImportUnoTunnelId::get().getSeq();
440 OUString SAL_CALL SmXMLImport_getImplementationName() throw()
442 return OUString( "com.sun.star.comp.Math.XMLImporter" );
445 uno::Sequence< OUString > SAL_CALL SmXMLImport_getSupportedServiceNames()
446 throw()
448 const OUString aServiceName( IMPORT_SVC_NAME );
449 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
450 return aSeq;
453 uno::Reference< uno::XInterface > SAL_CALL SmXMLImport_createInstance(
454 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
455 throw( uno::Exception )
457 return (cppu::OWeakObject*)new SmXMLImport(comphelper::getComponentContext(rSMgr), IMPORT_ALL);
460 ////////////////////////////////////////////////////////////
462 OUString SAL_CALL SmXMLImportMeta_getImplementationName() throw()
464 return OUString( "com.sun.star.comp.Math.XMLOasisMetaImporter" );
467 uno::Sequence< OUString > SAL_CALL SmXMLImportMeta_getSupportedServiceNames()
468 throw()
470 const OUString aServiceName( IMPORT_SVC_NAME );
471 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
472 return aSeq;
475 uno::Reference< uno::XInterface > SAL_CALL SmXMLImportMeta_createInstance(
476 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
477 throw( uno::Exception )
479 return (cppu::OWeakObject*)new SmXMLImport( comphelper::getComponentContext(rSMgr), IMPORT_META );
482 ////////////////////////////////////////////////////////////
484 OUString SAL_CALL SmXMLImportSettings_getImplementationName() throw()
486 return OUString( "com.sun.star.comp.Math.XMLOasisSettingsImporter" );
489 uno::Sequence< OUString > SAL_CALL SmXMLImportSettings_getSupportedServiceNames()
490 throw()
492 const OUString aServiceName( IMPORT_SVC_NAME );
493 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
494 return aSeq;
497 uno::Reference< uno::XInterface > SAL_CALL SmXMLImportSettings_createInstance(
498 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
499 throw( uno::Exception )
501 return (cppu::OWeakObject*)new SmXMLImport( comphelper::getComponentContext(rSMgr), IMPORT_SETTINGS );
504 ////////////////////////////////////////////////////////////
506 // XServiceInfo
507 // override empty method from parent class
508 OUString SAL_CALL SmXMLImport::getImplementationName()
509 throw(uno::RuntimeException)
511 OUString aTxt;
512 switch( getImportFlags() )
514 case IMPORT_META:
515 aTxt = SmXMLImportMeta_getImplementationName();
516 break;
517 case IMPORT_SETTINGS:
518 aTxt = SmXMLImportSettings_getImplementationName();
519 break;
520 case IMPORT_ALL:
521 default:
522 aTxt = SmXMLImport_getImplementationName();
523 break;
525 return aTxt;
529 sal_Int64 SAL_CALL SmXMLImport::getSomething(
530 const uno::Sequence< sal_Int8 >&rId )
531 throw(uno::RuntimeException)
533 if ( rId.getLength() == 16 &&
534 0 == memcmp( getUnoTunnelId().getConstArray(),
535 rId.getConstArray(), 16 ) )
536 return sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_uIntPtr >(this));
538 return SvXMLImport::getSomething( rId );
541 void SmXMLImport::endDocument(void)
542 throw(xml::sax::SAXException, uno::RuntimeException)
544 //Set the resulted tree into the SmDocShell where it belongs
545 SmNode *pTree;
546 if (NULL != (pTree = GetTree()))
548 uno::Reference <frame::XModel> xModel = GetModel();
549 uno::Reference <lang::XUnoTunnel> xTunnel;
550 xTunnel = uno::Reference <lang::XUnoTunnel> (xModel,uno::UNO_QUERY);
551 SmModel *pModel = reinterpret_cast<SmModel *>
552 (xTunnel->getSomething(SmModel::getUnoTunnelId()));
554 if (pModel)
556 SmDocShell *pDocShell =
557 static_cast<SmDocShell*>(pModel->GetObjectShell());
558 pDocShell->SetFormulaTree(pTree);
559 if (0 == aText.Len()) //If we picked up no annotation text
561 //Make up some editable text
562 aText = pDocShell->GetText();
563 pTree->CreateTextFromNode(aText);
564 aText = comphelper::string::stripEnd(aText, ' ');
566 pDocShell->SetText( String() );
568 // Convert symbol names
569 SmParser &rParser = pDocShell->GetParser();
570 bool bVal = rParser.IsImportSymbolNames();
571 rParser.SetImportSymbolNames( true );
572 SmNode *pTmpTree = rParser.Parse( aText );
573 aText = rParser.GetText();
574 delete pTmpTree;
575 rParser.SetImportSymbolNames( bVal );
577 pDocShell->SetText( aText );
579 OSL_ENSURE(pModel,"So there *was* a uno problem after all");
581 bSuccess = sal_True;
584 SvXMLImport::endDocument();
587 ////////////////////////////////////////////////////////////
589 class SmXMLImportContext: public SvXMLImportContext
591 public:
592 SmXMLImportContext( SmXMLImport &rImport, sal_uInt16 nPrfx,
593 const OUString& rLName)
594 : SvXMLImportContext(rImport, nPrfx, rLName) {}
596 const SmXMLImport& GetSmImport() const
598 return (const SmXMLImport&)GetImport();
601 SmXMLImport& GetSmImport()
603 return (SmXMLImport&)GetImport();
606 virtual void TCharacters(const OUString & /*rChars*/);
607 virtual void Characters(const OUString &rChars);
608 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/, const uno::Reference< xml::sax::XAttributeList > & /*xAttrList*/);
611 void SmXMLImportContext::TCharacters(const OUString & /*rChars*/)
615 void SmXMLImportContext::Characters(const OUString &rChars)
618 Whitespace occurring within the content of token elements is "trimmed"
619 from the ends (i.e. all whitespace at the beginning and end of the
620 content is removed), and "collapsed" internally (i.e. each sequence of
621 1 or more whitespace characters is replaced with one blank character).
623 //collapsing not done yet!
624 const OUString &rChars2 = rChars.trim();
625 if (!rChars2.isEmpty())
626 TCharacters(rChars2/*.collapse()*/);
629 SvXMLImportContext * SmXMLImportContext::CreateChildContext(sal_uInt16 /*nPrefix*/,
630 const OUString& /*rLocalName*/,
631 const uno::Reference< xml::sax::XAttributeList > & /*xAttrList*/)
633 return 0;
636 ////////////////////////////////////////////////////////////
638 struct SmXMLContext_Helper
640 sal_Int8 nIsBold;
641 sal_Int8 nIsItalic;
642 double nFontSize;
643 sal_Bool bFontNodeNeeded;
644 OUString sFontFamily;
645 OUString sColor;
647 SmXMLImportContext rContext;
649 SmXMLContext_Helper(SmXMLImportContext &rImport) :
650 nIsBold(-1), nIsItalic(-1), nFontSize(0.0), rContext(rImport) {}
652 void RetrieveAttrs(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
653 void ApplyAttrs();
656 void SmXMLContext_Helper::RetrieveAttrs(const uno::Reference<
657 xml::sax::XAttributeList > & xAttrList )
659 sal_Int8 nOldIsBold=nIsBold;
660 sal_Int8 nOldIsItalic=nIsItalic;
661 double nOldFontSize=nFontSize;
662 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
663 OUString sOldFontFamily = sFontFamily;
664 for (sal_Int16 i=0;i<nAttrCount;i++)
666 OUString sAttrName = xAttrList->getNameByIndex(i);
667 OUString aLocalName;
668 sal_uInt16 nPrefix = rContext.GetSmImport().GetNamespaceMap().
669 GetKeyByAttrName(sAttrName,&aLocalName);
670 OUString sValue = xAttrList->getValueByIndex(i);
671 const SvXMLTokenMap &rAttrTokenMap =
672 rContext.GetSmImport().GetPresLayoutAttrTokenMap();
673 switch(rAttrTokenMap.Get(nPrefix,aLocalName))
675 case XML_TOK_FONTWEIGHT:
676 nIsBold = sValue.equals(GetXMLToken(XML_BOLD));
677 break;
678 case XML_TOK_FONTSTYLE:
679 nIsItalic = sValue.equals(GetXMLToken(XML_ITALIC));
680 break;
681 case XML_TOK_FONTSIZE:
682 ::sax::Converter::convertDouble(nFontSize, sValue);
683 rContext.GetSmImport().GetMM100UnitConverter().
684 SetXMLMeasureUnit(util::MeasureUnit::POINT);
685 if (-1 == sValue.indexOf(GetXMLToken(XML_UNIT_PT)))
687 if (-1 == sValue.indexOf('%'))
688 nFontSize=0.0;
689 else
691 rContext.GetSmImport().GetMM100UnitConverter().
692 SetXMLMeasureUnit(util::MeasureUnit::PERCENT);
695 break;
696 case XML_TOK_FONTFAMILY:
697 sFontFamily = sValue;
698 break;
699 case XML_TOK_COLOR:
700 sColor = sValue;
701 break;
702 default:
703 break;
707 if ((nOldIsBold!=nIsBold) || (nOldIsItalic!=nIsItalic) ||
708 (nOldFontSize!=nFontSize) || (sOldFontFamily!=sFontFamily)
709 || !sColor.isEmpty())
710 bFontNodeNeeded=sal_True;
711 else
712 bFontNodeNeeded=sal_False;
715 void SmXMLContext_Helper::ApplyAttrs()
717 SmNodeStack &rNodeStack = rContext.GetSmImport().GetNodeStack();
719 if (bFontNodeNeeded)
721 SmToken aToken;
722 aToken.cMathChar = '\0';
723 aToken.nGroup = 0;
724 aToken.nLevel = 5;
726 if (nIsBold != -1)
728 if (nIsBold)
729 aToken.eType = TBOLD;
730 else
731 aToken.eType = TNBOLD;
732 SmStructureNode *pFontNode = static_cast<SmStructureNode *>
733 (new SmFontNode(aToken));
734 pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
735 rNodeStack.push(pFontNode);
737 if (nIsItalic != -1)
739 if (nIsItalic)
740 aToken.eType = TITALIC;
741 else
742 aToken.eType = TNITALIC;
743 SmStructureNode *pFontNode = static_cast<SmStructureNode *>
744 (new SmFontNode(aToken));
745 pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
746 rNodeStack.push(pFontNode);
748 if (nFontSize != 0.0)
750 aToken.eType = TSIZE;
751 SmFontNode *pFontNode = new SmFontNode(aToken);
753 if (util::MeasureUnit::PERCENT == rContext.GetSmImport()
754 .GetMM100UnitConverter().GetXMLMeasureUnit())
756 if (nFontSize < 100.00)
757 pFontNode->SetSizeParameter(Fraction(100.00/nFontSize),
758 FNTSIZ_DIVIDE);
759 else
760 pFontNode->SetSizeParameter(Fraction(nFontSize/100.00),
761 FNTSIZ_MULTIPLY);
763 else
764 pFontNode->SetSizeParameter(Fraction(nFontSize),FNTSIZ_ABSOLUT);
766 pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
767 rNodeStack.push(pFontNode);
769 if (!sFontFamily.isEmpty())
771 if (sFontFamily.equalsIgnoreAsciiCase(GetXMLToken(XML_FIXED)))
772 aToken.eType = TFIXED;
773 else if (sFontFamily.equalsIgnoreAsciiCase("sans"))
774 aToken.eType = TSANS;
775 else if (sFontFamily.equalsIgnoreAsciiCase("serif"))
776 aToken.eType = TSERIF;
777 else //Just give up, we need to extend our font mechanism to be
778 //more general
779 return;
781 aToken.aText = sFontFamily;
782 SmFontNode *pFontNode = new SmFontNode(aToken);
783 pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
784 rNodeStack.push(pFontNode);
786 if (!sColor.isEmpty())
788 //Again we can only handle a small set of colours in
789 //StarMath for now.
790 const SvXMLTokenMap& rTokenMap =
791 rContext.GetSmImport().GetColorTokenMap();
792 sal_uInt16 tok = rTokenMap.Get(XML_NAMESPACE_MATH, sColor);
793 if (tok != XML_TOK_UNKNOWN)
795 aToken.eType = static_cast<SmTokenType>(tok);
796 SmFontNode *pFontNode = new SmFontNode(aToken);
797 pFontNode->SetSubNodes(0,lcl_popOrZero(rNodeStack));
798 rNodeStack.push(pFontNode);
805 ////////////////////////////////////////////////////////////
807 class SmXMLDocContext_Impl : public SmXMLImportContext
809 public:
810 SmXMLDocContext_Impl( SmXMLImport &rImport, sal_uInt16 nPrfx,
811 const OUString& rLName)
812 : SmXMLImportContext(rImport,nPrfx,rLName) {}
814 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList);
816 void EndElement();
819 ////////////////////////////////////////////////////////////
821 /*avert thy gaze from the proginator*/
822 class SmXMLRowContext_Impl : public SmXMLDocContext_Impl
824 protected:
825 sal_uLong nElementCount;
827 public:
828 SmXMLRowContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
829 const OUString& rLName)
830 : SmXMLDocContext_Impl(rImport,nPrefix,rLName)
831 { nElementCount = GetSmImport().GetNodeStack().size(); }
833 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList);
835 SvXMLImportContext *StrictCreateChildContext(sal_uInt16 nPrefix,
836 const OUString& rLocalName,
837 const uno::Reference< xml::sax::XAttributeList > &xAttrList);
839 void EndElement();
842 ////////////////////////////////////////////////////////////
844 class SmXMLFracContext_Impl : public SmXMLRowContext_Impl
846 public:
847 SmXMLFracContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
848 const OUString& rLName)
849 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
851 void EndElement();
854 ////////////////////////////////////////////////////////////
856 class SmXMLSqrtContext_Impl : public SmXMLRowContext_Impl
858 public:
859 SmXMLSqrtContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
860 const OUString& rLName)
861 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
863 void EndElement();
866 ////////////////////////////////////////////////////////////
868 class SmXMLRootContext_Impl : public SmXMLRowContext_Impl
870 public:
871 SmXMLRootContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
872 const OUString& rLName)
873 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
875 void EndElement();
878 ////////////////////////////////////////////////////////////
880 class SmXMLStyleContext_Impl : public SmXMLRowContext_Impl
882 protected:
883 SmXMLContext_Helper aStyleHelper;
885 public:
886 /*Right now the style tag is completely ignored*/
887 SmXMLStyleContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
888 const OUString& rLName) : SmXMLRowContext_Impl(rImport,nPrefix,rLName),
889 aStyleHelper(*this) {}
891 void EndElement();
892 void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
895 void SmXMLStyleContext_Impl::StartElement(const uno::Reference<
896 xml::sax::XAttributeList > & xAttrList )
898 aStyleHelper.RetrieveAttrs(xAttrList);
902 void SmXMLStyleContext_Impl::EndElement()
905 <mstyle> accepts any number of arguments; if this number is not 1, its
906 contents are treated as a single "inferred <mrow>" containing its
907 arguments
909 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
910 if (rNodeStack.size() - nElementCount > 1)
911 SmXMLRowContext_Impl::EndElement();
912 aStyleHelper.ApplyAttrs();
915 ////////////////////////////////////////////////////////////
917 class SmXMLPaddedContext_Impl : public SmXMLRowContext_Impl
919 public:
920 /*Right now the style tag is completely ignored*/
921 SmXMLPaddedContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
922 const OUString& rLName)
923 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
925 void EndElement();
928 void SmXMLPaddedContext_Impl::EndElement()
931 <mpadded> accepts any number of arguments; if this number is not 1, its
932 contents are treated as a single "inferred <mrow>" containing its
933 arguments
935 if (GetSmImport().GetNodeStack().size() - nElementCount > 1)
936 SmXMLRowContext_Impl::EndElement();
939 ////////////////////////////////////////////////////////////
941 class SmXMLPhantomContext_Impl : public SmXMLRowContext_Impl
943 public:
944 /*Right now the style tag is completely ignored*/
945 SmXMLPhantomContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
946 const OUString& rLName)
947 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
949 void EndElement();
952 void SmXMLPhantomContext_Impl::EndElement()
955 <mphantom> accepts any number of arguments; if this number is not 1, its
956 contents are treated as a single "inferred <mrow>" containing its
957 arguments
959 if (GetSmImport().GetNodeStack().size() - nElementCount > 1)
960 SmXMLRowContext_Impl::EndElement();
962 SmToken aToken;
963 aToken.cMathChar = '\0';
964 aToken.nGroup = 0;
965 aToken.nLevel = 5;
966 aToken.eType = TPHANTOM;
968 SmStructureNode *pPhantom = static_cast<SmStructureNode *>
969 (new SmFontNode(aToken));
970 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
971 pPhantom->SetSubNodes(0,lcl_popOrZero(rNodeStack));
972 rNodeStack.push(pPhantom);
975 ////////////////////////////////////////////////////////////
977 class SmXMLFencedContext_Impl : public SmXMLRowContext_Impl
979 protected:
980 sal_Unicode cBegin;
981 sal_Unicode cEnd;
983 public:
984 SmXMLFencedContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
985 const OUString& rLName)
986 : SmXMLRowContext_Impl(rImport,nPrefix,rLName),
987 cBegin('('), cEnd(')') {}
989 void StartElement(const uno::Reference< xml::sax::XAttributeList > & xAttrList );
990 void EndElement();
994 void SmXMLFencedContext_Impl::StartElement(const uno::Reference<
995 xml::sax::XAttributeList > & xAttrList )
997 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
998 for (sal_Int16 i=0;i<nAttrCount;i++)
1000 OUString sAttrName = xAttrList->getNameByIndex(i);
1001 OUString aLocalName;
1002 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1003 GetKeyByAttrName(sAttrName,&aLocalName);
1004 OUString sValue = xAttrList->getValueByIndex(i);
1005 const SvXMLTokenMap &rAttrTokenMap =
1006 GetSmImport().GetFencedAttrTokenMap();
1007 switch(rAttrTokenMap.Get(nPrefix,aLocalName))
1009 //temp, starmath cannot handle multichar brackets (I think)
1010 case XML_TOK_OPEN:
1011 cBegin = sValue[0];
1012 break;
1013 case XML_TOK_CLOSE:
1014 cEnd = sValue[0];
1015 break;
1016 default:
1017 /*Go to superclass*/
1018 break;
1024 void SmXMLFencedContext_Impl::EndElement()
1026 SmToken aToken;
1027 aToken.cMathChar = '\0';
1028 aToken.nGroup = 0;
1029 aToken.aText = ",";
1030 aToken.eType = TLEFT;
1031 aToken.nLevel = 5;
1033 aToken.eType = TLPARENT;
1034 aToken.cMathChar = cBegin;
1035 SmStructureNode *pSNode = new SmBraceNode(aToken);
1036 SmNode *pLeft = new SmMathSymbolNode(aToken);
1038 aToken.cMathChar = cEnd;
1039 aToken.eType = TRPARENT;
1040 SmNode *pRight = new SmMathSymbolNode(aToken);
1042 SmNodeArray aRelationArray;
1043 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1045 aToken.cMathChar = '\0';
1046 aToken.aText = ",";
1047 aToken.eType = TIDENT;
1049 sal_uLong i = rNodeStack.size() - nElementCount;
1050 if (rNodeStack.size() - nElementCount > 1)
1051 i += rNodeStack.size() - 1 - nElementCount;
1052 aRelationArray.resize(i);
1053 while (rNodeStack.size() > nElementCount)
1055 aRelationArray[--i] = rNodeStack.top();
1056 rNodeStack.pop();
1057 if (i > 1 && rNodeStack.size() > 1)
1058 aRelationArray[--i] = new SmGlyphSpecialNode(aToken);
1061 SmToken aDummy;
1062 SmStructureNode *pBody = new SmExpressionNode(aDummy);
1063 pBody->SetSubNodes(aRelationArray);
1066 pSNode->SetSubNodes(pLeft,pBody,pRight);
1067 pSNode->SetScaleMode(SCALE_HEIGHT);
1068 GetSmImport().GetNodeStack().push(pSNode);
1072 ////////////////////////////////////////////////////////////
1074 class SmXMLErrorContext_Impl : public SmXMLRowContext_Impl
1076 public:
1077 SmXMLErrorContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1078 const OUString& rLName)
1079 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
1081 void EndElement();
1084 void SmXMLErrorContext_Impl::EndElement()
1086 /*Right now the error tag is completely ignored, what
1087 can I do with it in starmath, ?, maybe we need a
1088 report window ourselves, do a test for validity of
1089 the xml input, use merrors, and then generate
1090 the markup inside the merror with a big red colour
1091 of something. For now just throw them all away.
1093 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1094 while (rNodeStack.size() > nElementCount)
1096 delete rNodeStack.top();
1097 rNodeStack.pop();
1101 ////////////////////////////////////////////////////////////
1103 class SmXMLNumberContext_Impl : public SmXMLImportContext
1105 protected:
1106 SmToken aToken;
1108 public:
1109 SmXMLNumberContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1110 const OUString& rLName)
1111 : SmXMLImportContext(rImport,nPrefix,rLName)
1113 aToken.cMathChar = '\0';
1114 aToken.nGroup = 0;
1115 aToken.nLevel = 5;
1116 aToken.eType = TNUMBER;
1119 virtual void TCharacters(const OUString &rChars);
1121 void EndElement();
1124 void SmXMLNumberContext_Impl::TCharacters(const OUString &rChars)
1126 aToken.aText = rChars;
1129 void SmXMLNumberContext_Impl::EndElement()
1131 GetSmImport().GetNodeStack().push(new SmTextNode(aToken,FNT_NUMBER));
1134 ////////////////////////////////////////////////////////////
1136 class SmXMLAnnotationContext_Impl : public SmXMLImportContext
1138 sal_Bool bIsStarMath;
1140 public:
1141 SmXMLAnnotationContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1142 const OUString& rLName)
1143 : SmXMLImportContext(rImport,nPrefix,rLName), bIsStarMath(sal_False) {}
1145 virtual void Characters(const OUString &rChars);
1147 void StartElement(const uno::Reference<xml::sax::XAttributeList > & xAttrList );
1150 void SmXMLAnnotationContext_Impl::StartElement(const uno::Reference<
1151 xml::sax::XAttributeList > & xAttrList )
1153 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1154 for (sal_Int16 i=0;i<nAttrCount;i++)
1156 OUString sAttrName = xAttrList->getNameByIndex(i);
1157 OUString aLocalName;
1158 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1159 GetKeyByAttrName(sAttrName,&aLocalName);
1161 OUString sValue = xAttrList->getValueByIndex(i);
1162 const SvXMLTokenMap &rAttrTokenMap =
1163 GetSmImport().GetAnnotationAttrTokenMap();
1164 switch(rAttrTokenMap.Get(nPrefix,aLocalName))
1166 case XML_TOK_ENCODING:
1167 bIsStarMath= sValue == "StarMath 5.0";
1168 break;
1169 default:
1170 break;
1175 void SmXMLAnnotationContext_Impl::Characters(const OUString &rChars)
1177 if (bIsStarMath)
1178 GetSmImport().GetText().Append(String(rChars));
1181 ////////////////////////////////////////////////////////////
1183 class SmXMLTextContext_Impl : public SmXMLImportContext
1185 protected:
1186 SmToken aToken;
1188 public:
1189 SmXMLTextContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1190 const OUString& rLName)
1191 : SmXMLImportContext(rImport,nPrefix,rLName)
1193 aToken.cMathChar = '\0';
1194 aToken.nGroup = 0;
1195 aToken.nLevel = 5;
1196 aToken.eType = TTEXT;
1199 virtual void TCharacters(const OUString &rChars);
1201 void EndElement();
1204 void SmXMLTextContext_Impl::TCharacters(const OUString &rChars)
1206 aToken.aText = rChars;
1209 void SmXMLTextContext_Impl::EndElement()
1211 GetSmImport().GetNodeStack().push(new SmTextNode(aToken,FNT_TEXT));
1214 ////////////////////////////////////////////////////////////
1216 class SmXMLStringContext_Impl : public SmXMLImportContext
1218 protected:
1219 SmToken aToken;
1221 public:
1222 SmXMLStringContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1223 const OUString& rLName)
1224 : SmXMLImportContext(rImport,nPrefix,rLName)
1226 aToken.cMathChar = '\0';
1227 aToken.nGroup = 0;
1228 aToken.nLevel = 5;
1229 aToken.eType = TTEXT;
1232 virtual void TCharacters(const OUString &rChars);
1234 void EndElement();
1237 void SmXMLStringContext_Impl::TCharacters(const OUString &rChars)
1240 The content of <ms> elements should be rendered with visible "escaping" of
1241 certain characters in the content, including at least "double quote"
1242 itself, and preferably whitespace other than individual blanks. The intent
1243 is for the viewer to see that the expression is a string literal, and to
1244 see exactly which characters form its content. For example, <ms>double
1245 quote is "</ms> might be rendered as "double quote is \"".
1247 Obviously this isn't fully done here.
1249 aToken.aText = "\"" + rChars + "\"";
1252 void SmXMLStringContext_Impl::EndElement()
1254 GetSmImport().GetNodeStack().push(new SmTextNode(aToken,FNT_FIXED));
1257 ////////////////////////////////////////////////////////////
1259 class SmXMLIdentifierContext_Impl : public SmXMLImportContext
1261 protected:
1262 SmXMLContext_Helper aStyleHelper;
1263 SmToken aToken;
1265 public:
1266 SmXMLIdentifierContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1267 const OUString& rLName)
1268 : SmXMLImportContext(rImport,nPrefix,rLName),aStyleHelper(*this)
1270 aToken.cMathChar = '\0';
1271 aToken.nGroup = 0;
1272 aToken.nLevel = 5;
1273 aToken.eType = TIDENT;
1276 void TCharacters(const OUString &rChars);
1277 void StartElement(const uno::Reference< xml::sax::XAttributeList > & xAttrList )
1279 aStyleHelper.RetrieveAttrs(xAttrList);
1281 void EndElement();
1284 void SmXMLIdentifierContext_Impl::EndElement()
1286 SmTextNode *pNode = 0;
1287 //we will handle identifier italic/normal here instead of with a standalone
1288 //font node
1289 if (((aStyleHelper.nIsItalic == -1) && (aToken.aText.getLength() > 1))
1290 || ((aStyleHelper.nIsItalic == 0) && (aToken.aText.getLength() == 1)))
1292 pNode = new SmTextNode(aToken,FNT_FUNCTION);
1293 pNode->GetFont().SetItalic(ITALIC_NONE);
1294 aStyleHelper.nIsItalic = -1;
1296 else
1297 pNode = new SmTextNode(aToken,FNT_VARIABLE);
1298 if (aStyleHelper.bFontNodeNeeded && aStyleHelper.nIsItalic != -1)
1300 if (aStyleHelper.nIsItalic)
1301 pNode->GetFont().SetItalic(ITALIC_NORMAL);
1302 else
1303 pNode->GetFont().SetItalic(ITALIC_NONE);
1306 if ((-1!=aStyleHelper.nIsBold) || (0.0!=aStyleHelper.nFontSize) ||
1307 (!aStyleHelper.sFontFamily.isEmpty()) ||
1308 !aStyleHelper.sColor.isEmpty())
1309 aStyleHelper.bFontNodeNeeded=sal_True;
1310 else
1311 aStyleHelper.bFontNodeNeeded=sal_False;
1312 if (aStyleHelper.bFontNodeNeeded)
1313 aStyleHelper.ApplyAttrs();
1314 GetSmImport().GetNodeStack().push(pNode);
1317 void SmXMLIdentifierContext_Impl::TCharacters(const OUString &rChars)
1319 aToken.aText = rChars;
1322 ////////////////////////////////////////////////////////////
1324 class SmXMLOperatorContext_Impl : public SmXMLImportContext
1326 sal_Bool bIsStretchy;
1328 protected:
1329 SmToken aToken;
1331 public:
1332 SmXMLOperatorContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1333 const OUString& rLName)
1334 : SmXMLImportContext(rImport,nPrefix,rLName), bIsStretchy(sal_False)
1336 aToken.nGroup = 0;
1337 aToken.eType = TSPECIAL;
1338 aToken.nLevel = 5;
1341 void TCharacters(const OUString &rChars);
1342 void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
1343 void EndElement();
1346 void SmXMLOperatorContext_Impl::TCharacters(const OUString &rChars)
1348 aToken.cMathChar = rChars[0];
1351 void SmXMLOperatorContext_Impl::EndElement()
1353 SmMathSymbolNode *pNode = new SmMathSymbolNode(aToken);
1354 //For stretchy scaling the scaling must be retrieved from this node
1355 //and applied to the expression itself so as to get the expression
1356 //to scale the operator to the height of the expression itself
1357 if (bIsStretchy)
1358 pNode->SetScaleMode(SCALE_HEIGHT);
1359 GetSmImport().GetNodeStack().push(pNode);
1364 void SmXMLOperatorContext_Impl::StartElement(const uno::Reference<
1365 xml::sax::XAttributeList > & xAttrList )
1367 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1368 for (sal_Int16 i=0;i<nAttrCount;i++)
1370 OUString sAttrName = xAttrList->getNameByIndex(i);
1371 OUString aLocalName;
1372 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1373 GetKeyByAttrName(sAttrName,&aLocalName);
1375 OUString sValue = xAttrList->getValueByIndex(i);
1376 const SvXMLTokenMap &rAttrTokenMap =
1377 GetSmImport().GetOperatorAttrTokenMap();
1378 switch(rAttrTokenMap.Get(nPrefix,aLocalName))
1380 case XML_TOK_STRETCHY:
1381 bIsStretchy = sValue.equals(
1382 GetXMLToken(XML_TRUE));
1383 break;
1384 default:
1385 break;
1391 ////////////////////////////////////////////////////////////
1393 class SmXMLSpaceContext_Impl : public SmXMLImportContext
1395 public:
1396 SmXMLSpaceContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1397 const OUString& rLName)
1398 : SmXMLImportContext(rImport,nPrefix,rLName) {}
1400 void StartElement(const uno::Reference< xml::sax::XAttributeList >& xAttrList );
1403 void SmXMLSpaceContext_Impl::StartElement(
1404 const uno::Reference<xml::sax::XAttributeList > & /*xAttrList*/ )
1406 SmToken aToken;
1407 aToken.cMathChar = '\0';
1408 aToken.nGroup = 0;
1409 aToken.eType = TBLANK;
1410 aToken.nLevel = 5;
1411 SmBlankNode *pBlank = new SmBlankNode(aToken);
1412 pBlank->IncreaseBy(aToken);
1413 GetSmImport().GetNodeStack().push(pBlank);
1416 ////////////////////////////////////////////////////////////
1418 class SmXMLSubContext_Impl : public SmXMLRowContext_Impl
1420 protected:
1421 void GenericEndElement(SmTokenType eType,SmSubSup aSubSup);
1423 public:
1424 SmXMLSubContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1425 const OUString& rLName)
1426 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
1428 void EndElement()
1430 GenericEndElement(TRSUB,RSUB);
1435 void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType, SmSubSup eSubSup)
1437 /*The <msub> element requires exactly 2 arguments.*/
1438 const bool bNodeCheck = GetSmImport().GetNodeStack().size() - nElementCount == 2;
1439 OSL_ENSURE( bNodeCheck, "Sub has not two arguments" );
1440 if (!bNodeCheck)
1441 return;
1443 SmToken aToken;
1444 aToken.cMathChar = '\0';
1445 aToken.nGroup = 0;
1446 aToken.nLevel = 0;
1447 aToken.eType = eType;
1448 SmSubSupNode *pNode = new SmSubSupNode(aToken);
1449 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1451 // initialize subnodes array
1452 SmNodeArray aSubNodes;
1453 aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES);
1454 for (sal_uLong i = 1; i < aSubNodes.size(); i++)
1455 aSubNodes[i] = NULL;
1457 aSubNodes[eSubSup+1] = lcl_popOrZero(rNodeStack);
1458 aSubNodes[0] = lcl_popOrZero(rNodeStack);
1459 pNode->SetSubNodes(aSubNodes);
1460 rNodeStack.push(pNode);
1463 ////////////////////////////////////////////////////////////
1465 class SmXMLSupContext_Impl : public SmXMLSubContext_Impl
1467 public:
1468 SmXMLSupContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1469 const OUString& rLName)
1470 : SmXMLSubContext_Impl(rImport,nPrefix,rLName) {}
1472 void EndElement()
1474 GenericEndElement(TRSUP,RSUP);
1478 ////////////////////////////////////////////////////////////
1480 class SmXMLSubSupContext_Impl : public SmXMLRowContext_Impl
1482 protected:
1483 void GenericEndElement(SmTokenType eType, SmSubSup aSub,SmSubSup aSup);
1485 public:
1486 SmXMLSubSupContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1487 const OUString& rLName)
1488 : SmXMLRowContext_Impl(rImport,nPrefix,rLName) {}
1490 void EndElement()
1492 GenericEndElement(TRSUB,RSUB,RSUP);
1496 void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType,
1497 SmSubSup aSub,SmSubSup aSup)
1499 /*The <msub> element requires exactly 3 arguments.*/
1500 const bool bNodeCheck = GetSmImport().GetNodeStack().size() - nElementCount == 3;
1501 OSL_ENSURE( bNodeCheck, "SubSup has not three arguments" );
1502 if (!bNodeCheck)
1503 return;
1505 SmToken aToken;
1506 aToken.cMathChar = '\0';
1507 aToken.nGroup = 0;
1508 aToken.nLevel = 0;
1509 aToken.eType = eType;
1510 SmSubSupNode *pNode = new SmSubSupNode(aToken);
1511 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1513 // initialize subnodes array
1514 SmNodeArray aSubNodes;
1515 aSubNodes.resize(1 + SUBSUP_NUM_ENTRIES);
1516 for (sal_uLong i = 1; i < aSubNodes.size(); i++)
1517 aSubNodes[i] = NULL;
1519 aSubNodes[aSup+1] = lcl_popOrZero(rNodeStack);
1520 aSubNodes[aSub+1] = lcl_popOrZero(rNodeStack);
1521 aSubNodes[0] = lcl_popOrZero(rNodeStack);
1522 pNode->SetSubNodes(aSubNodes);
1523 rNodeStack.push(pNode);
1526 ////////////////////////////////////////////////////////////
1528 class SmXMLUnderContext_Impl : public SmXMLSubContext_Impl
1530 protected:
1531 sal_Int16 nAttrCount;
1533 public:
1534 SmXMLUnderContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1535 const OUString& rLName)
1536 : SmXMLSubContext_Impl(rImport,nPrefix,rLName) {}
1538 void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
1539 void EndElement();
1540 void HandleAccent();
1543 void SmXMLUnderContext_Impl::StartElement(const uno::Reference<
1544 xml::sax::XAttributeList > & xAttrList )
1546 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1549 void SmXMLUnderContext_Impl::HandleAccent()
1551 const bool bNodeCheck = GetSmImport().GetNodeStack().size() - nElementCount == 2;
1552 OSL_ENSURE( bNodeCheck, "Sub has not two arguments" );
1553 if (!bNodeCheck)
1554 return;
1556 /*Just one special case for the underline thing*/
1557 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1558 SmNode *pTest = lcl_popOrZero(rNodeStack);
1559 SmToken aToken;
1560 aToken.cMathChar = '\0';
1561 aToken.nGroup = 0;
1562 aToken.nLevel = 0;
1563 aToken.eType = TUNDERLINE;
1566 SmNodeArray aSubNodes;
1567 aSubNodes.resize(2);
1569 SmStructureNode *pNode = new SmAttributNode(aToken);
1570 if ((pTest->GetToken().cMathChar & 0x0FFF) == 0x0332)
1572 aSubNodes[0] = new SmRectangleNode(aToken);
1573 delete pTest;
1575 else
1576 aSubNodes[0] = pTest;
1578 aSubNodes[1] = lcl_popOrZero(rNodeStack);
1579 pNode->SetSubNodes(aSubNodes);
1580 pNode->SetScaleMode(SCALE_WIDTH);
1581 rNodeStack.push(pNode);
1585 void SmXMLUnderContext_Impl::EndElement()
1587 if (!nAttrCount)
1588 GenericEndElement(TCSUB,CSUB);
1589 else
1590 HandleAccent();
1593 ////////////////////////////////////////////////////////////
1595 class SmXMLOverContext_Impl : public SmXMLSubContext_Impl
1597 protected:
1598 sal_Int16 nAttrCount;
1600 public:
1601 SmXMLOverContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1602 const OUString& rLName)
1603 : SmXMLSubContext_Impl(rImport,nPrefix,rLName), nAttrCount(0) {}
1605 void EndElement();
1606 void StartElement(const uno::Reference< xml::sax::XAttributeList > &xAttrList );
1607 void HandleAccent();
1611 void SmXMLOverContext_Impl::StartElement(const uno::Reference<
1612 xml::sax::XAttributeList > & xAttrList )
1614 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1618 void SmXMLOverContext_Impl::EndElement()
1620 if (!nAttrCount)
1621 GenericEndElement(TCSUP,CSUP);
1622 else
1623 HandleAccent();
1627 void SmXMLOverContext_Impl::HandleAccent()
1629 const bool bNodeCheck = GetSmImport().GetNodeStack().size() - nElementCount == 2;
1630 OSL_ENSURE (bNodeCheck, "Sub has not two arguments");
1631 if (!bNodeCheck)
1632 return;
1634 SmToken aToken;
1635 aToken.cMathChar = '\0';
1636 aToken.nGroup = 0;
1637 aToken.nLevel = 0;
1638 aToken.eType = TACUTE;
1640 SmAttributNode *pNode = new SmAttributNode(aToken);
1641 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
1643 SmNodeArray aSubNodes;
1644 aSubNodes.resize(2);
1645 aSubNodes[0] = lcl_popOrZero(rNodeStack);
1646 aSubNodes[1] = lcl_popOrZero(rNodeStack);
1647 pNode->SetSubNodes(aSubNodes);
1648 pNode->SetScaleMode(SCALE_WIDTH);
1649 rNodeStack.push(pNode);
1653 ////////////////////////////////////////////////////////////
1655 class SmXMLUnderOverContext_Impl : public SmXMLSubSupContext_Impl
1657 public:
1658 SmXMLUnderOverContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1659 const OUString& rLName)
1660 : SmXMLSubSupContext_Impl(rImport,nPrefix,rLName) {}
1662 void EndElement()
1664 GenericEndElement(TCSUB,CSUB,CSUP);
1668 ////////////////////////////////////////////////////////////
1670 class SmXMLMultiScriptsContext_Impl : public SmXMLSubSupContext_Impl
1672 bool bHasPrescripts;
1674 void ProcessSubSupPairs(bool bIsPrescript);
1676 public:
1677 SmXMLMultiScriptsContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1678 const OUString& rLName) :
1679 SmXMLSubSupContext_Impl(rImport,nPrefix,rLName),
1680 bHasPrescripts(false) {}
1682 void EndElement();
1683 SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix,
1684 const OUString& rLocalName,
1685 const uno::Reference< xml::sax::XAttributeList > &xAttrList);
1688 ////////////////////////////////////////////////////////////
1690 class SmXMLNoneContext_Impl : public SmXMLImportContext
1692 public:
1693 SmXMLNoneContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1694 const OUString& rLName)
1695 : SmXMLImportContext(rImport,nPrefix,rLName) {}
1697 void EndElement();
1701 void SmXMLNoneContext_Impl::EndElement(void)
1703 SmToken aToken;
1704 aToken.cMathChar = '\0';
1705 aToken.nGroup = 0;
1706 aToken.aText = "";
1707 aToken.nLevel = 5;
1708 aToken.eType = TIDENT;
1709 GetSmImport().GetNodeStack().push(
1710 new SmTextNode(aToken,FNT_VARIABLE));
1713 ////////////////////////////////////////////////////////////
1715 class SmXMLPrescriptsContext_Impl : public SmXMLImportContext
1717 public:
1718 SmXMLPrescriptsContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1719 const OUString& rLName)
1720 : SmXMLImportContext(rImport,nPrefix,rLName) {}
1723 ////////////////////////////////////////////////////////////
1725 class SmXMLTableRowContext_Impl : public SmXMLRowContext_Impl
1727 public:
1728 SmXMLTableRowContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1729 const OUString& rLName) :
1730 SmXMLRowContext_Impl(rImport,nPrefix,rLName)
1733 SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix,
1734 const OUString& rLocalName,
1735 const uno::Reference< xml::sax::XAttributeList > &xAttrList);
1739 ////////////////////////////////////////////////////////////
1741 class SmXMLTableContext_Impl : public SmXMLTableRowContext_Impl
1743 public:
1744 SmXMLTableContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1745 const OUString& rLName) :
1746 SmXMLTableRowContext_Impl(rImport,nPrefix,rLName)
1749 void EndElement();
1750 SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix,
1751 const OUString& rLocalName,
1752 const uno::Reference< xml::sax::XAttributeList > &xAttrList);
1756 ////////////////////////////////////////////////////////////
1758 class SmXMLTableCellContext_Impl : public SmXMLRowContext_Impl
1760 public:
1761 SmXMLTableCellContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1762 const OUString& rLName) :
1763 SmXMLRowContext_Impl(rImport,nPrefix,rLName)
1767 ////////////////////////////////////////////////////////////
1769 class SmXMLAlignGroupContext_Impl : public SmXMLRowContext_Impl
1771 public:
1772 SmXMLAlignGroupContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1773 const OUString& rLName) :
1774 SmXMLRowContext_Impl(rImport,nPrefix,rLName)
1777 /*Don't do anything with alignment for now*/
1778 void EndElement()
1783 ////////////////////////////////////////////////////////////
1785 class SmXMLActionContext_Impl : public SmXMLRowContext_Impl
1787 public:
1788 SmXMLActionContext_Impl(SmXMLImport &rImport,sal_uInt16 nPrefix,
1789 const OUString& rLName) :
1790 SmXMLRowContext_Impl(rImport,nPrefix,rLName)
1793 void EndElement();
1796 ////////////////////////////////////////////////////////////
1798 // NB: virtually inherit so we can multiply inherit properly
1799 // in SmXMLFlatDocContext_Impl
1800 class SmXMLOfficeContext_Impl : public virtual SvXMLImportContext
1802 public:
1803 SmXMLOfficeContext_Impl( SmXMLImport &rImport, sal_uInt16 nPrfx,
1804 const OUString& rLName)
1805 : SvXMLImportContext(rImport,nPrfx,rLName) {}
1807 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList);
1810 SvXMLImportContext *SmXMLOfficeContext_Impl::CreateChildContext(sal_uInt16 nPrefix,
1811 const OUString& rLocalName,
1812 const uno::Reference< xml::sax::XAttributeList > &xAttrList)
1814 SvXMLImportContext *pContext = 0;
1815 if ( XML_NAMESPACE_OFFICE == nPrefix &&
1816 rLocalName == GetXMLToken(XML_META) )
1818 OSL_FAIL("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
1820 else if ( XML_NAMESPACE_OFFICE == nPrefix &&
1821 rLocalName == GetXMLToken(XML_SETTINGS) )
1823 pContext = new XMLDocumentSettingsContext( GetImport(),
1824 XML_NAMESPACE_OFFICE, rLocalName,
1825 xAttrList );
1827 else
1828 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1830 return pContext;
1833 ////////////////////////////////////////////////////////////
1835 // context for flat file xml format
1836 class SmXMLFlatDocContext_Impl
1837 : public SmXMLOfficeContext_Impl, public SvXMLMetaDocumentContext
1839 public:
1840 SmXMLFlatDocContext_Impl( SmXMLImport& i_rImport,
1841 sal_uInt16 i_nPrefix, const OUString & i_rLName,
1842 const uno::Reference<document::XDocumentProperties>& i_xDocProps);
1844 virtual ~SmXMLFlatDocContext_Impl();
1846 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 i_nPrefix, const OUString& i_rLocalName, const uno::Reference<xml::sax::XAttributeList>& i_xAttrList);
1849 SmXMLFlatDocContext_Impl::SmXMLFlatDocContext_Impl( SmXMLImport& i_rImport,
1850 sal_uInt16 i_nPrefix, const OUString & i_rLName,
1851 const uno::Reference<document::XDocumentProperties>& i_xDocProps) :
1852 SvXMLImportContext(i_rImport, i_nPrefix, i_rLName),
1853 SmXMLOfficeContext_Impl(i_rImport, i_nPrefix, i_rLName),
1854 SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName,
1855 i_xDocProps)
1859 SmXMLFlatDocContext_Impl::~SmXMLFlatDocContext_Impl()
1863 SvXMLImportContext *SmXMLFlatDocContext_Impl::CreateChildContext(
1864 sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
1865 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList)
1867 // behave like meta base class iff we encounter office:meta
1868 if ( XML_NAMESPACE_OFFICE == i_nPrefix &&
1869 i_rLocalName == GetXMLToken(XML_META) )
1871 return SvXMLMetaDocumentContext::CreateChildContext(
1872 i_nPrefix, i_rLocalName, i_xAttrList );
1874 else
1876 return SmXMLOfficeContext_Impl::CreateChildContext(
1877 i_nPrefix, i_rLocalName, i_xAttrList );
1881 ////////////////////////////////////////////////////////////
1883 static SvXMLTokenMapEntry aPresLayoutElemTokenMap[] =
1885 { XML_NAMESPACE_MATH, XML_SEMANTICS, XML_TOK_SEMANTICS },
1886 { XML_NAMESPACE_MATH, XML_MATH, XML_TOK_MATH },
1887 { XML_NAMESPACE_MATH, XML_MSTYLE, XML_TOK_MSTYLE },
1888 { XML_NAMESPACE_MATH, XML_MERROR, XML_TOK_MERROR },
1889 { XML_NAMESPACE_MATH, XML_MPHANTOM, XML_TOK_MPHANTOM },
1890 { XML_NAMESPACE_MATH, XML_MROW, XML_TOK_MROW },
1891 { XML_NAMESPACE_MATH, XML_MFRAC, XML_TOK_MFRAC },
1892 { XML_NAMESPACE_MATH, XML_MSQRT, XML_TOK_MSQRT },
1893 { XML_NAMESPACE_MATH, XML_MROOT, XML_TOK_MROOT },
1894 { XML_NAMESPACE_MATH, XML_MSUB, XML_TOK_MSUB },
1895 { XML_NAMESPACE_MATH, XML_MSUP, XML_TOK_MSUP },
1896 { XML_NAMESPACE_MATH, XML_MSUBSUP, XML_TOK_MSUBSUP },
1897 { XML_NAMESPACE_MATH, XML_MUNDER, XML_TOK_MUNDER },
1898 { XML_NAMESPACE_MATH, XML_MOVER, XML_TOK_MOVER },
1899 { XML_NAMESPACE_MATH, XML_MUNDEROVER, XML_TOK_MUNDEROVER },
1900 { XML_NAMESPACE_MATH, XML_MMULTISCRIPTS, XML_TOK_MMULTISCRIPTS },
1901 { XML_NAMESPACE_MATH, XML_MTABLE, XML_TOK_MTABLE },
1902 { XML_NAMESPACE_MATH, XML_MACTION, XML_TOK_MACTION },
1903 { XML_NAMESPACE_MATH, XML_MFENCED, XML_TOK_MFENCED },
1904 { XML_NAMESPACE_MATH, XML_MPADDED, XML_TOK_MPADDED },
1905 XML_TOKEN_MAP_END
1908 static SvXMLTokenMapEntry aPresLayoutAttrTokenMap[] =
1910 { XML_NAMESPACE_MATH, XML_FONTWEIGHT, XML_TOK_FONTWEIGHT },
1911 { XML_NAMESPACE_MATH, XML_FONTSTYLE, XML_TOK_FONTSTYLE },
1912 { XML_NAMESPACE_MATH, XML_FONTSIZE, XML_TOK_FONTSIZE },
1913 { XML_NAMESPACE_MATH, XML_FONTFAMILY, XML_TOK_FONTFAMILY },
1914 { XML_NAMESPACE_MATH, XML_COLOR, XML_TOK_COLOR },
1915 XML_TOKEN_MAP_END
1918 static SvXMLTokenMapEntry aFencedAttrTokenMap[] =
1920 { XML_NAMESPACE_MATH, XML_OPEN, XML_TOK_OPEN },
1921 { XML_NAMESPACE_MATH, XML_CLOSE, XML_TOK_CLOSE },
1922 XML_TOKEN_MAP_END
1925 static SvXMLTokenMapEntry aOperatorAttrTokenMap[] =
1927 { XML_NAMESPACE_MATH, XML_STRETCHY, XML_TOK_STRETCHY },
1928 XML_TOKEN_MAP_END
1931 static SvXMLTokenMapEntry aAnnotationAttrTokenMap[] =
1933 { XML_NAMESPACE_MATH, XML_ENCODING, XML_TOK_ENCODING },
1934 XML_TOKEN_MAP_END
1938 static SvXMLTokenMapEntry aPresElemTokenMap[] =
1940 { XML_NAMESPACE_MATH, XML_ANNOTATION, XML_TOK_ANNOTATION },
1941 { XML_NAMESPACE_MATH, XML_MI, XML_TOK_MI },
1942 { XML_NAMESPACE_MATH, XML_MN, XML_TOK_MN },
1943 { XML_NAMESPACE_MATH, XML_MO, XML_TOK_MO },
1944 { XML_NAMESPACE_MATH, XML_MTEXT, XML_TOK_MTEXT },
1945 { XML_NAMESPACE_MATH, XML_MSPACE,XML_TOK_MSPACE },
1946 { XML_NAMESPACE_MATH, XML_MS, XML_TOK_MS },
1947 { XML_NAMESPACE_MATH, XML_MALIGNGROUP, XML_TOK_MALIGNGROUP },
1948 XML_TOKEN_MAP_END
1951 static SvXMLTokenMapEntry aPresScriptEmptyElemTokenMap[] =
1953 { XML_NAMESPACE_MATH, XML_MPRESCRIPTS, XML_TOK_MPRESCRIPTS },
1954 { XML_NAMESPACE_MATH, XML_NONE, XML_TOK_NONE },
1955 XML_TOKEN_MAP_END
1958 static SvXMLTokenMapEntry aPresTableElemTokenMap[] =
1960 { XML_NAMESPACE_MATH, XML_MTR, XML_TOK_MTR },
1961 { XML_NAMESPACE_MATH, XML_MTD, XML_TOK_MTD },
1962 XML_TOKEN_MAP_END
1965 static SvXMLTokenMapEntry aColorTokenMap[] =
1967 { XML_NAMESPACE_MATH, XML_BLACK, TBLACK},
1968 { XML_NAMESPACE_MATH, XML_WHITE, TWHITE},
1969 { XML_NAMESPACE_MATH, XML_RED, TRED},
1970 { XML_NAMESPACE_MATH, XML_GREEN, TGREEN},
1971 { XML_NAMESPACE_MATH, XML_BLUE, TBLUE},
1972 { XML_NAMESPACE_MATH, XML_AQUA, TCYAN},
1973 { XML_NAMESPACE_MATH, XML_FUCHSIA, TMAGENTA},
1974 { XML_NAMESPACE_MATH, XML_YELLOW, TYELLOW},
1975 XML_TOKEN_MAP_END
1979 ////////////////////////////////////////////////////////////
1981 const SvXMLTokenMap& SmXMLImport::GetPresLayoutElemTokenMap()
1983 if (!pPresLayoutElemTokenMap)
1984 pPresLayoutElemTokenMap = new SvXMLTokenMap(aPresLayoutElemTokenMap);
1985 return *pPresLayoutElemTokenMap;
1988 const SvXMLTokenMap& SmXMLImport::GetPresLayoutAttrTokenMap()
1990 if (!pPresLayoutAttrTokenMap)
1991 pPresLayoutAttrTokenMap = new SvXMLTokenMap(aPresLayoutAttrTokenMap);
1992 return *pPresLayoutAttrTokenMap;
1996 const SvXMLTokenMap& SmXMLImport::GetFencedAttrTokenMap()
1998 if (!pFencedAttrTokenMap)
1999 pFencedAttrTokenMap = new SvXMLTokenMap(aFencedAttrTokenMap);
2000 return *pFencedAttrTokenMap;
2003 const SvXMLTokenMap& SmXMLImport::GetOperatorAttrTokenMap()
2005 if (!pOperatorAttrTokenMap)
2006 pOperatorAttrTokenMap = new SvXMLTokenMap(aOperatorAttrTokenMap);
2007 return *pOperatorAttrTokenMap;
2010 const SvXMLTokenMap& SmXMLImport::GetAnnotationAttrTokenMap()
2012 if (!pAnnotationAttrTokenMap)
2013 pAnnotationAttrTokenMap = new SvXMLTokenMap(aAnnotationAttrTokenMap);
2014 return *pAnnotationAttrTokenMap;
2017 const SvXMLTokenMap& SmXMLImport::GetPresElemTokenMap()
2019 if (!pPresElemTokenMap)
2020 pPresElemTokenMap = new SvXMLTokenMap(aPresElemTokenMap);
2021 return *pPresElemTokenMap;
2024 const SvXMLTokenMap& SmXMLImport::GetPresScriptEmptyElemTokenMap()
2026 if (!pPresScriptEmptyElemTokenMap)
2027 pPresScriptEmptyElemTokenMap = new
2028 SvXMLTokenMap(aPresScriptEmptyElemTokenMap);
2029 return *pPresScriptEmptyElemTokenMap;
2032 const SvXMLTokenMap& SmXMLImport::GetPresTableElemTokenMap()
2034 if (!pPresTableElemTokenMap)
2035 pPresTableElemTokenMap = new SvXMLTokenMap(aPresTableElemTokenMap);
2036 return *pPresTableElemTokenMap;
2039 const SvXMLTokenMap& SmXMLImport::GetColorTokenMap()
2041 if (!pColorTokenMap)
2042 pColorTokenMap = new SvXMLTokenMap(aColorTokenMap);
2043 return *pColorTokenMap;
2046 ////////////////////////////////////////////////////////////
2048 SvXMLImportContext *SmXMLDocContext_Impl::CreateChildContext(
2049 sal_uInt16 nPrefix,
2050 const OUString& rLocalName,
2051 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2053 SvXMLImportContext* pContext = 0L;
2055 const SvXMLTokenMap& rTokenMap = GetSmImport().GetPresLayoutElemTokenMap();
2057 switch(rTokenMap.Get(nPrefix, rLocalName))
2059 //Consider semantics a dummy except for any starmath annotations
2060 case XML_TOK_SEMANTICS:
2061 pContext = GetSmImport().CreateRowContext(nPrefix,rLocalName,
2062 xAttrList);
2063 break;
2064 /*General Layout Schemata*/
2065 case XML_TOK_MROW:
2066 pContext = GetSmImport().CreateRowContext(nPrefix,rLocalName,
2067 xAttrList);
2068 break;
2069 case XML_TOK_MFRAC:
2070 pContext = GetSmImport().CreateFracContext(nPrefix,rLocalName,
2071 xAttrList);
2072 break;
2073 case XML_TOK_MSQRT:
2074 pContext = GetSmImport().CreateSqrtContext(nPrefix,rLocalName,
2075 xAttrList);
2076 break;
2077 case XML_TOK_MROOT:
2078 pContext = GetSmImport().CreateRootContext(nPrefix,rLocalName,
2079 xAttrList);
2080 break;
2081 case XML_TOK_MSTYLE:
2082 pContext = GetSmImport().CreateStyleContext(nPrefix,rLocalName,
2083 xAttrList);
2084 break;
2085 case XML_TOK_MERROR:
2086 pContext = GetSmImport().CreateErrorContext(nPrefix,rLocalName,
2087 xAttrList);
2088 break;
2089 case XML_TOK_MPADDED:
2090 pContext = GetSmImport().CreatePaddedContext(nPrefix,rLocalName,
2091 xAttrList);
2092 break;
2093 case XML_TOK_MPHANTOM:
2094 pContext = GetSmImport().CreatePhantomContext(nPrefix,rLocalName,
2095 xAttrList);
2096 break;
2097 case XML_TOK_MFENCED:
2098 pContext = GetSmImport().CreateFencedContext(nPrefix,rLocalName,
2099 xAttrList);
2100 break;
2101 /*Script and Limit Schemata*/
2102 case XML_TOK_MSUB:
2103 pContext = GetSmImport().CreateSubContext(nPrefix,rLocalName,
2104 xAttrList);
2105 break;
2106 case XML_TOK_MSUP:
2107 pContext = GetSmImport().CreateSupContext(nPrefix,rLocalName,
2108 xAttrList);
2109 break;
2110 case XML_TOK_MSUBSUP:
2111 pContext = GetSmImport().CreateSubSupContext(nPrefix,rLocalName,
2112 xAttrList);
2113 break;
2114 case XML_TOK_MUNDER:
2115 pContext = GetSmImport().CreateUnderContext(nPrefix,rLocalName,
2116 xAttrList);
2117 break;
2118 case XML_TOK_MOVER:
2119 pContext = GetSmImport().CreateOverContext(nPrefix,rLocalName,
2120 xAttrList);
2121 break;
2122 case XML_TOK_MUNDEROVER:
2123 pContext = GetSmImport().CreateUnderOverContext(nPrefix,rLocalName,
2124 xAttrList);
2125 break;
2126 case XML_TOK_MMULTISCRIPTS:
2127 pContext = GetSmImport().CreateMultiScriptsContext(nPrefix,
2128 rLocalName, xAttrList);
2129 break;
2130 case XML_TOK_MTABLE:
2131 pContext = GetSmImport().CreateTableContext(nPrefix,
2132 rLocalName, xAttrList);
2133 break;
2134 case XML_TOK_MACTION:
2135 pContext = GetSmImport().CreateActionContext(nPrefix,
2136 rLocalName, xAttrList);
2137 break;
2138 default:
2139 /*Basically theres an implicit mrow around certain bare
2140 *elements, use a RowContext to see if this is one of
2141 *those ones*/
2142 SmXMLRowContext_Impl aTempContext(GetSmImport(),nPrefix,
2143 GetXMLToken(XML_MROW));
2145 pContext = aTempContext.StrictCreateChildContext(nPrefix,
2146 rLocalName, xAttrList);
2147 break;
2149 return pContext;
2152 void SmXMLDocContext_Impl::EndElement()
2154 SmNodeArray ContextArray;
2155 ContextArray.resize(1);
2156 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2158 ContextArray[0] = lcl_popOrZero(rNodeStack);
2160 SmToken aDummy;
2161 SmStructureNode *pSNode = new SmLineNode(aDummy);
2162 pSNode->SetSubNodes(ContextArray);
2163 rNodeStack.push(pSNode);
2165 SmNodeArray LineArray;
2166 sal_uLong n = rNodeStack.size();
2167 LineArray.resize(n);
2168 for (sal_uLong j = 0; j < n; j++)
2170 LineArray[n - (j + 1)] = rNodeStack.top();
2171 rNodeStack.pop();
2173 SmStructureNode *pSNode2 = new SmTableNode(aDummy);
2174 pSNode2->SetSubNodes(LineArray);
2175 rNodeStack.push(pSNode2);
2178 void SmXMLFracContext_Impl::EndElement()
2180 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2181 const bool bNodeCheck = rNodeStack.size() - nElementCount == 2;
2182 OSL_ENSURE( bNodeCheck, "Fraction (mfrac) tag is missing component" );
2183 if (!bNodeCheck)
2184 return;
2186 SmToken aToken;
2187 aToken.cMathChar = '\0';
2188 aToken.nGroup = 0;
2189 aToken.nLevel = 0;
2190 aToken.eType = TOVER;
2191 SmStructureNode *pSNode = new SmBinVerNode(aToken);
2192 SmNode *pOper = new SmRectangleNode(aToken);
2193 SmNode *pSecond = lcl_popOrZero(rNodeStack);
2194 SmNode *pFirst = lcl_popOrZero(rNodeStack);
2195 pSNode->SetSubNodes(pFirst,pOper,pSecond);
2196 rNodeStack.push(pSNode);
2199 void SmXMLRootContext_Impl::EndElement()
2201 /*The <mroot> element requires exactly 2 arguments.*/
2202 const bool bNodeCheck = GetSmImport().GetNodeStack().size() - nElementCount == 2;
2203 OSL_ENSURE( bNodeCheck, "Root tag is missing component");
2204 if (!bNodeCheck)
2205 return;
2207 SmToken aToken;
2208 aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font
2209 aToken.nGroup = 0;
2210 aToken.nLevel = 0;
2211 aToken.eType = TNROOT;
2212 SmStructureNode *pSNode = new SmRootNode(aToken);
2213 SmNode *pOper = new SmRootSymbolNode(aToken);
2214 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2215 SmNode *pIndex = lcl_popOrZero(rNodeStack);
2216 SmNode *pBase = lcl_popOrZero(rNodeStack);
2217 pSNode->SetSubNodes(pIndex,pOper,pBase);
2218 rNodeStack.push(pSNode);
2221 void SmXMLSqrtContext_Impl::EndElement()
2224 <msqrt> accepts any number of arguments; if this number is not 1, its
2225 contents are treated as a single "inferred <mrow>" containing its
2226 arguments
2228 if (GetSmImport().GetNodeStack().size() - nElementCount > 1)
2229 SmXMLRowContext_Impl::EndElement();
2231 SmToken aToken;
2232 aToken.cMathChar = MS_SQRT; //Temporary: alert, based on StarSymbol font
2233 aToken.nGroup = 0;
2234 aToken.nLevel = 0;
2235 aToken.eType = TSQRT;
2236 SmStructureNode *pSNode = new SmRootNode(aToken);
2237 SmNode *pOper = new SmRootSymbolNode(aToken);
2238 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2239 pSNode->SetSubNodes(0,pOper,lcl_popOrZero(rNodeStack));
2240 rNodeStack.push(pSNode);
2243 void SmXMLRowContext_Impl::EndElement()
2245 SmNodeArray aRelationArray;
2246 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2248 if (rNodeStack.size() > nElementCount)
2250 sal_uLong nSize = rNodeStack.size() - nElementCount;
2252 aRelationArray.resize(nSize);
2253 for (sal_uLong j=nSize;j > 0;j--)
2255 aRelationArray[j-1] = rNodeStack.top();
2256 rNodeStack.pop();
2259 //If the first or last element is an operator with stretchyness
2260 //set then we must create a brace node here from those elements,
2261 //removing the stretchness from the operators and applying it to
2262 //ourselves, and creating the appropriate dummy StarMath none bracket
2263 //to balance the arrangement
2264 if (((aRelationArray[0]->GetScaleMode() == SCALE_HEIGHT)
2265 && (aRelationArray[0]->GetType() == NMATH))
2266 || ((aRelationArray[nSize-1]->GetScaleMode() == SCALE_HEIGHT)
2267 && (aRelationArray[nSize-1]->GetType() == NMATH)))
2269 SmToken aToken;
2270 aToken.cMathChar = '\0';
2271 aToken.nGroup = 0;
2272 aToken.nLevel = 5;
2274 int nLeft=0,nRight=0;
2275 if ((aRelationArray[0]->GetScaleMode() == SCALE_HEIGHT)
2276 && (aRelationArray[0]->GetType() == NMATH))
2278 aToken = aRelationArray[0]->GetToken();
2279 nLeft=1;
2281 else
2282 aToken.cMathChar = '\0';
2284 aToken.eType = TLPARENT;
2285 SmNode *pLeft = new SmMathSymbolNode(aToken);
2287 if ((aRelationArray[nSize-1]->GetScaleMode() == SCALE_HEIGHT)
2288 && (aRelationArray[nSize-1]->GetType() == NMATH))
2290 aToken = aRelationArray[nSize-1]->GetToken();
2291 nRight=1;
2293 else
2294 aToken.cMathChar = '\0';
2296 aToken.eType = TRPARENT;
2297 SmNode *pRight = new SmMathSymbolNode(aToken);
2299 SmNodeArray aRelationArray2;
2301 //!! nSize-nLeft-nRight may be < 0 !!
2302 int nRelArrSize = nSize-nLeft-nRight;
2303 if (nRelArrSize > 0)
2305 aRelationArray2.resize(nRelArrSize);
2306 for (int i=0;i < nRelArrSize;i++)
2307 aRelationArray2[i] = aRelationArray[i+nLeft];
2310 SmToken aDummy;
2311 SmStructureNode *pSNode = new SmBraceNode(aToken);
2312 SmStructureNode *pBody = new SmExpressionNode(aDummy);
2313 pBody->SetSubNodes(aRelationArray2);
2315 pSNode->SetSubNodes(pLeft,pBody,pRight);
2316 pSNode->SetScaleMode(SCALE_HEIGHT);
2317 rNodeStack.push(pSNode);
2318 return;
2321 else //Multiple newlines result in empty row elements
2323 aRelationArray.resize(1);
2324 SmToken aToken;
2325 aToken.cMathChar = '\0';
2326 aToken.nGroup = 0;
2327 aToken.nLevel = 5;
2328 aToken.eType = TNEWLINE;
2329 aRelationArray[0] = new SmLineNode(aToken);
2332 SmToken aDummy;
2333 SmStructureNode *pSNode = new SmExpressionNode(aDummy);
2334 pSNode->SetSubNodes(aRelationArray);
2335 rNodeStack.push(pSNode);
2339 SvXMLImportContext *SmXMLRowContext_Impl::StrictCreateChildContext(
2340 sal_uInt16 nPrefix,
2341 const OUString& rLocalName,
2342 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2344 SvXMLImportContext* pContext = 0L;
2346 const SvXMLTokenMap& rTokenMap = GetSmImport().GetPresElemTokenMap();
2347 switch(rTokenMap.Get(nPrefix, rLocalName))
2349 /*Note that these should accept malignmark subelements, but do not*/
2350 case XML_TOK_MN:
2351 pContext = GetSmImport().CreateNumberContext(nPrefix,rLocalName,
2352 xAttrList);
2353 break;
2354 case XML_TOK_MI:
2355 pContext = GetSmImport().CreateIdentifierContext(nPrefix,rLocalName,
2356 xAttrList);
2357 break;
2358 case XML_TOK_MO:
2359 pContext = GetSmImport().CreateOperatorContext(nPrefix,rLocalName,
2360 xAttrList);
2361 break;
2362 case XML_TOK_MTEXT:
2363 pContext = GetSmImport().CreateTextContext(nPrefix,rLocalName,
2364 xAttrList);
2365 break;
2366 case XML_TOK_MSPACE:
2367 pContext = GetSmImport().CreateSpaceContext(nPrefix,rLocalName,
2368 xAttrList);
2369 break;
2370 case XML_TOK_MS:
2371 pContext = GetSmImport().CreateStringContext(nPrefix,rLocalName,
2372 xAttrList);
2373 break;
2375 /*Note: The maligngroup should only be seen when the row
2376 * (or decendants) are in a table*/
2377 case XML_TOK_MALIGNGROUP:
2378 pContext = GetSmImport().CreateAlignGroupContext(nPrefix,rLocalName,
2379 xAttrList);
2380 break;
2382 case XML_TOK_ANNOTATION:
2383 pContext = GetSmImport().CreateAnnotationContext(nPrefix,rLocalName,
2384 xAttrList);
2385 break;
2387 default:
2388 break;
2390 return pContext;
2394 SvXMLImportContext *SmXMLRowContext_Impl::CreateChildContext(
2395 sal_uInt16 nPrefix,
2396 const OUString& rLocalName,
2397 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2399 SvXMLImportContext* pContext = StrictCreateChildContext(nPrefix,
2400 rLocalName, xAttrList);
2402 if (!pContext)
2404 //Hmm, unrecognized for this level, check to see if its
2405 //an element that can have an implicit schema around it
2406 pContext = SmXMLDocContext_Impl::CreateChildContext(nPrefix,
2407 rLocalName,xAttrList);
2409 return pContext;
2413 SvXMLImportContext *SmXMLMultiScriptsContext_Impl::CreateChildContext(
2414 sal_uInt16 nPrefix,
2415 const OUString& rLocalName,
2416 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2418 SvXMLImportContext* pContext = 0L;
2420 const SvXMLTokenMap& rTokenMap = GetSmImport().
2421 GetPresScriptEmptyElemTokenMap();
2422 switch(rTokenMap.Get(nPrefix, rLocalName))
2424 case XML_TOK_MPRESCRIPTS:
2425 bHasPrescripts = true;
2426 ProcessSubSupPairs(false);
2427 pContext = GetSmImport().CreatePrescriptsContext(nPrefix,
2428 rLocalName, xAttrList);
2429 break;
2430 case XML_TOK_NONE:
2431 pContext = GetSmImport().CreateNoneContext(nPrefix,rLocalName,
2432 xAttrList);
2433 break;
2434 default:
2435 pContext = SmXMLRowContext_Impl::CreateChildContext(nPrefix,
2436 rLocalName,xAttrList);
2437 break;
2439 return pContext;
2442 void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript)
2444 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2446 if (rNodeStack.size() <= nElementCount)
2447 return;
2449 sal_uLong nCount = rNodeStack.size() - nElementCount - 1;
2450 if (nCount == 0)
2451 return;
2453 if (nCount % 2 == 0)
2455 SmToken aToken;
2456 aToken.cMathChar = '\0';
2457 aToken.nGroup = 0;
2458 aToken.nLevel = 0;
2459 aToken.eType = bIsPrescript ? TLSUB : TRSUB;
2461 SmNodeStack aReverseStack;
2462 for (sal_uLong i = 0; i < nCount + 1; i++)
2464 aReverseStack.push(rNodeStack.top());
2465 rNodeStack.pop();
2468 SmSubSup eSub = bIsPrescript ? LSUB : RSUB;
2469 SmSubSup eSup = bIsPrescript ? LSUP : RSUP;
2471 for (sal_uLong i = 0; i < nCount; i += 2)
2473 SmSubSupNode *pNode = new SmSubSupNode(aToken);
2475 // initialize subnodes array
2476 SmNodeArray aSubNodes(1 + SUBSUP_NUM_ENTRIES);
2478 /*On each loop the base and its sub sup pair becomes the
2479 base for the next loop to which the next sub sup pair is
2480 attached, i.e. wheels within wheels*/
2481 aSubNodes[0] = lcl_popOrZero(aReverseStack);
2483 SmNode *pScriptNode = lcl_popOrZero(aReverseStack);
2485 if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) ||
2486 (!pScriptNode->GetToken().aText.isEmpty())))
2487 aSubNodes[eSub+1] = pScriptNode;
2488 pScriptNode = lcl_popOrZero(aReverseStack);
2489 if (pScriptNode && ((pScriptNode->GetToken().eType != TIDENT) ||
2490 (!pScriptNode->GetToken().aText.isEmpty())))
2491 aSubNodes[eSup+1] = pScriptNode;
2493 pNode->SetSubNodes(aSubNodes);
2494 aReverseStack.push(pNode);
2496 rNodeStack.push(lcl_popOrZero(aReverseStack));
2498 else
2500 // Ignore odd number of elements.
2501 for (sal_uLong i = 0; i < nCount; i++)
2503 delete rNodeStack.top();
2504 rNodeStack.pop();
2510 void SmXMLTableContext_Impl::EndElement()
2512 SmNodeArray aExpressionArray;
2513 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2514 SmNodeStack aReverseStack;
2515 aExpressionArray.resize(rNodeStack.size()-nElementCount);
2517 sal_uLong nRows = rNodeStack.size()-nElementCount;
2518 sal_uInt16 nCols = 0;
2520 SmStructureNode *pArray;
2521 for (sal_uLong i=nRows;i > 0;i--)
2523 pArray = (SmStructureNode *)rNodeStack.top();
2524 rNodeStack.pop();
2525 if (pArray->GetNumSubNodes() == 0)
2527 //This is a little tricky, it is possible that there was
2528 //be elements that were not inside a <mtd> pair, in which
2529 //case they will not be in a row, i.e. they will not have
2530 //SubNodes, so we have to wait until here before we can
2531 //resolve the situation. Implicitsurrounding tags are
2532 //surprisingly difficult to get right within this
2533 //architecture
2535 SmNodeArray aRelationArray;
2536 aRelationArray.resize(1);
2537 aRelationArray[0] = pArray;
2538 SmToken aDummy;
2539 pArray = new SmExpressionNode(aDummy);
2540 pArray->SetSubNodes(aRelationArray);
2543 if (pArray->GetNumSubNodes() > nCols)
2544 nCols = pArray->GetNumSubNodes();
2545 aReverseStack.push(pArray);
2547 aExpressionArray.resize(nCols*nRows);
2548 sal_uLong j=0;
2549 while ( !aReverseStack.empty() )
2551 pArray = (SmStructureNode *)aReverseStack.top();
2552 aReverseStack.pop();
2553 for (sal_uInt16 i=0;i<pArray->GetNumSubNodes();i++)
2554 aExpressionArray[j++] = pArray->GetSubNode(i);
2557 SmToken aToken;
2558 aToken.cMathChar = '\0';
2559 aToken.nGroup = TRGROUP;
2560 aToken.nLevel = 0;
2561 aToken.eType = TMATRIX;
2562 SmMatrixNode *pSNode = new SmMatrixNode(aToken);
2563 pSNode->SetSubNodes(aExpressionArray);
2564 pSNode->SetRowCol(static_cast<sal_uInt16>(nRows),nCols);
2565 rNodeStack.push(pSNode);
2568 SvXMLImportContext *SmXMLTableRowContext_Impl::CreateChildContext(
2569 sal_uInt16 nPrefix,
2570 const OUString& rLocalName,
2571 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2573 SvXMLImportContext* pContext = 0L;
2575 const SvXMLTokenMap& rTokenMap = GetSmImport().
2576 GetPresTableElemTokenMap();
2577 switch(rTokenMap.Get(nPrefix, rLocalName))
2579 case XML_TOK_MTD:
2580 pContext = GetSmImport().CreateTableCellContext(nPrefix,
2581 rLocalName, xAttrList);
2582 break;
2583 default:
2584 pContext = SmXMLRowContext_Impl::CreateChildContext(nPrefix,
2585 rLocalName,xAttrList);
2586 break;
2588 return pContext;
2591 SvXMLImportContext *SmXMLTableContext_Impl::CreateChildContext(
2592 sal_uInt16 nPrefix,
2593 const OUString& rLocalName,
2594 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
2596 SvXMLImportContext* pContext = 0L;
2598 const SvXMLTokenMap& rTokenMap = GetSmImport().
2599 GetPresTableElemTokenMap();
2600 switch(rTokenMap.Get(nPrefix, rLocalName))
2602 case XML_TOK_MTR:
2603 pContext = GetSmImport().CreateTableRowContext(nPrefix,rLocalName,
2604 xAttrList);
2605 break;
2606 default:
2607 pContext = SmXMLTableRowContext_Impl::CreateChildContext(nPrefix,
2608 rLocalName,xAttrList);
2609 break;
2611 return pContext;
2614 void SmXMLMultiScriptsContext_Impl::EndElement()
2616 ProcessSubSupPairs(bHasPrescripts);
2619 void SmXMLActionContext_Impl::EndElement()
2621 /*For now we will just assume that the
2622 selected attribute is one, and then just display
2623 that expression alone, i.e. remove all expect the
2624 first pushed one*/
2626 SmNodeStack &rNodeStack = GetSmImport().GetNodeStack();
2627 for (sal_uLong i=rNodeStack.size()-nElementCount;i > 1;i--)
2629 delete rNodeStack.top();
2630 rNodeStack.pop();
2634 SvXMLImportContext *SmXMLImport::CreateContext(sal_uInt16 nPrefix,
2635 const OUString &rLocalName,
2636 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2638 if ( XML_NAMESPACE_OFFICE == nPrefix )
2640 if ( (IsXMLToken(rLocalName, XML_DOCUMENT) ||
2641 IsXMLToken(rLocalName, XML_DOCUMENT_META)))
2643 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
2644 GetModel(), uno::UNO_QUERY_THROW);
2645 return IsXMLToken(rLocalName, XML_DOCUMENT_META)
2646 ? new SvXMLMetaDocumentContext(*this,
2647 XML_NAMESPACE_OFFICE, rLocalName,
2648 xDPS->getDocumentProperties())
2649 // flat OpenDocument file format -- this has not been tested...
2650 : new SmXMLFlatDocContext_Impl( *this, nPrefix, rLocalName,
2651 xDPS->getDocumentProperties());
2653 else
2655 return new SmXMLOfficeContext_Impl( *this,nPrefix,rLocalName);
2658 else
2659 return new SmXMLDocContext_Impl(*this,nPrefix,rLocalName);
2662 SvXMLImportContext *SmXMLImport::CreateRowContext(sal_uInt16 nPrefix,
2663 const OUString &rLocalName,
2664 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2666 return new SmXMLRowContext_Impl(*this,nPrefix,rLocalName);
2669 SvXMLImportContext *SmXMLImport::CreateTextContext(sal_uInt16 nPrefix,
2670 const OUString &rLocalName,
2671 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2673 return new SmXMLTextContext_Impl(*this,nPrefix,rLocalName);
2676 SvXMLImportContext *SmXMLImport::CreateAnnotationContext(sal_uInt16 nPrefix,
2677 const OUString &rLocalName,
2678 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2680 return new SmXMLAnnotationContext_Impl(*this,nPrefix,rLocalName);
2683 SvXMLImportContext *SmXMLImport::CreateStringContext(sal_uInt16 nPrefix,
2684 const OUString &rLocalName,
2685 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2687 return new SmXMLStringContext_Impl(*this,nPrefix,rLocalName);
2690 SvXMLImportContext *SmXMLImport::CreateNumberContext(sal_uInt16 nPrefix,
2691 const OUString &rLocalName,
2692 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2694 return new SmXMLNumberContext_Impl(*this,nPrefix,rLocalName);
2697 SvXMLImportContext *SmXMLImport::CreateIdentifierContext(sal_uInt16 nPrefix,
2698 const OUString &rLocalName,
2699 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2701 return new SmXMLIdentifierContext_Impl(*this,nPrefix,rLocalName);
2704 SvXMLImportContext *SmXMLImport::CreateOperatorContext(sal_uInt16 nPrefix,
2705 const OUString &rLocalName,
2706 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2708 return new SmXMLOperatorContext_Impl(*this,nPrefix,rLocalName);
2711 SvXMLImportContext *SmXMLImport::CreateSpaceContext(sal_uInt16 nPrefix,
2712 const OUString &rLocalName,
2713 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2715 return new SmXMLSpaceContext_Impl(*this,nPrefix,rLocalName);
2719 SvXMLImportContext *SmXMLImport::CreateFracContext(sal_uInt16 nPrefix,
2720 const OUString &rLocalName,
2721 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2723 return new SmXMLFracContext_Impl(*this,nPrefix,rLocalName);
2726 SvXMLImportContext *SmXMLImport::CreateSqrtContext(sal_uInt16 nPrefix,
2727 const OUString &rLocalName,
2728 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2730 return new SmXMLSqrtContext_Impl(*this,nPrefix,rLocalName);
2733 SvXMLImportContext *SmXMLImport::CreateRootContext(sal_uInt16 nPrefix,
2734 const OUString &rLocalName,
2735 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2737 return new SmXMLRootContext_Impl(*this,nPrefix,rLocalName);
2740 SvXMLImportContext *SmXMLImport::CreateStyleContext(sal_uInt16 nPrefix,
2741 const OUString &rLocalName,
2742 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2744 return new SmXMLStyleContext_Impl(*this,nPrefix,rLocalName);
2747 SvXMLImportContext *SmXMLImport::CreatePaddedContext(sal_uInt16 nPrefix,
2748 const OUString &rLocalName,
2749 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2751 return new SmXMLPaddedContext_Impl(*this,nPrefix,rLocalName);
2754 SvXMLImportContext *SmXMLImport::CreatePhantomContext(sal_uInt16 nPrefix,
2755 const OUString &rLocalName,
2756 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2758 return new SmXMLPhantomContext_Impl(*this,nPrefix,rLocalName);
2761 SvXMLImportContext *SmXMLImport::CreateFencedContext(sal_uInt16 nPrefix,
2762 const OUString &rLocalName,
2763 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2765 return new SmXMLFencedContext_Impl(*this,nPrefix,rLocalName);
2768 SvXMLImportContext *SmXMLImport::CreateErrorContext(sal_uInt16 nPrefix,
2769 const OUString &rLocalName,
2770 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2772 return new SmXMLErrorContext_Impl(*this,nPrefix,rLocalName);
2775 SvXMLImportContext *SmXMLImport::CreateSubContext(sal_uInt16 nPrefix,
2776 const OUString &rLocalName,
2777 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2779 return new SmXMLSubContext_Impl(*this,nPrefix,rLocalName);
2782 SvXMLImportContext *SmXMLImport::CreateSubSupContext(sal_uInt16 nPrefix,
2783 const OUString &rLocalName,
2784 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2786 return new SmXMLSubSupContext_Impl(*this,nPrefix,rLocalName);
2789 SvXMLImportContext *SmXMLImport::CreateSupContext(sal_uInt16 nPrefix,
2790 const OUString &rLocalName,
2791 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2793 return new SmXMLSupContext_Impl(*this,nPrefix,rLocalName);
2796 SvXMLImportContext *SmXMLImport::CreateUnderContext(sal_uInt16 nPrefix,
2797 const OUString &rLocalName,
2798 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2800 return new SmXMLUnderContext_Impl(*this,nPrefix,rLocalName);
2803 SvXMLImportContext *SmXMLImport::CreateOverContext(sal_uInt16 nPrefix,
2804 const OUString &rLocalName,
2805 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2807 return new SmXMLOverContext_Impl(*this,nPrefix,rLocalName);
2810 SvXMLImportContext *SmXMLImport::CreateUnderOverContext(sal_uInt16 nPrefix,
2811 const OUString &rLocalName,
2812 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2814 return new SmXMLUnderOverContext_Impl(*this,nPrefix,rLocalName);
2817 SvXMLImportContext *SmXMLImport::CreateMultiScriptsContext(sal_uInt16 nPrefix,
2818 const OUString &rLocalName,
2819 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2821 return new SmXMLMultiScriptsContext_Impl(*this,nPrefix,rLocalName);
2824 SvXMLImportContext *SmXMLImport::CreateTableContext(sal_uInt16 nPrefix,
2825 const OUString &rLocalName,
2826 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2828 return new SmXMLTableContext_Impl(*this,nPrefix,rLocalName);
2830 SvXMLImportContext *SmXMLImport::CreateTableRowContext(sal_uInt16 nPrefix,
2831 const OUString &rLocalName,
2832 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2834 return new SmXMLTableRowContext_Impl(*this,nPrefix,rLocalName);
2836 SvXMLImportContext *SmXMLImport::CreateTableCellContext(sal_uInt16 nPrefix,
2837 const OUString &rLocalName,
2838 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2840 return new SmXMLTableCellContext_Impl(*this,nPrefix,rLocalName);
2843 SvXMLImportContext *SmXMLImport::CreateNoneContext(sal_uInt16 nPrefix,
2844 const OUString &rLocalName,
2845 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2847 return new SmXMLNoneContext_Impl(*this,nPrefix,rLocalName);
2850 SvXMLImportContext *SmXMLImport::CreatePrescriptsContext(sal_uInt16 nPrefix,
2851 const OUString &rLocalName,
2852 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2854 return new SmXMLPrescriptsContext_Impl(*this,nPrefix,rLocalName);
2857 SvXMLImportContext *SmXMLImport::CreateAlignGroupContext(sal_uInt16 nPrefix,
2858 const OUString &rLocalName,
2859 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2861 return new SmXMLAlignGroupContext_Impl(*this,nPrefix,rLocalName);
2864 SvXMLImportContext *SmXMLImport::CreateActionContext(sal_uInt16 nPrefix,
2865 const OUString &rLocalName,
2866 const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
2868 return new SmXMLActionContext_Impl(*this,nPrefix,rLocalName);
2871 SmXMLImport::~SmXMLImport() throw ()
2873 delete pPresLayoutElemTokenMap;
2874 delete pPresElemTokenMap;
2875 delete pPresScriptEmptyElemTokenMap;
2876 delete pPresTableElemTokenMap;
2877 delete pPresLayoutAttrTokenMap;
2878 delete pFencedAttrTokenMap;
2879 delete pColorTokenMap;
2880 delete pOperatorAttrTokenMap;
2881 delete pAnnotationAttrTokenMap;
2884 void SmXMLImport::SetViewSettings(const Sequence<PropertyValue>& aViewProps)
2886 uno::Reference <frame::XModel> xModel = GetModel();
2887 if ( !xModel.is() )
2888 return;
2890 uno::Reference <lang::XUnoTunnel> xTunnel;
2891 xTunnel = uno::Reference <lang::XUnoTunnel> (xModel,uno::UNO_QUERY);
2892 SmModel *pModel = reinterpret_cast<SmModel *>
2893 (xTunnel->getSomething(SmModel::getUnoTunnelId()));
2895 if ( !pModel )
2896 return;
2898 SmDocShell *pDocShell =
2899 static_cast<SmDocShell*>(pModel->GetObjectShell());
2900 if ( !pDocShell )
2901 return;
2903 Rectangle aRect( pDocShell->GetVisArea() );
2905 sal_Int32 nCount = aViewProps.getLength();
2906 const PropertyValue *pValue = aViewProps.getConstArray();
2908 long nTmp = 0;
2910 for (sal_Int32 i = 0; i < nCount ; i++)
2912 if (pValue->Name == "ViewAreaTop" )
2914 pValue->Value >>= nTmp;
2915 aRect.setY( nTmp );
2917 else if (pValue->Name == "ViewAreaLeft" )
2919 pValue->Value >>= nTmp;
2920 aRect.setX( nTmp );
2922 else if (pValue->Name == "ViewAreaWidth" )
2924 pValue->Value >>= nTmp;
2925 Size aSize( aRect.GetSize() );
2926 aSize.Width() = nTmp;
2927 aRect.SetSize( aSize );
2929 else if (pValue->Name == "ViewAreaHeight" )
2931 pValue->Value >>= nTmp;
2932 Size aSize( aRect.GetSize() );
2933 aSize.Height() = nTmp;
2934 aRect.SetSize( aSize );
2936 pValue++;
2939 pDocShell->SetVisArea ( aRect );
2942 void SmXMLImport::SetConfigurationSettings(const Sequence<PropertyValue>& aConfProps)
2944 uno::Reference < XPropertySet > xProps ( GetModel(), UNO_QUERY );
2945 if ( xProps.is() )
2947 Reference < XPropertySetInfo > xInfo ( xProps->getPropertySetInfo() );
2948 if (xInfo.is() )
2950 sal_Int32 nCount = aConfProps.getLength();
2951 const PropertyValue* pValues = aConfProps.getConstArray();
2953 const OUString sFormula ( "Formula" );
2954 const OUString sBasicLibraries ( "BasicLibraries" );
2955 const OUString sDialogLibraries ( "DialogLibraries" );
2956 while ( nCount-- )
2958 if (pValues->Name != sFormula &&
2959 pValues->Name != sBasicLibraries &&
2960 pValues->Name != sDialogLibraries)
2964 if ( xInfo->hasPropertyByName( pValues->Name ) )
2965 xProps->setPropertyValue( pValues->Name, pValues->Value );
2967 catch (const beans::PropertyVetoException &)
2969 // dealing with read-only properties here. Nothing to do...
2971 catch( Exception& )
2973 OSL_FAIL( "SmXMLImport::SetConfigurationSettings: Exception!" );
2977 pValues++;
2984 ////////////////////////////////////////////////////////////
2987 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */