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