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