From 189ce96bb303148031018aff206d454896ac2c72 Mon Sep 17 00:00:00 2001 From: Kulikova Svetlana Date: Tue, 6 Apr 2021 10:59:01 +0300 Subject: [PATCH] Fix bug 49448 --- Fb2File/Fb2File.cpp | 124 ++++++++++++++++++++++++------------------ Fb2File/test/main.cpp | 4 +- 2 files changed, 74 insertions(+), 54 deletions(-) diff --git a/Fb2File/Fb2File.cpp b/Fb2File/Fb2File.cpp index 731d06ef3a..3c31c86833 100644 --- a/Fb2File/Fb2File.cpp +++ b/Fb2File/Fb2File.cpp @@ -690,6 +690,7 @@ public: } } oTmpBuilder += L""; + i++; } // Размеры таблицы std::wstring sGridCol; @@ -1578,8 +1579,8 @@ HRESULT CFb2File::Open(const std::wstring& sPath, const std::wstring& sDirectory return S_OK; } -void readLi(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector& arrBinary, bool bUl); -void readStream(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector& arrBinary, bool bWasP) +void readLi(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector& arrBinary, bool bUl, bool bWasTable); +void readStream(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector& arrBinary, bool bWasP, bool bWasTable) { int nDeath = oIndexHtml.GetDepth(); if (oIndexHtml.IsEmptyNode() || !oIndexHtml.ReadNextSiblingNode2(nDeath)) @@ -1593,45 +1594,57 @@ void readStream(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& o { if (!bWasP) oXml.WriteString(L"

"); - readStream(oXml, oIndexHtml, arrBinary, true); + readStream(oXml, oIndexHtml, arrBinary, true, bWasTable); if (!bWasP) oXml.WriteString(L"

