Fb2File summary

This commit is contained in:
Kulikova Svetlana
2021-02-19 10:29:12 +03:00
parent 23ace16776
commit abffa8d301

View File

@ -96,7 +96,7 @@ struct STitleInfo
std::wstring getAuthors()
{
return std::accumulate(m_arAuthors.begin(), m_arAuthors.end(), std::wstring(),
[] (std::wstring& sRes, const SAuthor& vElem) { return sRes += vElem.middle_name + L" " + vElem.first_name + L" " + vElem.last_name + L" " + vElem.nickname + L";"; });
[] (std::wstring& sRes, const SAuthor& vElem) { return sRes += vElem.middle_name + L' ' + vElem.first_name + L' ' + vElem.last_name + L' ' + vElem.nickname + L';'; });
}
};
@ -201,6 +201,8 @@ public:
m_oLightReader.Clear();
m_mFootnotes.clear();
m_mImages.clear();
m_oTitleInfo.m_arAuthors.clear();
m_oTitleInfo.m_arGenres.clear();
/*
m_mCustomInfo.clear();
if(m_pSrcTitleInfo)
@ -221,7 +223,7 @@ public:
// Проверяет наличие тэга FictionBook
bool isFictionBook()
{
return m_oLightReader.ReadNextNode() ? m_oLightReader.GetName() == L"FictionBook" : false;
return m_oLightReader.ReadNextNode() && m_oLightReader.GetName() == L"FictionBook";
}
// Читает поля автора
@ -242,7 +244,7 @@ public:
else if (sName == L"last-name")
oAuthor.last_name = content();
else if (sName == L"nickname")
oAuthor.nickname = content();
oAuthor.nickname = content();
/*
else if(sName == L"home-page")
oAuthor.home_page.push_back(content());
@ -309,22 +311,22 @@ public:
// Читает title
void readTitle(const std::wstring& sLevel, NSStringUtils::CStringBuilder& oBuilder)
{
if(m_oLightReader.IsEmptyNode())
if (m_oLightReader.IsEmptyNode())
return;
bool bFirstP = true;
int nDeath = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nDeath))
while (m_oLightReader.ReadNextSiblingNode(nDeath))
{
// Пишем заголовок
if(m_oLightReader.GetName() == L"p")
if (m_oLightReader.GetName() == L"p")
{
// Пишем title + sLevel
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"";
oBuilder += sLevel;
oBuilder += L"\"/>";
// Заголовок книги с новой страницы
if(sLevel == L"title" && bFirstP)
if (sLevel == L"title" && bFirstP)
{
oBuilder += L"<w:pageBreakBefore/>";
bFirstP = false;
@ -332,7 +334,7 @@ public:
oBuilder += L"</w:pPr>";
// Пишем ссылку от оглавления
std::wstring sContentsId;
if(sLevel == L"title1")
if (sLevel == L"title1")
{
sContentsId = std::to_wstring(m_nContentsId++);
oBuilder += L"<w:bookmarkStart w:id=\"";
@ -343,7 +345,7 @@ public:
}
readP(L"", oBuilder);
// Пишем ссылку от оглавления
if(sLevel == L"title1")
if (sLevel == L"title1")
{
oBuilder += L"<w:bookmarkEnd w:id=\"";
oBuilder += sContentsId;
@ -391,7 +393,7 @@ public:
// Читает p
// НЕ имеет право писать p
// sRStyle - накопленный стиль
void readP(std::wstring sRStyle, NSStringUtils::CStringBuilder& oBuilder)
void readP(const std::wstring& sRStyle, NSStringUtils::CStringBuilder& oBuilder)
{
readCrossReference(oBuilder);
@ -427,7 +429,7 @@ public:
else if (sName == L"a")
{
// Читаем href
std::wstring sFootnoteName = L"";
std::wstring sFootnoteName;
while (m_oLightReader.MoveToNextAttribute())
{
std::wstring sTName = m_oLightReader.GetName();
@ -469,16 +471,16 @@ public:
else if (sName == L"strikethrough")
readP(sRStyle + L"<w:strike/>", oBuilder);
// Читает нижний текст
else if(sName == L"sub")
else if (sName == L"sub")
readP(sRStyle + L"<w:vertAlign w:val=\"subscript\"/>", oBuilder);
// Читает верхний текст
else if(sName == L"sup")
else if (sName == L"sup")
readP(sRStyle + L"<w:vertAlign w:val=\"superscript\"/>", oBuilder);
// Читает код
else if(sName == L"code")
else if (sName == L"code")
readP(sRStyle + L"<w:rStyle w:val=\"code\"/>", oBuilder);
// Читает картинку в тексте
else if(sName == L"image")
else if (sName == L"image")
readImage(oBuilder);
}
}
@ -539,27 +541,27 @@ public:
{
readCrossReference(oBuilder);
if(m_oLightReader.IsEmptyNode())
if (m_oLightReader.IsEmptyNode())
return;
int nDeath = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nDeath))
while (m_oLightReader.ReadNextSiblingNode(nDeath))
{
std::wstring sName = m_oLightReader.GetName();
if(sName == L"p" || sName == L"subtitle")
if (sName == L"p" || sName == L"subtitle")
{
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"cite-p\"/></w:pPr>";
readP(L"", oBuilder);
oBuilder += L"</w:p>";
}
else if(sName == L"empty-line")
else if (sName == L"empty-line")
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"cite-p\"/></w:pPr></w:p>";
else if(sName == L"poem")
else if (sName == L"poem")
readPoem(oBuilder);
else if(sName == L"table")
else if (sName == L"table")
readTable(oBuilder);
// Автор цитаты выделяется полужирным
else if(sName == L"text-author")
else if (sName == L"text-author")
{
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"cite-p\"/></w:pPr>";
readP(L"<w:b/>", oBuilder);
@ -573,7 +575,7 @@ public:
{
readCrossReference(oBuilder);
if(m_oLightReader.IsEmptyNode())
if (m_oLightReader.IsEmptyNode())
return;
// Стиль таблицы
@ -582,47 +584,43 @@ public:
NSStringUtils::CStringBuilder oTmpBuilder;
int nGridCol = 0;
int nDeath = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nDeath))
while (m_oLightReader.ReadNextSiblingNode(nDeath))
{
// tr - строки в таблице
if(m_oLightReader.GetName() == L"tr")
if (m_oLightReader.GetName() != L"tr" || m_oLightReader.IsEmptyNode())
continue;
int nTCol = 0;
oTmpBuilder += L"<w:tr>";
int nTrDeath = m_oLightReader.GetDepth();
while (m_oLightReader.ReadNextSiblingNode(nTrDeath))
{
if(m_oLightReader.IsEmptyNode())
continue;
int nTCol = 0;
oTmpBuilder += L"<w:tr>";
int nTrDeath = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nTrDeath))
oTmpBuilder += L"<w:tc><w:tcPr><w:textDirection w:val=\"lrTb\"/><w:noWrap w:val=\"false\"/></w:tcPr><w:p>";
// Читаем th. Ячейка заголовка таблицы. Выравнивание посередине. Выделяется полужирным
if (m_oLightReader.GetName() == L"th")
{
oTmpBuilder += L"<w:tc><w:tcPr><w:textDirection w:val=\"lrTb\"/><w:noWrap w:val=\"false\"/></w:tcPr><w:p>";
// Читаем th. Ячейка заголовка таблицы. Выравнивание посередине. Выделяется полужирным
if(m_oLightReader.GetName() == L"th")
{
if(++nTCol > nGridCol)
nGridCol = nTCol;
oTmpBuilder += L"<w:pPr><w:jc w:val=\"center\"/></w:pPr>";
readP(L"<w:b/>", oTmpBuilder);
}
// Читаем td. Ячейка таблицы. Выравнивание вправо
else if(m_oLightReader.GetName() == L"td")
{
if(++nTCol > nGridCol)
nGridCol = nTCol;
oTmpBuilder += L"<w:pPr><w:jc w:val=\"right\"/></w:pPr>";
readP(L"", oTmpBuilder);
}
oTmpBuilder += L"</w:p></w:tc>";
if (++nTCol > nGridCol)
nGridCol = nTCol;
oTmpBuilder += L"<w:pPr><w:jc w:val=\"center\"/></w:pPr>";
readP(L"<w:b/>", oTmpBuilder);
}
oTmpBuilder += L"</w:tr>";
// Читаем td. Ячейка таблицы. Выравнивание вправо
else if (m_oLightReader.GetName() == L"td")
{
if(++nTCol > nGridCol)
nGridCol = nTCol;
oTmpBuilder += L"<w:pPr><w:jc w:val=\"right\"/></w:pPr>";
readP(L"", oTmpBuilder);
}
oTmpBuilder += L"</w:p></w:tc>";
}
oTmpBuilder += L"</w:tr>";
}
// Размеры таблицы
std::wstring sGridCol = L"";
if(nGridCol != 0)
std::wstring sGridCol;
if (nGridCol != 0)
sGridCol = std::to_wstring((int)(9570.0 / (double)nGridCol));
oBuilder += L"<w:tblGrid>";
for(int i = 0; i < nGridCol; i++)
for (int i = 0; i < nGridCol; i++)
{
oBuilder += L"<w:gridCol w:w=\"";
oBuilder += sGridCol;
@ -641,26 +639,26 @@ public:
{
readCrossReference(oBuilder);
if(m_oLightReader.IsEmptyNode())
if (m_oLightReader.IsEmptyNode())
return;
int nADeath = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nADeath))
while (m_oLightReader.ReadNextSiblingNode(nADeath))
{
std::wstring sAnName = m_oLightReader.GetName();
if(sAnName == L"p" || sAnName == L"subtitle")
if (sAnName == L"p" || sAnName == L"subtitle")
{
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"annotation\"/></w:pPr>";
readP(L"", oBuilder);
oBuilder += L"</w:p>";
}
else if(sAnName == L"poem")
else if (sAnName == L"poem")
readPoem(oBuilder);
else if(sAnName == L"cite")
else if (sAnName == L"cite")
readCite(oBuilder);
else if(sAnName == L"empty-line")
else if (sAnName == L"empty-line")
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"annotation\"/></w:pPr></w:p>";
else if(sAnName == L"table")
else if (sAnName == L"table")
readTable(oBuilder);
}
}
@ -669,9 +667,9 @@ public:
void readCrossReference(NSStringUtils::CStringBuilder& oBuilder)
{
// id для перекрестных ссылок
while(m_oLightReader.MoveToNextAttribute())
while (m_oLightReader.MoveToNextAttribute())
{
if(m_oLightReader.GetName() == L"id")
if (m_oLightReader.GetName() == L"id")
{
std::wstring sCrossId = std::to_wstring(m_nCrossReferenceId++);
oBuilder += L"<w:bookmarkStart w:id=\"";
@ -688,55 +686,55 @@ public:
}
// Читает section
void readSection(unsigned int nLevel, NSStringUtils::CStringBuilder& oBuilder)
void readSection(int nLevel, NSStringUtils::CStringBuilder& oBuilder)
{
readCrossReference(oBuilder);
if(m_oLightReader.IsEmptyNode())
if (m_oLightReader.IsEmptyNode())
return;
int nDeath = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nDeath))
while (m_oLightReader.ReadNextSiblingNode(nDeath))
{
std::wstring sName = m_oLightReader.GetName();
if(sName == L"title")
if (sName == L"title")
{
std::wstring sTitle = L"section-p";
if(nLevel < 10)
if (nLevel < 10)
sTitle = L"title" + std::to_wstring(nLevel);
readTitle(sTitle, oBuilder);
}
else if(sName == L"epigraph")
else if (sName == L"epigraph")
readEpigraph(oBuilder);
else if(sName == L"image")
else if (sName == L"image")
{
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"image\"/></w:pPr>";
readImage(oBuilder);
oBuilder += L"</w:p>";
}
else if(sName == L"annotation")
else if (sName == L"annotation")
readAnnotation(oBuilder);
else if(sName == L"section")
else if (sName == L"section")
readSection(nLevel + 1, oBuilder);
else if(sName == L"p")
else if (sName == L"p")
{
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"section-p\"/></w:pPr>";
readP(L"", oBuilder);
oBuilder += L"</w:p>";
}
else if(sName == L"subtitle")
else if (sName == L"subtitle")
{
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"section-subtitle\"/></w:pPr>";
readP(L"", oBuilder);
oBuilder += L"</w:p>";
}
else if(sName == L"poem")
else if (sName == L"poem")
readPoem(oBuilder);
else if(sName == L"cite")
else if (sName == L"cite")
readCite(oBuilder);
else if(sName == L"empty-line")
else if (sName == L"empty-line")
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"section-p\"/></w:pPr></w:p>";
else if(sName == L"table")
else if (sName == L"table")
readTable(oBuilder);
}
}
@ -744,24 +742,24 @@ public:
// Читает body
void readBody(NSStringUtils::CStringBuilder& oBuilder)
{
if(m_oLightReader.IsEmptyNode())
if (m_oLightReader.IsEmptyNode())
return;
int nDeath = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nDeath))
while (m_oLightReader.ReadNextSiblingNode(nDeath))
{
std::wstring sName = m_oLightReader.GetName();
if(sName == L"image")
if (sName == L"image")
{
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"image\"/></w:pPr>";
readImage(oBuilder);
oBuilder += L"</w:p>";
}
else if(sName == L"title")
else if (sName == L"title")
readTitle(L"title", oBuilder);
else if(sName == L"epigraph")
else if (sName == L"epigraph")
readEpigraph(oBuilder);
else if(sName == L"section")
else if (sName == L"section")
readSection(1, oBuilder);
}
}
@ -769,53 +767,50 @@ public:
// Читает содержание, binary, body, сноски, description
bool readText(const std::wstring& sPath, const std::wstring& sMediaDirectory, NSStringUtils::CStringBuilder& oContents, NSStringUtils::CStringBuilder& oRels, NSStringUtils::CStringBuilder& oFootnotes)
{
if(!m_oLightReader.IsValid())
if (!m_oLightReader.IsValid())
{
// Открывает файл на проверку
if (!OpenFromFile(sPath))
return false;
// Читаем FictionBook
if(!isFictionBook())
if (!isFictionBook())
return false;
}
if(m_oLightReader.IsEmptyNode())
if (m_oLightReader.IsEmptyNode())
return true;
int nContentsId = 1;
int nImageId = 1;
int nImageId = 1;
int nFootnoteId = 1;
oContents += L"<w:sdt><w:sdtPr><w:docPartObj><w:docPartGallery w:val=\"Table of Contents\"/><w:docPartUnique/></w:docPartObj></w:sdtPr><w:sdtContent>";
int nDeath = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nDeath))
while (m_oLightReader.ReadNextSiblingNode(nDeath))
{
std::wstring sName = m_oLightReader.GetName();
// Читаем body
if(sName == L"body")
if (sName == L"body")
{
// Сноски
bool bNotes = false;
while(m_oLightReader.MoveToNextAttribute())
{
if(m_oLightReader.GetName() == L"name" &&
m_oLightReader.GetText() == L"notes")
if (m_oLightReader.GetName() == L"name" &&
m_oLightReader.GetText() == L"notes")
bNotes = true;
}
m_oLightReader.MoveToElement();
// Читаем сноски
if(bNotes)
if (bNotes)
readNotes(nFootnoteId, oFootnotes);
// Читаем содержание
else
readContents(nContentsId, oContents);
}
// Читаем картинки
else if(sName == L"binary")
{
std::wstring sImageId = std::to_wstring(nImageId++);
getImage(sImageId, sMediaDirectory, oRels);
}
else if (sName == L"binary")
getImage(std::to_wstring(nImageId++), sMediaDirectory, oRels);
}
oContents += L"</w:sdtContent></w:sdt>";
return true;
@ -824,183 +819,170 @@ public:
// Читает содержание
void readContents(int& nContentsId, NSStringUtils::CStringBuilder& oContents)
{
if(m_oLightReader.IsEmptyNode())
if (m_oLightReader.IsEmptyNode())
return;
bool bFirstTitle = true;
int nBDeath = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nBDeath))
while (m_oLightReader.ReadNextSiblingNode(nBDeath))
{
std::wstring sName = m_oLightReader.GetName();
// Читаем section
if(sName == L"section")
if (m_oLightReader.GetName() != L"section" || m_oLightReader.IsEmptyNode())
continue;
int nSDeath = m_oLightReader.GetDepth();
while (m_oLightReader.ReadNextSiblingNode(nSDeath))
{
if(m_oLightReader.IsEmptyNode())
// Читаем title
if (m_oLightReader.GetName() != L"title" || m_oLightReader.IsEmptyNode())
continue;
int nSDeath = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nSDeath))
oContents += L"<w:p><w:pPr><w:pStyle w:val=\"contents\"/><w:tabs><w:tab w:val=\"right\" w:pos=\"9355\" w:leader=\"none\"/></w:tabs>";
// Абзац с новой страницы
if (bFirstTitle)
oContents += L"<w:pageBreakBefore/>";
oContents += L"</w:pPr>";
if (bFirstTitle)
{
// Читаем title
if(m_oLightReader.GetName() == L"title")
oContents += L"<w:r><w:fldChar w:fldCharType=\"begin\"/><w:instrText xml:space=\"preserve\">TOC \\n \\h </w:instrText><w:fldChar w:fldCharType=\"separate\"/></w:r>";
bFirstTitle = false;
}
oContents += L"<w:hyperlink w:tooltip=\"Current Document\" w:anchor=\"_Toc";
oContents += std::to_wstring(nContentsId++);
oContents += L"\" w:history=\"1\">";
int nTDeath = m_oLightReader.GetDepth();
while (m_oLightReader.ReadNextSiblingNode(nTDeath))
{
if (m_oLightReader.GetName() == L"p")
{
if(m_oLightReader.IsEmptyNode())
continue;
std::wstring sContentsId = std::to_wstring(nContentsId++);
oContents += L"<w:p><w:pPr><w:pStyle w:val=\"contents\"/><w:tabs><w:tab w:val=\"right\" w:pos=\"9355\" w:leader=\"none\"/></w:tabs>";
// Абзац с новой страницы
if(bFirstTitle)
oContents += L"<w:pageBreakBefore/>";
oContents += L"</w:pPr>";
if(bFirstTitle)
{
oContents += L"<w:r><w:fldChar w:fldCharType=\"begin\"/><w:instrText xml:space=\"preserve\">TOC \\n \\h </w:instrText><w:fldChar w:fldCharType=\"separate\"/></w:r>";
bFirstTitle = false;
}
oContents += L"<w:hyperlink w:tooltip=\"Current Document\" w:anchor=\"_Toc";
oContents += sContentsId;
oContents += L"\" w:history=\"1\">";
int nTDeath = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nTDeath))
{
if(m_oLightReader.GetName() == L"p")
{
readP(L"<w:rStyle w:val=\"contents-p\"/>", oContents);
// Вставляем пробел между словами
oContents += L"<w:r><w:t xml:space=\"preserve\"> </w:t></w:r>";
}
}
oContents += L"</w:hyperlink></w:p>";
readP(L"<w:rStyle w:val=\"contents-p\"/>", oContents);
// Вставляем пробел между словами
oContents += L"<w:r><w:t xml:space=\"preserve\"> </w:t></w:r>";
}
}
oContents += L"</w:hyperlink></w:p>";
}
}
if(!bFirstTitle)
if (!bFirstTitle)
oContents += L"<w:p><w:r><w:fldChar w:fldCharType=\"end\"/></w:r></w:p>";
}
// Читает сноски
void readNotes(int& nFootnoteId, NSStringUtils::CStringBuilder& oFootnotes)
{
if(m_oLightReader.IsEmptyNode())
if (m_oLightReader.IsEmptyNode())
return;
int nBDepth = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nBDepth))
while (m_oLightReader.ReadNextSiblingNode(nBDepth))
{
if(m_oLightReader.GetName() == L"section")
if (m_oLightReader.GetName() != L"section")
continue;
// Читаем id
std::wstring sFootnoteName;
while (m_oLightReader.MoveToNextAttribute())
{
// Читаем id
std::wstring sFootnoteName = L"";
while(m_oLightReader.MoveToNextAttribute())
if (m_oLightReader.GetName() == L"id")
{
if(m_oLightReader.GetName() == L"id")
{
sFootnoteName = m_oLightReader.GetText();
break;
}
sFootnoteName = m_oLightReader.GetText();
break;
}
m_oLightReader.MoveToElement();
if(sFootnoteName == L"")
continue;
if(m_oLightReader.IsEmptyNode())
continue;
}
m_oLightReader.MoveToElement();
if (sFootnoteName.empty() || m_oLightReader.IsEmptyNode())
continue;
std::wstring sFootnoteId = std::to_wstring(nFootnoteId++);
m_mFootnotes.insert(std::make_pair(sFootnoteName, sFootnoteId));
// Пишем сноску
oFootnotes += L"<w:footnote w:id=\"";
oFootnotes += sFootnoteId;
oFootnotes += L"\">";
std::wstring sFootnoteId = std::to_wstring(nFootnoteId++);
m_mFootnotes.insert(std::make_pair(sFootnoteName, sFootnoteId));
// Пишем сноску
oFootnotes += L"<w:footnote w:id=\"";
oFootnotes += sFootnoteId;
oFootnotes += L"\">";
// Читаем внутренность section
int nSDepth = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nSDepth))
// Читаем внутренность section
int nSDepth = m_oLightReader.GetDepth();
while (m_oLightReader.ReadNextSiblingNode(nSDepth))
{
std::wstring sName = m_oLightReader.GetName();
if (sName == L"title")
{
std::wstring sName = m_oLightReader.GetName();
if(sName == L"title")
{
if(m_oLightReader.IsEmptyNode())
continue;
if (m_oLightReader.IsEmptyNode())
continue;
int nTDepth = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nTDepth))
int nTDepth = m_oLightReader.GetDepth();
while (m_oLightReader.ReadNextSiblingNode(nTDepth))
{
if (m_oLightReader.GetName() == L"p")
{
if(m_oLightReader.GetName() == L"p")
{
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>";
}
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")
{
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")
{
if(m_oLightReader.IsEmptyNode())
continue;
}
else if (sName == L"p" || sName == L"subtitle")
{
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")
{
if (m_oLightReader.IsEmptyNode())
continue;
int nPDepth = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nPDepth))
int nPDepth = m_oLightReader.GetDepth();
while (m_oLightReader.ReadNextSiblingNode(nPDepth))
{
std::wstring sPName = m_oLightReader.GetName();
// Читаем stanza (один или более)
if (sPName == L"stanza")
{
std::wstring sPName = m_oLightReader.GetName();
// Читаем stanza (один или более)
if(sPName == L"stanza")
{
if(m_oLightReader.IsEmptyNode())
continue;
if (m_oLightReader.IsEmptyNode())
continue;
int nSDeath = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nSDeath))
int nSDeath = m_oLightReader.GetDepth();
while (m_oLightReader.ReadNextSiblingNode(nSDeath))
{
// Читаем v (один или более)
if (m_oLightReader.GetName() == L"v")
{
// Читаем v (один или более)
if(m_oLightReader.GetName() == L"v")
{
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>";
}
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 (любое)
else if(sPName == L"text-author")
{
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 (любое)
else if (sPName == L"text-author")
{
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>";
}
}
}
oFootnotes += L"</w:footnote>";
}
oFootnotes += L"</w:footnote>";
}
}
// Читает binary
void getImage(const std::wstring& sImageId, const std::wstring& sMediaDirectory, NSStringUtils::CStringBuilder& oRels)
{
std::wstring sId = L"";
while(m_oLightReader.MoveToNextAttribute())
std::wstring sId;
while (m_oLightReader.MoveToNextAttribute())
{
// Читает id
if(m_oLightReader.GetName() == L"id")
if (m_oLightReader.GetName() == L"id")
sId = m_oLightReader.GetText();
}
m_oLightReader.MoveToElement();
if (sId == L"" || m_oLightReader.IsEmptyNode())
if (sId.empty() || m_oLightReader.IsEmptyNode())
return;
// Пишет картинку в файл
NSFile::CFileBinary oImageWriter;
if(oImageWriter.CreateFileW(sMediaDirectory + L"/" + sId + (sId.find(L'.') == std::wstring::npos ? L".png" : L"")))
if (oImageWriter.CreateFileW(sMediaDirectory + L'/' + sId + (sId.find(L'.') == std::wstring::npos ? L".png" : L"")))
{
std::string sBase64 = contentA();
int nSrcLen = (int)sBase64.length();
@ -1013,10 +995,10 @@ public:
// Получаем размеры картинки
CBgraFrame oBgraFrame;
oBgraFrame.OpenFile(sMediaDirectory + L"/" + sId);
oBgraFrame.OpenFile(sMediaDirectory + L'/' + sId);
int nHy = oBgraFrame.get_Height();
int nWx = oBgraFrame.get_Width();
if(nWx > nHy)
if (nWx > nHy)
{
int nW = nWx * 9525;
nW = (nW > 7000000 ? 7000000 : nW);
@ -1028,7 +1010,7 @@ public:
int nH = nHy * 9525;
nH = (nH > 9000000 ? 9000000 : nH);
int nW = (int)((double)nWx * (double)nH / (double)nHy);
if(nW > 7000000)
if (nW > 7000000)
{
nW = 7000000;
nHy = (int)((double)nHy * (double)nW / (double)nWx);
@ -1055,15 +1037,14 @@ public:
// Читает description
void readDescription(NSStringUtils::CStringBuilder& oBuilder)
{
if(m_oLightReader.IsEmptyNode())
if (m_oLightReader.IsEmptyNode())
return;
int nDepth = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nDepth))
while (m_oLightReader.ReadNextSiblingNode(nDepth))
{
std::wstring sName = m_oLightReader.GetName();
// Читаем title-info
if(sName == L"title-info")
if (m_oLightReader.GetName() == L"title-info")
getTitleInfo(m_oTitleInfo, oBuilder);
/*
// Читаем src-title-info (ноль или один)
@ -1101,7 +1082,6 @@ public:
}
*/
// Читает publish-info
/*
void getPublishInfo()
@ -1229,24 +1209,24 @@ public:
// Читает title-info и src-title-info
void getTitleInfo(STitleInfo& oTitleInfo, NSStringUtils::CStringBuilder& oBuilder)
{
if(m_oLightReader.IsEmptyNode())
if (m_oLightReader.IsEmptyNode())
return;
int nDepth = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nDepth))
while (m_oLightReader.ReadNextSiblingNode(nDepth))
{
std::wstring sName = m_oLightReader.GetName();
if(sName == L"annotation")
if (sName == L"annotation")
readAnnotation(oBuilder);
else if(sName == L"coverpage")
else if (sName == L"coverpage")
{
if(m_oLightReader.IsEmptyNode())
if (m_oLightReader.IsEmptyNode())
continue;
int nCDepth = m_oLightReader.GetDepth();
while(m_oLightReader.ReadNextSiblingNode(nCDepth))
while (m_oLightReader.ReadNextSiblingNode(nCDepth))
{
if(m_oLightReader.GetName() == L"image")
if (m_oLightReader.GetName() == L"image")
{
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"image\"/></w:pPr>";
readImage(oBuilder);
@ -1254,11 +1234,11 @@ public:
}
}
}
else if(sName == L"genre")
else if (sName == L"genre")
oTitleInfo.m_arGenres.push_back(content());
else if(sName == L"author")
else if (sName == L"author")
getAuthor(oTitleInfo.m_arAuthors);
else if(sName == L"book-title")
else if (sName == L"book-title")
oTitleInfo.m_sBookTitle = content();
/*
// Читаем keywords (ноль или один)
@ -1320,22 +1300,16 @@ public:
// Возвращает содержание узла
std::wstring content()
{
std::wstring sRes = L"";
if(m_oLightReader.IsEmptyNode())
return sRes;
if(m_oLightReader.ReadNextSiblingNode2(m_oLightReader.GetDepth()))
sRes = m_oLightReader.GetText();
return sRes;
if (!m_oLightReader.IsEmptyNode() && m_oLightReader.ReadNextSiblingNode2(m_oLightReader.GetDepth()))
return m_oLightReader.GetText();
return L"";
}
std::string contentA()
{
std::string sRes = "";
if(m_oLightReader.IsEmptyNode())
return sRes;
if(m_oLightReader.ReadNextSiblingNode2(m_oLightReader.GetDepth()))
sRes = m_oLightReader.GetTextA();
return sRes;
if(!m_oLightReader.IsEmptyNode() && m_oLightReader.ReadNextSiblingNode2(m_oLightReader.GetDepth()))
return m_oLightReader.GetTextA();
return "";
}
};
@ -1419,7 +1393,7 @@ HRESULT CFb2File::Open(const std::wstring& sPath, const std::wstring& sDirectory
else if (sName == L"body")
{
bool bNotes = false;
while(m_internal->m_oLightReader.MoveToNextAttribute())
while (m_internal->m_oLightReader.MoveToNextAttribute())
{
if (m_internal->m_oLightReader.GetName() == L"name" &&
m_internal->m_oLightReader.GetText() == L"notes")
@ -1528,8 +1502,8 @@ HRESULT CFb2File::Open(const std::wstring& sPath, const std::wstring& sDirectory
return S_OK;
}
static void readLi(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector<std::wstring>& arrBinary, bool bUl);
static void readStream(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector<std::wstring>& arrBinary, bool bWasP)
void readLi(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector<std::wstring>& arrBinary, bool bUl);
void readStream(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector<std::wstring>& arrBinary, bool bWasP)
{
int nDeath = oIndexHtml.GetDepth();
if (oIndexHtml.IsEmptyNode() || !oIndexHtml.ReadNextSiblingNode2(nDeath))
@ -1538,9 +1512,7 @@ static void readStream(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteRe
{
std::wstring sName = oIndexHtml.GetName();
if (sName == L"#text")
{
oXml.WriteString(oIndexHtml.GetText());
}
else if (sName == L"p")
{
if (!bWasP)
@ -1700,7 +1672,7 @@ static void readStream(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteRe
} while (oIndexHtml.ReadNextSiblingNode2(nDeath));
}
static void readLi(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector<std::wstring>& arrBinary, bool bUl)
void readLi(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader& oIndexHtml, std::vector<std::wstring>& arrBinary, bool bUl)
{
int nNum = 1;
int nDeath = oIndexHtml.GetDepth();
@ -1719,7 +1691,7 @@ static void readLi(NSStringUtils::CStringBuilder& oXml, XmlUtils::CXmlLiteReader
} while (oIndexHtml.ReadNextSiblingNode2(nDeath));
}
static std::wstring GenerateUUID()
std::wstring GenerateUUID()
{
std::mt19937 oRand(time(0));
std::wstringstream sstream;
@ -1738,9 +1710,8 @@ static std::wstring GenerateUUID()
HRESULT CFb2File::FromHtml(const std::wstring& sSrc, const std::wstring& sDst)
{
NSStringUtils::CStringBuilder oDocument;
oDocument.WriteString(L"<?xml version=\"1.0\" encoding=\"UTF-8\"?><FictionBook xmlns=\"http://www.gribuser.ru/xml/fictionbook/2.0\" xmlns:l=\"http://www.w3.org/1999/xlink\">");
oDocument.WriteString(L"<?xml version=\"1.0\" encoding=\"UTF-8\"?><FictionBook xmlns=\"http://www.gribuser.ru/xml/fictionbook/2.0\" xmlns:l=\"http://www.w3.org/1999/xlink\"><description>");
// description
oDocument.WriteString(L"<description>");
std::wstring sCoreXml;
if (NSFile::CFileBinary::ReadAllTextUtf8(sSrc + L"/docx_unpacked/docProps/core.xml", sCoreXml))
{
@ -1771,29 +1742,26 @@ HRESULT CFb2File::FromHtml(const std::wstring& sSrc, const std::wstring& sDst)
}
}
oDocument.WriteString(L"<genre>dramaturgy</genre>");
oDocument.WriteString(L"<author><nickname>" + sAuthor + L"</nickname></author>");
oDocument.WriteString(L"<book-title>" + sBookTitle + L"</book-title>");
oDocument.WriteString(L"<genre>dramaturgy</genre><author><nickname>");
oDocument.WriteString(sAuthor);
oDocument.WriteString(L"</nickname></author><book-title>");
oDocument.WriteString(sBookTitle);
oDocument.WriteString(L"</book-title>");
if (!sAnnotation.empty())
oDocument.WriteString(L"<annotation><p>" + sAnnotation + L"</p></annotation>");
if (!sKeywords.empty())
oDocument.WriteString(L"<keywords>" + sKeywords + L"</keywords>");
oDocument.WriteString(L"<lang>en</lang>");
oDocument.WriteString(L"</title-info>");
oDocument.WriteString(L"<lang>en</lang></title-info><document-info><author><nickname>");
// document-info
oDocument.WriteString(L"<document-info>");
oDocument.WriteString(L"<author><nickname>" + sAuthor + L"</nickname></author>");
oDocument.WriteString(L"<date></date>");
oDocument.WriteString(L"<id>" + GenerateUUID() + L"</id>");
oDocument.WriteString(L"<version>1.0</version>");
oDocument.WriteString(L"</document-info>");
oDocument.WriteString(sAuthor);
oDocument.WriteString(L"</nickname></author><date></date><id>");
oDocument.WriteString(GenerateUUID());
oDocument.WriteString(L"</id><version>1.0</version></document-info>");
}
oDocument.WriteString(L"</description>");
// body
oDocument.WriteString(L"<body><section>");
oDocument.WriteString(L"</description><body><section>");
std::string sContent;
NSFile::CFileBinary::ReadAllTextUtf8A(sSrc + L"/doct_unpacked/index.html", sContent);
NSFile::CFileBinary::ReadAllTextUtf8A(sSrc + L"/doct_unpacked/index.html", sContent);;
XmlUtils::CXmlLiteReader oIndexHtml;
std::vector<std::wstring> arrBinary;
if (oIndexHtml.FromString(htmlToXhtml(sContent)))