djvu GetInfo

This commit is contained in:
Kulikova Svetlana
2022-03-10 17:40:05 +03:00
parent 0852fc134e
commit 8ef62fd670
5 changed files with 71 additions and 10 deletions

View File

@ -157,9 +157,9 @@ static DWORD GetLength(BYTE* x)
int main()
{
#define XPS_TEST 1
#define XPS_TEST 0
#define DJVU_TEST 0
#define PDF_TEST 0
#define PDF_TEST 1
#if PDF_TEST
BYTE* pPdfData = NULL;
DWORD nPdfBytesCount;
@ -405,11 +405,11 @@ int main()
RELEASEARRAYOBJECTS(pDjVuData);
return 1;
}
int* info = GetInfo(test);
int pages_count = *info;
int* size = GetSize(test);
int pages_count = *size;
int test_page = 1;
int width = info[test_page * 3 + 1];
int height = info[test_page * 3 + 2];
int width = size[test_page * 3 + 1];
int height = size[test_page * 3 + 2];
std::cout << "Page " << test_page << " width " << width << " height " << height << std::endl;
std::cout << std::endl;
@ -435,7 +435,7 @@ int main()
BYTE* res = NULL;
if (pages_count > 0)
res = GetPixmap(test, test_page, width, height);
res = GetPixmap(test, test_page, width, height, 0xFFFFFF);
CBgraFrame* resFrame = new CBgraFrame();
resFrame->put_Data(res);
@ -446,6 +446,10 @@ int main()
resFrame->SaveFile(NSFile::GetProcessDirectory() + L"/res.png", _CXIMAGE_FORMAT_PNG);
resFrame->ClearNoAttack();
BYTE* info = GetInfo(test);
nLength = GetLength(info + 4);
std::cout << "json "<< std::string((char*)(info + 8), nLength);
std::cout << std::endl;
BYTE* pGlyphs = GetGlyphs(test, test_page);
@ -479,9 +483,9 @@ int main()
Close(test);
RELEASEARRAYOBJECTS(pDjVuData);
RELEASEARRAYOBJECTS(size);
RELEASEARRAYOBJECTS(info);
RELEASEARRAYOBJECTS(res);
RELEASEARRAYOBJECTS(pGlyphs);
RELEASEARRAYOBJECTS(pLinks);
RELEASEARRAYOBJECTS(pStructure);
RELEASEOBJECT(resFrame);

View File

@ -100,6 +100,8 @@ void CDjVuFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* p
}
BYTE* CDjVuFile::GetInfo()
{
if (m_pImplementation)
return m_pImplementation->GetInfo();
return NULL;
}
void CDjVuFile::ConvertToPdf(const std::wstring& wsDstPath)

View File

@ -258,6 +258,40 @@ void CDjVuFileImplementation::ConvertToPdf(const std::wstring& wsDstPath)
oPdf.SaveToFile(wsDstPath);
}
BYTE* CDjVuFileImplementation::GetInfo()
{
NSWasm::CData oRes;
oRes.SkipLen();
std::string sRes = "{";
double nW = 0;
double nH = 0;
double nDpi = 0;
GetPageInfo(0, &nW, &nH, &nDpi, &nDpi);
sRes += "\"PageSize\":\"";
std::string version = std::to_string(nW);
sRes += version.substr(0, version.length() - 4);
sRes += "x";
version = std::to_string(nH);
sRes += version.substr(0, version.length() - 4);
sRes += "\",";
sRes += "\"NumberOfPages\":";
sRes += std::to_string(GetPagesCount());
sRes += ",";
if (sRes[sRes.size() - 1] == ',')
sRes.pop_back();
sRes += "}";
oRes.WriteString((BYTE*)sRes.c_str(), sRes.length());
oRes.WriteLen();
BYTE* bRes = oRes.GetBuffer();
oRes.ClearWithoutAttack();
return bRes;
}
#ifdef BUILDING_WASM_MODULE
void getBookmars(const GP<DjVmNav>& nav, int& pos, int count, NSWasm::CData& out, int level)

View File

@ -77,6 +77,7 @@ public:
void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY) const;
void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
void ConvertToPdf(const std::wstring& wsDstPath);
BYTE* GetInfo();
#ifdef BUILDING_WASM_MODULE
BYTE* GetStructure();

View File

@ -450,6 +450,25 @@ return 0;
}\
}\
#define DICT_LOOKUP_DATE(info, obj1, name) \
if (info.dictLookup(name, &obj1)->isString())\
{\
char* str = obj1.getString()->getCString();\
int length = obj1.getString()->getLength();\
if (str && length > 21)\
{\
std::string sNoDate = std::string(str, length);\
std::string sDate = sNoDate.substr(2, 4) + '-' + sNoDate.substr(6, 2) + '-' + sNoDate.substr(8, 2) + 'T' +\
sNoDate.substr(10, 2) + ':' + sNoDate.substr(12, 2) + ':' + sNoDate.substr(14, 2) + ".000+" +\
sNoDate.substr(17, 2) + ':' + sNoDate.substr(20, 2);\
sRes += "\"";\
sRes += name;\
sRes += "\":\"";\
sRes += sDate;\
sRes += "\",";\
}\
}\
BYTE* CPdfReader::GetInfo()
{
if (!m_pInternal->m_pPDFDocument)
@ -467,8 +486,9 @@ return 0;
DICT_LOOKUP(info, obj1, "Keywords");
DICT_LOOKUP(info, obj1, "Creator");
DICT_LOOKUP(info, obj1, "Producer");
DICT_LOOKUP(info, obj1, "CreationDate");
DICT_LOOKUP(info, obj1, "ModDate");
DICT_LOOKUP_DATE(info, obj1, "CreationDate");
DICT_LOOKUP_DATE(info, obj1, "ModDate");
std::string version = std::to_string(GetVersion());
sRes += "\"Version\":";