mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Сделана специальная конвертация Djvu в Pdf, при которой ч/б картинки и составные картинки передаются через специальные функции для достижения лучшей скорости и лучшего финального размера pdf-файла.
git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63314 954022d7-b5bf-4e40-9824-e11837661b57
This commit is contained in:
committed by
Alexander Trofimov
parent
1c720f928d
commit
608c5df9fc
11
.gitignore
vendored
11
.gitignore
vendored
@ -76,3 +76,14 @@ ASCOfficePPTXFile/PPTXFormat/!_
|
|||||||
ASCOfficePPTXFile/PPTXFormat/_
|
ASCOfficePPTXFile/PPTXFormat/_
|
||||||
ASCOfficePPTXFile/Release
|
ASCOfficePPTXFile/Release
|
||||||
DesktopEditor/build
|
DesktopEditor/build
|
||||||
|
DjVuFile/Debug
|
||||||
|
DjVuFile/DjVuFile.pro.user
|
||||||
|
DjVuFile/DjVuFile.sdf
|
||||||
|
DjVuFile/DjVuFile.vcxproj.filters
|
||||||
|
DjVuFile/DjVuFile.vcxproj.user
|
||||||
|
DjVuFile/DjVuFileTest/Debug
|
||||||
|
DjVuFile/DjVuFileTest/DjVuFileTest.vcxproj.filters
|
||||||
|
DjVuFile/DjVuFileTest/DjVuFileTest.vcxproj.user
|
||||||
|
DjVuFile/DjVuFileTest/x64
|
||||||
|
DjVuFile/ipch
|
||||||
|
DjVuFile/x64
|
||||||
|
|||||||
@ -57,3 +57,8 @@ void CDjVuFile::ConvertToRaster(CApplicationFonts* pAppFonts, int
|
|||||||
if (m_pImplementation)
|
if (m_pImplementation)
|
||||||
m_pImplementation->ConvertToRaster(pAppFonts, nPageIndex, wsDstPath, nImageType);
|
m_pImplementation->ConvertToRaster(pAppFonts, nPageIndex, wsDstPath, nImageType);
|
||||||
}
|
}
|
||||||
|
void CDjVuFile::ConvertToPdf(CApplicationFonts* pAppFonts, const std::wstring& wsDstPath)
|
||||||
|
{
|
||||||
|
if (m_pImplementation)
|
||||||
|
m_pImplementation->ConvertToPdf(pAppFonts, wsDstPath);
|
||||||
|
}
|
||||||
|
|||||||
@ -27,4 +27,5 @@ public:
|
|||||||
void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY) const;
|
void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY) const;
|
||||||
void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
|
void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
|
||||||
void ConvertToRaster(CApplicationFonts* pAppFonts, int nPageIndex, const std::wstring& wsDstPath, int nImageType);
|
void ConvertToRaster(CApplicationFonts* pAppFonts, int nPageIndex, const std::wstring& wsDstPath, int nImageType);
|
||||||
|
void ConvertToPdf(CApplicationFonts* pAppFonts, const std::wstring& wsDstPath);
|
||||||
};
|
};
|
||||||
@ -42,7 +42,8 @@ Global
|
|||||||
{6D3BC8A8-93A8-468E-90CE-BCEAC28B8788}.Release|Mixed Platforms.Build.0 = Release|Win32
|
{6D3BC8A8-93A8-468E-90CE-BCEAC28B8788}.Release|Mixed Platforms.Build.0 = Release|Win32
|
||||||
{6D3BC8A8-93A8-468E-90CE-BCEAC28B8788}.Release|Win32.ActiveCfg = Release|Win32
|
{6D3BC8A8-93A8-468E-90CE-BCEAC28B8788}.Release|Win32.ActiveCfg = Release|Win32
|
||||||
{6D3BC8A8-93A8-468E-90CE-BCEAC28B8788}.Release|Win32.Build.0 = Release|Win32
|
{6D3BC8A8-93A8-468E-90CE-BCEAC28B8788}.Release|Win32.Build.0 = Release|Win32
|
||||||
{6D3BC8A8-93A8-468E-90CE-BCEAC28B8788}.Release|x64.ActiveCfg = Release|Win32
|
{6D3BC8A8-93A8-468E-90CE-BCEAC28B8788}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{6D3BC8A8-93A8-468E-90CE-BCEAC28B8788}.Release|x64.Build.0 = Release|x64
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@ -90,7 +90,7 @@
|
|||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;HAVE_NAMESPACES</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;HAVE_NAMESPACES</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<DisableSpecificWarnings>4267;4244</DisableSpecificWarnings>
|
<DisableSpecificWarnings>4267;4244</DisableSpecificWarnings>
|
||||||
<AdditionalIncludeDirectories>D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\Common\DocxFormat\Source\XML\libxml2\XML\include;D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\DesktopEditor\freetype-2.5.2\include;D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\DesktopEditor\agg-2.4\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\ServerComponents\Common\DocxFormat\Source\XML\libxml2\XML\include;..\..\ServerComponents\DesktopEditor\freetype-2.5.2\include;..\..\ServerComponents\DesktopEditor\agg-2.4\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
@ -126,7 +126,7 @@
|
|||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;HAVE_NAMESPACES</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;HAVE_NAMESPACES</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<DisableSpecificWarnings>4267;</DisableSpecificWarnings>
|
<DisableSpecificWarnings>4267;</DisableSpecificWarnings>
|
||||||
<AdditionalIncludeDirectories>D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\DesktopEditor\freetype-2.5.2\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\ServerComponents\Common\DocxFormat\Source\XML\libxml2\XML\include;..\..\ServerComponents\DesktopEditor\freetype-2.5.2\include;..\..\ServerComponents\DesktopEditor\agg-2.4\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|||||||
@ -12,6 +12,10 @@
|
|||||||
#include "../DesktopEditor/raster/BgraFrame.h"
|
#include "../DesktopEditor/raster/BgraFrame.h"
|
||||||
#include "../DesktopEditor/graphics/GraphicsRenderer.h"
|
#include "../DesktopEditor/graphics/GraphicsRenderer.h"
|
||||||
|
|
||||||
|
#include "../PdfWriter/PdfRenderer.h"
|
||||||
|
#include "../DesktopEditor/raster/JBig2/source/Encoder/jbig2enc.h"
|
||||||
|
#include "../DesktopEditor/raster/JBig2/source/LeptonLib/allheaders.h"
|
||||||
|
|
||||||
#define VER_DPI 96
|
#define VER_DPI 96
|
||||||
#define HOR_DPI 96
|
#define HOR_DPI 96
|
||||||
|
|
||||||
@ -58,7 +62,7 @@ namespace NSDjvu
|
|||||||
CDjVuFileImplementation::CDjVuFileImplementation()
|
CDjVuFileImplementation::CDjVuFileImplementation()
|
||||||
{
|
{
|
||||||
m_pDoc = NULL;
|
m_pDoc = NULL;
|
||||||
std::wstring wsTempPath = NSFile::CFileBinary::GetTempPathW();
|
std::wstring wsTempPath = NSFile::CFileBinary::GetTempPath();
|
||||||
wsTempPath += L"DJVU\\";
|
wsTempPath += L"DJVU\\";
|
||||||
m_wsTempDirectory = wsTempPath;
|
m_wsTempDirectory = wsTempPath;
|
||||||
NSDirectory::CreateDirectory(m_wsTempDirectory);
|
NSDirectory::CreateDirectory(m_wsTempDirectory);
|
||||||
@ -145,10 +149,15 @@ void CDjVuFileImplementation::DrawPageOnRenderer(IRenderer* pRende
|
|||||||
{
|
{
|
||||||
CreateGrFrame(pRenderer, pPage, pBreak);
|
CreateGrFrame(pRenderer, pPage, pBreak);
|
||||||
}
|
}
|
||||||
|
else if (c_nPDFWriter == lRendererType)
|
||||||
|
{
|
||||||
|
XmlUtils::CXmlNode oText = ParseText(pPage);
|
||||||
|
CreatePdfFrame(pRenderer, pPage, nPageIndex, oText);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
XmlUtils::CXmlNode text = ParseText(pPage);
|
XmlUtils::CXmlNode oText = ParseText(pPage);
|
||||||
CreateFrame(pRenderer, pPage, nPageIndex, text);
|
CreateFrame(pRenderer, pPage, nPageIndex, oText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
@ -195,6 +204,31 @@ void CDjVuFileImplementation::ConvertToRaster(CApplicationFonts* p
|
|||||||
oFrame.SaveFile(wsDstPath, nImageType);
|
oFrame.SaveFile(wsDstPath, nImageType);
|
||||||
RELEASEINTERFACE(pFontManager);
|
RELEASEINTERFACE(pFontManager);
|
||||||
}
|
}
|
||||||
|
void CDjVuFileImplementation::ConvertToPdf(CApplicationFonts* pAppFonts, const std::wstring& wsDstPath)
|
||||||
|
{
|
||||||
|
CPdfRenderer oPdf(pAppFonts);
|
||||||
|
|
||||||
|
bool bBreak = false;
|
||||||
|
for (int nPageIndex = 0, nPagesCount = GetPagesCount(); nPageIndex < nPagesCount; nPageIndex++)
|
||||||
|
{
|
||||||
|
oPdf.NewPage();
|
||||||
|
|
||||||
|
double dPageDpiX, dPageDpiY;
|
||||||
|
double dWidth, dHeight;
|
||||||
|
GetPageInfo(nPageIndex, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY);
|
||||||
|
dWidth *= 25.4 / dPageDpiX;
|
||||||
|
dHeight *= 25.4 / dPageDpiY;
|
||||||
|
oPdf.put_Width(dWidth);
|
||||||
|
oPdf.put_Height(dHeight);
|
||||||
|
|
||||||
|
DrawPageOnRenderer(&oPdf, nPageIndex, &bBreak);
|
||||||
|
#ifdef _DEBUG
|
||||||
|
printf("%d of %d pages\n", nPageIndex + 1, nPagesCount);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
oPdf.SaveToFile(wsDstPath);
|
||||||
|
}
|
||||||
void CDjVuFileImplementation::CreateFrame(IRenderer* pRenderer, GP<DjVuImage>& pPage, int nPage, XmlUtils::CXmlNode& text)
|
void CDjVuFileImplementation::CreateFrame(IRenderer* pRenderer, GP<DjVuImage>& pPage, int nPage, XmlUtils::CXmlNode& text)
|
||||||
{
|
{
|
||||||
int nWidth = pPage->get_real_width();
|
int nWidth = pPage->get_real_width();
|
||||||
@ -398,6 +432,257 @@ void CDjVuFileImplementation::CreateFrame(IRenderer* pRenderer, GP
|
|||||||
pRenderer->DrawImage((IGrObject*)&oImage, 0, 0, dRendWidth, dRendHeight);
|
pRenderer->DrawImage((IGrObject*)&oImage, 0, 0, dRendWidth, dRendHeight);
|
||||||
pRenderer->EndCommand(c_nPageType);
|
pRenderer->EndCommand(c_nPageType);
|
||||||
}
|
}
|
||||||
|
void CDjVuFileImplementation::CreatePdfFrame(IRenderer* pRenderer, GP<DjVuImage>& pPage, int nPageIndex, XmlUtils::CXmlNode& oText)
|
||||||
|
{
|
||||||
|
double dPageDpiX, dPageDpiY;
|
||||||
|
double dWidth, dHeight;
|
||||||
|
GetPageInfo(nPageIndex, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY);
|
||||||
|
dWidth *= 25.4 / dPageDpiX;
|
||||||
|
dHeight *= 25.4 / dPageDpiY;
|
||||||
|
|
||||||
|
pRenderer->BeginCommand(c_nPageType);
|
||||||
|
|
||||||
|
TextToRenderer(pRenderer, oText, 25.4 / pPage->get_dpi());
|
||||||
|
|
||||||
|
LONG lImageWidth = pPage->get_real_width();
|
||||||
|
LONG lImageHeight = pPage->get_real_height();
|
||||||
|
|
||||||
|
CPdfRenderer* pPdf = (CPdfRenderer*)pRenderer;
|
||||||
|
|
||||||
|
if (pPage->is_legal_photo())
|
||||||
|
{
|
||||||
|
BYTE* pBufferDst = new BYTE[4 * lImageHeight * lImageWidth];
|
||||||
|
if (!pBufferDst)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Aggplus::CImage oImage;
|
||||||
|
oImage.Create(pBufferDst, lImageWidth, lImageHeight, 4 * lImageWidth);
|
||||||
|
|
||||||
|
GRect oRectAll(0, 0, lImageWidth, lImageHeight);
|
||||||
|
GP<GPixmap> pImage = pPage->get_pixmap(oRectAll, oRectAll);
|
||||||
|
|
||||||
|
BYTE* pBuffer = pBufferDst;
|
||||||
|
for (int j = lImageHeight - 1; j >= 0; --j)
|
||||||
|
{
|
||||||
|
GPixel* pLine = pImage->operator [](j);
|
||||||
|
|
||||||
|
for (int i = 0; i < lImageWidth; ++i, pBuffer += 4, ++pLine)
|
||||||
|
{
|
||||||
|
pBuffer[0] = pLine->b;
|
||||||
|
pBuffer[1] = pLine->g;
|
||||||
|
pBuffer[2] = pLine->r;
|
||||||
|
pBuffer[3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pRenderer->DrawImage((IGrObject*)&oImage, 0, 0, dWidth, dHeight);
|
||||||
|
}
|
||||||
|
else if (pPage->is_legal_compound())
|
||||||
|
{
|
||||||
|
GRect oRectAll(0, 0, lImageWidth, lImageHeight);
|
||||||
|
GP<IW44Image> pIW44Image = pPage->get_bg44();
|
||||||
|
if (NULL != pIW44Image)
|
||||||
|
{
|
||||||
|
int nBgWidth = pIW44Image->get_width();
|
||||||
|
int nBgHeight = pIW44Image->get_height();
|
||||||
|
|
||||||
|
GP<GPixmap> pBgImage = pIW44Image->get_pixmap();
|
||||||
|
if (NULL != pBgImage)
|
||||||
|
{
|
||||||
|
BYTE* pBgBuffer = new BYTE[4 * nBgWidth * nBgHeight];
|
||||||
|
if (!pBgBuffer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Aggplus::CImage oBgImage;
|
||||||
|
oBgImage.Create(pBgBuffer, nBgWidth, nBgHeight, 4 * nBgWidth);
|
||||||
|
|
||||||
|
BYTE* pBuffer = pBgBuffer;
|
||||||
|
for (int j = nBgHeight - 1; j >= 0; --j)
|
||||||
|
{
|
||||||
|
GPixel* pLine = pBgImage->operator [](j);
|
||||||
|
|
||||||
|
for (int i = 0; i < nBgWidth; ++i, pBuffer += 4, ++pLine)
|
||||||
|
{
|
||||||
|
pBuffer[0] = pLine->b;
|
||||||
|
pBuffer[1] = pLine->g;
|
||||||
|
pBuffer[2] = pLine->r;
|
||||||
|
pBuffer[3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pRenderer->DrawImage((IGrObject*)&oBgImage, 0, 0, dWidth, dHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GP<GPixmap> pImage = pPage->get_fgpm();
|
||||||
|
if (NULL == pImage)
|
||||||
|
pImage = pPage->get_fg_pixmap(oRectAll);
|
||||||
|
|
||||||
|
if (NULL != pImage)
|
||||||
|
{
|
||||||
|
unsigned int unPixmapH = pImage->rows();
|
||||||
|
unsigned int unPixmapW = pImage->columns();
|
||||||
|
BYTE* pBufferDst = new BYTE[4 * unPixmapH * unPixmapW];
|
||||||
|
if (!pBufferDst)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Aggplus::CImage oImage;
|
||||||
|
oImage.Create(pBufferDst, unPixmapW, unPixmapH, 4 * unPixmapW);
|
||||||
|
|
||||||
|
BYTE* pBuffer = pBufferDst;
|
||||||
|
for (int j = unPixmapH - 1; j >= 0; --j)
|
||||||
|
{
|
||||||
|
GPixel* pLine = pImage->operator [](j);
|
||||||
|
|
||||||
|
for (int i = 0; i < unPixmapW; ++i, pBuffer += 4, ++pLine)
|
||||||
|
{
|
||||||
|
pBuffer[0] = pLine->b;
|
||||||
|
pBuffer[1] = pLine->g;
|
||||||
|
pBuffer[2] = pLine->r;
|
||||||
|
pBuffer[3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GP<GBitmap> pBitmap = pPage->get_bitmap(oRectAll, oRectAll, 4);
|
||||||
|
Pix* pPix = pixCreate(lImageWidth, lImageHeight, 1);
|
||||||
|
if (pPix)
|
||||||
|
{
|
||||||
|
for (int nY = 0; nY < lImageHeight; nY++)
|
||||||
|
{
|
||||||
|
BYTE* pLine = pBitmap->operator [](nY);
|
||||||
|
for (int nX = 0; nX < lImageWidth; nX++, pLine++)
|
||||||
|
{
|
||||||
|
pixSetPixel(pPix, nX, lImageHeight - 1 - nY, *pLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pPdf->DrawImageWith1bppMask((IGrObject*)&oImage, pPix, lImageWidth, lImageHeight, 0, 0, dWidth, dHeight);
|
||||||
|
pixDestroy(&pPix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (pPage->is_legal_bilevel())
|
||||||
|
{
|
||||||
|
GRect oRectAll(0, 0, lImageWidth, lImageHeight);
|
||||||
|
GP<GBitmap> pBitmap = pPage->get_bitmap(oRectAll, oRectAll, 4);
|
||||||
|
|
||||||
|
Pix* pPix = pixCreate(lImageWidth, lImageHeight, 1);
|
||||||
|
if (pPix)
|
||||||
|
{
|
||||||
|
for (int nY = 0; nY < lImageHeight; nY++)
|
||||||
|
{
|
||||||
|
BYTE* pLine = pBitmap->operator [](nY);
|
||||||
|
for (int nX = 0; nX < lImageWidth; nX++, pLine++)
|
||||||
|
{
|
||||||
|
pixSetPixel(pPix, nX, lImageHeight - 1 - nY, *pLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pPdf->DrawImage1bpp(pPix, lImageWidth, lImageHeight, 0, 0, dWidth, dHeight);
|
||||||
|
pixDestroy(&pPix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>??
|
||||||
|
//memset(pBufferDst, 0xFF, 4 * lImageWidth * lImageHeight);
|
||||||
|
GRect oRectAll(0, 0, lImageWidth, lImageHeight);
|
||||||
|
GP<GPixmap> pImage = pPage->get_pixmap(oRectAll, oRectAll);
|
||||||
|
|
||||||
|
if (NULL != pImage)
|
||||||
|
{
|
||||||
|
BYTE* pBufferDst = new BYTE[4 * lImageHeight * lImageWidth];
|
||||||
|
if (pBufferDst)
|
||||||
|
{
|
||||||
|
Aggplus::CImage oImage;
|
||||||
|
oImage.Create(pBufferDst, lImageWidth, lImageHeight, 4 * lImageWidth);
|
||||||
|
|
||||||
|
BYTE* pBuffer = pBufferDst;
|
||||||
|
for (int j = lImageHeight - 1; j >= 0; --j)
|
||||||
|
{
|
||||||
|
GPixel* pLine = pImage->operator [](j);
|
||||||
|
|
||||||
|
for (int i = 0; i < lImageWidth; ++i, pBuffer += 4, ++pLine)
|
||||||
|
{
|
||||||
|
pBuffer[0] = pLine->b;
|
||||||
|
pBuffer[1] = pLine->g;
|
||||||
|
pBuffer[2] = pLine->r;
|
||||||
|
pBuffer[3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pRenderer->DrawImage((IGrObject*)&oImage, 0, 0, dWidth, dHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GP<GBitmap> pBitmap = pPage->get_bitmap(oRectAll, oRectAll, 4);
|
||||||
|
if (NULL != pBitmap)
|
||||||
|
{
|
||||||
|
int nPaletteEntries = pBitmap->get_grays();
|
||||||
|
if (nPaletteEntries <= 2)
|
||||||
|
{
|
||||||
|
Pix* pPix = pixCreate(lImageWidth, lImageHeight, 1);
|
||||||
|
if (pPix)
|
||||||
|
{
|
||||||
|
for (int nY = 0; nY < lImageHeight; nY++)
|
||||||
|
{
|
||||||
|
BYTE* pLine = pBitmap->operator [](nY);
|
||||||
|
for (int nX = 0; nX < lImageWidth; nX++, pLine++)
|
||||||
|
{
|
||||||
|
pixSetPixel(pPix, nX, lImageHeight - 1 - nY, *pLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pPdf->DrawImage1bpp(pPix, lImageWidth, lImageHeight, 0, 0, dWidth, dHeight);
|
||||||
|
pixDestroy(&pPix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BYTE* pBufferDst = new BYTE[4 * lImageHeight * lImageWidth];
|
||||||
|
if (!pBufferDst)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Aggplus::CImage oImage;
|
||||||
|
oImage.Create(pBufferDst, lImageWidth, lImageHeight, 4 * lImageWidth);
|
||||||
|
|
||||||
|
DWORD* palette = new DWORD[nPaletteEntries];
|
||||||
|
|
||||||
|
// Create palette for the bitmap
|
||||||
|
int color = 0xff0000;
|
||||||
|
int decrement = color / (nPaletteEntries - 1);
|
||||||
|
for (int i = 0; i < nPaletteEntries; ++i)
|
||||||
|
{
|
||||||
|
BYTE level = (BYTE)(color >> 16);
|
||||||
|
palette[i] = (0xFF000000 | level << 16 | level << 8 | level);
|
||||||
|
color -= decrement;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD* pBuffer = (DWORD*)pBufferDst;
|
||||||
|
for (int j = lImageHeight - 1; j >= 0; --j)
|
||||||
|
{
|
||||||
|
BYTE* pLine = pBitmap->operator [](j);
|
||||||
|
|
||||||
|
for (int i = 0; i < lImageWidth; ++i, ++pBuffer, ++pLine)
|
||||||
|
{
|
||||||
|
if (*pLine < nPaletteEntries)
|
||||||
|
{
|
||||||
|
*pBuffer = palette[*pLine];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*pBuffer = palette[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RELEASEARRAYOBJECTS(palette);
|
||||||
|
pRenderer->DrawImage((IGrObject*)&oImage, 0, 0, dWidth, dHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pRenderer->EndCommand(c_nPageType);
|
||||||
|
}
|
||||||
void CDjVuFileImplementation::CreateGrFrame(IRenderer* pRenderer, GP<DjVuImage>& pPage, bool* pBreak)
|
void CDjVuFileImplementation::CreateGrFrame(IRenderer* pRenderer, GP<DjVuImage>& pPage, bool* pBreak)
|
||||||
{
|
{
|
||||||
int nWidth = pPage->get_real_width();
|
int nWidth = pPage->get_real_width();
|
||||||
@ -580,7 +865,7 @@ XmlUtils::CXmlNode CDjVuFileImplementation::ParseText(GP<DjVuImage> pPage)
|
|||||||
void CDjVuFileImplementation::TextToRenderer(IRenderer* pRenderer, XmlUtils::CXmlNode oTextNode, double dKoef, bool isView)
|
void CDjVuFileImplementation::TextToRenderer(IRenderer* pRenderer, XmlUtils::CXmlNode oTextNode, double dKoef, bool isView)
|
||||||
{
|
{
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>)
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>)
|
||||||
pRenderer->put_FontName(L"AVSEmptyFont");
|
pRenderer->put_FontName(L"DjvuEmptyFont");
|
||||||
CString csText = oTextNode.GetXml();
|
CString csText = oTextNode.GetXml();
|
||||||
XmlUtils::CXmlNodes oLinesNodes;
|
XmlUtils::CXmlNodes oLinesNodes;
|
||||||
oTextNode.GetNodes(L"LINE", oLinesNodes);
|
oTextNode.GetNodes(L"LINE", oLinesNodes);
|
||||||
@ -598,11 +883,11 @@ void CDjVuFileImplementation::TextToRenderer(IRenderer* pRenderer,
|
|||||||
CString csCoords = oWordNode.GetAttribute(L"coords");
|
CString csCoords = oWordNode.GetAttribute(L"coords");
|
||||||
double arrCoords[4];
|
double arrCoords[4];
|
||||||
ParseCoords(csCoords.GetBuffer(), arrCoords, dKoef);
|
ParseCoords(csCoords.GetBuffer(), arrCoords, dKoef);
|
||||||
DrawText(pRenderer, arrCoords, csWord.GetBuffer());
|
DrawPageText(pRenderer, arrCoords, csWord.GetBuffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CDjVuFileImplementation::DrawText(IRenderer* pRenderer, double* pdCoords, const std::wstring& wsText)
|
void CDjVuFileImplementation::DrawPageText(IRenderer* pRenderer, double* pdCoords, const std::wstring& wsText)
|
||||||
{
|
{
|
||||||
pRenderer->put_FontSize(pdCoords[1] - pdCoords[3]);
|
pRenderer->put_FontSize(pdCoords[1] - pdCoords[3]);
|
||||||
pRenderer->CommandDrawText(wsText,
|
pRenderer->CommandDrawText(wsText,
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
#include "libdjvu/DataPool.h"
|
#include "libdjvu/DataPool.h"
|
||||||
#include "libdjvu/DjVuText.h"
|
#include "libdjvu/DjVuText.h"
|
||||||
#include "libdjvu/DjVmNav.h"
|
#include "libdjvu/DjVmNav.h"
|
||||||
|
#include "libdjvu/IW44Image.h"
|
||||||
|
|
||||||
#define ZIP_NO_COMPRESSION 0
|
#define ZIP_NO_COMPRESSION 0
|
||||||
#define ZIP_BEST_SPEED 1
|
#define ZIP_BEST_SPEED 1
|
||||||
@ -45,13 +46,15 @@ public:
|
|||||||
void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY) const;
|
void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY) const;
|
||||||
void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
|
void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
|
||||||
void ConvertToRaster(CApplicationFonts* pAppFonts, int nPageIndex, const std::wstring& wsDstPath, int nImageType);
|
void ConvertToRaster(CApplicationFonts* pAppFonts, int nPageIndex, const std::wstring& wsDstPath, int nImageType);
|
||||||
|
void ConvertToPdf(CApplicationFonts* pAppFonts, const std::wstring& wsDstPath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void CreateFrame(IRenderer* pRenderer, GP<DjVuImage>& pImage, int nPage, XmlUtils::CXmlNode& text);
|
void CreateFrame(IRenderer* pRenderer, GP<DjVuImage>& pImage, int nPage, XmlUtils::CXmlNode& oText);
|
||||||
|
void CreatePdfFrame(IRenderer* pRenderer, GP<DjVuImage>& pImage, int nPage, XmlUtils::CXmlNode& oText);
|
||||||
void CreateGrFrame(IRenderer* pRenderer, GP<DjVuImage>& pImage, bool* pBreak);
|
void CreateGrFrame(IRenderer* pRenderer, GP<DjVuImage>& pImage, bool* pBreak);
|
||||||
XmlUtils::CXmlNode ParseText(GP<DjVuImage> pPage);
|
XmlUtils::CXmlNode ParseText(GP<DjVuImage> pPage);
|
||||||
void TextToRenderer(IRenderer* pRenderer, XmlUtils::CXmlNode text, double koef, bool isView = true);
|
void TextToRenderer(IRenderer* pRenderer, XmlUtils::CXmlNode text, double koef, bool isView = true);
|
||||||
void DrawText(IRenderer* pRenderer, double* pdCoords, const std::wstring& wsText);
|
void DrawPageText(IRenderer* pRenderer, double* pdCoords, const std::wstring& wsText);
|
||||||
void ParseCoords(const std::wstring& wsCoordsStr, double* pdCoords, double dKoef);
|
void ParseCoords(const std::wstring& wsCoordsStr, double* pdCoords, double dKoef);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,7 +8,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
|
|
||||||
|
#include "../../DesktopEditor/common/String.h"
|
||||||
#include "../../DesktopEditor/fontengine/ApplicationFonts.h"
|
#include "../../DesktopEditor/fontengine/ApplicationFonts.h"
|
||||||
|
#include <ctime>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
std::vector<std::wstring> GetAllFilesInFolder(std::wstring wsFolder, std::wstring wsExt)
|
std::vector<std::wstring> GetAllFilesInFolder(std::wstring wsFolder, std::wstring wsExt)
|
||||||
{
|
{
|
||||||
@ -33,7 +36,7 @@ std::vector<std::wstring> GetAllFilesInFolder(std::wstring wsFolder, std::wstrin
|
|||||||
}
|
}
|
||||||
return vwsNames;
|
return vwsNames;
|
||||||
}
|
}
|
||||||
void ConvertFolder(CDjVuFile& oReader, std::wstring wsFolderPath)
|
void ConvertFolderToRaster(CDjVuFile& oReader, std::wstring wsFolderPath)
|
||||||
{
|
{
|
||||||
CApplicationFonts oFonts;
|
CApplicationFonts oFonts;
|
||||||
oFonts.Initialize();
|
oFonts.Initialize();
|
||||||
@ -64,9 +67,41 @@ void ConvertFolder(CDjVuFile& oReader, std::wstring wsFolderPath)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void ConvertFolderToPdf(CDjVuFile& oReader, std::wstring wsFolderPath)
|
||||||
|
{
|
||||||
|
CApplicationFonts oFonts;
|
||||||
|
oFonts.Initialize();
|
||||||
|
oReader.Close();
|
||||||
|
|
||||||
|
clock_t oBeginTime = clock();
|
||||||
|
std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, L"djvu");
|
||||||
|
for (int nIndex = 0; nIndex < vFiles.size(); nIndex++)
|
||||||
|
{
|
||||||
|
std::wstring wsFilePath = wsFolderPath;
|
||||||
|
wsFilePath.append(vFiles.at(nIndex));
|
||||||
|
std::wstring wsFilePathName = (wsFilePath.substr(0, wsFilePath.size() - 5));
|
||||||
|
if (oReader.LoadFromFile(wsFilePath.c_str()))
|
||||||
|
{
|
||||||
|
std::wstring wsDstFilePath = wsFilePathName + L".pdf";
|
||||||
|
oReader.ConvertToPdf(&oFonts, wsDstFilePath);
|
||||||
|
printf("%d of %d converted\n", nIndex, vFiles.size());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("%d of %d %S error\n", nIndex, vFiles.size(), vFiles.at(nIndex).c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clock_t oEndTime = clock();
|
||||||
|
double dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC;
|
||||||
|
printf("%f\n", dElapsedSecs);
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
CDjVuFile oFile;
|
CDjVuFile oFile;
|
||||||
ConvertFolder(oFile, L"D:/Test Files//");
|
//ConvertFolderToRaster(oFile, L"D:/Test Files//");
|
||||||
|
ConvertFolderToPdf(oFile, L"D:/Test Files//djvu//");
|
||||||
|
|
||||||
|
char q;
|
||||||
|
std::cin >> q;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -99,7 +99,7 @@
|
|||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;HAVE_NAMESPACES;UNICODE;_UNICODE;_USE_LIBXML2_READER_;LIBXML_READER_ENABLED</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;HAVE_NAMESPACES;UNICODE;_UNICODE;_USE_LIBXML2_READER_;LIBXML_READER_ENABLED</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\DesktopEditor\freetype-2.5.2\include;D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\DesktopEditor\agg-2.4\include;D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\Common\DocxFormat\Source\XML\libxml2\XML\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\ServerComponents\Common\DocxFormat\Source\XML\libxml2\XML\include;..\..\..\ServerComponents\DesktopEditor\freetype-2.5.2\include;..\..\..\ServerComponents\DesktopEditor\agg-2.4\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -131,9 +131,9 @@
|
|||||||
<Optimization>MaxSpeed</Optimization>
|
<Optimization>MaxSpeed</Optimization>
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;HAVE_NAMESPACES</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;HAVE_NAMESPACES;UNICODE;_UNICODE;_USE_LIBXML2_READER_;LIBXML_READER_ENABLED</PreprocessorDefinitions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<AdditionalIncludeDirectories>D:\Subversion\AVS\Sources\TeamlabOffice\trunk\ServerComponents\DesktopEditor\freetype-2.5.2\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\..\ServerComponents\Common\DocxFormat\Source\XML\libxml2\XML\include;..\..\..\ServerComponents\DesktopEditor\freetype-2.5.2\include;..\..\..\ServerComponents\DesktopEditor\agg-2.4\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -152,12 +152,15 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\Common\DocxFormat\Source\Base\unicode_util.cpp">
|
<ClCompile Include="..\..\Common\DocxFormat\Source\Base\unicode_util.cpp">
|
||||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||||
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\Common\DocxFormat\Source\XML\libxml2\libxml2.cpp">
|
<ClCompile Include="..\..\Common\DocxFormat\Source\XML\libxml2\libxml2.cpp">
|
||||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||||
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\Common\DocxFormat\Source\XML\stringcommon.cpp">
|
<ClCompile Include="..\..\Common\DocxFormat\Source\XML\stringcommon.cpp">
|
||||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||||
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="DjVuFileTest.cpp" />
|
<ClCompile Include="DjVuFileTest.cpp" />
|
||||||
<ClCompile Include="stdafx.cpp">
|
<ClCompile Include="stdafx.cpp">
|
||||||
|
|||||||
@ -12,11 +12,14 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#pragma comment(lib, "../../Common/DocxFormat/Source/XML/libxml2/win_build/x64/Debug/libxml2.lib")
|
|
||||||
#pragma comment(lib, "../x64/Debug/DjVuFile.lib")
|
#pragma comment(lib, "../x64/Debug/DjVuFile.lib")
|
||||||
|
#pragma comment(lib, "../../PdfWriter/x64/Debug/PdfWriter.lib")
|
||||||
|
#pragma comment(lib, "../../Common/DocxFormat/Source/XML/libxml2/win_build/x64/Debug/libxml2.lib")
|
||||||
#pragma comment(lib, "../../DesktopEditor/Qt_build/graphics/project/debug/graphics.lib")
|
#pragma comment(lib, "../../DesktopEditor/Qt_build/graphics/project/debug/graphics.lib")
|
||||||
#else
|
#else
|
||||||
#pragma comment(lib, "../x64/Release/DjVuFile.lib")
|
#pragma comment(lib, "../x64/Release/DjVuFile.lib")
|
||||||
|
#pragma comment(lib, "../../PdfWriter/x64/Release/PdfWriter.lib")
|
||||||
|
#pragma comment(lib, "../../Common/DocxFormat/Source/XML/libxml2/win_build/x64/Release/libxml2.lib")
|
||||||
#pragma comment(lib, "../../DesktopEditor/Qt_build/graphics/project/release/graphics.lib")
|
#pragma comment(lib, "../../DesktopEditor/Qt_build/graphics/project/release/graphics.lib")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user