Commit 1e35ce87 authored by Oleg Korshul's avatar Oleg Korshul Committed by Alexander Trofimov

сделал общий интерфейс для открытия PdfReader, Djvu, Xps

parent 7fa8727e
#include "DjVu.h"
#include "DjVuFileImplementation.h"
#include "../DesktopEditor/fontengine/ApplicationFonts.h"
class CApplicationFonts;
CDjVuFile::CDjVuFile()
CDjVuFile::CDjVuFile(CApplicationFonts* pFonts)
{
m_pImplementation = new CDjVuFileImplementation();
m_pImplementation = new CDjVuFileImplementation(pFonts);
}
CDjVuFile::~CDjVuFile()
{
if (m_pImplementation)
delete m_pImplementation;
}
bool CDjVuFile::LoadFromFile(const std::wstring& wsSrcFileName, const std::wstring& wsXMLOptions)
bool CDjVuFile::LoadFromFile(const std::wstring& file, const std::wstring& options,
const std::wstring& owner_password, const std::wstring& user_password)
{
if (m_pImplementation)
return m_pImplementation->LoadFromFile(wsSrcFileName, wsXMLOptions);
if (m_pImplementation)
return m_pImplementation->LoadFromFile(file, options);
return false;
return false;
}
void CDjVuFile::Close()
void CDjVuFile::Close()
{
if (m_pImplementation)
m_pImplementation->Close();
}
std::wstring CDjVuFile::GetTempDirectory() const
{
if (m_pImplementation)
return m_pImplementation->GetTempDirectory();
return L"";
std::wstring CDjVuFile::GetTempDirectory()
{
return m_pImplementation ? m_pImplementation->GetTempDirectory() : L"";
}
void CDjVuFile::SetTempDirectory(const std::wstring& wsDirectory)
void CDjVuFile::SetTempDirectory(const std::wstring& wsDirectory)
{
if (m_pImplementation)
m_pImplementation->SetTempDirectory(wsDirectory);
}
int CDjVuFile::GetPagesCount() const
int CDjVuFile::GetPagesCount()
{
if (m_pImplementation)
return m_pImplementation->GetPagesCount();
return 0;
}
void CDjVuFile::GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY) const
void CDjVuFile::GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY)
{
if (m_pImplementation)
m_pImplementation->GetPageInfo(nPageIndex, pdWidth, pdHeight, pdDpiX, pdDpiY);
}
void CDjVuFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak)
void CDjVuFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak)
{
if (m_pImplementation)
m_pImplementation->DrawPageOnRenderer(pRenderer, nPageIndex, pBreak);
}
void CDjVuFile::ConvertToRaster(CApplicationFonts* pAppFonts, int nPageIndex, const std::wstring& wsDstPath, int nImageType)
void CDjVuFile::ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType)
{
if (m_pImplementation)
m_pImplementation->ConvertToRaster(pAppFonts, nPageIndex, wsDstPath, nImageType);
m_pImplementation->ConvertToRaster(nPageIndex, wsDstPath, nImageType);
}
void CDjVuFile::ConvertToPdf(CApplicationFonts* pAppFonts, const std::wstring& wsDstPath)
void CDjVuFile::ConvertToPdf(const std::wstring& wsDstPath)
{
if (m_pImplementation)
m_pImplementation->ConvertToPdf(pAppFonts, wsDstPath);
m_pImplementation->ConvertToPdf(wsDstPath);
}
#pragma once
#include <string>
#include "../DesktopEditor/graphics/IRenderer.h"
#ifndef DJVU_USE_DYNAMIC_LIBRARY
#define DJVU_DECL_EXPORT
#else
......@@ -10,28 +7,33 @@
#define DJVU_DECL_EXPORT Q_DECL_EXPORT
#endif
// –аботаем через класс CDjVuFileImplementation, чтобы когда цепл¤лс¤ данный h-файл, ничего лишнего не инклюдилось
#include "../DesktopEditor/common/officedrawingfile.h"
// работаем через класс CDjVuFileImplementation, чтобы когда цеплялся данный h-файл, ничего лишнего не инклюдилось
class CDjVuFileImplementation;
class CApplicationFonts;
class DJVU_DECL_EXPORT CDjVuFile
class DJVU_DECL_EXPORT CDjVuFile : public IOfficeDrawingFile
{
private:
CDjVuFileImplementation* m_pImplementation;
public:
CDjVuFile();
~CDjVuFile();
bool LoadFromFile(const std::wstring& wsSrcFileName, const std::wstring& wsXmlOptions = L"");
void Close();
std::wstring GetTempDirectory() const;
void SetTempDirectory(const std::wstring& wsDirectory);
int GetPagesCount() const;
void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY) const;
void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
void ConvertToRaster(CApplicationFonts* pAppFonts, int nPageIndex, const std::wstring& wsDstPath, int nImageType);
void ConvertToPdf(CApplicationFonts* pAppFonts, const std::wstring& wsDstPath);
CDjVuFile(CApplicationFonts* fonts);
virtual ~CDjVuFile();
virtual bool LoadFromFile(const std::wstring& file, const std::wstring& options = L"",
const std::wstring& owner_password = L"", const std::wstring& user_password = L"");
virtual void Close();
virtual std::wstring GetTempDirectory();
virtual void SetTempDirectory(const std::wstring& directory);
virtual int GetPagesCount();
virtual void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY);
virtual void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
virtual void ConvertToRaster(int nPageIndex, const std::wstring& path, int nImageType);
void ConvertToPdf(const std::wstring& path);
};
......@@ -58,13 +58,15 @@ namespace NSDjvu
}
}
CDjVuFileImplementation::CDjVuFileImplementation()
CDjVuFileImplementation::CDjVuFileImplementation(CApplicationFonts* pFonts)
{
m_pDoc = NULL;
std::wstring wsTempPath = NSFile::CFileBinary::GetTempPath();
wsTempPath += L"DJVU\\";
m_wsTempDirectory = wsTempPath;
NSDirectory::CreateDirectory(m_wsTempDirectory);
m_pApplicationFonts = pFonts;
}
CDjVuFileImplementation::~CDjVuFileImplementation()
{
......@@ -164,11 +166,14 @@ void CDjVuFileImplementation::DrawPageOnRenderer(IRenderer* pRende
// белая страница
}
}
void CDjVuFileImplementation::ConvertToRaster(CApplicationFonts* pAppFonts, int nPageIndex, const std::wstring& wsDstPath, int nImageType)
void CDjVuFileImplementation::ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType)
{
CFontManager *pFontManager = pAppFonts->GenerateFontManager();
if (!m_pApplicationFonts)
return;
CFontManager *pFontManager = m_pApplicationFonts->GenerateFontManager();
CFontsCache* pFontCache = new CFontsCache();
pFontCache->SetStreams(pAppFonts->GetStreams());
pFontCache->SetStreams(m_pApplicationFonts->GetStreams());
pFontManager->SetOwnerCache(pFontCache);
CGraphicsRenderer oRenderer;
......@@ -203,9 +208,9 @@ void CDjVuFileImplementation::ConvertToRaster(CApplicationFonts* p
oFrame.SaveFile(wsDstPath, nImageType);
RELEASEINTERFACE(pFontManager);
}
void CDjVuFileImplementation::ConvertToPdf(CApplicationFonts* pAppFonts, const std::wstring& wsDstPath)
void CDjVuFileImplementation::ConvertToPdf(const std::wstring& wsDstPath)
{
CPdfRenderer oPdf(pAppFonts);
CPdfRenderer oPdf(m_pApplicationFonts);
bool bBreak = false;
for (int nPageIndex = 0, nPagesCount = GetPagesCount(); nPageIndex < nPagesCount; nPageIndex++)
......
......@@ -32,10 +32,11 @@ private:
std::wstring m_wsTempDirectory;
GP<DjVuDocument> m_pDoc;
CApplicationFonts* m_pApplicationFonts;
public:
CDjVuFileImplementation();
CDjVuFileImplementation(CApplicationFonts* pFonts);
~CDjVuFileImplementation();
bool LoadFromFile(const std::wstring& wsSrcFileName, const std::wstring& wsXmlOptions = L"");
......@@ -45,8 +46,8 @@ public:
int GetPagesCount() const;
void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY) const;
void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
void ConvertToRaster(CApplicationFonts* pAppFonts, int nPageIndex, const std::wstring& wsDstPath, int nImageType);
void ConvertToPdf(CApplicationFonts* pAppFonts, const std::wstring& wsDstPath);
void ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType);
void ConvertToPdf(const std::wstring& wsDstPath);
private:
......
This diff is collapsed.
#ifndef _PDF_READER_H
#define _PDF_READER_H
#include "Src/ErrorConstants.h"
class IRenderer;
class CFontManager;
class CApplicationFonts;
#ifndef PDFREADER_USE_DYNAMIC_LIBRARY
#define PDFREADER_DECL_EXPORT
#else
......@@ -14,48 +8,44 @@ class CApplicationFonts;
#define PDFREADER_DECL_EXPORT Q_DECL_EXPORT
#endif
#include "Src/ErrorConstants.h"
#include "../DesktopEditor/common/officedrawingfile.h"
namespace PdfReader
{
class PDFDoc;
class GlobalParams;
class CFontList;
class CPdfReader_Private;
class PDFREADER_DECL_EXPORT CPdfReader
{
public:
CPdfReader(CApplicationFonts* pAppFonts);
CPdfReader(CApplicationFonts* fonts);
~CPdfReader();
bool LoadFromFile(const wchar_t* wsSrcPath, const wchar_t* wsOwnerPassword = 0, const wchar_t* wsUserPassword = 0, const wchar_t* wsOptions = 0);
void Close();
EError GetError();
double GetVersion();
int GetPermissions();
int GetPagesCount();
void GetPageSize(int nPageIndex, double* pdWidth, double* pdHeight);
void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY);
void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pbBreak);
void ConvertToRaster(int nPageIndex, const wchar_t* wsDstPath, int nImageType);
bool ExtractAllImages(const wchar_t* wsDstPath, const wchar_t* wsPrefix = 0);
virtual bool LoadFromFile(const std::wstring& file, const std::wstring& options = L"",
const std::wstring& owner_password = L"", const std::wstring& user_password = L"");
virtual void Close();
virtual std::wstring GetTempDirectory();
virtual void SetTempDirectory(const std::wstring& directory);
virtual int GetPagesCount();
virtual void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY);
virtual void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
virtual void ConvertToRaster(int nPageIndex, const std::wstring& path, int nImageType);
EError GetError();
double GetVersion();
int GetPermissions();
bool ExtractAllImages(const wchar_t* wsDstPath, const wchar_t* wsPrefix = 0);
int GetImagesCount();
void SetTempFolder(const wchar_t* wsTempFolder);
void SetCMapFolder(const wchar_t* wsCMapFolder);
void SetCMapFolder(const wchar_t* wsCMapFolder);
CFontManager*GetFontManager();
private:
PDFDoc* m_pPDFDocument;
GlobalParams* m_pGlobalParams;
wchar_t* m_wsTempFolder;
wchar_t* m_wsCMapFolder;
CApplicationFonts* m_pAppFonts;
CFontManager* m_pFontManager;
CFontList* m_pFontList;
CPdfReader_Private* m_pInternal;
};
}
......
......@@ -12,106 +12,125 @@
using namespace XPS;
CXpsFile::CXpsFile(CApplicationFonts* pAppFonts)
class CXpsFile_Private
{
m_pDocument = NULL;
m_pAppFonts = pAppFonts;
// Создаем менеджер шрифтов с собственным кэшем
m_pFontManager = pAppFonts->GenerateFontManager();
CFontsCache* pMeasurerCache = new CFontsCache();
pMeasurerCache->SetStreams(pAppFonts->GetStreams());
m_pFontManager->SetOwnerCache(pMeasurerCache);
pMeasurerCache->SetCacheSize(16);
public:
CApplicationFonts* m_pAppFonts;
CFontManager* m_pFontManager;
std::wstring m_wsTempFolder;
XPS::CDocument* m_pDocument;
public:
CXpsFile_Private(CApplicationFonts* pAppFonts)
{
m_pDocument = NULL;
m_pAppFonts = pAppFonts;
// Создаем менеджер шрифтов с собственным кэшем
m_pFontManager = pAppFonts->GenerateFontManager();
CFontsCache* pMeasurerCache = new CFontsCache();
pMeasurerCache->SetStreams(pAppFonts->GetStreams());
m_pFontManager->SetOwnerCache(pMeasurerCache);
pMeasurerCache->SetCacheSize(16);
m_wsTempFolder = L"";
}
~CXpsFile_Private()
{
}
};
m_wsTempFolder = L"";
SetTempFolder(NSFile::CFileBinary::GetTempPath());
CXpsFile::CXpsFile(CApplicationFonts* pAppFonts)
{
m_pInternal = new CXpsFile_Private(pAppFonts);
SetTempDirectory(NSFile::CFileBinary::GetTempPath());
}
CXpsFile::~CXpsFile()
{
if (L"" != m_wsTempFolder)
NSDirectory::DeleteDirectory(m_wsTempFolder);
if (L"" != m_pInternal->m_wsTempFolder)
NSDirectory::DeleteDirectory(m_pInternal->m_wsTempFolder);
Close();
RELEASEINTERFACE(m_pFontManager);
RELEASEINTERFACE((m_pInternal->m_pFontManager));
}
std::wstring CXpsFile::GetTempFolder() const
std::wstring CXpsFile::GetTempDirectory()
{
return m_wsTempFolder;
return m_pInternal->m_wsTempFolder;
}
void CXpsFile::SetTempFolder(const std::wstring& wsPath)
void CXpsFile::SetTempDirectory(const std::wstring& wsPath)
{
if (L"" != m_wsTempFolder)
NSDirectory::DeleteDirectory(m_wsTempFolder);
if (L"" != m_pInternal->m_wsTempFolder)
NSDirectory::DeleteDirectory(m_pInternal->m_wsTempFolder);
int nCounter = 0;
m_wsTempFolder = wsPath + L"/XPS/";
while (NSDirectory::Exists(m_wsTempFolder))
m_pInternal->m_wsTempFolder = wsPath + L"/XPS/";
while (NSDirectory::Exists(m_pInternal->m_wsTempFolder))
{
m_wsTempFolder = wsPath + L"/XPS" + std::to_wstring(nCounter) + L"/";
m_pInternal->m_wsTempFolder = wsPath + L"/XPS" + std::to_wstring(nCounter) + L"/";
nCounter++;
}
NSDirectory::CreateDirectory(m_wsTempFolder);
NSDirectory::CreateDirectory(m_pInternal->m_wsTempFolder);
}
bool CXpsFile::LoadFromFile(const std::wstring& wsSrcFileName, const std::wstring& wsXmlOptions)
bool CXpsFile::LoadFromFile(const std::wstring& wsSrcFileName, const std::wstring& wsXmlOptions,
const std::wstring& owner_password, const std::wstring& user_password)
{
Close();
// Распаковываем Zip-архив в темповую папку
COfficeUtils oUtils(NULL);
if (S_OK != oUtils.ExtractToDirectory(wsSrcFileName, m_wsTempFolder, NULL, 0))
if (S_OK != oUtils.ExtractToDirectory(wsSrcFileName, m_pInternal->m_wsTempFolder, NULL, 0))
return false;
m_pDocument = new XPS::CDocument(m_pFontManager);
if (!m_pDocument)
m_pInternal->m_pDocument = new XPS::CDocument(m_pInternal->m_pFontManager);
if (!m_pInternal->m_pDocument)
return false;
std::wstring wsPath = m_wsTempFolder + L"/";
m_pDocument->ReadFromPath(wsPath);
std::wstring wsPath = m_pInternal->m_wsTempFolder + L"/";
m_pInternal->m_pDocument->ReadFromPath(wsPath);
return true;
}
void CXpsFile::Close()
void CXpsFile::Close()
{
if (m_pDocument)
if (m_pInternal->m_pDocument)
{
m_pDocument->Close();
delete m_pDocument;
m_pDocument = NULL;
m_pInternal->m_pDocument->Close();
delete m_pInternal->m_pDocument;
m_pInternal->m_pDocument = NULL;
}
}
int CXpsFile::GetPagesCount()
int CXpsFile::GetPagesCount()
{
if (!m_pDocument)
if (!m_pInternal->m_pDocument)
return 0;
return m_pDocument->GetPageCount();
return m_pInternal->m_pDocument->GetPageCount();
}
void CXpsFile::GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY)
void CXpsFile::GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY)
{
int nW = 0, nH = 0;
if (m_pDocument)
m_pDocument->GetPageSize(nPageIndex, nW, nH);
if (m_pInternal->m_pDocument)
m_pInternal->m_pDocument->GetPageSize(nPageIndex, nW, nH);
*pdWidth = nW * 25.4 / 96;
*pdHeight = nH * 25.4 / 96;
*pdDpiX = 25.4;
*pdDpiY = 25.4;
}
void CXpsFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak)
void CXpsFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak)
{
if (!m_pDocument)
if (!m_pInternal->m_pDocument)
return;
m_pDocument->DrawPage(nPageIndex, pRenderer, pBreak);
m_pInternal->m_pDocument->DrawPage(nPageIndex, pRenderer, pBreak);
}
void CXpsFile::ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType)
void CXpsFile::ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType)
{
CFontManager *pFontManager = m_pAppFonts->GenerateFontManager();
CFontManager *pFontManager = m_pInternal->m_pAppFonts->GenerateFontManager();
CFontsCache* pFontCache = new CFontsCache();
pFontCache->SetStreams(m_pAppFonts->GetStreams());
pFontCache->SetStreams(m_pInternal->m_pAppFonts->GetStreams());
pFontManager->SetOwnerCache(pFontCache);
CGraphicsRenderer oRenderer;
......@@ -146,9 +165,9 @@ void CXpsFile::ConvertToRaster(int nPageIndex, const std::wstring& wsDst
oFrame.SaveFile(wsDstPath, nImageType);
RELEASEINTERFACE(pFontManager);
}
void CXpsFile::ConvertToPdf(const std::wstring& wsPath)
void CXpsFile::ConvertToPdf(const std::wstring& wsPath)
{
CPdfRenderer oPdf(m_pAppFonts);
CPdfRenderer oPdf(m_pInternal->m_pAppFonts);
bool bBreak = false;
int nPagesCount = GetPagesCount();
......
#ifndef _XPS_FILE_H
#define _XPS_FILE_H
#include <string>
#ifndef XPS_USE_DYNAMIC_LIBRARY
#define XPS_DECL_EXPORT
#else
......@@ -10,37 +8,32 @@
#define XPS_DECL_EXPORT Q_DECL_EXPORT
#endif
namespace XPS
{
class CDocument;
}
class IRenderer;
class CApplicationFonts;
class CFontManager;
#include "../DesktopEditor/common/officedrawingfile.h"
class CXpsFile_Private;
class XPS_DECL_EXPORT CXpsFile
{
public:
CXpsFile(CApplicationFonts* pAppFonts);
~CXpsFile();
bool LoadFromFile(const std::wstring& wsSrcFileName, const std::wstring& wsXmlOptions = L"");
void Close();
std::wstring GetTempFolder() const;
void SetTempFolder(const std::wstring& wsPath);
int GetPagesCount();
void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY);
void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
void ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType);
CXpsFile(CApplicationFonts* fonts);
virtual ~CXpsFile();
virtual bool LoadFromFile(const std::wstring& file, const std::wstring& options = L"",
const std::wstring& owner_password = L"", const std::wstring& user_password = L"");
virtual void Close();
virtual std::wstring GetTempDirectory();
virtual void SetTempDirectory(const std::wstring& directory);
virtual int GetPagesCount();
virtual void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY);
virtual void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
virtual void ConvertToRaster(int nPageIndex, const std::wstring& path, int nImageType);
void ConvertToPdf(const std::wstring& wsDstPath);
private:
CApplicationFonts* m_pAppFonts;
CFontManager* m_pFontManager;
std::wstring m_wsTempFolder;
XPS::CDocument* m_pDocument;
CXpsFile_Private* m_pInternal;
};
#endif // _XPS_FILE_H
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