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