sc/source/ui/docshell/impex.cxx | 22 ++++++++++++++++------ sw/source/core/fields/ddefld.cxx | 10 +++++++--- 2 files changed, 23 insertions(+), 9 deletions(-)
New commits: commit 2df4bd1dda0b233aadd8e09012df7b8530fa631c Author: Mike Kaganski <[email protected]> AuthorDate: Sat Oct 8 22:10:44 2022 +0300 Commit: Xisco Fauli <[email protected]> CommitDate: Tue Oct 11 16:34:54 2022 +0200 tdf#151429: don't convert OUStrings to system encoding ... just to convert back to OUString in the end. Change-Id: I727d5e4c03d1a49f64bd5ca3d64157a9149cd9ef Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141125 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> (cherry picked from commit 94df17f58fe6269452b7252b712a89978c444bec) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141073 Reviewed-by: Xisco Fauli <[email protected]> diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 9c43453f2fc3..3be11884ca72 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -288,14 +288,24 @@ bool ScImportExport::ExportData( const OUString& rMimeType, css::uno::Any & rValue ) { SvMemoryStream aStrm; + SotClipboardFormatId fmtId = SotExchange::GetFormatIdFromMimeType(rMimeType); + if (fmtId == SotClipboardFormatId::STRING) + aStrm.SetStreamCharSet(RTL_TEXTENCODING_UNICODE); // mba: no BaseURL for data exchange - if( ExportStream( aStrm, OUString(), - SotExchange::GetFormatIdFromMimeType( rMimeType ) )) + if (ExportStream(aStrm, OUString(), fmtId)) { - aStrm.WriteUChar( 0 ); - rValue <<= css::uno::Sequence< sal_Int8 >( - static_cast<sal_Int8 const *>(aStrm.GetData()), - aStrm.TellEnd() ); + if (fmtId == SotClipboardFormatId::STRING) + { + assert(aStrm.TellEnd() % sizeof(sal_Unicode) == 0); + rValue <<= OUString(static_cast<const sal_Unicode*>(aStrm.GetData()), + aStrm.TellEnd() / sizeof(sal_Unicode)); + } + else + { + aStrm.WriteUChar(0); + rValue <<= css::uno::Sequence<sal_Int8>(static_cast<sal_Int8 const*>(aStrm.GetData()), + aStrm.TellEnd()); + } return true; } return false; diff --git a/sw/source/core/fields/ddefld.cxx b/sw/source/core/fields/ddefld.cxx index 8b326d02cd62..f73a2b641820 100644 --- a/sw/source/core/fields/ddefld.cxx +++ b/sw/source/core/fields/ddefld.cxx @@ -69,9 +69,13 @@ public: case SotClipboardFormatId::STRING: if( !IsNoDataFlag() ) { - uno::Sequence< sal_Int8 > aSeq; - rValue >>= aSeq; - OUString sStr( reinterpret_cast<char const *>(aSeq.getConstArray()), aSeq.getLength(), osl_getThreadTextEncoding() ); + OUString sStr; + if (!(rValue >>= sStr)) + { + uno::Sequence< sal_Int8 > aSeq; + rValue >>= aSeq; + sStr = OUString(reinterpret_cast<char const*>(aSeq.getConstArray()), aSeq.getLength(), osl_getThreadTextEncoding()); + } // remove not needed CR-LF at the end sal_Int32 n = sStr.getLength();
