1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_starmath.hxx"
34 /*todo: Change characters and tcharacters to accumulate the characters together
35 into one string, xml parser hands them to us line by line rather than all in
38 #include <com/sun/star/xml/sax/XErrorHandler.hpp>
39 #include <com/sun/star/xml/sax/XEntityResolver.hpp>
40 #include <com/sun/star/xml/sax/InputSource.hpp>
41 #include <com/sun/star/xml/sax/XDTDHandler.hpp>
42 #include <com/sun/star/xml/sax/XParser.hpp>
43 #include <com/sun/star/io/XActiveDataSource.hpp>
44 #include <com/sun/star/io/XActiveDataControl.hpp>
45 #include <com/sun/star/document/XDocumentProperties.hpp>
46 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
47 #include <com/sun/star/packages/zip/ZipIOException.hpp>
48 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
49 #include <com/sun/star/beans/PropertyAttribute.hpp>
50 #include <com/sun/star/container/XNameAccess.hpp>
51 #include <com/sun/star/embed/ElementModes.hpp>
52 #include <com/sun/star/uno/Any.h>
54 #include <rtl/math.hxx>
55 #include <sfx2/frame.hxx>
56 #include <sfx2/docfile.hxx>
57 #include <tools/debug.hxx>
58 #include <tools/urlobj.hxx>
59 #include <svtools/sfxecode.hxx>
60 #include <svtools/saveopt.hxx>
61 #include <svtools/stritem.hxx>
62 #include <svtools/itemprop.hxx>
63 #include <unotools/processfactory.hxx>
64 #include <unotools/streamwrap.hxx>
65 #include <xmloff/xmlnmspe.hxx>
66 #include <xmloff/xmltoken.hxx>
67 #include <xmloff/nmspmap.hxx>
68 #include <xmloff/attrlist.hxx>
69 #include <xmloff/xmluconv.hxx>
70 #include <xmloff/xmlmetai.hxx>
71 #include <osl/mutex.hxx>
72 #include <comphelper/genericpropertyset.hxx>
76 #include "mathmlimport.hxx"
77 #include "mathtype.hxx"
78 #include <starmath.hrc>
79 #include <unomodel.hxx>
80 #include <document.hxx>
81 #include <utility.hxx>
83 using namespace ::com::sun::star::beans
;
84 using namespace ::com::sun::star::container
;
85 using namespace ::com::sun::star::document
;
86 using namespace ::com::sun::star::lang
;
87 using namespace ::com::sun::star::uno
;
88 using namespace ::com::sun::star
;
89 using namespace ::xmloff::token
;
91 using ::rtl::OUString
;
92 using ::rtl::OUStringBuffer
;
94 #define IMPORT_SVC_NAME RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.XMLImportFilter")
98 ////////////////////////////////////////////////////////////
100 ULONG
SmXMLImportWrapper::Import(SfxMedium
&rMedium
)
102 ULONG nError
= ERRCODE_SFX_DOLOADFAILED
;
104 uno::Reference
<lang::XMultiServiceFactory
> xServiceFactory(
105 utl::getProcessServiceFactory());
106 DBG_ASSERT(xServiceFactory
.is(), "XMLReader::Read: got no service manager");
107 if ( !xServiceFactory
.is() )
110 //Make a model component from our SmModel
111 uno::Reference
< lang::XComponent
> xModelComp( xModel
, uno::UNO_QUERY
);
112 DBG_ASSERT( xModelComp
.is(), "XMLReader::Read: got no model" );
114 // try to get an XStatusIndicator from the Medium
115 uno::Reference
<task::XStatusIndicator
> xStatusIndicator
;
117 sal_Bool bEmbedded
= sal_False
;
118 uno::Reference
<lang::XUnoTunnel
> xTunnel
;
119 xTunnel
= uno::Reference
<lang::XUnoTunnel
> (xModel
,uno::UNO_QUERY
);
120 SmModel
*pModel
= reinterpret_cast<SmModel
*>
121 (xTunnel
->getSomething(SmModel::getUnoTunnelId()));
123 SmDocShell
*pDocShell
= pModel
?
124 static_cast<SmDocShell
*>(pModel
->GetObjectShell()) : 0;
127 // if (pDocShell->GetMedium())
129 DBG_ASSERT( pDocShell
->GetMedium() == &rMedium
,
130 "different SfxMedium found" );
132 SfxItemSet
* pSet
= rMedium
.GetItemSet();
135 const SfxUnoAnyItem
* pItem
= static_cast<const SfxUnoAnyItem
*>(
136 pSet
->GetItem(SID_PROGRESS_STATUSBAR_CONTROL
) );
138 pItem
->GetValue() >>= xStatusIndicator
;
142 if ( SFX_CREATE_MODE_EMBEDDED
== pDocShell
->GetCreateMode() )
143 bEmbedded
= sal_True
;
146 comphelper::PropertyMapEntry aInfoMap
[] =
148 { "PrivateData", sizeof("PrivateData")-1, 0,
149 &::getCppuType( (Reference
<XInterface
> *)0 ),
150 beans::PropertyAttribute::MAYBEVOID
, 0 },
151 { "BaseURI", sizeof("BaseURI")-1, 0,
152 &::getCppuType( (OUString
*)0 ),
153 beans::PropertyAttribute::MAYBEVOID
, 0 },
154 { "StreamRelPath", sizeof("StreamRelPath")-1, 0,
155 &::getCppuType( (OUString
*)0 ),
156 beans::PropertyAttribute::MAYBEVOID
, 0 },
157 { "StreamName", sizeof("StreamName")-1, 0,
158 &::getCppuType( (OUString
*)0 ),
159 beans::PropertyAttribute::MAYBEVOID
, 0 },
160 { NULL
, 0, 0, NULL
, 0, 0 }
162 uno::Reference
< beans::XPropertySet
> xInfoSet(
163 comphelper::GenericPropertySet_CreateInstance(
164 new comphelper::PropertySetInfo( aInfoMap
) ) );
167 OUString
sPropName( RTL_CONSTASCII_USTRINGPARAM("BaseURI") );
168 xInfoSet
->setPropertyValue( sPropName
, makeAny( rMedium
.GetBaseURL() ) );
171 if ( !(rMedium
.IsStorage()))
174 sal_Int32
nProgressRange(nSteps
);
175 if (xStatusIndicator
.is())
177 xStatusIndicator
->start(String(SmResId(STR_STATSTR_READING
)),
182 if (xStatusIndicator
.is())
183 xStatusIndicator
->setValue(nSteps
++);
185 if ( rMedium
.IsStorage())
187 // TODO/LATER: handle the case of embedded links gracefully
188 if ( bEmbedded
) // && !rMedium.GetStorage()->IsRoot() )
190 OUString
aName( RTL_CONSTASCII_USTRINGPARAM( "dummyObjName" ) );
191 if ( rMedium
.GetItemSet() )
193 const SfxStringItem
* pDocHierarchItem
= static_cast<const SfxStringItem
*>(
194 rMedium
.GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME
) );
195 if ( pDocHierarchItem
)
196 aName
= pDocHierarchItem
->GetValue();
199 if ( aName
.getLength() )
201 sPropName
= OUString(RTL_CONSTASCII_USTRINGPARAM("StreamRelPath"));
202 xInfoSet
->setPropertyValue( sPropName
, makeAny( aName
) );
206 sal_Bool bOASIS
= ( SotStorage::GetVersion( rMedium
.GetStorage() ) > SOFFICE_FILEFORMAT_60
);
207 if (xStatusIndicator
.is())
208 xStatusIndicator
->setValue(nSteps
++);
210 ULONG nWarn
= ReadThroughComponent(
211 rMedium
.GetStorage(), xModelComp
, "meta.xml", "Meta.xml",
212 xServiceFactory
, xInfoSet
,
213 (bOASIS
? "com.sun.star.comp.Math.XMLOasisMetaImporter"
214 : "com.sun.star.comp.Math.XMLMetaImporter") );
216 if ( nWarn
!= ERRCODE_IO_BROKENPACKAGE
)
218 if (xStatusIndicator
.is())
219 xStatusIndicator
->setValue(nSteps
++);
221 nWarn
= ReadThroughComponent(
222 rMedium
.GetStorage(), xModelComp
, "settings.xml", 0,
223 xServiceFactory
, xInfoSet
,
224 (bOASIS
? "com.sun.star.comp.Math.XMLOasisSettingsImporter"
225 : "com.sun.star.comp.Math.XMLSettingsImporter" ) );
227 if ( nWarn
!= ERRCODE_IO_BROKENPACKAGE
)
229 if (xStatusIndicator
.is())
230 xStatusIndicator
->setValue(nSteps
++);
232 nError
= ReadThroughComponent(
233 rMedium
.GetStorage(), xModelComp
, "content.xml", "Content.xml",
234 xServiceFactory
, xInfoSet
, "com.sun.star.comp.Math.XMLImporter" );
237 nError
= ERRCODE_IO_BROKENPACKAGE
;
240 nError
= ERRCODE_IO_BROKENPACKAGE
;
244 Reference
<io::XInputStream
> xInputStream
=
245 new utl::OInputStreamWrapper(rMedium
.GetInStream());
247 if (xStatusIndicator
.is())
248 xStatusIndicator
->setValue(nSteps
++);
250 nError
= ReadThroughComponent( xInputStream
, xModelComp
,
251 xServiceFactory
, xInfoSet
, "com.sun.star.comp.Math.XMLImporter", FALSE
);
254 if (xStatusIndicator
.is())
255 xStatusIndicator
->end();
260 /// read a component (file + filter version)
261 ULONG
SmXMLImportWrapper::ReadThroughComponent(
262 Reference
<io::XInputStream
> xInputStream
,
263 Reference
<XComponent
> xModelComponent
,
264 Reference
<lang::XMultiServiceFactory
> & rFactory
,
265 Reference
<beans::XPropertySet
> & rPropSet
,
266 const sal_Char
* pFilterName
,
267 sal_Bool bEncrypted
)
269 ULONG nError
= ERRCODE_SFX_DOLOADFAILED
;
270 DBG_ASSERT(xInputStream
.is(), "input stream missing");
271 DBG_ASSERT(xModelComponent
.is(), "document missing");
272 DBG_ASSERT(rFactory
.is(), "factory missing");
273 DBG_ASSERT(NULL
!= pFilterName
,"I need a service name for the component!");
275 // prepare ParserInputSrouce
276 xml::sax::InputSource aParserInput
;
277 aParserInput
.aInputStream
= xInputStream
;
280 Reference
< xml::sax::XParser
> xParser(
281 rFactory
->createInstance(
282 OUString::createFromAscii("com.sun.star.xml.sax.Parser") ),
284 DBG_ASSERT( xParser
.is(), "Can't create parser" );
288 Sequence
<Any
> aArgs( 1 );
289 aArgs
[0] <<= rPropSet
;
292 Reference
< xml::sax::XDocumentHandler
> xFilter(
293 rFactory
->createInstanceWithArguments(
294 OUString::createFromAscii(pFilterName
), aArgs
),
296 DBG_ASSERT( xFilter
.is(), "Can't instantiate filter component." );
300 // connect parser and filter
301 xParser
->setDocumentHandler( xFilter
);
303 // connect model and filter
304 Reference
< XImporter
> xImporter( xFilter
, UNO_QUERY
);
305 xImporter
->setTargetDocument( xModelComponent
);
307 // finally, parser the stream
310 xParser
->parseStream( aParserInput
);
312 uno::Reference
<lang::XUnoTunnel
> xFilterTunnel
;
313 xFilterTunnel
= uno::Reference
<lang::XUnoTunnel
>
314 ( xFilter
, uno::UNO_QUERY
);
315 SmXMLImport
*pFilter
= reinterpret_cast< SmXMLImport
* >(
316 sal::static_int_cast
< sal_uIntPtr
>(
317 xFilterTunnel
->getSomething( SmXMLImport::getUnoTunnelId() )));
318 if ( pFilter
&& pFilter
->GetSuccess() )
321 catch( xml::sax::SAXParseException
& r
)
323 // sax parser sends wrapped exceptions,
324 // try to find the original one
325 xml::sax::SAXException aSaxEx
= *(xml::sax::SAXException
*)(&r
);
326 sal_Bool bTryChild
= sal_True
;
330 xml::sax::SAXException aTmp
;
331 if ( aSaxEx
.WrappedException
>>= aTmp
)
334 bTryChild
= sal_False
;
337 packages::zip::ZipIOException aBrokenPackage
;
338 if ( aSaxEx
.WrappedException
>>= aBrokenPackage
)
339 return ERRCODE_IO_BROKENPACKAGE
;
342 nError
= ERRCODE_SFX_WRONGPASSWORD
;
344 catch( xml::sax::SAXException
& r
)
346 packages::zip::ZipIOException aBrokenPackage
;
347 if ( r
.WrappedException
>>= aBrokenPackage
)
348 return ERRCODE_IO_BROKENPACKAGE
;
351 nError
= ERRCODE_SFX_WRONGPASSWORD
;
353 catch( packages::zip::ZipIOException
& )
355 nError
= ERRCODE_IO_BROKENPACKAGE
;
357 catch( io::IOException
& )
365 ULONG
SmXMLImportWrapper::ReadThroughComponent(
366 const uno::Reference
< embed::XStorage
>& xStorage
,
367 Reference
<XComponent
> xModelComponent
,
368 const sal_Char
* pStreamName
,
369 const sal_Char
* pCompatibilityStreamName
,
370 Reference
<lang::XMultiServiceFactory
> & rFactory
,
371 Reference
<beans::XPropertySet
> & rPropSet
,
372 const sal_Char
* pFilterName
)
374 DBG_ASSERT(xStorage
.is(), "Need storage!");
375 DBG_ASSERT(NULL
!= pStreamName
, "Please, please, give me a name!");
377 // open stream (and set parser input)
378 OUString sStreamName
= OUString::createFromAscii(pStreamName
);
379 uno::Reference
< container::XNameAccess
> xAccess( xStorage
, uno::UNO_QUERY
);
380 if ( !xAccess
->hasByName(sStreamName
) || !xStorage
->isStreamElement(sStreamName
) )
382 // stream name not found! Then try the compatibility name.
383 // do we even have an alternative name?
384 if ( pCompatibilityStreamName
)
385 sStreamName
= OUString::createFromAscii(pCompatibilityStreamName
);
391 uno::Reference
< io::XStream
> xEventsStream
= xStorage
->openStreamElement( sStreamName
, embed::ElementModes::READ
);
393 // determine if stream is encrypted or not
394 uno::Reference
< beans::XPropertySet
> xProps( xEventsStream
, uno::UNO_QUERY
);
395 Any aAny
= xProps
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Encrypted") ) );
396 sal_Bool bEncrypted
= sal_False
;
397 if ( aAny
.getValueType() == ::getBooleanCppuType() )
403 OUString
sPropName( RTL_CONSTASCII_USTRINGPARAM("StreamName") );
404 rPropSet
->setPropertyValue( sPropName
, makeAny( sStreamName
) );
408 Reference
< io::XInputStream
> xStream
= xEventsStream
->getInputStream();
409 return ReadThroughComponent( xStream
, xModelComponent
, rFactory
, rPropSet
, pFilterName
, bEncrypted
);
411 catch ( packages::WrongPasswordException
& )
413 return ERRCODE_SFX_WRONGPASSWORD
;
415 catch( packages::zip::ZipIOException
& )
417 return ERRCODE_IO_BROKENPACKAGE
;
419 catch ( uno::Exception
& )
423 return ERRCODE_SFX_DOLOADFAILED
;
426 ////////////////////////////////////////////////////////////
428 SmXMLImport::SmXMLImport(
429 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> xServiceFactory
,
430 sal_uInt16 nImportFlags
)
431 : SvXMLImport( xServiceFactory
, nImportFlags
),
432 pPresLayoutElemTokenMap(0),
433 pPresLayoutAttrTokenMap(0),
434 pFencedAttrTokenMap(0),
435 pOperatorAttrTokenMap(0),
436 pAnnotationAttrTokenMap(0),
437 pPresElemTokenMap(0),
438 pPresScriptEmptyElemTokenMap(0),
439 pPresTableElemTokenMap(0),
445 const uno::Sequence
< sal_Int8
> & SmXMLImport::getUnoTunnelId() throw()
447 static uno::Sequence
< sal_Int8
> * pSeq
= 0;
450 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
453 static uno::Sequence
< sal_Int8
> aSeq( 16 );
454 rtl_createUuid( (sal_uInt8
*)aSeq
.getArray(), 0, sal_True
);
461 OUString SAL_CALL
SmXMLImport_getImplementationName() throw()
463 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Math.XMLImporter" ) );
466 uno::Sequence
< OUString
> SAL_CALL
SmXMLImport_getSupportedServiceNames()
469 const OUString
aServiceName( IMPORT_SVC_NAME
);
470 const uno::Sequence
< OUString
> aSeq( &aServiceName
, 1 );
474 uno::Reference
< uno::XInterface
> SAL_CALL
SmXMLImport_createInstance(
475 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
476 throw( uno::Exception
)
479 // return (cppu::OWeakObject*)new SmXMLImport(IMPORT_ALL);
480 return (cppu::OWeakObject
*)new SmXMLImport(rSMgr
, IMPORT_ALL
);
483 ////////////////////////////////////////////////////////////
485 OUString SAL_CALL
SmXMLImportMeta_getImplementationName() throw()
487 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Math.XMLOasisMetaImporter" ) );
490 uno::Sequence
< OUString
> SAL_CALL
SmXMLImportMeta_getSupportedServiceNames()
493 const OUString
aServiceName( IMPORT_SVC_NAME
);
494 const uno::Sequence
< OUString
> aSeq( &aServiceName
, 1 );
498 uno::Reference
< uno::XInterface
> SAL_CALL
SmXMLImportMeta_createInstance(
499 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
500 throw( uno::Exception
)
503 // return (cppu::OWeakObject*)new SmXMLImport( IMPORT_META );
504 return (cppu::OWeakObject
*)new SmXMLImport( rSMgr
, IMPORT_META
);
507 ////////////////////////////////////////////////////////////
509 OUString SAL_CALL
SmXMLImportSettings_getImplementationName() throw()
511 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Math.XMLOasisSettingsImporter" ) );
514 uno::Sequence
< OUString
> SAL_CALL
SmXMLImportSettings_getSupportedServiceNames()
517 const OUString
aServiceName( IMPORT_SVC_NAME
);
518 const uno::Sequence
< OUString
> aSeq( &aServiceName
, 1 );
522 uno::Reference
< uno::XInterface
> SAL_CALL
SmXMLImportSettings_createInstance(
523 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
524 throw( uno::Exception
)
527 // return (cppu::OWeakObject*)new SmXMLImport( IMPORT_SETTINGS );
528 return (cppu::OWeakObject
*)new SmXMLImport( rSMgr
, IMPORT_SETTINGS
);
531 ////////////////////////////////////////////////////////////
534 // override empty method from parent class
535 rtl::OUString SAL_CALL
SmXMLImport::getImplementationName()
536 throw(uno::RuntimeException
)
539 switch( getImportFlags() )
542 aTxt
= SmXMLImportMeta_getImplementationName();
544 case IMPORT_SETTINGS
:
545 aTxt
= SmXMLImportSettings_getImplementationName();
549 aTxt
= SmXMLImport_getImplementationName();
556 sal_Int64 SAL_CALL
SmXMLImport::getSomething(
557 const uno::Sequence
< sal_Int8
>&rId
)
558 throw(uno::RuntimeException
)
560 if ( rId
.getLength() == 16 &&
561 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
562 rId
.getConstArray(), 16 ) )
563 return sal::static_int_cast
< sal_Int64
>(reinterpret_cast< sal_uIntPtr
>(this));
565 return SvXMLImport::getSomething( rId
);
568 void SmXMLImport::endDocument(void)
569 throw(xml::sax::SAXException
, uno::RuntimeException
)
571 //Set the resulted tree into the SmDocShell where it belongs
573 if (NULL
!= (pTree
= GetTree()))
575 uno::Reference
<frame::XModel
> xModel
= GetModel();
576 uno::Reference
<lang::XUnoTunnel
> xTunnel
;
577 xTunnel
= uno::Reference
<lang::XUnoTunnel
> (xModel
,uno::UNO_QUERY
);
578 SmModel
*pModel
= reinterpret_cast<SmModel
*>
579 (xTunnel
->getSomething(SmModel::getUnoTunnelId()));
583 SmDocShell
*pDocShell
=
584 static_cast<SmDocShell
*>(pModel
->GetObjectShell());
585 pDocShell
->SetFormulaTree(pTree
);
586 if (0 == aText
.Len()) //If we picked up no annotation text
588 //Make up some editable text
589 aText
= pDocShell
->GetText();
590 pTree
->CreateTextFromNode(aText
);
591 aText
.EraseTrailingChars();
592 if ((aText
.GetChar(0) == '{') &&
593 (aText
.GetChar(aText
.Len()-1) == '}'))
596 aText
.Erase(aText
.Len()-1,1);
599 pDocShell
->SetText( String() );
601 // Convert symbol names
602 SmParser
&rParser
= pDocShell
->GetParser();
603 BOOL bVal
= rParser
.IsImportSymbolNames();
604 rParser
.SetImportSymbolNames( TRUE
);
605 SmNode
*pTmpTree
= rParser
.Parse( aText
);
606 aText
= rParser
.GetText();
608 rParser
.SetImportSymbolNames( bVal
);
610 pDocShell
->SetText( aText
);
612 DBG_ASSERT(pModel
,"So there *was* a uno problem after all");
617 SvXMLImport::endDocument();
620 ////////////////////////////////////////////////////////////
622 class SmXMLImportContext
: public SvXMLImportContext
625 SmXMLImportContext( SmXMLImport
&rImport
, sal_uInt16 nPrfx
,
626 const OUString
& rLName
)
627 : SvXMLImportContext(rImport
, nPrfx
, rLName
) {}
629 const SmXMLImport
& GetSmImport() const
631 return (const SmXMLImport
&)GetImport();
634 SmXMLImport
& GetSmImport()
636 return (SmXMLImport
&)GetImport();
639 virtual void TCharacters(const OUString
& /*rChars*/);
640 virtual void Characters(const OUString
&rChars
);
641 virtual SvXMLImportContext
*CreateChildContext(sal_uInt16
/*nPrefix*/, const OUString
& /*rLocalName*/, const uno::Reference
< xml::sax::XAttributeList
> & /*xAttrList*/);
644 void SmXMLImportContext::TCharacters(const OUString
& /*rChars*/)
648 void SmXMLImportContext::Characters(const OUString
&rChars
)
651 Whitespace occurring within the content of token elements is "trimmed"
652 from the ends (i.e. all whitespace at the beginning and end of the
653 content is removed), and "collapsed" internally (i.e. each sequence of
654 1 or more whitespace characters is replaced with one blank character).
656 //collapsing not done yet!
657 const OUString
&rChars2
= rChars
.trim();
658 if (rChars2
.getLength())
659 TCharacters(rChars2
/*.collapse()*/);
662 SvXMLImportContext
* SmXMLImportContext::CreateChildContext(sal_uInt16
/*nPrefix*/,
663 const OUString
& /*rLocalName*/,
664 const uno::Reference
< xml::sax::XAttributeList
> & /*xAttrList*/)
669 ////////////////////////////////////////////////////////////
671 struct SmXMLContext_Helper
676 sal_Bool bFontNodeNeeded
;
677 OUString sFontFamily
;
680 SmXMLImportContext rContext
;
682 SmXMLContext_Helper(SmXMLImportContext
&rImport
) :
683 nIsBold(-1), nIsItalic(-1), nFontSize(0.0), rContext(rImport
) {}
685 void RetrieveAttrs(const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
689 void SmXMLContext_Helper::RetrieveAttrs(const uno::Reference
<
690 xml::sax::XAttributeList
> & xAttrList
)
692 sal_Int8 nOldIsBold
=nIsBold
;
693 sal_Int8 nOldIsItalic
=nIsItalic
;
694 double nOldFontSize
=nFontSize
;
695 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
696 OUString sOldFontFamily
= sFontFamily
;
697 for (sal_Int16 i
=0;i
<nAttrCount
;i
++)
699 OUString sAttrName
= xAttrList
->getNameByIndex(i
);
701 sal_uInt16 nPrefix
= rContext
.GetSmImport().GetNamespaceMap().
702 GetKeyByAttrName(sAttrName
,&aLocalName
);
703 OUString sValue
= xAttrList
->getValueByIndex(i
);
704 const SvXMLTokenMap
&rAttrTokenMap
=
705 rContext
.GetSmImport().GetPresLayoutAttrTokenMap();
706 switch(rAttrTokenMap
.Get(nPrefix
,aLocalName
))
708 case XML_TOK_FONTWEIGHT
:
709 nIsBold
= sValue
.equals(GetXMLToken(XML_BOLD
));
711 case XML_TOK_FONTSTYLE
:
712 nIsItalic
= sValue
.equals(GetXMLToken(XML_ITALIC
));
714 case XML_TOK_FONTSIZE
:
715 SvXMLUnitConverter::convertDouble(nFontSize
,sValue
);
716 rContext
.GetSmImport().GetMM100UnitConverter().
717 setXMLMeasureUnit(MAP_POINT
);
718 if (-1 == sValue
.indexOf(GetXMLToken(XML_UNIT_PT
)))
720 if (-1 == sValue
.indexOf('%'))
724 rContext
.GetSmImport().GetMM100UnitConverter().
725 setXMLMeasureUnit(MAP_RELATIVE
);
729 case XML_TOK_FONTFAMILY
:
730 sFontFamily
= sValue
;
740 if ((nOldIsBold
!=nIsBold
) || (nOldIsItalic
!=nIsItalic
) ||
741 (nOldFontSize
!=nFontSize
) || (sOldFontFamily
!=sFontFamily
)
742 || sColor
.getLength())
743 bFontNodeNeeded
=sal_True
;
745 bFontNodeNeeded
=sal_False
;
748 void SmXMLContext_Helper::ApplyAttrs()
750 SmNodeStack
&rNodeStack
= rContext
.GetSmImport().GetNodeStack();
755 aToken
.cMathChar
= '\0';
762 aToken
.eType
= TBOLD
;
764 aToken
.eType
= TNBOLD
;
765 SmStructureNode
*pFontNode
= static_cast<SmStructureNode
*>
766 (new SmFontNode(aToken
));
767 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
768 rNodeStack
.Push(pFontNode
);
773 aToken
.eType
= TITALIC
;
775 aToken
.eType
= TNITALIC
;
776 SmStructureNode
*pFontNode
= static_cast<SmStructureNode
*>
777 (new SmFontNode(aToken
));
778 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
779 rNodeStack
.Push(pFontNode
);
781 if (nFontSize
!= 0.0)
783 aToken
.eType
= TSIZE
;
784 SmFontNode
*pFontNode
= new SmFontNode(aToken
);
786 if (MAP_RELATIVE
== rContext
.GetSmImport().GetMM100UnitConverter().
789 if (nFontSize
< 100.00)
790 pFontNode
->SetSizeParameter(Fraction(100.00/nFontSize
),
793 pFontNode
->SetSizeParameter(Fraction(nFontSize
/100.00),
797 pFontNode
->SetSizeParameter(Fraction(nFontSize
),FNTSIZ_ABSOLUT
);
799 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
800 rNodeStack
.Push(pFontNode
);
802 if (sFontFamily
.getLength())
804 if (sFontFamily
.equalsIgnoreAsciiCase(GetXMLToken(XML_FIXED
)))
805 aToken
.eType
= TFIXED
;
806 else if (sFontFamily
.equalsIgnoreAsciiCase(OUString(
807 RTL_CONSTASCII_USTRINGPARAM("sans"))))
808 aToken
.eType
= TSANS
;
809 else if (sFontFamily
.equalsIgnoreAsciiCase(OUString(
810 RTL_CONSTASCII_USTRINGPARAM("serif"))))
811 aToken
.eType
= TSERIF
;
812 else //Just give up, we need to extend our font mechanism to be
816 aToken
.aText
= sFontFamily
;
817 SmFontNode
*pFontNode
= new SmFontNode(aToken
);
818 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
819 rNodeStack
.Push(pFontNode
);
821 if (sColor
.getLength())
823 //Again we can only handle a small set of colours in
825 const SvXMLTokenMap
& rTokenMap
=
826 rContext
.GetSmImport().GetColorTokenMap();
827 aToken
.eType
= static_cast<SmTokenType
>(rTokenMap
.Get(
828 XML_NAMESPACE_MATH
, sColor
));
829 if (aToken
.eType
!= -1)
831 SmFontNode
*pFontNode
= new SmFontNode(aToken
);
832 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
833 rNodeStack
.Push(pFontNode
);
840 ////////////////////////////////////////////////////////////
842 class SmXMLDocContext_Impl
: public SmXMLImportContext
845 SmXMLDocContext_Impl( SmXMLImport
&rImport
, sal_uInt16 nPrfx
,
846 const OUString
& rLName
)
847 : SmXMLImportContext(rImport
,nPrfx
,rLName
) {}
849 virtual SvXMLImportContext
*CreateChildContext(sal_uInt16 nPrefix
, const OUString
& rLocalName
, const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
854 ////////////////////////////////////////////////////////////
856 /*avert thy gaze from the proginator*/
857 class SmXMLRowContext_Impl
: public SmXMLDocContext_Impl
863 SmXMLRowContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
864 const OUString
& rLName
)
865 : SmXMLDocContext_Impl(rImport
,nPrefix
,rLName
)
866 { nElementCount
= GetSmImport().GetNodeStack().Count(); }
868 virtual SvXMLImportContext
*CreateChildContext(sal_uInt16 nPrefix
, const OUString
& rLocalName
, const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
870 SvXMLImportContext
*StrictCreateChildContext(sal_uInt16 nPrefix
,
871 const OUString
& rLocalName
,
872 const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
877 ////////////////////////////////////////////////////////////
879 class SmXMLFracContext_Impl
: public SmXMLRowContext_Impl
882 SmXMLFracContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
883 const OUString
& rLName
)
884 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
889 ////////////////////////////////////////////////////////////
891 class SmXMLSqrtContext_Impl
: public SmXMLRowContext_Impl
894 SmXMLSqrtContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
895 const OUString
& rLName
)
896 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
901 ////////////////////////////////////////////////////////////
903 class SmXMLRootContext_Impl
: public SmXMLRowContext_Impl
906 SmXMLRootContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
907 const OUString
& rLName
)
908 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
913 ////////////////////////////////////////////////////////////
915 class SmXMLStyleContext_Impl
: public SmXMLRowContext_Impl
918 SmXMLContext_Helper aStyleHelper
;
921 /*Right now the style tag is completely ignored*/
922 SmXMLStyleContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
923 const OUString
& rLName
) : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
),
924 aStyleHelper(*this) {}
927 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
930 void SmXMLStyleContext_Impl::StartElement(const uno::Reference
<
931 xml::sax::XAttributeList
> & xAttrList
)
934 aStyleHelper
.RetrieveAttrs(xAttrList
);
936 sal_Int8 nOldIsBold
=nIsBold
;
937 sal_Int8 nOldIsItalic
=nIsItalic
;
938 double nOldFontSize
=nFontSize
;
939 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
940 OUString sOldFontFamily
= sFontFamily
;
941 for (sal_Int16 i
=0;i
<nAttrCount
;i
++)
943 OUString sAttrName
= xAttrList
->getNameByIndex(i
);
945 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
946 GetKeyByAttrName(sAttrName
,&aLocalName
);
947 OUString sValue
= xAttrList
->getValueByIndex(i
);
948 const SvXMLTokenMap
&rAttrTokenMap
=
949 GetSmImport().GetPresLayoutAttrTokenMap();
950 switch(rAttrTokenMap
.Get(nPrefix
,aLocalName
))
952 case XML_TOK_FONTWEIGHT
:
953 nIsBold
= sValue
.equals(GetXMLToken(XML_BOLD
));
955 case XML_TOK_FONTSTYLE
:
956 nIsItalic
= sValue
.equals(GetXMLToken(XML_ITALIC
));
958 case XML_TOK_FONTSIZE
:
959 SvXMLUnitConverter::convertDouble(nFontSize
,sValue
);
960 GetSmImport().GetMM100UnitConverter().
961 setXMLMeasureUnit(MAP_POINT
);
962 if (-1 == sValue
.indexOf(GetXMLToken(XML_UNIT_PT
)))
963 if (-1 == sValue
.indexOf('%'))
967 GetSmImport().GetMM100UnitConverter().
968 setXMLMeasureUnit(MAP_RELATIVE
);
971 case XML_TOK_FONTFAMILY
:
972 sFontFamily
= sValue
;
982 if ((nOldIsBold
!=nIsBold
) || (nOldIsItalic
!=nIsItalic
) ||
983 (nOldFontSize
!=nFontSize
) || (sOldFontFamily
!=sFontFamily
)
984 || sColor
.getLength())
985 bFontNodeNeeded
=sal_True
;
987 bFontNodeNeeded
=sal_False
;
992 void SmXMLStyleContext_Impl::EndElement()
995 <mstyle> accepts any number of arguments; if this number is not 1, its
996 contents are treated as a single "inferred <mrow>" containing its
999 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1000 if (rNodeStack
.Count() - nElementCount
> 1)
1001 SmXMLRowContext_Impl::EndElement();
1003 aStyleHelper
.ApplyAttrs();
1005 if (bFontNodeNeeded
)
1008 aToken
.cMathChar
= '\0';
1015 aToken
.eType
= TBOLD
;
1017 aToken
.eType
= TNBOLD
;
1018 SmStructureNode
*pFontNode
= static_cast<SmStructureNode
*>
1019 (new SmFontNode(aToken
));
1020 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
1021 rNodeStack
.Push(pFontNode
);
1023 if (nIsItalic
!= -1)
1026 aToken
.eType
= TITALIC
;
1028 aToken
.eType
= TNITALIC
;
1029 SmStructureNode
*pFontNode
= static_cast<SmStructureNode
*>
1030 (new SmFontNode(aToken
));
1031 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
1032 rNodeStack
.Push(pFontNode
);
1034 if (nFontSize
!= 0.0)
1036 aToken
.eType
= TSIZE
;
1037 SmFontNode
*pFontNode
= new SmFontNode(aToken
);
1039 if (MAP_RELATIVE
== GetSmImport().GetMM100UnitConverter().
1040 getXMLMeasureUnit())
1042 if (nFontSize
< 100.00)
1043 pFontNode
->SetSizeParameter(Fraction(100.00/nFontSize
),
1046 pFontNode
->SetSizeParameter(Fraction(nFontSize
/100.00),
1050 pFontNode
->SetSizeParameter(Fraction(nFontSize
),FNTSIZ_ABSOLUT
);
1052 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
1053 rNodeStack
.Push(pFontNode
);
1055 if (sFontFamily
.getLength())
1057 if (sFontFamily
.equalsIgnoreCase(GetXMLToken(XML_FIXED
)))
1058 aToken
.eType
= TFIXED
;
1059 else if (sFontFamily
.equalsIgnoreCase(OUString(
1060 RTL_CONSTASCII_USTRINGPARAM("sans"))))
1061 aToken
.eType
= TSANS
;
1062 else if (sFontFamily
.equalsIgnoreCase(OUString(
1063 RTL_CONSTASCII_USTRINGPARAM("serif"))))
1064 aToken
.eType
= TSERIF
;
1065 else //Just give up, we need to extend our font mechanism to be
1069 aToken
.aText
= sFontFamily
;
1070 SmFontNode
*pFontNode
= new SmFontNode(aToken
);
1071 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
1072 rNodeStack
.Push(pFontNode
);
1074 if (sColor
.getLength())
1076 //Again we can only handle a small set of colours in
1078 const SvXMLTokenMap
& rTokenMap
=
1079 GetSmImport().GetColorTokenMap();
1080 aToken
.eType
= static_cast<SmTokenType
>(rTokenMap
.Get(
1081 XML_NAMESPACE_MATH
, sColor
));
1082 if (aToken
.eType
!= -1)
1084 SmFontNode
*pFontNode
= new SmFontNode(aToken
);
1085 pFontNode
->SetSubNodes(0,rNodeStack
.Pop());
1086 rNodeStack
.Push(pFontNode
);
1094 ////////////////////////////////////////////////////////////
1096 class SmXMLPaddedContext_Impl
: public SmXMLRowContext_Impl
1099 /*Right now the style tag is completely ignored*/
1100 SmXMLPaddedContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1101 const OUString
& rLName
)
1102 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
1107 void SmXMLPaddedContext_Impl::EndElement()
1110 <mpadded> accepts any number of arguments; if this number is not 1, its
1111 contents are treated as a single "inferred <mrow>" containing its
1114 if (GetSmImport().GetNodeStack().Count() - nElementCount
> 1)
1115 SmXMLRowContext_Impl::EndElement();
1118 ////////////////////////////////////////////////////////////
1120 class SmXMLPhantomContext_Impl
: public SmXMLRowContext_Impl
1123 /*Right now the style tag is completely ignored*/
1124 SmXMLPhantomContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1125 const OUString
& rLName
)
1126 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
1131 void SmXMLPhantomContext_Impl::EndElement()
1134 <mphantom> accepts any number of arguments; if this number is not 1, its
1135 contents are treated as a single "inferred <mrow>" containing its
1138 if (GetSmImport().GetNodeStack().Count() - nElementCount
> 1)
1139 SmXMLRowContext_Impl::EndElement();
1142 aToken
.cMathChar
= '\0';
1145 aToken
.eType
= TPHANTOM
;
1147 SmStructureNode
*pPhantom
= static_cast<SmStructureNode
*>
1148 (new SmFontNode(aToken
));
1149 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1150 pPhantom
->SetSubNodes(0,rNodeStack
.Pop());
1151 rNodeStack
.Push(pPhantom
);
1154 ////////////////////////////////////////////////////////////
1156 class SmXMLFencedContext_Impl
: public SmXMLRowContext_Impl
1163 SmXMLFencedContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1164 const OUString
& rLName
)
1165 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
),
1166 cBegin('('), cEnd(')') {}
1168 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
1173 void SmXMLFencedContext_Impl::StartElement(const uno::Reference
<
1174 xml::sax::XAttributeList
> & xAttrList
)
1176 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1177 for (sal_Int16 i
=0;i
<nAttrCount
;i
++)
1179 OUString sAttrName
= xAttrList
->getNameByIndex(i
);
1180 OUString aLocalName
;
1181 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
1182 GetKeyByAttrName(sAttrName
,&aLocalName
);
1183 OUString sValue
= xAttrList
->getValueByIndex(i
);
1184 const SvXMLTokenMap
&rAttrTokenMap
=
1185 GetSmImport().GetFencedAttrTokenMap();
1186 switch(rAttrTokenMap
.Get(nPrefix
,aLocalName
))
1188 //temp, starmath cannot handle multichar brackets (I think)
1196 /*Go to superclass*/
1203 void SmXMLFencedContext_Impl::EndElement()
1206 aToken
.cMathChar
= '\0';
1209 aToken
.eType
= TLEFT
;
1212 aToken
.eType
= TLPARENT
;
1213 aToken
.cMathChar
= cBegin
;
1214 SmStructureNode
*pSNode
= new SmBraceNode(aToken
);
1215 SmNode
*pLeft
= new SmMathSymbolNode(aToken
);
1217 aToken
.cMathChar
= cEnd
;
1218 aToken
.eType
= TRPARENT
;
1219 SmNode
*pRight
= new SmMathSymbolNode(aToken
);
1221 SmNodeArray aRelationArray
;
1222 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1224 aToken
.cMathChar
= '\0';
1226 aToken
.eType
= TIDENT
;
1228 ULONG i
= rNodeStack
.Count() - nElementCount
;
1229 if (rNodeStack
.Count() - nElementCount
> 1)
1230 i
+= rNodeStack
.Count() - 1 - nElementCount
;
1231 aRelationArray
.resize(i
);
1232 while (rNodeStack
.Count() > nElementCount
)
1234 aRelationArray
[--i
] = rNodeStack
.Pop();
1235 if (i
> 1 && rNodeStack
.Count() > 1)
1236 aRelationArray
[--i
] = new SmGlyphSpecialNode(aToken
);
1240 SmStructureNode
*pBody
= new SmExpressionNode(aDummy
);
1241 pBody
->SetSubNodes(aRelationArray
);
1244 pSNode
->SetSubNodes(pLeft
,pBody
,pRight
);
1245 pSNode
->SetScaleMode(SCALE_HEIGHT
);
1246 GetSmImport().GetNodeStack().Push(pSNode
);
1250 ////////////////////////////////////////////////////////////
1252 class SmXMLErrorContext_Impl
: public SmXMLRowContext_Impl
1255 SmXMLErrorContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1256 const OUString
& rLName
)
1257 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
1262 void SmXMLErrorContext_Impl::EndElement()
1264 /*Right now the error tag is completely ignored, what
1265 can I do with it in starmath, ?, maybe we need a
1266 report window ourselves, do a test for validity of
1267 the xml input, use merrors, and then generate
1268 the markup inside the merror with a big red colour
1269 of something. For now just throw them all away.
1271 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1272 while (rNodeStack
.Count() > nElementCount
)
1274 SmNode
*pNode
= rNodeStack
.Pop();
1279 ////////////////////////////////////////////////////////////
1281 class SmXMLNumberContext_Impl
: public SmXMLImportContext
1287 SmXMLNumberContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1288 const OUString
& rLName
)
1289 : SmXMLImportContext(rImport
,nPrefix
,rLName
)
1291 aToken
.cMathChar
= '\0';
1294 aToken
.eType
= TNUMBER
;
1297 virtual void TCharacters(const OUString
&rChars
);
1302 void SmXMLNumberContext_Impl::TCharacters(const OUString
&rChars
)
1304 aToken
.aText
= rChars
;
1307 void SmXMLNumberContext_Impl::EndElement()
1309 GetSmImport().GetNodeStack().Push(new SmTextNode(aToken
,FNT_NUMBER
));
1312 ////////////////////////////////////////////////////////////
1314 class SmXMLAnnotationContext_Impl
: public SmXMLImportContext
1316 sal_Bool bIsStarMath
;
1319 SmXMLAnnotationContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1320 const OUString
& rLName
)
1321 : SmXMLImportContext(rImport
,nPrefix
,rLName
), bIsStarMath(sal_False
) {}
1323 virtual void Characters(const OUString
&rChars
);
1325 void StartElement(const uno::Reference
<xml::sax::XAttributeList
> & xAttrList
);
1328 void SmXMLAnnotationContext_Impl::StartElement(const uno::Reference
<
1329 xml::sax::XAttributeList
> & xAttrList
)
1331 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1332 for (sal_Int16 i
=0;i
<nAttrCount
;i
++)
1334 OUString sAttrName
= xAttrList
->getNameByIndex(i
);
1335 OUString aLocalName
;
1336 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
1337 GetKeyByAttrName(sAttrName
,&aLocalName
);
1339 OUString sValue
= xAttrList
->getValueByIndex(i
);
1340 const SvXMLTokenMap
&rAttrTokenMap
=
1341 GetSmImport().GetAnnotationAttrTokenMap();
1342 switch(rAttrTokenMap
.Get(nPrefix
,aLocalName
))
1344 case XML_TOK_ENCODING
:
1345 bIsStarMath
= sValue
.equals(
1346 OUString(RTL_CONSTASCII_USTRINGPARAM("StarMath 5.0")));
1354 void SmXMLAnnotationContext_Impl::Characters(const OUString
&rChars
)
1357 GetSmImport().GetText().Append(String(rChars
));
1360 ////////////////////////////////////////////////////////////
1362 class SmXMLTextContext_Impl
: public SmXMLImportContext
1368 SmXMLTextContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1369 const OUString
& rLName
)
1370 : SmXMLImportContext(rImport
,nPrefix
,rLName
)
1372 aToken
.cMathChar
= '\0';
1375 aToken
.eType
= TTEXT
;
1378 virtual void TCharacters(const OUString
&rChars
);
1383 void SmXMLTextContext_Impl::TCharacters(const OUString
&rChars
)
1385 aToken
.aText
= rChars
;
1388 void SmXMLTextContext_Impl::EndElement()
1390 GetSmImport().GetNodeStack().Push(new SmTextNode(aToken
,FNT_TEXT
));
1393 ////////////////////////////////////////////////////////////
1395 class SmXMLStringContext_Impl
: public SmXMLImportContext
1401 SmXMLStringContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1402 const OUString
& rLName
)
1403 : SmXMLImportContext(rImport
,nPrefix
,rLName
)
1405 aToken
.cMathChar
= '\0';
1408 aToken
.eType
= TTEXT
;
1411 virtual void TCharacters(const OUString
&rChars
);
1416 void SmXMLStringContext_Impl::TCharacters(const OUString
&rChars
)
1419 The content of <ms> elements should be rendered with visible "escaping" of
1420 certain characters in the content, including at least "double quote"
1421 itself, and preferably whitespace other than individual blanks. The intent
1422 is for the viewer to see that the expression is a string literal, and to
1423 see exactly which characters form its content. For example, <ms>double
1424 quote is "</ms> might be rendered as "double quote is \"".
1426 Obviously this isn't fully done here.
1428 aToken
.aText
.Erase();
1429 aToken
.aText
+= '\"';
1430 aToken
.aText
+= String(rChars
);
1431 aToken
.aText
+= '\"';
1434 void SmXMLStringContext_Impl::EndElement()
1436 GetSmImport().GetNodeStack().Push(new SmTextNode(aToken
,FNT_FIXED
));
1439 ////////////////////////////////////////////////////////////
1441 class SmXMLIdentifierContext_Impl
: public SmXMLImportContext
1444 SmXMLContext_Helper aStyleHelper
;
1448 SmXMLIdentifierContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1449 const OUString
& rLName
)
1450 : SmXMLImportContext(rImport
,nPrefix
,rLName
),aStyleHelper(*this)
1452 aToken
.cMathChar
= '\0';
1455 aToken
.eType
= TIDENT
;
1458 void TCharacters(const OUString
&rChars
);
1459 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
1461 aStyleHelper
.RetrieveAttrs(xAttrList
);
1466 void SmXMLIdentifierContext_Impl::EndElement()
1468 SmTextNode
*pNode
= 0;
1469 //we will handle identifier italic/normal here instead of with a standalone
1471 if (((aStyleHelper
.nIsItalic
== -1) && (aToken
.aText
.Len() > 1))
1472 || ((aStyleHelper
.nIsItalic
== 0) && (aToken
.aText
.Len() == 1)))
1474 pNode
= new SmTextNode(aToken
,FNT_FUNCTION
);
1475 pNode
->GetFont().SetItalic(ITALIC_NONE
);
1476 aStyleHelper
.nIsItalic
= -1;
1479 pNode
= new SmTextNode(aToken
,FNT_VARIABLE
);
1480 if (aStyleHelper
.bFontNodeNeeded
&& aStyleHelper
.nIsItalic
!= -1)
1482 if (aStyleHelper
.nIsItalic
)
1483 pNode
->GetFont().SetItalic(ITALIC_NORMAL
);
1485 pNode
->GetFont().SetItalic(ITALIC_NONE
);
1488 if ((-1!=aStyleHelper
.nIsBold
) || (0.0!=aStyleHelper
.nFontSize
) ||
1489 (aStyleHelper
.sFontFamily
.getLength()) ||
1490 aStyleHelper
.sColor
.getLength())
1491 aStyleHelper
.bFontNodeNeeded
=sal_True
;
1493 aStyleHelper
.bFontNodeNeeded
=sal_False
;
1494 if (aStyleHelper
.bFontNodeNeeded
)
1495 aStyleHelper
.ApplyAttrs();
1496 GetSmImport().GetNodeStack().Push(pNode
);
1499 void SmXMLIdentifierContext_Impl::TCharacters(const OUString
&rChars
)
1501 aToken
.aText
= rChars
;
1504 ////////////////////////////////////////////////////////////
1506 class SmXMLOperatorContext_Impl
: public SmXMLImportContext
1508 sal_Bool bIsStretchy
;
1514 SmXMLOperatorContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1515 const OUString
& rLName
)
1516 : SmXMLImportContext(rImport
,nPrefix
,rLName
), bIsStretchy(sal_False
)
1519 aToken
.eType
= TSPECIAL
;
1523 void TCharacters(const OUString
&rChars
);
1524 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1528 void SmXMLOperatorContext_Impl::TCharacters(const OUString
&rChars
)
1530 aToken
.cMathChar
= rChars
[0];
1533 void SmXMLOperatorContext_Impl::EndElement()
1535 SmMathSymbolNode
*pNode
= new SmMathSymbolNode(aToken
);
1536 //For stretchy scaling the scaling must be retrieved from this node
1537 //and applied to the expression itself so as to get the expression
1538 //to scale the operator to the height of the expression itself
1540 pNode
->SetScaleMode(SCALE_HEIGHT
);
1541 GetSmImport().GetNodeStack().Push(pNode
);
1546 void SmXMLOperatorContext_Impl::StartElement(const uno::Reference
<
1547 xml::sax::XAttributeList
> & xAttrList
)
1549 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1550 for (sal_Int16 i
=0;i
<nAttrCount
;i
++)
1552 OUString sAttrName
= xAttrList
->getNameByIndex(i
);
1553 OUString aLocalName
;
1554 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
1555 GetKeyByAttrName(sAttrName
,&aLocalName
);
1557 OUString sValue
= xAttrList
->getValueByIndex(i
);
1558 const SvXMLTokenMap
&rAttrTokenMap
=
1559 GetSmImport().GetOperatorAttrTokenMap();
1560 switch(rAttrTokenMap
.Get(nPrefix
,aLocalName
))
1562 case XML_TOK_STRETCHY
:
1563 bIsStretchy
= sValue
.equals(
1564 GetXMLToken(XML_TRUE
));
1573 ////////////////////////////////////////////////////////////
1575 class SmXMLSpaceContext_Impl
: public SmXMLImportContext
1578 SmXMLSpaceContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1579 const OUString
& rLName
)
1580 : SmXMLImportContext(rImport
,nPrefix
,rLName
) {}
1582 void StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
);
1585 void SmXMLSpaceContext_Impl::StartElement(
1586 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/ )
1589 aToken
.cMathChar
= '\0';
1591 aToken
.eType
= TBLANK
;
1593 SmBlankNode
*pBlank
= new SmBlankNode(aToken
);
1594 pBlank
->IncreaseBy(aToken
);
1595 GetSmImport().GetNodeStack().Push(pBlank
);
1598 ////////////////////////////////////////////////////////////
1600 class SmXMLSubContext_Impl
: public SmXMLRowContext_Impl
1603 void GenericEndElement(SmTokenType eType
,SmSubSup aSubSup
);
1606 SmXMLSubContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1607 const OUString
& rLName
)
1608 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
1612 GenericEndElement(TRSUB
,RSUB
);
1617 void SmXMLSubContext_Impl::GenericEndElement(SmTokenType eType
, SmSubSup eSubSup
)
1619 /*The <msub> element requires exactly 2 arguments.*/
1620 DBG_ASSERT(GetSmImport().GetNodeStack().Count() - nElementCount
== 2,
1621 "Sub has not two arguments");
1623 aToken
.cMathChar
= '\0';
1626 aToken
.eType
= eType
;
1627 SmSubSupNode
*pNode
= new SmSubSupNode(aToken
);
1628 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1630 // initialize subnodes array
1631 SmNodeArray aSubNodes
;
1632 aSubNodes
.resize(1 + SUBSUP_NUM_ENTRIES
);
1633 for (ULONG i
= 1; i
< aSubNodes
.size(); i
++)
1634 aSubNodes
[i
] = NULL
;
1636 aSubNodes
[eSubSup
+1] = rNodeStack
.Pop();
1637 aSubNodes
[0] = rNodeStack
.Pop();
1638 pNode
->SetSubNodes(aSubNodes
);
1639 rNodeStack
.Push(pNode
);
1642 ////////////////////////////////////////////////////////////
1644 class SmXMLSupContext_Impl
: public SmXMLSubContext_Impl
1647 SmXMLSupContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1648 const OUString
& rLName
)
1649 : SmXMLSubContext_Impl(rImport
,nPrefix
,rLName
) {}
1653 GenericEndElement(TRSUP
,RSUP
);
1657 ////////////////////////////////////////////////////////////
1659 class SmXMLSubSupContext_Impl
: public SmXMLRowContext_Impl
1662 void GenericEndElement(SmTokenType eType
, SmSubSup aSub
,SmSubSup aSup
);
1665 SmXMLSubSupContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1666 const OUString
& rLName
)
1667 : SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
) {}
1671 GenericEndElement(TRSUB
,RSUB
,RSUP
);
1675 void SmXMLSubSupContext_Impl::GenericEndElement(SmTokenType eType
,
1676 SmSubSup aSub
,SmSubSup aSup
)
1678 /*The <msub> element requires exactly 3 arguments.*/
1679 DBG_ASSERT(GetSmImport().GetNodeStack().Count() - nElementCount
== 3,
1680 "SubSup has not three arguments");
1683 aToken
.cMathChar
= '\0';
1686 aToken
.eType
= eType
;
1687 SmSubSupNode
*pNode
= new SmSubSupNode(aToken
);
1688 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1690 // initialize subnodes array
1691 SmNodeArray aSubNodes
;
1692 aSubNodes
.resize(1 + SUBSUP_NUM_ENTRIES
);
1693 for (ULONG i
= 1; i
< aSubNodes
.size(); i
++)
1694 aSubNodes
[i
] = NULL
;
1696 aSubNodes
[aSup
+1] = rNodeStack
.Pop();
1697 aSubNodes
[aSub
+1] = rNodeStack
.Pop();
1698 aSubNodes
[0] = rNodeStack
.Pop();
1699 pNode
->SetSubNodes(aSubNodes
);
1700 rNodeStack
.Push(pNode
);
1703 ////////////////////////////////////////////////////////////
1705 class SmXMLUnderContext_Impl
: public SmXMLSubContext_Impl
1708 sal_Int16 nAttrCount
;
1711 SmXMLUnderContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1712 const OUString
& rLName
)
1713 : SmXMLSubContext_Impl(rImport
,nPrefix
,rLName
) {}
1715 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1717 void HandleAccent();
1720 void SmXMLUnderContext_Impl::StartElement(const uno::Reference
<
1721 xml::sax::XAttributeList
> & xAttrList
)
1723 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1726 void SmXMLUnderContext_Impl::HandleAccent()
1728 DBG_ASSERT(GetSmImport().GetNodeStack().Count() - nElementCount
== 2,
1729 "Sub has not two arguments");
1731 /*Just one special case for the underline thing*/
1732 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1733 SmNode
*pTest
= rNodeStack
.Pop();
1735 aToken
.cMathChar
= '\0';
1738 aToken
.eType
= TUNDERLINE
;
1741 SmNodeArray aSubNodes
;
1742 aSubNodes
.resize(2);
1744 SmStructureNode
*pNode
= new SmAttributNode(aToken
);
1745 if ((pTest
->GetToken().cMathChar
& 0x0FFF) == 0x0332)
1747 aSubNodes
[0] = new SmRectangleNode(aToken
);
1751 aSubNodes
[0] = pTest
;
1753 aSubNodes
[1] = rNodeStack
.Pop();
1754 pNode
->SetSubNodes(aSubNodes
);
1755 pNode
->SetScaleMode(SCALE_WIDTH
);
1756 rNodeStack
.Push(pNode
);
1760 void SmXMLUnderContext_Impl::EndElement()
1763 GenericEndElement(TCSUB
,CSUB
);
1768 SmStructureNode
*pNode
= rNodeStack
.Pop();
1769 if (pNode
->GetSubNode(1)->GetToken().cMathChar
== (0x0332|0xf000))
1770 if (pNode
->GetSubNode(0)->GetToken().cMathChar
== (0x0332|0xf000))
1774 ////////////////////////////////////////////////////////////
1776 class SmXMLOverContext_Impl
: public SmXMLSubContext_Impl
1779 sal_Int16 nAttrCount
;
1782 SmXMLOverContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1783 const OUString
& rLName
)
1784 : SmXMLSubContext_Impl(rImport
,nPrefix
,rLName
), nAttrCount(0) {}
1787 void StartElement(const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1788 void HandleAccent();
1792 void SmXMLOverContext_Impl::StartElement(const uno::Reference
<
1793 xml::sax::XAttributeList
> & xAttrList
)
1795 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
1799 void SmXMLOverContext_Impl::EndElement()
1802 GenericEndElement(TCSUP
,CSUP
);
1808 void SmXMLOverContext_Impl::HandleAccent()
1810 DBG_ASSERT(GetSmImport().GetNodeStack().Count() - nElementCount
== 2,
1811 "Sub has not two arguments");
1813 aToken
.cMathChar
= '\0';
1816 aToken
.eType
= TACUTE
;
1818 SmAttributNode
*pNode
= new SmAttributNode(aToken
);
1819 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
1821 SmNodeArray aSubNodes
;
1822 aSubNodes
.resize(2);
1823 aSubNodes
[0] = rNodeStack
.Pop();
1824 aSubNodes
[1] = rNodeStack
.Pop();
1825 pNode
->SetSubNodes(aSubNodes
);
1826 pNode
->SetScaleMode(SCALE_WIDTH
);
1827 rNodeStack
.Push(pNode
);
1831 ////////////////////////////////////////////////////////////
1833 class SmXMLUnderOverContext_Impl
: public SmXMLSubSupContext_Impl
1836 SmXMLUnderOverContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1837 const OUString
& rLName
)
1838 : SmXMLSubSupContext_Impl(rImport
,nPrefix
,rLName
) {}
1842 GenericEndElement(TCSUB
,CSUB
,CSUP
);
1846 ////////////////////////////////////////////////////////////
1848 class SmXMLMultiScriptsContext_Impl
: public SmXMLSubSupContext_Impl
1850 sal_Bool bHasPrescripts
;
1853 SmXMLMultiScriptsContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1854 const OUString
& rLName
) :
1855 SmXMLSubSupContext_Impl(rImport
,nPrefix
,rLName
),
1856 bHasPrescripts(FALSE
) {}
1859 void MiddleElement();
1860 SvXMLImportContext
*CreateChildContext(sal_uInt16 nPrefix
,
1861 const OUString
& rLocalName
,
1862 const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1865 ////////////////////////////////////////////////////////////
1867 class SmXMLNoneContext_Impl
: public SmXMLImportContext
1870 SmXMLNoneContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1871 const OUString
& rLName
)
1872 : SmXMLImportContext(rImport
,nPrefix
,rLName
) {}
1878 void SmXMLNoneContext_Impl::EndElement(void)
1881 aToken
.cMathChar
= '\0';
1883 aToken
.aText
.Erase();
1885 aToken
.eType
= TIDENT
;
1886 GetSmImport().GetNodeStack().Push(
1887 new SmTextNode(aToken
,FNT_VARIABLE
));
1890 ////////////////////////////////////////////////////////////
1892 class SmXMLPrescriptsContext_Impl
: public SmXMLImportContext
1895 SmXMLPrescriptsContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1896 const OUString
& rLName
)
1897 : SmXMLImportContext(rImport
,nPrefix
,rLName
) {}
1900 ////////////////////////////////////////////////////////////
1902 class SmXMLTableRowContext_Impl
: public SmXMLRowContext_Impl
1905 SmXMLTableRowContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1906 const OUString
& rLName
) :
1907 SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
)
1910 SvXMLImportContext
*CreateChildContext(sal_uInt16 nPrefix
,
1911 const OUString
& rLocalName
,
1912 const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1916 ////////////////////////////////////////////////////////////
1918 class SmXMLTableContext_Impl
: public SmXMLTableRowContext_Impl
1921 SmXMLTableContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1922 const OUString
& rLName
) :
1923 SmXMLTableRowContext_Impl(rImport
,nPrefix
,rLName
)
1927 SvXMLImportContext
*CreateChildContext(sal_uInt16 nPrefix
,
1928 const OUString
& rLocalName
,
1929 const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1933 ////////////////////////////////////////////////////////////
1935 class SmXMLTableCellContext_Impl
: public SmXMLRowContext_Impl
1938 SmXMLTableCellContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1939 const OUString
& rLName
) :
1940 SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
)
1944 ////////////////////////////////////////////////////////////
1946 class SmXMLAlignGroupContext_Impl
: public SmXMLRowContext_Impl
1949 SmXMLAlignGroupContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1950 const OUString
& rLName
) :
1951 SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
)
1954 /*Don't do anything with alignment for now*/
1960 ////////////////////////////////////////////////////////////
1962 class SmXMLActionContext_Impl
: public SmXMLRowContext_Impl
1965 SmXMLActionContext_Impl(SmXMLImport
&rImport
,sal_uInt16 nPrefix
,
1966 const OUString
& rLName
) :
1967 SmXMLRowContext_Impl(rImport
,nPrefix
,rLName
)
1973 ////////////////////////////////////////////////////////////
1975 // NB: virtually inherit so we can multiply inherit properly
1976 // in SmXMLFlatDocContext_Impl
1977 class SmXMLOfficeContext_Impl
: public virtual SvXMLImportContext
1980 SmXMLOfficeContext_Impl( SmXMLImport
&rImport
, sal_uInt16 nPrfx
,
1981 const OUString
& rLName
)
1982 : SvXMLImportContext(rImport
,nPrfx
,rLName
) {}
1984 virtual SvXMLImportContext
*CreateChildContext(sal_uInt16 nPrefix
, const OUString
& rLocalName
, const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
);
1987 SvXMLImportContext
*SmXMLOfficeContext_Impl::CreateChildContext(sal_uInt16 nPrefix
,
1988 const OUString
& rLocalName
,
1989 const uno::Reference
< xml::sax::XAttributeList
> &xAttrList
)
1991 SvXMLImportContext
*pContext
= 0;
1992 if ( XML_NAMESPACE_OFFICE
== nPrefix
&&
1993 rLocalName
== GetXMLToken(XML_META
) )
1995 DBG_WARNING("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
1997 else if ( XML_NAMESPACE_OFFICE
== nPrefix
&&
1998 rLocalName
== GetXMLToken(XML_SETTINGS
) )
2000 pContext
= new XMLDocumentSettingsContext( GetImport(),
2001 XML_NAMESPACE_OFFICE
, rLocalName
,
2005 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
2010 ////////////////////////////////////////////////////////////
2012 // context for flat file xml format
2013 class SmXMLFlatDocContext_Impl
2014 : public SmXMLOfficeContext_Impl
, public SvXMLMetaDocumentContext
2017 SmXMLFlatDocContext_Impl( SmXMLImport
& i_rImport
,
2018 USHORT i_nPrefix
, const OUString
& i_rLName
,
2019 const uno::Reference
<document::XDocumentProperties
>& i_xDocProps
,
2020 const uno::Reference
<xml::sax::XDocumentHandler
>& i_xDocBuilder
);
2022 virtual ~SmXMLFlatDocContext_Impl();
2024 virtual SvXMLImportContext
*CreateChildContext(USHORT i_nPrefix
, const OUString
& i_rLocalName
, const uno::Reference
<xml::sax::XAttributeList
>& i_xAttrList
);
2027 SmXMLFlatDocContext_Impl::SmXMLFlatDocContext_Impl( SmXMLImport
& i_rImport
,
2028 USHORT i_nPrefix
, const OUString
& i_rLName
,
2029 const uno::Reference
<document::XDocumentProperties
>& i_xDocProps
,
2030 const uno::Reference
<xml::sax::XDocumentHandler
>& i_xDocBuilder
) :
2031 SvXMLImportContext(i_rImport
, i_nPrefix
, i_rLName
),
2032 SmXMLOfficeContext_Impl(i_rImport
, i_nPrefix
, i_rLName
),
2033 SvXMLMetaDocumentContext(i_rImport
, i_nPrefix
, i_rLName
,
2034 i_xDocProps
, i_xDocBuilder
)
2038 SmXMLFlatDocContext_Impl::~SmXMLFlatDocContext_Impl()
2042 SvXMLImportContext
*SmXMLFlatDocContext_Impl::CreateChildContext(
2043 USHORT i_nPrefix
, const OUString
& i_rLocalName
,
2044 const uno::Reference
<xml::sax::XAttributeList
>& i_xAttrList
)
2046 // behave like meta base class iff we encounter office:meta
2047 if ( XML_NAMESPACE_OFFICE
== i_nPrefix
&&
2048 i_rLocalName
== GetXMLToken(XML_META
) )
2050 return SvXMLMetaDocumentContext::CreateChildContext(
2051 i_nPrefix
, i_rLocalName
, i_xAttrList
);
2055 return SmXMLOfficeContext_Impl::CreateChildContext(
2056 i_nPrefix
, i_rLocalName
, i_xAttrList
);
2060 ////////////////////////////////////////////////////////////
2062 static __FAR_DATA SvXMLTokenMapEntry aPresLayoutElemTokenMap
[] =
2064 { XML_NAMESPACE_MATH
, XML_SEMANTICS
, XML_TOK_SEMANTICS
},
2065 { XML_NAMESPACE_MATH
, XML_MATH
, XML_TOK_MATH
},
2066 { XML_NAMESPACE_MATH
, XML_MSTYLE
, XML_TOK_MSTYLE
},
2067 { XML_NAMESPACE_MATH
, XML_MERROR
, XML_TOK_MERROR
},
2068 { XML_NAMESPACE_MATH
, XML_MPHANTOM
, XML_TOK_MPHANTOM
},
2069 { XML_NAMESPACE_MATH
, XML_MROW
, XML_TOK_MROW
},
2070 { XML_NAMESPACE_MATH
, XML_MFRAC
, XML_TOK_MFRAC
},
2071 { XML_NAMESPACE_MATH
, XML_MSQRT
, XML_TOK_MSQRT
},
2072 { XML_NAMESPACE_MATH
, XML_MROOT
, XML_TOK_MROOT
},
2073 { XML_NAMESPACE_MATH
, XML_MSUB
, XML_TOK_MSUB
},
2074 { XML_NAMESPACE_MATH
, XML_MSUP
, XML_TOK_MSUP
},
2075 { XML_NAMESPACE_MATH
, XML_MSUBSUP
, XML_TOK_MSUBSUP
},
2076 { XML_NAMESPACE_MATH
, XML_MUNDER
, XML_TOK_MUNDER
},
2077 { XML_NAMESPACE_MATH
, XML_MOVER
, XML_TOK_MOVER
},
2078 { XML_NAMESPACE_MATH
, XML_MUNDEROVER
, XML_TOK_MUNDEROVER
},
2079 { XML_NAMESPACE_MATH
, XML_MMULTISCRIPTS
, XML_TOK_MMULTISCRIPTS
},
2080 { XML_NAMESPACE_MATH
, XML_MTABLE
, XML_TOK_MTABLE
},
2081 { XML_NAMESPACE_MATH
, XML_MACTION
, XML_TOK_MACTION
},
2082 { XML_NAMESPACE_MATH
, XML_MFENCED
, XML_TOK_MFENCED
},
2083 { XML_NAMESPACE_MATH
, XML_MPADDED
, XML_TOK_MPADDED
},
2087 static __FAR_DATA SvXMLTokenMapEntry aPresLayoutAttrTokenMap
[] =
2089 { XML_NAMESPACE_MATH
, XML_FONTWEIGHT
, XML_TOK_FONTWEIGHT
},
2090 { XML_NAMESPACE_MATH
, XML_FONTSTYLE
, XML_TOK_FONTSTYLE
},
2091 { XML_NAMESPACE_MATH
, XML_FONTSIZE
, XML_TOK_FONTSIZE
},
2092 { XML_NAMESPACE_MATH
, XML_FONTFAMILY
, XML_TOK_FONTFAMILY
},
2093 { XML_NAMESPACE_MATH
, XML_COLOR
, XML_TOK_COLOR
},
2097 static __FAR_DATA SvXMLTokenMapEntry aFencedAttrTokenMap
[] =
2099 { XML_NAMESPACE_MATH
, XML_OPEN
, XML_TOK_OPEN
},
2100 { XML_NAMESPACE_MATH
, XML_CLOSE
, XML_TOK_CLOSE
},
2104 static __FAR_DATA SvXMLTokenMapEntry aOperatorAttrTokenMap
[] =
2106 { XML_NAMESPACE_MATH
, XML_STRETCHY
, XML_TOK_STRETCHY
},
2110 static __FAR_DATA SvXMLTokenMapEntry aAnnotationAttrTokenMap
[] =
2112 { XML_NAMESPACE_MATH
, XML_ENCODING
, XML_TOK_ENCODING
},
2117 static __FAR_DATA SvXMLTokenMapEntry aPresElemTokenMap
[] =
2119 { XML_NAMESPACE_MATH
, XML_ANNOTATION
, XML_TOK_ANNOTATION
},
2120 { XML_NAMESPACE_MATH
, XML_MI
, XML_TOK_MI
},
2121 { XML_NAMESPACE_MATH
, XML_MN
, XML_TOK_MN
},
2122 { XML_NAMESPACE_MATH
, XML_MO
, XML_TOK_MO
},
2123 { XML_NAMESPACE_MATH
, XML_MTEXT
, XML_TOK_MTEXT
},
2124 { XML_NAMESPACE_MATH
, XML_MSPACE
,XML_TOK_MSPACE
},
2125 { XML_NAMESPACE_MATH
, XML_MS
, XML_TOK_MS
},
2126 { XML_NAMESPACE_MATH
, XML_MALIGNGROUP
, XML_TOK_MALIGNGROUP
},
2130 static __FAR_DATA SvXMLTokenMapEntry aPresScriptEmptyElemTokenMap
[] =
2132 { XML_NAMESPACE_MATH
, XML_MPRESCRIPTS
, XML_TOK_MPRESCRIPTS
},
2133 { XML_NAMESPACE_MATH
, XML_NONE
, XML_TOK_NONE
},
2137 static __FAR_DATA SvXMLTokenMapEntry aPresTableElemTokenMap
[] =
2139 { XML_NAMESPACE_MATH
, XML_MTR
, XML_TOK_MTR
},
2140 { XML_NAMESPACE_MATH
, XML_MTD
, XML_TOK_MTD
},
2144 static __FAR_DATA SvXMLTokenMapEntry aColorTokenMap
[] =
2146 { XML_NAMESPACE_MATH
, XML_BLACK
, TBLACK
},
2147 { XML_NAMESPACE_MATH
, XML_WHITE
, TWHITE
},
2148 { XML_NAMESPACE_MATH
, XML_RED
, TRED
},
2149 { XML_NAMESPACE_MATH
, XML_GREEN
, TGREEN
},
2150 { XML_NAMESPACE_MATH
, XML_BLUE
, TBLUE
},
2151 { XML_NAMESPACE_MATH
, XML_AQUA
, TCYAN
},
2152 { XML_NAMESPACE_MATH
, XML_FUCHSIA
, TMAGENTA
},
2153 { XML_NAMESPACE_MATH
, XML_YELLOW
, TYELLOW
},
2158 ////////////////////////////////////////////////////////////
2160 const SvXMLTokenMap
& SmXMLImport::GetPresLayoutElemTokenMap()
2162 if (!pPresLayoutElemTokenMap
)
2163 pPresLayoutElemTokenMap
= new SvXMLTokenMap(aPresLayoutElemTokenMap
);
2164 return *pPresLayoutElemTokenMap
;
2167 const SvXMLTokenMap
& SmXMLImport::GetPresLayoutAttrTokenMap()
2169 if (!pPresLayoutAttrTokenMap
)
2170 pPresLayoutAttrTokenMap
= new SvXMLTokenMap(aPresLayoutAttrTokenMap
);
2171 return *pPresLayoutAttrTokenMap
;
2175 const SvXMLTokenMap
& SmXMLImport::GetFencedAttrTokenMap()
2177 if (!pFencedAttrTokenMap
)
2178 pFencedAttrTokenMap
= new SvXMLTokenMap(aFencedAttrTokenMap
);
2179 return *pFencedAttrTokenMap
;
2182 const SvXMLTokenMap
& SmXMLImport::GetOperatorAttrTokenMap()
2184 if (!pOperatorAttrTokenMap
)
2185 pOperatorAttrTokenMap
= new SvXMLTokenMap(aOperatorAttrTokenMap
);
2186 return *pOperatorAttrTokenMap
;
2189 const SvXMLTokenMap
& SmXMLImport::GetAnnotationAttrTokenMap()
2191 if (!pAnnotationAttrTokenMap
)
2192 pAnnotationAttrTokenMap
= new SvXMLTokenMap(aAnnotationAttrTokenMap
);
2193 return *pAnnotationAttrTokenMap
;
2196 const SvXMLTokenMap
& SmXMLImport::GetPresElemTokenMap()
2198 if (!pPresElemTokenMap
)
2199 pPresElemTokenMap
= new SvXMLTokenMap(aPresElemTokenMap
);
2200 return *pPresElemTokenMap
;
2203 const SvXMLTokenMap
& SmXMLImport::GetPresScriptEmptyElemTokenMap()
2205 if (!pPresScriptEmptyElemTokenMap
)
2206 pPresScriptEmptyElemTokenMap
= new
2207 SvXMLTokenMap(aPresScriptEmptyElemTokenMap
);
2208 return *pPresScriptEmptyElemTokenMap
;
2211 const SvXMLTokenMap
& SmXMLImport::GetPresTableElemTokenMap()
2213 if (!pPresTableElemTokenMap
)
2214 pPresTableElemTokenMap
= new SvXMLTokenMap(aPresTableElemTokenMap
);
2215 return *pPresTableElemTokenMap
;
2218 const SvXMLTokenMap
& SmXMLImport::GetColorTokenMap()
2220 if (!pColorTokenMap
)
2221 pColorTokenMap
= new SvXMLTokenMap(aColorTokenMap
);
2222 return *pColorTokenMap
;
2225 ////////////////////////////////////////////////////////////
2227 SvXMLImportContext
*SmXMLDocContext_Impl::CreateChildContext(
2229 const OUString
& rLocalName
,
2230 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
2232 SvXMLImportContext
* pContext
= 0L;
2234 const SvXMLTokenMap
& rTokenMap
= GetSmImport().GetPresLayoutElemTokenMap();
2236 //UINT32 nTest = rTokenMap.Get(nPrefix, rLocalName);
2238 switch(rTokenMap
.Get(nPrefix
, rLocalName
))
2240 //Consider semantics a dummy except for any starmath annotations
2241 case XML_TOK_SEMANTICS
:
2242 pContext
= GetSmImport().CreateRowContext(nPrefix
,rLocalName
,
2245 /*General Layout Schemata*/
2247 pContext
= GetSmImport().CreateRowContext(nPrefix
,rLocalName
,
2251 pContext
= GetSmImport().CreateFracContext(nPrefix
,rLocalName
,
2255 pContext
= GetSmImport().CreateSqrtContext(nPrefix
,rLocalName
,
2259 pContext
= GetSmImport().CreateRootContext(nPrefix
,rLocalName
,
2262 case XML_TOK_MSTYLE
:
2263 pContext
= GetSmImport().CreateStyleContext(nPrefix
,rLocalName
,
2266 case XML_TOK_MERROR
:
2267 pContext
= GetSmImport().CreateErrorContext(nPrefix
,rLocalName
,
2270 case XML_TOK_MPADDED
:
2271 pContext
= GetSmImport().CreatePaddedContext(nPrefix
,rLocalName
,
2274 case XML_TOK_MPHANTOM
:
2275 pContext
= GetSmImport().CreatePhantomContext(nPrefix
,rLocalName
,
2278 case XML_TOK_MFENCED
:
2279 pContext
= GetSmImport().CreateFencedContext(nPrefix
,rLocalName
,
2282 /*Script and Limit Schemata*/
2284 pContext
= GetSmImport().CreateSubContext(nPrefix
,rLocalName
,
2288 pContext
= GetSmImport().CreateSupContext(nPrefix
,rLocalName
,
2291 case XML_TOK_MSUBSUP
:
2292 pContext
= GetSmImport().CreateSubSupContext(nPrefix
,rLocalName
,
2295 case XML_TOK_MUNDER
:
2296 pContext
= GetSmImport().CreateUnderContext(nPrefix
,rLocalName
,
2300 pContext
= GetSmImport().CreateOverContext(nPrefix
,rLocalName
,
2303 case XML_TOK_MUNDEROVER
:
2304 pContext
= GetSmImport().CreateUnderOverContext(nPrefix
,rLocalName
,
2307 case XML_TOK_MMULTISCRIPTS
:
2308 pContext
= GetSmImport().CreateMultiScriptsContext(nPrefix
,
2309 rLocalName
, xAttrList
);
2311 case XML_TOK_MTABLE
:
2312 pContext
= GetSmImport().CreateTableContext(nPrefix
,
2313 rLocalName
, xAttrList
);
2315 case XML_TOK_MACTION
:
2316 pContext
= GetSmImport().CreateActionContext(nPrefix
,
2317 rLocalName
, xAttrList
);
2320 /*Basically theres an implicit mrow around certain bare
2321 *elements, use a RowContext to see if this is one of
2323 SmXMLRowContext_Impl
aTempContext(GetSmImport(),nPrefix
,
2324 GetXMLToken(XML_MROW
));
2326 pContext
= aTempContext
.StrictCreateChildContext(nPrefix
,
2327 rLocalName
, xAttrList
);
2333 void SmXMLDocContext_Impl::EndElement()
2335 SmNodeArray ContextArray
;
2336 ContextArray
.resize(1);
2337 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2339 for (ULONG i
=0;i
< 1;i
++)
2340 ContextArray
[i
] = rNodeStack
.Pop();
2343 SmStructureNode
*pSNode
= new SmLineNode(aDummy
);
2344 pSNode
->SetSubNodes(ContextArray
);
2345 rNodeStack
.Push(pSNode
);
2347 SmNodeArray LineArray
;
2348 ULONG n
= rNodeStack
.Count();
2349 LineArray
.resize(n
);
2350 for (ULONG j
= 0; j
< n
; j
++)
2351 LineArray
[n
- (j
+ 1)] = rNodeStack
.Pop();
2352 SmStructureNode
*pSNode2
= new SmTableNode(aDummy
);
2353 pSNode2
->SetSubNodes(LineArray
);
2354 rNodeStack
.Push(pSNode2
);
2357 void SmXMLFracContext_Impl::EndElement()
2360 aToken
.cMathChar
= '\0';
2363 aToken
.eType
= TOVER
;
2364 SmStructureNode
*pSNode
= new SmBinVerNode(aToken
);
2365 SmNode
*pOper
= new SmRectangleNode(aToken
);
2366 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2367 DBG_ASSERT(rNodeStack
.Count() - nElementCount
== 2,
2368 "Fraction (mfrac) tag is missing component");
2369 if (rNodeStack
.Count() - nElementCount
== 2)
2371 SmNode
*pSecond
= rNodeStack
.Pop();
2372 SmNode
*pFirst
= rNodeStack
.Pop();
2373 pSNode
->SetSubNodes(pFirst
,pOper
,pSecond
);
2374 rNodeStack
.Push(pSNode
);
2378 void SmXMLRootContext_Impl::EndElement()
2380 /*The <mroot> element requires exactly 2 arguments.*/
2381 DBG_ASSERT(GetSmImport().GetNodeStack().Count() - nElementCount
== 2,
2382 "Root tag is missing component");
2385 aToken
.cMathChar
= MS_SQRT
; //Temporary: alert, based on StarSymbol font
2388 aToken
.eType
= TNROOT
;
2389 SmStructureNode
*pSNode
= new SmRootNode(aToken
);
2390 SmNode
*pOper
= new SmRootSymbolNode(aToken
);
2391 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2392 SmNode
*pIndex
= rNodeStack
.Pop();
2393 SmNode
*pBase
= rNodeStack
.Pop();
2394 pSNode
->SetSubNodes(pIndex
,pOper
,pBase
);
2395 rNodeStack
.Push(pSNode
);
2398 void SmXMLSqrtContext_Impl::EndElement()
2401 <msqrt> accepts any number of arguments; if this number is not 1, its
2402 contents are treated as a single "inferred <mrow>" containing its
2405 if (GetSmImport().GetNodeStack().Count() - nElementCount
> 1)
2406 SmXMLRowContext_Impl::EndElement();
2409 aToken
.cMathChar
= MS_SQRT
; //Temporary: alert, based on StarSymbol font
2412 aToken
.eType
= TSQRT
;
2413 SmStructureNode
*pSNode
= new SmRootNode(aToken
);
2414 SmNode
*pOper
= new SmRootSymbolNode(aToken
);
2415 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2416 pSNode
->SetSubNodes(0,pOper
,rNodeStack
.Pop());
2417 rNodeStack
.Push(pSNode
);
2420 void SmXMLRowContext_Impl::EndElement()
2422 SmNodeArray aRelationArray
;
2423 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2424 ULONG nSize
= rNodeStack
.Count()-nElementCount
;
2428 aRelationArray
.resize(nSize
);
2429 for (ULONG j
=rNodeStack
.Count()-nElementCount
;j
> 0;j
--)
2430 aRelationArray
[j
-1] = rNodeStack
.Pop();
2433 //If the first or last element is an operator with stretchyness
2434 //set then we must create a brace node here from those elements,
2435 //removing the stretchness from the operators and applying it to
2436 //ourselves, and creating the appropiate dummy StarMath none bracket
2437 //to balance the arrangement
2438 if (((aRelationArray
[0]->GetScaleMode() == SCALE_HEIGHT
)
2439 && (aRelationArray
[0]->GetType() == NMATH
))
2440 || ((aRelationArray
[nSize
-1]->GetScaleMode() == SCALE_HEIGHT
)
2441 && (aRelationArray
[nSize
-1]->GetType() == NMATH
)))
2444 aToken
.cMathChar
= '\0';
2448 int nLeft
=0,nRight
=0;
2449 if ((aRelationArray
[0]->GetScaleMode() == SCALE_HEIGHT
)
2450 && (aRelationArray
[0]->GetType() == NMATH
))
2452 aToken
= aRelationArray
[0]->GetToken();
2456 aToken
.cMathChar
= '\0';
2458 aToken
.eType
= TLPARENT
;
2459 SmNode
*pLeft
= new SmMathSymbolNode(aToken
);
2461 if ((aRelationArray
[nSize
-1]->GetScaleMode() == SCALE_HEIGHT
)
2462 && (aRelationArray
[nSize
-1]->GetType() == NMATH
))
2464 aToken
= aRelationArray
[nSize
-1]->GetToken();
2468 aToken
.cMathChar
= '\0';
2470 aToken
.eType
= TRPARENT
;
2471 SmNode
*pRight
= new SmMathSymbolNode(aToken
);
2473 SmNodeArray aRelationArray2
;
2475 //!! nSize-nLeft-nRight may be < 0 !!
2476 int nRelArrSize
= nSize
-nLeft
-nRight
;
2477 if (nRelArrSize
> 0)
2479 aRelationArray2
.resize(nRelArrSize
);
2480 for (int i
=0;i
< nRelArrSize
;i
++)
2481 aRelationArray2
[i
] = aRelationArray
[i
+nLeft
];
2485 SmStructureNode
*pSNode
= new SmBraceNode(aToken
);
2486 SmStructureNode
*pBody
= new SmExpressionNode(aDummy
);
2487 pBody
->SetSubNodes(aRelationArray2
);
2489 pSNode
->SetSubNodes(pLeft
,pBody
,pRight
);
2490 pSNode
->SetScaleMode(SCALE_HEIGHT
);
2491 rNodeStack
.Push(pSNode
);
2495 else //Multiple newlines result in empty row elements
2497 aRelationArray
.resize(1);
2499 aToken
.cMathChar
= '\0';
2502 aToken
.eType
= TNEWLINE
;
2503 aRelationArray
[0] = new SmLineNode(aToken
);
2507 SmStructureNode
*pSNode
= new SmExpressionNode(aDummy
);
2508 pSNode
->SetSubNodes(aRelationArray
);
2509 rNodeStack
.Push(pSNode
);
2513 SvXMLImportContext
*SmXMLRowContext_Impl::StrictCreateChildContext(
2515 const OUString
& rLocalName
,
2516 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
2518 SvXMLImportContext
* pContext
= 0L;
2520 const SvXMLTokenMap
& rTokenMap
= GetSmImport().GetPresElemTokenMap();
2521 switch(rTokenMap
.Get(nPrefix
, rLocalName
))
2523 /*Note that these should accept malignmark subelements, but do not*/
2525 pContext
= GetSmImport().CreateNumberContext(nPrefix
,rLocalName
,
2529 pContext
= GetSmImport().CreateIdentifierContext(nPrefix
,rLocalName
,
2533 pContext
= GetSmImport().CreateOperatorContext(nPrefix
,rLocalName
,
2537 pContext
= GetSmImport().CreateTextContext(nPrefix
,rLocalName
,
2540 case XML_TOK_MSPACE
:
2541 pContext
= GetSmImport().CreateSpaceContext(nPrefix
,rLocalName
,
2545 pContext
= GetSmImport().CreateStringContext(nPrefix
,rLocalName
,
2549 /*Note: The maligngroup should only be seen when the row
2550 * (or decendants) are in a table*/
2551 case XML_TOK_MALIGNGROUP
:
2552 pContext
= GetSmImport().CreateAlignGroupContext(nPrefix
,rLocalName
,
2556 case XML_TOK_ANNOTATION
:
2557 pContext
= GetSmImport().CreateAnnotationContext(nPrefix
,rLocalName
,
2568 SvXMLImportContext
*SmXMLRowContext_Impl::CreateChildContext(
2570 const OUString
& rLocalName
,
2571 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
2573 SvXMLImportContext
* pContext
= StrictCreateChildContext(nPrefix
,
2574 rLocalName
, xAttrList
);
2578 //Hmm, unrecognized for this level, check to see if its
2579 //an element that can have an implicit schema around it
2580 pContext
= SmXMLDocContext_Impl::CreateChildContext(nPrefix
,
2581 rLocalName
,xAttrList
);
2587 SvXMLImportContext
*SmXMLMultiScriptsContext_Impl::CreateChildContext(
2589 const OUString
& rLocalName
,
2590 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
2592 SvXMLImportContext
* pContext
= 0L;
2594 const SvXMLTokenMap
& rTokenMap
= GetSmImport().
2595 GetPresScriptEmptyElemTokenMap();
2596 switch(rTokenMap
.Get(nPrefix
, rLocalName
))
2598 case XML_TOK_MPRESCRIPTS
:
2600 pContext
= GetSmImport().CreatePrescriptsContext(nPrefix
,
2601 rLocalName
, xAttrList
);
2604 pContext
= GetSmImport().CreateNoneContext(nPrefix
,rLocalName
,
2608 pContext
= SmXMLRowContext_Impl::CreateChildContext(nPrefix
,
2609 rLocalName
,xAttrList
);
2615 void SmXMLMultiScriptsContext_Impl::MiddleElement()
2617 bHasPrescripts
=sal_True
;
2619 DBG_ASSERT(GetSmImport().GetNodeStack().Count() - nElementCount
> 0,
2620 "Sub has no arguments");
2621 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2622 if (rNodeStack
.Count()-nElementCount
> 1)
2625 aToken
.cMathChar
= '\0';
2628 aToken
.eType
= TRSUB
;
2629 ULONG nFinalCount
= rNodeStack
.Count()-nElementCount
-1;
2631 SmNodeStack aReverseStack
;
2632 while (rNodeStack
.Count()-nElementCount
)
2634 SmNode
*pThing
= rNodeStack
.Pop();
2635 aReverseStack
.Push(pThing
);
2638 for (ULONG nCount
=0;nCount
< nFinalCount
;nCount
+=2)
2640 SmSubSupNode
*pNode
= new SmSubSupNode(aToken
);
2642 // initialize subnodes array
2643 SmNodeArray aSubNodes
;
2644 aSubNodes
.resize(1 + SUBSUP_NUM_ENTRIES
);
2645 for (ULONG i
= 1; i
< aSubNodes
.size(); i
++)
2646 aSubNodes
[i
] = NULL
;
2648 /*On each loop the base and its sub sup pair becomes the
2649 base for the next loop to which the next sub sup pair is
2650 attached, i.e. wheels within wheels*/
2652 aSubNodes
[0] = aReverseStack
.Pop();
2654 SmNode
*pScriptNode
= aReverseStack
.Pop();
2656 if (pScriptNode
&& ((pScriptNode
->GetToken().eType
!= TIDENT
) ||
2657 (pScriptNode
->GetToken().aText
.Len())))
2658 aSubNodes
[RSUB
+1] = pScriptNode
;
2659 pScriptNode
= aReverseStack
.Pop();
2660 if (pScriptNode
&& ((pScriptNode
->GetToken().eType
!= TIDENT
) ||
2661 (pScriptNode
->GetToken().aText
.Len())))
2662 aSubNodes
[RSUP
+1] = pScriptNode
;
2664 pNode
->SetSubNodes(aSubNodes
);
2665 aReverseStack
.Push(pNode
);
2667 rNodeStack
.Push(aReverseStack
.Pop());
2672 void SmXMLTableContext_Impl::EndElement()
2674 SmNodeArray aExpressionArray
;
2675 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2676 SmNodeStack aReverseStack
;
2677 aExpressionArray
.resize(rNodeStack
.Count()-nElementCount
);
2679 ULONG nRows
= rNodeStack
.Count()-nElementCount
;
2682 SmStructureNode
*pArray
;
2683 for (ULONG i
=rNodeStack
.Count()-nElementCount
;i
> 0;i
--)
2685 pArray
= (SmStructureNode
*)rNodeStack
.Pop();
2686 if (pArray
->GetNumSubNodes() == 0)
2688 //This is a little tricky, it is possible that there was
2689 //be elements that were not inside a <mtd> pair, in which
2690 //case they will not be in a row, i.e. they will not have
2691 //SubNodes, so we have to wait until here before we can
2692 //resolve the situation. Implicitsurrounding tags are
2693 //surprisingly difficult to get right within this
2696 SmNodeArray aRelationArray
;
2697 aRelationArray
.resize(1);
2698 aRelationArray
[0] = pArray
;
2700 pArray
= new SmExpressionNode(aDummy
);
2701 pArray
->SetSubNodes(aRelationArray
);
2704 if (pArray
->GetNumSubNodes() > nCols
)
2705 nCols
= pArray
->GetNumSubNodes();
2706 aReverseStack
.Push(pArray
);
2708 aExpressionArray
.resize(nCols
*nRows
);
2710 while (aReverseStack
.Count())
2712 pArray
= (SmStructureNode
*)aReverseStack
.Pop();
2713 for (USHORT i
=0;i
<pArray
->GetNumSubNodes();i
++)
2714 aExpressionArray
[j
++] = pArray
->GetSubNode(i
);
2718 aToken
.cMathChar
= '\0';
2719 aToken
.nGroup
= TRGROUP
;
2721 aToken
.eType
= TMATRIX
;
2722 SmMatrixNode
*pSNode
= new SmMatrixNode(aToken
);
2723 pSNode
->SetSubNodes(aExpressionArray
);
2724 pSNode
->SetRowCol(static_cast<USHORT
>(nRows
),nCols
);
2725 rNodeStack
.Push(pSNode
);
2728 SvXMLImportContext
*SmXMLTableRowContext_Impl::CreateChildContext(
2730 const OUString
& rLocalName
,
2731 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
2733 SvXMLImportContext
* pContext
= 0L;
2735 const SvXMLTokenMap
& rTokenMap
= GetSmImport().
2736 GetPresTableElemTokenMap();
2737 switch(rTokenMap
.Get(nPrefix
, rLocalName
))
2740 pContext
= GetSmImport().CreateTableCellContext(nPrefix
,
2741 rLocalName
, xAttrList
);
2744 pContext
= SmXMLRowContext_Impl::CreateChildContext(nPrefix
,
2745 rLocalName
,xAttrList
);
2751 SvXMLImportContext
*SmXMLTableContext_Impl::CreateChildContext(
2753 const OUString
& rLocalName
,
2754 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
2756 SvXMLImportContext
* pContext
= 0L;
2758 const SvXMLTokenMap
& rTokenMap
= GetSmImport().
2759 GetPresTableElemTokenMap();
2760 switch(rTokenMap
.Get(nPrefix
, rLocalName
))
2763 pContext
= GetSmImport().CreateTableRowContext(nPrefix
,rLocalName
,
2767 pContext
= SmXMLTableRowContext_Impl::CreateChildContext(nPrefix
,
2768 rLocalName
,xAttrList
);
2774 void SmXMLMultiScriptsContext_Impl::EndElement()
2776 if (!bHasPrescripts
)
2779 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2780 if (rNodeStack
.Count()-nElementCount
> 1)
2783 aToken
.cMathChar
= '\0';
2786 aToken
.eType
= TLSUB
;
2787 ULONG nFinalCount
= rNodeStack
.Count()-nElementCount
-1;
2789 SmNodeStack aReverseStack
;
2790 while (rNodeStack
.Count()-nElementCount
)
2791 aReverseStack
.Push(rNodeStack
.Pop());
2792 for (ULONG nCount
=0;nCount
< nFinalCount
;nCount
+=2)
2794 SmSubSupNode
*pNode
= new SmSubSupNode(aToken
);
2796 // initialize subnodes array
2797 SmNodeArray aSubNodes
;
2798 aSubNodes
.resize(1 + SUBSUP_NUM_ENTRIES
);
2799 for (ULONG i
= 1; i
< aSubNodes
.size(); i
++)
2800 aSubNodes
[i
] = NULL
;
2802 /*On each loop the base and its sub sup pair becomes the
2803 base for the next loop to which the next sub sup pair is
2804 attached, i.e. wheels within wheels*/
2806 aSubNodes
[0] = aReverseStack
.Pop();
2808 SmNode
*pScriptNode
= aReverseStack
.Pop();
2809 if (pScriptNode
->GetToken().aText
.Len())
2810 aSubNodes
[LSUB
+1] = pScriptNode
;
2811 pScriptNode
= aReverseStack
.Pop();
2812 if (pScriptNode
->GetToken().aText
.Len())
2813 aSubNodes
[LSUP
+1] = pScriptNode
;
2815 pNode
->SetSubNodes(aSubNodes
);
2816 aReverseStack
.Push(pNode
);
2818 rNodeStack
.Push(aReverseStack
.Pop());
2822 void SmXMLActionContext_Impl::EndElement()
2824 /*For now we will just assume that the
2825 selected attribute is one, and then just display
2826 that expression alone, i.e. remove all expect the
2829 SmNodeStack
&rNodeStack
= GetSmImport().GetNodeStack();
2830 for (ULONG i
=rNodeStack
.Count()-nElementCount
;i
> 1;i
--)
2832 delete rNodeStack
.Pop();
2836 SvXMLImportContext
*SmXMLImport::CreateContext(sal_uInt16 nPrefix
,
2837 const OUString
&rLocalName
,
2838 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2840 if ( XML_NAMESPACE_OFFICE
== nPrefix
)
2842 if ( (IsXMLToken(rLocalName
, XML_DOCUMENT
) ||
2843 IsXMLToken(rLocalName
, XML_DOCUMENT_META
)))
2845 uno::Reference
<xml::sax::XDocumentHandler
> xDocBuilder(
2846 mxServiceFactory
->createInstance(
2847 ::rtl::OUString::createFromAscii(
2848 "com.sun.star.xml.dom.SAXDocumentBuilder")),
2849 uno::UNO_QUERY_THROW
);
2850 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
2851 GetModel(), uno::UNO_QUERY_THROW
);
2852 return IsXMLToken(rLocalName
, XML_DOCUMENT_META
)
2853 ? new SvXMLMetaDocumentContext(*this,
2854 XML_NAMESPACE_OFFICE
, rLocalName
,
2855 xDPS
->getDocumentProperties(), xDocBuilder
)
2856 // flat OpenDocument file format -- this has not been tested...
2857 : new SmXMLFlatDocContext_Impl( *this, nPrefix
, rLocalName
,
2858 xDPS
->getDocumentProperties(), xDocBuilder
);
2862 return new SmXMLOfficeContext_Impl( *this,nPrefix
,rLocalName
);
2866 return new SmXMLDocContext_Impl(*this,nPrefix
,rLocalName
);
2869 SvXMLImportContext
*SmXMLImport::CreateRowContext(sal_uInt16 nPrefix
,
2870 const OUString
&rLocalName
,
2871 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2873 return new SmXMLRowContext_Impl(*this,nPrefix
,rLocalName
);
2876 SvXMLImportContext
*SmXMLImport::CreateTextContext(sal_uInt16 nPrefix
,
2877 const OUString
&rLocalName
,
2878 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2880 return new SmXMLTextContext_Impl(*this,nPrefix
,rLocalName
);
2883 SvXMLImportContext
*SmXMLImport::CreateAnnotationContext(sal_uInt16 nPrefix
,
2884 const OUString
&rLocalName
,
2885 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2887 return new SmXMLAnnotationContext_Impl(*this,nPrefix
,rLocalName
);
2890 SvXMLImportContext
*SmXMLImport::CreateStringContext(sal_uInt16 nPrefix
,
2891 const OUString
&rLocalName
,
2892 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2894 return new SmXMLStringContext_Impl(*this,nPrefix
,rLocalName
);
2897 SvXMLImportContext
*SmXMLImport::CreateNumberContext(sal_uInt16 nPrefix
,
2898 const OUString
&rLocalName
,
2899 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2901 return new SmXMLNumberContext_Impl(*this,nPrefix
,rLocalName
);
2904 SvXMLImportContext
*SmXMLImport::CreateIdentifierContext(sal_uInt16 nPrefix
,
2905 const OUString
&rLocalName
,
2906 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2908 return new SmXMLIdentifierContext_Impl(*this,nPrefix
,rLocalName
);
2911 SvXMLImportContext
*SmXMLImport::CreateOperatorContext(sal_uInt16 nPrefix
,
2912 const OUString
&rLocalName
,
2913 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2915 return new SmXMLOperatorContext_Impl(*this,nPrefix
,rLocalName
);
2918 SvXMLImportContext
*SmXMLImport::CreateSpaceContext(sal_uInt16 nPrefix
,
2919 const OUString
&rLocalName
,
2920 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2922 return new SmXMLSpaceContext_Impl(*this,nPrefix
,rLocalName
);
2926 SvXMLImportContext
*SmXMLImport::CreateFracContext(sal_uInt16 nPrefix
,
2927 const OUString
&rLocalName
,
2928 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2930 return new SmXMLFracContext_Impl(*this,nPrefix
,rLocalName
);
2933 SvXMLImportContext
*SmXMLImport::CreateSqrtContext(sal_uInt16 nPrefix
,
2934 const OUString
&rLocalName
,
2935 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2937 return new SmXMLSqrtContext_Impl(*this,nPrefix
,rLocalName
);
2940 SvXMLImportContext
*SmXMLImport::CreateRootContext(sal_uInt16 nPrefix
,
2941 const OUString
&rLocalName
,
2942 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2944 return new SmXMLRootContext_Impl(*this,nPrefix
,rLocalName
);
2947 SvXMLImportContext
*SmXMLImport::CreateStyleContext(sal_uInt16 nPrefix
,
2948 const OUString
&rLocalName
,
2949 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2951 return new SmXMLStyleContext_Impl(*this,nPrefix
,rLocalName
);
2954 SvXMLImportContext
*SmXMLImport::CreatePaddedContext(sal_uInt16 nPrefix
,
2955 const OUString
&rLocalName
,
2956 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2958 return new SmXMLPaddedContext_Impl(*this,nPrefix
,rLocalName
);
2961 SvXMLImportContext
*SmXMLImport::CreatePhantomContext(sal_uInt16 nPrefix
,
2962 const OUString
&rLocalName
,
2963 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2965 return new SmXMLPhantomContext_Impl(*this,nPrefix
,rLocalName
);
2968 SvXMLImportContext
*SmXMLImport::CreateFencedContext(sal_uInt16 nPrefix
,
2969 const OUString
&rLocalName
,
2970 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2972 return new SmXMLFencedContext_Impl(*this,nPrefix
,rLocalName
);
2975 SvXMLImportContext
*SmXMLImport::CreateErrorContext(sal_uInt16 nPrefix
,
2976 const OUString
&rLocalName
,
2977 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2979 return new SmXMLErrorContext_Impl(*this,nPrefix
,rLocalName
);
2982 SvXMLImportContext
*SmXMLImport::CreateSubContext(sal_uInt16 nPrefix
,
2983 const OUString
&rLocalName
,
2984 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2986 return new SmXMLSubContext_Impl(*this,nPrefix
,rLocalName
);
2989 SvXMLImportContext
*SmXMLImport::CreateSubSupContext(sal_uInt16 nPrefix
,
2990 const OUString
&rLocalName
,
2991 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
2993 return new SmXMLSubSupContext_Impl(*this,nPrefix
,rLocalName
);
2996 SvXMLImportContext
*SmXMLImport::CreateSupContext(sal_uInt16 nPrefix
,
2997 const OUString
&rLocalName
,
2998 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3000 return new SmXMLSupContext_Impl(*this,nPrefix
,rLocalName
);
3003 SvXMLImportContext
*SmXMLImport::CreateUnderContext(sal_uInt16 nPrefix
,
3004 const OUString
&rLocalName
,
3005 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3007 return new SmXMLUnderContext_Impl(*this,nPrefix
,rLocalName
);
3010 SvXMLImportContext
*SmXMLImport::CreateOverContext(sal_uInt16 nPrefix
,
3011 const OUString
&rLocalName
,
3012 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3014 return new SmXMLOverContext_Impl(*this,nPrefix
,rLocalName
);
3017 SvXMLImportContext
*SmXMLImport::CreateUnderOverContext(sal_uInt16 nPrefix
,
3018 const OUString
&rLocalName
,
3019 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3021 return new SmXMLUnderOverContext_Impl(*this,nPrefix
,rLocalName
);
3024 SvXMLImportContext
*SmXMLImport::CreateMultiScriptsContext(sal_uInt16 nPrefix
,
3025 const OUString
&rLocalName
,
3026 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3028 return new SmXMLMultiScriptsContext_Impl(*this,nPrefix
,rLocalName
);
3031 SvXMLImportContext
*SmXMLImport::CreateTableContext(sal_uInt16 nPrefix
,
3032 const OUString
&rLocalName
,
3033 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3035 return new SmXMLTableContext_Impl(*this,nPrefix
,rLocalName
);
3037 SvXMLImportContext
*SmXMLImport::CreateTableRowContext(sal_uInt16 nPrefix
,
3038 const OUString
&rLocalName
,
3039 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3041 return new SmXMLTableRowContext_Impl(*this,nPrefix
,rLocalName
);
3043 SvXMLImportContext
*SmXMLImport::CreateTableCellContext(sal_uInt16 nPrefix
,
3044 const OUString
&rLocalName
,
3045 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3047 return new SmXMLTableCellContext_Impl(*this,nPrefix
,rLocalName
);
3050 SvXMLImportContext
*SmXMLImport::CreateNoneContext(sal_uInt16 nPrefix
,
3051 const OUString
&rLocalName
,
3052 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3054 return new SmXMLNoneContext_Impl(*this,nPrefix
,rLocalName
);
3057 SvXMLImportContext
*SmXMLImport::CreatePrescriptsContext(sal_uInt16 nPrefix
,
3058 const OUString
&rLocalName
,
3059 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3061 return new SmXMLPrescriptsContext_Impl(*this,nPrefix
,rLocalName
);
3064 SvXMLImportContext
*SmXMLImport::CreateAlignGroupContext(sal_uInt16 nPrefix
,
3065 const OUString
&rLocalName
,
3066 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3068 return new SmXMLAlignGroupContext_Impl(*this,nPrefix
,rLocalName
);
3071 SvXMLImportContext
*SmXMLImport::CreateActionContext(sal_uInt16 nPrefix
,
3072 const OUString
&rLocalName
,
3073 const uno::Reference
<xml::sax::XAttributeList
> & /*xAttrList*/)
3075 return new SmXMLActionContext_Impl(*this,nPrefix
,rLocalName
);
3078 SmXMLImport::~SmXMLImport() throw ()
3080 delete pPresLayoutElemTokenMap
;
3081 delete pPresElemTokenMap
;
3082 delete pPresScriptEmptyElemTokenMap
;
3083 delete pPresTableElemTokenMap
;
3084 delete pPresLayoutAttrTokenMap
;
3085 delete pFencedAttrTokenMap
;
3086 delete pColorTokenMap
;
3087 delete pOperatorAttrTokenMap
;
3088 delete pAnnotationAttrTokenMap
;
3091 void SmXMLImport::SetViewSettings(const Sequence
<PropertyValue
>& aViewProps
)
3093 uno::Reference
<frame::XModel
> xModel
= GetModel();
3097 uno::Reference
<lang::XUnoTunnel
> xTunnel
;
3098 xTunnel
= uno::Reference
<lang::XUnoTunnel
> (xModel
,uno::UNO_QUERY
);
3099 SmModel
*pModel
= reinterpret_cast<SmModel
*>
3100 (xTunnel
->getSomething(SmModel::getUnoTunnelId()));
3105 SmDocShell
*pDocShell
=
3106 static_cast<SmDocShell
*>(pModel
->GetObjectShell());
3110 Rectangle
aRect( pDocShell
->GetVisArea() );
3112 sal_Int32 nCount
= aViewProps
.getLength();
3113 const PropertyValue
*pValue
= aViewProps
.getConstArray();
3116 //sal_Bool bShowDeletes = sal_False, bShowInserts = sal_False, bShowFooter = sal_False, bShowHeader = sal_False;
3118 for (sal_Int32 i
= 0; i
< nCount
; i
++)
3120 if (pValue
->Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaTop" ) ) )
3122 pValue
->Value
>>= nTmp
;
3125 else if (pValue
->Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaLeft" ) ) )
3127 pValue
->Value
>>= nTmp
;
3130 else if (pValue
->Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaWidth" ) ) )
3132 pValue
->Value
>>= nTmp
;
3133 Size
aSize( aRect
.GetSize() );
3134 aSize
.Width() = nTmp
;
3135 aRect
.SetSize( aSize
);
3137 else if (pValue
->Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaHeight" ) ) )
3139 pValue
->Value
>>= nTmp
;
3140 Size
aSize( aRect
.GetSize() );
3141 aSize
.Height() = nTmp
;
3142 aRect
.SetSize( aSize
);
3147 pDocShell
->SetVisArea ( aRect
);
3150 void SmXMLImport::SetConfigurationSettings(const Sequence
<PropertyValue
>& aConfProps
)
3152 uno::Reference
< XPropertySet
> xProps ( GetModel(), UNO_QUERY
);
3155 Reference
< XPropertySetInfo
> xInfo ( xProps
->getPropertySetInfo() );
3158 sal_Int32 nCount
= aConfProps
.getLength();
3159 const PropertyValue
* pValues
= aConfProps
.getConstArray();
3161 const OUString
sFormula ( RTL_CONSTASCII_USTRINGPARAM ( "Formula" ) );
3162 const OUString
sBasicLibraries ( RTL_CONSTASCII_USTRINGPARAM ( "BasicLibraries" ) );
3163 const OUString
sDialogLibraries ( RTL_CONSTASCII_USTRINGPARAM ( "DialogLibraries" ) );
3166 if (pValues
->Name
!= sFormula
&&
3167 pValues
->Name
!= sBasicLibraries
&&
3168 pValues
->Name
!= sDialogLibraries
)
3172 if ( xInfo
->hasPropertyByName( pValues
->Name
) )
3173 xProps
->setPropertyValue( pValues
->Name
, pValues
->Value
);
3177 DBG_ERROR( "SmXMLImport::SetConfigurationSettings: Exception!" );
3188 ////////////////////////////////////////////////////////////