template and compress to docx

This commit is contained in:
Куликова Светлана Александровна
2020-07-10 11:53:21 +03:00
parent b4830f457d
commit 295a3e1a7e
22 changed files with 50169 additions and 12 deletions

View File

@ -4,6 +4,7 @@
#include "../DesktopEditor/common/File.h"
#include "../DesktopEditor/common/Directory.h"
#include "../DesktopEditor/common/StringBuilder.h"
#include "../OfficeUtils/src/OfficeUtils.h"
#include <vector>
#include <map>
@ -1255,9 +1256,14 @@ void CFb2File::SetTmpDirectory(const std::wstring& sFolder)
}
// Проверяет, соответствует ли fb2 файл формату
// sPath - путь к сохраненному файлу, sDirectory - путь к сохраненным картинкам
int CFb2File::Convert(const std::wstring& sPath, const std::wstring& sDirectory)
// sPath - путь к файлу fb2, sDirectory - директория, где формируется и создается docx
int CFb2File::Convert(const std::wstring& sPath, const std::wstring& sDirectory, bool bNeedDocx)
{
// Копирование шаблона
// КОСТЫЛЬ
std::wstring sTemplate = sDirectory + L"/../../../../template/";
NSDirectory::CopyDirectory(sTemplate, sDirectory);
// Начало файла
m_internal->m_oBuilder += 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\">";
@ -1327,7 +1333,7 @@ int CFb2File::Convert(const std::wstring& sPath, const std::wstring& sDirectory)
oRels += L"<Relationship Id=\"rId6\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes\" Target=\"footnotes.xml\"/>";
// Читает картинки
std::wstring sMediaDirectory = sDirectory + L"/media";
std::wstring sMediaDirectory = sDirectory + L"/word/media";
NSDirectory::CreateDirectory(sMediaDirectory);
do
{
@ -1389,7 +1395,7 @@ int CFb2File::Convert(const std::wstring& sPath, const std::wstring& sDirectory)
// Конец файла рельсов
oRels += L"</Relationships>";
// Пишем рельсы в файл
std::wstring sRelsDirectory = sDirectory + L"/_rels";
std::wstring sRelsDirectory = sDirectory + L"/word/_rels";
NSFile::CFileBinary oRelsWriter;
if (!oRelsWriter.CreateFileW(sRelsDirectory + L"/document.xml.rels"))
return false;
@ -1398,10 +1404,19 @@ int CFb2File::Convert(const std::wstring& sPath, const std::wstring& sDirectory)
// Создаем файл для записи
NSFile::CFileBinary oDocumentXmlWriter;
if (!oDocumentXmlWriter.CreateFileW(sDirectory + L"/document.xml"))
if (!oDocumentXmlWriter.CreateFileW(sDirectory + L"/word/document.xml"))
return false;
oDocumentXmlWriter.WriteStringUTF8(m_internal->m_oBuilder.GetData());
oDocumentXmlWriter.CloseFile();
// Архивим в docx
if(bNeedDocx)
{
COfficeUtils oZip;
HRESULT oRes = oZip.CompressFileOrDirectory(sDirectory, sDirectory + L"/res.docx");
if(oRes == S_FALSE)
return false;
}
return TRUE;
}

View File

@ -21,7 +21,7 @@ public:
bool IsFb2File(const std::wstring& sFile);
void SetTmpDirectory(const std::wstring& sFolder);
int Convert(const std::wstring& sPath, const std::wstring& sDirectory);
int Convert(const std::wstring& sPath, const std::wstring& sDirectory, bool bNeedDocx = false);
};
#endif // _FB2FILE_FB2FILE_H

View File

@ -16,7 +16,7 @@ CORE_ROOT_DIR = $$PWD/../../core
PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
ADD_DEPENDENCY(kernel)
ADD_DEPENDENCY(kernel, OfficeUtils)
SOURCES += Fb2File.cpp

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="jpg" ContentType="image/jpeg"/>
<Default Extension="png" ContentType="image/png"/>
<Default Extension="jpeg" ContentType="image/jpeg"/>
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="bin" ContentType="application/vnd.openxmlformats-officedocument.oleObject"/>
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
<Override PartName="/word/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>
<Override PartName="/word/fontTable.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"/>
<Override PartName="/word/webSettings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"/>
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
<Override PartName="/word/settings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"/>
<Override PartName="/word/footnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"/>
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
</Types>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
</Relationships>

