summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--starmath/inc/document.hxx9
-rw-r--r--starmath/inc/parse.hxx27
-rw-r--r--starmath/source/document.cxx86
-rw-r--r--starmath/source/parse.cxx78
4 files changed, 104 insertions, 96 deletions
diff --git a/starmath/inc/document.hxx b/starmath/inc/document.hxx
index d3a6dbf5c175..d88c69510e08 100644
--- a/starmath/inc/document.hxx
+++ b/starmath/inc/document.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: document.hxx,v $
*
- * $Revision: 1.12 $
+ * $Revision: 1.13 $
*
- * last change: $Author: tl $ $Date: 2001-08-02 15:31:38 $
+ * last change: $Author: tl $ $Date: 2001-12-14 09:07:32 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -212,9 +212,8 @@ class SmDocShell : public SfxObjectShell, public SfxInPlaceObject,
Printer *GetPrt();
- void Convert40To50Txt( String &rText );
- void Convert50To60Txt( String &rText );
- void Convert60To50Txt( String &rText );
+ // used to convert the formula text between different office versions
+ void ConvertText( String &rText, SmConvert eConv );
BOOL IsFormulaArranged() const { return bIsFormulaArranged; }
void SetFormulaArranged(BOOL bVal) { bIsFormulaArranged = bVal; }
diff --git a/starmath/inc/parse.hxx b/starmath/inc/parse.hxx
index 9ae0d5b37075..72a49795ac65 100644
--- a/starmath/inc/parse.hxx
+++ b/starmath/inc/parse.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: parse.hxx,v $
*
- * $Revision: 1.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: tl $ $Date: 2001-08-28 07:46:06 $
+ * last change: $Author: tl $ $Date: 2001-12-14 09:07:32 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -199,6 +199,17 @@ DECLARE_LIST(SmErrDescList, SmErrorDesc *);
/**************************************************************************/
+// defines possible conversions of the formula text from the format of
+// one release to the one of another.
+enum SmConvert
+{
+ CONVERT_NONE,
+ CONVERT_40_TO_50,
+ CONVERT_50_TO_60,
+ CONVERT_60_TO_50
+};
+
+
class SmParser
{
String BufferString;
@@ -206,12 +217,13 @@ class SmParser
SmNodeStack NodeStack;
SmErrDescList ErrDescList;
int CurError;
+ LanguageType nLang;
xub_StrLen BufferIndex,
nTokenIndex;
USHORT Row,
ColOff;
- BOOL bConvert40To50,
- bImportSymNames,
+ SmConvert eConversion;
+ BOOL bImportSymNames,
bExportSymNames;
// declare copy-constructor and assignment-operator private
@@ -259,6 +271,9 @@ protected:
void GlyphSpecial();
// end of grammar
+ LanguageType GetLanguage() const { return nLang; }
+ void SetLanguage( LanguageType nNewLang ) { nLang = nNewLang; }
+
void Error(SmParseError Error);
public:
@@ -269,8 +284,8 @@ public:
const String & GetText() const { return BufferString; };
- BOOL IsConvert40To50() const { return bConvert40To50; }
- void SetConvert40To50(BOOL bConvert) { bConvert40To50 = bConvert; }
+ SmConvert GetConversion() const { return eConversion; }
+ void SetConversion(SmConvert eConv) { eConversion = eConv; }
BOOL IsImportSymbolNames() const { return bImportSymNames; }
void SetImportSymbolNames(BOOL bVal) { bImportSymNames = bVal; }
diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx
index 5ed8e3db7375..a54f3df8aa00 100644
--- a/starmath/source/document.cxx
+++ b/starmath/source/document.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: document.cxx,v $
*
- * $Revision: 1.45 $
+ * $Revision: 1.46 $
*
- * last change: $Author: tl $ $Date: 2001-11-21 11:59:48 $
+ * last change: $Author: tl $ $Date: 2001-12-14 09:07:32 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -726,23 +726,25 @@ BOOL SmDocShell::SetData( const String& rData )
return TRUE;
}
-void SmDocShell::Convert40To50Txt( String &rText )
- // adapts the text 'aText' to be parsed from 4.0 version, to changes made
- // in 5.0 version. (Namely that functions do not need arguments any more)
- // Example: "2 over sin x" acts very different in 4.0 and 5.0
+void SmDocShell::ConvertText( String &rText, SmConvert eConv )
+ // adapts the text 'rText' that suits one office version to be
+ // usable in another office version.
+ // Example: "2 over sin x" acts very different in 4.0 and 5.0,
+ // and from 5.2 to 6.0 many symbol names were renamed.
{
if (pTree)
delete pTree;
- // parse in old 4.0 style and make changes for 5.0 style
- BOOL bVal = aInterpreter.IsConvert40To50();
- aInterpreter.SetConvert40To50(TRUE);
- pTree = aInterpreter.Parse(rText);
- aInterpreter.SetConvert40To50(bVal);
+ SmConvert eTmpConv = aInterpreter.GetConversion();
- // get new to 5.0 version converted text
+ // parse in old style and make changes for new style
+ aInterpreter.SetConversion(eConv);
+ pTree = aInterpreter.Parse(rText);
+ // get to new version converted text
rText = aInterpreter.GetText();
+ aInterpreter.SetConversion(eTmpConv);
+
// clean up tree parsed in old style
if (pTree)
{ delete pTree;
@@ -751,56 +753,6 @@ void SmDocShell::Convert40To50Txt( String &rText )
}
-void SmDocShell::Convert50To60Txt( String &rText )
-{
- // change 50 symbol-names to their 60 equivalent
- LanguageType nLang = Application::GetSettings().GetUILanguage();
- SmLocalizedSymbolData &rData = SM_MOD1()->GetLocSymbolData();
- const ResStringArray *p50Names = rData.Get50NamesArray( nLang );
- const ResStringArray *p60Names = rData.Get60NamesArray( nLang );
- if (p50Names && p60Names)
- {
- DBG_ASSERT( p50Names->Count() == p60Names->Count(),
- "array length mismatch" );
- USHORT nCount = p50Names->Count();
- String aPreSym( RTL_CONSTASCII_STRINGPARAM("%") );
- for (USHORT i = 0; i < nCount; ++i)
- {
- String a50Tmp( aPreSym );
- String a60Tmp( aPreSym );
- a50Tmp += p50Names->GetString(i);
- a60Tmp += p60Names->GetString(i);
- rText.SearchAndReplaceAll( a50Tmp, a60Tmp );
- }
- }
-}
-
-
-void SmDocShell::Convert60To50Txt( String &rText )
-{
- // change 60 symbol-names to their 50 equivalent
- LanguageType nLang = Application::GetSettings().GetUILanguage();
- SmLocalizedSymbolData &rData = SM_MOD1()->GetLocSymbolData();
- const ResStringArray *p50Names = rData.Get50NamesArray( nLang );
- const ResStringArray *p60Names = rData.Get60NamesArray( nLang );
- if (p50Names && p60Names)
- {
- DBG_ASSERT( p50Names->Count() == p60Names->Count(),
- "array length mismatch" );
- USHORT nCount = p60Names->Count();
- String aPreSym( RTL_CONSTASCII_STRINGPARAM("%") );
- for (USHORT i = 0; i < nCount; ++i)
- {
- String a50Tmp( aPreSym );
- String a60Tmp( aPreSym );
- a50Tmp += p50Names->GetString(i);
- a60Tmp += p60Names->GetString(i);
- rText.SearchAndReplaceAll( a60Tmp, a50Tmp );
- }
- }
-}
-
-
BOOL SmDocShell::ConvertFrom(SfxMedium &rMedium)
{
BOOL bSuccess = FALSE;
@@ -916,9 +868,9 @@ BOOL SmDocShell::Load(SvStorage *pStor)
{
long nVersion = pStor->GetVersion();
if ( nVersion <= SOFFICE_FILEFORMAT_40 )
- Convert40To50Txt( aText );
+ ConvertText( aText, CONVERT_40_TO_50 );
if ( nVersion <= SOFFICE_FILEFORMAT_50 )
- Convert50To60Txt( aText );
+ ConvertText( aText, CONVERT_50_TO_60 );
if (pTree)
{ delete pTree;
pTree = NULL;
@@ -971,9 +923,9 @@ BOOL SmDocShell::Insert(SvStorage *pStor)
if( bChkOldVersion )
{
if( SOFFICE_FILEFORMAT_40 >= pStor->GetVersion() )
- Convert40To50Txt( aText );
+ ConvertText( aText, CONVERT_40_TO_50 );
if( SOFFICE_FILEFORMAT_50 >= pStor->GetVersion() )
- Convert50To60Txt( aText );
+ ConvertText( aText, CONVERT_50_TO_60 );
}
Parse();
@@ -995,7 +947,7 @@ void SmDocShell::ImplSave( SvStorageStreamRef xStrm )
{
String aTmp( aText );
if (SOFFICE_FILEFORMAT_50 >= xStrm->GetVersion())
- Convert60To50Txt( aTmp );
+ ConvertText( aTmp, CONVERT_60_TO_50 );
ByteString exString( ExportString( aTmp ) );
*xStrm << SM304AIDENT << SM50VERSION
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index d58f8a169c7c..50e0739178ed 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: parse.cxx,v $
*
- * $Revision: 1.16 $
+ * $Revision: 1.17 $
*
- * last change: $Author: tl $ $Date: 2001-11-20 10:08:19 $
+ * last change: $Author: tl $ $Date: 2001-12-14 09:07:32 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -1036,7 +1036,7 @@ void SmParser::Align()
if (TokenInGroup(TGALIGN))
{
- if (IsConvert40To50())
+ if (CONVERT_40_TO_50 == GetConversion())
// encapsulate expression to be aligned in group braces
// (here group-open brace)
{ Insert('{', GetTokenIndex());
@@ -1063,7 +1063,7 @@ void SmParser::Align()
NextToken();
// allow for just one align statement in 5.0
- if (!IsConvert40To50() && TokenInGroup(TGALIGN))
+ if (CONVERT_40_TO_50 != GetConversion() && TokenInGroup(TGALIGN))
{ Error(PE_DOUBLE_ALIGN);
return;
}
@@ -1099,7 +1099,7 @@ void SmParser::Line()
}
while (CurToken.eType != TEND && CurToken.eType != TNEWLINE)
- { if (!IsConvert40To50())
+ { if (CONVERT_40_TO_50 != GetConversion())
Expression();
else
Align();
@@ -1507,7 +1507,7 @@ void SmParser::Term()
NodeStack.Push(pFirstNode);
}
else if (TokenInGroup(TGFUNCTION))
- { if (!IsConvert40To50())
+ { if (CONVERT_40_TO_50 != GetConversion())
{ Function();
}
else // encapsulate old 4.0 style parsing in braces
@@ -2270,24 +2270,62 @@ void SmParser::Matrix()
void SmParser::Special()
{
- //
- // conversion of symbol names for 6.0 (XML) fileformat
- //
BOOL bReplace = FALSE;
String &rName = CurToken.aText;
String aNewName;
- if (IsImportSymbolNames())
+
+ if (CONVERT_NONE == GetConversion())
{
- const SmLocalizedSymbolData &rLSD = SM_MOD1()->GetLocSymbolData();
- aNewName = rLSD.GetUiSymbolName( rName );
- bReplace = TRUE;
+ // conversion of symbol names for 6.0 (XML) file format
+ // (name change on import / export.
+ // UI uses localized names XML file format does not.)
+ if (IsImportSymbolNames())
+ {
+ const SmLocalizedSymbolData &rLSD = SM_MOD1()->GetLocSymbolData();
+ aNewName = rLSD.GetUiSymbolName( rName );
+ bReplace = TRUE;
+ }
+ else if (IsExportSymbolNames())
+ {
+ const SmLocalizedSymbolData &rLSD = SM_MOD1()->GetLocSymbolData();
+ aNewName = rLSD.GetExportSymbolName( rName );
+ bReplace = TRUE;
+ }
}
- else if (IsExportSymbolNames())
+ else // 5.0 <-> 6.0 formula text (symbol name) conversion
{
- const SmLocalizedSymbolData &rLSD = SM_MOD1()->GetLocSymbolData();
- aNewName = rLSD.GetExportSymbolName( rName );
- bReplace = TRUE;
+ LanguageType nLang = GetLanguage();
+ SmLocalizedSymbolData &rData = SM_MOD1()->GetLocSymbolData();
+ const ResStringArray *pFrom = 0;
+ const ResStringArray *pTo = 0;
+ if (CONVERT_50_TO_60 == GetConversion())
+ {
+ pFrom = rData.Get50NamesArray( nLang );
+ pTo = rData.Get60NamesArray( nLang );
+ }
+ else if (CONVERT_60_TO_50 == GetConversion())
+ {
+ pFrom = rData.Get60NamesArray( nLang );
+ pTo = rData.Get50NamesArray( nLang );
+ }
+ if (pFrom && pTo)
+ {
+ DBG_ASSERT( pFrom->Count() == pTo->Count(),
+ "array length mismatch" );
+ USHORT nCount = pFrom->Count();
+ for (USHORT i = 0; i < nCount; ++i)
+ {
+ if (pFrom->GetString(i) == rName)
+ {
+ aNewName = pTo->GetString(i);
+ bReplace = TRUE;
+ }
+ }
+ }
+ else
+ DBG_ERROR( "unexpected conversion or data missing" );
}
+
if (bReplace && aNewName.Len() && rName != aNewName)
{
Replace( GetTokenIndex() + 1, rName.Len(), aNewName );
@@ -2328,7 +2366,9 @@ void SmParser::Error(SmParseError eError)
SmParser::SmParser()
{
- bConvert40To50 = bImportSymNames = bExportSymNames = FALSE;
+ eConversion = CONVERT_NONE;
+ bImportSymNames = bExportSymNames = FALSE;
+ nLang = Application::GetSettings().GetUILanguage();
}
@@ -2348,6 +2388,7 @@ BOOL SmParser::CheckSyntax(const String &rBuffer)
OldErrorList = ErrDescList;
ErrDescList.Clear();
+ SetLanguage( Application::GetSettings().GetUILanguage() );
NextToken();
Table();
@@ -2385,6 +2426,7 @@ SmNode *SmParser::Parse(const String &rBuffer)
NodeStack.Clear();
+ SetLanguage( Application::GetSettings().GetUILanguage() );
NextToken();
Table();