From cb66e15faf51b04f6849135d609bbee8425cd29d Mon Sep 17 00:00:00 2001 From: "Elena.Subbotina" Date: Tue, 30 May 2023 15:59:07 +0300 Subject: [PATCH] for bug #62789 --- Common/MS-LCID.h | 1 + RtfFile/Format/DestinationCommand.cpp | 2 +- RtfFile/Format/RtfReader.cpp | 119 +++++++++++++------------- RtfFile/Format/RtfShape.cpp | 6 +- 4 files changed, 66 insertions(+), 62 deletions(-) diff --git a/Common/MS-LCID.h b/Common/MS-LCID.h index 425107672b..08be08a150 100644 --- a/Common/MS-LCID.h +++ b/Common/MS-LCID.h @@ -524,6 +524,7 @@ public: m_mapLCID2DefCodePage.insert(std::make_pair(0x40E, 1250)); m_mapLCID2DefCodePage.insert(std::make_pair(0x40F, 1252)); m_mapLCID2DefCodePage.insert(std::make_pair(0x410, 1252)); + m_mapLCID2DefCodePage.insert(std::make_pair(0x412, 949)); m_mapLCID2DefCodePage.insert(std::make_pair(0x413, 1252)); m_mapLCID2DefCodePage.insert(std::make_pair(0x414, 1252)); m_mapLCID2DefCodePage.insert(std::make_pair(0x415, 1250)); diff --git a/RtfFile/Format/DestinationCommand.cpp b/RtfFile/Format/DestinationCommand.cpp index 65fe23e646..6d14a90bd7 100644 --- a/RtfFile/Format/DestinationCommand.cpp +++ b/RtfFile/Format/DestinationCommand.cpp @@ -3298,7 +3298,7 @@ void RtfFontTableReader::ExecuteTextInternal2( RtfDocument& oDocument, RtfReader oDocument.m_oProperty.m_nAnsiCodePage = m_oFont.m_nCodePage; } - if (m_oFont.m_nCharset != PROP_DEF && m_oFont.m_nCharset >= 0 && oDocument.m_oProperty.m_nAnsiCodePage == 0) + if (m_oFont.m_nCharset != PROP_DEF && m_oFont.m_nCharset > 2 && oDocument.m_oProperty.m_nAnsiCodePage == 0 && !m_oFont.m_sName.empty()) { oDocument.m_oProperty.m_nAnsiCodePage = RtfUtility::CharsetToCodepage(m_oFont.m_nCharset); } diff --git a/RtfFile/Format/RtfReader.cpp b/RtfFile/Format/RtfReader.cpp index 518985aacc..1e5783fb31 100644 --- a/RtfFile/Format/RtfReader.cpp +++ b/RtfFile/Format/RtfReader.cpp @@ -342,71 +342,74 @@ void RtfAbstractReader::ExecuteTextInternalSkipChars(std::wstring & sResult, Rtf } std::wstring RtfAbstractReader::ExecuteTextInternalCodePage( std::string& sCharString, RtfDocument& oDocument, RtfReader& oReader) { - std::wstring sResult; + if (sCharString.empty()) return L""; + if (sCharString == "*") return L"*"; + + std::wstring sResult; - if( false == sCharString.empty()) - { - if (sCharString == "*") return L"*"; + int nCodepage = -1; - int nCodepage = -1; - - //применяем параметры codepage от текущего шрифта todo associated fonts. - RtfFont oFont; - if ( true == oDocument.m_oFontTable.GetFont( oReader.m_oState->m_oCharProp.m_nFont, oFont ) && !m_bUseGlobalCodepage) - { - if( PROP_DEF != oFont.m_nCodePage ) - { - nCodepage = oFont.m_nCodePage; - } - else if (PROP_DEF != oFont.m_nCharset && (PROP_DEF == oDocument.m_oProperty.m_nAnsiCodePage || 0 == oDocument.m_oProperty.m_nAnsiCodePage)) + //применяем параметры codepage от текущего шрифта todo associated fonts. + RtfFont oFont; + if ((!m_bUseGlobalCodepage) && (true == oDocument.m_oFontTable.GetFont(oReader.m_oState->m_oCharProp.m_nFont, oFont))) + { + if (PROP_DEF != oFont.m_nCodePage) + { + nCodepage = oFont.m_nCodePage; + } + else if ((PROP_DEF != oFont.m_nCharset && oFont.m_nCharset > 2) + && (PROP_DEF == oDocument.m_oProperty.m_nAnsiCodePage || 0 == oDocument.m_oProperty.m_nAnsiCodePage)) + { + nCodepage = RtfUtility::CharsetToCodepage(oFont.m_nCharset); + } + } + //от настроек документа + if (-1 == nCodepage && RtfDocumentProperty::cp_none != oDocument.m_oProperty.m_eCodePage) + { + switch (oDocument.m_oProperty.m_eCodePage) + { + case RtfDocumentProperty::cp_ansi: + { + if (PROP_DEF != oDocument.m_oProperty.m_nAnsiCodePage) { - nCodepage = RtfUtility::CharsetToCodepage(oFont.m_nCharset); + nCodepage = oDocument.m_oProperty.m_nAnsiCodePage; } - } - //от настроек документа - if( -1 == nCodepage && RtfDocumentProperty::cp_none != oDocument.m_oProperty.m_eCodePage ) - { - switch ( oDocument.m_oProperty.m_eCodePage ) - { - case RtfDocumentProperty::cp_ansi: - { - if( PROP_DEF != oDocument.m_oProperty.m_nAnsiCodePage ) - { - nCodepage = oDocument.m_oProperty.m_nAnsiCodePage; - } - else - nCodepage = CP_ACP; - break; - } - case RtfDocumentProperty::cp_mac: nCodepage = CP_MACCP; break; //?? todooo - case RtfDocumentProperty::cp_pc: nCodepage = 437; break; //ms dos latin us - case RtfDocumentProperty::cp_pca: nCodepage = 850; break; //ms dos latin eu - } - } - //если ничего нет ставим ANSI или default from user - if( -1 == nCodepage ) - { - nCodepage = CP_ACP; + else + nCodepage = CP_ACP; + break; } - if (nCodepage == CP_ACP && oDocument.m_nUserLCID > 0) - { - nCodepage = msLCID2DefCodePage(oDocument.m_nUserLCID); + case RtfDocumentProperty::cp_mac: nCodepage = CP_MACCP; break; //?? todooo + case RtfDocumentProperty::cp_pc: nCodepage = 437; break; //ms dos latin us + case RtfDocumentProperty::cp_pca: nCodepage = 850; break; //ms dos latin eu } + } + //если ничего нет ставим ANSI или default from user + if (-1 == nCodepage) + { + nCodepage = CP_ACP; + } + if (nCodepage == CP_ACP && oDocument.m_nUserLCID > 0) + { + nCodepage = msLCID2DefCodePage(oDocument.m_nUserLCID); + } + if (m_bUseGlobalCodepage && nCodepage == 0 && PROP_DEF != oDocument.m_oProperty.m_nDefLang ) + { + nCodepage = msLCID2DefCodePage(oDocument.m_oProperty.m_nDefLang); + } - if (m_bUseGlobalCodepage && nCodepage == 0) - { - sResult = std::wstring(sCharString.begin(), sCharString.end()); - } - else - { - sResult = RtfUtility::convert_string_icu(sCharString.begin(), sCharString.end(), nCodepage); - } + if (m_bUseGlobalCodepage && nCodepage == 0) + { + sResult = std::wstring(sCharString.begin(), sCharString.end()); + } + else + { + sResult = RtfUtility::convert_string_icu(sCharString.begin(), sCharString.end(), nCodepage); + } - //if (!sCharString.empty() && sResult.empty()) - //{ - // //code page not support in icu !!! - // sResult = RtfUtility::convert_string(sCharString.begin(), sCharString.end(), nCodepage); .. to UnicodeConverter - //} - } + //if (!sCharString.empty() && sResult.empty()) + //{ + // //code page not support in icu !!! + // sResult = RtfUtility::convert_string(sCharString.begin(), sCharString.end(), nCodepage); .. to UnicodeConverter + //} return sResult; } diff --git a/RtfFile/Format/RtfShape.cpp b/RtfFile/Format/RtfShape.cpp index 2028df428d..b54a468298 100644 --- a/RtfFile/Format/RtfShape.cpp +++ b/RtfFile/Format/RtfShape.cpp @@ -690,10 +690,10 @@ std::wstring RtfShape::RenderToRtfShapeProperty(RenderParameter oRenderParameter RtfFont oFont; if( true == pDocument->m_oFontTable.GetFont( m_sGtextFont, oFont ) ) { - if( PROP_DEF != oFont.m_nCharset ) + if (PROP_DEF != oFont.m_nCodePage) + nCodePage = oFont.m_nCodePage; + else if( PROP_DEF != oFont.m_nCharset && oFont.m_nCharset > 2) nCodePage = RtfUtility::CharsetToCodepage( oFont.m_nCharset ); - else if( PROP_DEF != oFont.m_nCodePage ) - nCodePage = oFont.m_nCodePage; } }