Hello Jonas,
By the way, is the SmNodeToTextVisitor as good as it gets now?
Or is it possible to do more improvements ? and if so, should we leave
as an easy hack we or someone can pickup later? (if not lets remove it
from the wiki).
I don't know how good it is with regards to minimizing the use of
brackets. E.g. if it's realistic to do it any better...
I'm very sorry for stretching this out so long. I've played a little
more with this and I'm not sure I'm really getting anywhere. I realized
it would be possible to just have brackets in the SmExpressionNode
Visitor. It seems to work okay to me, but maybe there will be other
problems caused by this as I haven't been able to work out why some of
the extra brackets were there. I don't know what you would think about
this?
Anyway, some other stuff, I noticed something else while looking around
and noticed what seemed to me to be a better place to deal with the
percent sign. Again, I'm not sure if I've found the right place to deal
with this, but it seemed better to deal with it like this rather than in
SmNodeToTextVisitor.
I guess that as I came across this while looking at SmNodeToTextVisitor
I thought it could be solved there.
Oh, another thing I noticed was that there seems to be a crash when
moving to the right of an SmPlaceNode and deleting it. It would be very
easy to patch the symptoms of this in SmCursor::AnnotateSelection, but I
guess that it would be better to work out what is going wrong. I haven't
worked it out yet, but I thought it would be best to mention it.
Sorry, for so much in one email.
Regards,
Luke
From 902c47b34b3cfa78628f5aafb92a0d2c1ceb9c9a Mon Sep 17 00:00:00 2001
From: Luke Dixon <6b8b4567@gmail.com>
Date: Sun, 5 Dec 2010 17:09:57 +0000
Subject: [PATCH] Remove as many brackets as possible.
---
starmath/source/visitors.cxx | 32 ++++++++++----------------------
1 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx
index 3b9bdef..2e7e4e3 100644
--- a/starmath/source/visitors.cxx
+++ b/starmath/source/visitors.cxx
@@ -2242,39 +2242,33 @@ 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 ) );
@@ -2380,18 +2374,15 @@ void SmNodeToTextVisitor::Visit( SmFontNode* pNode )
void SmNodeToTextVisitor::Visit( SmUnHorNode* pNode )
{
- Append( "{" );
SmNodeIterator it( pNode, pNode->GetSubNode( 1 )->GetToken( ).eType == TFACT );
while( it.Next( ) ) {
Separate( );
it->Accept( this );
}
- Append( " }" );
}
void SmNodeToTextVisitor::Visit( SmBinHorNode* pNode )
{
- Append( "{" );
SmNode *pLeft = pNode->GetSubNode( 0 ),
*pOper = pNode->GetSubNode( 1 ),
*pRight = pNode->GetSubNode( 2 );
@@ -2402,7 +2393,6 @@ void SmNodeToTextVisitor::Visit( SmBinHorNode* pNode )
Separate( );
pRight->Accept( this );
Separate( );
- Append( "}" );
}
void SmNodeToTextVisitor::Visit( SmBinVerNode* pNode )
@@ -2466,11 +2456,9 @@ 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( "#" );
}
@@ -2478,7 +2466,7 @@ void SmNodeToTextVisitor::Visit( SmMatrixNode* pNode )
if( i != pNode->GetNumRows( ) - 1 )
Append( "##" );
}
- Append( "}" );
+ Append( "} " );
}
void SmNodeToTextVisitor::Visit( SmPlaceNode* )
@@ -2535,8 +2523,8 @@ void SmNodeToTextVisitor::Visit( SmLineNode* pNode )
void SmNodeToTextVisitor::Visit( SmExpressionNode* pNode )
{
- USHORT nSize = pNode->GetNumSubNodes();
- if (nSize > 1) {
+ bool bracketsNeeded = pNode->GetNumSubNodes() != 1 || pNode->GetSubNode(0)->GetType() !=
NEXPRESSION;
+ if (bracketsNeeded) {
Append( "{ " );
}
SmNodeIterator it( pNode );
@@ -2544,7 +2532,7 @@ void SmNodeToTextVisitor::Visit( SmExpressionNode* pNode )
it->Accept( this );
Separate( );
}
- if (nSize > 1) {
+ if (bracketsNeeded) {
Append( "} " );
}
}
--
1.7.3.2
From 73f6bbfd13d6989694f0fb845ce69a400b2d1489 Mon Sep 17 00:00:00 2001
From: Luke Dixon <6b8b4567@gmail.com>
Date: Sun, 5 Dec 2010 17:58:45 +0000
Subject: [PATCH 1/2] Add the percent sign as a symbol that is inserted when % is pressed
---
starmath/inc/cursor.hxx | 3 ++-
starmath/inc/types.hxx | 4 +++-
starmath/source/cursor.cxx | 9 +++++++++
starmath/source/view.cxx | 2 ++
4 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/starmath/inc/cursor.hxx b/starmath/inc/cursor.hxx
index 139d5c4..5c61d12 100644
--- a/starmath/inc/cursor.hxx
+++ b/starmath/inc/cursor.hxx
@@ -52,7 +52,8 @@ enum SmFormulaElement{
CDotElement,
EqualElement,
LessThanElement,
- GreaterThanElement
+ GreaterThanElement,
+ PercentElement
};
/** Bracket types that can be inserted */
diff --git a/starmath/inc/types.hxx b/starmath/inc/types.hxx
index 833c88c..d72df24 100644
--- a/starmath/inc/types.hxx
+++ b/starmath/inc/types.hxx
@@ -198,7 +198,9 @@ enum MathSymbol
MS_SETZ = (sal_Unicode) 0x2124,
MS_SETQ = (sal_Unicode) 0x211A,
MS_SETR = (sal_Unicode) 0x211D,
- MS_SETC = (sal_Unicode) 0x2102
+ MS_SETC = (sal_Unicode) 0x2102,
+
+ MS_PERCENT = (sal_Unicode) 0x0025
};
#endif
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx
index 94b9e38..249d6a4 100644
--- a/starmath/source/cursor.cxx
+++ b/starmath/source/cursor.cxx
@@ -1058,6 +1058,15 @@ void SmCursor::InsertElement(SmFormulaElement element){
token.aText.AssignAscii(">");
pNewNode = new SmMathSymbolNode(token);
}break;
+ case PercentElement:
+ {
+ SmToken token;
+ token.eType = TTEXT;
+ token.cMathChar = MS_PERCENT;
+ token.nGroup = 0;
+ token.aText.AssignAscii("\"%\"");
+ pNewNode = new SmMathSymbolNode(token);
+ }break;
default:
j_assert(false, "Element unknown!");
}
diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx
index 97a9035..810ddd7 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -513,6 +513,8 @@ void SmGraphicWindow::KeyInput(const KeyEvent& rKEvt)
rCursor.InsertBrackets(CurlyBrackets);
}else if(code == '!') {
rCursor.InsertElement(FactorialElement);
+ }else if(code == '%') {
+ rCursor.InsertElement(PercentElement);
}else{
if(code != 0){
rCursor.InsertText(code);
--
1.7.3.2
Context
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.