diff options
author | dante <dante19031999@gmail.com> | 2021-02-17 13:55:33 +0100 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-02-19 15:01:16 +0100 |
commit | a260aac0a26dbf659aff55b8a76fdaa7636def53 (patch) | |
tree | d8964e4a3c3c325f524319bc7abb7fcc5b900fad /starmath | |
parent | b925043f64179c23c5f7cfbc20b7c46cebdd1a26 (diff) |
Starmath now allows multiple parsers
This is an intermediate step towards making a parser wich supports
mathml standards.
The parser now is a "mask" wich calls the correct parser behind the
scenes.
Parser 6 is the same as parser 5, but will be implemented soon.
Parser 5 does what the old parser did.
Using as defualt smsyntax5 in order to be able to code parser6 without
provoking any backguards compatibility problem.
Change-Id: Iccf73e5ba96870450b98907f78a2a0c28abf6093
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111066
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/inc/cfgitem.hxx | 3 | ||||
-rw-r--r-- | starmath/inc/document.hxx | 4 | ||||
-rw-r--r-- | starmath/inc/mathml/mathmlimport.hxx | 3 | ||||
-rw-r--r-- | starmath/inc/starmath.hrc | 1 | ||||
-rw-r--r-- | starmath/source/cfgitem.cxx | 29 | ||||
-rw-r--r-- | starmath/source/document.cxx | 1 | ||||
-rw-r--r-- | starmath/source/mathml/mathmlexport.cxx | 13 | ||||
-rw-r--r-- | starmath/source/mathml/mathmlimport.cxx | 16 |
8 files changed, 65 insertions, 5 deletions
diff --git a/starmath/inc/cfgitem.hxx b/starmath/inc/cfgitem.hxx index 35f0955c243a..8e450d04a1d3 100644 --- a/starmath/inc/cfgitem.hxx +++ b/starmath/inc/cfgitem.hxx @@ -178,6 +178,9 @@ public: bool IsShowFormulaCursor() const; void SetShowFormulaCursor(bool bVal); + sal_uInt16 GetDefaultSmSyntaxVersion() const; + void SetDefaultSmSyntaxVersion(sal_uInt16 nVal); + SmFontPickList& GetFontPickList(sal_uInt16 nIdent) { return vFontPickList[nIdent]; } void ItemSetToConfig(const SfxItemSet& rSet); diff --git a/starmath/inc/document.hxx b/starmath/inc/document.hxx index 1b425c91e7d1..17933546265c 100644 --- a/starmath/inc/document.hxx +++ b/starmath/inc/document.hxx @@ -93,6 +93,7 @@ class SM_DLLPUBLIC SmDocShell : public SfxObjectShell, public SfxListener VclPtr<Printer> mpTmpPrinter; //ditto sal_uInt16 mnModifyCount; bool mbFormulaArranged; + sal_uInt16 mnSmSyntaxVersion; std::unique_ptr<SmCursor> mpCursor; std::set< OUString > maUsedSymbols; // to export used symbols only when saving @@ -174,6 +175,9 @@ public: SmParser & GetParser() { return maParser; } const SmTableNode *GetFormulaTree() const { return mpTree.get(); } void SetFormulaTree(SmTableNode *pTree) { mpTree.reset(pTree); } + sal_uInt16 GetSmSyntaxVersion() const { return mnSmSyntaxVersion; } + void SetSmSyntaxVersion(sal_uInt16 nSmSyntaxVersion) + { mnSmSyntaxVersion = nSmSyntaxVersion; } const std::set< OUString > & GetUsedSymbols() const { return maUsedSymbols; } diff --git a/starmath/inc/mathml/mathmlimport.hxx b/starmath/inc/mathml/mathmlimport.hxx index 215948b4a3cb..efbaeba47908 100644 --- a/starmath/inc/mathml/mathmlimport.hxx +++ b/starmath/inc/mathml/mathmlimport.hxx @@ -78,6 +78,7 @@ class SmXMLImport : public SvXMLImport bool bSuccess; int nParseDepth; OUString aText; + sal_uInt16 mnSmSyntaxVersion; public: SmXMLImport(const css::uno::Reference<css::uno::XComponentContext>& rContext, @@ -108,6 +109,8 @@ public: void IncParseDepth() { ++nParseDepth; } bool TooDeep() const { return nParseDepth >= 2048; } void DecParseDepth() { --nParseDepth; } + void SetSmSyntaxVersion(sal_uInt16 nSmSyntaxVersion) { mnSmSyntaxVersion = nSmSyntaxVersion; } + sal_uInt16 GetSmSyntaxVersion() const { return mnSmSyntaxVersion; } }; #endif diff --git a/starmath/inc/starmath.hrc b/starmath/inc/starmath.hrc index 60fd52e7cade..d8a98c4d0dad 100644 --- a/starmath/inc/starmath.hrc +++ b/starmath/inc/starmath.hrc @@ -68,6 +68,7 @@ #define SID_SAVE_ONLY_USED_SYMBOLS (SID_SMA_START + 125) #define SID_ELEMENTSDOCKINGWINDOW (SID_SMA_START + 126) #define SID_AUTO_CLOSE_BRACKETS (SID_SMA_START + 127) +#define SID_DEFAULT_SM_SYNTAX_VERSION (SID_SMA_START + 130) #endif diff --git a/starmath/source/cfgitem.cxx b/starmath/source/cfgitem.cxx index 2648d749ea89..34dbdebba656 100644 --- a/starmath/source/cfgitem.cxx +++ b/starmath/source/cfgitem.cxx @@ -124,6 +124,7 @@ struct SmCfgOther { SmPrintSize ePrintSize; sal_uInt16 nPrintZoomFactor; + sal_uInt16 nSmSyntaxVersion; bool bPrintTitle; bool bPrintFormulaText; bool bPrintFrame; @@ -141,6 +142,8 @@ struct SmCfgOther SmCfgOther::SmCfgOther() : ePrintSize(PRINT_SIZE_NORMAL) , nPrintZoomFactor(100) + // Defaulted as 5 so I have time to code the parser 6 + , nSmSyntaxVersion(5) , bPrintTitle(true) , bPrintFormulaText(true) , bPrintFrame(true) @@ -748,6 +751,7 @@ void SmMathConfig::LoadOther() pOther->nPrintZoomFactor = officecfg::Office::Math::Print::ZoomFactor::get(); pOther->bIsSaveOnlyUsedSymbols = officecfg::Office::Math::LoadSave::IsSaveOnlyUsedSymbols::get(); pOther->bIsAutoCloseBrackets = officecfg::Office::Math::Misc::AutoCloseBrackets::get(); + pOther->nSmSyntaxVersion = officecfg::Office::Math::Misc::DefaultSmSyntaxVersion::get(); pOther->bIgnoreSpacesRight = officecfg::Office::Math::Misc::IgnoreSpacesRight::get(); pOther->bToolboxVisible = officecfg::Office::Math::View::ToolboxVisible::get(); pOther->bAutoRedraw = officecfg::Office::Math::View::AutoRedraw::get(); @@ -770,6 +774,7 @@ void SmMathConfig::SaveOther() officecfg::Office::Math::Print::ZoomFactor::set(pOther->nPrintZoomFactor, batch); officecfg::Office::Math::LoadSave::IsSaveOnlyUsedSymbols::set(pOther->bIsSaveOnlyUsedSymbols, batch); officecfg::Office::Math::Misc::AutoCloseBrackets::set(pOther->bIsAutoCloseBrackets, batch); + officecfg::Office::Math::Misc::DefaultSmSyntaxVersion::set(pOther->nSmSyntaxVersion, batch); officecfg::Office::Math::Misc::IgnoreSpacesRight::set(pOther->bIgnoreSpacesRight, batch); officecfg::Office::Math::View::ToolboxVisible::set(pOther->bToolboxVisible, batch); officecfg::Office::Math::View::AutoRedraw::set(pOther->bAutoRedraw, batch); @@ -1110,6 +1115,13 @@ bool SmMathConfig::IsAutoCloseBrackets() const return pOther->bIsAutoCloseBrackets; } +sal_uInt16 SmMathConfig::GetDefaultSmSyntaxVersion() const +{ + if (!pOther) + const_cast<SmMathConfig*>(this)->LoadOther(); + return pOther->nSmSyntaxVersion; +} + bool SmMathConfig::IsPrintFrame() const { if (!pOther) @@ -1141,6 +1153,16 @@ void SmMathConfig::SetAutoCloseBrackets( bool bVal ) SetOtherIfNotEqual( pOther->bIsAutoCloseBrackets, bVal ); } +void SmMathConfig::SetDefaultSmSyntaxVersion( sal_uInt16 nVal ) +{ + if (!pOther) + LoadOther(); + if (nVal != pOther->nSmSyntaxVersion) + { + pOther->nSmSyntaxVersion = nVal; + SetOtherModified( true ); + } +} bool SmMathConfig::IsIgnoreSpacesRight() const { @@ -1244,6 +1266,12 @@ void SmMathConfig::ItemSetToConfig(const SfxItemSet &rSet) SetAutoCloseBrackets( bVal ); } + if (rSet.GetItemState(SID_DEFAULT_SM_SYNTAX_VERSION, true, &pItem) == SfxItemState::SET) + { + nU16 = static_cast<const SfxUInt16Item *>(pItem)->GetValue(); + SetDefaultSmSyntaxVersion( nU16 ); + } + SaveOther(); } @@ -1264,6 +1292,7 @@ void SmMathConfig::ConfigToItemSet(SfxItemSet &rSet) const rSet.Put(SfxBoolItem(pPool->GetWhich(SID_NO_RIGHT_SPACES), IsIgnoreSpacesRight())); rSet.Put(SfxBoolItem(pPool->GetWhich(SID_SAVE_ONLY_USED_SYMBOLS), IsSaveOnlyUsedSymbols())); rSet.Put(SfxBoolItem(pPool->GetWhich(SID_AUTO_CLOSE_BRACKETS), IsAutoCloseBrackets())); + rSet.Put(SfxBoolItem(pPool->GetWhich(SID_DEFAULT_SM_SYNTAX_VERSION), GetDefaultSmSyntaxVersion())); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx index d44c41f2a6f4..a80297cac604 100644 --- a/starmath/source/document.cxx +++ b/starmath/source/document.cxx @@ -620,6 +620,7 @@ SmDocShell::SmDocShell( SfxModelFlags i_nSfxCreationFlags ) , mpTmpPrinter(nullptr) , mnModifyCount(0) , mbFormulaArranged(false) + , mnSmSyntaxVersion(SM_MOD()->GetConfig()->GetDefaultSmSyntaxVersion()) { SvtLinguConfig().GetOptions(maLinguOptions); diff --git a/starmath/source/mathml/mathmlexport.cxx b/starmath/source/mathml/mathmlexport.cxx index f9d7affd02e3..e9e65697f83a 100644 --- a/starmath/source/mathml/mathmlexport.cxx +++ b/starmath/source/mathml/mathmlexport.cxx @@ -463,9 +463,13 @@ void SmXMLExport::ExportContent_() if (aText.isEmpty()) return; + SmModule* pMod = SM_MOD(); + sal_uInt16 nSmSyntaxVersion = pMod->GetConfig()->GetDefaultSmSyntaxVersion(); + // Convert symbol names if (pDocShell) { + nSmSyntaxVersion = pDocShell->GetSmSyntaxVersion(); SmParser& rParser = pDocShell->GetParser(); bool bVal = rParser.IsExportSymbolNames(); rParser.SetExportSymbolNames(true); @@ -475,7 +479,14 @@ void SmXMLExport::ExportContent_() rParser.SetExportSymbolNames(bVal); } - AddAttribute(XML_NAMESPACE_MATH, XML_ENCODING, OUString("StarMath 5.0")); + OUStringBuffer sStrBuf(12); + sStrBuf.append(u"StarMath "); + if (nSmSyntaxVersion == 5) + sStrBuf.append(u"5.0"); + else + sStrBuf.append(OUString::number(nSmSyntaxVersion)); + + AddAttribute(XML_NAMESPACE_MATH, XML_ENCODING, sStrBuf.makeStringAndClear()); SvXMLElementExport aAnnotation(*this, XML_NAMESPACE_MATH, XML_ANNOTATION, true, false); GetDocHandler()->characters(aText); } diff --git a/starmath/source/mathml/mathmlimport.cxx b/starmath/source/mathml/mathmlimport.cxx index 9c455d5be86d..b5870bf86324 100644 --- a/starmath/source/mathml/mathmlimport.cxx +++ b/starmath/source/mathml/mathmlimport.cxx @@ -71,6 +71,8 @@ one go*/ #include <utility.hxx> #include <visitors.hxx> #include <starmathdatabase.hxx> +#include <smmod.hxx> +#include <cfgitem.hxx> using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; @@ -402,6 +404,7 @@ SmXMLImport::SmXMLImport(const css::uno::Reference<css::uno::XComponentContext>& : SvXMLImport(rContext, implementationName, nImportFlags) , bSuccess(false) , nParseDepth(0) + , mnSmSyntaxVersion(SM_MOD()->GetConfig()->GetDefaultSmSyntaxVersion()) { } @@ -479,6 +482,7 @@ void SmXMLImport::endDocument() rParser.SetImportSymbolNames(bVal); pDocShell->SetText(aText); + pDocShell->SetSmSyntaxVersion(mnSmSyntaxVersion); } OSL_ENSURE(pModel, "So there *was* a UNO problem after all"); @@ -1194,12 +1198,12 @@ namespace { class SmXMLAnnotationContext_Impl : public SmXMLImportContext { - bool bIsStarMath; + sal_uInt8 mnStarMathVersion; public: SmXMLAnnotationContext_Impl(SmXMLImport& rImport) : SmXMLImportContext(rImport) - , bIsStarMath(false) + , mnStarMathVersion(0) { } @@ -1219,7 +1223,8 @@ void SmXMLAnnotationContext_Impl::startFastElement( switch (aIter.getToken() & TOKEN_MASK) { case XML_ENCODING: - bIsStarMath = aIter.toView() == "StarMath 5.0"; + mnStarMathVersion + = aIter.toView() == "StarMath 5.0" ? 5 : aIter.toView() == "StarMath 6" ? 6 : 0; break; default: XMLOFF_WARN_UNKNOWN("starmath", aIter); @@ -1230,8 +1235,11 @@ void SmXMLAnnotationContext_Impl::startFastElement( void SmXMLAnnotationContext_Impl::characters(const OUString& rChars) { - if (bIsStarMath) + if (mnStarMathVersion) + { GetSmImport().SetText(GetSmImport().GetText() + rChars); + GetSmImport().SetSmSyntaxVersion(mnStarMathVersion); + } } namespace |