diff --git a/DesktopEditor/graphics/pro/js/wasm/js/xps_base.js b/DesktopEditor/graphics/pro/js/wasm/js/xps_base.js index 0365c029e4..e7c2c0fdbe 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/xps_base.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/xps_base.js @@ -126,6 +126,12 @@ { var res = Module["_XPS_GetPixmap"](this.nativeFile, pageIndex, width, height); + this.getGlyphs(pageIndex); + + return res; + }; + CFile.prototype.getGlyphs = function(pageIndex) + { var glyphs = Module["_XPS_GetGlyphs"](this.nativeFile, pageIndex); if (glyphs == null) return res; @@ -207,8 +213,6 @@ } } Module["_XPS_Delete"](glyphs); - - return res; }; CFile.prototype.structure = function() { diff --git a/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.cpp b/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.cpp index 8fed5d88cc..2c5b2e2df2 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.cpp @@ -67,9 +67,9 @@ WASM_EXPORT BYTE* XPS_GetGlyphs(CGraphicsFileDrawing* pGraphics, int nPageIndex) { return pGraphics->GetXPSGlyphs(nPageIndex); } -WASM_EXPORT BYTE* DJVU_GetGlyphs(CGraphicsFileDrawing* pGraphics) +WASM_EXPORT BYTE* DJVU_GetGlyphs(CGraphicsFileDrawing* pGraphics, int nPageIndex, int nRasterW, int nRasterH) { - return pGraphics->GetDJVUGlyphs(); + return pGraphics->GetDJVUGlyphs(nPageIndex, nRasterW, nRasterH); } WASM_EXPORT BYTE* XPS_GetStructure(CGraphicsFileDrawing* pGraphics) { @@ -212,23 +212,8 @@ int main() int pages_count = *info; int width = info[1] * 96 / info[3]; int height = info[2] * 96 / info[3]; - BYTE* res = NULL; - if (pages_count > 0) - res = XPS_GetPixmap(test, 1, width, height); - for (int i = 0; i < 100; i++) - std::cout << (int)res[i] << " "; - - 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(); - - BYTE* pGlyphs = DJVU_GetGlyphs(test); + BYTE* pGlyphs = DJVU_GetGlyphs(test, 3, width, height); DWORD nLength = GetLength(pGlyphs); DWORD i = 4; nLength -= 4; @@ -257,6 +242,22 @@ int main() i += nPathLength; } + BYTE* res = NULL; + if (pages_count > 0) + res = XPS_GetPixmap(test, 3, width, height); + + for (int i = 0; i < 100; i++) + std::cout << (int)res[i] << " "; + + 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(); + BYTE* pStructure = DJVU_GetStructure(test); nLength = GetLength(pStructure); i = 4; diff --git a/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.h b/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.h index ae189e7e68..b877576b42 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.h +++ b/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.h @@ -78,9 +78,9 @@ public: { return ((CXpsFile*)pReader)->GetGlyphs(nPageIndex); } - BYTE* GetDJVUGlyphs() + BYTE* GetDJVUGlyphs(int nPageIndex, int nRasterW, int nRasterH) { - return ((CDjVuFile*)pReader)->GetPageGlyphs(); + return ((CDjVuFile*)pReader)->GetPageGlyphs(nPageIndex, nRasterW, nRasterH); } BYTE* GetXPSStructure() { diff --git a/DjVuFile/DjVu.cpp b/DjVuFile/DjVu.cpp index ab69a4a326..7b49fbe7e0 100644 --- a/DjVuFile/DjVu.cpp +++ b/DjVuFile/DjVu.cpp @@ -112,10 +112,10 @@ BYTE* CDjVuFile::GetStructure() return m_pImplementation->GetStructure(); return NULL; } -BYTE* CDjVuFile::GetPageGlyphs() +BYTE* CDjVuFile::GetPageGlyphs(int nPageIndex, int nRasterW, int nRasterH) { if (m_pImplementation) - return m_pImplementation->GetPageGlyphs(); + return m_pImplementation->GetPageGlyphs(nPageIndex, nRasterW, nRasterH); return NULL; } #endif diff --git a/DjVuFile/DjVu.h b/DjVuFile/DjVu.h index 0bcbe5bf04..84204f54ad 100644 --- a/DjVuFile/DjVu.h +++ b/DjVuFile/DjVu.h @@ -73,6 +73,6 @@ public: void ConvertToPdf(const std::wstring& path); #ifdef WASM_MODE BYTE* GetStructure(); - BYTE* GetPageGlyphs(); + BYTE* GetPageGlyphs(int nPageIndex, int nRasterW, int nRasterH); #endif }; diff --git a/DjVuFile/DjVuFileImplementation.cpp b/DjVuFile/DjVuFileImplementation.cpp index f508c06f56..93ae86cbfb 100644 --- a/DjVuFile/DjVuFileImplementation.cpp +++ b/DjVuFile/DjVuFileImplementation.cpp @@ -92,8 +92,6 @@ CDjVuFileImplementation::CDjVuFileImplementation(NSFonts::IApplicationFonts* pFo wsTempPath += L"DJVU\\"; m_wsTempDirectory = wsTempPath; NSDirectory::CreateDirectory(m_wsTempDirectory); -#else - m_pGlyphs = NULL; #endif m_pApplicationFonts = pFonts; } @@ -101,8 +99,6 @@ CDjVuFileImplementation::~CDjVuFileImplementation() { #ifndef WASM_MODE NSDirectory::DeleteDirectory(m_wsTempDirectory); -#else - RELEASEOBJECT(m_pGlyphs); #endif } bool CDjVuFileImplementation::LoadFromFile(const std::wstring& wsSrcFileName, const std::wstring& wsXMLOptions) @@ -192,7 +188,7 @@ void CDjVuFileImplementation::GetPageInfo(int nPageIndex, double* *pdDpiX = nDpi; *pdDpiY = nDpi; } -void CDjVuFileImplementation::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak, double dKoefX, double dKoefY) +void CDjVuFileImplementation::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak) { if (!m_pDoc) return; @@ -218,7 +214,7 @@ void CDjVuFileImplementation::DrawPageOnRenderer(IRenderer* pRende #endif else { - XmlUtils::CXmlNode oText = ParseText(pPage, dKoefX, dKoefY); + XmlUtils::CXmlNode oText = ParseText(pPage); CreateFrame(pRenderer, pPage, nPageIndex, oText); } } @@ -264,7 +260,7 @@ BYTE* CDjVuFileImplementation::ConvertToPixels(int nPageIndex, cons pRenderer->put_Height(dHeight); bool bBreak = false; - DrawPageOnRenderer(pRenderer, nPageIndex, &bBreak, (double)nWidth * dPageDpiX / 25.4 / dWidth, (double)nHeight * dPageDpiX / 25.4 / dHeight); + DrawPageOnRenderer(pRenderer, nPageIndex, &bBreak); RELEASEINTERFACE(pFontManager); RELEASEOBJECT(pRenderer); @@ -341,7 +337,129 @@ void CDjVuFileImplementation::ConvertToPdf(const std::wstring& wsD oPdf.SaveToFile(wsDstPath); } #ifdef WASM_MODE -void getBookmars(const GP& nav, int& pos, int count, CDjVuFileImplementation::CData& out, int level) +class CData +{ +protected: + unsigned char* m_pData; + size_t m_lSize; + + unsigned char* m_pDataCur; + size_t m_lSizeCur; + +public: + CData() + { + m_pData = NULL; + m_lSize = 0; + + m_pDataCur = m_pData; + m_lSizeCur = m_lSize; + } + virtual ~CData() + { + Clear(); + } + + inline void AddSize(size_t nSize) + { + if (NULL == m_pData) + { + m_lSize = 1000; + if (nSize > m_lSize) + m_lSize = nSize; + + m_pData = (unsigned char*)malloc(m_lSize * sizeof(unsigned char)); + + m_lSizeCur = 0; + m_pDataCur = m_pData; + return; + } + + if ((m_lSizeCur + nSize) > m_lSize) + { + while ((m_lSizeCur + nSize) > m_lSize) + m_lSize *= 2; + + unsigned char* pRealloc = (unsigned char*)realloc(m_pData, m_lSize * sizeof(unsigned char)); + if (NULL != pRealloc) + { + m_pData = pRealloc; + m_pDataCur = m_pData + m_lSizeCur; + } + else + { + unsigned char* pMalloc = (unsigned char*)malloc(m_lSize * sizeof(unsigned char)); + memcpy(pMalloc, m_pData, m_lSizeCur * sizeof(unsigned char)); + + free(m_pData); + m_pData = pMalloc; + m_pDataCur = m_pData + m_lSizeCur; + } + } + } + +public: + void AddInt(unsigned int value) + { + AddSize(4); + memcpy(m_pDataCur, &value, sizeof(unsigned int)); + m_pDataCur += 4; + m_lSizeCur += 4; + } + void WriteString(unsigned char* value, unsigned int len) + { + AddSize(len + 4); + memcpy(m_pDataCur, &len, sizeof(unsigned int)); + m_pDataCur += 4; + m_lSizeCur += 4; + memcpy(m_pDataCur, value, len); + m_pDataCur += len; + m_lSizeCur += len; + } + unsigned char* GetBuffer() + { + return m_pData; + } + + void Clear() + { + if (m_pData) free(m_pData); + + m_pData = NULL; + m_lSize = 0; + + m_pDataCur = m_pData; + m_lSizeCur = 0; + } + void ClearWithoutAttack() + { + m_pData = NULL; + m_lSize = 0; + + m_pDataCur = m_pData; + m_lSizeCur = 0; + } + void ClearNoAttack() + { + m_pDataCur = m_pData; + m_lSizeCur = 0; + } + unsigned int GetSize() + { + return (unsigned int)m_lSizeCur; + } + + void SkipLen() + { + AddInt(0); + } + void WriteLen() + { + unsigned int len = (unsigned int)m_lSizeCur; + memcpy(m_pData, &len, sizeof(unsigned int)); + } +}; +void getBookmars(const GP& nav, int& pos, int count, CData& out, int level) { while (count > 0 && pos < nav->getBookMarkCount()) { @@ -382,16 +500,73 @@ BYTE* CDjVuFileImplementation::GetStructure() oRes.ClearWithoutAttack(); return bRes; } -BYTE* CDjVuFileImplementation::GetPageGlyphs() +BYTE* CDjVuFileImplementation::GetPageGlyphs(int nPageIndex, const int& nRasterW, const int& nRasterH) { - if (m_pGlyphs) + double dPageDpiX, dPageDpiY; + double dWidth, dHeight; + GetPageInfo(nPageIndex, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY); + + GP pPage = m_pDoc->get_page(nPageIndex); + const GP text(DjVuText::create()); + const GP text_str(pPage->get_text()); + if (!text_str) + return NULL; + + text->decode(text_str); + GUTF8String pageText = text->get_xmlText(pPage->get_height()); + XmlUtils::CXmlNode hiddenText; + XmlUtils::CXmlNode pageColumn; + XmlUtils::CXmlNode region; + hiddenText.FromXmlStringA(NSDjvu::MakeCString(pageText)); + hiddenText.GetNode(L"PAGECOLUMN", pageColumn); + pageColumn.GetNode(L"REGION", region); + + 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++) { - BYTE* res = m_pGlyphs->GetBuffer(); - m_pGlyphs->ClearWithoutAttack(); - RELEASEOBJECT(m_pGlyphs); - return res; + XmlUtils::CXmlNode oParagraphNode; + oParagraphsNodes.GetAt(nParagraphIndex, oParagraphNode); + XmlUtils::CXmlNodes oLinesNodes; + oParagraphNode.GetNodes(L"LINE", oLinesNodes); + for (int nLineIndex = 0; nLineIndex < oLinesNodes.GetCount(); nLineIndex++) + { + XmlUtils::CXmlNode oLineNode; + oLinesNodes.GetAt(nLineIndex, oLineNode); + XmlUtils::CXmlNodes oWordsNodes; + oLineNode.GetNodes(L"WORD", oWordsNodes); + for (int nWordIndex = 0; nWordIndex < oWordsNodes.GetCount(); ++nWordIndex) + { + XmlUtils::CXmlNode oWordNode; + oWordsNodes.GetAt(nWordIndex, oWordNode); + std::wstring csWord = oWordNode.GetText(); + std::wstring csCoords = oWordNode.GetAttribute(L"coords"); + double arrCoords[4]; + ParseCoords(csCoords, arrCoords, dKoef); + + std::string sText = U_TO_UTF8(csWord); + oRes.WriteString((BYTE*)sText.c_str(), sText.length()); + std::string sX = std::to_string(arrCoords[0] * dKoefX); + oRes.WriteString((BYTE*)sX.c_str(), sX.length()); + std::string sY = std::to_string(arrCoords[3] * dKoefY); + oRes.WriteString((BYTE*)sY.c_str(), sY.length()); + std::string sW = std::to_string((arrCoords[2] - arrCoords[0]) * dKoefX); + oRes.WriteString((BYTE*)sW.c_str(), sW.length()); + std::string sH = std::to_string((arrCoords[1] - arrCoords[3]) * dKoefY); + oRes.WriteString((BYTE*)sH.c_str(), sH.length()); + } + } } - return NULL; + oRes.WriteLen(); + + BYTE* res = oRes.GetBuffer(); + oRes.ClearWithoutAttack(); + return res; } #endif void CDjVuFileImplementation::CreateFrame(IRenderer* pRenderer, GP& pPage, int nPage, XmlUtils::CXmlNode& text) @@ -1009,7 +1184,7 @@ void CDjVuFileImplementation::CreateGrFrame(IRenderer* pRenderer, } } } -XmlUtils::CXmlNode CDjVuFileImplementation::ParseText(GP pPage, double dKoefX, double dKoefY) +XmlUtils::CXmlNode CDjVuFileImplementation::ParseText(GP pPage) { XmlUtils::CXmlNode paragraph; const GP text(DjVuText::create()); @@ -1025,50 +1200,6 @@ XmlUtils::CXmlNode CDjVuFileImplementation::ParseText(GP pPage, doubl hiddenText.GetNode(L"PAGECOLUMN", pageColumn); pageColumn.GetNode(L"REGION", region); region.GetNode(L"PARAGRAPH", paragraph); - - #ifdef WASM_MODE - RELEASEOBJECT(m_pGlyphs); - m_pGlyphs = new CData(); - m_pGlyphs->SkipLen(); - double dKoef = 25.4 / pPage->get_dpi(); - XmlUtils::CXmlNodes oParagraphsNodes; - region.GetNodes(L"PARAGRAPH", oParagraphsNodes); - for (int nParagraphIndex = 0; nParagraphIndex < oParagraphsNodes.GetCount(); nParagraphIndex++) - { - XmlUtils::CXmlNode oParagraphNode; - oParagraphsNodes.GetAt(nParagraphIndex, oParagraphNode); - XmlUtils::CXmlNodes oLinesNodes; - oParagraphNode.GetNodes(L"LINE", oLinesNodes); - for (int nLineIndex = 0; nLineIndex < oLinesNodes.GetCount(); nLineIndex++) - { - XmlUtils::CXmlNode oLineNode; - oLinesNodes.GetAt(nLineIndex, oLineNode); - XmlUtils::CXmlNodes oWordsNodes; - oLineNode.GetNodes(L"WORD", oWordsNodes); - for (int nWordIndex = 0; nWordIndex < oWordsNodes.GetCount(); ++nWordIndex) - { - XmlUtils::CXmlNode oWordNode; - oWordsNodes.GetAt(nWordIndex, oWordNode); - std::wstring csWord = oWordNode.GetText(); - std::wstring csCoords = oWordNode.GetAttribute(L"coords"); - double arrCoords[4]; - ParseCoords(csCoords, arrCoords, dKoef); - - std::string sText = U_TO_UTF8(csWord); - m_pGlyphs->WriteString((BYTE*)sText.c_str(), sText.length()); - std::string sX = std::to_string(arrCoords[0] * dKoefX); - m_pGlyphs->WriteString((BYTE*)sX.c_str(), sX.length()); - std::string sY = std::to_string(arrCoords[3] * dKoefY); - m_pGlyphs->WriteString((BYTE*)sY.c_str(), sY.length()); - std::string sW = std::to_string((arrCoords[2] - arrCoords[0]) * dKoefX); - m_pGlyphs->WriteString((BYTE*)sW.c_str(), sW.length()); - std::string sH = std::to_string((arrCoords[1] - arrCoords[3]) * dKoefY); - m_pGlyphs->WriteString((BYTE*)sH.c_str(), sH.length()); - } - } - } - m_pGlyphs->WriteLen(); - #endif } return paragraph; } diff --git a/DjVuFile/DjVuFileImplementation.h b/DjVuFile/DjVuFileImplementation.h index afe595c862..bb742390c7 100644 --- a/DjVuFile/DjVuFileImplementation.h +++ b/DjVuFile/DjVuFileImplementation.h @@ -75,136 +75,13 @@ public: 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, double dKoefX = 0, double dKoefY = 0); + 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 ConvertToPdf(const std::wstring& wsDstPath); #ifdef WASM_MODE - class CData - { - protected: - unsigned char* m_pData; - size_t m_lSize; - - unsigned char* m_pDataCur; - size_t m_lSizeCur; - - public: - CData() - { - m_pData = NULL; - m_lSize = 0; - - m_pDataCur = m_pData; - m_lSizeCur = m_lSize; - } - virtual ~CData() - { - Clear(); - } - - inline void AddSize(size_t nSize) - { - if (NULL == m_pData) - { - m_lSize = 1000; - if (nSize > m_lSize) - m_lSize = nSize; - - m_pData = (unsigned char*)malloc(m_lSize * sizeof(unsigned char)); - - m_lSizeCur = 0; - m_pDataCur = m_pData; - return; - } - - if ((m_lSizeCur + nSize) > m_lSize) - { - while ((m_lSizeCur + nSize) > m_lSize) - m_lSize *= 2; - - unsigned char* pRealloc = (unsigned char*)realloc(m_pData, m_lSize * sizeof(unsigned char)); - if (NULL != pRealloc) - { - m_pData = pRealloc; - m_pDataCur = m_pData + m_lSizeCur; - } - else - { - unsigned char* pMalloc = (unsigned char*)malloc(m_lSize * sizeof(unsigned char)); - memcpy(pMalloc, m_pData, m_lSizeCur * sizeof(unsigned char)); - - free(m_pData); - m_pData = pMalloc; - m_pDataCur = m_pData + m_lSizeCur; - } - } - } - - public: - void AddInt(unsigned int value) - { - AddSize(4); - memcpy(m_pDataCur, &value, sizeof(unsigned int)); - m_pDataCur += 4; - m_lSizeCur += 4; - } - void WriteString(unsigned char* value, unsigned int len) - { - AddSize(len + 4); - memcpy(m_pDataCur, &len, sizeof(unsigned int)); - m_pDataCur += 4; - m_lSizeCur += 4; - memcpy(m_pDataCur, value, len); - m_pDataCur += len; - m_lSizeCur += len; - } - unsigned char* GetBuffer() - { - return m_pData; - } - - void Clear() - { - if (m_pData) free(m_pData); - - m_pData = NULL; - m_lSize = 0; - - m_pDataCur = m_pData; - m_lSizeCur = 0; - } - void ClearWithoutAttack() - { - m_pData = NULL; - m_lSize = 0; - - m_pDataCur = m_pData; - m_lSizeCur = 0; - } - void ClearNoAttack() - { - m_pDataCur = m_pData; - m_lSizeCur = 0; - } - unsigned int GetSize() - { - return (unsigned int)m_lSizeCur; - } - - void SkipLen() - { - AddInt(0); - } - void WriteLen() - { - unsigned int len = (unsigned int)m_lSizeCur; - memcpy(m_pData, &len, sizeof(unsigned int)); - } - }; BYTE* GetStructure(); - BYTE* GetPageGlyphs(); - CData* m_pGlyphs; + BYTE* GetPageGlyphs(int nPageIndex, const int& nRasterW, const int& nRasterH); #endif private: @@ -212,7 +89,7 @@ private: void CreateFrame(IRenderer* pRenderer, GP& pImage, int nPage, XmlUtils::CXmlNode& oText); void CreatePdfFrame(IRenderer* pRenderer, GP& pImage, int nPage, XmlUtils::CXmlNode& oText); void CreateGrFrame(IRenderer* pRenderer, GP& pImage, bool* pBreak); - XmlUtils::CXmlNode ParseText(GP pPage, double dKoefX, double dKoefY); + XmlUtils::CXmlNode ParseText(GP pPage); void TextToRenderer(IRenderer* pRenderer, XmlUtils::CXmlNode text, double koef, bool isView = true); void DrawPageText(IRenderer* pRenderer, double* pdCoords, const std::wstring& wsText); void ParseCoords(const std::wstring& wsCoordsStr, double* pdCoords, double dKoef); diff --git a/DjVuFile/wasm/all_files_test/code.js b/DjVuFile/wasm/all_files_test/code.js index aa13dbba4c..93f7471057 100644 --- a/DjVuFile/wasm/all_files_test/code.js +++ b/DjVuFile/wasm/all_files_test/code.js @@ -377,6 +377,11 @@ window.onload = function() return res; }; + this.getGlyphs = function(pageIndex, width, height) + { + this.file.getGlyphs(pageIndex, width, height); + }; + this._paint = function() { if (!this.isRepaint) @@ -454,7 +459,10 @@ window.onload = function() } if (!page.Image) + { page.Image = this.file.getPage(i, w, h); + this.getGlyphs(i, w, h); + } let x = ((xCenter * this.retinaPixelRatio) >> 0) - (w >> 1); let y = ((page.Y - yPos) * this.retinaPixelRatio) >> 0; diff --git a/DjVuFile/wasm/djvu_base.js b/DjVuFile/wasm/djvu_base.js index 530324ca1a..3a2f10d062 100644 --- a/DjVuFile/wasm/djvu_base.js +++ b/DjVuFile/wasm/djvu_base.js @@ -124,16 +124,18 @@ }; CFile.prototype.getPagePixmap = function(pageIndex, width, height) { - var res = Module["_XPS_GetPixmap"](this.nativeFile, pageIndex, width, height); - - var glyphs = Module["_DJVU_GetGlyphs"](this.nativeFile, pageIndex); + return Module["_XPS_GetPixmap"](this.nativeFile, pageIndex, width, height); + }; + CFile.prototype.getGlyphs = function(pageIndex, width, height) + { + var glyphs = Module["_DJVU_GetGlyphs"](this.nativeFile, pageIndex, width, height); if (glyphs == null) - return res; + return; var lenArray = new Int32Array(Module["HEAP8"].buffer, glyphs, 4); var len = lenArray[0]; len -= 4; if (len <= 0) - return res; + return; this.pages[pageIndex].Lines = []; var buffer = new Uint8Array(Module["HEAP8"].buffer, glyphs + 4, len); @@ -174,8 +176,7 @@ this.pages[pageIndex].Lines[Line].Glyphs[0].Y = _Y + _H; this.pages[pageIndex].Lines[Line].Glyphs[0].fontSize = _H; } - - return res; + Module["_XPS_Delete"](glyphs); }; CFile.prototype.structure = function() { diff --git a/XpsFile/XpsLib/Page.cpp b/XpsFile/XpsLib/Page.cpp index f2c7403814..b7b7e77a6c 100644 --- a/XpsFile/XpsLib/Page.cpp +++ b/XpsFile/XpsLib/Page.cpp @@ -187,6 +187,88 @@ namespace XPS } return NULL; } + BYTE* ForGetGlyphs2(XmlUtils::CXmlLiteReader& oReader) + { + if (oReader.IsEmptyNode()) + return NULL; + + int nCurDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nCurDepth)) + { + if (oReader.GetName() == L"Glyphs") + { + + } + } + + return NULL; + } + BYTE* Page::GetGlyphs2() + { + XmlUtils::CXmlLiteReader oReader; + + if (!oReader.FromStringA(m_wsRootPath->readXml(m_wsPagePath))) + return NULL; + + if (!oReader.ReadNextNode()) + return NULL; + + CWString wsNodeName = oReader.GetName(); + if (wsNodeName == L"mc:AlternateContent") + { + if (!oReader.IsEmptyNode()) + { + int nAltDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nAltDepth)) + { + wsNodeName = oReader.GetName(); + if (wsNodeName == L"mc:Choice") + { + CWString wsAttr; + ReadAttribute(oReader, L"Requires", wsAttr); + if (wsAttr == L"xps") + { + if (!oReader.IsEmptyNode()) + { + int nAltDepth2 = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nAltDepth2)) + { + wsNodeName = oReader.GetName(); + if (wsNodeName == L"FixedPage") + { + return ForGetGlyphs2(oReader); + } + } + } + break; + } + } + else if (wsNodeName == L"mc:Fallback") + { + if (!oReader.IsEmptyNode()) + { + int nAltDepth2 = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nAltDepth2)) + { + wsNodeName = oReader.GetName(); + if (wsNodeName == L"FixedPage") + { + return ForGetGlyphs2(oReader); + } + } + } + break; + } + } + } + } + else if (wsNodeName == L"FixedPage") + { + return ForGetGlyphs2(oReader); + } + + return NULL; + } #endif void Page::Draw(IRenderer* pRenderer, bool* pbBreak) { diff --git a/XpsFile/XpsLib/Page.h b/XpsFile/XpsLib/Page.h index 5cbbfec57d..7718f4881f 100644 --- a/XpsFile/XpsLib/Page.h +++ b/XpsFile/XpsLib/Page.h @@ -55,6 +55,7 @@ namespace XPS void GetSize(int& nW, int& nH) const; #ifdef BUILDING_WASM_MODULE BYTE* GetGlyphs(); + BYTE* GetGlyphs2(); class CData { protected: