From d6d117c5dd3078cfd13e6cbd7e6310d9abf4ecf6 Mon Sep 17 00:00:00 2001 From: Ivan Morozov Date: Fri, 25 Mar 2022 22:37:15 +0300 Subject: [PATCH 1/6] fix bug #56110 --- .../PPTFormatLib/PPTXWriter/Converter.cpp | 20 ++++++++++++------- .../PPTFormatLib/Records/MetafileBlob.h | 9 +++++++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp index 6560d423e6..201945b70d 100644 --- a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp @@ -614,7 +614,7 @@ void PPT_FORMAT::CPPTXWriter::WriteThemes() int nStartLayout = 0, nIndexTheme = 0; if (HasRoundTrips() && m_pDocument->m_arThemes.size()) - { + { std::unordered_set writedFilesHash; for (const auto& oIterSlide : m_pUserInfo->m_mapMasters) { @@ -644,6 +644,9 @@ void PPT_FORMAT::CPPTXWriter::WriteThemes() bool CPPTXWriter::HasRoundTrips() const { + if (m_pUserInfo == nullptr || m_pUserInfo->m_mapMasters.empty() || m_pUserInfo->m_mapMasters.begin()->second == nullptr) + return false; + std::vector arrRTTheme; m_pUserInfo->m_mapMasters.begin()->second->GetRecordsByType(&arrRTTheme, false, true); @@ -1015,14 +1018,17 @@ void PPT_FORMAT::CPPTXWriter::WriteTheme(CThemePtr pTheme, int & nIndexTheme, in WriteColorScheme(oStringWriter, L"Default", pTheme->m_arColorScheme); - oStringWriter.WriteString(std::wstring(L"m_arFonts[0].Name); - oStringWriter.WriteString(std::wstring(L"\"/>")); + if (!pTheme->m_arFonts.empty()) + { + oStringWriter.WriteString(std::wstring(L"m_arFonts[0].Name); + oStringWriter.WriteString(std::wstring(L"\"/>")); - oStringWriter.WriteString(std::wstring(L"m_arFonts.size() > 1 ) oStringWriter.WriteString (pTheme->m_arFonts[1].Name); - else oStringWriter.WriteStringXML(pTheme->m_arFonts[0].Name); + if (pTheme->m_arFonts.size() > 1 ) oStringWriter.WriteString (pTheme->m_arFonts[1].Name); + else oStringWriter.WriteStringXML(pTheme->m_arFonts[0].Name); + } oStringWriter.WriteString(std::wstring(L"\"/>")); oStringWriter.WriteString(std::wstring(L"")); diff --git a/ASCOfficePPTFile/PPTFormatLib/Records/MetafileBlob.h b/ASCOfficePPTFile/PPTFormatLib/Records/MetafileBlob.h index 4f0db277f6..a669e58503 100644 --- a/ASCOfficePPTFile/PPTFormatLib/Records/MetafileBlob.h +++ b/ASCOfficePPTFile/PPTFormatLib/Records/MetafileBlob.h @@ -60,8 +60,13 @@ public: m_nMM = StreamUtils::ReadSHORT(pStream); m_nExtX = StreamUtils::ReadSHORT(pStream); m_nExtY = StreamUtils::ReadSHORT(pStream); - pStream->read(m_pData, m_oHeader.RecLen - 6); - std::cout << m_pData << "\n\n"; + + const int dataLen = m_oHeader.RecLen - 6; + if (dataLen > 6) + { + m_pData = new BYTE[dataLen]; + pStream->read(m_pData, dataLen); + } } }; From 96a3ac70cabb5786b1ca7dcc404759e69633eef8 Mon Sep 17 00:00:00 2001 From: "Elena.Subbotina" Date: Mon, 28 Mar 2022 11:34:36 +0300 Subject: [PATCH 2/6] fix bug #56304 --- .../src/odf/datatypes/textposition.h | 23 ++++++------------- .../src/odf/style_text_properties.cpp | 20 ++++++++++++---- .../source/Oox2OdfConverter/DocxConverter.cpp | 6 ++--- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/ASCOfficeOdfFile/src/odf/datatypes/textposition.h b/ASCOfficeOdfFile/src/odf/datatypes/textposition.h index bc46178d81..6735d6e256 100644 --- a/ASCOfficeOdfFile/src/odf/datatypes/textposition.h +++ b/ASCOfficeOdfFile/src/odf/datatypes/textposition.h @@ -52,24 +52,16 @@ public: text_position() {} - text_position(type _Type) : type_(_Type), - has_font_size_(false) + text_position(type _Type) : type_(_Type) {} - text_position(double _Percent) : type_(Percent), - position_(_Percent), - has_font_size_(false) + text_position(double _Percent) : type_(Percent), position_(_Percent) {} - text_position(type _Type, double _FontSize) : type_(_Type), - has_font_size_(true), - font_size_(_FontSize) + text_position(type _Type, double _pctFontSize) : type_(_Type), font_size_(_pctFontSize) {} - text_position(double _Percent, double _FontSize) : type_(Percent), - position_(_Percent), - has_font_size_(true), - font_size_(_FontSize) + text_position(double _Percent, double _pctFontSize) : type_(Percent), position_(_Percent), font_size_(_pctFontSize) {} type get_type() const @@ -84,12 +76,12 @@ public: bool has_font_size() const { - return has_font_size_; + return font_size_.has_value(); } const percent & font_size() const { - return font_size_; + return font_size_.get_value_or(0); } static text_position parse(const std::wstring & Str); @@ -98,8 +90,7 @@ private: type type_; percent position_; - bool has_font_size_; - percent font_size_; + _CP_OPT(percent) font_size_; }; diff --git a/ASCOfficeOdfFile/src/odf/style_text_properties.cpp b/ASCOfficeOdfFile/src/odf/style_text_properties.cpp index 8d592f6a51..2cbc7881e7 100644 --- a/ASCOfficeOdfFile/src/odf/style_text_properties.cpp +++ b/ASCOfficeOdfFile/src/odf/style_text_properties.cpp @@ -834,6 +834,11 @@ void text_format_properties_content::docx_serialize(std::wostream & _rPr, fonts_ _rPr << L""; } } + else + { + if (mul < -0.3) _rPr << L""; + else if (mul > 0.3) _rPr << L""; + } } if (style_text_position_->has_font_size() && !noNeedSize) @@ -1236,11 +1241,11 @@ void text_format_properties_content::docx_convert(oox::docx_conversion_context & if (style_text_line_through_type_->get_type() == line_type::Single) _rPr << L""; else if (style_text_line_through_type_->get_type() == line_type::Double) - _rPr << L""; + _rPr << L""; } else if (style_text_line_through_style_ && style_text_line_through_style_->get_type() != line_style::None) { - _rPr << L""; + _rPr << L""; } } @@ -1256,12 +1261,12 @@ void text_format_properties_content::docx_convert(oox::docx_conversion_context & bool noNeedSize = false; if (style_text_position_->get_type() == text_position::Sub) { - _rPr << L""; + _rPr << L""; noNeedSize = true; } if (style_text_position_->get_type() == text_position::Super) { - _rPr << L""; + _rPr << L""; noNeedSize = true; } @@ -1282,6 +1287,11 @@ void text_format_properties_content::docx_convert(oox::docx_conversion_context & _rPr << L""; } } + else + { + if (mul < - 0.3) _rPr << L""; + else if (mul > 0.3) _rPr << L""; + } } if (style_text_position_->has_font_size() && !noNeedSize) @@ -1293,7 +1303,7 @@ void text_format_properties_content::docx_convert(oox::docx_conversion_context & if (!fontSize.empty()) { needProcessFontSize = false; - _rPr << L""; + _rPr << L""; } } } diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp index 3b192fcef7..48ad880817 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp @@ -2814,11 +2814,9 @@ void DocxConverter::convert(OOX::Logic::CRunProperty *oox_run_pr, odf_writer::st switch(oox_run_pr->m_oVertAlign->m_oVal->GetValue()) { case SimpleTypes::verticalalignrunSuperscript: - //text_properties->content_.style_text_position_ = odf_types::text_position(odf_types::text_position::Super); break; - text_properties->content_.style_text_position_ = odf_types::text_position(+33.); break; + text_properties->content_.style_text_position_ = odf_types::text_position(odf_types::text_position::Super, 58); break; case SimpleTypes::verticalalignrunSubscript: - //text_properties->content_.style_text_position_ = odf_types::text_position(odf_types::text_position::Sub); break; - text_properties->content_.style_text_position_ = odf_types::text_position(-33.); break;//по умолчанию 58% - хуже выглядит + text_properties->content_.style_text_position_ = odf_types::text_position(odf_types::text_position::Sub, 58); break; } } if (oox_run_pr->m_oW.IsInit() && oox_run_pr->m_oW->m_oVal.IsInit()) From 258e4cda5a65bfdea472dfe87b772fa40c884cf3 Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Mon, 28 Mar 2022 17:37:48 +0300 Subject: [PATCH 3/6] For bug 55777 --- PdfReader/Src/RendererOutputDev.cpp | 33 +++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/PdfReader/Src/RendererOutputDev.cpp b/PdfReader/Src/RendererOutputDev.cpp index f29c1b93ff..890943bf5b 100644 --- a/PdfReader/Src/RendererOutputDev.cpp +++ b/PdfReader/Src/RendererOutputDev.cpp @@ -3978,6 +3978,27 @@ namespace PdfReader if (nMaskWidth <= 0 || nMaskHeight <= 0) drawImage(pGState, pRef, pStream, nWidth, nHeight, pColorMap, NULL, false, interpolate); + if (nMaskWidth > nWidth || nMaskHeight > nHeight) + { + // If the mask is higher resolution than the image, use + // drawSoftMaskedImage() instead. + + GfxImageColorMap *maskColorMap; + Object maskDecode, decodeLow, decodeHigh; + + decodeLow.initInt(bMaskInvert ? 0 : 1); + decodeHigh.initInt(bMaskInvert ? 1 : 0); + maskDecode.initArray(m_pXref); + maskDecode.arrayAdd(&decodeLow); + maskDecode.arrayAdd(&decodeHigh); + maskColorMap = new GfxImageColorMap(1, &maskDecode, new GfxDeviceGrayColorSpace()); + maskDecode.free(); + drawSoftMaskedImage(pGState, pRef, pStream, nWidth, nHeight, + pColorMap, pStreamRef, pMaskStream, nMaskWidth, nMaskHeight, maskColorMap, NULL, interpolate); + delete maskColorMap; + return; + } + double dPageHeight = pGState->getPageHeight(); int nBufferSize = 4 * nWidth * nHeight; @@ -4011,11 +4032,11 @@ namespace PdfReader unsigned char unMask = 0; for (int nY = nMaskHeight - 1; nY >= 0; nY--) { + int nIndex = nY * nMaskWidth; for (int nX = 0; nX < nMaskWidth; nX++) { - int nIndex = nX + nY * nMaskWidth; pMask->getPixel(&unMask); - pMaskBuffer[nIndex] = unMask; + pMaskBuffer[nIndex++] = unMask; } } @@ -4025,9 +4046,9 @@ namespace PdfReader unsigned char unPixel[4] ={ 0, 0, 0, 0 }; for (int nY = nHeight - 1; nY >= 0; nY--) { + int nIndex = 4 * nY * nWidth; for (int nX = 0; nX < nWidth; nX++) { - int nIndex = 4 * (nX + nY * nWidth); pImageStream->getPixel(unPixel); int nNearestY = (std::min)((int)(nY / dScaleHeight), nMaskHeight - 1); @@ -4044,6 +4065,8 @@ namespace PdfReader pBufferPtr[nIndex + 3] = 0; else pBufferPtr[nIndex + 3] = 255; + + nIndex += 4; } } @@ -4055,9 +4078,9 @@ namespace PdfReader unsigned char unMask = 0; for (int nY = nHeight - 1; nY >= 0; nY--) { + int nIndex = 4 * nY * nWidth; for (int nX = 0; nX < nWidth; nX++) { - int nIndex = 4 * (nX + nY * nWidth); pImageStream->getPixel(unPixel); pMask->getPixel(&unMask); GfxRGB oRGB; @@ -4070,6 +4093,8 @@ namespace PdfReader pBufferPtr[nIndex + 3] = 0; else pBufferPtr[nIndex + 3] = 255; + + nIndex += 4; } } } From e88f00c27d60b2236ca8dde429adf4db77a87da8 Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Wed, 30 Mar 2022 14:05:09 +0300 Subject: [PATCH 4/6] Fix build for 32bit platform --- Common/3dParty/v8/v8.pri | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Common/3dParty/v8/v8.pri b/Common/3dParty/v8/v8.pri index 1615b4a28c..90868ca0c7 100644 --- a/Common/3dParty/v8/v8.pri +++ b/Common/3dParty/v8/v8.pri @@ -3,7 +3,11 @@ v8_version_89 { CONFIG += c++14 CONFIG += use_v8_monolith DEFINES += V8_VERSION_89_PLUS - DEFINES += V8_COMPRESS_POINTERS + + core_win_32:CONFIG += build_platform_32 + core_linux_32:CONFIG += build_platform_32 + !build_platform_32:DEFINES += V8_COMPRESS_POINTERS + CORE_V8_PATH_OVERRIDE = $$PWD/../v8_89 } From 286eb3fe9a79b3785ca566a798da8de316d4f67c Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Wed, 30 Mar 2022 15:58:54 +0300 Subject: [PATCH 5/6] Fix logic bug because of which with memory problems --- DocxRenderer/src/logic/FontManagerBase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DocxRenderer/src/logic/FontManagerBase.h b/DocxRenderer/src/logic/FontManagerBase.h index 15f070f0eb..3c8f8fcd4c 100644 --- a/DocxRenderer/src/logic/FontManagerBase.h +++ b/DocxRenderer/src/logic/FontManagerBase.h @@ -640,7 +640,7 @@ namespace NSFontManager { std::list::iterator posOld = pos; CFontPickUp& oPick = *(pos++); - if ((oPick.m_oFont.m_oFont.IsEqual(&m_oFont.m_oFont)) && (lRangeNum == oPick.m_lRangeNum) && (lRange == oPick.m_lRange)) + if ((oPick.m_oFont.m_oFont.IsEqual2(&m_oFont.m_oFont)) && (lRangeNum == oPick.m_lRangeNum) && (lRange == oPick.m_lRange)) { // нашли! ничего подбирать не нужно // нужно просто выкинуть этот шрифт наверх From 8eb21889bf514cfe25dfb5c7b65c0951a311e6df Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Wed, 30 Mar 2022 21:22:15 +0300 Subject: [PATCH 6/6] Fix bug 56275 --- OfficeUtils/src/ZipFolder.h | 60 +++++++++++++++++++++++++++++++++++++ XpsFile/XpsLib/Document.cpp | 4 +-- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/OfficeUtils/src/ZipFolder.h b/OfficeUtils/src/ZipFolder.h index d0c83d8867..50452bae59 100644 --- a/OfficeUtils/src/ZipFolder.h +++ b/OfficeUtils/src/ZipFolder.h @@ -85,11 +85,71 @@ public: { write(path, (BYTE*)xml.c_str(), (DWORD)xml.length()); } + bool existsXml(const std::wstring& path) + { + if (exists(path)) + return true; + + std::vector arPieces = getFiles(path, false); + if (0 < arPieces.size()) + { + std::sort(arPieces.begin(), arPieces.end()); + std::vector::iterator iter = arPieces.begin(); + while (iter != arPieces.end()) + { + std::wstring::size_type len = iter->length(); + std::wstring::size_type pos = iter->rfind(L".piece"); + if (std::wstring::npos != pos && ((pos + 6) == len)) + { + return true; + } + } + } + + return false; + } std::string readXml(const std::wstring& path) { CBuffer* buffer = NULL; if (!read(path, buffer)) + { + std::vector arPieces = getFiles(path, false); + if (0 < arPieces.size()) + { + std::sort(arPieces.begin(), arPieces.end()); + std::vector::iterator iter = arPieces.begin(); + while (iter != arPieces.end()) + { + std::wstring::size_type len = iter->length(); + std::wstring::size_type pos = iter->rfind(L".piece"); + if (std::wstring::npos != pos && ((pos + 6) == len)) + { + iter++; + continue; + } + else + { + iter = arPieces.erase(iter); + } + } + } + if (0 < arPieces.size()) + { + std::string sResult; + for (std::vector::iterator iter = arPieces.begin(); iter != arPieces.end(); iter++) + { + CBuffer* bufferPiece = NULL; + if (read(*iter, bufferPiece)) + { + sResult += std::string((char*)bufferPiece->Buffer, (size_t)bufferPiece->Size); + } + delete bufferPiece; + } + return sResult; + } + return ""; + } std::string sXmlUtf8((char*)buffer->Buffer, (size_t)buffer->Size); delete buffer; return sXmlUtf8; diff --git a/XpsFile/XpsLib/Document.cpp b/XpsFile/XpsLib/Document.cpp index 7dc4246967..dbcec8bdfb 100644 --- a/XpsFile/XpsLib/Document.cpp +++ b/XpsFile/XpsLib/Document.cpp @@ -236,10 +236,10 @@ namespace XPS ReadAttribute(oReader, L"Source", wsSource); std::wstring wsPagePath = wsSource; - if (!m_wsPath->exists(wsPagePath)) + if (!m_wsPath->existsXml(wsPagePath)) { wsPagePath = wsFilePath + wsSource; - if (!m_wsPath->exists(wsPagePath)) + if (!m_wsPath->existsXml(wsPagePath)) continue; }