View File

@ -0,0 +1 @@
<?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>ONLYOFFICE/5.5.1.78</Application><Company>SPecialiST RePack</Company><DocSecurity>0</DocSecurity><HyperlinksChanged>false</HyperlinksChanged><LinksUpToDate>false</LinksUpToDate><ScaleCrop>false</ScaleCrop><SharedDoc>false</SharedDoc><Template>Normal.dotm</Template></Properties>

View File

@ -0,0 +1,7 @@
<?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:creator/>
<cp:revision>1</cp:revision>
<dcterms:created xsi:type="dcterms:W3CDTF">2020-07-07T14:24:00Z</dcterms:created>
<dcterms:modified xsi:type="dcterms:W3CDTF">2020-07-08T12:47:15Z</dcterms:modified>
</cp:coreProperties>

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:fonts xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" 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" mc:Ignorable="w14 w15">
<w:font w:name="Times New Roman">
<w:panose1 w:val="02020603050405020304"/>
</w:font>
<w:font w:name="Arial">
<w:panose1 w:val="020B0604020202020204"/>
</w:font>
<w:font w:name="Calibri">
<w:panose1 w:val="020F0502020204030204"/>
</w:font>
<w:font w:name="Cambria">
<w:panose1 w:val="02040503050406030204"/>
</w:font>
</w:fonts>

View File