"); } else if (sName == L"h1") { - oXml.WriteString(L"
<p>"); - readStream(oXml, oIndexHtml, arrBinary, true); - oXml.WriteString(L"</p>
"); + if (!bWasP) + oXml.WriteString(L"
<p>"); + readStream(oXml, oIndexHtml, arrBinary, true, bWasTable); + if (!bWasP) + oXml.WriteString(L"</p>
"); } else if (sName == L"h2") { - oXml.WriteString(L"
<p>"); - readStream(oXml, oIndexHtml, arrBinary, true); - oXml.WriteString(L"</p>
"); + if (!bWasP) + oXml.WriteString(L"
<p>"); + readStream(oXml, oIndexHtml, arrBinary, true, bWasTable); + if (!bWasP) + oXml.WriteString(L"</p>
"); } else if (sName == L"h3") { - oXml.WriteString(L"
<p>"); - readStream(oXml, oIndexHtml, arrBinary, true); - oXml.WriteString(L"</p>
"); + if (!bWasP) + oXml.WriteString(L"
<p>"); + readStream(oXml, oIndexHtml, arrBinary, true, bWasTable); + if (!bWasP) + oXml.WriteString(L"</p>
"); } else if (sName == L"h4") { - oXml.WriteString(L"
<p>"); - readStream(oXml, oIndexHtml, arrBinary, true); - oXml.WriteString(L"</p>
"); + if (!bWasP) + oXml.WriteString(L"
<p>"); + readStream(oXml, oIndexHtml, arrBinary, true, bWasTable); + if (!bWasP) + oXml.WriteString(L"</p>
"); } else if (sName == L"h5") { - oXml.WriteString(L"
<p>"); - readStream(oXml, oIndexHtml, arrBinary, true); - oXml.WriteString(L"</p>
"); + if (!bWasP) + oXml.WriteString(L"
<p>"); + readStream(oXml, oIndexHtml, arrBinary, true, bWasTable); + if (!bWasP) + oXml.WriteString(L"</p>
"); } else if (sName == L"h6") { - oXml.WriteString(L"
<p>"); - readStream(oXml, oIndexHtml, arrBinary, true); - oXml.WriteString(L"</p>
"); + if (!bWasP) + oXml.WriteString(L"
<p>"); + readStream(oXml, oIndexHtml, arrBinary, true, bWasTable); + if (!bWasP) + oXml.WriteString(L"</p>
"); } else if (sName == L"span") { @@ -1651,66 +1664,73 @@ void readStream(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& o if (sAlign == L"super") { oXml.WriteString(L""); - readStream(oXml, oIndexHtml, arrBinary, bWasP); + readStream(oXml, oIndexHtml, arrBinary, bWasP, bWasTable); oXml.WriteString(L""); } else if (sAlign == L"sub") { oXml.WriteString(L""); - readStream(oXml, oIndexHtml, arrBinary, bWasP); + readStream(oXml, oIndexHtml, arrBinary, bWasP, bWasTable); oXml.WriteString(L""); } else - readStream(oXml, oIndexHtml, arrBinary, bWasP); + readStream(oXml, oIndexHtml, arrBinary, bWasP, bWasTable); } else - readStream(oXml, oIndexHtml, arrBinary, bWasP); + readStream(oXml, oIndexHtml, arrBinary, bWasP, bWasTable); } else if (sName == L"s") { oXml.WriteString(L""); - readStream(oXml, oIndexHtml, arrBinary, bWasP); + readStream(oXml, oIndexHtml, arrBinary, bWasP, bWasTable); oXml.WriteString(L""); } else if (sName == L"i") { oXml.WriteString(L""); - readStream(oXml, oIndexHtml, arrBinary, bWasP); + readStream(oXml, oIndexHtml, arrBinary, bWasP, bWasTable); oXml.WriteString(L""); } else if (sName == L"b") { oXml.WriteString(L""); - readStream(oXml, oIndexHtml, arrBinary, bWasP); + readStream(oXml, oIndexHtml, arrBinary, bWasP, bWasTable); oXml.WriteString(L""); } else if (sName == L"table") { - oXml.WriteString(L""); - readStream(oXml, oIndexHtml, arrBinary, bWasP); - oXml.WriteString(L"
"); + if (!bWasTable) + oXml.WriteString(L""); + readStream(oXml, oIndexHtml, arrBinary, bWasP, bWasTable); + if (!bWasTable) + oXml.WriteString(L"
"); } else if (sName == L"tr") { - oXml.WriteString(L""); - readStream(oXml, oIndexHtml, arrBinary, bWasP); - oXml.WriteString(L""); + if (!bWasTable) + oXml.WriteString(L""); + readStream(oXml, oIndexHtml, arrBinary, bWasP, bWasTable); + if (!bWasTable) + oXml.WriteString(L""); } else if (sName == L"td" || sName == L"th") { - oXml.WriteString(L""); } - oIndexHtml.MoveToElement(); - - oXml.WriteString(L""); - readStream(oXml, oIndexHtml, arrBinary, true); - oXml.WriteString(L""); + readStream(oXml, oIndexHtml, arrBinary, true, true); + if (!bWasTable) + oXml.WriteString(L""); } else if (sName == L"a") { @@ -1719,13 +1739,13 @@ void readStream(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& o oXml.WriteEncodeXmlString(oIndexHtml.GetText()); oXml.WriteString(L"\">"); oIndexHtml.MoveToElement(); - readStream(oXml, oIndexHtml, arrBinary, bWasP); + readStream(oXml, oIndexHtml, arrBinary, bWasP, bWasTable); oXml.WriteString(L""); } else if (sName == L"ul") - readLi(oXml, oIndexHtml, arrBinary, true); + readLi(oXml, oIndexHtml, arrBinary, true, bWasTable); else if (sName == L"ol") - readLi(oXml, oIndexHtml, arrBinary, false); + readLi(oXml, oIndexHtml, arrBinary, false, bWasTable); else if (sName == L"img") { std::wstring sBinary; @@ -1742,11 +1762,11 @@ void readStream(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& o oXml.WriteString(L""); } else - readStream(oXml, oIndexHtml, arrBinary, bWasP); + readStream(oXml, oIndexHtml, arrBinary, bWasP, bWasTable); } while (oIndexHtml.ReadNextSiblingNode2(nDeath)); } -void readLi(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector& arrBinary, bool bUl) +void readLi(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector& arrBinary, bool bUl, bool bWasTable) { int nNum = 1; int nDeath = oIndexHtml.GetDepth(); @@ -1759,7 +1779,7 @@ void readLi(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& oInde oXml.WriteString(L"

"); bUl ? oXml.AddCharSafe(183) : oXml.AddInt(nNum++); oXml.WriteString(L" "); - readStream(oXml, oIndexHtml, arrBinary, true); + readStream(oXml, oIndexHtml, arrBinary, true, bWasTable); oXml.WriteString(L"

"); } } while (oIndexHtml.ReadNextSiblingNode2(nDeath)); @@ -1847,7 +1867,7 @@ HRESULT CFb2File::FromHtml(const std::wstring& sHtmlFile, const std::wstring& sC int nDepth = oIndexHtml.GetDepth(); oIndexHtml.ReadNextSiblingNode(nDepth); // head oIndexHtml.ReadNextSiblingNode(nDepth); // body - readStream(oDocument, oIndexHtml, arrBinary, false); + readStream(oDocument, oIndexHtml, arrBinary, false, false); } oDocument.WriteString(L""); // binary diff --git a/Fb2File/test/main.cpp b/Fb2File/test/main.cpp index 1e9a5995ce..5ce34d4f6a 100644 --- a/Fb2File/test/main.cpp +++ b/Fb2File/test/main.cpp @@ -91,7 +91,7 @@ int main() CFb2File oFile; // Файл, который открываем - std::wstring sFile = NSFile::GetProcessDirectory() + L"/../../../examples/8-sezon-groz.fb2"; + std::wstring sFile = NSFile::GetProcessDirectory() + L"/../../../examples/res.fb2"; // Директория, где будем создавать docx std::wstring sOutputDirectory = NSFile::GetProcessDirectory() + L"/res"; @@ -102,7 +102,7 @@ int main() if (bFromHtml) { sFile = NSFile::GetProcessDirectory() + L"/../../../examples/test3"; - oFile.FromHtml(sFile, sOutputDirectory + L"/res.fb2"); + oFile.FromHtml(sFile, sFile, sOutputDirectory + L"/res.fb2", L"Test Title"); return 0; }