Re: [Libreoffice] SmNodeToTextVisitor Fixes
> Sorry, forgot something. And of course I forgot to add the attachments :( >From 1313f82a72ca5c361eead3a86d55f3be394514e0 Mon Sep 17 00:00:00 2001 From: Luke Dixon <6b8b4...@gmail.com> Date: Tue, 23 Nov 2010 16:17:23 + Subject: [PATCH] Fix matrices with blank elements. --- starmath/source/visitors.cxx |2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx index ab2ac87..3b9bdef 100644 --- a/starmath/source/visitors.cxx +++ b/starmath/source/visitors.cxx @@ -2466,9 +2466,11 @@ void SmNodeToTextVisitor::Visit( SmMatrixNode* pNode ) for ( USHORT i = 0; i < pNode->GetNumRows( ); i++ ) { for ( USHORT j = 0; j < pNode->GetNumCols( ); j++ ) { SmNode* pSubNode = pNode->GetSubNode( i * pNode->GetNumCols( ) + j ); +Append( "{" ); Separate( ); pSubNode->Accept( this ); Separate( ); +Append( "}" ); if( j != pNode->GetNumCols( ) - 1 ) Append( "#" ); } -- 1.7.3.2 >From c37501af6c442eb4bef6a5914e83ed1d8e6fe029 Mon Sep 17 00:00:00 2001 From: Luke Dixon <6b8b4...@gmail.com> Date: Tue, 23 Nov 2010 16:49:15 + Subject: [PATCH] Add some tests for SmNodeToTextVisitor. --- starmath/qa/cppunit/makefile.mk |1 + starmath/qa/cppunit/test_nodetotextvisitors.cxx | 462 +++ 2 files changed, 463 insertions(+), 0 deletions(-) create mode 100644 starmath/qa/cppunit/test_nodetotextvisitors.cxx diff --git a/starmath/qa/cppunit/makefile.mk b/starmath/qa/cppunit/makefile.mk index 7bdc6c8..212cb8b 100644 --- a/starmath/qa/cppunit/makefile.mk +++ b/starmath/qa/cppunit/makefile.mk @@ -48,6 +48,7 @@ CFLAGSCXX += $(CPPUNIT_CFLAGS) SHL1OBJS= \ $(SLO)/test_starmath.obj \ +$(SLO)/test_nodetotextvisitors.obj SHL1STDLIBS= \ diff --git a/starmath/qa/cppunit/test_nodetotextvisitors.cxx b/starmath/qa/cppunit/test_nodetotextvisitors.cxx new file mode 100644 index 000..93def14 --- /dev/null +++ b/starmath/qa/cppunit/test_nodetotextvisitors.cxx @@ -0,0 +1,462 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_starmath.hxx" + +#include "sal/config.h" + +#include +using namespace std; + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "preextstl.h" +#include +#include +#include +#include +#include +#include "postextstl.h" + +namespace CppUnit { +template<> +struct assertion_traits +{ +static bool equal(const String& x, const String& y) +{ +return x == y; +} + +static std::string toString(const String& x) +{ +std::string text = ByteString(x, RTL_TEXTENCODING_UTF8).GetBuffer(); +OStringStream ost; +ost << text; +cout << ost.str(); +return ost.str(); +} +}; +} + +SO2_DECL_REF(SmDocShell) +SO2_IMPL_REF(SmDocShell) + +using namespace ::com::sun::star; + +namespace { + +class Test : public CppUnit::TestFixture { +public: +// init +virtual void setUp(); +virtual void tearDown(); + +// tests +void SimpleUnaryOp(); +void SimpleBinaryOp(); +void SimpleRelationalOp(); +void SimpleSetOp(); +void SimpleFunctions(); +void SimpleOperators(); +void SimpleAttributes(); +void SimpleMisc(); +void SimpleBrackets(); +void SimpleFormats(); +void SimpleGreekChars(); +void SimpleSpecialChars(); + +CPPUNIT_TEST_SUITE(Test); +CPPUNIT_TEST(SimpleUnaryOp); +CPPUNIT_TEST(SimpleBinaryOp); +CPPUNIT_TEST(SimpleRelationalOp); +CPPUNIT_TEST(SimpleSetOp); +CPPUNIT_TEST(SimpleFunctions); +CPPUNIT_TEST(SimpleOperators); +CPPUNIT_TEST(SimpleAttributes); +CPPUNIT_TEST(SimpleMisc); +CPPUNIT_TEST(SimpleBrackets); +CPPUNIT_TEST(SimpleFormats); +CPPUNIT_TEST(SimpleGreekChars); +CPPUNIT_TEST(SimpleSpecialChars); +CPPUNIT_TEST_SUITE_END(); + +private: +uno::Reference< uno::XComponentContext > m_context; +SmDocShellRef xDocShRef; +void parseandparseagain(const char *input, const char *test_name); +}; + +void Test::setUp() +{ +m_context = cppu::defaultBootstrap_InitialComponentContext(); + +uno::Reference xFactory(m_context->getServiceManager()); +uno::Reference xSM(xFactory, uno::UNO_QUERY_THROW); + +//Without this we're crashing because callees are using +//getProcessServiceFactory. In general those should be removed in favour +//of retaining references to the root ServiceFactory as its passed around +comphelper::setProcessServiceFactory(xSM); + +InitVCL(xSM); + +SmDLL::Init(); + +xDocShRef = new SmDocShell(SFXOBJECTSHELL_STD_NORMAL); +} + +void Test::tearDown() +{ +} + +/* + * Most of the formula commands in this file came from: + * http://wiki.services.openoffice.org/wiki/Template:Math_comm
Re: [Libreoffice] SmNodeToTextVisitor Fixes
Hello again, Sorry, forgot something. > 3. Some of the subs & sups seemed to need extra brackets when used with > an operator node (for example int or sum). 4. Matrices with blank elements seem to cause problems so I added more brackets (supposed to be removing them :( ). Also, I've made the code used to find these into cppunit tests. I took all the formula commands from: http://wiki.services.openoffice.org/wiki/Template:Math_commands_reference This page is licensed with the Creative Common Attribution 3.0 license (CC-BY), so I put a note in the code with all the contributors names (Hopefully that covers it). What the code does is parses the formula command, runs the NodeToTextVisitor on it, then parses it again, then visits again. It occurred to me that the NodeToTextVisitor should output the same text both times. It was quite fun writing this and learning about the different string types that are used and working out how to do this without putting printf all over the place. I didn't see any of the other tests doing like this with the assertion_traits template and CPPUNIT_ASSERT_EQUAL_MESSAGE, so I hope I haven't gone too far. Regards, Luke ___ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice
[Libreoffice] SmNodeToTextVisitor Fixes
Hello Jonas and list, I started looking at the SmNodeToTextVisitor. There were a few problems I noticed. 1. The Greek and special characters beginning with a % get changed to comments (%%) and then lost. 2. Stacks get ## inserted instead of # for rows. 3. Some of the subs & sups seemed to need extra brackets when used with an operator node (for example int or sum). I also added something I spotted in SmNode::CreateTextFromNode to the NodeToTextVisitor for SmExpressionNodes which makes it so that not so many brackets are added. I also have a very small patch which removes a couple of things from the todo list (maybe it ought to be an unnumbered list, so all the numbers don't need changing each time). Regards, Luke >From 7cb737c90fa6b4f5bcef96add805c2f47b441a86 Mon Sep 17 00:00:00 2001 From: Luke Dixon <6b8b4...@gmail.com> Date: Tue, 23 Nov 2010 10:36:18 + Subject: [PATCH] Fix Greek characters, stacks and subs/sups for operators. --- starmath/source/visitors.cxx | 30 -- 1 files changed, 20 insertions(+), 10 deletions(-) diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx index 6ca86fd..ab2ac87 100644 --- a/starmath/source/visitors.cxx +++ b/starmath/source/visitors.cxx @@ -2174,7 +2174,7 @@ void SmNodeToTextVisitor::Visit( SmTableNode* pNode ) LineToText( it.Current( ) ); if( it.Next( ) ) { Separate( ); -Append( "## " ); +Append( "# " ); }else break; } @@ -2242,33 +2242,39 @@ void SmNodeToTextVisitor::Visit( SmOperNode* pNode ) SmNode* pChild; if( ( pChild = pSubSup->GetSubSup( LSUP ) ) ) { Separate( ); -Append( "lsup " ); +Append( "lsup { " ); LineToText( pChild ); +Append( "} "); } if( ( pChild = pSubSup->GetSubSup( LSUB ) ) ) { Separate( ); -Append( "lsub " ); +Append( "lsub { " ); LineToText( pChild ); +Append( "} "); } if( ( pChild = pSubSup->GetSubSup( RSUP ) ) ) { Separate( ); -Append( "rsup " ); +Append( "rsup { " ); LineToText( pChild ); +Append( "} "); } if( ( pChild = pSubSup->GetSubSup( RSUB ) ) ) { Separate( ); -Append( "rsub " ); +Append( "rsub { " ); LineToText( pChild ); +Append( "} "); } if( ( pChild = pSubSup->GetSubSup( CSUP ) ) ) { Separate( ); -Append( "csup " ); +Append( "csup { " ); LineToText( pChild ); +Append( "} "); } if( ( pChild = pSubSup->GetSubSup( CSUB ) ) ) { Separate( ); -Append( "csub " ); +Append( "csub { " ); LineToText( pChild ); +Append( "} "); } } LineToText( pNode->GetSubNode( 1 ) ); @@ -2490,7 +2496,6 @@ void SmNodeToTextVisitor::Visit( SmTextNode* pNode ) void SmNodeToTextVisitor::Visit( SmSpecialNode* pNode ) { -Append( "%" ); Append( pNode->GetToken( ).aText ); } @@ -2528,13 +2533,18 @@ void SmNodeToTextVisitor::Visit( SmLineNode* pNode ) void SmNodeToTextVisitor::Visit( SmExpressionNode* pNode ) { -Append( "{ " ); +USHORT nSize = pNode->GetNumSubNodes(); +if (nSize > 1) { +Append( "{ " ); +} SmNodeIterator it( pNode ); while( it.Next( ) ) { it->Accept( this ); Separate( ); } -Append( "}" ); +if (nSize > 1) { +Append( "} " ); +} } void SmNodeToTextVisitor::Visit( SmPolyLineNode* ) -- 1.7.3.2 >From 413ec5e6f3f63253a2f2eaff814f1ee82ac6b408 Mon Sep 17 00:00:00 2001 From: Luke Dixon <6b8b4...@gmail.com> Date: Tue, 23 Nov 2010 10:41:04 + Subject: [PATCH] Clear 2 things from the visual formula editor todo list. --- starmath/visual-editor-todo | 16 +++- 1 files changed, 7 insertions(+), 9 deletions(-) diff --git a/starmath/visual-editor-todo b/starmath/visual-editor-todo index 9f19e88..b19c1e7 100644 --- a/starmath/visual-editor-todo +++ b/starmath/visual-editor-todo @@ -12,13 +12,12 @@ on IRC (jopsen) or e-mail me at jop...@gmail.com. Easy -1. Draw a non-blinking line under the visual line that the caret is in, in SmCaretDrawingVisitor. -2. SmGraphicWindow::KeyInput relies on comparison of sal_Char, a better way must be available for CTRL+c -3. Code style (missing spaces, linebreaks and a few renames) -4. More documentation -5. Replace j_assert with DBG_ASSERT (don't do this yet). -6. Remove the CreateTextFromNode methods and replace calls to it with NodeToTextVisitor -7. Extend NodeToTextVisitor to update token offsets so SmNode::GetRow and SmNode::GetColumn will work. +1. SmGraphicWindow::KeyInput relies on comparison of sal_Char, a better way must be available for CTRL+c