Commit 695c38c8 authored by konovalovsergey's avatar konovalovsergey

docx, xlsx, pptx to image

parent 8e17291c
......@@ -240,6 +240,7 @@ namespace NSOnlineOfficeBinToPdf
oRenderer.CreateFromBgraFrame(&oFrame);
oRenderer.SetTileImageDpi(96.0);
oRenderer.SetSwapRGB(false);
this->m_pRenderer = &oRenderer;
BYTE* pBufferPage = oInfo.arSizes[nPageIndex].data;
......
......@@ -882,18 +882,18 @@ namespace NSOnlineOfficeBinToPdf
{
case ctPageWidth:
{
arSizes[PagesCount].width = (ReadInt(current, curindex) / 100000.0);
arSizes[PagesCount - 1].width = (ReadInt(current, curindex) / 100000.0);
break;
}
case ctPageHeight:
{
arSizes[PagesCount].height = (ReadInt(current, curindex) / 100000.0);
arSizes[PagesCount - 1].height = (ReadInt(current, curindex) / 100000.0);
break;
}
case ctPageStart:
{
AddPage();
arSizes[PagesCount].data = current;
arSizes[PagesCount - 1].data = current;
break;
}
case ctPageEnd:
......@@ -1021,7 +1021,7 @@ namespace NSOnlineOfficeBinToPdf
LONG lColorsCount = (LONG)ReadInt(current, curindex);
if (0 <= lColorsCount)
{
SkipInt(current, curindex, 8 * lColorsCount);
SkipInt(current, curindex, 2 * lColorsCount);
}
break;
......
......@@ -83,6 +83,7 @@ core_mac {
INCLUDEPATH += ../../../DesktopEditor/xml/libxml2/include
INCLUDEPATH += ../../../DesktopEditor/freetype-2.5.2/include
INCLUDEPATH += ../../../DesktopEditor/agg-2.4/include
INCLUDEPATH += $$PWD/../../../Common/DocxFormat
DEPENDPATH += $$PWD/../../../Common/DocxFormat
......@@ -107,7 +108,8 @@ SOURCES += ../../src/main.cpp \
../../src/ASCConverters.cpp
HEADERS += ../../src/cextracttools.h \
../../../Common/OfficeFileFormatChecker.h \
../../src/ASCConverters.h
../../src/ASCConverters.h \
../../../DesktopEditor/graphics/MetafileToGraphicsRenderer.h
###############################################################################################################
......
......@@ -51,6 +51,7 @@
#include "../../ASCOfficeOdfFileW/source/Oox2OdfConverter/Oox2OdfConverter.h"
#include "../../DesktopEditor/doctrenderer/doctrenderer.h"
#include "../../DesktopEditor/fontengine/ApplicationFonts.h"
#include "../../DesktopEditor/graphics/MetafileToGraphicsRenderer.h"
#include "../../PdfReader/PdfReader.h"
#include "../../PdfReader/Src/ErrorConstants.h"
#include "../../DjVuFile/DjVu.h"
......@@ -695,6 +696,81 @@ namespace NExtractTools
NSFile::CFileBinary::Remove(sPdfBinFile);
return nRes;
}
//doct_bin -> image
int doct_bin2image(NSDoctRenderer::DoctRendererFormat::FormatFile eFromType, const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, bool bPaid, const std::wstring &sThemeDir, InputParams& params)
{
int nRes = 0;
NSDoctRenderer::DoctRendererFormat::FormatFile eToType = NSDoctRenderer::DoctRendererFormat::FormatFile::PDF;
std::wstring sTFileDir = FileSystem::Directory::GetFolderPath(sFrom);
std::wstring sImagesDirectory = sTFileDir + FILE_SEPARATOR_STR + _T("media");
std::wstring sPdfBinFile = sTFileDir + FILE_SEPARATOR_STR + _T("pdf.bin");
NSDoctRenderer::CDoctrenderer oDoctRenderer(NULL != params.m_sAllFontsPath ? *params.m_sAllFontsPath : _T(""));
std::wstring sXml = getDoctXml(eFromType, eToType, sTFileDir, sPdfBinFile, sImagesDirectory, sThemeDir, -1, _T(""), params);
std::wstring sResult;
bool bRes = oDoctRenderer.Execute(sXml, sResult);
if (-1 != sResult.find(_T("error")))
{
std::wcerr << _T("DoctRenderer:") << sResult << std::endl;
nRes = AVS_FILEUTILS_ERROR_CONVERT;
}
else
{
CApplicationFonts oApplicationFonts;
initApplicationFonts(oApplicationFonts, params);
NSOnlineOfficeBinToPdf::CMetafileToRenderterRaster imageWriter(NULL);
imageWriter.wsHtmlPlace = sTFileDir;
imageWriter.wsThemesPlace = sThemeDir;
imageWriter.wsTempDir = sTemp;
imageWriter.appFonts = &oApplicationFonts;
if(NULL != params.m_oThumbnail)
{
InputParamsThumbnail* oThumbnail = params.m_oThumbnail;
if(NULL != oThumbnail->format)
{
imageWriter.m_nRasterFormat = *oThumbnail->format;
}
if(NULL != oThumbnail->aspect)
{
imageWriter.m_nSaveType = *oThumbnail->aspect;
}
if(NULL != oThumbnail->first)
{
imageWriter.m_bIsOnlyFirst = *oThumbnail->first;
}
if(NULL != oThumbnail->width)
{
imageWriter.m_nRasterW = *oThumbnail->width;
}
if(NULL != oThumbnail->height)
{
imageWriter.m_nRasterH = *oThumbnail->height;
}
}
std::wstring sThumbnailDir;
if(imageWriter.m_bIsOnlyFirst)
{
imageWriter.m_sFileName = sTo;
}
else
{
sThumbnailDir = sTemp + FILE_SEPARATOR_STR + _T("thumbnails");
FileSystem::Directory::CreateDirectory(sThumbnailDir);
std::wstring::size_type pos = sTo.find_last_of('.');
std::wstring sExt = std::wstring::npos == pos ? L"" : sTo.substr(pos);
imageWriter.m_sFileName = sThumbnailDir + FILE_SEPARATOR_STR + L"image" + sExt;
}
BYTE* pData;
DWORD nBytesCount;
NSFile::CFileBinary::ReadAllBytes(sPdfBinFile, &pData, nBytesCount);
nRes = imageWriter.ConvertBuffer(pData, nBytesCount) ? nRes : AVS_FILEUTILS_ERROR_CONVERT;
if(!imageWriter.m_bIsOnlyFirst)
{
COfficeUtils oCOfficeUtils(NULL);
nRes = S_OK == oCOfficeUtils.CompressFileOrDirectory(sThumbnailDir, sTo, -1) ? nRes : AVS_FILEUTILS_ERROR_CONVERT;
}
}
return nRes;
}
// ppsx -> pptx
int ppsx2pptx (const std::wstring &sFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params)
......@@ -1696,6 +1772,11 @@ namespace NExtractTools
NSDoctRenderer::DoctRendererFormat::FormatFile eFromType = NSDoctRenderer::DoctRendererFormat::FormatFile::DOCT;
nRes = doct_bin2pdf(eFromType, sFrom, sTo, sTemp, bPaid, sThemeDir, params);
}
else if(AVS_OFFICESTUDIO_FILE_IMAGE == nFormatTo)
{
NSDoctRenderer::DoctRendererFormat::FormatFile eFromType = NSDoctRenderer::DoctRendererFormat::FormatFile::DOCT;
nRes = doct_bin2image(eFromType, sFrom, sTo, sTemp, bPaid, sThemeDir, params);
}
else if(0 != (AVS_OFFICESTUDIO_FILE_DOCUMENT & nFormatTo))
{
std::wstring sDocxDir = sTemp + FILE_SEPARATOR_STR + _T("docx_unpacked");
......@@ -1858,6 +1939,11 @@ namespace NExtractTools
NSDoctRenderer::DoctRendererFormat::FormatFile eFromType = NSDoctRenderer::DoctRendererFormat::FormatFile::XLST;
nRes = doct_bin2pdf(eFromType, sFrom, sTo, sTemp, bPaid, sThemeDir, params);
}
else if(AVS_OFFICESTUDIO_FILE_IMAGE == nFormatTo)
{
NSDoctRenderer::DoctRendererFormat::FormatFile eFromType = NSDoctRenderer::DoctRendererFormat::FormatFile::XLST;
nRes = doct_bin2image(eFromType, sFrom, sTo, sTemp, bPaid, sThemeDir, params);
}
else if(0 != (AVS_OFFICESTUDIO_FILE_SPREADSHEET & nFormatTo))
{
std::wstring sXlsxDir = sTemp + FILE_SEPARATOR_STR + _T("xlsx_unpacked");
......@@ -1982,6 +2068,11 @@ namespace NExtractTools
NSDoctRenderer::DoctRendererFormat::FormatFile eFromType = NSDoctRenderer::DoctRendererFormat::FormatFile::PPTT;
nRes = doct_bin2pdf(eFromType, sFrom, sTo, sTemp, bPaid, sThemeDir, params);
}
else if(AVS_OFFICESTUDIO_FILE_IMAGE == nFormatTo)
{
NSDoctRenderer::DoctRendererFormat::FormatFile eFromType = NSDoctRenderer::DoctRendererFormat::FormatFile::PPTT;
nRes = doct_bin2image(eFromType, sFrom, sTo, sTemp, bPaid, sThemeDir, params);
}
else if(0 != (AVS_OFFICESTUDIO_FILE_PRESENTATION & nFormatTo))
{
std::wstring sPptxDir = sTemp + FILE_SEPARATOR_STR + _T("pptx_unpacked");
......
......@@ -259,6 +259,63 @@ namespace NExtractTools
}
};
class InputParamsThumbnail
{
public:
int* format;
int* aspect;
bool* first;
int* width;
int* height;
InputParamsThumbnail()
{
format = NULL;
aspect = NULL;
first = NULL;
width = NULL;
height = NULL;
}
~InputParamsThumbnail()
{
RELEASEOBJECT(format);
RELEASEOBJECT(aspect);
RELEASEOBJECT(first);
RELEASEOBJECT(width);
RELEASEOBJECT(height);
}
bool FromXmlNode(XmlUtils::CXmlNode& oNode)
{
XmlUtils::CXmlNodes oXmlNodes;
if(TRUE == oNode.GetChilds(oXmlNodes))
{
for(int i = 0; i < oXmlNodes.GetCount(); ++i)
{
XmlUtils::CXmlNode oXmlNode;
if(oXmlNodes.GetAt(i, oXmlNode))
{
CString sValue;
if(oXmlNode.GetTextIfExist(sValue))
{
std::wstring sName = oXmlNode.GetName();
if(_T("format") == sName)
format = new int(XmlUtils::GetInteger(sValue));
else if(_T("aspect") == sName)
aspect = new int(XmlUtils::GetInteger(sValue));
else if(_T("first") == sName)
first = new bool(XmlUtils::GetBoolean2(sValue));
else if(_T("width") == sName)
width = new int(XmlUtils::GetInteger(sValue));
else if(_T("height") == sName)
height = new int(XmlUtils::GetInteger(sValue));
}
}
}
}
return true;
}
};
class InputParams
{
public:
......@@ -276,6 +333,7 @@ namespace NExtractTools
std::wstring* m_sFontDir;
std::wstring* m_sThemeDir;
InputParamsMailMerge* m_oMailMergeSend;
InputParamsThumbnail* m_oThumbnail;
int* m_nDoctParams;
std::wstring* m_sHtmlFileInternalPath;
std::wstring* m_sPassword;
......@@ -296,6 +354,7 @@ namespace NExtractTools
m_sFontDir = NULL;
m_sThemeDir = NULL;
m_oMailMergeSend = NULL;
m_oThumbnail = NULL;
m_nDoctParams = NULL;
m_sHtmlFileInternalPath = NULL;
m_sPassword = NULL;
......@@ -316,6 +375,7 @@ namespace NExtractTools
RELEASEOBJECT(m_sFontDir);
RELEASEOBJECT(m_sThemeDir);
RELEASEOBJECT(m_oMailMergeSend);
RELEASEOBJECT(m_oThumbnail);
RELEASEOBJECT(m_nDoctParams);
RELEASEOBJECT(m_sHtmlFileInternalPath);
RELEASEOBJECT(m_sPassword);
......@@ -340,6 +400,11 @@ namespace NExtractTools
m_oMailMergeSend = new InputParamsMailMerge();
m_oMailMergeSend->FromXmlNode(oXmlNode);
}
else if(_T("m_oThumbnail") == sName)
{
m_oThumbnail = new InputParamsThumbnail();
m_oThumbnail->FromXmlNode(oXmlNode);
}
else
{
CString sValue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment