1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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>
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"
85 ////////////////////////////////////////////////////////////
88 template < typename T
>
89 T
* lcl_popOrZero( ::std::stack
<T
*> & rStack
)
93 T
* pTmp
= rStack
.top();
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;
122 OSL_ENSURE( pDocShell
->GetMedium() == &rMedium
,
123 "different SfxMedium found" );
125 SfxItemSet
* pSet
= rMedium
.GetItemSet();
128 const SfxUnoAnyItem
* pItem
= static_cast<const SfxUnoAnyItem
*>(
129 pSet
->GetItem(SID_PROGRESS_STATUSBAR_CONTROL
) );
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
) ) );
159 OUString
sPropName( "BaseURI" );
160 xInfoSet
->setPropertyValue( sPropName
, makeAny( rMedium
.GetBaseURL() ) );
163 if ( !(rMedium
.IsStorage()))
166 sal_Int32
nProgressRange(nSteps
);
167 if (xStatusIndicator
.is())
169 xStatusIndicator
->start(SM_RESSTR(STR_STATSTR_READING
), nProgressRange
);
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",
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,
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" );
228 nError
= ERRCODE_IO_BROKENPACKAGE
;
231 nError
= ERRCODE_IO_BROKENPACKAGE
;
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();
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
;
271 Reference
< xml::sax::XParser
> xParser
= xml::sax::Parser::create(rxContext
);
273 Sequence
<Any
> aArgs( 1 );
274 aArgs
[0] <<= rPropSet
;
277 Reference
< xml::sax::XDocumentHandler
> xFilter(
278 rxContext
->getServiceManager()->createInstanceWithArgumentsAndContext(
279 OUString::createFromAscii(pFilterName
), aArgs
, rxContext
),
281 OSL_ENSURE( xFilter
.is(), "Can't instantiate filter component." );
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() )
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
;
315 xml::sax::SAXException aTmp
;
316 if ( aSaxEx
.WrappedException
>>= aTmp
)
319 bTryChild
= sal_False
;
322 packages::zip::ZipIOException aBrokenPackage
;
323 if ( aSaxEx
.WrappedException
>>= aBrokenPackage
)
324 return ERRCODE_IO_BROKENPACKAGE
;
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
;
336 nError
= ERRCODE_SFX_WRONGPASSWORD
;
338 catch( packages::zip::ZipIOException
& )
340 nError
= ERRCODE_IO_BROKENPACKAGE
;
342 catch( io::IOException
& )
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
);
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() )
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),
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()
448 const OUString
aServiceName( IMPORT_SVC_NAME
);
449 const uno::Sequence
< OUString
> aSeq( &aServiceName
, 1 );
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()
470 const OUString
aServiceName( IMPORT_SVC_NAME
);
471 const uno::Sequence
< OUString
> aSeq( &aServiceName
, 1 );
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()
492 const OUString
aServiceName( IMPORT_SVC_NAME
);
493 const uno::Sequence
< OUString
> aSeq( &aServiceName
, 1 );
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 ////////////////////////////////////////////////////////////
507 // override empty method from parent class
508 OUString SAL_CALL
SmXMLImport::getImplementationName()
509 throw(uno::RuntimeException
)
512 switch( getImportFlags() )
515 aTxt
= SmXMLImportMeta_getImplementationName();
517 case IMPORT_SETTINGS
:
518 aTxt
= SmXMLImportSettings_getImplementationName();
522 aTxt
= SmXMLImport_getImplementationName();
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
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()));
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();
575 rParser
.SetImportSymbolNames( bVal
);
577 pDocShell
->SetText( aText
);
579 OSL_ENSURE(pModel
,"So there *was* a uno problem after all");
584 SvXMLImport::endDocument();
587 ////////////////////////////////////////////////////////////
589 class SmXMLImportContext
: public SvXMLImportContext
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*/)
636 ////////////////////////////////////////////////////////////
638 struct SmXMLContext_Helper
643 sal_Bool bFontNodeNeeded
;
644 OUString sFontFamily
;
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
);
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
);
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
));
678 case XML_TOK_FONTSTYLE
:
679 nIsItalic
= sValue
.equals(GetXMLToken(XML_ITALIC
));
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('%'))
691 rContext
.GetSmImport().GetMM100UnitConverter().
692 SetXMLMeasureUnit(util::MeasureUnit::PERCENT
);
696 case XML_TOK_FONTFAMILY
:
697 sFontFamily
= sValue
;
707 if ((nOldIsBold
!=nIsBold
) || (nOldIsItalic
!=nIsItalic
) ||
708 (nOldFontSize
!=nFontSize
) || (sOldFontFamily
!=sFontFamily
)
709 || !sColor
.isEmpty())
710 bFontNodeNeeded
=sal_True
;
712 bFontNodeNeeded
=sal_False
;
715 void SmXMLContext_Helper::ApplyAttrs()
717 SmNodeStack
&rNodeStack
= rContext
.GetSmImport().GetNodeStack();
722 aToken
.cMathChar
= '\0';
729 aToken
.eType
= TBOLD
;
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
);
740 aToken
.eType
= TITALIC
;
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
),
760 pFontNode
->SetSizeParameter(Fraction(nFontSize
/100.00),
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
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
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
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
);
819 ////////////////////////////////////////////////////////////
821 /*avert thy gaze from the proginator*/
822 class SmXMLRowContext_Impl
: public SmXMLDocContext_Impl
825 sal_uLong nElementCount
;
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
);
842 ////////////////////////////////////////////////////////////
844 class SmXMLFracContext_Impl
: public SmXMLRowContext_Impl
847 SmXMLFracContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
848 const OUString
& rLName
)
849 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
854 ////////////////////////////////////////////////////////////
856 class SmXMLSqrtContext_Impl
: public SmXMLRowContext_Impl
859 SmXMLSqrtContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
860 const OUString
& rLName
)
861 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
866 ////////////////////////////////////////////////////////////
868 class SmXMLRootContext_Impl
: public SmXMLRowContext_Impl
871 SmXMLRootContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
872 const OUString
& rLName
)
873 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
878 ////////////////////////////////////////////////////////////
880 class SmXMLStyleContext_Impl
: public SmXMLRowContext_Impl
883 SmXMLContext_Helper aStyleHelper
;
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) {}
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
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
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
) {}
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
935 if (GetSmImport().GetNodeStack().size() - nElementCount
> 1)
936 SmXMLRowContext_Impl::EndElement();
939 ////////////////////////////////////////////////////////////
941 class SmXMLPhantomContext_Impl
: public SmXMLRowContext_Impl
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
) {}
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
959 if (GetSmImport().GetNodeStack().size() - nElementCount
> 1)
960 SmXMLRowContext_Impl::EndElement();
963 aToken
.cMathChar
= '\0';
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
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
);
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)
1017 /*Go to superclass*/
1024 void SmXMLFencedContext_Impl::EndElement()
1027 aToken
.cMathChar
= '\0';
1030 aToken
.eType
= TLEFT
;
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';
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();
1057 if (i
> 1 && rNodeStack
.size() > 1)
1058 aRelationArray
[--i
] = new SmGlyphSpecialNode(aToken
);
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
1077 SmXMLErrorContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1078 const OUString
& rLName
)
1079 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
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();
1101 ////////////////////////////////////////////////////////////
1103 class SmXMLNumberContext_Impl
: public SmXMLImportContext
1109 SmXMLNumberContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1110 const OUString
& rLName
)
1111 : SmXMLImportContext(rImport
,nPrefix
,rLName
)
1113 aToken
.cMathChar
= '\0';
1116 aToken
.eType
= TNUMBER
;
1119 virtual void TCharacters(const OUString
&rChars
);
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
;
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";
1175 void SmXMLAnnotationContext_Impl::Characters(const OUString
&rChars
)
1178 GetSmImport().GetText().Append(String(rChars
));
1181 ////////////////////////////////////////////////////////////
1183 class SmXMLTextContext_Impl
: public SmXMLImportContext
1189 SmXMLTextContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1190 const OUString
& rLName
)
1191 : SmXMLImportContext(rImport
,nPrefix
,rLName
)
1193 aToken
.cMathChar
= '\0';
1196 aToken
.eType
= TTEXT
;
1199 virtual void TCharacters(const OUString
&rChars
);
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
1222 SmXMLStringContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1223 const OUString
& rLName
)
1224 : SmXMLImportContext(rImport
,nPrefix
,rLName
)
1226 aToken
.cMathChar
= '\0';
1229 aToken
.eType
= TTEXT
;
1232 virtual void TCharacters(const OUString
&rChars
);
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
1262 SmXMLContext_Helper aStyleHelper
;
1266 SmXMLIdentifierContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1267 const OUString
& rLName
)
1268 : SmXMLImportContext(rImport
,nPrefix
,rLName
),aStyleHelper(*this)
1270 aToken
.cMathChar
= '\0';
1273 aToken
.eType
= TIDENT
;
1276 void TCharacters(const OUString
&rChars
);
1277 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
1279 aStyleHelper
.RetrieveAttrs(xAttrList
);
1284 void SmXMLIdentifierContext_Impl::EndElement()
1286 SmTextNode
*pNode
= 0;
1287 //we will handle identifier italic/normal here instead of with a standalone
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;
1297 pNode
= new SmTextNode(aToken
,FNT_VARIABLE
);
1298 if (aStyleHelper
.bFontNodeNeeded
&& aStyleHelper
.nIsItalic
!= -1)
1300 if (aStyleHelper
.nIsItalic
)
1301 pNode
->GetFont().SetItalic(ITALIC_NORMAL
);
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
;
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
;
1332 SmXMLOperatorContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1333 const OUString
& rLName
)
1334 : SmXMLImportContext(rImport
,nPrefix
,rLName
), bIsStretchy(sal_False
)
1337 aToken
.eType
= TSPECIAL
;
1341 void TCharacters(const OUString
&rChars
);
1342 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
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
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
));
1391 ////////////////////////////////////////////////////////////
1393 class SmXMLSpaceContext_Impl
: public SmXMLImportContext
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*/ )
1407 aToken
.cMathChar
= '\0';
1409 aToken
.eType
= TBLANK
;
1411 SmBlankNode
*pBlank
= new SmBlankNode(aToken
);
1412 pBlank
->IncreaseBy(aToken
);
1413 GetSmImport().GetNodeStack().push(pBlank
);
1416 ////////////////////////////////////////////////////////////
1418 class SmXMLSubContext_Impl
: public SmXMLRowContext_Impl
1421 void GenericEndElement(SmTokenType eType
,SmSubSup aSubSup
);
1424 SmXMLSubContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1425 const OUString
& rLName
)
1426 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
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" );
1444 aToken
.cMathChar
= '\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
1468 SmXMLSupContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1469 const OUString
& rLName
)
1470 : SmXMLSubContext_Impl(rImport
,nPrefix
,rLName
) {}
1474 GenericEndElement(TRSUP
,RSUP
);
1478 ////////////////////////////////////////////////////////////
1480 class SmXMLSubSupContext_Impl
: public SmXMLRowContext_Impl
1483 void GenericEndElement(SmTokenType eType
, SmSubSup aSub
,SmSubSup aSup
);
1486 SmXMLSubSupContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1487 const OUString
& rLName
)
1488 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
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" );
1506 aToken
.cMathChar
= '\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
1531 sal_Int16 nAttrCount
;
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
);
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" );
1556 /*Just one special case for the underline thing*/
1557 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1558 SmNode
*pTest
= lcl_popOrZero(rNodeStack
);
1560 aToken
.cMathChar
= '\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
);
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()
1588 GenericEndElement(TCSUB
,CSUB
);
1593 ////////////////////////////////////////////////////////////
1595 class SmXMLOverContext_Impl
: public SmXMLSubContext_Impl
1598 sal_Int16 nAttrCount
;
1601 SmXMLOverContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1602 const OUString
& rLName
)
1603 : SmXMLSubContext_Impl(rImport
,nPrefix
,rLName
), nAttrCount(0) {}
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()
1621 GenericEndElement(TCSUP
,CSUP
);
1627 void SmXMLOverContext_Impl::HandleAccent()
1629 const bool bNodeCheck
= GetSmImport().GetNodeStack().size() - nElementCount
== 2;
1630 OSL_ENSURE (bNodeCheck
, "Sub has not two arguments");
1635 aToken
.cMathChar
= '\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
1658 SmXMLUnderOverContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1659 const OUString
& rLName
)
1660 : SmXMLSubSupContext_Impl(rImport
,nPrefix
,rLName
) {}
1664 GenericEndElement(TCSUB
,CSUB
,CSUP
);
1668 ////////////////////////////////////////////////////////////
1670 class SmXMLMultiScriptsContext_Impl
: public SmXMLSubSupContext_Impl
1672 bool bHasPrescripts
;
1674 void ProcessSubSupPairs(bool bIsPrescript
);
1677 SmXMLMultiScriptsContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1678 const OUString
& rLName
) :
1679 SmXMLSubSupContext_Impl(rImport
,nPrefix
,rLName
),
1680 bHasPrescripts(false) {}
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
1693 SmXMLNoneContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1694 const OUString
& rLName
)
1695 : SmXMLImportContext(rImport
,nPrefix
,rLName
) {}
1701 void SmXMLNoneContext_Impl::EndElement(void)
1704 aToken
.cMathChar
= '\0';
1708 aToken
.eType
= TIDENT
;
1709 GetSmImport().GetNodeStack().push(
1710 new SmTextNode(aToken
,FNT_VARIABLE
));
1713 ////////////////////////////////////////////////////////////
1715 class SmXMLPrescriptsContext_Impl
: public SmXMLImportContext
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
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
1744 SmXMLTableContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1745 const OUString
& rLName
) :
1746 SmXMLTableRowContext_Impl(rImport
,nPrefix
,rLName
)
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
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
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*/
1783 ////////////////////////////////////////////////////////////
1785 class SmXMLActionContext_Impl
: public SmXMLRowContext_Impl
1788 SmXMLActionContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1789 const OUString
& rLName
) :
1790 SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
)
1796 ////////////////////////////////////////////////////////////
1798 // NB: virtually inherit so we can multiply inherit properly
1799 // in SmXMLFlatDocContext_Impl
1800 class SmXMLOfficeContext_Impl
: public virtual SvXMLImportContext
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
,
1828 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
1833 ////////////////////////////////////////////////////////////
1835 // context for flat file xml format
1836 class SmXMLFlatDocContext_Impl
1837 : public SmXMLOfficeContext_Impl
, public SvXMLMetaDocumentContext
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
,
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
);
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
},
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
},
1918 static SvXMLTokenMapEntry aFencedAttrTokenMap
[] =
1920 { XML_NAMESPACE_MATH
, XML_OPEN
, XML_TOK_OPEN
},
1921 { XML_NAMESPACE_MATH
, XML_CLOSE
, XML_TOK_CLOSE
},
1925 static SvXMLTokenMapEntry aOperatorAttrTokenMap
[] =
1927 { XML_NAMESPACE_MATH
, XML_STRETCHY
, XML_TOK_STRETCHY
},
1931 static SvXMLTokenMapEntry aAnnotationAttrTokenMap
[] =
1933 { XML_NAMESPACE_MATH
, XML_ENCODING
, XML_TOK_ENCODING
},
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
},
1951 static SvXMLTokenMapEntry aPresScriptEmptyElemTokenMap
[] =
1953 { XML_NAMESPACE_MATH
, XML_MPRESCRIPTS
, XML_TOK_MPRESCRIPTS
},
1954 { XML_NAMESPACE_MATH
, XML_NONE
, XML_TOK_NONE
},
1958 static SvXMLTokenMapEntry aPresTableElemTokenMap
[] =
1960 { XML_NAMESPACE_MATH
, XML_MTR
, XML_TOK_MTR
},
1961 { XML_NAMESPACE_MATH
, XML_MTD
, XML_TOK_MTD
},
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
},
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(
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
,
2064 /*General Layout Schemata*/
2066 pContext
= GetSmImport().CreateRowContext(nPrefix
,rLocalName
,
2070 pContext
= GetSmImport().CreateFracContext(nPrefix
,rLocalName
,
2074 pContext
= GetSmImport().CreateSqrtContext(nPrefix
,rLocalName
,
2078 pContext
= GetSmImport().CreateRootContext(nPrefix
,rLocalName
,
2081 case XML_TOK_MSTYLE
:
2082 pContext
= GetSmImport().CreateStyleContext(nPrefix
,rLocalName
,
2085 case XML_TOK_MERROR
:
2086 pContext
= GetSmImport().CreateErrorContext(nPrefix
,rLocalName
,
2089 case XML_TOK_MPADDED
:
2090 pContext
= GetSmImport().CreatePaddedContext(nPrefix
,rLocalName
,
2093 case XML_TOK_MPHANTOM
:
2094 pContext
= GetSmImport().CreatePhantomContext(nPrefix
,rLocalName
,
2097 case XML_TOK_MFENCED
:
2098 pContext
= GetSmImport().CreateFencedContext(nPrefix
,rLocalName
,
2101 /*Script and Limit Schemata*/
2103 pContext
= GetSmImport().CreateSubContext(nPrefix
,rLocalName
,
2107 pContext
= GetSmImport().CreateSupContext(nPrefix
,rLocalName
,
2110 case XML_TOK_MSUBSUP
:
2111 pContext
= GetSmImport().CreateSubSupContext(nPrefix
,rLocalName
,
2114 case XML_TOK_MUNDER
:
2115 pContext
= GetSmImport().CreateUnderContext(nPrefix
,rLocalName
,
2119 pContext
= GetSmImport().CreateOverContext(nPrefix
,rLocalName
,
2122 case XML_TOK_MUNDEROVER
:
2123 pContext
= GetSmImport().CreateUnderOverContext(nPrefix
,rLocalName
,
2126 case XML_TOK_MMULTISCRIPTS
:
2127 pContext
= GetSmImport().CreateMultiScriptsContext(nPrefix
,
2128 rLocalName
, xAttrList
);
2130 case XML_TOK_MTABLE
:
2131 pContext
= GetSmImport().CreateTableContext(nPrefix
,
2132 rLocalName
, xAttrList
);
2134 case XML_TOK_MACTION
:
2135 pContext
= GetSmImport().CreateActionContext(nPrefix
,
2136 rLocalName
, xAttrList
);
2139 /*Basically theres an implicit mrow around certain bare
2140 *elements, use a RowContext to see if this is one of
2142 SmXMLRowContext_Impl
aTempContext(GetSmImport(),nPrefix
,
2143 GetXMLToken(XML_MROW
));
2145 pContext
= aTempContext
.StrictCreateChildContext(nPrefix
,
2146 rLocalName
, xAttrList
);
2152 void SmXMLDocContext_Impl::EndElement()
2154 SmNodeArray ContextArray
;
2155 ContextArray
.resize(1);
2156 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2158 ContextArray
[0] = lcl_popOrZero(rNodeStack
);
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();
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" );
2187 aToken
.cMathChar
= '\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");
2208 aToken
.cMathChar
= MS_SQRT
; //Temporary: alert, based on StarSymbol font
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
2228 if (GetSmImport().GetNodeStack().size() - nElementCount
> 1)
2229 SmXMLRowContext_Impl::EndElement();
2232 aToken
.cMathChar
= MS_SQRT
; //Temporary: alert, based on StarSymbol font
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();
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
)))
2270 aToken
.cMathChar
= '\0';
2274 int nLeft
=0,nRight
=0;
2275 if ((aRelationArray
[0]->GetScaleMode() == SCALE_HEIGHT
)
2276 && (aRelationArray
[0]->GetType() == NMATH
))
2278 aToken
= aRelationArray
[0]->GetToken();
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();
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
];
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
);
2321 else //Multiple newlines result in empty row elements
2323 aRelationArray
.resize(1);
2325 aToken
.cMathChar
= '\0';
2328 aToken
.eType
= TNEWLINE
;
2329 aRelationArray
[0] = new SmLineNode(aToken
);
2333 SmStructureNode
*pSNode
= new SmExpressionNode(aDummy
);
2334 pSNode
->SetSubNodes(aRelationArray
);
2335 rNodeStack
.push(pSNode
);
2339 SvXMLImportContext
*SmXMLRowContext_Impl::StrictCreateChildContext(
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*/
2351 pContext
= GetSmImport().CreateNumberContext(nPrefix
,rLocalName
,
2355 pContext
= GetSmImport().CreateIdentifierContext(nPrefix
,rLocalName
,
2359 pContext
= GetSmImport().CreateOperatorContext(nPrefix
,rLocalName
,
2363 pContext
= GetSmImport().CreateTextContext(nPrefix
,rLocalName
,
2366 case XML_TOK_MSPACE
:
2367 pContext
= GetSmImport().CreateSpaceContext(nPrefix
,rLocalName
,
2371 pContext
= GetSmImport().CreateStringContext(nPrefix
,rLocalName
,
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
,
2382 case XML_TOK_ANNOTATION
:
2383 pContext
= GetSmImport().CreateAnnotationContext(nPrefix
,rLocalName
,
2394 SvXMLImportContext
*SmXMLRowContext_Impl::CreateChildContext(
2396 const OUString
& rLocalName
,
2397 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
2399 SvXMLImportContext
* pContext
= StrictCreateChildContext(nPrefix
,
2400 rLocalName
, xAttrList
);
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
);
2413 SvXMLImportContext
*SmXMLMultiScriptsContext_Impl::CreateChildContext(
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
);
2431 pContext
= GetSmImport().CreateNoneContext(nPrefix
,rLocalName
,
2435 pContext
= SmXMLRowContext_Impl::CreateChildContext(nPrefix
,
2436 rLocalName
,xAttrList
);
2442 void SmXMLMultiScriptsContext_Impl::ProcessSubSupPairs(bool bIsPrescript
)
2444 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2446 if (rNodeStack
.size() <= nElementCount
)
2449 sal_uLong nCount
= rNodeStack
.size() - nElementCount
- 1;
2453 if (nCount
% 2 == 0)
2456 aToken
.cMathChar
= '\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());
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
));
2500 // Ignore odd number of elements.
2501 for (sal_uLong i
= 0; i
< nCount
; i
++)
2503 delete rNodeStack
.top();
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();
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
2535 SmNodeArray aRelationArray
;
2536 aRelationArray
.resize(1);
2537 aRelationArray
[0] = pArray
;
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
);
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
);
2558 aToken
.cMathChar
= '\0';
2559 aToken
.nGroup
= TRGROUP
;
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(
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
))
2580 pContext
= GetSmImport().CreateTableCellContext(nPrefix
,
2581 rLocalName
, xAttrList
);
2584 pContext
= SmXMLRowContext_Impl::CreateChildContext(nPrefix
,
2585 rLocalName
,xAttrList
);
2591 SvXMLImportContext
*SmXMLTableContext_Impl::CreateChildContext(
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
))
2603 pContext
= GetSmImport().CreateTableRowContext(nPrefix
,rLocalName
,
2607 pContext
= SmXMLTableRowContext_Impl::CreateChildContext(nPrefix
,
2608 rLocalName
,xAttrList
);
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
2626 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2627 for (sal_uLong i
=rNodeStack
.size()-nElementCount
;i
> 1;i
--)
2629 delete rNodeStack
.top();
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());
2655 return new SmXMLOfficeContext_Impl( *this,nPrefix
,rLocalName
);
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();
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()));
2898 SmDocShell
*pDocShell
=
2899 static_cast<SmDocShell
*>(pModel
->GetObjectShell());
2903 Rectangle
aRect( pDocShell
->GetVisArea() );
2905 sal_Int32 nCount
= aViewProps
.getLength();
2906 const PropertyValue
*pValue
= aViewProps
.getConstArray();
2910 for (sal_Int32 i
= 0; i
< nCount
; i
++)
2912 if (pValue
->Name
== "ViewAreaTop" )
2914 pValue
->Value
>>= nTmp
;
2917 else if (pValue
->Name
== "ViewAreaLeft" )
2919 pValue
->Value
>>= 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
);
2939 pDocShell
->SetVisArea ( aRect
);
2942 void SmXMLImport::SetConfigurationSettings(const Sequence
<PropertyValue
>& aConfProps
)
2944 uno::Reference
< XPropertySet
> xProps ( GetModel(), UNO_QUERY
);
2947 Reference
< XPropertySetInfo
> xInfo ( xProps
->getPropertySetInfo() );
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" );
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...
2973 OSL_FAIL( "SmXMLImport::SetConfigurationSettings: Exception!" );
2984 ////////////////////////////////////////////////////////////
2987 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */