#90485# import of formulas stored in 5.0 format with multi-byte encoding fixed

This commit is contained in:
Thomas Lange 2001-08-08 10:22:18 +00:00
parent 20b4a36740
commit 3e51156023
7 changed files with 169 additions and 49 deletions

View file

@ -2,9 +2,9 @@
*
* $RCSfile: utility.hxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: tl $ $Date: 2000-11-02 15:07:16 $
* last change: $Author: tl $ $Date: 2001-08-08 11:22:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -86,8 +86,12 @@ class String;
#define C2S(cChar) String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(cChar))
const ByteString ExportString(const String& rString);
/////////////////////////////////////////////////////////////////
const ByteString ExportString( const String& rString );
const String ImportString( const ByteString& rByteString );
/////////////////////////////////////////////////////////////////
inline long SmPtsTo100th_mm(long nNumPts)
// returns the length (in 100th of mm) that corresponds to the length

View file

@ -2,9 +2,9 @@
*
* $RCSfile: cfgitem.cxx,v $
*
* $Revision: 1.8 $
* $Revision: 1.9 $
*
* last change: $Author: tl $ $Date: 2001-07-17 08:28:20 $
* last change: $Author: tl $ $Date: 2001-08-08 11:22:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -776,7 +776,7 @@ SmFontFormat SmMathConfig::ReadFontFormat( SmMathConfigItem &rCfg,
bOK = FALSE;
++pValue;
if (pValue->hasValue() && (*pValue >>= nTmp16))
aRes.nCharSet = nTmp16;
aRes.nCharSet = nTmp16; // 6.0 file-format GetSOLoadTextEncoding not needed
else
bOK = FALSE;
++pValue;
@ -848,7 +848,7 @@ void SmMathConfig::SaveFontFormatList()
// CharSet
pVal->Name = aNodeNameDelim;
pVal->Name += *pName++;
pVal->Value <<= (INT16) aFntFmt.nCharSet;
pVal->Value <<= (INT16) aFntFmt.nCharSet; // 6.0 file-format GetSOStoreTextEncoding not needed
pVal++;
// Family
pVal->Name = aNodeNameDelim;

View file

@ -2,9 +2,9 @@
*
* $RCSfile: document.cxx,v $
*
* $Revision: 1.39 $
* $Revision: 1.40 $
*
* last change: $Author: tl $ $Date: 2001-08-02 15:36:37 $
* last change: $Author: tl $ $Date: 2001-08-08 11:22:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -1083,6 +1083,7 @@ BOOL SmDocShell::ImportSM20File(SvStream *pStream, BOOL bInsert)
long lTime;
ULONG lDate;
String aBuffer;
ByteString aByteStr;
SmSymSet *pSymbolSet;
ULONG FilePos = pStream->Tell();
@ -1093,13 +1094,14 @@ BOOL SmDocShell::ImportSM20File(SvStream *pStream, BOOL bInsert)
DBG_ASSERT((lVersion == FRMVERSION), "Illegal file version");
*pStream >> cTag;
rtl_TextEncoding eEnc = gsl_getSystemTextEncoding();
rtl_TextEncoding eEnc = RTL_TEXTENCODING_MS_1252;
while (cTag && !pStream->IsEof())
{
switch (cTag)
{
case 'T':
pStream->ReadByteString(aBuffer, eEnc);
pStream->ReadByteString( aByteStr );
aBuffer = ImportString( aByteStr );
if (! bInsert)
{
aText = aBuffer;
@ -1589,6 +1591,7 @@ BOOL SmDocShell::Try3x (SvStorage *pStor,
long lTime;
ULONG lDate;
String aBuffer;
ByteString aByteStr;
*pSvStream >> lIdent >> lVersion;
@ -1598,13 +1601,14 @@ BOOL SmDocShell::Try3x (SvStorage *pStor,
(lVersion == SM50VERSION), "Illegal file version");
*pSvStream >> cTag;
rtl_TextEncoding eEnc = gsl_getSystemTextEncoding();
rtl_TextEncoding eEnc = RTL_TEXTENCODING_MS_1252;
while (cTag && !pSvStream->IsEof())
{
switch (cTag)
{
case 'T':
pSvStream->ReadByteString(aText, eEnc);
pSvStream->ReadByteString( aByteStr );
aText = ImportString( aByteStr );
Parse();
break;
@ -1634,7 +1638,7 @@ BOOL SmDocShell::Try3x (SvStorage *pStor,
{
String aTmp;
USHORT n;
pSvStream->ReadByteString(aTmp, gsl_getSystemTextEncoding());
pSvStream->ReadByteString(aTmp, eEnc);
*pSvStream >> n;
break;
}
@ -1689,6 +1693,7 @@ BOOL SmDocShell::Try2x (SvStorage *pStor,
ULONG lDate;
UINT32 lDataSize;
String aBuffer;
ByteString aByteStr;
SmSymSet *pSymbolSet;
*pSvStream >> lDataSize >> lIdent >> lVersion;
@ -1698,14 +1703,14 @@ BOOL SmDocShell::Try2x (SvStorage *pStor,
DBG_ASSERT((lVersion == FRMVERSION), "Illegal file version");
*pSvStream >> cTag;
rtl_TextEncoding eEnc = gsl_getSystemTextEncoding();
rtl_TextEncoding eEnc = RTL_TEXTENCODING_MS_1252;
while (cTag && !pSvStream->IsEof())
{
switch (cTag)
{
case 'T':
pSvStream->ReadByteString(aBuffer, eEnc);
aText = aBuffer;
pSvStream->ReadByteString( aByteStr );
aText = ImportString( aByteStr );
Parse();
break;

View file

@ -2,9 +2,9 @@
*
* $RCSfile: format.cxx,v $
*
* $Revision: 1.3 $
* $Revision: 1.4 $
*
* last change: $Author: tl $ $Date: 2001-05-02 16:58:48 $
* last change: $Author: tl $ $Date: 2001-08-08 11:22:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -117,6 +117,8 @@ SmFormat::SmFormat()
vFont[FNT_FIXED] = SmFace(C2S(FNTNAME_COUR), aBaseSize);
vFont[FNT_MATH] = SmFace(C2S(FNTNAME_MATH), aBaseSize);
vFont[FNT_MATH].SetCharSet( RTL_TEXTENCODING_UNICODE );
vFont[FNT_VARIABLE].SetItalic(ITALIC_NORMAL);
vFont[FNT_FUNCTION].SetItalic(ITALIC_NONE);
vFont[FNT_TEXT].SetItalic(ITALIC_NONE);

View file

@ -2,9 +2,9 @@
*
* $RCSfile: node.cxx,v $
*
* $Revision: 1.9 $
* $Revision: 1.10 $
*
* last change: $Author: cmc $ $Date: 2001-07-23 09:07:42 $
* last change: $Author: tl $ $Date: 2001-08-08 11:22:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -385,7 +385,9 @@ void SmNode::Prepare(const SmFormat &rFormat, const SmDocShell &rDocShell)
}
GetFont() = rFormat.GetFont(FNT_MATH);
GetFont().SetCharSet(RTL_TEXTENCODING_SYMBOL);
//GetFont().SetCharSet(RTL_TEXTENCODING_SYMBOL);
DBG_ASSERT( GetFont().GetCharSet() == RTL_TEXTENCODING_UNICODE,
"unexpected CharSet" );
GetFont().SetWeight(WEIGHT_NORMAL);
GetFont().SetItalic(ITALIC_NONE);

View file

@ -2,9 +2,9 @@
*
* $RCSfile: symbol.cxx,v $
*
* $Revision: 1.14 $
* $Revision: 1.15 $
*
* last change: $Author: tl $ $Date: 2001-08-02 15:37:39 $
* last change: $Author: tl $ $Date: 2001-08-08 11:22:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -295,7 +295,10 @@ SvStream& operator << (SvStream& rStream, const SmSym& rSymbol)
SvStream& operator >> (SvStream& rStream, SmSym& rSymbol)
{
rStream.ReadByteString( rSymbol.Name, gsl_getSystemTextEncoding() );
ByteString aByteStr;
rStream.ReadByteString( aByteStr );
rSymbol.Name = ImportString( aByteStr );
if (SF_Ident == SF_SM20IDENT)
ReadSM20Font(rStream, rSymbol.Face);
else
@ -422,8 +425,10 @@ SvStream& operator >> (SvStream& rStream, SmSymSet& rSymbolSet)
{
USHORT n;
SmSym *pSymbol;
ByteString aByteStr;
rStream.ReadByteString(rSymbolSet.Name, gsl_getSystemTextEncoding());
rStream.ReadByteString( aByteStr );
rSymbolSet.Name = ImportString( aByteStr );
rStream >> n;
for (int i = 0; i < n; i++)

View file

@ -2,9 +2,9 @@
*
* $RCSfile: utility.cxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: tl $ $Date: 2001-04-09 09:47:44 $
* last change: $Author: tl $ $Date: 2001-08-08 11:22:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -70,6 +70,15 @@
#ifndef NOOLDSV //autogen
#include <vcl/system.hxx>
#endif
#ifndef _STRING_HXX
#include <tools/string.hxx>
#endif
#ifndef _TOOLS_TENCCVT_HXX
#include <tools/tenccvt.hxx>
#endif
#ifndef _OSL_THREAD_H_
#include <osl/thread.h>
#endif
#include "starmath.hrc"
@ -95,7 +104,7 @@ SvStream& operator << (SvStream& rStream, const SmFace& rFont)
{
rStream.WriteByteString(ExportString(rFont.GetName()));
rStream << (ULONG)rFont.GetFamily();
rStream << (ULONG)rFont.GetCharSet();
rStream << (ULONG)GetSOStoreTextEncoding( rFont.GetCharSet() );
rStream << (ULONG)rFont.GetWeight();
rStream << (ULONG)rFont.GetItalic();
@ -105,15 +114,14 @@ SvStream& operator << (SvStream& rStream, const SmFace& rFont)
SvStream& operator >> (SvStream& rStream, SmFace& rFont)
{
ULONG nData;
String aString;
ByteString aByteStr;
rtl_TextEncoding eEnc = gsl_getSystemTextEncoding();
rStream.ReadByteString(aString);
rFont.SetName(aString);
rStream.ReadByteString( aByteStr );
rFont.SetName( ImportString( aByteStr ) );
rStream >> nData;
rFont.SetFamily((FontFamily)nData);
rStream >> nData;
rFont.SetCharSet((CharSet)nData);
rFont.SetCharSet( GetSOLoadTextEncoding( (rtl_TextEncoding) nData ) );
rStream >> nData;
rFont.SetWeight((FontWeight)nData);
rStream >> nData;
@ -126,15 +134,14 @@ void ReadSM20Font(SvStream& rStream, Font& rFont)
{
BOOL bData;
ULONG nData;
String aString;
ByteString aByteStr;
rtl_TextEncoding eEnc = gsl_getSystemTextEncoding();
rStream.ReadByteString(aString);
rFont.SetName(aString);
rStream.ReadByteString( aByteStr );
rFont.SetName( ImportString( aByteStr ) );
rStream >> nData;
rFont.SetFamily((FontFamily)nData);
rStream >> nData;
rFont.SetCharSet((CharSet)nData);
rFont.SetCharSet( GetSOLoadTextEncoding( (rtl_TextEncoding) nData ) );
rStream >> nData;
rFont.SetWeight((FontWeight)nData);
rStream >> bData;
@ -234,40 +241,135 @@ void SmRectCache::Reset()
////////////////////////////////////////////////////////////
#define TE_UCS2 "UCS2"
#define PRE_TE "<?"
#define POST_TE ")>"
ByteString ConvertUnknownCharacter(sal_Unicode ch)
{
ByteString aString("<?");
aString += "UCS2(";
ByteString aString( RTL_CONSTASCII_STRINGPARAM( PRE_TE TE_UCS2 ) );
aString += ByteString::CreateFromInt32(ch);
aString += ")>";
aString += POST_TE;
return aString;
}
const ByteString ExportString(const String& rString)
const ByteString ExportString( const String& rString )
{
ByteString aString;
rtl_TextEncoding eEnc = gsl_getSystemTextEncoding();
rtl_TextEncoding nEnc = RTL_TEXTENCODING_MS_1252;
for (xub_StrLen i = 0; i < rString.Len(); i++)
{
sal_Unicode ch = rString.GetChar(i);
if ((ch != '\r') && (ch != '\n') && (ch != '\t'))
{
sal_Char cChar = ByteString::ConvertFromUnicode( ch, eEnc );
sal_Char cChar = ByteString::ConvertFromUnicode( ch, nEnc, FALSE );
if (cChar == 0)
aString += ConvertUnknownCharacter(ch);
else
aString += cChar;
}
else
aString += ch;
aString += (sal_Char) ch;
}
aString.ConvertLineEnd(LINEEND_CRLF);
return aString;
}
return (aString);
#define TEXTENCODINGTAB_LEN 12
static const struct
{
const char *pText;
rtl_TextEncoding nEnc;
} aTextEncodingTab[ TEXTENCODINGTAB_LEN ] =
{
{ TE_UCS2, RTL_TEXTENCODING_UCS2 }, // is RTL_TEXTENCODING_UNICODE in 6.0
{ "DONTKNOW", RTL_TEXTENCODING_DONTKNOW },
{ "ANSI", RTL_TEXTENCODING_MS_1252 },
{ "MAC", RTL_TEXTENCODING_APPLE_ROMAN },
{ "PC437", RTL_TEXTENCODING_IBM_437 },
{ "PC850", RTL_TEXTENCODING_ASCII_US },
{ "PC860", RTL_TEXTENCODING_IBM_860 },
{ "PC861", RTL_TEXTENCODING_IBM_861 },
{ "PC863", RTL_TEXTENCODING_IBM_863 },
{ "PC865", RTL_TEXTENCODING_IBM_865 },
{ "SYSTEM", RTL_TEXTENCODING_DONTKNOW },
{ "SYMBOL", RTL_TEXTENCODING_SYMBOL }
};
int GetTextEncodingTabIndex( const String &rTxt, xub_StrLen nPos )
{
int nRes = -1;
for (int i = 0; i < TEXTENCODINGTAB_LEN && nRes == -1; ++i)
{
if (nPos == rTxt.SearchAscii( aTextEncodingTab[i].pText , nPos ))
nRes = i;
}
return nRes;
}
const String ImportString( const ByteString& rByteString )
{
String aString( rByteString, RTL_TEXTENCODING_MS_1252 );
const xub_StrLen nPreLen = sizeof( PRE_TE ) - 1;
const xub_StrLen nPostLen = sizeof( POST_TE ) - 1;
xub_StrLen nPreStart = 0;
while( STRING_NOTFOUND != ( nPreStart =
aString.SearchAscii( PRE_TE, nPreStart )) )
{
//
// convert 'unknown character' to unicode character
//
xub_StrLen nTeStart = nPreStart + nPreLen;
xub_StrLen nTeLen = 0;
int nIdx = GetTextEncodingTabIndex( aString, nTeStart );
DBG_ASSERT( nIdx >= 0, "text-encoding is missing" );
rtl_TextEncoding nEnc = RTL_TEXTENCODING_DONTKNOW;
if (nIdx >= 0)
{
nEnc = aTextEncodingTab[ nIdx ].nEnc;
nTeLen = strlen( aTextEncodingTab[ nIdx ].pText );
}
if (RTL_TEXTENCODING_DONTKNOW == nEnc)
nEnc = osl_getThreadTextEncoding();
//
xub_StrLen nNumStart = nTeStart + nTeLen + 1, // +1 because of "("
nReplLen;
xub_StrLen nPostStart = aString.SearchAscii( POST_TE, nNumStart );
String sRepl;
if( STRING_NOTFOUND != nPostStart )
{
INT32 nCharVal = aString.Copy( nNumStart, nPostStart - nNumStart ).ToInt32();
DBG_ASSERT( nCharVal != 0, "String -> Int32 failed ?" );
if (RTL_TEXTENCODING_UNICODE == nEnc)
sRepl = (sal_Unicode) nCharVal;
else
{
DBG_ASSERT( 0 <= nCharVal && nCharVal <= 256,
"character value out of range" );
sRepl = ByteString::ConvertToUnicode( nCharVal, nEnc );
}
DBG_ASSERT( sRepl.Len(), "conversion failed" );
nReplLen = nPostStart + nPostLen - nPreStart;
}
else
{
DBG_ERROR( "import error: 'unknown character' delimiter missing" );
sRepl.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "<?>" ) );
nReplLen = nPreLen;
}
aString.Replace( nPreStart, nReplLen, sRepl );
nPreStart += sRepl.Len();
}
aString.ConvertLineEnd();
return aString;
}
////////////////////////////////////////////////////////////