Kaydet (Commit) e3dc11d4 authored tarafından Mark Hung's avatar Mark Hung Kaydeden (comit) Andras Timar

Fix tdf#93438 Impress generate abnormal style when copy-pasting

from Writer with Chinese UI. When user configure UI language as
Chinese, style names are also translated. However when Copy-pasting
from Writer to Impress ( select RTF fromat with paste-special),
Chinese (unicode) style names are borken into multiparts, where
some of them are empty string. Neither deleting the abnormal
style nor saving the file can be achieved. The only remedy is to
remove style with emtpy name with macro. With this patch:
1) Catch NoSuchElementException and ignores it, so
   user still has chance saving file.
2) Make sure style has valid number before inserting it.
3) Prevent text breaking into multiple tokens by handling  ucN in
 ScanText().

Change-Id: I417f70b81c23ac63c175cc13c548068873d13a38
Reviewed-on: https://gerrit.libreoffice.org/18148Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNorbert Thiebaud <nthiebaud@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/19685
(cherry picked from commit 52f3eb47)
üst f81ea780
...@@ -300,6 +300,7 @@ void SvxRTFParser::ReadStyleTable() ...@@ -300,6 +300,7 @@ void SvxRTFParser::ReadStyleTable()
{ {
int nToken, bSaveChkStyleAttr = bChkStyleAttr ? 1 : 0; int nToken, bSaveChkStyleAttr = bChkStyleAttr ? 1 : 0;
sal_uInt16 nStyleNo = 0; sal_uInt16 nStyleNo = 0;
bool bHasStyleNo = false;
int _nOpenBrakets = 1; // the first was already detected earlier!! int _nOpenBrakets = 1; // the first was already detected earlier!!
SvxRTFStyleType* pStyle = new SvxRTFStyleType( *pAttrPool, &aWhichMap[0] ); SvxRTFStyleType* pStyle = new SvxRTFStyleType( *pAttrPool, &aWhichMap[0] );
pStyle->aAttrSet.Put( GetRTFDefaults() ); pStyle->aAttrSet.Put( GetRTFDefaults() );
...@@ -340,12 +341,16 @@ void SvxRTFParser::ReadStyleTable() ...@@ -340,12 +341,16 @@ void SvxRTFParser::ReadStyleTable()
case RTF_SNEXT: pStyle->nNext = sal_uInt16(nTokenValue); break; case RTF_SNEXT: pStyle->nNext = sal_uInt16(nTokenValue); break;
case RTF_OUTLINELEVEL: case RTF_OUTLINELEVEL:
case RTF_SOUTLVL: pStyle->nOutlineNo = sal_uInt8(nTokenValue); break; case RTF_SOUTLVL: pStyle->nOutlineNo = sal_uInt8(nTokenValue); break;
case RTF_S: nStyleNo = (short)nTokenValue; break; case RTF_S: nStyleNo = (short)nTokenValue;
bHasStyleNo = true;
break;
case RTF_CS: nStyleNo = (short)nTokenValue; case RTF_CS: nStyleNo = (short)nTokenValue;
bHasStyleNo = true;
pStyle->bIsCharFmt = true; pStyle->bIsCharFmt = true;
break; break;
case RTF_TEXTTOKEN: case RTF_TEXTTOKEN:
if (bHasStyleNo)
{ {
pStyle->sName = DelCharAtEnd( aToken, ';' ); pStyle->sName = DelCharAtEnd( aToken, ';' );
...@@ -358,6 +363,7 @@ void SvxRTFParser::ReadStyleTable() ...@@ -358,6 +363,7 @@ void SvxRTFParser::ReadStyleTable()
pStyle = new SvxRTFStyleType( *pAttrPool, &aWhichMap[0] ); pStyle = new SvxRTFStyleType( *pAttrPool, &aWhichMap[0] );
pStyle->aAttrSet.Put( GetRTFDefaults() ); pStyle->aAttrSet.Put( GetRTFDefaults() );
nStyleNo = 0; nStyleNo = 0;
bHasStyleNo = false;
} }
break; break;
default: default:
......
...@@ -431,6 +431,24 @@ void SvRTFParser::ScanText( const sal_Unicode cBreak ) ...@@ -431,6 +431,24 @@ void SvRTFParser::ScanText( const sal_Unicode cBreak )
aToken = sSave; aToken = sSave;
bRTF_InTextRead = false; bRTF_InTextRead = false;
} }
else if ( 'c' == nNextCh )
{
// Prevent text breaking into multiple tokens.
rInput.SeekRel( 2 );
nNextCh = GetNextChar();
if (RTF_ISDIGIT( nNextCh ))
{
sal_uInt8 nNewOverread = 0 ;
do {
nNewOverread *= 10;
nNewOverread += nNextCh - '0';
nNextCh = GetNextChar();
} while ( RTF_ISDIGIT( nNextCh ) );
nUCharOverread = nNewOverread;
aParserStates.top().nUCharOverread = nNewOverread;
}
bNextCh = 0x20 == nNextCh;
}
else else
{ {
nNextCh = '\\'; nNextCh = '\\';
...@@ -448,8 +466,7 @@ void SvRTFParser::ScanText( const sal_Unicode cBreak ) ...@@ -448,8 +466,7 @@ void SvRTFParser::ScanText( const sal_Unicode cBreak )
} }
break; break;
case sal_Unicode(EOF): case sal_Unicode(EOF): eState = SVPAR_ERROR;
eState = SVPAR_ERROR;
// continue // continue
case '{': case '{':
case '}': case '}':
......
...@@ -419,6 +419,10 @@ void XMLStyleExport::exportStyleFamily( ...@@ -419,6 +419,10 @@ void XMLStyleExport::exportStyleFamily(
// not export them here and remain silent. // not export them here and remain silent.
continue; continue;
} }
catch(css::container::NoSuchElementException&)
{
continue;
}
assert(xStyle.is()); assert(xStyle.is());
if (!bUsed || xStyle->isInUse()) if (!bUsed || xStyle->isInUse())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment