From 3d38fdd0050c6ac430ca6ff4b3720d0bcb4492dd Mon Sep 17 00:00:00 2001 From: ElenaSubbotina Date: Wed, 25 Sep 2024 17:14:45 +0300 Subject: [PATCH] refactoring math --- OdfFile/Projects/Windows/OdfFormatW.vcxproj | 2 + .../Windows/OdfFormatW.vcxproj.filters | 9 + OdfFile/Projects/Windows/cpodf.vcxproj | 2 + .../Projects/Windows/cpodf.vcxproj.filters | 1262 +++++------------ .../StarMath2OOXML/cconversionsmtoooxml.cpp | 3 +- .../Converter/StarMath2OOXML/cooxml2odf.cpp | 6 +- OdfFile/Reader/Format/math_elements.cpp | 8 - OdfFile/Writer/Converter/Converter.h | 6 +- OdfFile/Writer/Converter/MathConverter.cpp | 280 +--- OdfFile/Writer/Format/odf_math_context.cpp | 18 +- OdfFile/Writer/Format/odf_math_context.h | 9 +- 11 files changed, 379 insertions(+), 1226 deletions(-) diff --git a/OdfFile/Projects/Windows/OdfFormatW.vcxproj b/OdfFile/Projects/Windows/OdfFormatW.vcxproj index f3700f4dee..c939187b7e 100644 --- a/OdfFile/Projects/Windows/OdfFormatW.vcxproj +++ b/OdfFile/Projects/Windows/OdfFormatW.vcxproj @@ -19,6 +19,7 @@ + @@ -101,6 +102,7 @@ + diff --git a/OdfFile/Projects/Windows/OdfFormatW.vcxproj.filters b/OdfFile/Projects/Windows/OdfFormatW.vcxproj.filters index a8d205d1bb..f035eb6633 100644 --- a/OdfFile/Projects/Windows/OdfFormatW.vcxproj.filters +++ b/OdfFile/Projects/Windows/OdfFormatW.vcxproj.filters @@ -4,6 +4,9 @@ {2c07ccd6-b0a1-40b5-99b2-2c732a124cff} + + {b7620571-58c3-496f-ab28-245c69522663} + @@ -137,6 +140,9 @@ + + math + @@ -217,5 +223,8 @@ + + math + \ No newline at end of file diff --git a/OdfFile/Projects/Windows/cpodf.vcxproj b/OdfFile/Projects/Windows/cpodf.vcxproj index dcb8f521d8..805181c0db 100644 --- a/OdfFile/Projects/Windows/cpodf.vcxproj +++ b/OdfFile/Projects/Windows/cpodf.vcxproj @@ -681,6 +681,8 @@ + + diff --git a/OdfFile/Projects/Windows/cpodf.vcxproj.filters b/OdfFile/Projects/Windows/cpodf.vcxproj.filters index 68c27b33cf..d4afee8fee 100644 --- a/OdfFile/Projects/Windows/cpodf.vcxproj.filters +++ b/OdfFile/Projects/Windows/cpodf.vcxproj.filters @@ -1,960 +1,338 @@ - + - - {e8d90800-7021-4032-8d17-274da4aa8e51} - - - {9727d03b-cbbc-4826-8201-33a7efbe18ae} - - - {be7ec2fb-7bd5-4d53-b95d-c8fdc54ce7e1} - - - {cd06f6d0-4dca-49f4-9dd1-f3ef8bc9ccad} - - - {364be721-ed85-4b58-a882-46ad3b9fa58e} - - - {deeff4dd-2ea3-4438-a021-54ddc8f67f16} - - - {ebc99137-74a5-4b8c-9e31-56190141e2bd} - - - {67b2bf43-5673-4a6f-82cb-fe4be01aee5f} - - - {7d3e34d2-a224-4d68-9144-4889bbcc3698} - - - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - oox\docx - - - oox\docx - - - oox\docx - - - oox\docx - - - oox\docx - - - oox\docx - - - oox\docx - - - oox\docx - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx\styles - - - oox\xlsx\styles - + - - oox\pptx - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - starmath + math - starmath - - elements + math - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - elements - - - oox\docx - - - oox\docx - - - oox\docx - - - oox\docx - - - oox\docx - - - oox\docx - - - oox\docx - - - oox\docx - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\oox\chart - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\pptx - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx\styles - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx - - - oox\xlsx\styles - - - oox\xlsx\styles - + - - oox\pptx - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - starmath + math - starmath + math + + + math + + + math - starmath - - elements + math + + + {36f1d987-256f-4be8-93b9-74cd74341f45} + + \ No newline at end of file diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp index 8d091fa5d9..3aaecc45ff 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cconversionsmtoooxml.cpp @@ -38,7 +38,8 @@ namespace StarMath { } CConversionSMtoOOXML::~CConversionSMtoOOXML() { - delete m_pXmlWrite; + if (m_pXmlWrite) + delete m_pXmlWrite; } //check XMLWrite(if not nullptr == delete) void CConversionSMtoOOXML::StartConversion(std::vector arPars, const unsigned int& iAlignment) diff --git a/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.cpp b/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.cpp index dfde5785ea..3a157772e1 100644 --- a/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.cpp +++ b/OdfFile/Reader/Converter/StarMath2OOXML/cooxml2odf.cpp @@ -34,9 +34,9 @@ namespace StarMath m_pXmlWrite->WriteNodeEnd(L"w",true,false); m_pXmlWrite->WriteString(m_wsAnnotationStarMath); EndOdf(); - NSFile::CFileBinary oOriginal; - oOriginal.CreateFile(L"X:/Rabotka/Original.txt"); - oOriginal.WriteStringUTF8(m_pXmlWrite->GetXmlString()); + //NSFile::CFileBinary oOriginal; + //oOriginal.CreateFile(L"X:/Rabotka/Original.txt"); + //oOriginal.WriteStringUTF8(m_pXmlWrite->GetXmlString()); } void COOXml2Odf::NodeDefinition(OOX::WritingElement *pNode,const bool& bMatrix) { diff --git a/OdfFile/Reader/Format/math_elements.cpp b/OdfFile/Reader/Format/math_elements.cpp index a47bea0701..9e354bf1ac 100644 --- a/OdfFile/Reader/Format/math_elements.cpp +++ b/OdfFile/Reader/Format/math_elements.cpp @@ -112,13 +112,6 @@ void math_semantics::oox_convert(oox::math_context &Context, int iTypeConversion StarMath::CParserStarMathString parser; StarMath::CConversionSMtoOOXML converter; - // базовые свойства шрифта для математики - /*parser.set*/ /*?*/ /*converter.set*/ Context.base_font_name_; - /*parser.set*/ /*?*/ /*converter.set*/ Context.base_font_size_; - /*parser.set*/ /*?*/ /*converter.set*/ Context.base_alignment_; - /*parser.set*/ /*?*/ /*converter.set*/ Context.base_font_italic_; - /*parser.set*/ /*?*/ /*converter.set*/ Context.base_font_bold_; - parser.SetBaseFont(Context.base_font_name_); parser.SetBaseSize(Context.base_font_size_); parser.SetBaseAlignment(Context.base_alignment_); @@ -127,7 +120,6 @@ void math_semantics::oox_convert(oox::math_context &Context, int iTypeConversion /*result = */converter.StartConversion(parser.Parse(annotation_text,iTypeConversion),parser.GetAlignment()); - Context.output_stream() << converter.GetOOXML(); } diff --git a/OdfFile/Writer/Converter/Converter.h b/OdfFile/Writer/Converter/Converter.h index 72b6617e26..36c081a94d 100644 --- a/OdfFile/Writer/Converter/Converter.h +++ b/OdfFile/Writer/Converter/Converter.h @@ -31,7 +31,8 @@ */ #pragma once -#include +#include "../../Common/CPOptional.h" + #include "../../../OOXML/Base/SmartPtr.h" #include "../../../OOXML/DocxFormat/Math/oMathContent.h" #include "../../../OOXML/DocxFormat/Logic/VmlWord.h" @@ -680,8 +681,7 @@ public: std::vector>& brackets(); int& lvl_of_me(); std::vector& end_counter(); - std::wstring& annotation(); - bool& annotation_flag(); + void lvl_up_counter_increace(double val); void lvl_up_counter_decreace(double val); void lvl_down_counter_increace(double val); diff --git a/OdfFile/Writer/Converter/MathConverter.cpp b/OdfFile/Writer/Converter/MathConverter.cpp index abea02d0cd..87dd901a65 100644 --- a/OdfFile/Writer/Converter/MathConverter.cpp +++ b/OdfFile/Writer/Converter/MathConverter.cpp @@ -33,6 +33,8 @@ //#include "../utils.h" +#include "../../Reader/Converter/StarMath2OOXML/cooxml2odf.h" + #include "../../OOXML/DocxFormat/DocxFlat.h" #include "../../OOXML/DocxFormat/Math/OMath.h" #include "../../OOXML/DocxFormat/Math/oMathContent.h" @@ -97,56 +99,6 @@ namespace Oox2Odf lvl_down_counter += val; } - std::wstring& OoxConverter::annotation() - { - return odf_context()->math_context()->annotation; - } - - void annotaionReplaceAll(std::wstring& annotation, std::wstring substr1, std::wstring substr2) - { - size_t pos = annotation.find(substr1); - while (pos != std::wstring::npos) - { - annotation.replace(pos, substr1.size(), substr2); - pos = annotation.find(substr1, pos + substr2.size()); - } - } - - void annotationPostProd(std::wstring& annotation) - { - annotaionReplaceAll(annotation, L"=", L"\"=\""); - annotaionReplaceAll(annotation, L"+", L"\"+\""); - annotaionReplaceAll(annotation, L"-", L"\"-\""); - annotaionReplaceAll(annotation, L"{) }", L")"); - annotaionReplaceAll(annotation, L"{( }", L"("); - annotaionReplaceAll(annotation, L"*", L"\"*\""); - annotaionReplaceAll(annotation, L"|", L"\"|\""); - // ∥ - size_t pos = annotation.find(L"∥"); - std::vector positions; - //positions.push_back(pos); - while (pos != std::wstring::npos) - { - positions.push_back(pos); - pos = annotation.find(L"∥", pos + 1); - } - std::wstring str1 = L"ldline"; - std::wstring str2 = L"rdline"; - for (int i = positions.size() - 1; i >= 0; i--) - { - if (i % 2 == 0) - annotation.replace(positions[i], 1, str1); - else - annotation.replace(positions[i], 1, str2); - } - - //if (annotation[0] == L'=') - // annotation = L"\"\"" + annotation; - - //if ((annotation[annotation.size() - 1] == L'=') || (annotation[annotation.size() - 1] == L' ') && annotation[annotation.size() - 2] == L'=') - // annotation = annotation + L"\"\""; - } - std::vector hexToIntColor(std::wstring clr) { std::vector rgb; @@ -198,11 +150,6 @@ namespace Oox2Odf return arrColor[index]; } - bool& OoxConverter::annotation_flag() - { - return odf_context()->math_context()->annotation_flag; - } - void OoxConverter::mrow() // обертка для тега { CREATE_MATH_TAG(L"mrow"); @@ -227,33 +174,12 @@ namespace Oox2Odf brackets().resize(1); bool bStart = odf_context()->start_math(); - for (size_t i = 0; i < oox_math->m_arrItems.size(); ++i) { convert(oox_math->m_arrItems[i]); - } - if (annotation_flag()) - { - CREATE_MATH_TAG(L"annotation"); - typedef odf_writer::math_annotation* T; - T tmp = dynamic_cast(elm.get()); - if (tmp) - { - tmp->encoding_ = L"StarMath 5.0"; - } - - annotationPostProd(annotation()); + } - elm->add_text(annotation()); - OPEN_MATH_TAG(elm); - CLOSE_MATH_TAG; - } - else - annotation_flag() = true; - annotation().clear(); - - if (bStart) odf_context()->end_math(); } @@ -294,7 +220,26 @@ namespace Oox2Odf { convert(oox_math_para->m_arrItems[i]); } +// перенести в OMath + StarMath::COOXml2Odf starMathConverter; + starMathConverter.StartConversion(oox_math_para); + std::wstring annotation_text = starMathConverter.GetAnnotation(); + + if (false == annotation_text.empty()) + { + CREATE_MATH_TAG(L"annotation"); + typedef odf_writer::math_annotation* T; + T tmp = dynamic_cast(elm.get()); + if (tmp) + { + tmp->encoding_ = L"StarMath 5.0"; + } + elm->add_text(annotation_text); + + OPEN_MATH_TAG(elm); + CLOSE_MATH_TAG; + } if (bStart) odf_context()->end_math(); } @@ -335,25 +280,9 @@ namespace Oox2Odf std::wstring symbol; symbol = (map[diakSymbol]); - std::map& annotation_map = odf_context()->math_context()->annotation_diak_symbols; - bool annotation_flag; - if (annotation_map.find(symbol) != annotation_map.end()) - { - annotation() += annotation_map[symbol] + L" "; - annotation_flag = true; - } - else - annotation_flag = false; - - annotation() += L"{"; convert(oox_acc->m_oElement.GetPointer()); - annotation() += L"}"; - if (!annotation_flag) - { - annotation() += L" csup "; - annotation() += L"\"" + symbol + L"\""; - } + { CREATE_MATH_TAG(L"mo"); elm->add_text(symbol); @@ -366,7 +295,6 @@ namespace Oox2Odf if (values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -413,9 +341,6 @@ namespace Oox2Odf CREATE_MATH_TAG(tag.c_str()); OPEN_MATH_TAG(elm); { - if(values.auxFlag) annotation() += L"bar {"; - else annotation() += L"underline { "; - convert(oox_bar->m_oElement.GetPointer()); CREATE_MATH_TAG(L"mo"); if (values.auxFlag) elm->add_text(L"¯"); @@ -423,8 +348,6 @@ namespace Oox2Odf OPEN_MATH_TAG(elm); CLOSE_MATH_TAG; - - annotation() += L"} "; } CLOSE_MATH_TAG; if (values.auxFlag) @@ -434,7 +357,6 @@ namespace Oox2Odf if (values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -461,7 +383,6 @@ namespace Oox2Odf if (values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -499,7 +420,6 @@ namespace Oox2Odf if (val.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -571,10 +491,6 @@ namespace Oox2Odf } OPEN_MATH_TAG(elm); CLOSE_MATH_TAG; - if (values.begEndChrs.first == L"") - annotation() += L"left none "; //left none - else - annotation() += L"left " + odf_context()->math_context()->annotation_brackets_begin[values.begEndChrs.first] + L" "; } for (size_t i = 0; i < oox_del->m_arrItems.size(); ++i) @@ -597,17 +513,11 @@ namespace Oox2Odf } OPEN_MATH_TAG(elm); CLOSE_MATH_TAG; - if (values.begEndChrs.second == L"") - annotation() += L"right none "; //right none - else - annotation() += L"right " + odf_context()->math_context()->annotation_brackets_end[values.begEndChrs.second] + L" "; - } endOfMrow(); if (values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -660,8 +570,6 @@ namespace Oox2Odf CREATE_MATH_TAG(L"mtable"); OPEN_MATH_TAG(elm); { - for (size_t i = 1; i < oox_eq_arr->m_arrItems.size() - 1; ++i) - annotation() += L" binom "; for (size_t i = 1; i < oox_eq_arr->m_arrItems.size(); ++i) { CREATE_MATH_TAG(L"mtr"); @@ -670,9 +578,7 @@ namespace Oox2Odf CREATE_MATH_TAG(L"mtd"); OPEN_MATH_TAG(elm); mrow(); - annotation() += L"{"; convert(oox_eq_arr->m_arrItems[i]); - annotation() += L"} "; endOfMrow(); CLOSE_MATH_TAG; } @@ -683,7 +589,6 @@ namespace Oox2Odf if(values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -735,15 +640,10 @@ namespace Oox2Odf if (val.str == L"lin") { - - annotation() += L"{"; - mrow(); convert(oox_fraction->m_oNum.GetPointer()); endOfMrow(); - annotation() += L"} / {"; - CREATE_MATH_TAG(L"mo"); elm->add_text(L"/"); OPEN_MATH_TAG(elm); @@ -751,8 +651,6 @@ namespace Oox2Odf mrow(); convert(oox_fraction->m_oDen.GetPointer()); endOfMrow(); - - annotation() += L"}"; } else if (val.str == L"skw") { @@ -767,15 +665,12 @@ namespace Oox2Odf tmp->bevelled = true; } OPEN_MATH_TAG(elm); - annotation() += L"{"; mrow(); convert(oox_fraction->m_oNum.GetPointer()); endOfMrow(); - annotation() += L"} wideslash {"; mrow(); convert(oox_fraction->m_oDen.GetPointer()); endOfMrow(); - annotation() += L"}"; CLOSE_MATH_TAG; lvl_up_counter_decreace(1); lvl_down_counter_increace(1); @@ -790,12 +685,12 @@ namespace Oox2Odf { CREATE_MATH_TAG(L"mtd"); OPEN_MATH_TAG(elm); - annotation() += L"binom{"; + mrow(); convert(oox_fraction->m_oNum.GetPointer()); endOfMrow(); + CLOSE_MATH_TAG; - annotation() += L"} {"; } CLOSE_MATH_TAG; } @@ -809,7 +704,6 @@ namespace Oox2Odf convert(oox_fraction->m_oDen.GetPointer()); endOfMrow(); CLOSE_MATH_TAG; - annotation() += L"}"; } CLOSE_MATH_TAG; } @@ -820,23 +714,22 @@ namespace Oox2Odf CREATE_MATH_TAG(L"mfrac"); lvl_up_counter_increace(1); lvl_down_counter_decreace(1); - annotation() += L"{"; + OPEN_MATH_TAG(elm); mrow(); convert(oox_fraction->m_oNum.GetPointer()); endOfMrow(); - annotation() += L"} over {"; + mrow(); convert(oox_fraction->m_oDen.GetPointer()); endOfMrow(); - annotation() += L"}"; + CLOSE_MATH_TAG; lvl_up_counter_decreace(1); lvl_down_counter_increace(1); } if (val.colorFlag) { - annotation() += L"}"; CLOSE_MATH_TAG; } } @@ -895,7 +788,6 @@ namespace Oox2Odf if (values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -969,16 +861,11 @@ namespace Oox2Odf { if (oox_lim) { - annotation() += L"overbrace {"; convert(oox_lim); - annotation() += L"}"; } - else - annotation() += L"overbrace \"\""; } else { - annotation() += L" csup "; convert(oox_group_ch->m_oGroupChrPr->m_oChr.GetPointer()); } } @@ -986,7 +873,6 @@ namespace Oox2Odf { if (oox_group_ch->m_oGroupChrPr->m_oChr.IsInit()) { - annotation() += L" csub "; convert(oox_group_ch->m_oGroupChrPr->m_oChr.GetPointer()); } else @@ -995,14 +881,11 @@ namespace Oox2Odf elm->add_text(L" ⏟ "); OPEN_MATH_TAG(elm); CLOSE_MATH_TAG; + if (oox_lim) { - annotation() += L"underbrace {"; convert(oox_lim); - annotation() += L"}"; } - else - annotation() += L"underbrace \"\""; } } CLOSE_MATH_TAG; @@ -1013,7 +896,6 @@ namespace Oox2Odf if (values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -1061,14 +943,11 @@ namespace Oox2Odf } else { - odf_context()->math_context()->annotation_oper_flag = true; mrow(); convert(oox_lim_low->m_oElement.GetPointer()); endOfMrow(); - annotation() += L"from {"; convert(oox_lim_low->m_oLim.GetPointer()); - annotation() += L"} "; } CLOSE_MATH_TAG; @@ -1080,7 +959,6 @@ namespace Oox2Odf if (values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -1121,15 +999,11 @@ namespace Oox2Odf } else { - annotation() += L"oper "; - mrow(); convert(oox_lim_upp->m_oElement.GetPointer()); endOfMrow(); - annotation() += L"to {"; convert(oox_lim_upp->m_oLim.GetPointer()); - annotation() += L"} "; } @@ -1139,7 +1013,6 @@ namespace Oox2Odf if (values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -1173,7 +1046,7 @@ namespace Oox2Odf CREATE_MATH_TAG(L"mtable"); OPEN_MATH_TAG(elm); - annotation() += L"matrix{"; + for (size_t i = 0; i < oox_matrix->m_arrItems.size(); ++i) { if(oox_matrix->m_arrItems[i]->getType() != OOX::EElementType::et_m_mPr) @@ -1182,11 +1055,10 @@ namespace Oox2Odf CLOSE_MATH_TAG; odf_context()->math_context()->matrix_row_counter = 0; - annotation() += L"} "; + if (values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -1293,18 +1165,14 @@ namespace Oox2Odf OPEN_MATH_TAG(elm); convert(oox_mr->m_arrItems[i]); CLOSE_MATH_TAG; - if( i != oox_mr->m_arrItems.size() - 1) - annotation() += L"# "; } CLOSE_MATH_TAG; matrix_row_counter--; - if(matrix_row_counter > 0) - annotation() += L"## "; + if(color_flag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -1351,15 +1219,10 @@ namespace Oox2Odf convert(oox_mrun->m_oText.GetPointer()); convert(oox_mrun->m_oYearLong.GetPointer()); convert(oox_mrun->m_oYearShort.GetPointer()); + if (clrFlag) { CLOSE_MATH_TAG; - if(odf_context()->math_context()->annotation_oper_flag) - odf_context()->math_context()->annotation_oper_flag = false; - else - { - annotation() += L"}"; - } } } @@ -1409,12 +1272,7 @@ namespace Oox2Odf clr2.erase(0, 1); std::vector rgb = hexToIntColor(clr2); boost::to_upper(clr2); - if (odf_context()->math_context()->annotation_oper_flag) - { - annotation() += L" color hex " + clr2 + L" oper "; - } - else - annotation() += L" color hex " + clr2 + L"{" ; + return true; } } @@ -1442,7 +1300,6 @@ namespace Oox2Odf elm->add_text(sub_s_val); OPEN_MATH_TAG(elm); CLOSE_MATH_TAG; - annotation() += XmlUtils::EncodeXmlString(sub_s_val); sub_s_val.clear(); } CREATE_MATH_TAG(L"mtext"); @@ -1451,7 +1308,6 @@ namespace Oox2Odf OPEN_MATH_TAG(elm); CLOSE_MATH_TAG; - annotation() += XmlUtils::EncodeXmlString(std::wstring(1, s_val[i])) + L" "; } else if (w_val <= 57 && w_val >= 48) @@ -1462,7 +1318,6 @@ namespace Oox2Odf elm->add_text(sub_s_val); OPEN_MATH_TAG(elm); CLOSE_MATH_TAG; - annotation() += XmlUtils::EncodeXmlString(sub_s_val) + L" "; sub_s_val.clear(); } @@ -1472,7 +1327,6 @@ namespace Oox2Odf OPEN_MATH_TAG(elm); CLOSE_MATH_TAG; - annotation() += XmlUtils::EncodeXmlString(std::wstring(1, s_val[i])) + L" "; } else if (mo.find(w_val) != mo.end()) { @@ -1482,7 +1336,6 @@ namespace Oox2Odf elm->add_text(sub_s_val); OPEN_MATH_TAG(elm); CLOSE_MATH_TAG; - annotation() += XmlUtils::EncodeXmlString(sub_s_val) + L" "; sub_s_val.clear(); } @@ -1492,7 +1345,6 @@ namespace Oox2Odf OPEN_MATH_TAG(elm); CLOSE_MATH_TAG; - annotation() += XmlUtils::EncodeXmlString(std::wstring(1, s_val[i])) + L" "; } else // { @@ -1505,7 +1357,6 @@ namespace Oox2Odf elm->add_text(sub_s_val); OPEN_MATH_TAG(elm); CLOSE_MATH_TAG; - annotation() += XmlUtils::EncodeXmlString(sub_s_val) + L" "; } } } @@ -1560,22 +1411,16 @@ std::wstring str1, str2; if (!values.narySubHide) { - - annotation() += str1; - //mrow(); convert(oox_nary->m_oSub.GetPointer()); //endOfMrow(); - annotation() += L"}"; } if (!values.narySupHide) { - annotation() += str2; //mrow(); convert(oox_nary->m_oSup.GetPointer()); //endOfMrow(); - annotation() += L"} "; } if (flag_nary) @@ -1591,15 +1436,12 @@ std::wstring str1, str2; else if (tag == L"munder") lvl_down_counter_increace(1); } - annotation() += L" {"; convert(oox_nary->m_oElement.GetPointer()); - annotation() += L"} "; endOfMrow(); if (values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -1659,21 +1501,11 @@ std::wstring str1, str2; if (!oox_chr || (oox_chr && !oox_chr->m_val.IsInit())) { - annotation() += L"int "; elm->add_text(L"∫"); } else { std::wstring val = oox_chr->m_val->GetValue(); - std::map& map = odf_context()->math_context()->annotation_operators; - if (map.count(val)) - { - flag = true; - annotation() += map[val]; - } - else - //annotation_flag() = false; - annotation() += (val + L" "); elm->add_text(val); } OPEN_MATH_TAG(elm); @@ -1720,11 +1552,11 @@ std::wstring str1, str2; { CREATE_MATH_TAG(L"msqrt"); OPEN_MATH_TAG(elm); - annotation() += L"sqrt {"; + mrow(); convert(oox_rad->m_oElement.GetPointer()); endOfMrow(); - annotation() += L"}"; + CLOSE_MATH_TAG; odf_context()->math_context()->symbol_counter++; } @@ -1734,7 +1566,6 @@ std::wstring str1, str2; if (val.colorFlag) { - annotation() += L"}"; CLOSE_MATH_TAG; } @@ -1766,24 +1597,13 @@ std::wstring str1, str2; CREATE_MATH_TAG(L"mroot"); OPEN_MATH_TAG(elm); - size_t iterator = annotation().size(); - convert(oox_elm); - size_t rootSize = annotation().size() - iterator; - std::wstring root(&annotation()[iterator], rootSize); - mrow(); for (size_t i = 0; i < oox_deg->m_arrItems.size(); ++i) convert(oox_deg->m_arrItems[i]); endOfMrow(); - size_t degreeSize = annotation().size() - rootSize - iterator; - std::wstring degree(&annotation()[iterator + rootSize], degreeSize); - - annotation().erase(iterator); - annotation() += L"nroot {" + degree + L"} {" + root + L"}"; - CLOSE_MATH_TAG; } @@ -1797,13 +1617,10 @@ std::wstring str1, str2; OPEN_MATH_TAG(elm); lvl_up_counter_increace(0.4); lvl_down_counter_decreace(0.4); - annotation() += L"{"; mrow(); convert(oox_s_pre->m_oElement.GetPointer()); endOfMrow(); - annotation() += L"} lsub {"; - { CREATE_MATH_TAG(L"mprescripts"); OPEN_MATH_TAG(elm); @@ -1813,20 +1630,15 @@ std::wstring str1, str2; convert(oox_s_pre->m_oSub.GetPointer()); endOfMrow(); - annotation() += L"} lsup {"; - mrow(); convert(oox_s_pre->m_oSup.GetPointer()); endOfMrow(); - - annotation() += L"}"; } CLOSE_MATH_TAG; lvl_up_counter_decreace(0.4); lvl_down_counter_increace(0.4); if (values.colorFlag) { - annotation() += L"}"; CLOSE_MATH_TAG; } } @@ -1847,14 +1659,11 @@ std::wstring str1, str2; CREATE_MATH_TAG(L"msup"); OPEN_MATH_TAG(elm); lvl_up_counter_increace(0.4); - annotation() += L"{"; mrow(); convert(oox_elm); endOfMrow(); - annotation() += L"}^{"; - mrow(); for (size_t i = 0; i < oox_sup->m_arrItems.size(); ++i) { @@ -1862,7 +1671,6 @@ std::wstring str1, str2; } endOfMrow(); - annotation() += L"}"; CLOSE_MATH_TAG; lvl_up_counter_decreace(0.4); } @@ -1874,20 +1682,16 @@ std::wstring str1, str2; CREATE_MATH_TAG(L"msub"); OPEN_MATH_TAG(elm); lvl_down_counter_decreace(0.4); - annotation() += L"{"; mrow(); convert(oox_elm); endOfMrow(); - annotation() += L"}_{"; - for (size_t i = 0; i < oox_sub->m_arrItems.size(); ++i) { convert(oox_sub->m_arrItems[i]); } - annotation() += L"}"; CLOSE_MATH_TAG; lvl_down_counter_increace(0.4); } @@ -1921,7 +1725,6 @@ std::wstring str1, str2; if (values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -1944,25 +1747,19 @@ std::wstring str1, str2; OPEN_MATH_TAG(elm); lvl_up_counter_increace(0.4); lvl_down_counter_decreace(0.4); - annotation() += L"{"; mrow(); convert(oox_ssub_sup->m_oElement.GetPointer()); endOfMrow(); - annotation() += L"}_{"; - mrow(); convert(oox_ssub_sup->m_oSub.GetPointer()); endOfMrow(); - annotation() += L"}^{"; - mrow(); convert(oox_ssub_sup->m_oSup.GetPointer()); endOfMrow(); - annotation() += L"}"; CLOSE_MATH_TAG; lvl_up_counter_decreace(0.4); lvl_down_counter_increace(0.4); @@ -1970,7 +1767,6 @@ std::wstring str1, str2; if (values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -2000,7 +1796,6 @@ std::wstring str1, str2; if (values.colorFlag) { CLOSE_MATH_TAG; - annotation() += L"}"; } } @@ -2017,9 +1812,6 @@ std::wstring str1, str2; { if (!oox_elm) return; - if (oox_elm->m_arrItems.empty()) - annotation() += L"\"\""; - resizeBrackets(); if (!brackets()[lvl_of_me()].empty()) diff --git a/OdfFile/Writer/Format/odf_math_context.cpp b/OdfFile/Writer/Format/odf_math_context.cpp index 83be706f66..b94a9bf192 100644 --- a/OdfFile/Writer/Format/odf_math_context.cpp +++ b/OdfFile/Writer/Format/odf_math_context.cpp @@ -111,7 +111,7 @@ namespace odf_writer odf_math_context::odf_math_context(odf_conversion_context *odf_context) : impl_(new odf_math_context::Impl(odf_context)), - lvl_of_me(0), style_flag(true), counter(0), symbol_counter(0), annotation_flag(true), annotation_oper_flag(false), matrix_row_counter(0) + lvl_of_me(0), style_flag(true), counter(0), symbol_counter(0), matrix_row_counter(0) { mo = { L'+', L'-', L'±', L'∓', L'∙', L'×', L'∗', L'÷', L'/', L'≂', L'⊕', L'⊖', L'⊙', L'⊗', L'⊘', L'∘', L'¬', L'∧', L'∨', // un/bi operators L'=', L'≠', L'<', L'≤', L'>', L'≥', L'≪', L'≫', L'≈', L'~', L'≃', L'≡', L'∝', L'∥', L'⟂', L'|', L'∤', L'→', L'⊷', // relations @@ -129,22 +129,6 @@ namespace odf_writer //{L'', L''}, { L'', L'' }, { L'', L'' }, { L'', L'' }, { L'', L'' }, { L'', L'' }, { L'', L'' } }; - annotation_diak_symbols = { {L"˙",L"dot"}, {L"¨",L"ddot"}, {L"⃛",L"dddot"}, {L"˄", L"hat"}, {L"ˇ",L"check"}, {L"´",L"acute"}, {L"ˋ",L"grave"}, {L"˘",L"breve"}, - {L"~",L"tilde"},{L"¯",L"overline"},{L"→",L"vec"}, {L"⇀",L"harpoon"}, {L"-",L"underline"}/*, {L"",L""}, {L"",L""}, {L"",L""}, {L"",L""}, {L"",L""}, {L"",L""},{L"",L""}, - {L"",L""}*/ - }; - - annotation_operators = { {L"∫",L"int"}, {L"∬", L"iint "}, {L"∭", L"iiint "}, {L"∮", L"lint "}, {L"∯", L"llint "}, - {L"∰", L"lllint "}, {L"∑", L"sum "}, {L"∏", L"prod "}, {L"∐", L"coprod "} - - }; - - annotation_brackets_begin = { {L"(", L"("}, {L"[", L"["}, {L"{", L"lbrace"}, {L"⟨", L"langle"}, {L"〈", L"langle"}, {L"⌊", L"lfloor"}, {L"⌈", L"lceil"}, {L"|", L"lline"}, {L"‖", L"ldline"}, - {L"]", L"]"}, {L"⟦", L"ldbracket"} - }; - annotation_brackets_end = { {L")", L")"}, {L"]", L"]"}, {L"}", L"rbrace"}, {L"⟩", L"rangle"}, {L"〉", L"rangle"},{L"⌋", L"rfloor"}, {L"⌉", L"rceil"}, {L"|", L"rline"}, {L"‖", L"rdline"}, - {L"[", L"["}, {L"⟧", L"rdbracket"} - }; lvl_counter = 1; lvl_up_counter = 1; lvl_down_counter = -1; diff --git a/OdfFile/Writer/Format/odf_math_context.h b/OdfFile/Writer/Format/odf_math_context.h index 33941348b1..a9ed3f8bed 100644 --- a/OdfFile/Writer/Format/odf_math_context.h +++ b/OdfFile/Writer/Format/odf_math_context.h @@ -112,7 +112,6 @@ namespace cpdoccore { void end_element(); std::vector> brackets; - std::wstring annotation; int lvl_of_me = 0; int matrix_row_counter = 0; std::vector end_counter; @@ -129,13 +128,7 @@ namespace cpdoccore { double size = 0; std::set mo; std::map diak_symbols; - bool annotation_flag; - bool annotation_oper_flag; - std::map annotation_operators; - std::map annotation_brackets_begin; - std::map annotation_brackets_end; - std::map annotation_diak_symbols; - //std::pair, bool> annotation_from_to_operators; + void end_math(); std::wofstream debug_stream;