mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
xps get glyphs and links without repaint
This commit is contained in:
@ -71,13 +71,13 @@ WASM_EXPORT BYTE* DJVU_GetGlyphs(CGraphicsFileDrawing* pGraphics, int nPageIndex
|
||||
{
|
||||
return pGraphics->GetDJVUGlyphs(nPageIndex, nRasterW, nRasterH);
|
||||
}
|
||||
WASM_EXPORT BYTE* XPS_GetExternalLinks(CGraphicsFileDrawing* pGraphics, int nPageIndex)
|
||||
WASM_EXPORT BYTE* XPS_GetExternalLinks(CGraphicsFileDrawing* pGraphics, int nPageIndex, int nRasterW, int nRasterH)
|
||||
{
|
||||
return pGraphics->GetXPSExternalLinks(nPageIndex);
|
||||
return pGraphics->GetXPSExternalLinks(nPageIndex, nRasterW, nRasterH);
|
||||
}
|
||||
WASM_EXPORT BYTE* XPS_GetInternalLinks(CGraphicsFileDrawing* pGraphics, int nPageIndex)
|
||||
WASM_EXPORT BYTE* XPS_GetInternalLinks(CGraphicsFileDrawing* pGraphics, int nPageIndex, int nRasterW, int nRasterH)
|
||||
{
|
||||
return pGraphics->GetXPSInternalLinks(nPageIndex);
|
||||
return pGraphics->GetXPSInternalLinks(nPageIndex, nRasterW, nRasterH);
|
||||
}
|
||||
WASM_EXPORT BYTE* XPS_GetStructure(CGraphicsFileDrawing* pGraphics)
|
||||
{
|
||||
@ -158,24 +158,7 @@ int main()
|
||||
}
|
||||
}
|
||||
|
||||
BYTE* res = NULL;
|
||||
if (pages_count > 0)
|
||||
res = XPS_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();
|
||||
|
||||
BYTE* pInternal = XPS_GetInternalLinks(test, 22);
|
||||
BYTE* pInternal = XPS_GetInternalLinks(test, 22, width, height);
|
||||
nLength = GetLength(pInternal);
|
||||
i = 4;
|
||||
nLength -= 4;
|
||||
@ -202,7 +185,7 @@ int main()
|
||||
i += nPathLength;
|
||||
}
|
||||
|
||||
BYTE* pExternal = XPS_GetExternalLinks(test, 22);
|
||||
BYTE* pExternal = XPS_GetExternalLinks(test, 22, width, height);
|
||||
nLength = GetLength(pExternal);
|
||||
i = 4;
|
||||
nLength -= 4;
|
||||
@ -252,10 +235,29 @@ int main()
|
||||
i += nPathLength;
|
||||
}
|
||||
|
||||
BYTE* res = NULL;
|
||||
if (pages_count > 0)
|
||||
res = XPS_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();
|
||||
|
||||
XPS_Close(test);
|
||||
RELEASEARRAYOBJECTS(info);
|
||||
RELEASEARRAYOBJECTS(res);
|
||||
RELEASEARRAYOBJECTS(pGlyphs);
|
||||
RELEASEARRAYOBJECTS(pInternal);
|
||||
RELEASEARRAYOBJECTS(pExternal);
|
||||
RELEASEARRAYOBJECTS(pStructure);
|
||||
RELEASEOBJECT(resFrame);
|
||||
return 0;
|
||||
|
||||
@ -82,13 +82,13 @@ public:
|
||||
{
|
||||
return ((CDjVuFile*)pReader)->GetPageGlyphs(nPageIndex, nRasterW, nRasterH);
|
||||
}
|
||||
BYTE* GetXPSExternalLinks(int nPageIndex)
|
||||
BYTE* GetXPSExternalLinks(int nPageIndex, int nRasterW, int nRasterH)
|
||||
{
|
||||
return ((CXpsFile*)pReader)->GetExternalLinks(nPageIndex);
|
||||
return ((CXpsFile*)pReader)->GetExternalLinks(nPageIndex, nRasterW, nRasterH);
|
||||
}
|
||||
BYTE* GetXPSInternalLinks(int nPageIndex)
|
||||
BYTE* GetXPSInternalLinks(int nPageIndex, int nRasterW, int nRasterH)
|
||||
{
|
||||
return ((CXpsFile*)pReader)->GetInternalLinks(nPageIndex);
|
||||
return ((CXpsFile*)pReader)->GetInternalLinks(nPageIndex, nRasterW, nRasterH);
|
||||
}
|
||||
BYTE* GetXPSStructure()
|
||||
{
|
||||
|
||||
@ -74,6 +74,7 @@ public:
|
||||
|
||||
CXpsFile::CXpsFile(NSFonts::IApplicationFonts* pAppFonts)
|
||||
{
|
||||
nLastW = -1, nLastH = -1;
|
||||
m_pInternal = new CXpsFile_Private(pAppFonts);
|
||||
}
|
||||
CXpsFile::~CXpsFile()
|
||||
@ -166,10 +167,11 @@ void CXpsFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pB
|
||||
if (!m_pInternal->m_pDocument)
|
||||
return;
|
||||
|
||||
m_pInternal->m_pDocument->DrawPage(nPageIndex, pRenderer, pBreak);
|
||||
m_pInternal->m_pDocument->DrawPage(nPageIndex, pRenderer, pBreak, nLastW, nLastH);
|
||||
}
|
||||
BYTE* CXpsFile::ConvertToPixels(int nPageIndex, int nRasterW, int nRasterH)
|
||||
{
|
||||
nLastW = nRasterW, nLastH = nRasterH;
|
||||
NSFonts::IFontManager *pFontManager = m_pInternal->m_pAppFonts->GenerateFontManager();
|
||||
NSFonts::IFontsCache* pFontCache = NSFonts::NSFontCache::Create();
|
||||
pFontCache->SetStreams(m_pInternal->m_pAppFonts->GetStreams());
|
||||
@ -283,22 +285,35 @@ void CXpsFile::ConvertToPdf(const std::wstring& wsPath)
|
||||
oPdf.SaveToFile(wsPath);
|
||||
}
|
||||
#ifdef BUILDING_WASM_MODULE
|
||||
BYTE* CXpsFile::GetGlyphs(int nPageIndex, int nRasterW, int nRasterH)
|
||||
{
|
||||
BYTE* oTemp = ConvertToPixels(nPageIndex, nRasterW, nRasterH);
|
||||
RELEASEARRAYOBJECTS(oTemp);
|
||||
return m_pInternal->m_pDocument->GetPageGlyphs(nPageIndex);
|
||||
}
|
||||
BYTE* CXpsFile::GetStructure()
|
||||
{
|
||||
return m_pInternal->m_pDocument->GetStructure();
|
||||
}
|
||||
BYTE* CXpsFile::GetExternalLinks(int nPageIndex)
|
||||
BYTE* CXpsFile::GetGlyphs (int nPageIndex, int nRasterW, int nRasterH)
|
||||
{
|
||||
if (!m_pInternal->m_pDocument->CompareWH(nPageIndex, nRasterW, nRasterH))
|
||||
{
|
||||
BYTE* oTemp = ConvertToPixels(nPageIndex, nRasterW, nRasterH);
|
||||
RELEASEARRAYOBJECTS(oTemp);
|
||||
}
|
||||
return m_pInternal->m_pDocument->GetPageGlyphs(nPageIndex);
|
||||
}
|
||||
BYTE* CXpsFile::GetExternalLinks(int nPageIndex, int nRasterW, int nRasterH)
|
||||
{
|
||||
if (!m_pInternal->m_pDocument->CompareWH(nPageIndex, nRasterW, nRasterH))
|
||||
{
|
||||
BYTE* oTemp = ConvertToPixels(nPageIndex, nRasterW, nRasterH);
|
||||
RELEASEARRAYOBJECTS(oTemp);
|
||||
}
|
||||
return m_pInternal->m_pDocument->GetExternalLinks(nPageIndex);
|
||||
}
|
||||
BYTE* CXpsFile::GetInternalLinks(int nPageIndex)
|
||||
BYTE* CXpsFile::GetInternalLinks(int nPageIndex, int nRasterW, int nRasterH)
|
||||
{
|
||||
if (!m_pInternal->m_pDocument->CompareWH(nPageIndex, nRasterW, nRasterH))
|
||||
{
|
||||
BYTE* oTemp = ConvertToPixels(nPageIndex, nRasterW, nRasterH);
|
||||
RELEASEARRAYOBJECTS(oTemp);
|
||||
}
|
||||
return m_pInternal->m_pDocument->GetInternalLinks(nPageIndex);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -67,13 +67,14 @@ public:
|
||||
|
||||
void ConvertToPdf(const std::wstring& wsDstPath);
|
||||
#ifdef BUILDING_WASM_MODULE
|
||||
BYTE* GetGlyphs(int nPageIndex, int nRasterW, int nRasterH);
|
||||
BYTE* GetStructure();
|
||||
BYTE* GetExternalLinks(int nPageIndex);
|
||||
BYTE* GetInternalLinks(int nPageIndex);
|
||||
BYTE* GetGlyphs (int nPageIndex, int nRasterW, int nRasterH);
|
||||
BYTE* GetExternalLinks(int nPageIndex, int nRasterW, int nRasterH);
|
||||
BYTE* GetInternalLinks(int nPageIndex, int nRasterW, int nRasterH);
|
||||
#endif
|
||||
|
||||
private:
|
||||
int nLastW, nLastH;
|
||||
CXpsFile_Private* m_pInternal;
|
||||
};
|
||||
|
||||
|
||||
@ -322,12 +322,19 @@ namespace XPS
|
||||
return oIter->second->GetInternalLinks();
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
void CDocument::DrawPage(int nPageIndex, IRenderer* pRenderer, bool* pbBreak)
|
||||
bool CDocument::CompareWH(int nPageIndex, int nRasterW, int nRasterH)
|
||||
{
|
||||
std::map<int, XPS::Page*>::const_iterator oIter = m_mPages.find(nPageIndex);
|
||||
if (oIter != m_mPages.end())
|
||||
oIter->second->Draw(pRenderer, pbBreak);
|
||||
return oIter->second->CompareWH(nRasterW, nRasterH);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
void CDocument::DrawPage(int nPageIndex, IRenderer* pRenderer, bool* pbBreak, int nRasterW, int nRasterH)
|
||||
{
|
||||
std::map<int, XPS::Page*>::const_iterator oIter = m_mPages.find(nPageIndex);
|
||||
if (oIter != m_mPages.end())
|
||||
oIter->second->Draw(pRenderer, pbBreak, nRasterW, nRasterH);
|
||||
}
|
||||
void CDocument::Close()
|
||||
{
|
||||
|
||||
@ -54,7 +54,7 @@ namespace XPS
|
||||
bool Read(IFolder* pFolder);
|
||||
int GetPageCount() const;
|
||||
void GetPageSize(int nPageIndex, int& nW, int& nH);
|
||||
void DrawPage(int nPageIndex, IRenderer* pRenderer, bool* pbBreak);
|
||||
void DrawPage(int nPageIndex, IRenderer* pRenderer, bool* pbBreak, int nRasterW, int nRasterH);
|
||||
void Close();
|
||||
CStaticResource* GetStaticResource(const wchar_t* wsPath);
|
||||
|
||||
@ -71,6 +71,7 @@ namespace XPS
|
||||
BYTE* GetPageGlyphs(int nPageIndex);
|
||||
BYTE* GetExternalLinks(int nPageIndex);
|
||||
BYTE* GetInternalLinks(int nPageIndex);
|
||||
bool CompareWH(int nPageIndex, int nRasterW, int nRasterH);
|
||||
std::vector<CDocumentStructure> m_vStructure;
|
||||
std::map<std::wstring, int> m_mInternalLinks;
|
||||
#endif
|
||||
|
||||
@ -89,6 +89,7 @@ namespace XPS
|
||||
m_pDocument = pDocument;
|
||||
#ifdef BUILDING_WASM_MODULE
|
||||
m_pGlyphs = NULL;
|
||||
nLastW = -1, nLastH = -1;
|
||||
#endif
|
||||
}
|
||||
Page::~Page()
|
||||
@ -232,11 +233,18 @@ namespace XPS
|
||||
oRes.ClearWithoutAttack();
|
||||
return res;
|
||||
}
|
||||
bool Page::CompareWH(int nRasterW, int nRasterH)
|
||||
{
|
||||
return nRasterW == nLastW && nRasterH == nLastH;
|
||||
}
|
||||
#endif
|
||||
void Page::Draw(IRenderer* pRenderer, bool* pbBreak)
|
||||
void Page::Draw(IRenderer* pRenderer, bool* pbBreak, int nRasterW, int nRasterH)
|
||||
{
|
||||
#ifdef BUILDING_WASM_MODULE
|
||||
nLastW = nRasterW, nLastH = nRasterH;
|
||||
RELEASEOBJECT(m_pGlyphs);
|
||||
m_vExternalLinks.clear();
|
||||
m_vInternalLinks.clear();
|
||||
#endif
|
||||
XmlUtils::CXmlLiteReader oReader;
|
||||
|
||||
|
||||
@ -53,10 +53,12 @@ namespace XPS
|
||||
~Page();
|
||||
|
||||
void GetSize(int& nW, int& nH) const;
|
||||
void Draw(IRenderer* pRenderer, bool* pbBreak, int nRasterW, int nRasterH);
|
||||
#ifdef BUILDING_WASM_MODULE
|
||||
BYTE* GetGlyphs();
|
||||
BYTE* GetExternalLinks();
|
||||
BYTE* GetInternalLinks();
|
||||
bool CompareWH(int nRasterW, int nRasterH);
|
||||
class CData
|
||||
{
|
||||
protected:
|
||||
@ -179,6 +181,8 @@ namespace XPS
|
||||
memcpy(m_pData, &len, sizeof(unsigned int));
|
||||
}
|
||||
};
|
||||
private:
|
||||
|
||||
CData* m_pGlyphs;
|
||||
struct CPageLink
|
||||
{
|
||||
@ -191,8 +195,8 @@ namespace XPS
|
||||
};
|
||||
std::vector<CPageLink> m_vExternalLinks;
|
||||
std::vector<CPageLink> m_vInternalLinks;
|
||||
int nLastW, nLastH;
|
||||
#endif
|
||||
void Draw(IRenderer* pRenderer, bool* pbBreak);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user