fix coords

This commit is contained in:
Kulikova Svetlana
2021-10-15 16:03:26 +03:00
parent fafa2023d1
commit e20588a3da
14 changed files with 165 additions and 175 deletions

View File

@ -67,8 +67,8 @@ public:
virtual void ConvertToRaster(int nPageIndex, const std::wstring& path, int nImageType, const int nRasterW = -1, const int nRasterH = -1) = 0;
#ifdef BUILDING_WASM_MODULE
virtual unsigned char* GetStructure() = 0;
virtual unsigned char* GetGlyphs(int nPageIndex, int nRasterW, int nRasterH) = 0;
virtual unsigned char* GetLinks (int nPageIndex, int nRasterW, int nRasterH) = 0;
virtual unsigned char* GetGlyphs(int nPageIndex) = 0;
virtual unsigned char* GetLinks (int nPageIndex) = 0;
#endif
};

View File

@ -296,6 +296,7 @@
{
var rec = {};
rec["link"] = reader.readString();
rec["dest"] = reader.readDouble();
rec["x"] = (this.type == 2 ? 1.015 : 1) * reader.readDouble();
rec["y"] = (this.type == 2 ? 1.015 : 1) * reader.readDouble();
rec["w"] = reader.readDouble();

View File

@ -121,13 +121,13 @@ WASM_EXPORT BYTE* GetPixmap (CGraphicsFileDrawing* pGraphics, int nPageIndex, in
{
return pGraphics->GetPage(nPageIndex, nRasterW, nRasterH);
}
WASM_EXPORT BYTE* GetGlyphs (CGraphicsFileDrawing* pGraphics, int nPageIndex, int nRasterW, int nRasterH)
WASM_EXPORT BYTE* GetGlyphs (CGraphicsFileDrawing* pGraphics, int nPageIndex)
{
return pGraphics->GetGlyphs(nPageIndex, nRasterW, nRasterH);
return pGraphics->GetGlyphs(nPageIndex);
}
WASM_EXPORT BYTE* GetLinks (CGraphicsFileDrawing* pGraphics, int nPageIndex, int nRasterW, int nRasterH)
WASM_EXPORT BYTE* GetLinks (CGraphicsFileDrawing* pGraphics, int nPageIndex)
{
return pGraphics->GetLinks(nPageIndex, nRasterW, nRasterH);
return pGraphics->GetLinks(nPageIndex);
}
WASM_EXPORT BYTE* GetStructure(CGraphicsFileDrawing* pGraphics)
{
@ -163,16 +163,16 @@ int main()
CGraphicsFileDrawing* test = Open(pPdfData, nPdfBytesCount);
int* info = GetInfo(test);
int pages_count = *info;
int width = info[1] * 96 / info[3];
int height = info[2] * 96 / info[3];
int test_page = 0;
int width = info[test_page * 3 + 1];
int height = info[test_page * 3 + 2];
std::cout << "Page " << test_page << " width " << width << " height " << height << std::endl;
width *= 96.0 / (double)info[test_page * 3 + 3];
height *= 96.0 / (double)info[test_page * 3 + 3];
BYTE* res = NULL;
if (pages_count > 0)
res = GetPixmap(test, 0, width, height);
for (int i = 0; i < 100; i++)
std::cout << (int)res[i] << " ";
std::cout << std::endl;
res = GetPixmap(test, test_page, width, height);
CBgraFrame* resFrame = new CBgraFrame();
resFrame->put_Data(res);
@ -183,7 +183,8 @@ int main()
resFrame->SaveFile(NSFile::GetProcessDirectory() + L"/res.png", _CXIMAGE_FORMAT_PNG);
resFrame->ClearNoAttack();
BYTE* pLinks = GetLinks(test, 0, width, height);
std::cout << std::endl;
BYTE* pLinks = GetLinks(test, test_page);
DWORD nLength = GetLength(pLinks);
DWORD i = 4;
nLength -= 4;
@ -195,6 +196,9 @@ int main()
i += nPathLength;
nPathLength = GetLength(pLinks + i);
i += 4;
std::cout << " Ydest " << (double)nPathLength / 100.0;
nPathLength = GetLength(pLinks + i);
i += 4;
std::cout << " X " << (double)nPathLength / 100.0;
nPathLength = GetLength(pLinks + i);
i += 4;
@ -207,6 +211,7 @@ int main()
std::cout << " H " << (double)nPathLength / 100.0 << std::endl;
}
std::cout << std::endl;
BYTE* pStructure = GetStructure(test);
nLength = GetLength(pStructure);
i = 4;
@ -228,7 +233,8 @@ int main()
i += nPathLength;
}
BYTE* pGlyphs = GetGlyphs(test, 0, width, height);
std::cout << std::endl;
BYTE* pGlyphs = GetGlyphs(test, test_page);
nLength = GetLength(pGlyphs);
i = 4;
nLength -= 4;
@ -304,13 +310,36 @@ int main()
oFile.CloseFile();
CGraphicsFileDrawing* test = Open(pXpsData, nXpsBytesCount);
RELEASEARRAYOBJECTS(pXpsData);
int* info = GetInfo(test);
int pages_count = *info;
int width = info[1] * 96 / info[3];
int height = info[2] * 96 / info[3];
int test_page = 22;
int width = info[test_page * 3 + 1];
int height = info[test_page * 3 + 2];
std::cout << "Page " << test_page << " width " << width << " height " << height << std::endl;
width *= 96.0 / (double)info[test_page * 3 + 3];
height *= 96.0 / (double)info[test_page * 3 + 3];
BYTE* pGlyphs = GetGlyphs(test, 22, width, height);
BYTE* res = NULL;
if (pages_count > 0)
res = GetPixmap(test, test_page, width, height);
if (!res)
{
RELEASEARRAYOBJECTS(pXpsData);
RELEASEARRAYOBJECTS(info);
return 1;
}
CBgraFrame* resFrame = new CBgraFrame();
resFrame->put_Data(res);
resFrame->put_Width(width);
resFrame->put_Height(height);
resFrame->put_Stride(4 * width);
resFrame->put_IsRGBA(true);
resFrame->SaveFile(NSFile::GetProcessDirectory() + L"/res.png", _CXIMAGE_FORMAT_PNG);
resFrame->ClearNoAttack();
std::cout << std::endl;
BYTE* pGlyphs = GetGlyphs(test, test_page);
DWORD nLength = GetLength(pGlyphs);
DWORD i = 4;
nLength -= 4;
@ -341,7 +370,8 @@ int main()
}
}
BYTE* pLinks = GetLinks(test, 22, width, height);
std::cout << std::endl;
BYTE* pLinks = GetLinks(test, test_page);
nLength = GetLength(pLinks);
i = 4;
nLength -= 4;
@ -353,6 +383,9 @@ int main()
i += nPathLength;
nPathLength = GetLength(pLinks + i);
i += 4;
std::cout << " Ydest " << (double)nPathLength / 100.0;
nPathLength = GetLength(pLinks + i);
i += 4;
std::cout << " X " << (double)nPathLength / 100.0;
nPathLength = GetLength(pLinks + i);
i += 4;
@ -365,6 +398,7 @@ int main()
std::cout << " H " << (double)nPathLength / 100.0 << std::endl;
}
std::cout << std::endl;
BYTE* pStructure = GetStructure(test);
nLength = GetLength(pStructure);
i = 4;
@ -386,24 +420,8 @@ int main()
i += nPathLength;
}
BYTE* res = NULL;
if (pages_count > 0)
res = GetPixmap(test, 22, width, height);
for (int i = 0; i < 100; i++)
std::cout << (int)res[i] << " ";
std::cout << std::endl;
CBgraFrame* resFrame = new CBgraFrame();
resFrame->put_Data(res);
resFrame->put_Width(width);
resFrame->put_Height(height);
resFrame->put_Stride(-4 * width);
resFrame->put_IsRGBA(true);
resFrame->SaveFile(NSFile::GetProcessDirectory() + L"/res.png", _CXIMAGE_FORMAT_PNG);
resFrame->ClearNoAttack();
Close(test);
RELEASEARRAYOBJECTS(pXpsData);
RELEASEARRAYOBJECTS(info);
RELEASEARRAYOBJECTS(res);
RELEASEARRAYOBJECTS(pGlyphs);
@ -424,29 +442,31 @@ int main()
oFile.CloseFile();
CGraphicsFileDrawing* test = Open(pDjVuData, nDjVuBytesCount);
RELEASEARRAYOBJECTS(pDjVuData);
int* info = GetInfo(test);
int pages_count = *info;
int width = info[1] * 96 / info[3];
int height = info[2] * 96 / info[3];
int test_page = 0;
int width = info[test_page * 3 + 1];
int height = info[test_page * 3 + 2];
std::cout << "Page " << test_page << " width " << width << " height " << height << std::endl;
width *= 96.0 / (double)info[test_page * 3 + 3];
height *= 96.0 / (double)info[test_page * 3 + 3];
BYTE* res = NULL;
if (pages_count > 0)
res = GetPixmap(test, 0, width, height);
for (int i = 0; i < 100; i++)
std::cout << (int)res[i] << " ";
res = GetPixmap(test, test_page, width, height);
CBgraFrame* resFrame = new CBgraFrame();
resFrame->put_Data(res);
resFrame->put_Width(width);
resFrame->put_Height(height);
resFrame->put_Stride(-4 * width);
resFrame->put_Stride(4 * width);
resFrame->put_IsRGBA(true);
resFrame->SaveFile(NSFile::GetProcessDirectory() + L"/res.png", _CXIMAGE_FORMAT_PNG);
resFrame->ClearNoAttack();
BYTE* pGlyphs = GetGlyphs(test, 0, width, height);
std::cout << std::endl;
BYTE* pGlyphs = GetGlyphs(test, test_page);
DWORD nLength = GetLength(pGlyphs);
DWORD i = 4;
nLength -= 4;
@ -455,27 +475,24 @@ int main()
DWORD nPathLength = GetLength(pGlyphs + i);
i += 4;
std::string oWord = std::string((char*)(pGlyphs + i), nPathLength);
std::wcout << L"Word " << UTF8_TO_U(oWord) << L" ";
std::wcout << L"Word " << UTF8_TO_U(oWord);
i += nPathLength;
nPathLength = GetLength(pGlyphs + i);
i += 4;
std::cout << "X " << std::string((char*)(pGlyphs + i), nPathLength) << " ";
i += nPathLength;
std::cout << " X " << (double)nPathLength / 100.0;
nPathLength = GetLength(pGlyphs + i);
i += 4;
std::cout << "Y " << std::string((char*)(pGlyphs + i), nPathLength) << " ";
i += nPathLength;
std::cout << " Y " << (double)nPathLength / 100.0;
nPathLength = GetLength(pGlyphs + i);
i += 4;
std::cout << "W " << std::string((char*)(pGlyphs + i), nPathLength) << " ";
i += nPathLength;
std::cout << " W " << (double)nPathLength / 100.0;
nPathLength = GetLength(pGlyphs + i);
i += 4;
std::cout << "H " << std::string((char*)(pGlyphs + i), nPathLength) << std::endl;
i += nPathLength;
std::cout << " H " << (double)nPathLength / 100.0 << std::endl;
}
BYTE* pLinks = GetLinks(test, 0, width, height);
std::cout << std::endl;
BYTE* pLinks = GetLinks(test, test_page);
nLength = GetLength(pLinks);
i = 4;
nLength -= 4;
@ -483,26 +500,26 @@ int main()
{
DWORD nPathLength = GetLength(pLinks + i);
i += 4;
std::cout << "Link "<< std::string((char*)(pLinks + i), nPathLength) << " ";
std::cout << "Link "<< std::string((char*)(pLinks + i), nPathLength);
i += nPathLength;
nPathLength = GetLength(pLinks + i);
i += 4;
std::cout << "X " << std::string((char*)(pLinks + i), nPathLength) << " ";
i += nPathLength;
std::cout << " Ydest " << (double)nPathLength / 100.0;
nPathLength = GetLength(pLinks + i);
i += 4;
std::cout << "Y " << std::string((char*)(pLinks + i), nPathLength) << " ";
i += nPathLength;
std::cout << " X " << (double)nPathLength / 100.0;
nPathLength = GetLength(pLinks + i);
i += 4;
std::cout << "W " << std::string((char*)(pLinks + i), nPathLength) << " ";
i += nPathLength;
std::cout << " Y " << (double)nPathLength / 100.0;
nPathLength = GetLength(pLinks + i);
i += 4;
std::cout << "H " << std::string((char*)(pLinks + i), nPathLength) << std::endl;
i += nPathLength;
std::cout << " W " << (double)nPathLength / 100.0;
nPathLength = GetLength(pLinks + i);
i += 4;
std::cout << " H " << (double)nPathLength / 100.0 << std::endl;
}
std::cout << std::endl;
BYTE* pStructure = GetStructure(test);
nLength = GetLength(pStructure);
i = 4;
@ -511,18 +528,20 @@ int main()
{
DWORD nPathLength = GetLength(pStructure + i);
i += 4;
std::cout << "Page " << nPathLength << ", ";
std::cout << "Page " << nPathLength;
nPathLength = GetLength(pStructure + i);
i += 4;
std::cout << "Level " << nPathLength << ", ";
std::cout << " Level " << nPathLength;
i += 4; // y 0.0
nPathLength = GetLength(pStructure + i);
i += 4;
std::string oDs = std::string((char*)(pStructure + i), nPathLength);
std::wcout << L"Description "<< UTF8_TO_U(oDs) << std::endl;
std::wcout << L" Description "<< UTF8_TO_U(oDs) << std::endl;
i += nPathLength;
}
Close(test);
RELEASEARRAYOBJECTS(pDjVuData);
RELEASEARRAYOBJECTS(info);
RELEASEARRAYOBJECTS(res);
RELEASEARRAYOBJECTS(pGlyphs);

