mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Fix bug 49447
Fixed duplication of footnotes for Fb2File
This commit is contained in:
@ -395,38 +395,42 @@ public:
|
|||||||
// Читаем ссылку
|
// Читаем ссылку
|
||||||
else if (sName == L"a")
|
else if (sName == L"a")
|
||||||
{
|
{
|
||||||
bool bCross = true;
|
bool bCross = true, bMsoFootnote = false;
|
||||||
// Читаем href
|
// Читаем href
|
||||||
std::wstring sRef;
|
std::wstring sRef;
|
||||||
while (m_oLightReader.MoveToNextAttribute())
|
while (m_oLightReader.MoveToNextAttribute())
|
||||||
{
|
{
|
||||||
std::wstring sTName = m_oLightReader.GetName();
|
std::wstring sTName = m_oLightReader.GetName();
|
||||||
|
std::wstring sTText = m_oLightReader.GetText();
|
||||||
size_t nLen = (sTName.length() > 4 ? sTName.length() - 4 : 0);
|
size_t nLen = (sTName.length() > 4 ? sTName.length() - 4 : 0);
|
||||||
if (sTName.substr(nLen) == L"href")
|
if (sTName.substr(nLen) == L"href")
|
||||||
{
|
{
|
||||||
std::wstring sText = m_oLightReader.GetText();
|
|
||||||
size_t nRef = sText.find('#');
|
size_t nRef = sTText.find('#');
|
||||||
if (nRef != 0)
|
if (nRef != 0)
|
||||||
{
|
{
|
||||||
bCross = false;
|
bCross = false;
|
||||||
sRef = sText;
|
sRef = sTText;
|
||||||
}
|
}
|
||||||
else if (sText.length() > 1)
|
else if (sTText.length() > 1)
|
||||||
sRef = sText.substr(1);
|
sRef = sTText.substr(1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (sTName == L"style" && sTText.find(L"mso-footnote-id") != std::wstring::npos)
|
||||||
|
bMsoFootnote = true;
|
||||||
}
|
}
|
||||||
m_oLightReader.MoveToElement();
|
m_oLightReader.MoveToElement();
|
||||||
|
if (m_bFootnote && bMsoFootnote)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (bCross)
|
if (bCross)
|
||||||
{
|
{
|
||||||
std::map<std::wstring, std::wstring>::iterator it = m_mFootnotes.find(sRef);
|
std::map<std::wstring, std::wstring>::iterator it = m_mFootnotes.find(sRef);
|
||||||
if (it != m_mFootnotes.end())
|
if (it != m_mFootnotes.end())
|
||||||
{
|
{
|
||||||
// Пробел перед текстом внутри сноски
|
|
||||||
oBuilder += L"<w:r><w:t xml:space=\"preserve\"> </w:t></w:r>";
|
|
||||||
// Читаем текст внутри сноски
|
// Читаем текст внутри сноски
|
||||||
readP(sRStyle, oBuilder);
|
if (!bMsoFootnote)
|
||||||
|
readP(sRStyle, oBuilder);
|
||||||
// Стиль сноски
|
// Стиль сноски
|
||||||
oBuilder += L"<w:r><w:rPr><w:rStyle w:val=\"footnote\"/></w:rPr><w:footnoteReference w:id=\"";
|
oBuilder += L"<w:r><w:rPr><w:rStyle w:val=\"footnote\"/></w:rPr><w:footnoteReference w:id=\"";
|
||||||
oBuilder += it->second;
|
oBuilder += it->second;
|
||||||
@ -995,19 +999,11 @@ public:
|
|||||||
while (m_oLightReader.ReadNextSiblingNode(nTDepth))
|
while (m_oLightReader.ReadNextSiblingNode(nTDepth))
|
||||||
{
|
{
|
||||||
if (m_oLightReader.GetName() == L"p")
|
if (m_oLightReader.GetName() == L"p")
|
||||||
{
|
ReadFootnote(oFootnotes);
|
||||||
oFootnotes += L"<w:p><w:pPr><w:pStyle w:val=\"footnote-p\"/></w:pPr><w:r><w:rPr><w:rStyle w:val=\"footnote\"/></w:rPr></w:r>";
|
|
||||||
readP(L"", oFootnotes);
|
|
||||||
oFootnotes += L"</w:p>";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (sName == L"p" || sName == L"subtitle")
|
else if (sName == L"p" || sName == L"subtitle")
|
||||||
{
|
ReadFootnote(oFootnotes);
|
||||||
oFootnotes += L"<w:p><w:pPr><w:pStyle w:val=\"footnote-p\"/></w:pPr><w:r><w:rPr><w:rStyle w:val=\"footnote\"/></w:rPr></w:r>";
|
|
||||||
readP(L"", oFootnotes);
|
|
||||||
oFootnotes += L"</w:p>";
|
|
||||||
}
|
|
||||||
else if (sName == L"poem")
|
else if (sName == L"poem")
|
||||||
{
|
{
|
||||||
if (m_oLightReader.IsEmptyNode())
|
if (m_oLightReader.IsEmptyNode())
|
||||||
@ -1028,20 +1024,12 @@ public:
|
|||||||
{
|
{
|
||||||
// Читаем v (один или более)
|
// Читаем v (один или более)
|
||||||
if (m_oLightReader.GetName() == L"v")
|
if (m_oLightReader.GetName() == L"v")
|
||||||
{
|
ReadFootnote(oFootnotes);
|
||||||
oFootnotes += L"<w:p><w:pPr><w:pStyle w:val=\"footnote-p\"/></w:pPr><w:r><w:rPr><w:rStyle w:val=\"footnote\"/></w:rPr></w:r>";
|
|
||||||
readP(L"", oFootnotes);
|
|
||||||
oFootnotes += L"</w:p>";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Читаем text-author (любое)
|
// Читаем text-author (любое)
|
||||||
else if (sPName == L"text-author")
|
else if (sPName == L"text-author")
|
||||||
{
|
ReadFootnote(oFootnotes);
|
||||||
oFootnotes += L"<w:p><w:pPr><w:pStyle w:val=\"footnote-p\"/></w:pPr><w:r><w:rPr><w:rStyle w:val=\"footnote\"/></w:rPr></w:r>";
|
|
||||||
readP(L"", oFootnotes);
|
|
||||||
oFootnotes += L"</w:p>";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1682,6 +1670,10 @@ public:
|
|||||||
{
|
{
|
||||||
if (!m_bFootnote && sAtrName == L"style" && sAtrText.find(L"mso-footnote-id") != std::wstring::npos)
|
if (!m_bFootnote && sAtrName == L"style" && sAtrText.find(L"mso-footnote-id") != std::wstring::npos)
|
||||||
{
|
{
|
||||||
|
oXml.WriteString(sAtrName + L"=\"");
|
||||||
|
oXml.WriteEncodeXmlString(sAtrText);
|
||||||
|
oXml.WriteString(L"\" ");
|
||||||
|
|
||||||
sAtrText = sAtrText.substr(sAtrText.rfind(L':') + 1);
|
sAtrText = sAtrText.substr(sAtrText.rfind(L':') + 1);
|
||||||
oXml.WriteString(L"href=\"#");
|
oXml.WriteString(L"href=\"#");
|
||||||
oXml.WriteString(sAtrText);
|
oXml.WriteString(sAtrText);
|
||||||
@ -1867,6 +1859,16 @@ public:
|
|||||||
if (number >= 1) return L"i" + ToLowerRoman(number - 1);
|
if (number >= 1) return L"i" + ToLowerRoman(number - 1);
|
||||||
return L"";
|
return L"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void ReadFootnote(NSStringUtils::CStringBuilder& oFootnotes)
|
||||||
|
{
|
||||||
|
oFootnotes += L"<w:p><w:pPr><w:pStyle w:val=\"footnote-p\"/></w:pPr><w:r><w:rPr><w:rStyle w:val=\"footnote\"/></w:rPr><w:footnoteRef/></w:r>";
|
||||||
|
m_bFootnote = true;
|
||||||
|
readP(L"", oFootnotes);
|
||||||
|
m_bFootnote = false;
|
||||||
|
oFootnotes += L"</w:p>";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CFb2File::CFb2File()
|
CFb2File::CFb2File()
|
||||||
|
|||||||
@ -16,7 +16,7 @@ void getDirectories(const std::wstring& sDirectory, std::vector<std::wstring>& a
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
bool bBatchMode = false;
|
bool bBatchMode = false;
|
||||||
bool bFromHtml = false;
|
bool bFromHtml = false;
|
||||||
if (bBatchMode)
|
if (bBatchMode)
|
||||||
{
|
{
|
||||||
// Директория файлов
|
// Директория файлов
|
||||||
@ -113,7 +113,7 @@ int main()
|
|||||||
|
|
||||||
CFb2Params oParams;
|
CFb2Params oParams;
|
||||||
oParams.bNeedDocx = true;
|
oParams.bNeedDocx = true;
|
||||||
oParams.bNeedContents = true;
|
oParams.bNeedContents = false;
|
||||||
|
|
||||||
std::cout << (oFile.Open(sFile, sOutputDirectory, &oParams) == S_OK ? "Success" : "Failure") << std::endl;
|
std::cout << (oFile.Open(sFile, sOutputDirectory, &oParams) == S_OK ? "Success" : "Failure") << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user