@ -0,0 +1,25 @@
<?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">
<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: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:r/>
</w:p>
</w:footnote>
</w:footnotes>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:settings xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml">
<w:clrSchemeMapping w:accent1="accent1" w:accent2="accent2" w:accent3="accent3" w:accent4="accent4" w:accent5="accent5" w:accent6="accent6" w:bg1="light1" w:bg2="light2" w:followedHyperlink="followedHyperlink" w:hyperlink="hyperlink" w:t1="dark1" w:t2="dark2"/>
<w:defaultTabStop w:val="708"/>
<m:mathPr/>
<w:trackRevisions w:val="false"/>
<w:footnotePr>
<w:footnote w:id="-1"/>
<w:footnote w:id="0"/>
<w:numFmt w:val="decimal"/>
<w:numRestart w:val="continuous"/>
<w:numStart w:val="1"/>
<w:pos w:val="pageBottom"/>
</w:footnotePr>
<w:decimalSymbol w:val=","/>
<w:listSeparator w:val=";"/>
<w:compat>
<w:compatSetting w:name="compatibilityMode" w:uri="http://schemas.microsoft.com/office/word" w:val="14"/>
<w:compatSetting w:name="overrideTableStyleFontSizeAndJustification" w:uri="http://schemas.microsoft.com/office/word" w:val="1"/>
<w:compatSetting w:name="enableOpenTypeFeatures" w:uri="http://schemas.microsoft.com/office/word" w:val="1"/>
<w:compatSetting w:name="doNotFlipMirrorIndents" w:uri="http://schemas.microsoft.com/office/word" w:val="1"/>
</w:compat>
<w:zoom w:percent="100"/>
<w:characterSpacingControl w:val="doNotCompress"/>
<w:themeFontLang w:val="en-US" w:eastAsia="zh-CN"/>
<w:shapeDefaults>
<o:shapedefaults v:ext="edit" spidmax="1026"/>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1"/>
</o:shapelayout>
</w:shapeDefaults>
</w:settings>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" name="Office Theme"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000"></a:sysClr></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"></a:sysClr></a:lt1><a:dk2><a:srgbClr val="44546A"></a:srgbClr></a:dk2><a:lt2><a:srgbClr val="E7E6E6"></a:srgbClr></a:lt2><a:accent1><a:srgbClr val="5B9BD5"></a:srgbClr></a:accent1><a:accent2><a:srgbClr val="ED7D31"></a:srgbClr></a:accent2><a:accent3><a:srgbClr val="A5A5A5"></a:srgbClr></a:accent3><a:accent4><a:srgbClr val="FFC000"></a:srgbClr></a:accent4><a:accent5><a:srgbClr val="4472C4"></a:srgbClr></a:accent5><a:accent6><a:srgbClr val="70AD47"></a:srgbClr></a:accent6><a:hlink><a:srgbClr val="0563C1"></a:srgbClr></a:hlink><a:folHlink><a:srgbClr val="954F72"></a:srgbClr></a:folHlink></a:clrScheme><a:fontScheme name="Office Classic 2"><a:majorFont><a:latin typeface="Arial"></a:latin><a:ea typeface="Arial"></a:ea><a:cs typeface="Arial"></a:cs></a:majorFont><a:minorFont><a:latin typeface="Arial"></a:latin><a:ea typeface="Arial"></a:ea><a:cs typeface="Arial"></a:cs></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"></a:schemeClr></a:solidFill><a:gradFill><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"></a:tint><a:satMod val="300000"></a:satMod></a:schemeClr></a:gs><a:gs pos="35000"><a:schemeClr val="phClr"><a:tint val="37000"></a:tint><a:satMod val="300000"></a:satMod></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="15000"></a:tint><a:satMod val="350000"></a:satMod></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000" scaled="1"></a:lin></a:gradFill><a:gradFill><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:shade val="51000"></a:shade><a:satMod val="130000"></a:satMod></a:schemeClr></a:gs><a:gs pos="80000"><a:schemeClr val="phClr"><a:shade val="93000"></a:shade><a:satMod val="130000"></a:satMod></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="94000"></a:shade><a:satMod val="135000"></a:satMod></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000" scaled="0"></a:lin></a:gradFill></a:fillStyleLst><a:lnStyleLst><a:ln w="6350" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"><a:shade val="95000"></a:shade><a:satMod val="105000"></a:satMod></a:schemeClr></a:solidFill></a:ln><a:ln w="12700" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"></a:schemeClr></a:solidFill></a:ln><a:ln w="19050" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"></a:schemeClr></a:solidFill></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="20000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="38000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"></a:schemeClr></a:solidFill><a:gradFill><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"></a:tint><a:satMod val="350000"></a:satMod></a:schemeClr></a:gs><a:gs pos="40000"><a:schemeClr val="phClr"><a:tint val="45000"></a:tint><a:shade val="99000"></a:shade><a:satMod val="350000"></a:satMod></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="20000"></a:shade><a:satMod val="255000"></a:satMod></a:schemeClr></a:gs></a:gsLst><a:path path="circle"></a:path></a:gradFill><a:gradFill><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"></a:tint><a:satMod val="300000"></a:satMod></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="30000"></a:shade><a:satMod val="200000"></a:satMod></a:schemeClr></a:gs></a:gsLst><a:path path="circle"></a:path></a:gradFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements><a:objectDefaults></a:objectDefaults></a:theme>

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <w:webSettings xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> <w:optimizeForBrowser/> </w:webSettings>

View File

@ -6,16 +6,14 @@
int main()
{
setlocale(LC_ALL, "Russian");
CFb2File oFile;
oFile.SetTmpDirectory(NSFile::GetProcessDirectory() + L"/tmp");
// файл, который открываем
std::wstring sFile = NSFile::GetProcessDirectory() + L"/../../../examples/1-posledneye-zhelaniye.fb2";
std::wstring sFile = NSFile::GetProcessDirectory() + L"/../../../examples/8-sezon-groz.fb2";
// директория, где будем создавать docx
std::wstring sOutputDirectory = NSFile::GetProcessDirectory() + L"/word";
std::wstring sOutputDirectory = NSFile::GetProcessDirectory() + L"/res";
if (!NSDirectory::Exists(sOutputDirectory))
NSDirectory::CreateDirectory(sOutputDirectory);
@ -26,7 +24,7 @@ int main()
return 1;
}
int nResConvert = oFile.Convert(sFile, sOutputDirectory);
int nResConvert = oFile.Convert(sFile, sOutputDirectory, true);
if(nResConvert)
std::cout << "Success" << std::endl;
else