View File

@ -41,7 +41,7 @@ public:
{
return pReader->GetPagesCount();
}
void GetPageInfo (int nPageIndex, int& nWidth, int& nHeight, int& nPageDpiX)
void GetPageInfo(int nPageIndex, int& nWidth, int& nHeight, int& nPageDpiX)
{
double dPageDpiX, dPageDpiY;
double dWidth, dHeight;
@ -50,17 +50,17 @@ public:
nHeight = dHeight;
nPageDpiX = dPageDpiX;
}
BYTE* GetPage (int nPageIndex, int nRasterW, int nRasterH)
BYTE* GetPage (int nPageIndex, int nRasterW, int nRasterH)
{
return pReader->ConvertToPixels(nPageIndex, nRasterW, nRasterH, true);
}
BYTE* GetGlyphs (int nPageIndex, int nRasterW, int nRasterH)
BYTE* GetGlyphs (int nPageIndex)
{
return pReader->GetGlyphs(nPageIndex, nRasterW, nRasterH);
return pReader->GetGlyphs(nPageIndex);
}
BYTE* GetLinks (int nPageIndex, int nRasterW, int nRasterH)
BYTE* GetLinks (int nPageIndex)
{
return pReader->GetLinks(nPageIndex, nRasterW, nRasterH);
return pReader->GetLinks(nPageIndex);
}
BYTE* GetStructure()
{

View File

@ -117,16 +117,16 @@ BYTE* CDjVuFile::GetStructure()
return m_pImplementation->GetStructure();
return NULL;
}
BYTE* CDjVuFile::GetGlyphs(int nPageIndex, int nRasterW, int nRasterH)
BYTE* CDjVuFile::GetGlyphs(int nPageIndex)
{
if (m_pImplementation)
return m_pImplementation->GetPageGlyphs(nPageIndex, nRasterW, nRasterH);
return m_pImplementation->GetPageGlyphs(nPageIndex);
return NULL;
}
BYTE* CDjVuFile::GetLinks (int nPageIndex, int nRasterW, int nRasterH)
BYTE* CDjVuFile::GetLinks (int nPageIndex)
{
if (m_pImplementation)
return m_pImplementation->GetPageLinks(nPageIndex, nRasterW, nRasterH);
return m_pImplementation->GetPageLinks(nPageIndex);
return NULL;
}
#endif

View File

@ -75,7 +75,7 @@ public:
void ConvertToPdf(const std::wstring& path);
#ifdef BUILDING_WASM_MODULE
virtual BYTE* GetStructure();
virtual BYTE* GetGlyphs(int nPageIndex, int nRasterW, int nRasterH);
virtual BYTE* GetLinks (int nPageIndex, int nRasterW, int nRasterH);
virtual BYTE* GetGlyphs(int nPageIndex);
virtual BYTE* GetLinks (int nPageIndex);
#endif
};

View File

@ -46,6 +46,9 @@
#define HOR_DPI 96
#include <vector>
#ifdef BUILDING_WASM_MODULE
#include "../DesktopEditor/graphics/pro/js/wasm/src/serialize.h"
#endif
namespace NSDjvu
{
@ -337,8 +340,6 @@ void CDjVuFileImplementation::ConvertToPdf(const std::wstring& wsD
oPdf.SaveToFile(wsDstPath);
}
#ifdef BUILDING_WASM_MODULE
#include "../DesktopEditor/graphics/pro/js/wasm/src/serialize.h"
void getBookmars(const GP<DjVmNav>& nav, int& pos, int count, NSWasm::CData& out, int level)
{
while (count > 0 && pos < nav->getBookMarkCount())
@ -362,7 +363,7 @@ void getBookmars(const GP<DjVmNav>& nav, int& pos, int count, NSWasm::CData& out
count--;
}
}
BYTE* CDjVuFileImplementation::GetStructure()
BYTE* CDjVuFileImplementation::GetStructure()
{
GP<DjVmNav> nav = m_pDoc->get_djvm_nav();
if (!nav)
@ -381,12 +382,8 @@ BYTE* CDjVuFileImplementation::GetStructure()
oRes.ClearWithoutAttack();
return bRes;
}
BYTE* CDjVuFileImplementation::GetPageGlyphs(int nPageIndex, const int& nRasterW, const int& nRasterH)
BYTE* CDjVuFileImplementation::GetPageGlyphs(int nPageIndex)
{
double dPageDpiX, dPageDpiY;
double dWidth, dHeight;
GetPageInfo(nPageIndex, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY);
try
{
GP<DjVuImage> pPage = m_pDoc->get_page(nPageIndex);
@ -406,9 +403,6 @@ BYTE* CDjVuFileImplementation::GetPageGlyphs(int nPageIndex, const int& nRasterW
NSWasm::CData oRes;
oRes.SkipLen();
double dKoef = 25.4 / pPage->get_dpi();
double dKoefX = (double)nRasterW * dPageDpiX / 25.4 / dWidth;
double dKoefY = (double)nRasterH * dPageDpiY / 25.4 / dHeight;
XmlUtils::CXmlNodes oParagraphsNodes;
region.GetNodes(L"PARAGRAPH", oParagraphsNodes);
for (int nParagraphIndex = 0; nParagraphIndex < oParagraphsNodes.GetCount(); nParagraphIndex++)
@ -430,14 +424,14 @@ BYTE* CDjVuFileImplementation::GetPageGlyphs(int nPageIndex, const int& nRasterW
std::wstring csWord = oWordNode.GetText();
std::wstring csCoords = oWordNode.GetAttribute(L"coords");
double arrCoords[4];
ParseCoords(csCoords, arrCoords, dKoef);
ParseCoords(csCoords, arrCoords, 1);
std::string sText = U_TO_UTF8(csWord);
oRes.WriteString((BYTE*)sText.c_str(), sText.length());
oRes.AddDouble(arrCoords[0] * dKoefX);
oRes.AddDouble(arrCoords[3] * dKoefY);
oRes.AddDouble((arrCoords[2] - arrCoords[0]) * dKoefX);
oRes.AddDouble((arrCoords[1] - arrCoords[3]) * dKoefY);
oRes.AddDouble(arrCoords[0]);
oRes.AddDouble(arrCoords[3]);
oRes.AddDouble(arrCoords[2] - arrCoords[0]);
oRes.AddDouble(arrCoords[1] - arrCoords[3]);
}
}
}
@ -450,7 +444,7 @@ BYTE* CDjVuFileImplementation::GetPageGlyphs(int nPageIndex, const int& nRasterW
catch (...) {}
return NULL;
}
BYTE* CDjVuFileImplementation::GetPageLinks (int nPageIndex, const int& nRasterW, const int& nRasterH)
BYTE* CDjVuFileImplementation::GetPageLinks (int nPageIndex)
{
double dPageDpiX, dPageDpiY;
double dWidth, dHeight;
@ -467,20 +461,18 @@ BYTE* CDjVuFileImplementation::GetPageLinks (int nPageIndex, const int& nRasterW
NSWasm::CData oRes;
oRes.SkipLen();
double dKoefX = (double)nRasterW / dWidth;
double dKoefY = (double)nRasterH / dHeight;
for (GPosition pos(map_areas); pos; ++pos)
{
GUTF8String str = map_areas[pos]->url;
oRes.WriteString((BYTE*)str.getbuf(), str.length());
double x = map_areas[pos]->get_xmin() * dKoefX;
double y = (double)nRasterH - map_areas[pos]->get_ymin() * dKoefY;
double x = map_areas[pos]->get_xmin();
double y = dHeight - map_areas[pos]->get_ymin();
oRes.AddDouble(0.0);
oRes.AddDouble(x);
oRes.AddDouble(y);
oRes.AddDouble(map_areas[pos]->get_xmax() * dKoefX - x);
oRes.AddDouble((double)nRasterH - map_areas[pos]->get_ymax() * dKoefY - y);
oRes.AddDouble(map_areas[pos]->get_xmax() - x);
oRes.AddDouble(dHeight - map_areas[pos]->get_ymax() - y);
}
oRes.WriteLen();

View File

@ -79,11 +79,11 @@ public:
BYTE* ConvertToPixels(int nPageIndex, const int& nRasterW = -1, const int& nRasterH = -1, bool bIsFlip = false);
void ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType, const int& nRasterW = -1, const int& nRasterH = -1);
void ConvertToPdf(const std::wstring& wsDstPath);
#ifdef BUILDING_WASM_MODULE
#ifdef BUILDING_WASM_MODULE
BYTE* GetStructure();
BYTE* GetPageGlyphs(int nPageIndex, const int& nRasterW, const int& nRasterH);
BYTE* GetPageLinks (int nPageIndex, const int& nRasterW, const int& nRasterH);
#endif
BYTE* GetPageGlyphs(int nPageIndex);
BYTE* GetPageLinks (int nPageIndex);
#endif
private:

View File

@ -536,7 +536,6 @@ return 0;
}
else
pg = pLinkDest->getPageNum();
// TODO: домножение координат
double dy = pLinkDest->getTop();
RELEASEOBJECT(pLinkDest);
@ -586,15 +585,10 @@ return 0;
oRes.ClearWithoutAttack();
return bRes;
}
BYTE* CPdfReader::GetGlyphs(int nPageIndex, int nRasterW, int nRasterH)
BYTE* CPdfReader::GetGlyphs(int nPageIndex)
{
if (!m_pInternal->m_pPDFDocument)
return NULL;
double dWidth, dHeight;
double dDpiX, dDpiY;
GetPageInfo(nPageIndex, &dWidth, &dHeight, &dDpiX, &dDpiY);
double dKoefX = (double)nRasterW / dWidth;
double dKoefY = (double)nRasterH / dHeight;
nPageIndex++;
TextOutputControl *pControl = new TextOutputControl();
pControl->mode = textOutPhysLayout;
@ -625,7 +619,7 @@ return 0;
int amount = pWord->getLength();
oRes.WriteString((BYTE*)sFont->getCString(), sFont->getLength());
oRes.AddDouble(dFontSize * dKoefY);
oRes.AddDouble(dFontSize);
oRes.AddInt(rot);
oRes.AddInt(amount);
for (int j = 0; j < amount; j++)
@ -634,8 +628,8 @@ return 0;
pWord->getCharBBox(j, &x1, &y1, &x2, &y2);
Unicode ch = pWord->getChar(j);
oRes.AddDouble(x1 * dKoefX);
oRes.AddDouble(y1 * dKoefY);
oRes.AddDouble(x1);
oRes.AddDouble(y1);
oRes.AddInt(ch);
}
@ -648,10 +642,10 @@ return 0;
rot = pWord->getRotation();
oRes.WriteString((BYTE*)sWord->getCString(), sWord->getLength());
oRes.AddDouble(x1 * dKoefX);
oRes.AddDouble(y1 * dKoefY);
oRes.AddDouble((x2 - x1) * dKoefX);
oRes.AddDouble((y2 - y1) * dKoefY);
oRes.AddDouble(x1);
oRes.AddDouble(y1);
oRes.AddDouble(x2 - x1);
oRes.AddDouble(y2 - y1);
*/
}
}
@ -664,16 +658,11 @@ return 0;
oRes.ClearWithoutAttack();
return res;
}
BYTE* CPdfReader::GetLinks (int nPageIndex, int nRasterW, int nRasterH)
BYTE* CPdfReader::GetLinks (int nPageIndex)
{
if (!m_pInternal->m_pPDFDocument)
return NULL;
double dWidth, dHeight;
double dDpiX, dDpiY;
GetPageInfo(nPageIndex, &dWidth, &dHeight, &dDpiX, &dDpiY);
double dKoefX = (double)nRasterW / dWidth;
double dKoefY = (double)nRasterH / dHeight;
nPageIndex++;
NSWasm::CData oRes;
oRes.SkipLen();
@ -723,14 +712,16 @@ return 0;
oRes.WriteString((BYTE*)str->getCString(), str->getLength());
else
oRes.WriteString(NULL, 0);
oRes.AddDouble(x1 * dKoefX);
oRes.AddDouble(y1 * dKoefY);
oRes.AddDouble((x2 - x1) * dKoefX);
oRes.AddDouble((y2 - y1) * dKoefY);
oRes.AddDouble(0.0);
oRes.AddDouble(x1);
oRes.AddDouble(y1);
oRes.AddDouble(x2 - x1);
oRes.AddDouble(y2 - y1);
RELEASEOBJECT(str);
}
oRes.WriteLen();
RELEASEOBJECT(pLinks);
BYTE* res = oRes.GetBuffer();
oRes.ClearWithoutAttack();
return res;

View File

@ -99,8 +99,8 @@ namespace PdfReader
std::wstring ToXml(const std::wstring& wsXmlPath);
#ifdef BUILDING_WASM_MODULE
virtual BYTE* GetStructure();
virtual BYTE* GetGlyphs(int nPageIndex, int nRasterW, int nRasterH);
virtual BYTE* GetLinks (int nPageIndex, int nRasterW, int nRasterH);
virtual BYTE* GetGlyphs(int nPageIndex);
virtual BYTE* GetLinks (int nPageIndex);
#endif
private:

View File

@ -298,11 +298,11 @@ BYTE* CXpsFile::GetStructure()
{
return m_pInternal->m_pDocument->GetStructure();
}
BYTE* CXpsFile::GetGlyphs (int nPageIndex, int nRasterW, int nRasterH)
BYTE* CXpsFile::GetGlyphs(int nPageIndex)
{
return m_pInternal->m_pDocument->GetPageGlyphs(nPageIndex);
}
BYTE* CXpsFile::GetLinks(int nPageIndex, int nRasterW, int nRasterH)
BYTE* CXpsFile::GetLinks (int nPageIndex)
{
return m_pInternal->m_pDocument->GetPageLinks(nPageIndex);
}

View File

@ -73,8 +73,8 @@ public:
#ifdef BUILDING_WASM_MODULE
virtual BYTE* GetStructure();
virtual BYTE* GetGlyphs(int nPageIndex, int nRasterW, int nRasterH);
virtual BYTE* GetLinks (int nPageIndex, int nRasterW, int nRasterH);
virtual BYTE* GetGlyphs(int nPageIndex);
virtual BYTE* GetLinks (int nPageIndex);
#endif
private:

