mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
PdfWriter & DjvuFile builds
This commit is contained in:
@ -89,6 +89,24 @@ namespace NSImages
|
||||
void Destroy();
|
||||
void* native();
|
||||
};
|
||||
|
||||
class CJbig2Context_private;
|
||||
class GRAPHICS_DECL CJbig2Context
|
||||
{
|
||||
private:
|
||||
CJbig2Context_private* m_internal;
|
||||
|
||||
public:
|
||||
CJbig2Context();
|
||||
~CJbig2Context();
|
||||
|
||||
bool IsInit();
|
||||
void Init(float thresh, float weight, int xres, int yres, bool full_headers, int refine_level);
|
||||
BYTE* PagesComplete(int* const length);
|
||||
BYTE* ProducePage(int page_no, int xres, int yres, int *const length);
|
||||
void AddPage(CPixJbig2* pix);
|
||||
void Destroy();
|
||||
};
|
||||
}
|
||||
|
||||
namespace MetaFile
|
||||
|
||||
@ -32,8 +32,6 @@ DEFINES += \
|
||||
MNG_STORE_CHUNKS\
|
||||
MNG_ERROR_TELLTALE
|
||||
|
||||
DEFINES += STRING_EXT_NO_CODEPAGES
|
||||
|
||||
core_linux {
|
||||
DEFINES += \
|
||||
HAVE_UNISTD_H
|
||||
@ -121,7 +119,6 @@ SOURCES += \
|
||||
./../GraphicsRenderer.cpp \
|
||||
./../Image.cpp \
|
||||
./../MetafileToRenderer.cpp \
|
||||
./../../raster/Metafile.cpp \
|
||||
\
|
||||
./../../fontengine/ApplicationFonts.cpp \
|
||||
./../../fontengine/FontFile.cpp \
|
||||
|
||||
@ -75,6 +75,7 @@ namespace NSImages
|
||||
}
|
||||
CPixJbig2::~CPixJbig2()
|
||||
{
|
||||
Destroy();
|
||||
RELEASEOBJECT(m_internal);
|
||||
}
|
||||
|
||||
@ -99,5 +100,64 @@ namespace NSImages
|
||||
{
|
||||
return (void*)m_internal->m_pix;
|
||||
}
|
||||
|
||||
class CJbig2Context_private
|
||||
{
|
||||
public:
|
||||
jbig2ctx* m_context;
|
||||
|
||||
public:
|
||||
CJbig2Context_private()
|
||||
{
|
||||
m_context = NULL;
|
||||
}
|
||||
~CJbig2Context_private()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
CJbig2Context::CJbig2Context()
|
||||
{
|
||||
m_internal = new CJbig2Context_private();
|
||||
}
|
||||
CJbig2Context::~CJbig2Context()
|
||||
{
|
||||
Destroy();
|
||||
RELEASEOBJECT(m_internal);
|
||||
}
|
||||
|
||||
bool CJbig2Context::IsInit()
|
||||
{
|
||||
return (m_internal->m_context != NULL) ? true : false;
|
||||
}
|
||||
|
||||
void CJbig2Context::Init(float thresh, float weight, int xres, int yres, bool full_headers, int refine_level)
|
||||
{
|
||||
m_internal->m_context = jbig2_init(thresh, weight, xres, yres, full_headers, refine_level);
|
||||
}
|
||||
|
||||
BYTE* CJbig2Context::PagesComplete(int* const length)
|
||||
{
|
||||
return jbig2_pages_complete(m_internal->m_context, length);
|
||||
}
|
||||
|
||||
BYTE* CJbig2Context::ProducePage(int page_no, int xres, int yres, int *const length)
|
||||
{
|
||||
return jbig2_produce_page(m_internal->m_context, page_no, xres, yres, length);
|
||||
}
|
||||
|
||||
void CJbig2Context::AddPage(CPixJbig2* pix)
|
||||
{
|
||||
jbig2_add_page(m_internal->m_context, (Pix*)pix->native());
|
||||
}
|
||||
|
||||
void CJbig2Context::Destroy()
|
||||
{
|
||||
if (!m_internal->m_context)
|
||||
return;
|
||||
|
||||
jbig2_destroy(m_internal->m_context);
|
||||
m_internal->m_context = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -163,3 +163,67 @@ HRESULT COfficeUtils::GetFilesSize(const std::wstring& zipFile, const std::wstri
|
||||
return S_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
class CDeflate_private
|
||||
{
|
||||
public:
|
||||
z_stream m_stream;
|
||||
|
||||
public:
|
||||
CDeflate_private()
|
||||
{
|
||||
memset(&m_stream, 0x00, sizeof(z_stream));
|
||||
}
|
||||
};
|
||||
|
||||
CDeflate::CDeflate()
|
||||
{
|
||||
m_internal = new CDeflate_private();
|
||||
}
|
||||
CDeflate::~CDeflate()
|
||||
{
|
||||
delete m_internal;
|
||||
}
|
||||
|
||||
void CDeflate::SetIn(BYTE* next_in, UINT avail_in, ULONG total_in)
|
||||
{
|
||||
m_internal->m_stream.next_in = next_in;
|
||||
m_internal->m_stream.avail_in = avail_in;
|
||||
|
||||
if (-1 != total_in)
|
||||
m_internal->m_stream.total_in = total_in;
|
||||
}
|
||||
|
||||
void CDeflate::SetOut(BYTE* next_out, UINT avail_out, ULONG total_out)
|
||||
{
|
||||
m_internal->m_stream.next_out = next_out;
|
||||
m_internal->m_stream.avail_out = avail_out;
|
||||
|
||||
if (-1 != total_out)
|
||||
m_internal->m_stream.total_out = total_out;
|
||||
}
|
||||
|
||||
UINT CDeflate::GetAvailIn()
|
||||
{
|
||||
return m_internal->m_stream.avail_in;
|
||||
}
|
||||
|
||||
UINT CDeflate::GetAvailOut()
|
||||
{
|
||||
return m_internal->m_stream.avail_out;
|
||||
}
|
||||
|
||||
void CDeflate::Init(int level, int stream_size)
|
||||
{
|
||||
deflateInit_(&m_internal->m_stream, level, ZLIB_VERSION, (stream_size == -1) ? sizeof(z_stream) : stream_size);
|
||||
}
|
||||
|
||||
int CDeflate::Process(int flush)
|
||||
{
|
||||
return deflate(&m_internal->m_stream, flush);
|
||||
}
|
||||
|
||||
void CDeflate::End()
|
||||
{
|
||||
deflateEnd(&m_internal->m_stream);
|
||||
}
|
||||
|
||||
@ -57,4 +57,41 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#define DEFLATE_OK 0
|
||||
#define DEFLATE_STREAM_END 1
|
||||
|
||||
#define DEFLATE_NO_FLUSH 0
|
||||
#define DEFLATE_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
|
||||
#define DEFLATE_SYNC_FLUSH 2
|
||||
#define DEFLATE_FULL_FLUSH 3
|
||||
#define DEFLATE_FINISH 4
|
||||
#define DEFLATE_BLOCK 5
|
||||
|
||||
#define DEFLATE_NO_COMPRESSION 0
|
||||
#define DEFLATE_BEST_SPEED 1
|
||||
#define DEFLATE_BEST_COMPRESSION 9
|
||||
#define DEFLATE_DEFAULT_COMPRESSION (-1)
|
||||
|
||||
class CDeflate_private;
|
||||
class KERNEL_DECL CDeflate
|
||||
{
|
||||
private:
|
||||
CDeflate_private* m_internal;
|
||||
|
||||
public:
|
||||
CDeflate();
|
||||
~CDeflate();
|
||||
|
||||
public:
|
||||
void SetIn(BYTE* next_in, UINT avail_in, ULONG total_in = -1);
|
||||
void SetOut(BYTE* next_out, UINT avail_out, ULONG total_out = -1);
|
||||
|
||||
UINT GetAvailIn();
|
||||
UINT GetAvailOut();
|
||||
|
||||
void Init(int level, int stream_size = -1);
|
||||
int Process(int flush);
|
||||
void End();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -44,9 +44,8 @@
|
||||
#include "../DesktopEditor/graphics/structures.h"
|
||||
#include "../DesktopEditor/raster/BgraFrame.h"
|
||||
#include "../DesktopEditor/raster/ImageFileFormatChecker.h"
|
||||
#include "../DesktopEditor/fontengine/ApplicationFonts.h"
|
||||
#include "../DesktopEditor/fontengine/FontManager.h"
|
||||
#include "../DesktopEditor/raster/Metafile/MetaFile.h"
|
||||
#include "../DesktopEditor/graphics/pro/Fonts.h"
|
||||
#include "../DesktopEditor/graphics/pro/Image.h"
|
||||
|
||||
#include "OnlineOfficeBinToPdf.h"
|
||||
|
||||
@ -487,7 +486,7 @@ CPdfRenderer::CPdfRenderer(NSFonts::IApplicationFonts* pAppFonts) : m_oCommandMa
|
||||
|
||||
// Создаем менеджер шрифтов с собственным кэшем
|
||||
m_pFontManager = pAppFonts->GenerateFontManager();
|
||||
CFontsCache* pMeasurerCache = new CFontsCache();
|
||||
NSFonts::IFontsCache* pMeasurerCache = NSFonts::NSFontCache::Create();
|
||||
pMeasurerCache->SetStreams(pAppFonts->GetStreams());
|
||||
m_pFontManager->SetOwnerCache(pMeasurerCache);
|
||||
|
||||
@ -1350,12 +1349,14 @@ HRESULT CPdfRenderer::DrawImageFromFile(const std::wstring& wsImagePath, const d
|
||||
if (_CXIMAGE_FORMAT_WMF == oImageFormat.eFileType || _CXIMAGE_FORMAT_EMF == oImageFormat.eFileType || _CXIMAGE_FORMAT_SVM == oImageFormat.eFileType)
|
||||
{
|
||||
// TODO: Реализовать отрисовку метафайлов по-нормальному
|
||||
MetaFile::CMetaFile oMeta(m_pAppFonts);
|
||||
oMeta.LoadFromFile(wsImagePath.c_str());
|
||||
MetaFile::IMetaFile* pMeta = MetaFile::Create(m_pAppFonts);
|
||||
pMeta->LoadFromFile(wsImagePath.c_str());
|
||||
|
||||
double dNewW = std::max(10.0, dW) / 25.4 * 300;
|
||||
std::wstring wsTempFile = GetTempFile();
|
||||
oMeta.ConvertToRaster(wsTempFile.c_str(), _CXIMAGE_FORMAT_PNG, dNewW);
|
||||
pMeta->ConvertToRaster(wsTempFile.c_str(), _CXIMAGE_FORMAT_PNG, dNewW);
|
||||
|
||||
RELEASEOBJECT(pMeta);
|
||||
|
||||
pAggImage = new Aggplus::CImage(wsTempFile);
|
||||
}
|
||||
@ -1452,7 +1453,7 @@ HRESULT CPdfRenderer::DrawImage1bpp(NSImages::CPixJbig2* pImageBuffer, const uns
|
||||
UpdateTransform();
|
||||
|
||||
CImageDict* pPdfImage = m_pDocument->CreateImage();
|
||||
pPdfImage->LoadBW((Pix*)pImageBuffer->native(), unWidth, unHeight);
|
||||
pPdfImage->LoadBW(pImageBuffer, unWidth, unHeight);
|
||||
m_pPage->DrawImage(pPdfImage, MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY - dH), MM_2_PT(dW), MM_2_PT(dH));
|
||||
|
||||
m_pPage->GrRestore();
|
||||
@ -1485,7 +1486,7 @@ HRESULT CPdfRenderer::DrawImageWith1bppMask(IGrObject* pImage, NSImages::CPixJbi
|
||||
m_pPage->GrSave();
|
||||
UpdateTransform();
|
||||
CImageDict* pPdfImage = LoadImage((Aggplus::CImage*)pImage, 255);
|
||||
pPdfImage->LoadMask((Pix*)pMaskBuffer->native(), unMaskWidth, unMaskHeight);
|
||||
pPdfImage->LoadMask(pMaskBuffer, unMaskWidth, unMaskHeight);
|
||||
m_pPage->DrawImage(pPdfImage, MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY - dH), MM_2_PT(dW), MM_2_PT(dH));
|
||||
m_pPage->GrRestore();
|
||||
return S_OK;
|
||||
@ -1753,8 +1754,8 @@ void CPdfRenderer::UpdateBrush()
|
||||
else if (_CXIMAGE_FORMAT_WMF == oImageFormat.eFileType || _CXIMAGE_FORMAT_EMF == oImageFormat.eFileType || _CXIMAGE_FORMAT_SVM == oImageFormat.eFileType)
|
||||
{
|
||||
// TODO: Реализовать отрисовку метафайлов по-нормальному
|
||||
MetaFile::CMetaFile oMeta(m_pAppFonts);
|
||||
oMeta.LoadFromFile(wsTexturePath.c_str());
|
||||
MetaFile::IMetaFile* pMeta = MetaFile::Create(m_pAppFonts);
|
||||
pMeta->LoadFromFile(wsTexturePath.c_str());
|
||||
|
||||
double dL, dR, dT, dB;
|
||||
m_oPath.GetBounds(dL, dT, dR, dB);
|
||||
@ -1762,7 +1763,9 @@ void CPdfRenderer::UpdateBrush()
|
||||
double dNewW = std::max(10.0, dR - dL) / 72 * 300;
|
||||
|
||||
std::wstring wsTempFile = GetTempFile();
|
||||
oMeta.ConvertToRaster(wsTempFile.c_str(), _CXIMAGE_FORMAT_PNG, dNewW);
|
||||
pMeta->ConvertToRaster(wsTempFile.c_str(), _CXIMAGE_FORMAT_PNG, dNewW);
|
||||
|
||||
RELEASEOBJECT(pMeta);
|
||||
|
||||
Aggplus::CImage oImage(wsTempFile);
|
||||
nImageW = abs((int)oImage.GetWidth());
|
||||
|
||||
@ -20,9 +20,65 @@ DEFINES += GRAPHICS_USE_DYNAMIC_LIBRARY
|
||||
LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lUnicodeConverter -lkernel -lgraphics
|
||||
|
||||
DEFINES += NOMINMAX
|
||||
|
||||
core_windows {
|
||||
DEFINES -= UNICODE
|
||||
DEFINES -= _UNICODE
|
||||
|
||||
LIBS += -lAdvapi32
|
||||
LIBS += -lShell32
|
||||
LIBS += -lUser32
|
||||
}
|
||||
|
||||
# FREETYPE ------------------------------------
|
||||
DEFINES += FT2_BUILD_LIBRARY
|
||||
|
||||
INCLUDEPATH += \
|
||||
../DesktopEditor/freetype-2.5.2/include
|
||||
|
||||
SOURCES += \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftbbox.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftgxval.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftlcdfil.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftmm.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftotval.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftpatent.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftpfr.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftsynth.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/fttype1.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftwinfnt.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftxf86.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/pcf/pcf.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/pfr/pfr.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/psaux/psaux.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/pshinter/pshinter.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/psnames/psmodule.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/raster/raster.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/sfnt/sfnt.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/truetype/truetype.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/type1/type1.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/cid/type1cid.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/type42/type42.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/winfonts/winfnt.c \
|
||||
\
|
||||
../DesktopEditor/freetype-2.5.2/src/autofit/autofit.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/bdf/bdf.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/cff/cff.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftbase.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftbitmap.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/cache/ftcache.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftfstype.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftgasp.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftglyph.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/gzip/ftgzip.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftinit.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/lzw/ftlzw.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftstroke.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/base/ftsystem.c \
|
||||
../DesktopEditor/freetype-2.5.2/src/smooth/smooth.c
|
||||
|
||||
# ---------------------------------------------
|
||||
|
||||
core_windows {
|
||||
|
||||
LIBS += -lgdi32 \
|
||||
|
||||
@ -38,8 +38,9 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "../../DesktopEditor/fontengine/FontManager.h"
|
||||
#include "../../DesktopEditor/common/File.h"
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_TRUETYPE_TABLES_H
|
||||
|
||||
namespace PdfWriter
|
||||
@ -103,4 +104,4 @@ namespace PdfWriter
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _PDF_WRITER_SRC_FONTCIDTT_H
|
||||
#endif // _PDF_WRITER_SRC_FONTCIDTT_H
|
||||
|
||||
@ -33,12 +33,10 @@
|
||||
#include "Streams.h"
|
||||
#include "Document.h"
|
||||
|
||||
#include "../../DesktopEditor/raster/JBig2/source/Encoder/jbig2enc.h"
|
||||
#include "../../DesktopEditor/raster/JBig2/source/LeptonLib/allheaders.h"
|
||||
|
||||
// TODO: write JPG from Photoshop...
|
||||
#include "../../DesktopEditor/raster/ImageFileFormatChecker.h"
|
||||
#include "../../DesktopEditor/raster/BgraFrame.h"
|
||||
|
||||
namespace NSImageReSaver
|
||||
{
|
||||
static void CorrectImage(const wchar_t* wsFileName, BYTE*& pBuffer, int& nBufferSize, unsigned int& unWidth, unsigned int& unHeight)
|
||||
@ -375,7 +373,7 @@ namespace PdfWriter
|
||||
pParams->Add("JBIG2Globals", pJbig2Global);
|
||||
Add("DecodeParms", pDecodeParams);
|
||||
}
|
||||
void CImageDict::LoadBW(Pix* pPix, unsigned int unWidth, unsigned int unHeight)
|
||||
void CImageDict::LoadBW(NSImages::CPixJbig2* pPix, unsigned int unWidth, unsigned int unHeight)
|
||||
{
|
||||
SetStream(m_pXref, new CMemoryStream());
|
||||
CJbig2Global* pJbig2Global = m_pDocument->GetJbig2Global();
|
||||
@ -395,7 +393,7 @@ namespace PdfWriter
|
||||
pParams->Add("JBIG2Globals", pJbig2Global);
|
||||
Add("DecodeParms", pDecodeParams);
|
||||
}
|
||||
void CImageDict::LoadMask(Pix* pPix, unsigned int unWidth, unsigned int unHeight)
|
||||
void CImageDict::LoadMask(NSImages::CPixJbig2* pPix, unsigned int unWidth, unsigned int unHeight)
|
||||
{
|
||||
CImageDict* pMask = new CImageDict(m_pXref, m_pDocument);
|
||||
if (!pMask)
|
||||
@ -427,19 +425,18 @@ namespace PdfWriter
|
||||
CJbig2Global::CJbig2Global(CXref* pXref) : CDictObject(pXref)
|
||||
{
|
||||
m_pXref = pXref;
|
||||
m_pContext = jbig2_init(0.85, 0.5, -1, -1, false, -1);
|
||||
m_pContext.Init(0.85, 0.5, -1, -1, false, -1);
|
||||
}
|
||||
CJbig2Global::~CJbig2Global()
|
||||
{
|
||||
if (m_pContext)
|
||||
jbig2_destroy(m_pContext);
|
||||
m_pContext.Destroy();
|
||||
}
|
||||
void CJbig2Global::FlushStreams()
|
||||
{
|
||||
CStream* pStream = GetStream();
|
||||
|
||||
int nLen = 0;
|
||||
BYTE* pBuffer = jbig2_pages_complete(m_pContext, &nLen);
|
||||
BYTE* pBuffer = m_pContext.PagesComplete(&nLen);
|
||||
|
||||
if (pBuffer)
|
||||
{
|
||||
@ -449,7 +446,7 @@ namespace PdfWriter
|
||||
|
||||
for (int nIndex = 0, nCount = m_vImages.size(); nIndex < nCount; nIndex++)
|
||||
{
|
||||
pBuffer = jbig2_produce_page(m_pContext, nIndex, -1, -1, &nLen);
|
||||
pBuffer = m_pContext.ProducePage(nIndex, -1, -1, &nLen);
|
||||
if (pBuffer)
|
||||
{
|
||||
pStream = m_vImages.at(nIndex);
|
||||
@ -461,16 +458,15 @@ namespace PdfWriter
|
||||
}
|
||||
}
|
||||
|
||||
jbig2_destroy(m_pContext);
|
||||
m_pContext = NULL;
|
||||
m_pContext.Destroy();
|
||||
}
|
||||
void CJbig2Global::AddImage(const BYTE* pImage, unsigned int unWidth, unsigned int unHeight, unsigned int unStride, CStream* pImageStream)
|
||||
{
|
||||
if (!m_pContext)
|
||||
if (!m_pContext.IsInit())
|
||||
return;
|
||||
|
||||
Pix* pPix = pixCreate(unWidth, unHeight, 1);
|
||||
if (!pPix)
|
||||
NSImages::CPixJbig2 pPix;
|
||||
if (!pPix.Create(unWidth, unHeight, 1))
|
||||
return;
|
||||
|
||||
BYTE* pLine = (BYTE*)pImage;
|
||||
@ -480,7 +476,7 @@ namespace PdfWriter
|
||||
BYTE* pCur = pLine;
|
||||
for (unsigned int unX = 0; unX < unWidth; unX++)
|
||||
{
|
||||
pixSetPixel(pPix, unX, unY, pCur[0] & (1 << nBit));
|
||||
pPix.SetPixel(unX, unY, pCur[0] & (1 << nBit));
|
||||
nBit++;
|
||||
|
||||
if (8 == nBit)
|
||||
@ -491,16 +487,16 @@ namespace PdfWriter
|
||||
}
|
||||
}
|
||||
|
||||
jbig2_add_page(m_pContext, pPix);
|
||||
pixDestroy(&pPix);
|
||||
m_pContext.AddPage(&pPix);
|
||||
pPix.Destroy();
|
||||
m_vImages.push_back(pImageStream);
|
||||
}
|
||||
void CJbig2Global::AddImage(Pix* pPix, CStream* pImageStream)
|
||||
void CJbig2Global::AddImage(NSImages::CPixJbig2* pPix, CStream* pImageStream)
|
||||
{
|
||||
if (!m_pContext)
|
||||
if (!m_pContext.IsInit())
|
||||
return;
|
||||
|
||||
jbig2_add_page(m_pContext, pPix);
|
||||
m_pContext.AddPage(pPix);
|
||||
m_vImages.push_back(pImageStream);
|
||||
}
|
||||
int CJbig2Global::GetImagesCount()
|
||||
|
||||
@ -33,9 +33,7 @@
|
||||
#define _PDF_WRITER_SRC_IMAGE_H
|
||||
|
||||
#include "Objects.h"
|
||||
|
||||
struct jbig2ctx;
|
||||
struct Pix;
|
||||
#include "../../DesktopEditor/graphics/pro/Image.h"
|
||||
|
||||
namespace PdfWriter
|
||||
{
|
||||
@ -68,8 +66,8 @@ namespace PdfWriter
|
||||
void LoadSMask(const BYTE* pBgra, unsigned int unWidth, unsigned int unHeight, unsigned char lAlpha = 255, bool bVerFlip = false);
|
||||
void LoadSMask(const BYTE* pBuffer, unsigned int unSize, unsigned int unWidth, unsigned int unHeight);
|
||||
void LoadBW(const BYTE* pImage, unsigned int unWidth, unsigned int unHeight, unsigned int unStride);
|
||||
void LoadBW(Pix* pPix, unsigned int unWidth, unsigned int unHeight);
|
||||
void LoadMask(Pix* pPix, unsigned int unWidth, unsigned int unHeight);
|
||||
void LoadBW(NSImages::CPixJbig2* pPix, unsigned int unWidth, unsigned int unHeight);
|
||||
void LoadMask(NSImages::CPixJbig2* pPix, unsigned int unWidth, unsigned int unHeight);
|
||||
|
||||
private:
|
||||
|
||||
@ -86,15 +84,15 @@ namespace PdfWriter
|
||||
CJbig2Global(CXref* pXref);
|
||||
~CJbig2Global();
|
||||
void AddImage(const BYTE* pImage, unsigned int unWidth, unsigned int unHeight, unsigned int unStride, CStream* pImageStream);
|
||||
void AddImage(Pix* pPix, CStream* pImageStream);
|
||||
void AddImage(NSImages::CPixJbig2* pPix, CStream* pImageStream);
|
||||
void FlushStreams();
|
||||
int GetImagesCount();
|
||||
|
||||
private:
|
||||
|
||||
CXref* m_pXref;
|
||||
jbig2ctx* m_pContext;
|
||||
std::vector<CStream*> m_vImages;
|
||||
CXref* m_pXref;
|
||||
NSImages::CJbig2Context m_pContext;
|
||||
std::vector<CStream*> m_vImages;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "../../OfficeUtils/src/zlib-1.2.3/zlib.h"
|
||||
#include "../../OfficeUtils/src/OfficeUtils.h"
|
||||
|
||||
#define DEFLATE_BUF_SIZ ((int)(STREAM_BUF_SIZ * 1.1) + 13)
|
||||
|
||||
@ -363,39 +363,34 @@ namespace PdfWriter
|
||||
{
|
||||
unsigned long nRet = OK;
|
||||
|
||||
z_stream pZStream;
|
||||
Bytef inbuf[STREAM_BUF_SIZ];
|
||||
Bytef otbuf[DEFLATE_BUF_SIZ];
|
||||
CDeflate ZStream;
|
||||
BYTE inbuf[STREAM_BUF_SIZ];
|
||||
BYTE otbuf[DEFLATE_BUF_SIZ];
|
||||
BYTE ebuf[DEFLATE_BUF_SIZ];
|
||||
|
||||
// initialize input stream
|
||||
pStream->Seek(0, SeekSet);
|
||||
|
||||
// initialize decompression stream.
|
||||
MemSet(&pZStream, 0x00, sizeof(z_stream));
|
||||
pZStream.next_out = otbuf;
|
||||
pZStream.avail_out = DEFLATE_BUF_SIZ;
|
||||
ZStream.SetOut(otbuf, DEFLATE_BUF_SIZ);
|
||||
ZStream.Init(DEFLATE_DEFAULT_COMPRESSION, -1);
|
||||
ZStream.SetIn(inbuf, 0);
|
||||
|
||||
deflateInit_(&pZStream, Z_DEFAULT_COMPRESSION, ZLIB_VERSION, sizeof(z_stream));
|
||||
|
||||
pZStream.next_in = inbuf;
|
||||
pZStream.avail_in = 0;
|
||||
for (;;)
|
||||
{
|
||||
unsigned int unSize = STREAM_BUF_SIZ;
|
||||
pStream->Read(inbuf, &unSize);
|
||||
|
||||
pZStream.next_in = inbuf;
|
||||
pZStream.avail_in = unSize;
|
||||
ZStream.SetIn(inbuf, unSize);
|
||||
|
||||
if (0 == unSize)
|
||||
break;
|
||||
|
||||
while (pZStream.avail_in > 0)
|
||||
while (ZStream.GetAvailIn() > 0)
|
||||
{
|
||||
deflate(&pZStream, Z_NO_FLUSH);
|
||||
ZStream.Process(DEFLATE_NO_FLUSH);
|
||||
|
||||
if (pZStream.avail_out == 0)
|
||||
if (ZStream.GetAvailOut() == 0)
|
||||
{
|
||||
if (pEncrypt)
|
||||
{
|
||||
@ -405,8 +400,7 @@ namespace PdfWriter
|
||||
else
|
||||
Write(otbuf, DEFLATE_BUF_SIZ);
|
||||
|
||||
pZStream.next_out = otbuf;
|
||||
pZStream.avail_out = DEFLATE_BUF_SIZ;
|
||||
ZStream.SetOut(otbuf, DEFLATE_BUF_SIZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -414,19 +408,19 @@ namespace PdfWriter
|
||||
bool bEnd = false;
|
||||
for (;;)
|
||||
{
|
||||
nRet = deflate(&pZStream, Z_FINISH);
|
||||
if (Z_OK != nRet && Z_STREAM_END != nRet)
|
||||
nRet = ZStream.Process(DEFLATE_FINISH);
|
||||
if (DEFLATE_OK != nRet && DEFLATE_STREAM_END != nRet)
|
||||
{
|
||||
deflateEnd(&pZStream);
|
||||
ZStream.End();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Z_STREAM_END == nRet)
|
||||
if (DEFLATE_STREAM_END == nRet)
|
||||
bEnd = true;
|
||||
|
||||
if (pZStream.avail_out < DEFLATE_BUF_SIZ)
|
||||
if (ZStream.GetAvailOut() < DEFLATE_BUF_SIZ)
|
||||
{
|
||||
unsigned int osize = DEFLATE_BUF_SIZ - pZStream.avail_out;
|
||||
unsigned int osize = DEFLATE_BUF_SIZ - ZStream.GetAvailOut();
|
||||
if (pEncrypt)
|
||||
{
|
||||
pEncrypt->CryptBuf(otbuf, ebuf, osize);
|
||||
@ -435,15 +429,14 @@ namespace PdfWriter
|
||||
else
|
||||
Write(otbuf, osize);
|
||||
|
||||
pZStream.next_out = otbuf;
|
||||
pZStream.avail_out = DEFLATE_BUF_SIZ;
|
||||
ZStream.SetOut(otbuf, DEFLATE_BUF_SIZ);
|
||||
}
|
||||
|
||||
if (bEnd)
|
||||
break;
|
||||
}
|
||||
|
||||
deflateEnd(&pZStream);
|
||||
ZStream.End();
|
||||
}
|
||||
void CStream::WriteStream(CStream* pStream, unsigned int unFilter, CEncrypt *pEncrypt)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user