mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
optimization
This commit is contained in:
@ -52,6 +52,8 @@ bool CDjVuFile::LoadFromFile(const std::wstring& file, const std::wstring& optio
|
|||||||
bool CDjVuFile::LoadFromMemory(BYTE* data, DWORD length, const std::wstring& options,
|
bool CDjVuFile::LoadFromMemory(BYTE* data, DWORD length, const std::wstring& options,
|
||||||
const std::wstring& owner_password, const std::wstring& user_password)
|
const std::wstring& owner_password, const std::wstring& user_password)
|
||||||
{
|
{
|
||||||
|
if (m_pImplementation)
|
||||||
|
return m_pImplementation->LoadFromMemory(data, length, options);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,6 +91,8 @@ void CDjVuFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* p
|
|||||||
}
|
}
|
||||||
BYTE* CDjVuFile::ConvertToPixels(int nPageIndex, int nRasterW, int nRasterH)
|
BYTE* CDjVuFile::ConvertToPixels(int nPageIndex, int nRasterW, int nRasterH)
|
||||||
{
|
{
|
||||||
|
if (m_pImplementation)
|
||||||
|
return m_pImplementation->ConvertToPixels(nPageIndex, nRasterW, nRasterH);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
void CDjVuFile::ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType, const int nRasterW, const int nRasterH)
|
void CDjVuFile::ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType, const int nRasterW, const int nRasterH)
|
||||||
|
|||||||
@ -115,6 +115,22 @@ bool CDjVuFileImplementation::LoadFromFile(const std::wstring& wsS
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
bool CDjVuFileImplementation::LoadFromMemory(BYTE* data, DWORD length, const std::wstring& wsXmlOptions)
|
||||||
|
{
|
||||||
|
m_pDoc = NULL;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
GP<ByteStream> stream = ByteStream::create(data, (size_t)length);
|
||||||
|
m_pDoc = DjVuDocument::create(stream);
|
||||||
|
m_pDoc->wait_get_pages_num();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
void CDjVuFileImplementation::Close()
|
void CDjVuFileImplementation::Close()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -202,6 +218,51 @@ void CDjVuFileImplementation::DrawPageOnRenderer(IRenderer* pRende
|
|||||||
// белая страница
|
// белая страница
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BYTE* CDjVuFileImplementation::ConvertToPixels(int nPageIndex, const int& nRasterW, const int& nRasterH)
|
||||||
|
{
|
||||||
|
if (!m_pApplicationFonts)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
NSFonts::IFontManager *pFontManager = m_pApplicationFonts->GenerateFontManager();
|
||||||
|
NSFonts::IFontsCache* pFontCache = NSFonts::NSFontCache::Create();
|
||||||
|
pFontCache->SetStreams(m_pApplicationFonts->GetStreams());
|
||||||
|
pFontManager->SetOwnerCache(pFontCache);
|
||||||
|
|
||||||
|
NSGraphics::IGraphicsRenderer* pRenderer = NSGraphics::Create();
|
||||||
|
pRenderer->SetFontManager(pFontManager);
|
||||||
|
|
||||||
|
double dPageDpiX, dPageDpiY;
|
||||||
|
double dWidth, dHeight;
|
||||||
|
GetPageInfo(nPageIndex, &dWidth, &dHeight, &dPageDpiX, &dPageDpiX);
|
||||||
|
|
||||||
|
int nWidth = (nRasterW > 0) ? nRasterW : ((int)dWidth * 96 / dPageDpiX);
|
||||||
|
int nHeight = (nRasterH > 0) ? nRasterH : ((int)dHeight * 96 / dPageDpiX);
|
||||||
|
|
||||||
|
BYTE* pBgraData = new BYTE[nWidth * nHeight * 4];
|
||||||
|
if (!pBgraData)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
memset(pBgraData, 0xff, nWidth * nHeight * 4);
|
||||||
|
CBgraFrame oFrame;
|
||||||
|
oFrame.put_Data(pBgraData);
|
||||||
|
oFrame.put_Width(nWidth);
|
||||||
|
oFrame.put_Height(nHeight);
|
||||||
|
oFrame.put_Stride(-4 * nWidth);
|
||||||
|
|
||||||
|
pRenderer->CreateFromBgraFrame(&oFrame);
|
||||||
|
pRenderer->SetSwapRGB(true);
|
||||||
|
pRenderer->put_Width(dWidth);
|
||||||
|
pRenderer->put_Height(dHeight);
|
||||||
|
|
||||||
|
bool bBreak = false;
|
||||||
|
DrawPageOnRenderer(pRenderer, nPageIndex, &bBreak);
|
||||||
|
|
||||||
|
RELEASEINTERFACE(pFontManager);
|
||||||
|
RELEASEOBJECT(pRenderer);
|
||||||
|
oFrame.ClearNoAttack();
|
||||||
|
|
||||||
|
return pBgraData;
|
||||||
|
}
|
||||||
void CDjVuFileImplementation::ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType, const int& nRasterW, const int& nRasterH)
|
void CDjVuFileImplementation::ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType, const int& nRasterW, const int& nRasterH)
|
||||||
{
|
{
|
||||||
if (!m_pApplicationFonts)
|
if (!m_pApplicationFonts)
|
||||||
|
|||||||
@ -69,12 +69,14 @@ public:
|
|||||||
~CDjVuFileImplementation();
|
~CDjVuFileImplementation();
|
||||||
|
|
||||||
bool LoadFromFile(const std::wstring& wsSrcFileName, const std::wstring& wsXmlOptions = L"");
|
bool LoadFromFile(const std::wstring& wsSrcFileName, const std::wstring& wsXmlOptions = L"");
|
||||||
|
bool LoadFromMemory(BYTE* data, DWORD length, const std::wstring& wsXmlOptions = L"");
|
||||||
void Close();
|
void Close();
|
||||||
std::wstring GetTempDirectory() const;
|
std::wstring GetTempDirectory() const;
|
||||||
void SetTempDirectory(const std::wstring& wsDirectory);
|
void SetTempDirectory(const std::wstring& wsDirectory);
|
||||||
int GetPagesCount() const;
|
int GetPagesCount() const;
|
||||||
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);
|
||||||
|
BYTE* ConvertToPixels(int nPageIndex, const int& nRasterW = -1, const int& nRasterH = -1);
|
||||||
void ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType, const int& nRasterW = -1, const int& nRasterH = -1);
|
void ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType, const int& nRasterW = -1, const int& nRasterH = -1);
|
||||||
void ConvertToPdf(const std::wstring& wsDstPath);
|
void ConvertToPdf(const std::wstring& wsDstPath);
|
||||||
|
|
||||||
|
|||||||
@ -226,7 +226,7 @@ int main(int argc, char *argv[])
|
|||||||
int pages_count = *info;
|
int pages_count = *info;
|
||||||
if (pages_count > 0)
|
if (pages_count > 0)
|
||||||
{
|
{
|
||||||
unsigned char* pixmap = DJVU_GetPixmap(file, 0, 300, 300);
|
unsigned char* pixmap = DJVU_GetPixmap(file, 0, info[1] * 96 / info[3], info[2] * 96 / info[3]);
|
||||||
delete [] pixmap;
|
delete [] pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -125,14 +125,6 @@ void CZipBuffer::move(const std::string& sSrc, const std::string& sDst)
|
|||||||
if (it != m_arrFiles.end())
|
if (it != m_arrFiles.end())
|
||||||
it->m_sPath = sDst;
|
it->m_sPath = sDst;
|
||||||
}
|
}
|
||||||
// Возвращает вектор путей в архиве
|
|
||||||
std::vector<std::string> CZipBuffer::getPaths()
|
|
||||||
{
|
|
||||||
std::vector<std::string> oRes;
|
|
||||||
for (CFile& oFile : m_arrFiles)
|
|
||||||
oRes.push_back(oFile.m_sPath);
|
|
||||||
return oRes;
|
|
||||||
}
|
|
||||||
// Сохраняет архив в переданную память, полученные данные необходимо освободить
|
// Сохраняет архив в переданную память, полученные данные необходимо освободить
|
||||||
void CZipBuffer::save(BYTE*& data, DWORD& length)
|
void CZipBuffer::save(BYTE*& data, DWORD& length)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -28,6 +28,8 @@ private:
|
|||||||
};
|
};
|
||||||
// Вектор файлов в архиве
|
// Вектор файлов в архиве
|
||||||
std::vector<CFile> m_arrFiles;
|
std::vector<CFile> m_arrFiles;
|
||||||
|
|
||||||
|
friend class CZipFolderMemory;
|
||||||
public:
|
public:
|
||||||
// Создает архив в памяти
|
// Создает архив в памяти
|
||||||
CZipBuffer()
|
CZipBuffer()
|
||||||
|
|||||||
@ -289,8 +289,7 @@ public:
|
|||||||
virtual bool exists(const std::wstring& path)
|
virtual bool exists(const std::wstring& path)
|
||||||
{
|
{
|
||||||
std::string sPath = getLocalFilePathA(path);
|
std::string sPath = getLocalFilePathA(path);
|
||||||
std::vector<std::string> sPaths = m_zlib->getPaths();
|
return std::find_if(m_zlib->m_arrFiles.begin(), m_zlib->m_arrFiles.end(), [sPath](const CZipBuffer::CFile& file){ return file.m_sPath == sPath; }) != m_zlib->m_arrFiles.end();
|
||||||
return std::find(sPaths.begin(), sPaths.end(), sPath) != sPaths.end();
|
|
||||||
}
|
}
|
||||||
// Удаляет файл по относительному пути в архиве
|
// Удаляет файл по относительному пути в архиве
|
||||||
virtual void remove(const std::wstring& path)
|
virtual void remove(const std::wstring& path)
|
||||||
@ -302,28 +301,27 @@ public:
|
|||||||
virtual void createDirectory(const std::wstring& path)
|
virtual void createDirectory(const std::wstring& path)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
// Возвращает вектор путей в архиве до файлов расположенной в папке
|
// Возвращает вектор путей расположенных в папке
|
||||||
virtual std::vector<std::wstring> getFiles(const std::wstring& path, bool bIsRecursion)
|
virtual std::vector<std::wstring> getFiles(const std::wstring& path, bool bIsRecursion)
|
||||||
{
|
{
|
||||||
std::string sPath = getLocalFilePathA(path);
|
std::string sPath = getLocalFilePathA(path);
|
||||||
std::vector<std::string> sPaths = m_zlib->getPaths();
|
|
||||||
std::vector<std::wstring> sRes;
|
std::vector<std::wstring> sRes;
|
||||||
|
|
||||||
for (std::string& i : sPaths)
|
for (const CZipBuffer::CFile& i : m_zlib->m_arrFiles)
|
||||||
{
|
{
|
||||||
if (bIsRecursion)
|
if (bIsRecursion)
|
||||||
{
|
{
|
||||||
if (i.find(sPath) == 0)
|
if (i.m_sPath.find(sPath) == 0)
|
||||||
sRes.push_back(L'/' + UTF8_TO_U(i));
|
sRes.push_back(L'/' + UTF8_TO_U(i.m_sPath));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
size_t nFindDirectory = i.find(sPath);
|
size_t nFindDirectory = i.m_sPath.find(sPath);
|
||||||
if (nFindDirectory == 0)
|
if (nFindDirectory == 0)
|
||||||
{
|
{
|
||||||
nFindDirectory = i.find_first_of("\\/", sPath.length());
|
nFindDirectory = i.m_sPath.find_first_of("\\/", sPath.length());
|
||||||
if (nFindDirectory != std::wstring::npos && i.find_first_of("\\/", nFindDirectory + 1) == std::wstring::npos)
|
if (nFindDirectory != std::wstring::npos && i.m_sPath.find_first_of("\\/", nFindDirectory + 1) == std::wstring::npos)
|
||||||
sRes.push_back(L'/' + UTF8_TO_U(i));
|
sRes.push_back(L'/' + UTF8_TO_U(i.m_sPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user