View File

@ -82,15 +82,15 @@ namespace XPS
m_pFontList = pFontList;
m_pFontManager = pFontManager;
m_pDocument = pDocument;
#ifdef BUILDING_WASM_MODULE
#ifdef BUILDING_WASM_MODULE
m_pGlyphs = NULL;
#endif
#endif
}
Page::~Page()
{
#ifdef BUILDING_WASM_MODULE
#ifdef BUILDING_WASM_MODULE
RELEASEOBJECT(m_pGlyphs);
#endif
#endif
}
void Page::GetSize(int& nW, int& nH) const
{
@ -184,16 +184,16 @@ namespace XPS
}
BYTE* Page::GetLinks()
{
NSWasm::CData oRes;
NSWasm::CData oRes;
oRes.SkipLen();
for (const CPageLink& link : m_vLinks)
{
std::string s = U_TO_UTF8(link.sLink);
oRes.WriteString((BYTE*)s.c_str(), s.length());
oRes.AddDouble(link.dX);
oRes.AddDouble(link.dY);
oRes.AddDouble(link.dW);
oRes.AddDouble(link.dH);
oRes.WriteString((BYTE*)link.sLink.c_str(), link.sLink.length());
oRes.AddDouble(0.0);
oRes.AddDouble(link.dX);
oRes.AddDouble(link.dY);
oRes.AddDouble(link.dW);
oRes.AddDouble(link.dH);
}
oRes.WriteLen();
@ -707,22 +707,18 @@ namespace XPS
if (!bIsSideways)
{
#ifdef BUILDING_WASM_MODULE
#ifdef BUILDING_WASM_MODULE
if (!m_pGlyphs)
{
m_pGlyphs = new NSWasm::CData();
m_pGlyphs->SkipLen();
}
double pdA, pdB, pdC, pdD, pdE, pdF;
pRenderer->GetTransform(&pdA, &pdB, &pdC, &pdD, &pdE, &pdF);
Aggplus::CMatrix oTransform(pdA, pdB, pdC, pdD, pdE, pdF);
std::string sFontName = U_TO_UTF8(m_pFontManager->GetName());
m_pGlyphs->WriteString((BYTE*)sFontName.c_str(), sFontName.length());
m_pGlyphs->AddDouble(dFontSize * pdA + pdE);
m_pGlyphs->AddDouble(dFontSize);
m_pGlyphs->AddInt(unUtf16Len);
#endif
#endif
while (GetNextGlyph(wsIndices.c_str(), nIndicesPos, nIndicesLen, pUtf16, nUtf16Pos, unUtf16Len, oEntry))
{
@ -755,16 +751,12 @@ namespace XPS
pState->PushTransform(pTransform);
}
#ifdef BUILDING_WASM_MODULE
double _dX = dXorigin;
double _dY = dYorigin;
oTransform.TransformPoint(_dX, _dY);
m_pGlyphs->AddDouble(_dX);
m_pGlyphs->AddDouble(_dY);
#ifdef BUILDING_WASM_MODULE
m_pGlyphs->AddDouble(dXorigin);
m_pGlyphs->AddDouble(dYorigin);
m_pGlyphs->AddInt(oEntry.nUnicode);
m_pGlyphs->WriteLen();
#endif
#endif
if (oEntry.bGid)
pRenderer->CommandDrawTextExCHAR(oEntry.nUnicode, oEntry.nGid, xpsUnitToMM(dXorigin), xpsUnitToMM(dYorigin), 0, 0);
@ -992,12 +984,9 @@ namespace XPS
}
else if (L"FixedPage.NavigateUri" == wsAttrName)
{
double pdA, pdB, pdC, pdD, pdE, pdF;
pRenderer->GetTransform(&pdA, &pdB, &pdC, &pdD, &pdE, &pdF);
Aggplus::CMatrix oTransform(pdA, pdB, pdC, pdD, pdE, pdF);
double x1 = 0, y1 = 0, x2 = 0, y2 = 0, x3 = 0, y3 = 0;
CPageLink oLink = {0, 0, 0, 0, L""};
CPageLink oLink = {0, 0, 0, 0, ""};
std::wstring wsPath = wsPathData.c_stdstr();
size_t nFindX = wsPath.find(L"M ");
if (nFindX != std::wstring::npos)
@ -1011,7 +1000,6 @@ namespace XPS
size_t nFindEndY = wsPath.find(L' ', nFindY);
if (nFindEndY != std::wstring::npos)
y1 = GetDouble(wsPath.substr(nFindY, nFindEndY - nFindY));
oTransform.TransformPoint(x1, y1);
}
}
nFindX = wsPath.find(L"L ");
@ -1026,7 +1014,6 @@ namespace XPS
size_t nFindEndY = wsPath.find(L' ', nFindY);
if (nFindEndY != std::wstring::npos)
y2 = GetDouble(wsPath.substr(nFindY, nFindEndY - nFindY));
oTransform.TransformPoint(x2, y2);
}
}
nFindX = wsPath.find(L"L ", nFindX);
@ -1041,7 +1028,6 @@ namespace XPS
size_t nFindEndY = wsPath.find(L' ', nFindY);
if (nFindEndY != std::wstring::npos)
y3 = GetDouble(wsPath.substr(nFindY, nFindEndY - nFindY));
oTransform.TransformPoint(x3, y3);
}
}
oLink.dX = x1 == x2 ? fmin(x1, x3) : fmin(x1, x2);
@ -1052,18 +1038,19 @@ namespace XPS
std::wstring wsNameTarget = oReader.GetText();
if (wsNameTarget.find(L"http") == 0)
{
oLink.sLink = wsNameTarget;
oLink.sLink = U_TO_UTF8(wsNameTarget);
m_vLinks.push_back(oLink);
}
else
{
// координата назначения на странице назначения
size_t nSharp = wsNameTarget.find(L'#');
if (nSharp != std::wstring::npos)
{
std::map<std::wstring, int>::iterator find = m_pDocument->m_mInternalLinks.find(wsNameTarget.substr(nSharp + 1));
if (find != m_pDocument->m_mInternalLinks.end())
{
oLink.sLink = L'#' + std::to_wstring(find->second);
oLink.sLink = '#' + std::to_string(find->second);
m_vLinks.push_back(oLink);
}
}
@ -1088,6 +1075,7 @@ namespace XPS
nFindY++;
size_t nFindEndY = wsPath.find(L' ', nFindY);
if (nFindEndY != std::wstring::npos)
// координата назначения на странице назначения
find->dY = GetDouble(wsPath.substr(nFindY, nFindEndY - nFindY));
}
}

View File

@ -62,7 +62,6 @@ namespace XPS
BYTE* GetLinks();
private:
NSWasm::CData* m_pGlyphs;
struct CPageLink
{
@ -70,7 +69,7 @@ namespace XPS
double dY;
double dW;
double dH;
std::wstring sLink;
std::string sLink;
};
std::vector<CPageLink> m_vLinks;
#endif