1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_starmath.hxx"
31 /*todo: Change characters and tcharacters to accumulate the characters together
32 into one string, xml parser hands them to us line by line rather than all in
35 #include <com/sun/star/xml/sax/XErrorHandler.hpp>
36 #include <com/sun/star/xml/sax/XEntityResolver.hpp>
37 #include <com/sun/star/xml/sax/InputSource.hpp>
38 #include <com/sun/star/xml/sax/XDTDHandler.hpp>
39 #include <com/sun/star/xml/sax/XParser.hpp>
40 #include <com/sun/star/io/XActiveDataSource.hpp>
41 #include <com/sun/star/io/XActiveDataControl.hpp>
42 #include <com/sun/star/document/XDocumentProperties.hpp>
43 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
44 #include <com/sun/star/packages/zip/ZipIOException.hpp>
45 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
46 #include <com/sun/star/beans/PropertyAttribute.hpp>
47 #include <com/sun/star/container/XNameAccess.hpp>
48 #include <com/sun/star/embed/ElementModes.hpp>
49 #include <com/sun/star/uno/Any.h>
51 #include <rtl/math.hxx>
52 #include <sfx2/frame.hxx>
53 #include <sfx2/docfile.hxx>
54 #include <tools/debug.hxx>
55 #include <tools/urlobj.hxx>
56 #include <svtools/sfxecode.hxx>
57 #include <unotools/saveopt.hxx>
58 #include <svl/stritem.hxx>
59 #include <svl/itemprop.hxx>
60 #include <unotools/processfactory.hxx>
61 #include <unotools/streamwrap.hxx>
62 #include <xmloff/xmlnmspe.hxx>
63 #include <xmloff/xmltoken.hxx>
64 #include <xmloff/nmspmap.hxx>
65 #include <xmloff/attrlist.hxx>
66 #include <xmloff/xmluconv.hxx>
67 #include <xmloff/xmlmetai.hxx>
68 #include <osl/mutex.hxx>
69 #include <comphelper/genericpropertyset.hxx>
73 #include "mathmlimport.hxx"
74 #include <starmath.hrc>
75 #include <unomodel.hxx>
76 #include <document.hxx>
77 #include <utility.hxx>
79 using namespace ::com::sun::star::beans
;
80 using namespace ::com::sun::star::container
;
81 using namespace ::com::sun::star::document
;
82 using namespace ::com::sun::star::lang
;
83 using namespace ::com::sun::star::uno
;
84 using namespace ::com::sun::star
;
85 using namespace ::xmloff::token
;
87 using ::rtl::OUString
;
88 using ::rtl::OUStringBuffer
;
90 #define IMPORT_SVC_NAME RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.XMLImportFilter")
94 ////////////////////////////////////////////////////////////
96 sal_uLong
SmXMLImportWrapper::Import(SfxMedium
&rMedium
)
98 sal_uLong nError
= ERRCODE_SFX_DOLOADFAILED
;
100 uno::Reference
<lang::XMultiServiceFactory
> xServiceFactory(
101 utl::getProcessServiceFactory());
102 DBG_ASSERT(xServiceFactory
.is(), "XMLReader::Read: got no service manager");
103 if ( !xServiceFactory
.is() )
106 //Make a model component from our SmModel
107 uno::Reference
< lang::XComponent
> xModelComp( xModel
, uno::UNO_QUERY
);
108 DBG_ASSERT( xModelComp
.is(), "XMLReader::Read: got no model" );
110 // try to get an XStatusIndicator from the Medium
111 uno::Reference
<task::XStatusIndicator
> xStatusIndicator
;
113 sal_Bool bEmbedded
= sal_False
;
114 uno::Reference
<lang::XUnoTunnel
> xTunnel
;
115 xTunnel
= uno::Reference
<lang::XUnoTunnel
> (xModel
,uno::UNO_QUERY
);
116 SmModel
*pModel
= reinterpret_cast<SmModel
*>
117 (xTunnel
->getSomething(SmModel::getUnoTunnelId()));
119 SmDocShell
*pDocShell
= pModel
?
120 static_cast<SmDocShell
*>(pModel
->GetObjectShell()) : 0;
123 // if (pDocShell->GetMedium())
125 DBG_ASSERT( pDocShell
->GetMedium() == &rMedium
,
126 "different SfxMedium found" );
128 SfxItemSet
* pSet
= rMedium
.GetItemSet();
131 const SfxUnoAnyItem
* pItem
= static_cast<const SfxUnoAnyItem
*>(
132 pSet
->GetItem(SID_PROGRESS_STATUSBAR_CONTROL
) );
134 pItem
->GetValue() >>= xStatusIndicator
;
138 if ( SFX_CREATE_MODE_EMBEDDED
== pDocShell
->GetCreateMode() )
139 bEmbedded
= sal_True
;
142 comphelper::PropertyMapEntry aInfoMap
[] =
144 { "PrivateData", sizeof("PrivateData")-1, 0,
145 &::getCppuType( (Reference
<XInterface
> *)0 ),
146 beans::PropertyAttribute::MAYBEVOID
, 0 },
147 { "BaseURI", sizeof("BaseURI")-1, 0,
148 &::getCppuType( (OUString
*)0 ),
149 beans::PropertyAttribute::MAYBEVOID
, 0 },
150 { "StreamRelPath", sizeof("StreamRelPath")-1, 0,
151 &::getCppuType( (OUString
*)0 ),
152 beans::PropertyAttribute::MAYBEVOID
, 0 },
153 { "StreamName", sizeof("StreamName")-1, 0,
154 &::getCppuType( (OUString
*)0 ),
155 beans::PropertyAttribute::MAYBEVOID
, 0 },
156 { NULL
, 0, 0, NULL
, 0, 0 }
158 uno::Reference
< beans::XPropertySet
> xInfoSet(
159 comphelper::GenericPropertySet_CreateInstance(
160 new comphelper::PropertySetInfo( aInfoMap
) ) );
163 OUString
sPropName( RTL_CONSTASCII_USTRINGPARAM("BaseURI") );
164 xInfoSet
->setPropertyValue( sPropName
, makeAny( rMedium
.GetBaseURL() ) );
167 if ( !(rMedium
.IsStorage()))
170 sal_Int32
nProgressRange(nSteps
);
171 if (xStatusIndicator
.is())
173 xStatusIndicator
->start(String(SmResId(STR_STATSTR_READING
)),
178 if (xStatusIndicator
.is())
179 xStatusIndicator
->setValue(nSteps
++);
181 if ( rMedium
.IsStorage())
183 // TODO/LATER: handle the case of embedded links gracefully
184 if ( bEmbedded
) // && !rMedium.GetStorage()->IsRoot() )
186 OUString
aName( RTL_CONSTASCII_USTRINGPARAM( "dummyObjName" ) );
187 if ( rMedium
.GetItemSet() )
189 const SfxStringItem
* pDocHierarchItem
= static_cast<const SfxStringItem
*>(
190 rMedium
.GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME
) );
191 if ( pDocHierarchItem
)
192 aName
= pDocHierarchItem
->GetValue();
195 if ( aName
.getLength() )
197 sPropName
= OUString(RTL_CONSTASCII_USTRINGPARAM("StreamRelPath"));
198 xInfoSet
->setPropertyValue( sPropName
, makeAny( aName
) );
202 sal_Bool bOASIS
= ( SotStorage::GetVersion( rMedium
.GetStorage() ) > SOFFICE_FILEFORMAT_60
);
203 if (xStatusIndicator
.is())
204 xStatusIndicator
->setValue(nSteps
++);
206 sal_uLong nWarn
= ReadThroughComponent(
207 rMedium
.GetStorage(), xModelComp
, "meta.xml", "Meta.xml",
208 xServiceFactory
, xInfoSet
,
209 (bOASIS
? "com.sun.star.comp.Math.XMLOasisMetaImporter"
210 : "com.sun.star.comp.Math.XMLMetaImporter") );
212 if ( nWarn
!= ERRCODE_IO_BROKENPACKAGE
)
214 if (xStatusIndicator
.is())
215 xStatusIndicator
->setValue(nSteps
++);
217 nWarn
= ReadThroughComponent(
218 rMedium
.GetStorage(), xModelComp
, "settings.xml", 0,
219 xServiceFactory
, xInfoSet
,
220 (bOASIS
? "com.sun.star.comp.Math.XMLOasisSettingsImporter"
221 : "com.sun.star.comp.Math.XMLSettingsImporter" ) );
223 if ( nWarn
!= ERRCODE_IO_BROKENPACKAGE
)
225 if (xStatusIndicator
.is())
226 xStatusIndicator
->setValue(nSteps
++);
228 nError
= ReadThroughComponent(
229 rMedium
.GetStorage(), xModelComp
, "content.xml", "Content.xml",
230 xServiceFactory
, xInfoSet
, "com.sun.star.comp.Math.XMLImporter" );
233 nError
= ERRCODE_IO_BROKENPACKAGE
;
236 nError
= ERRCODE_IO_BROKENPACKAGE
;
240 Reference
<io::XInputStream
> xInputStream
=
241 new utl::OInputStreamWrapper(rMedium
.GetInStream());
243 if (xStatusIndicator
.is())
244 xStatusIndicator
->setValue(nSteps
++);
246 nError
= ReadThroughComponent( xInputStream
, xModelComp
,
247 xServiceFactory
, xInfoSet
, "com.sun.star.comp.Math.XMLImporter", sal_False
);
250 if (xStatusIndicator
.is())
251 xStatusIndicator
->end();
256 /// read a component (file + filter version)
257 sal_uLong
SmXMLImportWrapper::ReadThroughComponent(
258 Reference
<io::XInputStream
> xInputStream
,
259 Reference
<XComponent
> xModelComponent
,
260 Reference
<lang::XMultiServiceFactory
> & rFactory
,
261 Reference
<beans::XPropertySet
> & rPropSet
,
262 const sal_Char
* pFilterName
,
263 sal_Bool bEncrypted
)
265 sal_uLong nError
= ERRCODE_SFX_DOLOADFAILED
;
266 DBG_ASSERT(xInputStream
.is(), "input stream missing");
267 DBG_ASSERT(xModelComponent
.is(), "document missing");
268 DBG_ASSERT(rFactory
.is(), "factory missing");
269 DBG_ASSERT(NULL
!= pFilterName
,"I need a service name for the component!");
271 // prepare ParserInputSrouce
272 xml::sax::InputSource aParserInput
;
273 aParserInput
.aInputStream
= xInputStream
;
276 Reference
< xml::sax::XParser
> xParser(
277 rFactory
->createInstance(
278 OUString::createFromAscii("com.sun.star.xml.sax.Parser") ),
280 DBG_ASSERT( xParser
.is(), "Can't create parser" );
284 Sequence
<Any
> aArgs( 1 );
285 aArgs
[0] <<= rPropSet
;
288 Reference
< xml::sax::XDocumentHandler
> xFilter(
289 rFactory
->createInstanceWithArguments(
290 OUString::createFromAscii(pFilterName
), aArgs
),
292 DBG_ASSERT( xFilter
.is(), "Can't instantiate filter component." );
296 // connect parser and filter
297 xParser
->setDocumentHandler( xFilter
);
299 // connect model and filter
300 Reference
< XImporter
> xImporter( xFilter
, UNO_QUERY
);
301 xImporter
->setTargetDocument( xModelComponent
);
303 // finally, parser the stream
306 xParser
->parseStream( aParserInput
);
308 uno::Reference
<lang::XUnoTunnel
> xFilterTunnel
;
309 xFilterTunnel
= uno::Reference
<lang::XUnoTunnel
>
310 ( xFilter
, uno::UNO_QUERY
);
311 SmXMLImport
*pFilter
= reinterpret_cast< SmXMLImport
* >(
312 sal::static_int_cast
< sal_uIntPtr
>(
313 xFilterTunnel
->getSomething( SmXMLImport::getUnoTunnelId() )));
314 if ( pFilter
&& pFilter
->GetSuccess() )
317 catch( xml::sax::SAXParseException
& r
)
319 // sax parser sends wrapped exceptions,
320 // try to find the original one
321 xml::sax::SAXException aSaxEx
= *(xml::sax::SAXException
*)(&r
);
322 sal_Bool bTryChild
= sal_True
;
326 xml::sax::SAXException aTmp
;
327 if ( aSaxEx
.WrappedException
>>= aTmp
)
330 bTryChild
= sal_False
;
333 packages::zip::ZipIOException aBrokenPackage
;
334 if ( aSaxEx
.WrappedException
>>= aBrokenPackage
)
335 return ERRCODE_IO_BROKENPACKAGE
;
338 nError
= ERRCODE_SFX_WRONGPASSWORD
;
340 catch( xml::sax::SAXException
& r
)
342 packages::zip::ZipIOException aBrokenPackage
;
343 if ( r
.WrappedException
>>= aBrokenPackage
)
344 return ERRCODE_IO_BROKENPACKAGE
;
347 nError
= ERRCODE_SFX_WRONGPASSWORD
;
349 catch( packages::zip::ZipIOException
& )
351 nError
= ERRCODE_IO_BROKENPACKAGE
;
353 catch( io::IOException
& )
361 sal_uLong
SmXMLImportWrapper::ReadThroughComponent(
362 const uno::Reference
< embed::XStorage
>& xStorage
,
363 Reference
<XComponent
> xModelComponent
,
364 const sal_Char
* pStreamName
,
365 const sal_Char
* pCompatibilityStreamName
,
366 Reference
<lang::XMultiServiceFactory
> & rFactory
,
367 Reference
<beans::XPropertySet
> & rPropSet
,
368 const sal_Char
* pFilterName
)
370 DBG_ASSERT(xStorage
.is(), "Need storage!");
371 DBG_ASSERT(NULL
!= pStreamName
, "Please, please, give me a name!");
373 // open stream (and set parser input)
374 OUString sStreamName
= OUString::createFromAscii(pStreamName
);
375 uno::Reference
< container::XNameAccess
> xAccess( xStorage
, uno::UNO_QUERY
);
376 if ( !xAccess
->hasByName(sStreamName
) || !xStorage
->isStreamElement(sStreamName
) )
378 // stream name not found! Then try the compatibility name.
379 // do we even have an alternative name?
380 if ( pCompatibilityStreamName
)
381 sStreamName
= OUString::createFromAscii(pCompatibilityStreamName
);
387 uno::Reference
< io::XStream
> xEventsStream
= xStorage
->openStreamElement( sStreamName
, embed::ElementModes::READ
);
389 // determine if stream is encrypted or not
390 uno::Reference
< beans::XPropertySet
> xProps( xEventsStream
, uno::UNO_QUERY
);
391 Any aAny
= xProps
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Encrypted") ) );
392 sal_Bool bEncrypted
= sal_False
;
393 if ( aAny
.getValueType() == ::getBooleanCppuType() )
399 OUString
sPropName( RTL_CONSTASCII_USTRINGPARAM("StreamName") );
400 rPropSet
->setPropertyValue( sPropName
, makeAny( sStreamName
) );
404 Reference
< io::XInputStream
> xStream
= xEventsStream
->getInputStream();
405 return ReadThroughComponent( xStream
, xModelComponent
, rFactory
, rPropSet
, pFilterName
, bEncrypted
);
407 catch ( packages::WrongPasswordException
& )
409 return ERRCODE_SFX_WRONGPASSWORD
;
411 catch( packages::zip::ZipIOException
& )
413 return ERRCODE_IO_BROKENPACKAGE
;
415 catch ( uno::Exception
& )
419 return ERRCODE_SFX_DOLOADFAILED
;
422 ////////////////////////////////////////////////////////////
424 SmXMLImport::SmXMLImport(
425 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> xServiceFactory
,
426 sal_uInt16 nImportFlags
)
427 : SvXMLImport( xServiceFactory
, nImportFlags
),
428 pPresLayoutElemTokenMap(0),
429 pPresLayoutAttrTokenMap(0),
430 pFencedAttrTokenMap(0),
431 pOperatorAttrTokenMap(0),
432 pAnnotationAttrTokenMap(0),
433 pPresElemTokenMap(0),
434 pPresScriptEmptyElemTokenMap(0),
435 pPresTableElemTokenMap(0),
441 const uno::Sequence
< sal_Int8
> & SmXMLImport::getUnoTunnelId() throw()
443 static uno::Sequence
< sal_Int8
> * pSeq
= 0;
446 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
449 static uno::Sequence
< sal_Int8
> aSeq( 16 );
450 rtl_createUuid( (sal_uInt8
*)aSeq
.getArray(), 0, sal_True
);
457 OUString SAL_CALL
SmXMLImport_getImplementationName() throw()
459 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Math.XMLImporter" ) );
462 uno::Sequence
< OUString
> SAL_CALL
SmXMLImport_getSupportedServiceNames()
465 const OUString
aServiceName( IMPORT_SVC_NAME
);
466 const uno::Sequence
< OUString
> aSeq( &aServiceName
, 1 );
470 uno::Reference
< uno::XInterface
> SAL_CALL
SmXMLImport_createInstance(
471 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
472 throw( uno::Exception
)
475 // return (cppu::OWeakObject*)new SmXMLImport(IMPORT_ALL);
476 return (cppu::OWeakObject
*)new SmXMLImport(rSMgr
, IMPORT_ALL
);
479 ////////////////////////////////////////////////////////////
481 OUString SAL_CALL
SmXMLImportMeta_getImplementationName() throw()
483 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Math.XMLOasisMetaImporter" ) );
486 uno::Sequence
< OUString
> SAL_CALL
SmXMLImportMeta_getSupportedServiceNames()
489 const OUString
aServiceName( IMPORT_SVC_NAME
);
490 const uno::Sequence
< OUString
> aSeq( &aServiceName
, 1 );
494 uno::Reference
< uno::XInterface
> SAL_CALL
SmXMLImportMeta_createInstance(
495 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
496 throw( uno::Exception
)
499 // return (cppu::OWeakObject*)new SmXMLImport( IMPORT_META );
500 return (cppu::OWeakObject
*)new SmXMLImport( rSMgr
, IMPORT_META
);
503 ////////////////////////////////////////////////////////////
505 OUString SAL_CALL
SmXMLImportSettings_getImplementationName() throw()
507 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Math.XMLOasisSettingsImporter" ) );
510 uno::Sequence
< OUString
> SAL_CALL
SmXMLImportSettings_getSupportedServiceNames()
513 const OUString
aServiceName( IMPORT_SVC_NAME
);
514 const uno::Sequence
< OUString
> aSeq( &aServiceName
, 1 );
518 uno::Reference
< uno::XInterface
> SAL_CALL
SmXMLImportSettings_createInstance(
519 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
520 throw( uno::Exception
)
523 // return (cppu::OWeakObject*)new SmXMLImport( IMPORT_SETTINGS );
524 return (cppu::OWeakObject
*)new SmXMLImport( rSMgr
, IMPORT_SETTINGS
);
527 ////////////////////////////////////////////////////////////
530 // override empty method from parent class
531 rtl::OUString SAL_CALL
SmXMLImport::getImplementationName()
532 throw(uno::RuntimeException
)
535 switch( getImportFlags() )
538 aTxt
= SmXMLImportMeta_getImplementationName();
540 case IMPORT_SETTINGS
:
541 aTxt
= SmXMLImportSettings_getImplementationName();
545 aTxt
= SmXMLImport_getImplementationName();
552 sal_Int64 SAL_CALL
SmXMLImport::getSomething(
553 const uno::Sequence
< sal_Int8
>&rId
)
554 throw(uno::RuntimeException
)
556 if ( rId
.getLength() == 16 &&
557 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
558 rId
.getConstArray(), 16 ) )
559 return sal::static_int_cast
< sal_Int64
>(reinterpret_cast< sal_uIntPtr
>(this));
561 return SvXMLImport::getSomething( rId
);
564 void SmXMLImport::endDocument(void)
565 throw(xml::sax::SAXException
, uno::RuntimeException
)
567 //Set the resulted tree into the SmDocShell where it belongs
569 if (NULL
!= (pTree
= GetTree()))
571 uno::Reference
<frame::XModel
> xModel
= GetModel();
572 uno::Reference
<lang::XUnoTunnel
> xTunnel
;
573 xTunnel
= uno::Reference
<lang::XUnoTunnel
> (xModel
,uno::UNO_QUERY
);
574 SmModel
*pModel
= reinterpret_cast<SmModel
*>
575 (xTunnel
->getSomething(SmModel::getUnoTunnelId()));
579 SmDocShell
*pDocShell
=
580 static_cast<SmDocShell
*>(pModel
->GetObjectShell());
581 pDocShell
->SetFormulaTree(pTree
);
582 if (0 == aText
.Len()) //If we picked up no annotation text
584 //Make up some editable text
585 aText
= pDocShell
->GetText();
586 pTree
->CreateTextFromNode(aText
);
587 aText
.EraseTrailingChars();
588 if ((aText
.GetChar(0) == '{') &&
589 (aText
.GetChar(aText
.Len()-1) == '}'))
592 aText
.Erase(aText
.Len()-1,1);
595 pDocShell
->SetText( String() );
597 // Convert symbol names
598 SmParser
&rParser
= pDocShell
->GetParser();
599 sal_Bool bVal
= rParser
.IsImportSymbolNames();
600 rParser
.SetImportSymbolNames( sal_True
);
601 SmNode
*pTmpTree
= rParser
.Parse( aText
);
602 aText
= rParser
.GetText();
604 rParser
.SetImportSymbolNames( bVal
);
606 pDocShell
->SetText( aText
);
608 DBG_ASSERT(pModel
,"So there *was* a uno problem after all");
613 SvXMLImport::endDocument();
616 ////////////////////////////////////////////////////////////
618 class SmXMLImportContext
: public SvXMLImportContext
621 SmXMLImportContext( SmXMLImport
&rImport
, sal_uInt16 nPrfx
,
622 const OUString
& rLName
)
623 : SvXMLImportContext(rImport
, nPrfx
, rLName
) {}
625 const SmXMLImport
& GetSmImport() const
627 return (const SmXMLImport
&)GetImport();
630 SmXMLImport
& GetSmImport()
632 return (SmXMLImport
&)GetImport();
635 virtual void TCharacters(const OUString
& /*rChars*/);
636 virtual void Characters(const OUString
&rChars
);
637 virtual SvXMLImportContext
*CreateChildContext(sal_uInt16
/*nPrefix*/, const OUString
& /*rLocalName*/, const uno::Reference
< xml::sax::XAttributeList
> & /*xAttrList*/);
640 void SmXMLImportContext::TCharacters(const OUString
& /*rChars*/)
644 void SmXMLImportContext::Characters(const OUString
&rChars
)
647 Whitespace occurring within the content of token elements is "trimmed"
648 from the ends (i.e. all whitespace at the beginning and end of the
649 content is removed), and "collapsed" internally (i.e. each sequence of
650 1 or more whitespace characters is replaced with one blank character).
652 //collapsing not done yet!
653 const OUString
&rChars2
= rChars
.trim();
654 if (rChars2
.getLength())
655 TCharacters(rChars2
/*.collapse()*/);
658 SvXMLImportContext
* SmXMLImportContext::CreateChildContext(sal_uInt16
/*nPrefix*/,
659 const OUString
& /*rLocalName*/,
660 const uno::Reference
< xml::sax::XAttributeList
> & /*xAttrList*/)
665 ////////////////////////////////////////////////////////////
667 struct SmXMLContext_Helper
672 sal_Bool bFontNodeNeeded
;
673 OUString sFontFamily
;
676 SmXMLImportContext rContext
;
678 SmXMLContext_Helper(SmXMLImportContext
&rImport
) :
679 nIsBold(-1), nIsItalic(-1), nFontSize(0.0), rContext(rImport
) {}
681 void RetrieveAttrs(const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
685 void SmXMLContext_Helper::RetrieveAttrs(const uno::Reference
<
686 xml::sax::XAttributeList
> & xAttrList
)
688 sal_Int8 nOldIsBold
=nIsBold
;
689 sal_Int8 nOldIsItalic
=nIsItalic
;
690 double nOldFontSize
=nFontSize
;
691 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
692 OUString sOldFontFamily
= sFontFamily
;
693 for (sal_Int16 i
=0;i
<nAttrCount
;i
++)
695 OUString sAttrName
= xAttrList
->getNameByIndex(i
);
697 sal_uInt16 nPrefix
= rContext
.GetSmImport().GetNamespaceMap().
698 GetKeyByAttrName(sAttrName
,&aLocalName
);
699 OUString sValue
= xAttrList
->getValueByIndex(i
);
700 const SvXMLTokenMap
&rAttrTokenMap
=
701 rContext
.GetSmImport().GetPresLayoutAttrTokenMap();
702 switch(rAttrTokenMap
.Get(nPrefix
,aLocalName
))
704 case XML_TOK_FONTWEIGHT
:
705 nIsBold
= sValue
.equals(GetXMLToken(XML_BOLD
));
707 case XML_TOK_FONTSTYLE
:
708 nIsItalic
= sValue
.equals(GetXMLToken(XML_ITALIC
));
710 case XML_TOK_FONTSIZE
:
711 SvXMLUnitConverter::convertDouble(nFontSize
,sValue
);
712 rContext
.GetSmImport().GetMM100UnitConverter().
713 setXMLMeasureUnit(MAP_POINT
);
714 if (-1 == sValue
.indexOf(GetXMLToken(XML_UNIT_PT
)))
716 if (-1 == sValue
.indexOf('%'))
720 rContext
.GetSmImport().GetMM100UnitConverter().
721 setXMLMeasureUnit(MAP_RELATIVE
);
725 case XML_TOK_FONTFAMILY
:
726 sFontFamily
= sValue
;
736 if ((nOldIsBold
!=nIsBold
) || (nOldIsItalic
!=nIsItalic
) ||
737 (nOldFontSize
!=nFontSize
) || (sOldFontFamily
!=sFontFamily
)
738 || sColor
.getLength())
739 bFontNodeNeeded
=sal_True
;
741 bFontNodeNeeded
=sal_False
;
744 void SmXMLContext_Helper::ApplyAttrs()
746 SmNodeStack
&rNodeStack
= rContext
.GetSmImport().GetNodeStack();
751 aToken
.cMathChar
= '\0';
758 aToken
.eType
= TBOLD
;
760 aToken
.eType
= TNBOLD
;
761 SmStructureNode
*pFontNode
= static_cast<SmStructureNode
*>
762 (new SmFontNode(aToken
));
763 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
764 rNodeStack
.Push(pFontNode
);
769 aToken
.eType
= TITALIC
;
771 aToken
.eType
= TNITALIC
;
772 SmStructureNode
*pFontNode
= static_cast<SmStructureNode
*>
773 (new SmFontNode(aToken
));
774 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
775 rNodeStack
.Push(pFontNode
);
777 if (nFontSize
!= 0.0)
779 aToken
.eType
= TSIZE
;
780 SmFontNode
*pFontNode
= new SmFontNode(aToken
);
782 if (MAP_RELATIVE
== rContext
.GetSmImport().GetMM100UnitConverter().
785 if (nFontSize
< 100.00)
786 pFontNode
->SetSizeParameter(Fraction(100.00/nFontSize
),
789 pFontNode
->SetSizeParameter(Fraction(nFontSize
/100.00),
793 pFontNode
->SetSizeParameter(Fraction(nFontSize
),FNTSIZ_ABSOLUT
);
795 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
796 rNodeStack
.Push(pFontNode
);
798 if (sFontFamily
.getLength())
800 if (sFontFamily
.equalsIgnoreAsciiCase(GetXMLToken(XML_FIXED
)))
801 aToken
.eType
= TFIXED
;
802 else if (sFontFamily
.equalsIgnoreAsciiCase(OUString(
803 RTL_CONSTASCII_USTRINGPARAM("sans"))))
804 aToken
.eType
= TSANS
;
805 else if (sFontFamily
.equalsIgnoreAsciiCase(OUString(
806 RTL_CONSTASCII_USTRINGPARAM("serif"))))
807 aToken
.eType
= TSERIF
;
808 else //Just give up, we need to extend our font mechanism to be
812 aToken
.aText
= sFontFamily
;
813 SmFontNode
*pFontNode
= new SmFontNode(aToken
);
814 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
815 rNodeStack
.Push(pFontNode
);
817 if (sColor
.getLength())
819 //Again we can only handle a small set of colours in
821 const SvXMLTokenMap
& rTokenMap
=
822 rContext
.GetSmImport().GetColorTokenMap();
823 aToken
.eType
= static_cast<SmTokenType
>(rTokenMap
.Get(
824 XML_NAMESPACE_MATH
, sColor
));
825 if (aToken
.eType
!= -1)
827 SmFontNode
*pFontNode
= new SmFontNode(aToken
);
828 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
829 rNodeStack
.Push(pFontNode
);
836 ////////////////////////////////////////////////////////////
838 class SmXMLDocContext_Impl
: public SmXMLImportContext
841 SmXMLDocContext_Impl( SmXMLImport
&rImport
, sal_uInt16 nPrfx
,
842 const OUString
& rLName
)
843 : SmXMLImportContext(rImport
,nPrfx
,rLName
) {}
845 virtual SvXMLImportContext
*CreateChildContext(sal_uInt16 nPrefix
, const OUString
& rLocalName
, const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
850 ////////////////////////////////////////////////////////////
852 /*avert thy gaze from the proginator*/
853 class SmXMLRowContext_Impl
: public SmXMLDocContext_Impl
856 sal_uLong nElementCount
;
859 SmXMLRowContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
860 const OUString
& rLName
)
861 : SmXMLDocContext_Impl(rImport
,nPrefix
,rLName
)
862 { nElementCount
= GetSmImport().GetNodeStack().Count(); }
864 virtual SvXMLImportContext
*CreateChildContext(sal_uInt16 nPrefix
, const OUString
& rLocalName
, const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
866 SvXMLImportContext
*StrictCreateChildContext(sal_uInt16 nPrefix
,
867 const OUString
& rLocalName
,
868 const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
873 ////////////////////////////////////////////////////////////
875 class SmXMLFracContext_Impl
: public SmXMLRowContext_Impl
878 SmXMLFracContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
879 const OUString
& rLName
)
880 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
885 ////////////////////////////////////////////////////////////
887 class SmXMLSqrtContext_Impl
: public SmXMLRowContext_Impl
890 SmXMLSqrtContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
891 const OUString
& rLName
)
892 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
897 ////////////////////////////////////////////////////////////
899 class SmXMLRootContext_Impl
: public SmXMLRowContext_Impl
902 SmXMLRootContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
903 const OUString
& rLName
)
904 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
909 ////////////////////////////////////////////////////////////
911 class SmXMLStyleContext_Impl
: public SmXMLRowContext_Impl
914 SmXMLContext_Helper aStyleHelper
;
917 /*Right now the style tag is completely ignored*/
918 SmXMLStyleContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
919 const OUString
& rLName
) : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
),
920 aStyleHelper(*this) {}
923 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
926 void SmXMLStyleContext_Impl::StartElement(const uno::Reference
<
927 xml::sax::XAttributeList
> & xAttrList
)
930 aStyleHelper
.RetrieveAttrs(xAttrList
);
932 sal_Int8 nOldIsBold
=nIsBold
;
933 sal_Int8 nOldIsItalic
=nIsItalic
;
934 double nOldFontSize
=nFontSize
;
935 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
936 OUString sOldFontFamily
= sFontFamily
;
937 for (sal_Int16 i
=0;i
<nAttrCount
;i
++)
939 OUString sAttrName
= xAttrList
->getNameByIndex(i
);
941 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
942 GetKeyByAttrName(sAttrName
,&aLocalName
);
943 OUString sValue
= xAttrList
->getValueByIndex(i
);
944 const SvXMLTokenMap
&rAttrTokenMap
=
945 GetSmImport().GetPresLayoutAttrTokenMap();
946 switch(rAttrTokenMap
.Get(nPrefix
,aLocalName
))
948 case XML_TOK_FONTWEIGHT
:
949 nIsBold
= sValue
.equals(GetXMLToken(XML_BOLD
));
951 case XML_TOK_FONTSTYLE
:
952 nIsItalic
= sValue
.equals(GetXMLToken(XML_ITALIC
));
954 case XML_TOK_FONTSIZE
:
955 SvXMLUnitConverter::convertDouble(nFontSize
,sValue
);
956 GetSmImport().GetMM100UnitConverter().
957 setXMLMeasureUnit(MAP_POINT
);
958 if (-1 == sValue
.indexOf(GetXMLToken(XML_UNIT_PT
)))
959 if (-1 == sValue
.indexOf('%'))
963 GetSmImport().GetMM100UnitConverter().
964 setXMLMeasureUnit(MAP_RELATIVE
);
967 case XML_TOK_FONTFAMILY
:
968 sFontFamily
= sValue
;
978 if ((nOldIsBold
!=nIsBold
) || (nOldIsItalic
!=nIsItalic
) ||
979 (nOldFontSize
!=nFontSize
) || (sOldFontFamily
!=sFontFamily
)
980 || sColor
.getLength())
981 bFontNodeNeeded
=sal_True
;
983 bFontNodeNeeded
=sal_False
;
988 void SmXMLStyleContext_Impl::EndElement()
991 <mstyle> accepts any number of arguments; if this number is not 1, its
992 contents are treated as a single "inferred <mrow>" containing its
995 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
996 if (rNodeStack
.Count() - nElementCount
> 1)
997 SmXMLRowContext_Impl::EndElement();
999 aStyleHelper
.ApplyAttrs();
1001 if (bFontNodeNeeded
)
1004 aToken
.cMathChar
= '\0';
1011 aToken
.eType
= TBOLD
;
1013 aToken
.eType
= TNBOLD
;
1014 SmStructureNode
*pFontNode
= static_cast<SmStructureNode
*>
1015 (new SmFontNode(aToken
));
1016 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
1017 rNodeStack
.Push(pFontNode
);
1019 if (nIsItalic
!= -1)
1022 aToken
.eType
= TITALIC
;
1024 aToken
.eType
= TNITALIC
;
1025 SmStructureNode
*pFontNode
= static_cast<SmStructureNode
*>
1026 (new SmFontNode(aToken
));
1027 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
1028 rNodeStack
.Push(pFontNode
);
1030 if (nFontSize
!= 0.0)
1032 aToken
.eType
= TSIZE
;
1033 SmFontNode
*pFontNode
= new SmFontNode(aToken
);
1035 if (MAP_RELATIVE
== GetSmImport().GetMM100UnitConverter().
1036 getXMLMeasureUnit())
1038 if (nFontSize
< 100.00)
1039 pFontNode
->SetSizeParameter(Fraction(100.00/nFontSize
),
1042 pFontNode
->SetSizeParameter(Fraction(nFontSize
/100.00),
1046 pFontNode
->SetSizeParameter(Fraction(nFontSize
),FNTSIZ_ABSOLUT
);
1048 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
1049 rNodeStack
.Push(pFontNode
);
1051 if (sFontFamily
.getLength())
1053 if (sFontFamily
.equalsIgnoreCase(GetXMLToken(XML_FIXED
)))
1054 aToken
.eType
= TFIXED
;
1055 else if (sFontFamily
.equalsIgnoreCase(OUString(
1056 RTL_CONSTASCII_USTRINGPARAM("sans"))))
1057 aToken
.eType
= TSANS
;
1058 else if (sFontFamily
.equalsIgnoreCase(OUString(
1059 RTL_CONSTASCII_USTRINGPARAM("serif"))))
1060 aToken
.eType
= TSERIF
;
1061 else //Just give up, we need to extend our font mechanism to be
1065 aToken
.aText
= sFontFamily
;
1066 SmFontNode
*pFontNode
= new SmFontNode(aToken
);
1067 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
1068 rNodeStack
.Push(pFontNode
);
1070 if (sColor
.getLength())
1072 //Again we can only handle a small set of colours in
1074 const SvXMLTokenMap
& rTokenMap
=
1075 GetSmImport().GetColorTokenMap();
1076 aToken
.eType
= static_cast<SmTokenType
>(rTokenMap
.Get(
1077 XML_NAMESPACE_MATH
, sColor
));
1078 if (aToken
.eType
!= -1)
1080 SmFontNode
*pFontNode
= new SmFontNode(aToken
);
1081 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
1082 rNodeStack
.Push(pFontNode
);
1090 ////////////////////////////////////////////////////////////
1092 class SmXMLPaddedContext_Impl
: public SmXMLRowContext_Impl
1095 /*Right now the style tag is completely ignored*/
1096 SmXMLPaddedContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1097 const OUString
& rLName
)
1098 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
1103 void SmXMLPaddedContext_Impl::EndElement()
1106 <mpadded> accepts any number of arguments; if this number is not 1, its
1107 contents are treated as a single "inferred <mrow>" containing its
1110 if (GetSmImport().GetNodeStack().Count() - nElementCount
> 1)
1111 SmXMLRowContext_Impl::EndElement();
1114 ////////////////////////////////////////////////////////////
1116 class SmXMLPhantomContext_Impl
: public SmXMLRowContext_Impl
1119 /*Right now the style tag is completely ignored*/
1120 SmXMLPhantomContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1121 const OUString
& rLName
)
1122 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
1127 void SmXMLPhantomContext_Impl::EndElement()
1130 <mphantom> accepts any number of arguments; if this number is not 1, its
1131 contents are treated as a single "inferred <mrow>" containing its
1134 if (GetSmImport().GetNodeStack().Count() - nElementCount
> 1)
1135 SmXMLRowContext_Impl::EndElement();
1138 aToken
.cMathChar
= '\0';
1141 aToken
.eType
= TPHANTOM
;
1143 SmStructureNode
*pPhantom
= static_cast<SmStructureNode
*>
1144 (new SmFontNode(aToken
));
1145 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1146 pPhantom
->SetSubNodes(0,rNodeStack
.Pop());
1147 rNodeStack
.Push(pPhantom
);
1150 ////////////////////////////////////////////////////////////
1152 class SmXMLFencedContext_Impl
: public SmXMLRowContext_Impl
1159 SmXMLFencedContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1160 const OUString
& rLName
)
1161 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
),
1162 cBegin('('), cEnd(')') {}
1164 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
1169 void SmXMLFencedContext_Impl::StartElement(const uno::Reference
<
1170 xml::sax::XAttributeList
> & xAttrList
)
1172 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1173 for (sal_Int16 i
=0;i
<nAttrCount
;i
++)
1175 OUString sAttrName
= xAttrList
->getNameByIndex(i
);
1176 OUString aLocalName
;
1177 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
1178 GetKeyByAttrName(sAttrName
,&aLocalName
);
1179 OUString sValue
= xAttrList
->getValueByIndex(i
);
1180 const SvXMLTokenMap
&rAttrTokenMap
=
1181 GetSmImport().GetFencedAttrTokenMap();
1182 switch(rAttrTokenMap
.Get(nPrefix
,aLocalName
))
1184 //temp, starmath cannot handle multichar brackets (I think)
1192 /*Go to superclass*/
1199 void SmXMLFencedContext_Impl::EndElement()
1202 aToken
.cMathChar
= '\0';
1205 aToken
.eType
= TLEFT
;
1208 aToken
.eType
= TLPARENT
;
1209 aToken
.cMathChar
= cBegin
;
1210 SmStructureNode
*pSNode
= new SmBraceNode(aToken
);
1211 SmNode
*pLeft
= new SmMathSymbolNode(aToken
);
1213 aToken
.cMathChar
= cEnd
;
1214 aToken
.eType
= TRPARENT
;
1215 SmNode
*pRight
= new SmMathSymbolNode(aToken
);
1217 SmNodeArray aRelationArray
;
1218 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1220 aToken
.cMathChar
= '\0';
1222 aToken
.eType
= TIDENT
;
1224 sal_uLong i
= rNodeStack
.Count() - nElementCount
;
1225 if (rNodeStack
.Count() - nElementCount
> 1)
1226 i
+= rNodeStack
.Count() - 1 - nElementCount
;
1227 aRelationArray
.resize(i
);
1228 while (rNodeStack
.Count() > nElementCount
)
1230 aRelationArray
[--i
] = rNodeStack
.Pop();
1231 if (i
> 1 && rNodeStack
.Count() > 1)
1232 aRelationArray
[--i
] = new SmGlyphSpecialNode(aToken
);
1236 SmStructureNode
*pBody
= new SmExpressionNode(aDummy
);
1237 pBody
->SetSubNodes(aRelationArray
);
1240 pSNode
->SetSubNodes(pLeft
,pBody
,pRight
);
1241 pSNode
->SetScaleMode(SCALE_HEIGHT
);
1242 GetSmImport().GetNodeStack().Push(pSNode
);
1246 ////////////////////////////////////////////////////////////
1248 class SmXMLErrorContext_Impl
: public SmXMLRowContext_Impl
1251 SmXMLErrorContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1252 const OUString
& rLName
)
1253 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
1258 void SmXMLErrorContext_Impl::EndElement()
1260 /*Right now the error tag is completely ignored, what
1261 can I do with it in starmath, ?, maybe we need a
1262 report window ourselves, do a test for validity of
1263 the xml input, use merrors, and then generate
1264 the markup inside the merror with a big red colour
1265 of something. For now just throw them all away.
1267 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1268 while (rNodeStack
.Count() > nElementCount
)
1270 SmNode
*pNode
= rNodeStack
.Pop();
1275 ////////////////////////////////////////////////////////////
1277 class SmXMLNumberContext_Impl
: public SmXMLImportContext
1283 SmXMLNumberContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1284 const OUString
& rLName
)
1285 : SmXMLImportContext(rImport
,nPrefix
,rLName
)
1287 aToken
.cMathChar
= '\0';
1290 aToken
.eType
= TNUMBER
;
1293 virtual void TCharacters(const OUString
&rChars
);
1298 void SmXMLNumberContext_Impl::TCharacters(const OUString
&rChars
)
1300 aToken
.aText
= rChars
;
1303 void SmXMLNumberContext_Impl::EndElement()
1305 GetSmImport().GetNodeStack().Push(new SmTextNode(aToken
,FNT_NUMBER
));
1308 ////////////////////////////////////////////////////////////
1310 class SmXMLAnnotationContext_Impl
: public SmXMLImportContext
1312 sal_Bool bIsStarMath
;
1315 SmXMLAnnotationContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1316 const OUString
& rLName
)
1317 : SmXMLImportContext(rImport
,nPrefix
,rLName
), bIsStarMath(sal_False
) {}
1319 virtual void Characters(const OUString
&rChars
);
1321 void StartElement(const uno::Reference
<xml::sax::XAttributeList
> & xAttrList
);
1324 void SmXMLAnnotationContext_Impl::StartElement(const uno::Reference
<
1325 xml::sax::XAttributeList
> & xAttrList
)
1327 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1328 for (sal_Int16 i
=0;i
<nAttrCount
;i
++)
1330 OUString sAttrName
= xAttrList
->getNameByIndex(i
);
1331 OUString aLocalName
;
1332 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
1333 GetKeyByAttrName(sAttrName
,&aLocalName
);
1335 OUString sValue
= xAttrList
->getValueByIndex(i
);
1336 const SvXMLTokenMap
&rAttrTokenMap
=
1337 GetSmImport().GetAnnotationAttrTokenMap();
1338 switch(rAttrTokenMap
.Get(nPrefix
,aLocalName
))
1340 case XML_TOK_ENCODING
:
1341 bIsStarMath
= sValue
.equals(
1342 OUString(RTL_CONSTASCII_USTRINGPARAM("StarMath 5.0")));
1350 void SmXMLAnnotationContext_Impl::Characters(const OUString
&rChars
)
1353 GetSmImport().GetText().Append(String(rChars
));
1356 ////////////////////////////////////////////////////////////
1358 class SmXMLTextContext_Impl
: public SmXMLImportContext
1364 SmXMLTextContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1365 const OUString
& rLName
)
1366 : SmXMLImportContext(rImport
,nPrefix
,rLName
)
1368 aToken
.cMathChar
= '\0';
1371 aToken
.eType
= TTEXT
;
1374 virtual void TCharacters(const OUString
&rChars
);
1379 void SmXMLTextContext_Impl::TCharacters(const OUString
&rChars
)
1381 aToken
.aText
= rChars
;
1384 void SmXMLTextContext_Impl::EndElement()
1386 GetSmImport().GetNodeStack().Push(new SmTextNode(aToken
,FNT_TEXT
));
1389 ////////////////////////////////////////////////////////////
1391 class SmXMLStringContext_Impl
: public SmXMLImportContext
1397 SmXMLStringContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1398 const OUString
& rLName
)
1399 : SmXMLImportContext(rImport
,nPrefix
,rLName
)
1401 aToken
.cMathChar
= '\0';
1404 aToken
.eType
= TTEXT
;
1407 virtual void TCharacters(const OUString
&rChars
);
1412 void SmXMLStringContext_Impl::TCharacters(const OUString
&rChars
)
1415 The content of <ms> elements should be rendered with visible "escaping" of
1416 certain characters in the content, including at least "double quote"
1417 itself, and preferably whitespace other than individual blanks. The intent
1418 is for the viewer to see that the expression is a string literal, and to
1419 see exactly which characters form its content. For example, <ms>double
1420 quote is "</ms> might be rendered as "double quote is \"".
1422 Obviously this isn't fully done here.
1424 aToken
.aText
.Erase();
1425 aToken
.aText
+= '\"';
1426 aToken
.aText
+= String(rChars
);
1427 aToken
.aText
+= '\"';
1430 void SmXMLStringContext_Impl::EndElement()
1432 GetSmImport().GetNodeStack().Push(new SmTextNode(aToken
,FNT_FIXED
));
1435 ////////////////////////////////////////////////////////////
1437 class SmXMLIdentifierContext_Impl
: public SmXMLImportContext
1440 SmXMLContext_Helper aStyleHelper
;
1444 SmXMLIdentifierContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1445 const OUString
& rLName
)
1446 : SmXMLImportContext(rImport
,nPrefix
,rLName
),aStyleHelper(*this)
1448 aToken
.cMathChar
= '\0';
1451 aToken
.eType
= TIDENT
;
1454 void TCharacters(const OUString
&rChars
);
1455 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
1457 aStyleHelper
.RetrieveAttrs(xAttrList
);
1462 void SmXMLIdentifierContext_Impl::EndElement()
1464 SmTextNode
*pNode
= 0;
1465 //we will handle identifier italic/normal here instead of with a standalone
1467 if (((aStyleHelper
.nIsItalic
== -1) && (aToken
.aText
.Len() > 1))
1468 || ((aStyleHelper
.nIsItalic
== 0) && (aToken
.aText
.Len() == 1)))
1470 pNode
= new SmTextNode(aToken
,FNT_FUNCTION
);
1471 pNode
->GetFont().SetItalic(ITALIC_NONE
);
1472 aStyleHelper
.nIsItalic
= -1;
1475 pNode
= new SmTextNode(aToken
,FNT_VARIABLE
);
1476 if (aStyleHelper
.bFontNodeNeeded
&& aStyleHelper
.nIsItalic
!= -1)
1478 if (aStyleHelper
.nIsItalic
)
1479 pNode
->GetFont().SetItalic(ITALIC_NORMAL
);
1481 pNode
->GetFont().SetItalic(ITALIC_NONE
);
1484 if ((-1!=aStyleHelper
.nIsBold
) || (0.0!=aStyleHelper
.nFontSize
) ||
1485 (aStyleHelper
.sFontFamily
.getLength()) ||
1486 aStyleHelper
.sColor
.getLength())
1487 aStyleHelper
.bFontNodeNeeded
=sal_True
;
1489 aStyleHelper
.bFontNodeNeeded
=sal_False
;
1490 if (aStyleHelper
.bFontNodeNeeded
)
1491 aStyleHelper
.ApplyAttrs();
1492 GetSmImport().GetNodeStack().Push(pNode
);
1495 void SmXMLIdentifierContext_Impl::TCharacters(const OUString
&rChars
)
1497 aToken
.aText
= rChars
;
1500 ////////////////////////////////////////////////////////////
1502 class SmXMLOperatorContext_Impl
: public SmXMLImportContext
1504 sal_Bool bIsStretchy
;
1510 SmXMLOperatorContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1511 const OUString
& rLName
)
1512 : SmXMLImportContext(rImport
,nPrefix
,rLName
), bIsStretchy(sal_False
)
1515 aToken
.eType
= TSPECIAL
;
1519 void TCharacters(const OUString
&rChars
);
1520 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1524 void SmXMLOperatorContext_Impl::TCharacters(const OUString
&rChars
)
1526 aToken
.cMathChar
= rChars
[0];
1529 void SmXMLOperatorContext_Impl::EndElement()
1531 SmMathSymbolNode
*pNode
= new SmMathSymbolNode(aToken
);
1532 //For stretchy scaling the scaling must be retrieved from this node
1533 //and applied to the expression itself so as to get the expression
1534 //to scale the operator to the height of the expression itself
1536 pNode
->SetScaleMode(SCALE_HEIGHT
);
1537 GetSmImport().GetNodeStack().Push(pNode
);
1542 void SmXMLOperatorContext_Impl::StartElement(const uno::Reference
<
1543 xml::sax::XAttributeList
> & xAttrList
)
1545 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1546 for (sal_Int16 i
=0;i
<nAttrCount
;i
++)
1548 OUString sAttrName
= xAttrList
->getNameByIndex(i
);
1549 OUString aLocalName
;
1550 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
1551 GetKeyByAttrName(sAttrName
,&aLocalName
);
1553 OUString sValue
= xAttrList
->getValueByIndex(i
);
1554 const SvXMLTokenMap
&rAttrTokenMap
=
1555 GetSmImport().GetOperatorAttrTokenMap();
1556 switch(rAttrTokenMap
.Get(nPrefix
,aLocalName
))
1558 case XML_TOK_STRETCHY
:
1559 bIsStretchy
= sValue
.equals(
1560 GetXMLToken(XML_TRUE
));
1569 ////////////////////////////////////////////////////////////
1571 class SmXMLSpaceContext_Impl
: public SmXMLImportContext
1574 SmXMLSpaceContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1575 const OUString
& rLName
)
1576 : SmXMLImportContext(rImport
,nPrefix
,rLName
) {}
1578 void StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
);
1581 void SmXMLSpaceContext_Impl::StartElement(
1582 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/ )
1585 aToken
.cMathChar
= '\0';
1587 aToken
.eType
= TBLANK
;
1589 SmBlankNode
*pBlank
= new SmBlankNode(aToken
);
1590 pBlank
->IncreaseBy(aToken
);
1591 GetSmImport().GetNodeStack().Push(pBlank
);
1594 ////////////////////////////////////////////////////////////
1596 class SmXMLSubContext_Impl
: public SmXMLRowContext_Impl
1599 void GenericEndElement(SmTokenType eType
,SmSubSup aSubSup
);
1602 SmXMLSubContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1603 const OUString
& rLName
)
1604 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
1608 GenericEndElement(TRSUB
,RSUB
);
1613 void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType
, SmSubSup eSubSup
)
1615 /*The <msub> element requires exactly 2 arguments.*/
1616 const bool bNodeCheck
= GetSmImport().GetNodeStack().Count() - nElementCount
== 2;
1617 DBG_ASSERT( bNodeCheck
, "Sub has not two arguments" );
1622 aToken
.cMathChar
= '\0';
1625 aToken
.eType
= eType
;
1626 SmSubSupNode
*pNode
= new SmSubSupNode(aToken
);
1627 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1629 // initialize subnodes array
1630 SmNodeArray aSubNodes
;
1631 aSubNodes
.resize(1 + SUBSUP_NUM_ENTRIES
);
1632 for (sal_uLong i
= 1; i
< aSubNodes
.size(); i
++)
1633 aSubNodes
[i
] = NULL
;
1635 aSubNodes
[eSubSup
+1] = rNodeStack
.Pop();
1636 aSubNodes
[0] = rNodeStack
.Pop();
1637 pNode
->SetSubNodes(aSubNodes
);
1638 rNodeStack
.Push(pNode
);
1641 ////////////////////////////////////////////////////////////
1643 class SmXMLSupContext_Impl
: public SmXMLSubContext_Impl
1646 SmXMLSupContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1647 const OUString
& rLName
)
1648 : SmXMLSubContext_Impl(rImport
,nPrefix
,rLName
) {}
1652 GenericEndElement(TRSUP
,RSUP
);
1656 ////////////////////////////////////////////////////////////
1658 class SmXMLSubSupContext_Impl
: public SmXMLRowContext_Impl
1661 void GenericEndElement(SmTokenType eType
, SmSubSup aSub
,SmSubSup aSup
);
1664 SmXMLSubSupContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1665 const OUString
& rLName
)
1666 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
1670 GenericEndElement(TRSUB
,RSUB
,RSUP
);
1674 void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType
,
1675 SmSubSup aSub
,SmSubSup aSup
)
1677 /*The <msub> element requires exactly 3 arguments.*/
1678 const bool bNodeCheck
= GetSmImport().GetNodeStack().Count() - nElementCount
== 3;
1679 DBG_ASSERT( bNodeCheck
, "SubSup has not three arguments" );
1684 aToken
.cMathChar
= '\0';
1687 aToken
.eType
= eType
;
1688 SmSubSupNode
*pNode
= new SmSubSupNode(aToken
);
1689 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1691 // initialize subnodes array
1692 SmNodeArray aSubNodes
;
1693 aSubNodes
.resize(1 + SUBSUP_NUM_ENTRIES
);
1694 for (sal_uLong i
= 1; i
< aSubNodes
.size(); i
++)
1695 aSubNodes
[i
] = NULL
;
1697 aSubNodes
[aSup
+1] = rNodeStack
.Pop();
1698 aSubNodes
[aSub
+1] = rNodeStack
.Pop();
1699 aSubNodes
[0] = rNodeStack
.Pop();
1700 pNode
->SetSubNodes(aSubNodes
);
1701 rNodeStack
.Push(pNode
);
1704 ////////////////////////////////////////////////////////////
1706 class SmXMLUnderContext_Impl
: public SmXMLSubContext_Impl
1709 sal_Int16 nAttrCount
;
1712 SmXMLUnderContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1713 const OUString
& rLName
)
1714 : SmXMLSubContext_Impl(rImport
,nPrefix
,rLName
) {}
1716 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1718 void HandleAccent();
1721 void SmXMLUnderContext_Impl::StartElement(const uno::Reference
<
1722 xml::sax::XAttributeList
> & xAttrList
)
1724 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1727 void SmXMLUnderContext_Impl::HandleAccent()
1729 const bool bNodeCheck
= GetSmImport().GetNodeStack().Count() - nElementCount
== 2;
1730 DBG_ASSERT( bNodeCheck
, "Sub has not two arguments" );
1734 /*Just one special case for the underline thing*/
1735 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1736 SmNode
*pTest
= rNodeStack
.Pop();
1738 aToken
.cMathChar
= '\0';
1741 aToken
.eType
= TUNDERLINE
;
1744 SmNodeArray aSubNodes
;
1745 aSubNodes
.resize(2);
1747 SmStructureNode
*pNode
= new SmAttributNode(aToken
);
1748 if ((pTest
->GetToken().cMathChar
& 0x0FFF) == 0x0332)
1750 aSubNodes
[0] = new SmRectangleNode(aToken
);
1754 aSubNodes
[0] = pTest
;
1756 aSubNodes
[1] = rNodeStack
.Pop();
1757 pNode
->SetSubNodes(aSubNodes
);
1758 pNode
->SetScaleMode(SCALE_WIDTH
);
1759 rNodeStack
.Push(pNode
);
1763 void SmXMLUnderContext_Impl::EndElement()
1766 GenericEndElement(TCSUB
,CSUB
);
1771 SmStructureNode
*pNode
= rNodeStack
.Pop();
1772 if (pNode
->GetSubNode(1)->GetToken().cMathChar
== (0x0332|0xf000))
1773 if (pNode
->GetSubNode(0)->GetToken().cMathChar
== (0x0332|0xf000))
1777 ////////////////////////////////////////////////////////////
1779 class SmXMLOverContext_Impl
: public SmXMLSubContext_Impl
1782 sal_Int16 nAttrCount
;
1785 SmXMLOverContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1786 const OUString
& rLName
)
1787 : SmXMLSubContext_Impl(rImport
,nPrefix
,rLName
), nAttrCount(0) {}
1790 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1791 void HandleAccent();
1795 void SmXMLOverContext_Impl::StartElement(const uno::Reference
<
1796 xml::sax::XAttributeList
> & xAttrList
)
1798 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1802 void SmXMLOverContext_Impl::EndElement()
1805 GenericEndElement(TCSUP
,CSUP
);
1811 void SmXMLOverContext_Impl::HandleAccent()
1813 const bool bNodeCheck
= GetSmImport().GetNodeStack().Count() - nElementCount
== 2;
1814 DBG_ASSERT( bNodeCheck
, "Sub has not two arguments" );
1819 aToken
.cMathChar
= '\0';
1822 aToken
.eType
= TACUTE
;
1824 SmAttributNode
*pNode
= new SmAttributNode(aToken
);
1825 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1827 SmNodeArray aSubNodes
;
1828 aSubNodes
.resize(2);
1829 aSubNodes
[0] = rNodeStack
.Pop();
1830 aSubNodes
[1] = rNodeStack
.Pop();
1831 pNode
->SetSubNodes(aSubNodes
);
1832 pNode
->SetScaleMode(SCALE_WIDTH
);
1833 rNodeStack
.Push(pNode
);
1837 ////////////////////////////////////////////////////////////
1839 class SmXMLUnderOverContext_Impl
: public SmXMLSubSupContext_Impl
1842 SmXMLUnderOverContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1843 const OUString
& rLName
)
1844 : SmXMLSubSupContext_Impl(rImport
,nPrefix
,rLName
) {}
1848 GenericEndElement(TCSUB
,CSUB
,CSUP
);
1852 ////////////////////////////////////////////////////////////
1854 class SmXMLMultiScriptsContext_Impl
: public SmXMLSubSupContext_Impl
1856 sal_Bool bHasPrescripts
;
1859 SmXMLMultiScriptsContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1860 const OUString
& rLName
) :
1861 SmXMLSubSupContext_Impl(rImport
,nPrefix
,rLName
),
1862 bHasPrescripts(sal_False
) {}
1865 void MiddleElement();
1866 SvXMLImportContext
*CreateChildContext(sal_uInt16 nPrefix
,
1867 const OUString
& rLocalName
,
1868 const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1871 ////////////////////////////////////////////////////////////
1873 class SmXMLNoneContext_Impl
: public SmXMLImportContext
1876 SmXMLNoneContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1877 const OUString
& rLName
)
1878 : SmXMLImportContext(rImport
,nPrefix
,rLName
) {}
1884 void SmXMLNoneContext_Impl::EndElement(void)
1887 aToken
.cMathChar
= '\0';
1889 aToken
.aText
.Erase();
1891 aToken
.eType
= TIDENT
;
1892 GetSmImport().GetNodeStack().Push(
1893 new SmTextNode(aToken
,FNT_VARIABLE
));
1896 ////////////////////////////////////////////////////////////
1898 class SmXMLPrescriptsContext_Impl
: public SmXMLImportContext
1901 SmXMLPrescriptsContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1902 const OUString
& rLName
)
1903 : SmXMLImportContext(rImport
,nPrefix
,rLName
) {}
1906 ////////////////////////////////////////////////////////////
1908 class SmXMLTableRowContext_Impl
: public SmXMLRowContext_Impl
1911 SmXMLTableRowContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1912 const OUString
& rLName
) :
1913 SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
)
1916 SvXMLImportContext
*CreateChildContext(sal_uInt16 nPrefix
,
1917 const OUString
& rLocalName
,
1918 const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1922 ////////////////////////////////////////////////////////////
1924 class SmXMLTableContext_Impl
: public SmXMLTableRowContext_Impl
1927 SmXMLTableContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1928 const OUString
& rLName
) :
1929 SmXMLTableRowContext_Impl(rImport
,nPrefix
,rLName
)
1933 SvXMLImportContext
*CreateChildContext(sal_uInt16 nPrefix
,
1934 const OUString
& rLocalName
,
1935 const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1939 ////////////////////////////////////////////////////////////
1941 class SmXMLTableCellContext_Impl
: public SmXMLRowContext_Impl
1944 SmXMLTableCellContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1945 const OUString
& rLName
) :
1946 SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
)
1950 ////////////////////////////////////////////////////////////
1952 class SmXMLAlignGroupContext_Impl
: public SmXMLRowContext_Impl
1955 SmXMLAlignGroupContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1956 const OUString
& rLName
) :
1957 SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
)
1960 /*Don't do anything with alignment for now*/
1966 ////////////////////////////////////////////////////////////
1968 class SmXMLActionContext_Impl
: public SmXMLRowContext_Impl
1971 SmXMLActionContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1972 const OUString
& rLName
) :
1973 SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
)
1979 ////////////////////////////////////////////////////////////
1981 // NB: virtually inherit so we can multiply inherit properly
1982 // in SmXMLFlatDocContext_Impl
1983 class SmXMLOfficeContext_Impl
: public virtual SvXMLImportContext
1986 SmXMLOfficeContext_Impl( SmXMLImport
&rImport
, sal_uInt16 nPrfx
,
1987 const OUString
& rLName
)
1988 : SvXMLImportContext(rImport
,nPrfx
,rLName
) {}
1990 virtual SvXMLImportContext
*CreateChildContext(sal_uInt16 nPrefix
, const OUString
& rLocalName
, const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1993 SvXMLImportContext
*SmXMLOfficeContext_Impl::CreateChildContext(sal_uInt16 nPrefix
,
1994 const OUString
& rLocalName
,
1995 const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
)
1997 SvXMLImportContext
*pContext
= 0;
1998 if ( XML_NAMESPACE_OFFICE
== nPrefix
&&
1999 rLocalName
== GetXMLToken(XML_META
) )
2001 DBG_WARNING("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
2003 else if ( XML_NAMESPACE_OFFICE
== nPrefix
&&
2004 rLocalName
== GetXMLToken(XML_SETTINGS
) )
2006 pContext
= new XMLDocumentSettingsContext( GetImport(),
2007 XML_NAMESPACE_OFFICE
, rLocalName
,
2011 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
2016 ////////////////////////////////////////////////////////////
2018 // context for flat file xml format
2019 class SmXMLFlatDocContext_Impl
2020 : public SmXMLOfficeContext_Impl
, public SvXMLMetaDocumentContext
2023 SmXMLFlatDocContext_Impl( SmXMLImport
& i_rImport
,
2024 sal_uInt16 i_nPrefix
, const OUString
& i_rLName
,
2025 const uno::Reference
<document::XDocumentProperties
>& i_xDocProps
,
2026 const uno::Reference
<xml::sax::XDocumentHandler
>& i_xDocBuilder
);
2028 virtual ~SmXMLFlatDocContext_Impl();
2030 virtual SvXMLImportContext
*CreateChildContext(sal_uInt16 i_nPrefix
, const OUString
& i_rLocalName
, const uno::Reference
<xml::sax::XAttributeList
>& i_xAttrList
);
2033 SmXMLFlatDocContext_Impl::SmXMLFlatDocContext_Impl( SmXMLImport
& i_rImport
,
2034 sal_uInt16 i_nPrefix
, const OUString
& i_rLName
,
2035 const uno::Reference
<document::XDocumentProperties
>& i_xDocProps
,
2036 const uno::Reference
<xml::sax::XDocumentHandler
>& i_xDocBuilder
) :
2037 SvXMLImportContext(i_rImport
, i_nPrefix
, i_rLName
),
2038 SmXMLOfficeContext_Impl(i_rImport
, i_nPrefix
, i_rLName
),
2039 SvXMLMetaDocumentContext(i_rImport
, i_nPrefix
, i_rLName
,
2040 i_xDocProps
, i_xDocBuilder
)
2044 SmXMLFlatDocContext_Impl::~SmXMLFlatDocContext_Impl()
2048 SvXMLImportContext
*SmXMLFlatDocContext_Impl::CreateChildContext(
2049 sal_uInt16 i_nPrefix
, const OUString
& i_rLocalName
,
2050 const uno::Reference
<xml::sax::XAttributeList
>& i_xAttrList
)
2052 // behave like meta base class iff we encounter office:meta
2053 if ( XML_NAMESPACE_OFFICE
== i_nPrefix
&&
2054 i_rLocalName
== GetXMLToken(XML_META
) )
2056 return SvXMLMetaDocumentContext::CreateChildContext(
2057 i_nPrefix
, i_rLocalName
, i_xAttrList
);
2061 return SmXMLOfficeContext_Impl::CreateChildContext(
2062 i_nPrefix
, i_rLocalName
, i_xAttrList
);
2066 ////////////////////////////////////////////////////////////
2068 static __FAR_DATA SvXMLTokenMapEntry aPresLayoutElemTokenMap
[] =
2070 { XML_NAMESPACE_MATH
, XML_SEMANTICS
, XML_TOK_SEMANTICS
},
2071 { XML_NAMESPACE_MATH
, XML_MATH
, XML_TOK_MATH
},
2072 { XML_NAMESPACE_MATH
, XML_MSTYLE
, XML_TOK_MSTYLE
},
2073 { XML_NAMESPACE_MATH
, XML_MERROR
, XML_TOK_MERROR
},
2074 { XML_NAMESPACE_MATH
, XML_MPHANTOM
, XML_TOK_MPHANTOM
},
2075 { XML_NAMESPACE_MATH
, XML_MROW
, XML_TOK_MROW
},
2076 { XML_NAMESPACE_MATH
, XML_MFRAC
, XML_TOK_MFRAC
},
2077 { XML_NAMESPACE_MATH
, XML_MSQRT
, XML_TOK_MSQRT
},
2078 { XML_NAMESPACE_MATH
, XML_MROOT
, XML_TOK_MROOT
},
2079 { XML_NAMESPACE_MATH
, XML_MSUB
, XML_TOK_MSUB
},
2080 { XML_NAMESPACE_MATH
, XML_MSUP
, XML_TOK_MSUP
},
2081 { XML_NAMESPACE_MATH
, XML_MSUBSUP
, XML_TOK_MSUBSUP
},
2082 { XML_NAMESPACE_MATH
, XML_MUNDER
, XML_TOK_MUNDER
},
2083 { XML_NAMESPACE_MATH
, XML_MOVER
, XML_TOK_MOVER
},
2084 { XML_NAMESPACE_MATH
, XML_MUNDEROVER
, XML_TOK_MUNDEROVER
},
2085 { XML_NAMESPACE_MATH
, XML_MMULTISCRIPTS
, XML_TOK_MMULTISCRIPTS
},
2086 { XML_NAMESPACE_MATH
, XML_MTABLE
, XML_TOK_MTABLE
},
2087 { XML_NAMESPACE_MATH
, XML_MACTION
, XML_TOK_MACTION
},
2088 { XML_NAMESPACE_MATH
, XML_MFENCED
, XML_TOK_MFENCED
},
2089 { XML_NAMESPACE_MATH
, XML_MPADDED
, XML_TOK_MPADDED
},
2093 static __FAR_DATA SvXMLTokenMapEntry aPresLayoutAttrTokenMap
[] =
2095 { XML_NAMESPACE_MATH
, XML_FONTWEIGHT
, XML_TOK_FONTWEIGHT
},
2096 { XML_NAMESPACE_MATH
, XML_FONTSTYLE
, XML_TOK_FONTSTYLE
},
2097 { XML_NAMESPACE_MATH
, XML_FONTSIZE
, XML_TOK_FONTSIZE
},
2098 { XML_NAMESPACE_MATH
, XML_FONTFAMILY
, XML_TOK_FONTFAMILY
},
2099 { XML_NAMESPACE_MATH
, XML_COLOR
, XML_TOK_COLOR
},
2103 static __FAR_DATA SvXMLTokenMapEntry aFencedAttrTokenMap
[] =
2105 { XML_NAMESPACE_MATH
, XML_OPEN
, XML_TOK_OPEN
},
2106 { XML_NAMESPACE_MATH
, XML_CLOSE
, XML_TOK_CLOSE
},
2110 static __FAR_DATA SvXMLTokenMapEntry aOperatorAttrTokenMap
[] =
2112 { XML_NAMESPACE_MATH
, XML_STRETCHY
, XML_TOK_STRETCHY
},
2116 static __FAR_DATA SvXMLTokenMapEntry aAnnotationAttrTokenMap
[] =
2118 { XML_NAMESPACE_MATH
, XML_ENCODING
, XML_TOK_ENCODING
},
2123 static __FAR_DATA SvXMLTokenMapEntry aPresElemTokenMap
[] =
2125 { XML_NAMESPACE_MATH
, XML_ANNOTATION
, XML_TOK_ANNOTATION
},
2126 { XML_NAMESPACE_MATH
, XML_MI
, XML_TOK_MI
},
2127 { XML_NAMESPACE_MATH
, XML_MN
, XML_TOK_MN
},
2128 { XML_NAMESPACE_MATH
, XML_MO
, XML_TOK_MO
},
2129 { XML_NAMESPACE_MATH
, XML_MTEXT
, XML_TOK_MTEXT
},
2130 { XML_NAMESPACE_MATH
, XML_MSPACE
,XML_TOK_MSPACE
},
2131 { XML_NAMESPACE_MATH
, XML_MS
, XML_TOK_MS
},
2132 { XML_NAMESPACE_MATH
, XML_MALIGNGROUP
, XML_TOK_MALIGNGROUP
},
2136 static __FAR_DATA SvXMLTokenMapEntry aPresScriptEmptyElemTokenMap
[] =
2138 { XML_NAMESPACE_MATH
, XML_MPRESCRIPTS
, XML_TOK_MPRESCRIPTS
},
2139 { XML_NAMESPACE_MATH
, XML_NONE
, XML_TOK_NONE
},
2143 static __FAR_DATA SvXMLTokenMapEntry aPresTableElemTokenMap
[] =
2145 { XML_NAMESPACE_MATH
, XML_MTR
, XML_TOK_MTR
},
2146 { XML_NAMESPACE_MATH
, XML_MTD
, XML_TOK_MTD
},
2150 static __FAR_DATA SvXMLTokenMapEntry aColorTokenMap
[] =
2152 { XML_NAMESPACE_MATH
, XML_BLACK
, TBLACK
},
2153 { XML_NAMESPACE_MATH
, XML_WHITE
, TWHITE
},
2154 { XML_NAMESPACE_MATH
, XML_RED
, TRED
},
2155 { XML_NAMESPACE_MATH
, XML_GREEN
, TGREEN
},
2156 { XML_NAMESPACE_MATH
, XML_BLUE
, TBLUE
},
2157 { XML_NAMESPACE_MATH
, XML_AQUA
, TCYAN
},
2158 { XML_NAMESPACE_MATH
, XML_FUCHSIA
, TMAGENTA
},
2159 { XML_NAMESPACE_MATH
, XML_YELLOW
, TYELLOW
},
2164 ////////////////////////////////////////////////////////////
2166 const SvXMLTokenMap
& SmXMLImport::GetPresLayoutElemTokenMap()
2168 if (!pPresLayoutElemTokenMap
)
2169 pPresLayoutElemTokenMap
= new SvXMLTokenMap(aPresLayoutElemTokenMap
);
2170 return *pPresLayoutElemTokenMap
;
2173 const SvXMLTokenMap
& SmXMLImport::GetPresLayoutAttrTokenMap()
2175 if (!pPresLayoutAttrTokenMap
)
2176 pPresLayoutAttrTokenMap
= new SvXMLTokenMap(aPresLayoutAttrTokenMap
);
2177 return *pPresLayoutAttrTokenMap
;
2181 const SvXMLTokenMap
& SmXMLImport::GetFencedAttrTokenMap()
2183 if (!pFencedAttrTokenMap
)
2184 pFencedAttrTokenMap
= new SvXMLTokenMap(aFencedAttrTokenMap
);
2185 return *pFencedAttrTokenMap
;
2188 const SvXMLTokenMap
& SmXMLImport::GetOperatorAttrTokenMap()
2190 if (!pOperatorAttrTokenMap
)
2191 pOperatorAttrTokenMap
= new SvXMLTokenMap(aOperatorAttrTokenMap
);
2192 return *pOperatorAttrTokenMap
;
2195 const SvXMLTokenMap
& SmXMLImport::GetAnnotationAttrTokenMap()
2197 if (!pAnnotationAttrTokenMap
)
2198 pAnnotationAttrTokenMap
= new SvXMLTokenMap(aAnnotationAttrTokenMap
);
2199 return *pAnnotationAttrTokenMap
;
2202 const SvXMLTokenMap
& SmXMLImport::GetPresElemTokenMap()
2204 if (!pPresElemTokenMap
)
2205 pPresElemTokenMap
= new SvXMLTokenMap(aPresElemTokenMap
);
2206 return *pPresElemTokenMap
;
2209 const SvXMLTokenMap
& SmXMLImport::GetPresScriptEmptyElemTokenMap()
2211 if (!pPresScriptEmptyElemTokenMap
)
2212 pPresScriptEmptyElemTokenMap
= new
2213 SvXMLTokenMap(aPresScriptEmptyElemTokenMap
);
2214 return *pPresScriptEmptyElemTokenMap
;
2217 const SvXMLTokenMap
& SmXMLImport::GetPresTableElemTokenMap()
2219 if (!pPresTableElemTokenMap
)
2220 pPresTableElemTokenMap
= new SvXMLTokenMap(aPresTableElemTokenMap
);
2221 return *pPresTableElemTokenMap
;
2224 const SvXMLTokenMap
& SmXMLImport::GetColorTokenMap()
2226 if (!pColorTokenMap
)
2227 pColorTokenMap
= new SvXMLTokenMap(aColorTokenMap
);
2228 return *pColorTokenMap
;
2231 ////////////////////////////////////////////////////////////
2233 SvXMLImportContext
*SmXMLDocContext_Impl::CreateChildContext(
2235 const OUString
& rLocalName
,
2236 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
2238 SvXMLImportContext
* pContext
= 0L;
2240 const SvXMLTokenMap
& rTokenMap
= GetSmImport().GetPresLayoutElemTokenMap();
2242 //sal_uInt32 nTest = rTokenMap.Get(nPrefix, rLocalName);
2244 switch(rTokenMap
.Get(nPrefix
, rLocalName
))
2246 //Consider semantics a dummy except for any starmath annotations
2247 case XML_TOK_SEMANTICS
:
2248 pContext
= GetSmImport().CreateRowContext(nPrefix
,rLocalName
,
2251 /*General Layout Schemata*/
2253 pContext
= GetSmImport().CreateRowContext(nPrefix
,rLocalName
,
2257 pContext
= GetSmImport().CreateFracContext(nPrefix
,rLocalName
,
2261 pContext
= GetSmImport().CreateSqrtContext(nPrefix
,rLocalName
,
2265 pContext
= GetSmImport().CreateRootContext(nPrefix
,rLocalName
,
2268 case XML_TOK_MSTYLE
:
2269 pContext
= GetSmImport().CreateStyleContext(nPrefix
,rLocalName
,
2272 case XML_TOK_MERROR
:
2273 pContext
= GetSmImport().CreateErrorContext(nPrefix
,rLocalName
,
2276 case XML_TOK_MPADDED
:
2277 pContext
= GetSmImport().CreatePaddedContext(nPrefix
,rLocalName
,
2280 case XML_TOK_MPHANTOM
:
2281 pContext
= GetSmImport().CreatePhantomContext(nPrefix
,rLocalName
,
2284 case XML_TOK_MFENCED
:
2285 pContext
= GetSmImport().CreateFencedContext(nPrefix
,rLocalName
,
2288 /*Script and Limit Schemata*/
2290 pContext
= GetSmImport().CreateSubContext(nPrefix
,rLocalName
,
2294 pContext
= GetSmImport().CreateSupContext(nPrefix
,rLocalName
,
2297 case XML_TOK_MSUBSUP
:
2298 pContext
= GetSmImport().CreateSubSupContext(nPrefix
,rLocalName
,
2301 case XML_TOK_MUNDER
:
2302 pContext
= GetSmImport().CreateUnderContext(nPrefix
,rLocalName
,
2306 pContext
= GetSmImport().CreateOverContext(nPrefix
,rLocalName
,
2309 case XML_TOK_MUNDEROVER
:
2310 pContext
= GetSmImport().CreateUnderOverContext(nPrefix
,rLocalName
,
2313 case XML_TOK_MMULTISCRIPTS
:
2314 pContext
= GetSmImport().CreateMultiScriptsContext(nPrefix
,
2315 rLocalName
, xAttrList
);
2317 case XML_TOK_MTABLE
:
2318 pContext
= GetSmImport().CreateTableContext(nPrefix
,
2319 rLocalName
, xAttrList
);
2321 case XML_TOK_MACTION
:
2322 pContext
= GetSmImport().CreateActionContext(nPrefix
,
2323 rLocalName
, xAttrList
);
2326 /*Basically theres an implicit mrow around certain bare
2327 *elements, use a RowContext to see if this is one of
2329 SmXMLRowContext_Impl
aTempContext(GetSmImport(),nPrefix
,
2330 GetXMLToken(XML_MROW
));
2332 pContext
= aTempContext
.StrictCreateChildContext(nPrefix
,
2333 rLocalName
, xAttrList
);
2339 void SmXMLDocContext_Impl::EndElement()
2341 SmNodeArray ContextArray
;
2342 ContextArray
.resize(1);
2343 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2345 for (sal_uLong i
=0;i
< 1;i
++)
2346 ContextArray
[i
] = rNodeStack
.Pop();
2349 SmStructureNode
*pSNode
= new SmLineNode(aDummy
);
2350 pSNode
->SetSubNodes(ContextArray
);
2351 rNodeStack
.Push(pSNode
);
2353 SmNodeArray LineArray
;
2354 sal_uLong n
= rNodeStack
.Count();
2355 LineArray
.resize(n
);
2356 for (sal_uLong j
= 0; j
< n
; j
++)
2357 LineArray
[n
- (j
+ 1)] = rNodeStack
.Pop();
2358 SmStructureNode
*pSNode2
= new SmTableNode(aDummy
);
2359 pSNode2
->SetSubNodes(LineArray
);
2360 rNodeStack
.Push(pSNode2
);
2363 void SmXMLFracContext_Impl::EndElement()
2365 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2366 const bool bNodeCheck
= rNodeStack
.Count() - nElementCount
== 2;
2367 DBG_ASSERT( bNodeCheck
, "Fraction (mfrac) tag is missing component" );
2372 aToken
.cMathChar
= '\0';
2375 aToken
.eType
= TOVER
;
2376 SmStructureNode
*pSNode
= new SmBinVerNode(aToken
);
2377 SmNode
*pOper
= new SmRectangleNode(aToken
);
2378 SmNode
*pSecond
= rNodeStack
.Pop();
2379 SmNode
*pFirst
= rNodeStack
.Pop();
2380 pSNode
->SetSubNodes(pFirst
,pOper
,pSecond
);
2381 rNodeStack
.Push(pSNode
);
2384 void SmXMLRootContext_Impl::EndElement()
2386 /*The <mroot> element requires exactly 2 arguments.*/
2387 const bool bNodeCheck
= GetSmImport().GetNodeStack().Count() - nElementCount
== 2;
2388 DBG_ASSERT( bNodeCheck
, "Root tag is missing component" );
2393 aToken
.cMathChar
= MS_SQRT
; //Temporary: alert, based on StarSymbol font
2396 aToken
.eType
= TNROOT
;
2397 SmStructureNode
*pSNode
= new SmRootNode(aToken
);
2398 SmNode
*pOper
= new SmRootSymbolNode(aToken
);
2399 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2400 SmNode
*pIndex
= rNodeStack
.Pop();
2401 SmNode
*pBase
= rNodeStack
.Pop();
2402 pSNode
->SetSubNodes(pIndex
,pOper
,pBase
);
2403 rNodeStack
.Push(pSNode
);
2406 void SmXMLSqrtContext_Impl::EndElement()
2409 <msqrt> accepts any number of arguments; if this number is not 1, its
2410 contents are treated as a single "inferred <mrow>" containing its
2413 if (GetSmImport().GetNodeStack().Count() - nElementCount
> 1)
2414 SmXMLRowContext_Impl::EndElement();
2417 aToken
.cMathChar
= MS_SQRT
; //Temporary: alert, based on StarSymbol font
2420 aToken
.eType
= TSQRT
;
2421 SmStructureNode
*pSNode
= new SmRootNode(aToken
);
2422 SmNode
*pOper
= new SmRootSymbolNode(aToken
);
2423 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2424 pSNode
->SetSubNodes(0,pOper
,rNodeStack
.Pop());
2425 rNodeStack
.Push(pSNode
);
2428 void SmXMLRowContext_Impl::EndElement()
2430 SmNodeArray aRelationArray
;
2431 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2432 sal_uLong nSize
= rNodeStack
.Count()-nElementCount
;
2436 aRelationArray
.resize(nSize
);
2437 for (sal_uLong j
=rNodeStack
.Count()-nElementCount
;j
> 0;j
--)
2438 aRelationArray
[j
-1] = rNodeStack
.Pop();
2441 //If the first or last element is an operator with stretchyness
2442 //set then we must create a brace node here from those elements,
2443 //removing the stretchness from the operators and applying it to
2444 //ourselves, and creating the appropiate dummy StarMath none bracket
2445 //to balance the arrangement
2446 if (((aRelationArray
[0]->GetScaleMode() == SCALE_HEIGHT
)
2447 && (aRelationArray
[0]->GetType() == NMATH
))
2448 || ((aRelationArray
[nSize
-1]->GetScaleMode() == SCALE_HEIGHT
)
2449 && (aRelationArray
[nSize
-1]->GetType() == NMATH
)))
2452 aToken
.cMathChar
= '\0';
2456 int nLeft
=0,nRight
=0;
2457 if ((aRelationArray
[0]->GetScaleMode() == SCALE_HEIGHT
)
2458 && (aRelationArray
[0]->GetType() == NMATH
))
2460 aToken
= aRelationArray
[0]->GetToken();
2464 aToken
.cMathChar
= '\0';
2466 aToken
.eType
= TLPARENT
;
2467 SmNode
*pLeft
= new SmMathSymbolNode(aToken
);
2469 if ((aRelationArray
[nSize
-1]->GetScaleMode() == SCALE_HEIGHT
)
2470 && (aRelationArray
[nSize
-1]->GetType() == NMATH
))
2472 aToken
= aRelationArray
[nSize
-1]->GetToken();
2476 aToken
.cMathChar
= '\0';
2478 aToken
.eType
= TRPARENT
;
2479 SmNode
*pRight
= new SmMathSymbolNode(aToken
);
2481 SmNodeArray aRelationArray2
;
2483 //!! nSize-nLeft-nRight may be < 0 !!
2484 int nRelArrSize
= nSize
-nLeft
-nRight
;
2485 if (nRelArrSize
> 0)
2487 aRelationArray2
.resize(nRelArrSize
);
2488 for (int i
=0;i
< nRelArrSize
;i
++)
2489 aRelationArray2
[i
] = aRelationArray
[i
+nLeft
];
2493 SmStructureNode
*pSNode
= new SmBraceNode(aToken
);
2494 SmStructureNode
*pBody
= new SmExpressionNode(aDummy
);
2495 pBody
->SetSubNodes(aRelationArray2
);
2497 pSNode
->SetSubNodes(pLeft
,pBody
,pRight
);
2498 pSNode
->SetScaleMode(SCALE_HEIGHT
);
2499 rNodeStack
.Push(pSNode
);
2503 else //Multiple newlines result in empty row elements
2505 aRelationArray
.resize(1);
2507 aToken
.cMathChar
= '\0';
2510 aToken
.eType
= TNEWLINE
;
2511 aRelationArray
[0] = new SmLineNode(aToken
);
2515 SmStructureNode
*pSNode
= new SmExpressionNode(aDummy
);
2516 pSNode
->SetSubNodes(aRelationArray
);
2517 rNodeStack
.Push(pSNode
);
2521 SvXMLImportContext
*SmXMLRowContext_Impl::StrictCreateChildContext(
2523 const OUString
& rLocalName
,
2524 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
2526 SvXMLImportContext
* pContext
= 0L;
2528 const SvXMLTokenMap
& rTokenMap
= GetSmImport().GetPresElemTokenMap();
2529 switch(rTokenMap
.Get(nPrefix
, rLocalName
))
2531 /*Note that these should accept malignmark subelements, but do not*/
2533 pContext
= GetSmImport().CreateNumberContext(nPrefix
,rLocalName
,
2537 pContext
= GetSmImport().CreateIdentifierContext(nPrefix
,rLocalName
,
2541 pContext
= GetSmImport().CreateOperatorContext(nPrefix
,rLocalName
,
2545 pContext
= GetSmImport().CreateTextContext(nPrefix
,rLocalName
,
2548 case XML_TOK_MSPACE
:
2549 pContext
= GetSmImport().CreateSpaceContext(nPrefix
,rLocalName
,
2553 pContext
= GetSmImport().CreateStringContext(nPrefix
,rLocalName
,
2557 /*Note: The maligngroup should only be seen when the row
2558 * (or decendants) are in a table*/
2559 case XML_TOK_MALIGNGROUP
:
2560 pContext
= GetSmImport().CreateAlignGroupContext(nPrefix
,rLocalName
,
2564 case XML_TOK_ANNOTATION
:
2565 pContext
= GetSmImport().CreateAnnotationContext(nPrefix
,rLocalName
,
2576 SvXMLImportContext
*SmXMLRowContext_Impl::CreateChildContext(
2578 const OUString
& rLocalName
,
2579 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
2581 SvXMLImportContext
* pContext
= StrictCreateChildContext(nPrefix
,
2582 rLocalName
, xAttrList
);
2586 //Hmm, unrecognized for this level, check to see if its
2587 //an element that can have an implicit schema around it
2588 pContext
= SmXMLDocContext_Impl::CreateChildContext(nPrefix
,
2589 rLocalName
,xAttrList
);
2595 SvXMLImportContext
*SmXMLMultiScriptsContext_Impl::CreateChildContext(
2597 const OUString
& rLocalName
,
2598 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
2600 SvXMLImportContext
* pContext
= 0L;
2602 const SvXMLTokenMap
& rTokenMap
= GetSmImport().
2603 GetPresScriptEmptyElemTokenMap();
2604 switch(rTokenMap
.Get(nPrefix
, rLocalName
))
2606 case XML_TOK_MPRESCRIPTS
:
2608 pContext
= GetSmImport().CreatePrescriptsContext(nPrefix
,
2609 rLocalName
, xAttrList
);
2612 pContext
= GetSmImport().CreateNoneContext(nPrefix
,rLocalName
,
2616 pContext
= SmXMLRowContext_Impl::CreateChildContext(nPrefix
,
2617 rLocalName
,xAttrList
);
2623 void SmXMLMultiScriptsContext_Impl::MiddleElement()
2625 bHasPrescripts
=sal_True
;
2627 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2628 DBG_ASSERT( rNodeStack
.Count() - nElementCount
> 0, "Sub has no arguments" );
2629 if (rNodeStack
.Count()-nElementCount
> 1)
2632 aToken
.cMathChar
= '\0';
2635 aToken
.eType
= TRSUB
;
2636 sal_uLong nFinalCount
= rNodeStack
.Count()-nElementCount
-1;
2638 SmNodeStack aReverseStack
;
2639 while (rNodeStack
.Count()-nElementCount
)
2641 SmNode
*pThing
= rNodeStack
.Pop();
2642 aReverseStack
.Push(pThing
);
2645 for (sal_uLong nCount
=0;nCount
< nFinalCount
;nCount
+=2)
2647 SmSubSupNode
*pNode
= new SmSubSupNode(aToken
);
2649 // initialize subnodes array
2650 SmNodeArray aSubNodes
;
2651 aSubNodes
.resize(1 + SUBSUP_NUM_ENTRIES
);
2652 for (sal_uLong i
= 1; i
< aSubNodes
.size(); i
++)
2653 aSubNodes
[i
] = NULL
;
2655 /*On each loop the base and its sub sup pair becomes the
2656 base for the next loop to which the next sub sup pair is
2657 attached, i.e. wheels within wheels*/
2659 aSubNodes
[0] = aReverseStack
.Pop();
2661 SmNode
*pScriptNode
= aReverseStack
.Pop();
2663 if (pScriptNode
&& ((pScriptNode
->GetToken().eType
!= TIDENT
) ||
2664 (pScriptNode
->GetToken().aText
.Len())))
2665 aSubNodes
[RSUB
+1] = pScriptNode
;
2666 pScriptNode
= aReverseStack
.Pop();
2667 if (pScriptNode
&& ((pScriptNode
->GetToken().eType
!= TIDENT
) ||
2668 (pScriptNode
->GetToken().aText
.Len())))
2669 aSubNodes
[RSUP
+1] = pScriptNode
;
2671 pNode
->SetSubNodes(aSubNodes
);
2672 aReverseStack
.Push(pNode
);
2674 rNodeStack
.Push(aReverseStack
.Pop());
2679 void SmXMLTableContext_Impl::EndElement()
2681 SmNodeArray aExpressionArray
;
2682 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2683 SmNodeStack aReverseStack
;
2684 aExpressionArray
.resize(rNodeStack
.Count()-nElementCount
);
2686 sal_uLong nRows
= rNodeStack
.Count()-nElementCount
;
2687 sal_uInt16 nCols
= 0;
2689 SmStructureNode
*pArray
;
2690 for (sal_uLong i
=rNodeStack
.Count()-nElementCount
;i
> 0;i
--)
2692 pArray
= (SmStructureNode
*)rNodeStack
.Pop();
2693 if (pArray
->GetNumSubNodes() == 0)
2695 //This is a little tricky, it is possible that there was
2696 //be elements that were not inside a <mtd> pair, in which
2697 //case they will not be in a row, i.e. they will not have
2698 //SubNodes, so we have to wait until here before we can
2699 //resolve the situation. Implicitsurrounding tags are
2700 //surprisingly difficult to get right within this
2703 SmNodeArray aRelationArray
;
2704 aRelationArray
.resize(1);
2705 aRelationArray
[0] = pArray
;
2707 pArray
= new SmExpressionNode(aDummy
);
2708 pArray
->SetSubNodes(aRelationArray
);
2711 if (pArray
->GetNumSubNodes() > nCols
)
2712 nCols
= pArray
->GetNumSubNodes();
2713 aReverseStack
.Push(pArray
);
2715 aExpressionArray
.resize(nCols
*nRows
);
2717 while (aReverseStack
.Count())
2719 pArray
= (SmStructureNode
*)aReverseStack
.Pop();
2720 for (sal_uInt16 i
=0;i
<pArray
->GetNumSubNodes();i
++)
2721 aExpressionArray
[j
++] = pArray
->GetSubNode(i
);
2725 aToken
.cMathChar
= '\0';
2726 aToken
.nGroup
= TRGROUP
;
2728 aToken
.eType
= TMATRIX
;
2729 SmMatrixNode
*pSNode
= new SmMatrixNode(aToken
);
2730 pSNode
->SetSubNodes(aExpressionArray
);
2731 pSNode
->SetRowCol(static_cast<sal_uInt16
>(nRows
),nCols
);
2732 rNodeStack
.Push(pSNode
);
2735 SvXMLImportContext
*SmXMLTableRowContext_Impl::CreateChildContext(
2737 const OUString
& rLocalName
,
2738 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
2740 SvXMLImportContext
* pContext
= 0L;
2742 const SvXMLTokenMap
& rTokenMap
= GetSmImport().
2743 GetPresTableElemTokenMap();
2744 switch(rTokenMap
.Get(nPrefix
, rLocalName
))
2747 pContext
= GetSmImport().CreateTableCellContext(nPrefix
,
2748 rLocalName
, xAttrList
);
2751 pContext
= SmXMLRowContext_Impl::CreateChildContext(nPrefix
,
2752 rLocalName
,xAttrList
);
2758 SvXMLImportContext
*SmXMLTableContext_Impl::CreateChildContext(
2760 const OUString
& rLocalName
,
2761 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
2763 SvXMLImportContext
* pContext
= 0L;
2765 const SvXMLTokenMap
& rTokenMap
= GetSmImport().
2766 GetPresTableElemTokenMap();
2767 switch(rTokenMap
.Get(nPrefix
, rLocalName
))
2770 pContext
= GetSmImport().CreateTableRowContext(nPrefix
,rLocalName
,
2774 pContext
= SmXMLTableRowContext_Impl::CreateChildContext(nPrefix
,
2775 rLocalName
,xAttrList
);
2781 void SmXMLMultiScriptsContext_Impl::EndElement()
2783 if (!bHasPrescripts
)
2786 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2787 if (rNodeStack
.Count()-nElementCount
> 1)
2790 aToken
.cMathChar
= '\0';
2793 aToken
.eType
= TLSUB
;
2794 sal_uLong nFinalCount
= rNodeStack
.Count()-nElementCount
-1;
2796 SmNodeStack aReverseStack
;
2797 while (rNodeStack
.Count()-nElementCount
)
2798 aReverseStack
.Push(rNodeStack
.Pop());
2799 for (sal_uLong nCount
=0;nCount
< nFinalCount
;nCount
+=2)
2801 SmSubSupNode
*pNode
= new SmSubSupNode(aToken
);
2803 // initialize subnodes array
2804 SmNodeArray aSubNodes
;
2805 aSubNodes
.resize(1 + SUBSUP_NUM_ENTRIES
);
2806 for (sal_uLong i
= 1; i
< aSubNodes
.size(); i
++)
2807 aSubNodes
[i
] = NULL
;
2809 /*On each loop the base and its sub sup pair becomes the
2810 base for the next loop to which the next sub sup pair is
2811 attached, i.e. wheels within wheels*/
2813 aSubNodes
[0] = aReverseStack
.Pop();
2815 SmNode
*pScriptNode
= aReverseStack
.Pop();
2816 if (pScriptNode
->GetToken().aText
.Len())
2817 aSubNodes
[LSUB
+1] = pScriptNode
;
2818 pScriptNode
= aReverseStack
.Pop();
2819 if (pScriptNode
->GetToken().aText
.Len())
2820 aSubNodes
[LSUP
+1] = pScriptNode
;
2822 pNode
->SetSubNodes(aSubNodes
);
2823 aReverseStack
.Push(pNode
);
2825 rNodeStack
.Push(aReverseStack
.Pop());
2829 void SmXMLActionContext_Impl::EndElement()
2831 /*For now we will just assume that the
2832 selected attribute is one, and then just display
2833 that expression alone, i.e. remove all expect the
2836 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2837 for (sal_uLong i
=rNodeStack
.Count()-nElementCount
;i
> 1;i
--)
2839 delete rNodeStack
.Pop();
2843 SvXMLImportContext
*SmXMLImport::CreateContext(sal_uInt16 nPrefix
,
2844 const OUString
&rLocalName
,
2845 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2847 if ( XML_NAMESPACE_OFFICE
== nPrefix
)
2849 if ( (IsXMLToken(rLocalName
, XML_DOCUMENT
) ||
2850 IsXMLToken(rLocalName
, XML_DOCUMENT_META
)))
2852 uno::Reference
<xml::sax::XDocumentHandler
> xDocBuilder(
2853 mxServiceFactory
->createInstance(
2854 ::rtl::OUString::createFromAscii(
2855 "com.sun.star.xml.dom.SAXDocumentBuilder")),
2856 uno::UNO_QUERY_THROW
);
2857 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
2858 GetModel(), uno::UNO_QUERY_THROW
);
2859 return IsXMLToken(rLocalName
, XML_DOCUMENT_META
)
2860 ? new SvXMLMetaDocumentContext(*this,
2861 XML_NAMESPACE_OFFICE
, rLocalName
,
2862 xDPS
->getDocumentProperties(), xDocBuilder
)
2863 // flat OpenDocument file format -- this has not been tested...
2864 : new SmXMLFlatDocContext_Impl( *this, nPrefix
, rLocalName
,
2865 xDPS
->getDocumentProperties(), xDocBuilder
);
2869 return new SmXMLOfficeContext_Impl( *this,nPrefix
,rLocalName
);
2873 return new SmXMLDocContext_Impl(*this,nPrefix
,rLocalName
);
2876 SvXMLImportContext
*SmXMLImport::CreateRowContext(sal_uInt16 nPrefix
,
2877 const OUString
&rLocalName
,
2878 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2880 return new SmXMLRowContext_Impl(*this,nPrefix
,rLocalName
);
2883 SvXMLImportContext
*SmXMLImport::CreateTextContext(sal_uInt16 nPrefix
,
2884 const OUString
&rLocalName
,
2885 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2887 return new SmXMLTextContext_Impl(*this,nPrefix
,rLocalName
);
2890 SvXMLImportContext
*SmXMLImport::CreateAnnotationContext(sal_uInt16 nPrefix
,
2891 const OUString
&rLocalName
,
2892 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2894 return new SmXMLAnnotationContext_Impl(*this,nPrefix
,rLocalName
);
2897 SvXMLImportContext
*SmXMLImport::CreateStringContext(sal_uInt16 nPrefix
,
2898 const OUString
&rLocalName
,
2899 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2901 return new SmXMLStringContext_Impl(*this,nPrefix
,rLocalName
);
2904 SvXMLImportContext
*SmXMLImport::CreateNumberContext(sal_uInt16 nPrefix
,
2905 const OUString
&rLocalName
,
2906 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2908 return new SmXMLNumberContext_Impl(*this,nPrefix
,rLocalName
);
2911 SvXMLImportContext
*SmXMLImport::CreateIdentifierContext(sal_uInt16 nPrefix
,
2912 const OUString
&rLocalName
,
2913 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2915 return new SmXMLIdentifierContext_Impl(*this,nPrefix
,rLocalName
);
2918 SvXMLImportContext
*SmXMLImport::CreateOperatorContext(sal_uInt16 nPrefix
,
2919 const OUString
&rLocalName
,
2920 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2922 return new SmXMLOperatorContext_Impl(*this,nPrefix
,rLocalName
);
2925 SvXMLImportContext
*SmXMLImport::CreateSpaceContext(sal_uInt16 nPrefix
,
2926 const OUString
&rLocalName
,
2927 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2929 return new SmXMLSpaceContext_Impl(*this,nPrefix
,rLocalName
);
2933 SvXMLImportContext
*SmXMLImport::CreateFracContext(sal_uInt16 nPrefix
,
2934 const OUString
&rLocalName
,
2935 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2937 return new SmXMLFracContext_Impl(*this,nPrefix
,rLocalName
);
2940 SvXMLImportContext
*SmXMLImport::CreateSqrtContext(sal_uInt16 nPrefix
,
2941 const OUString
&rLocalName
,
2942 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2944 return new SmXMLSqrtContext_Impl(*this,nPrefix
,rLocalName
);
2947 SvXMLImportContext
*SmXMLImport::CreateRootContext(sal_uInt16 nPrefix
,
2948 const OUString
&rLocalName
,
2949 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2951 return new SmXMLRootContext_Impl(*this,nPrefix
,rLocalName
);
2954 SvXMLImportContext
*SmXMLImport::CreateStyleContext(sal_uInt16 nPrefix
,
2955 const OUString
&rLocalName
,
2956 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2958 return new SmXMLStyleContext_Impl(*this,nPrefix
,rLocalName
);
2961 SvXMLImportContext
*SmXMLImport::CreatePaddedContext(sal_uInt16 nPrefix
,
2962 const OUString
&rLocalName
,
2963 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2965 return new SmXMLPaddedContext_Impl(*this,nPrefix
,rLocalName
);
2968 SvXMLImportContext
*SmXMLImport::CreatePhantomContext(sal_uInt16 nPrefix
,
2969 const OUString
&rLocalName
,
2970 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2972 return new SmXMLPhantomContext_Impl(*this,nPrefix
,rLocalName
);
2975 SvXMLImportContext
*SmXMLImport::CreateFencedContext(sal_uInt16 nPrefix
,
2976 const OUString
&rLocalName
,
2977 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2979 return new SmXMLFencedContext_Impl(*this,nPrefix
,rLocalName
);
2982 SvXMLImportContext
*SmXMLImport::CreateErrorContext(sal_uInt16 nPrefix
,
2983 const OUString
&rLocalName
,
2984 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2986 return new SmXMLErrorContext_Impl(*this,nPrefix
,rLocalName
);
2989 SvXMLImportContext
*SmXMLImport::CreateSubContext(sal_uInt16 nPrefix
,
2990 const OUString
&rLocalName
,
2991 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2993 return new SmXMLSubContext_Impl(*this,nPrefix
,rLocalName
);
2996 SvXMLImportContext
*SmXMLImport::CreateSubSupContext(sal_uInt16 nPrefix
,
2997 const OUString
&rLocalName
,
2998 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3000 return new SmXMLSubSupContext_Impl(*this,nPrefix
,rLocalName
);
3003 SvXMLImportContext
*SmXMLImport::CreateSupContext(sal_uInt16 nPrefix
,
3004 const OUString
&rLocalName
,
3005 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3007 return new SmXMLSupContext_Impl(*this,nPrefix
,rLocalName
);
3010 SvXMLImportContext
*SmXMLImport::CreateUnderContext(sal_uInt16 nPrefix
,
3011 const OUString
&rLocalName
,
3012 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3014 return new SmXMLUnderContext_Impl(*this,nPrefix
,rLocalName
);
3017 SvXMLImportContext
*SmXMLImport::CreateOverContext(sal_uInt16 nPrefix
,
3018 const OUString
&rLocalName
,
3019 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3021 return new SmXMLOverContext_Impl(*this,nPrefix
,rLocalName
);
3024 SvXMLImportContext
*SmXMLImport::CreateUnderOverContext(sal_uInt16 nPrefix
,
3025 const OUString
&rLocalName
,
3026 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3028 return new SmXMLUnderOverContext_Impl(*this,nPrefix
,rLocalName
);
3031 SvXMLImportContext
*SmXMLImport::CreateMultiScriptsContext(sal_uInt16 nPrefix
,
3032 const OUString
&rLocalName
,
3033 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3035 return new SmXMLMultiScriptsContext_Impl(*this,nPrefix
,rLocalName
);
3038 SvXMLImportContext
*SmXMLImport::CreateTableContext(sal_uInt16 nPrefix
,
3039 const OUString
&rLocalName
,
3040 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3042 return new SmXMLTableContext_Impl(*this,nPrefix
,rLocalName
);
3044 SvXMLImportContext
*SmXMLImport::CreateTableRowContext(sal_uInt16 nPrefix
,
3045 const OUString
&rLocalName
,
3046 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3048 return new SmXMLTableRowContext_Impl(*this,nPrefix
,rLocalName
);
3050 SvXMLImportContext
*SmXMLImport::CreateTableCellContext(sal_uInt16 nPrefix
,
3051 const OUString
&rLocalName
,
3052 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3054 return new SmXMLTableCellContext_Impl(*this,nPrefix
,rLocalName
);
3057 SvXMLImportContext
*SmXMLImport::CreateNoneContext(sal_uInt16 nPrefix
,
3058 const OUString
&rLocalName
,
3059 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3061 return new SmXMLNoneContext_Impl(*this,nPrefix
,rLocalName
);
3064 SvXMLImportContext
*SmXMLImport::CreatePrescriptsContext(sal_uInt16 nPrefix
,
3065 const OUString
&rLocalName
,
3066 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3068 return new SmXMLPrescriptsContext_Impl(*this,nPrefix
,rLocalName
);
3071 SvXMLImportContext
*SmXMLImport::CreateAlignGroupContext(sal_uInt16 nPrefix
,
3072 const OUString
&rLocalName
,
3073 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3075 return new SmXMLAlignGroupContext_Impl(*this,nPrefix
,rLocalName
);
3078 SvXMLImportContext
*SmXMLImport::CreateActionContext(sal_uInt16 nPrefix
,
3079 const OUString
&rLocalName
,
3080 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3082 return new SmXMLActionContext_Impl(*this,nPrefix
,rLocalName
);
3085 SmXMLImport::~SmXMLImport() throw ()
3087 delete pPresLayoutElemTokenMap
;
3088 delete pPresElemTokenMap
;
3089 delete pPresScriptEmptyElemTokenMap
;
3090 delete pPresTableElemTokenMap
;
3091 delete pPresLayoutAttrTokenMap
;
3092 delete pFencedAttrTokenMap
;
3093 delete pColorTokenMap
;
3094 delete pOperatorAttrTokenMap
;
3095 delete pAnnotationAttrTokenMap
;
3098 void SmXMLImport::SetViewSettings(const Sequence
<PropertyValue
>& aViewProps
)
3100 uno::Reference
<frame::XModel
> xModel
= GetModel();
3104 uno::Reference
<lang::XUnoTunnel
> xTunnel
;
3105 xTunnel
= uno::Reference
<lang::XUnoTunnel
> (xModel
,uno::UNO_QUERY
);
3106 SmModel
*pModel
= reinterpret_cast<SmModel
*>
3107 (xTunnel
->getSomething(SmModel::getUnoTunnelId()));
3112 SmDocShell
*pDocShell
=
3113 static_cast<SmDocShell
*>(pModel
->GetObjectShell());
3117 Rectangle
aRect( pDocShell
->GetVisArea() );
3119 sal_Int32 nCount
= aViewProps
.getLength();
3120 const PropertyValue
*pValue
= aViewProps
.getConstArray();
3123 //sal_Bool bShowDeletes = sal_False, bShowInserts = sal_False, bShowFooter = sal_False, bShowHeader = sal_False;
3125 for (sal_Int32 i
= 0; i
< nCount
; i
++)
3127 if (pValue
->Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaTop" ) ) )
3129 pValue
->Value
>>= nTmp
;
3132 else if (pValue
->Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaLeft" ) ) )
3134 pValue
->Value
>>= nTmp
;
3137 else if (pValue
->Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaWidth" ) ) )
3139 pValue
->Value
>>= nTmp
;
3140 Size
aSize( aRect
.GetSize() );
3141 aSize
.Width() = nTmp
;
3142 aRect
.SetSize( aSize
);
3144 else if (pValue
->Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaHeight" ) ) )
3146 pValue
->Value
>>= nTmp
;
3147 Size
aSize( aRect
.GetSize() );
3148 aSize
.Height() = nTmp
;
3149 aRect
.SetSize( aSize
);
3154 pDocShell
->SetVisArea ( aRect
);
3157 void SmXMLImport::SetConfigurationSettings(const Sequence
<PropertyValue
>& aConfProps
)
3159 uno::Reference
< XPropertySet
> xProps ( GetModel(), UNO_QUERY
);
3162 Reference
< XPropertySetInfo
> xInfo ( xProps
->getPropertySetInfo() );
3165 sal_Int32 nCount
= aConfProps
.getLength();
3166 const PropertyValue
* pValues
= aConfProps
.getConstArray();
3168 const OUString
sFormula ( RTL_CONSTASCII_USTRINGPARAM ( "Formula" ) );
3169 const OUString
sBasicLibraries ( RTL_CONSTASCII_USTRINGPARAM ( "BasicLibraries" ) );
3170 const OUString
sDialogLibraries ( RTL_CONSTASCII_USTRINGPARAM ( "DialogLibraries" ) );
3173 if (pValues
->Name
!= sFormula
&&
3174 pValues
->Name
!= sBasicLibraries
&&
3175 pValues
->Name
!= sDialogLibraries
)
3179 if ( xInfo
->hasPropertyByName( pValues
->Name
) )
3180 xProps
->setPropertyValue( pValues
->Name
, pValues
->Value
);
3182 catch (beans::PropertyVetoException
&e
)
3185 // dealing with read-only properties here. Nothing to do...
3187 catch( Exception
& e
)
3190 DBG_ERROR( "SmXMLImport::SetConfigurationSettings: Exception!" );
3201 ////////////////////////////////////////////////////////////