mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-20 01:04:34 +08:00
code optimization
This commit is contained in:
@ -95,6 +95,7 @@ struct STitleInfo
|
||||
};
|
||||
|
||||
// Описание информации о fb2-документе. Тэг document-info
|
||||
/*
|
||||
struct SDocumentInfo
|
||||
{
|
||||
std::vector<SAuthor> m_arAuthors; // Авторы
|
||||
@ -125,8 +126,10 @@ struct SDocumentInfo
|
||||
RELEASEARRAYOBJECTS(m_pHistory);
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
// Информация о бумажном издании. Тэг publish-info
|
||||
/*
|
||||
struct SPublishInfo
|
||||
{
|
||||
std::wstring* m_pBookName; // Название
|
||||
@ -157,33 +160,33 @@ struct SPublishInfo
|
||||
RELEASEARRAYOBJECTS(m_pIsbn);
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
class CFb2File_Private
|
||||
{
|
||||
public:
|
||||
XmlUtils::CXmlLiteReader m_oLightReader; // SAX Reader
|
||||
STitleInfo m_oTitleInfo; // Данные о книге
|
||||
SDocumentInfo m_oDocumentInfo; // Информация об fb2-документе
|
||||
std::wstring m_sTmpFolder; // Рабочая папка
|
||||
// SDocumentInfo m_oDocumentInfo; // Информация об fb2-документе
|
||||
// std::wstring m_sTmpFolder; // Рабочая папка
|
||||
|
||||
int m_nContentsId; // ID содержания
|
||||
int m_nCrossReferenceId; // ID перекрестной ссылки
|
||||
|
||||
STitleInfo* m_pSrcTitleInfo; // Данные об исходнике книги
|
||||
SPublishInfo* m_pPublishInfo; // Сведения об издании книги
|
||||
// STitleInfo* m_pSrcTitleInfo; // Данные об исходнике книги
|
||||
// SPublishInfo* m_pPublishInfo; // Сведения об издании книги
|
||||
|
||||
std::map<std::wstring, std::wstring> m_mFootnotes; // Сноски
|
||||
std::map<std::wstring, std::vector<std::wstring>> m_mImages; // Картинки
|
||||
std::map<std::wstring, std::wstring> m_mCustomInfo; // Произвольная информация
|
||||
// std::map<std::wstring, std::wstring> m_mCustomInfo; // Произвольная информация
|
||||
|
||||
public:
|
||||
CFb2File_Private()
|
||||
{
|
||||
m_pSrcTitleInfo = NULL;
|
||||
m_pPublishInfo = NULL;
|
||||
// m_pSrcTitleInfo = NULL;
|
||||
// m_pPublishInfo = NULL;
|
||||
m_nContentsId = 1;
|
||||
m_nCrossReferenceId = 1;
|
||||
m_sTmpFolder = L"";
|
||||
}
|
||||
|
||||
~CFb2File_Private()
|
||||
@ -191,11 +194,13 @@ public:
|
||||
m_oLightReader.Clear();
|
||||
m_mFootnotes.clear();
|
||||
m_mImages.clear();
|
||||
/*
|
||||
m_mCustomInfo.clear();
|
||||
if(m_pSrcTitleInfo)
|
||||
delete m_pSrcTitleInfo;
|
||||
if(m_pPublishInfo)
|
||||
delete m_pPublishInfo;
|
||||
*/
|
||||
}
|
||||
|
||||
// wrapper для чтения из файла
|
||||
@ -206,12 +211,12 @@ public:
|
||||
return m_oLightReader.FromStringA(sFileContentUtf8);
|
||||
}
|
||||
|
||||
// Читает и проверят соответствует ли текущий раздел ожиданиям
|
||||
bool isSection(const std::wstring& sName)
|
||||
// Проверяет наличие тэга FictionBook
|
||||
bool isFictionBook()
|
||||
{
|
||||
if(!m_oLightReader.ReadNextNode())
|
||||
return false;
|
||||
if(m_oLightReader.GetName() != sName)
|
||||
if(m_oLightReader.GetName() != L"FictionBook")
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@ -256,7 +261,11 @@ public:
|
||||
std::wstring sName = m_oLightReader.GetName();
|
||||
size_t nLen = (sName.length() > 4 ? sName.length() - 4 : 0);
|
||||
if(sName.substr(nLen) == L"href")
|
||||
sImageName = m_oLightReader.GetText().substr(1);
|
||||
{
|
||||
std::wstring sText = m_oLightReader.GetText();
|
||||
if(sText.length() > 1)
|
||||
sImageName = sText.substr(1);
|
||||
}
|
||||
}
|
||||
m_oLightReader.MoveToElement();
|
||||
|
||||
@ -266,41 +275,33 @@ public:
|
||||
if(it != m_mImages.end())
|
||||
{
|
||||
// Пишем картинку в файл
|
||||
oBuilder += L"<w:r><w:drawing><wp:inline distT=\"0\" distB=\"0\" distL=\"0\" distR=\"0\">";
|
||||
// extent
|
||||
oBuilder += L"<wp:extent cx=\"";
|
||||
oBuilder += L"<w:r><w:drawing><wp:inline distT=\"0\" distB=\"0\" distL=\"0\" distR=\"0\"><wp:extent cx=\"";
|
||||
oBuilder += it->second[1];
|
||||
oBuilder += L"\" cy=\"";
|
||||
oBuilder += it->second[2];
|
||||
oBuilder += L"\"/>";
|
||||
// docPr
|
||||
oBuilder += L"<wp:docPr id=\"";
|
||||
oBuilder += L"\"/><wp:docPr id=\"";
|
||||
oBuilder += it->second[0];
|
||||
oBuilder += L"\" name=\"\"/>";
|
||||
// graphic
|
||||
oBuilder += L"<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"><a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\"><pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">";
|
||||
// pic:nvPicPr
|
||||
oBuilder += L"<pic:nvPicPr><pic:cNvPr id=\"";
|
||||
oBuilder += L"\" name=\"\"/><a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"><a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\"><pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\"><pic:nvPicPr><pic:cNvPr id=\"";
|
||||
oBuilder += it->second[0];
|
||||
oBuilder += L"\" name=\"\"/><pic:cNvPicPr></pic:cNvPicPr></pic:nvPicPr>";
|
||||
// pic:blipFill
|
||||
// рельсы rPic + id
|
||||
oBuilder += L"<pic:blipFill><a:blip r:embed=\"rPic";
|
||||
oBuilder += L"\" name=\"\"/><pic:cNvPicPr></pic:cNvPicPr></pic:nvPicPr><pic:blipFill><a:blip r:embed=\"rPic";
|
||||
oBuilder += it->second[0];
|
||||
oBuilder += L"\"/><a:stretch/></pic:blipFill>";
|
||||
// pic:spPr
|
||||
oBuilder += L"<pic:spPr bwMode=\"auto\"><a:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\"";
|
||||
oBuilder += L"\"/><a:stretch/></pic:blipFill><pic:spPr bwMode=\"auto\"><a:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\"";
|
||||
oBuilder += it->second[1];
|
||||
oBuilder += L"\" cy=\"";
|
||||
oBuilder += it->second[2];
|
||||
oBuilder += L"\"/></a:xfrm><a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom></pic:spPr>";
|
||||
// Конец записи
|
||||
oBuilder += L"</pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing></w:r>";
|
||||
oBuilder += L"\"/></a:xfrm><a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing></w:r>";
|
||||
}
|
||||
}
|
||||
|
||||
// Читает title
|
||||
// имеет право писать p
|
||||
void readTitle(std::wstring sLevel, NSStringUtils::CStringBuilder& oBuilder)
|
||||
{
|
||||
if(m_oLightReader.IsEmptyNode())
|
||||
@ -349,7 +350,6 @@ public:
|
||||
}
|
||||
|
||||
// Читает epigraph
|
||||
// имеет право писать p
|
||||
void readEpigraph(NSStringUtils::CStringBuilder& oBuilder)
|
||||
{
|
||||
readCrossReference(oBuilder);
|
||||
@ -373,6 +373,7 @@ public:
|
||||
readCite(oBuilder);
|
||||
else if(sName == L"empty-line")
|
||||
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"epigraph-p\"/></w:pPr></w:p>";
|
||||
// Автор эпиграфа выделяется полужирным
|
||||
else if(sName == L"text-author")
|
||||
{
|
||||
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"epigraph-p\"/></w:pPr>";
|
||||
@ -399,13 +400,11 @@ public:
|
||||
// Читаем обычный текст
|
||||
if(sName == L"#text")
|
||||
{
|
||||
oBuilder += L"<w:r>";
|
||||
// Стиль текста
|
||||
oBuilder += L"<w:rPr>";
|
||||
oBuilder += L"<w:r><w:rPr>";
|
||||
oBuilder += sRStyle;
|
||||
oBuilder += L"</w:rPr>";
|
||||
// Сам текст
|
||||
oBuilder += L"<w:t xml:space=\"preserve\">";
|
||||
oBuilder += L"</w:rPr><w:t xml:space=\"preserve\">";
|
||||
oBuilder.WriteEncodeXmlString(m_oLightReader.GetText());
|
||||
oBuilder += L"</w:t></w:r>";
|
||||
|
||||
@ -430,7 +429,9 @@ public:
|
||||
size_t nLen = (sTName.length() > 4 ? sTName.length() - 4 : 0);
|
||||
if(sTName.substr(nLen) == L"href")
|
||||
{
|
||||
sFootnoteName = m_oLightReader.GetText().substr(1);
|
||||
std::wstring sText = m_oLightReader.GetText();
|
||||
if(sText.length() > 1)
|
||||
sFootnoteName = sText.substr(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -478,7 +479,6 @@ public:
|
||||
}
|
||||
|
||||
// Читает poem
|
||||
// имеет право писать p
|
||||
void readPoem(NSStringUtils::CStringBuilder& oBuilder)
|
||||
{
|
||||
readCrossReference(oBuilder);
|
||||
@ -490,13 +490,10 @@ public:
|
||||
while(m_oLightReader.ReadNextSiblingNode(nDeath))
|
||||
{
|
||||
std::wstring sName = m_oLightReader.GetName();
|
||||
// Читаем title (ноль или один)
|
||||
if(sName == L"title")
|
||||
readTitle(L"title4", oBuilder);
|
||||
// Читаем epigraph (любое)
|
||||
else if(sName == L"epigraph")
|
||||
readEpigraph(oBuilder);
|
||||
// Читаем stanza (один или более)
|
||||
else if(sName == L"stanza")
|
||||
{
|
||||
if(m_oLightReader.IsEmptyNode())
|
||||
@ -506,11 +503,8 @@ public:
|
||||
while(m_oLightReader.ReadNextSiblingNode(nSDeath))
|
||||
{
|
||||
std::wstring sSName = m_oLightReader.GetName();
|
||||
// Читаем title (ноль или один)
|
||||
if(sSName == L"title")
|
||||
readTitle(L"title5", oBuilder);
|
||||
// Читаем subtitle (ноль или один)
|
||||
// Читаем v (один или более)
|
||||
else if(sSName == L"v" || sSName == L"subtitle")
|
||||
{
|
||||
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"v-stanza\"/></w:pPr>";
|
||||
@ -519,14 +513,13 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
// Читаем text-author (любое)
|
||||
// Автор поэмы выделяется полужирным
|
||||
else if(sName == L"text-author")
|
||||
{
|
||||
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"v-stanza\"/></w:pPr>";
|
||||
readP(L"<w:b/>", oBuilder);
|
||||
oBuilder += L"</w:p>";
|
||||
}
|
||||
// Читаем date (ноль или один)
|
||||
else if(sName == L"date")
|
||||
{
|
||||
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"v-stanza\"/></w:pPr><w:r><w:t>";
|
||||
@ -537,7 +530,6 @@ public:
|
||||
}
|
||||
|
||||
// Читает cite
|
||||
// имеет право писать p
|
||||
void readCite(NSStringUtils::CStringBuilder& oBuilder)
|
||||
{
|
||||
readCrossReference(oBuilder);
|
||||
@ -561,6 +553,7 @@ public:
|
||||
readPoem(oBuilder);
|
||||
else if(sName == L"table")
|
||||
readTable(oBuilder);
|
||||
// Автор цитаты выделяется полужирным
|
||||
else if(sName == L"text-author")
|
||||
{
|
||||
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"cite-p\"/></w:pPr>";
|
||||
@ -586,6 +579,7 @@ public:
|
||||
int nDeath = m_oLightReader.GetDepth();
|
||||
while(m_oLightReader.ReadNextSiblingNode(nDeath))
|
||||
{
|
||||
// tr - строки в таблице
|
||||
if(m_oLightReader.GetName() == L"tr")
|
||||
{
|
||||
if(m_oLightReader.IsEmptyNode())
|
||||
@ -597,8 +591,7 @@ public:
|
||||
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 (любое)
|
||||
// Читаем th. Ячейка заголовка таблицы. Выравнивание посередине. Выделяется полужирным
|
||||
if(m_oLightReader.GetName() == L"th")
|
||||
{
|
||||
if(++nTCol > nGridCol)
|
||||
@ -606,7 +599,7 @@ public:
|
||||
oTmpBuilder += L"<w:pPr><w:jc w:val=\"center\"/></w:pPr>";
|
||||
readP(L"<w:b/>", oTmpBuilder);
|
||||
}
|
||||
// Читаем td (любое)
|
||||
// Читаем td. Ячейка таблицы. Выравнивание вправо
|
||||
else if(m_oLightReader.GetName() == L"td")
|
||||
{
|
||||
if(++nTCol > nGridCol)
|
||||
@ -634,12 +627,11 @@ public:
|
||||
// Конец таблицы
|
||||
oBuilder += oTmpBuilder.GetData();
|
||||
oBuilder += L"</w:tbl>";
|
||||
// Пустая строка после таблицы
|
||||
// Пустая строка после таблицы, чтобы следующий текст не приклеивался
|
||||
oBuilder += L"<w:p></w:p>";
|
||||
}
|
||||
|
||||
// Читает annotation
|
||||
// имеет право писать p
|
||||
void readAnnotation(NSStringUtils::CStringBuilder& oBuilder)
|
||||
{
|
||||
readCrossReference(oBuilder);
|
||||
@ -691,7 +683,6 @@ public:
|
||||
}
|
||||
|
||||
// Читает section
|
||||
// имеет право писать p
|
||||
void readSection(unsigned int nLevel, NSStringUtils::CStringBuilder& oBuilder)
|
||||
{
|
||||
readCrossReference(oBuilder);
|
||||
@ -703,41 +694,33 @@ public:
|
||||
while(m_oLightReader.ReadNextSiblingNode(nDeath))
|
||||
{
|
||||
std::wstring sName = m_oLightReader.GetName();
|
||||
// Читаем title (ноль или один)
|
||||
if(sName == L"title")
|
||||
{
|
||||
std::wstring sTitle = L"";
|
||||
std::wstring sTitle = L"section-p";
|
||||
if(nLevel < 10)
|
||||
sTitle = L"title" + std::to_wstring(nLevel);
|
||||
readTitle(sTitle, oBuilder);
|
||||
}
|
||||
// Читаем epigraph (любое)
|
||||
else if(sName == L"epigraph")
|
||||
readEpigraph(oBuilder);
|
||||
// Читаем 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>";
|
||||
}
|
||||
// Читаем annotation (ноль или один)
|
||||
else if(sName == L"annotation")
|
||||
readAnnotation(oBuilder);
|
||||
// Читаем вложенные section (любое)
|
||||
else if(sName == L"section")
|
||||
readSection(nLevel + 1, oBuilder);
|
||||
// Читаем произвольный набор
|
||||
else if(sName == L"p")
|
||||
{
|
||||
// Стиль section-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")
|
||||
{
|
||||
// Стиль section-subtitle
|
||||
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"section-subtitle\"/></w:pPr>";
|
||||
readP(L"", oBuilder);
|
||||
oBuilder += L"</w:p>";
|
||||
@ -754,7 +737,6 @@ public:
|
||||
}
|
||||
|
||||
// Читает body
|
||||
// имеет право писать p
|
||||
void readBody(NSStringUtils::CStringBuilder& oBuilder)
|
||||
{
|
||||
if(m_oLightReader.IsEmptyNode())
|
||||
@ -764,21 +746,16 @@ public:
|
||||
while(m_oLightReader.ReadNextSiblingNode(nDeath))
|
||||
{
|
||||
std::wstring sName = m_oLightReader.GetName();
|
||||
// Читаем image (ноль или один)
|
||||
if(sName == L"image")
|
||||
{
|
||||
oBuilder += L"<w:p><w:pPr><w:pStyle w:val=\"image\"/></w:pPr>";
|
||||
readImage(oBuilder);
|
||||
oBuilder += L"</w:p>";
|
||||
}
|
||||
// Читаем title (ноль или один)
|
||||
// 0 - заголовок книги
|
||||
else if(sName == L"title")
|
||||
readTitle(L"title", oBuilder);
|
||||
// Читаем epigraph (любое)
|
||||
else if(sName == L"epigraph")
|
||||
readEpigraph(oBuilder);
|
||||
// Читаем section (один или более)
|
||||
else if(sName == L"section")
|
||||
readSection(1, oBuilder);
|
||||
}
|
||||
@ -793,7 +770,7 @@ public:
|
||||
if (!OpenFromFile(sPath))
|
||||
return false;
|
||||
// Читаем FictionBook
|
||||
if(!isSection(L"FictionBook"))
|
||||
if(!isFictionBook())
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -845,7 +822,7 @@ public:
|
||||
if(m_oLightReader.IsEmptyNode())
|
||||
return;
|
||||
|
||||
bool bFirstP = true;
|
||||
bool bFirstTitle = true;
|
||||
int nBDeath = m_oLightReader.GetDepth();
|
||||
while(m_oLightReader.ReadNextSiblingNode(nBDeath))
|
||||
{
|
||||
@ -868,13 +845,13 @@ public:
|
||||
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(bFirstP)
|
||||
if(bFirstTitle)
|
||||
oContents += L"<w:pageBreakBefore/>";
|
||||
oContents += L"</w:pPr>";
|
||||
if(bFirstP)
|
||||
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>";
|
||||
bFirstP = false;
|
||||
bFirstTitle = false;
|
||||
}
|
||||
oContents += L"<w:hyperlink w:tooltip=\"Current Document\" w:anchor=\"_Toc";
|
||||
oContents += sContentsId;
|
||||
@ -883,18 +860,19 @@ public:
|
||||
int nTDeath = m_oLightReader.GetDepth();
|
||||
while(m_oLightReader.ReadNextSiblingNode(nTDeath))
|
||||
{
|
||||
// Читаем p
|
||||
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:r><w:t xml:space=\"preserve\"> </w:t></w:r>";
|
||||
}
|
||||
}
|
||||
oContents += L"</w:hyperlink></w:p>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!bFirstP)
|
||||
if(!bFirstTitle)
|
||||
oContents += L"<w:p><w:r><w:fldChar w:fldCharType=\"end\"/></w:r></w:p>";
|
||||
}
|
||||
|
||||
@ -907,7 +885,6 @@ public:
|
||||
int nBDepth = m_oLightReader.GetDepth();
|
||||
while(m_oLightReader.ReadNextSiblingNode(nBDepth))
|
||||
{
|
||||
// Читаем section (один или более)
|
||||
if(m_oLightReader.GetName() == L"section")
|
||||
{
|
||||
// Читаем id
|
||||
@ -948,9 +925,7 @@ public:
|
||||
{
|
||||
if(m_oLightReader.GetName() == L"p")
|
||||
{
|
||||
// Стиль section-p
|
||||
oFootnotes += L"<w:p><w:pPr><w:pStyle w:val=\"footnote-p\"/></w:pPr>";
|
||||
oFootnotes += L"<w:r><w:rPr><w:rStyle w:val=\"footnote\"/></w:rPr></w:r>";
|
||||
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>";
|
||||
}
|
||||
@ -958,9 +933,7 @@ public:
|
||||
}
|
||||
else if(sName == L"p" || sName == L"subtitle")
|
||||
{
|
||||
// Стиль section-p
|
||||
oFootnotes += L"<w:p><w:pPr><w:pStyle w:val=\"footnote-p\"/></w:pPr>";
|
||||
oFootnotes += L"<w:r><w:rPr><w:rStyle w:val=\"footnote\"/></w:rPr></w:r>";
|
||||
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>";
|
||||
}
|
||||
@ -985,8 +958,7 @@ public:
|
||||
// Читаем v (один или более)
|
||||
if(m_oLightReader.GetName() == L"v")
|
||||
{
|
||||
oFootnotes += L"<w:p><w:pPr><w:pStyle w:val=\"footnote-p\"/></w:pPr>";
|
||||
oFootnotes += L"<w:r><w:rPr><w:rStyle w:val=\"footnote\"/></w:rPr></w:r>";
|
||||
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>";
|
||||
}
|
||||
@ -995,8 +967,7 @@ public:
|
||||
// Читаем text-author (любое)
|
||||
else if(sPName == L"text-author")
|
||||
{
|
||||
oFootnotes += L"<w:p><w:pPr><w:pStyle w:val=\"footnote-p\"/></w:pPr>";
|
||||
oFootnotes += L"<w:r><w:rPr><w:rStyle w:val=\"footnote\"/></w:rPr></w:r>";
|
||||
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>";
|
||||
}
|
||||
@ -1059,13 +1030,10 @@ public:
|
||||
{
|
||||
nW = 7000000;
|
||||
nHy = (int)((double)nHy * (double)nW / (double)nWx);
|
||||
nWx = nW;
|
||||
}
|
||||
else
|
||||
{
|
||||
nWx = nW;
|
||||
nHy = nH;
|
||||
}
|
||||
nWx = nW;
|
||||
}
|
||||
std::vector<std::wstring> vImage;
|
||||
vImage.push_back(sImageId);
|
||||
@ -1119,6 +1087,7 @@ public:
|
||||
}
|
||||
|
||||
// Читает custom-info
|
||||
/*
|
||||
void getCustomInfo()
|
||||
{
|
||||
std::wstring sIntoType = L"";
|
||||
@ -1128,8 +1097,11 @@ public:
|
||||
std::wstring sCustomInfo = content();
|
||||
m_mCustomInfo.insert(std::make_pair(sIntoType, sCustomInfo));
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// Читает publish-info
|
||||
/*
|
||||
void getPublishInfo()
|
||||
{
|
||||
if(m_oLightReader.IsEmptyNode())
|
||||
@ -1196,8 +1168,10 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Читает document-info
|
||||
/*
|
||||
void getDocumentInfo()
|
||||
{
|
||||
if(m_oLightReader.IsEmptyNode())
|
||||
@ -1248,6 +1222,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Читает title-info и src-title-info
|
||||
void getTitleInfo(STitleInfo& oTitleInfo, NSStringUtils::CStringBuilder& oBuilder)
|
||||
@ -1259,16 +1234,13 @@ public:
|
||||
while(m_oLightReader.ReadNextSiblingNode(nDepth))
|
||||
{
|
||||
std::wstring sName = m_oLightReader.GetName();
|
||||
// Читаем annotation (ноль или один)
|
||||
if(sName == L"annotation")
|
||||
readAnnotation(oBuilder);
|
||||
// Читаем coverpage (ноль или один)
|
||||
else if(sName == L"coverpage")
|
||||
{
|
||||
if(m_oLightReader.IsEmptyNode())
|
||||
continue;
|
||||
|
||||
// Читаем image (один или более)
|
||||
int nCDepth = m_oLightReader.GetDepth();
|
||||
while(m_oLightReader.ReadNextSiblingNode(nCDepth))
|
||||
{
|
||||
@ -1280,13 +1252,10 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
// Читаем genre (один или более)
|
||||
else if(sName == L"genre")
|
||||
oTitleInfo.m_arGenres.push_back(content());
|
||||
// Читаем author (один или более)
|
||||
else if(sName == L"author")
|
||||
getAuthor(oTitleInfo.m_arAuthors);
|
||||
// Читаем book-title
|
||||
else if(sName == L"book-title")
|
||||
oTitleInfo.m_sBookTitle = content();
|
||||
/*
|
||||
@ -1385,7 +1354,7 @@ bool CFb2File::IsFb2File(const std::wstring& sFile)
|
||||
if (!m_internal->OpenFromFile(sFile))
|
||||
return false;
|
||||
// Читаем FictionBook
|
||||
if(!m_internal->isSection(L"FictionBook"))
|
||||
if(!m_internal->isFictionBook())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@ -1393,7 +1362,7 @@ bool CFb2File::IsFb2File(const std::wstring& sFile)
|
||||
// Выставление рабочей папки
|
||||
void CFb2File::SetTmpDirectory(const std::wstring& sFolder)
|
||||
{
|
||||
m_internal->m_sTmpFolder = sFolder;
|
||||
// m_internal->m_sTmpFolder = sFolder;
|
||||
}
|
||||
|
||||
// Проверяет, соответствует ли fb2 файл формату
|
||||
@ -1406,15 +1375,12 @@ HRESULT CFb2File::Open(const std::wstring& sPath, const std::wstring& sDirectory
|
||||
|
||||
// Начало файла
|
||||
NSStringUtils::CStringBuilder oDocument;
|
||||
oDocument += L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
|
||||
oDocument += L"<w:document xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" mc:Ignorable=\"w14 w15 wp14\"><w:body>";
|
||||
oDocument += L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:document xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" mc:Ignorable=\"w14 w15 wp14\"><w:body>";
|
||||
|
||||
// Создаем сноски
|
||||
NSStringUtils::CStringBuilder oFootnotes;
|
||||
oFootnotes += L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
|
||||
oFootnotes += L"<w:footnotes xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" mc:Ignorable=\"w14 w15 wp14\">";
|
||||
oFootnotes += L"<w:footnote w:type=\"separator\" w:id=\"-1\"><w:p><w:pPr><w:spacing w:lineRule=\"auto\" w:line=\"240\" w:after=\"0\"/></w:pPr><w:r><w:separator/></w:r></w:p></w:footnote>";
|
||||
oFootnotes += L"<w:footnote w:type=\"continuationSeparator\" w:id=\"0\"><w:p><w:pPr><w:spacing w:lineRule=\"auto\" w:line=\"240\" w:after=\"0\"/></w:pPr><w:r><w:continuationSeparator/></w:r></w:p></w:footnote>";
|
||||
oFootnotes += L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><w:footnotes xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" mc:Ignorable=\"w14 w15 wp14\">";
|
||||
oFootnotes += L"<w:footnote w:type=\"separator\" w:id=\"-1\"><w:p><w:pPr><w:spacing w:lineRule=\"auto\" w:line=\"240\" w:after=\"0\"/></w:pPr><w:r><w:separator/></w:r></w:p></w:footnote><w:footnote w:type=\"continuationSeparator\" w:id=\"0\"><w:p><w:pPr><w:spacing w:lineRule=\"auto\" w:line=\"240\" w:after=\"0\"/></w:pPr><w:r><w:continuationSeparator/></w:r></w:p></w:footnote>";
|
||||
|
||||
// Создаем рельсы
|
||||
NSStringUtils::CStringBuilder oRels;
|
||||
@ -1432,15 +1398,16 @@ HRESULT CFb2File::Open(const std::wstring& sPath, const std::wstring& sDirectory
|
||||
|
||||
NSStringUtils::CStringBuilder oBuilder;
|
||||
NSStringUtils::CStringBuilder oDescription;
|
||||
NSStringUtils::CStringBuilder oContents;
|
||||
|
||||
// Читаем содержание, картинки, сноски
|
||||
bool bNeedContents = false;
|
||||
if(oParams)
|
||||
bNeedContents = oParams->bNeedContents;
|
||||
NSStringUtils::CStringBuilder oContents;
|
||||
if(!m_internal->readText(sPath, sMediaDirectory, oContents, oRels, oFootnotes))
|
||||
return S_FALSE;
|
||||
|
||||
// Переходим в начало
|
||||
if(!m_internal->m_oLightReader.MoveToStart())
|
||||
return S_FALSE;
|
||||
|
||||
@ -1448,10 +1415,8 @@ HRESULT CFb2File::Open(const std::wstring& sPath, const std::wstring& sDirectory
|
||||
while(m_internal->m_oLightReader.ReadNextSiblingNode(nDeath))
|
||||
{
|
||||
std::wstring sName = m_internal->m_oLightReader.GetName();
|
||||
// Читаем description
|
||||
if(sName == L"description")
|
||||
m_internal->readDescription(oDescription);
|
||||
// Читаем body
|
||||
else if(sName == L"body")
|
||||
{
|
||||
bool bNotes = false;
|
||||
@ -1471,9 +1436,8 @@ HRESULT CFb2File::Open(const std::wstring& sPath, const std::wstring& sDirectory
|
||||
// Конец сносок
|
||||
oFootnotes += L"</w:footnotes>";
|
||||
// Пишем сноски в файл
|
||||
std::wstring sFootnotesDirectory = sDirectory + L"/word";
|
||||
NSFile::CFileBinary oFootnotesWriter;
|
||||
if (oFootnotesWriter.CreateFileW(sFootnotesDirectory + L"/footnotes.xml"))
|
||||
if (oFootnotesWriter.CreateFileW(sDirectory + L"/word/footnotes.xml"))
|
||||
{
|
||||
oFootnotesWriter.WriteStringUTF8(oFootnotes.GetData());
|
||||
oFootnotesWriter.CloseFile();
|
||||
@ -1487,8 +1451,7 @@ HRESULT CFb2File::Open(const std::wstring& sPath, const std::wstring& sDirectory
|
||||
// Вставляем основное тело
|
||||
oDocument += oBuilder.GetData();
|
||||
// Конец документа
|
||||
oDocument += L"<w:sectPr><w:footnotePr/><w:type w:val=\"nextPage\"/><w:pgSz w:w=\"11906\" w:h=\"16838\" w:orient=\"portrait\"/><w:pgMar w:top=\"1134\" w:right=\"850\" w:bottom=\"1134\" w:left=\"1701\" w:header=\"709\" w:footer=\"709\" w:gutter=\"0\"/><w:cols w:num=\"1\" w:sep=\"0\" w:space=\"708\" w:equalWidth=\"1\"/><w:docGrid w:linePitch=\"360\"/></w:sectPr></w:body>";
|
||||
oDocument += L"</w:document>";
|
||||
oDocument += L"<w:sectPr><w:footnotePr/><w:type w:val=\"nextPage\"/><w:pgSz w:w=\"11906\" w:h=\"16838\" w:orient=\"portrait\"/><w:pgMar w:top=\"1134\" w:right=\"850\" w:bottom=\"1134\" w:left=\"1701\" w:header=\"709\" w:footer=\"709\" w:gutter=\"0\"/><w:cols w:num=\"1\" w:sep=\"0\" w:space=\"708\" w:equalWidth=\"1\"/><w:docGrid w:linePitch=\"360\"/></w:sectPr></w:body></w:document>";
|
||||
// Пишем документ в файл
|
||||
NSFile::CFileBinary oDocumentXmlWriter;
|
||||
if (oDocumentXmlWriter.CreateFileW(sDirectory + L"/word/document.xml"))
|
||||
@ -1500,9 +1463,8 @@ HRESULT CFb2File::Open(const std::wstring& sPath, const std::wstring& sDirectory
|
||||
// Конец рельсов
|
||||
oRels += L"</Relationships>";
|
||||
// Пишем рельсы в файл
|
||||
std::wstring sRelsDirectory = sDirectory + L"/word/_rels";
|
||||
NSFile::CFileBinary oRelsWriter;
|
||||
if (oRelsWriter.CreateFileW(sRelsDirectory + L"/document.xml.rels"))
|
||||
if (oRelsWriter.CreateFileW(sDirectory + L"/word/_rels/document.xml.rels"))
|
||||
{
|
||||
oRelsWriter.WriteStringUTF8(oRels.GetData());
|
||||
oRelsWriter.CloseFile();
|
||||
@ -1514,22 +1476,17 @@ HRESULT CFb2File::Open(const std::wstring& sPath, const std::wstring& sDirectory
|
||||
|
||||
// Создаем core.xml
|
||||
NSStringUtils::CStringBuilder oCore;
|
||||
oCore += L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
|
||||
oCore += L"<cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:dcmitype=\"http://purl.org/dc/dcmitype/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">";
|
||||
// Заголовок
|
||||
oCore += L"<dc:title>";
|
||||
oCore += L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:dcmitype=\"http://purl.org/dc/dcmitype/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><dc:title>";
|
||||
oCore.WriteEncodeXmlString(m_internal->m_oTitleInfo.m_sBookTitle);
|
||||
oCore += L"</dc:title>";
|
||||
// Жанры
|
||||
oCore += L"<dc:subject>";
|
||||
oCore += L"</dc:title><dc:subject>";
|
||||
oCore.WriteEncodeXmlString(m_internal->m_oTitleInfo.getGenres());
|
||||
oCore += L"</dc:subject>";
|
||||
// Авторы
|
||||
oCore += L"<dc:creator>";
|
||||
oCore += L"</dc:subject><dc:creator>";
|
||||
oCore.WriteEncodeXmlString(m_internal->m_oTitleInfo.getAuthors());
|
||||
oCore += L"</dc:creator>";
|
||||
// Конец core
|
||||
oCore += L"<cp:revision>1</cp:revision></cp:coreProperties>";
|
||||
oCore += L"</dc:creator><cp:revision>1</cp:revision></cp:coreProperties>";
|
||||
// Пишем core в файл
|
||||
NSFile::CFileBinary oCoreWriter;
|
||||
if (oCoreWriter.CreateFileW(sDocPropsDirectory + L"/core.xml"))
|
||||
@ -1549,13 +1506,9 @@ HRESULT CFb2File::Open(const std::wstring& sPath, const std::wstring& sDirectory
|
||||
sApplication += UTF8_TO_U(sVersion);
|
||||
// Создаем app.xml
|
||||
NSStringUtils::CStringBuilder oApp;
|
||||
oApp += L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
|
||||
oApp += L"<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\">";
|
||||
oApp += L"<Application>";
|
||||
oApp += L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\"><Application>";
|
||||
oApp += sApplication;
|
||||
oApp += L"</Application>";
|
||||
oApp += L"<Characters>0</Characters><CharactersWithSpaces>0</CharactersWithSpaces><DocSecurity>0</DocSecurity><HyperlinksChanged>false</HyperlinksChanged><Lines>1</Lines><LinksUpToDate>false</LinksUpToDate><Pages>1</Pages><Paragraphs>1</Paragraphs><ScaleCrop>false</ScaleCrop><SharedDoc>false</SharedDoc><TotalTime>1</TotalTime><Words>0</Words>";
|
||||
oApp += L"</Properties>";
|
||||
oApp += L"</Application><Characters>0</Characters><CharactersWithSpaces>0</CharactersWithSpaces><DocSecurity>0</DocSecurity><HyperlinksChanged>false</HyperlinksChanged><Lines>1</Lines><LinksUpToDate>false</LinksUpToDate><Pages>1</Pages><Paragraphs>1</Paragraphs><ScaleCrop>false</ScaleCrop><SharedDoc>false</SharedDoc><TotalTime>1</TotalTime><Words>0</Words></Properties>";
|
||||
// Пишем app в файл
|
||||
NSFile::CFileBinary oAppWriter;
|
||||
if (oAppWriter.CreateFileW(sDocPropsDirectory + L"/app.xml"))
|
||||
@ -1574,6 +1527,5 @@ HRESULT CFb2File::Open(const std::wstring& sPath, const std::wstring& sDirectory
|
||||
HRESULT oRes = oZip.CompressFileOrDirectory(sDirectory, sDirectory + L"/" + NSFile::GetFileName(sPath) + L".docx");
|
||||
return oRes;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user