diff --git a/DesktopEditor/fontengine/FontManager.cpp b/DesktopEditor/fontengine/FontManager.cpp index 90961da84a..6e621c6c8b 100644 --- a/DesktopEditor/fontengine/FontManager.cpp +++ b/DesktopEditor/fontengine/FontManager.cpp @@ -122,6 +122,8 @@ NSFonts::IFontStream* CApplicationFontStreams::GetStream(const std::wstring &str if (NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage()) { pStream = (CFontStream*)NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage()->Get(strFile); + // чтобы удалить и из мапа и из стораджа + pStream->AddRef(); } else { @@ -153,13 +155,11 @@ void CApplicationFontStreams::Clear() { if (NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage()) NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage()->Clear(); - else + + for (std::map::iterator iter = m_mapStreams.begin(); iter != m_mapStreams.end(); ++iter) { - for (std::map::iterator iter = m_mapStreams.begin(); iter != m_mapStreams.end(); ++iter) - { - CFontStream* pFile = iter->second; - RELEASEINTERFACE(pFile); - } + CFontStream* pFile = iter->second; + RELEASEINTERFACE(pFile); } m_mapStreams.clear(); } diff --git a/DesktopEditor/graphics/pro/pro_Fonts.cpp b/DesktopEditor/graphics/pro/pro_Fonts.cpp index 79c667cbad..29a5e0ebcf 100644 --- a/DesktopEditor/graphics/pro/pro_Fonts.cpp +++ b/DesktopEditor/graphics/pro/pro_Fonts.cpp @@ -32,6 +32,7 @@ #include "Fonts.h" #include "../../common/File.h" +#include "../../common/StringExt.h" #include "../../fontengine/ApplicationFonts.h" #ifdef __APPLE__ @@ -165,7 +166,7 @@ namespace NSFonts virtual bool Add(const std::wstring& id, BYTE* data, LONG size, bool bClear = false) { std::wstring sFile = id; - string_replace(sFile, L"\\", L"/"); + NSStringExt::Replace(sFile, L"\\", L"/"); std::map::iterator it = m_mapStreams.find(sFile); if (it != m_mapStreams.end()) return false; @@ -178,7 +179,7 @@ namespace NSFonts virtual bool Remove(const std::wstring& id) { std::wstring sFile = id; - string_replace(sFile, L"\\", L"/"); + NSStringExt::Replace(sFile, L"\\", L"/"); std::map::iterator it = m_mapStreams.find(sFile); if (it == m_mapStreams.end()) return false; @@ -197,7 +198,7 @@ namespace NSFonts virtual IFontStream* Get(const std::wstring& id) { std::wstring sFile = id; - string_replace(sFile, L"\\", L"/"); + NSStringExt::Replace(sFile, L"\\", L"/"); std::map::iterator it = m_mapStreams.find(sFile); return it != m_mapStreams.end() ? it->second : NULL; } diff --git a/DjVuFile/DjVuFileImplementation.cpp b/DjVuFile/DjVuFileImplementation.cpp index 02e0522055..bbb3a4a35f 100644 --- a/DjVuFile/DjVuFileImplementation.cpp +++ b/DjVuFile/DjVuFileImplementation.cpp @@ -337,129 +337,9 @@ void CDjVuFileImplementation::ConvertToPdf(const std::wstring& wsD oPdf.SaveToFile(wsDstPath); } #ifdef BUILDING_WASM_MODULE -class CData -{ -protected: - unsigned char* m_pData; - size_t m_lSize; +#include "../DesktopEditor/graphics/pro/js/wasm/src/serialize.h" - 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) +void getBookmars(const GP& nav, int& pos, int count, NSWasm::CData& out, int level) { while (count > 0 && pos < nav->getBookMarkCount()) { @@ -473,6 +353,7 @@ void getBookmars(const GP& nav, int& pos, int count, CDat { out.AddInt(nPage); out.AddInt(level); + out.AddInt(0); // Y position GUTF8String description = gpBookMark->displayname; out.WriteString((BYTE*)description.getbuf(), description.length()); } @@ -481,7 +362,7 @@ void getBookmars(const GP& nav, int& pos, int count, CDat count--; } } -BYTE* CDjVuFileImplementation::GetStructure() +BYTE* CDjVuFileImplementation::GetStructure() { GP nav = m_pDoc->get_djvm_nav(); if (!nav) @@ -492,7 +373,7 @@ BYTE* CDjVuFileImplementation::GetStructure() if (count <= 0) return NULL; - CData oRes; + NSWasm::CData oRes; oRes.SkipLen(); getBookmars(nav, pos, count, oRes, 1); oRes.WriteLen(); @@ -500,7 +381,7 @@ BYTE* CDjVuFileImplementation::GetStructure() oRes.ClearWithoutAttack(); return bRes; } -BYTE* CDjVuFileImplementation::GetPageGlyphs(int nPageIndex, const int& nRasterW, const int& nRasterH) +BYTE* CDjVuFileImplementation::GetPageGlyphs(int nPageIndex, const int& nRasterW, const int& nRasterH) { double dPageDpiX, dPageDpiY; double dWidth, dHeight; @@ -523,7 +404,7 @@ BYTE* CDjVuFileImplementation::GetPageGlyphs(int nPageIndex, const hiddenText.GetNode(L"PAGECOLUMN", pageColumn); pageColumn.GetNode(L"REGION", region); - CData oRes; + NSWasm::CData oRes; oRes.SkipLen(); double dKoef = 25.4 / pPage->get_dpi(); double dKoefX = (double)nRasterW * dPageDpiX / 25.4 / dWidth; @@ -573,7 +454,7 @@ BYTE* CDjVuFileImplementation::GetPageGlyphs(int nPageIndex, const catch (...) {} return NULL; } -BYTE* CDjVuFileImplementation::GetPageLinks (int nPageIndex, const int& nRasterW, const int& nRasterH) +BYTE* CDjVuFileImplementation::GetPageLinks (int nPageIndex, const int& nRasterW, const int& nRasterH) { double dPageDpiX, dPageDpiY; double dWidth, dHeight; @@ -588,7 +469,7 @@ BYTE* CDjVuFileImplementation::GetPageLinks (int nPageIndex, const return NULL; GPList map_areas = pAnno->ant->map_areas; - CData oRes; + NSWasm::CData oRes; oRes.SkipLen(); double dKoefX = (double)nRasterW / dWidth; double dKoefY = (double)nRasterH / dHeight; @@ -596,16 +477,14 @@ BYTE* CDjVuFileImplementation::GetPageLinks (int nPageIndex, const { GUTF8String str = map_areas[pos]->url; oRes.WriteString((BYTE*)str.getbuf(), str.length()); + double x = map_areas[pos]->get_xmin() * dKoefX; - std::string s = std::to_string(x); - oRes.WriteString((BYTE*)s.c_str(), s.length()); double y = (double)nRasterH - map_areas[pos]->get_ymin() * dKoefY; - s = std::to_string(y); - oRes.WriteString((BYTE*)s.c_str(), s.length()); - s = std::to_string(map_areas[pos]->get_xmax() * dKoefX - x); - oRes.WriteString((BYTE*)s.c_str(), s.length()); - s = std::to_string((double)nRasterH - map_areas[pos]->get_ymax() * dKoefY - y); - oRes.WriteString((BYTE*)s.c_str(), s.length()); + + 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.WriteLen(); diff --git a/XpsFile/XpsFile.cpp b/XpsFile/XpsFile.cpp index 2badc72f6b..dd86f13a3a 100644 --- a/XpsFile/XpsFile.cpp +++ b/XpsFile/XpsFile.cpp @@ -302,20 +302,10 @@ BYTE* CXpsFile::GetStructure() } 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::GetLinks(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->GetPageLinks(nPageIndex); } #endif diff --git a/XpsFile/XpsLib/Document.cpp b/XpsFile/XpsLib/Document.cpp index 8718d53b9d..d0a7373b36 100644 --- a/XpsFile/XpsLib/Document.cpp +++ b/XpsFile/XpsLib/Document.cpp @@ -286,17 +286,16 @@ namespace XPS if (oIter != m_mPages.end()) oIter->second->GetSize(nW, nH); } - #ifdef BUILDING_WASM_MODULE +#ifdef BUILDING_WASM_MODULE BYTE* CDocument::GetStructure() { - XPS::Page::CData oRes; + NSWasm::CData oRes; oRes.SkipLen(); for (const CDocumentStructure& str : m_vStructure) { - std::string sY = std::to_string(str.dY); oRes.AddInt(str.nPage); oRes.AddInt(str.nLevel); - oRes.WriteString((BYTE*)sY.c_str(), sY.length()); + oRes.AddDouble(str.dY); oRes.WriteString((BYTE*)str.sDescription.c_str(), str.sDescription.length()); } oRes.WriteLen(); @@ -318,14 +317,7 @@ namespace XPS return oIter->second->GetLinks(); return NULL; } - bool CDocument::CompareWH(int nPageIndex, int nRasterW, int nRasterH) - { - std::map::const_iterator oIter = m_mPages.find(nPageIndex); - if (oIter != m_mPages.end()) - return oIter->second->CompareWH(nRasterW, nRasterH); - return false; - } - #endif +#endif void CDocument::DrawPage(int nPageIndex, IRenderer* pRenderer, bool* pbBreak, int nRasterW, int nRasterH) { std::map::const_iterator oIter = m_mPages.find(nPageIndex); diff --git a/XpsFile/XpsLib/Document.h b/XpsFile/XpsLib/Document.h index 28db50bb3a..97dab16ad6 100644 --- a/XpsFile/XpsLib/Document.h +++ b/XpsFile/XpsLib/Document.h @@ -70,7 +70,6 @@ namespace XPS BYTE* GetStructure(); BYTE* GetPageGlyphs(int nPageIndex); BYTE* GetPageLinks (int nPageIndex); - bool CompareWH(int nPageIndex, int nRasterW, int nRasterH); std::vector m_vStructure; std::map m_mInternalLinks; #endif diff --git a/XpsFile/XpsLib/XpsPage.cpp b/XpsFile/XpsLib/XpsPage.cpp index ce95b05bf8..83f869b8b2 100644 --- a/XpsFile/XpsLib/XpsPage.cpp +++ b/XpsFile/XpsLib/XpsPage.cpp @@ -171,7 +171,7 @@ namespace XPS nH = wsAttrName.tointeger(); } } - #ifdef BUILDING_WASM_MODULE +#ifdef BUILDING_WASM_MODULE BYTE* Page::GetGlyphs() { if (m_pGlyphs) @@ -185,20 +185,16 @@ namespace XPS } BYTE* Page::GetLinks() { - 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()); - s = std::to_string(link.dX); - oRes.WriteString((BYTE*)s.c_str(), s.length()); - s = std::to_string(link.dY); - oRes.WriteString((BYTE*)s.c_str(), s.length()); - s = std::to_string(link.dW); - oRes.WriteString((BYTE*)s.c_str(), s.length()); - s = std::to_string(link.dH); - 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.WriteLen(); @@ -206,11 +202,7 @@ namespace XPS oRes.ClearWithoutAttack(); return res; } - bool Page::CompareWH(int nRasterW, int nRasterH) - { - return nRasterW == nLastW && nRasterH == nLastH; - } - #endif +#endif void Page::Draw(IRenderer* pRenderer, bool* pbBreak, int nRasterW, int nRasterH) { #ifdef BUILDING_WASM_MODULE @@ -717,10 +709,10 @@ namespace XPS if (!bIsSideways) { - #ifdef BUILDING_WASM_MODULE +#ifdef BUILDING_WASM_MODULE if (!m_pGlyphs) { - m_pGlyphs = new CData(); + m_pGlyphs = new NSWasm::CData(); m_pGlyphs->SkipLen(); } @@ -733,7 +725,7 @@ namespace XPS std::string sFontSize = std::to_string(dFontSize * pdA + pdE); m_pGlyphs->WriteString((BYTE*)sFontSize.c_str(), sFontSize.length()); m_pGlyphs->AddInt(unUtf16Len); - #endif +#endif while (GetNextGlyph(wsIndices.c_str(), nIndicesPos, nIndicesLen, pUtf16, nUtf16Pos, unUtf16Len, oEntry)) { @@ -766,7 +758,7 @@ namespace XPS pState->PushTransform(pTransform); } - #ifdef BUILDING_WASM_MODULE +#ifdef BUILDING_WASM_MODULE double _dX = dXorigin; double _dY = dYorigin; oTransform.TransformPoint(_dX, _dY); @@ -777,7 +769,7 @@ namespace XPS m_pGlyphs->WriteString((BYTE*)sY.c_str(), sY.length()); 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); diff --git a/XpsFile/XpsLib/XpsPage.h b/XpsFile/XpsLib/XpsPage.h index 157c97362a..a9274f4208 100644 --- a/XpsFile/XpsLib/XpsPage.h +++ b/XpsFile/XpsLib/XpsPage.h @@ -39,6 +39,10 @@ #include "Utils.h" #include "ContextState.h" +#ifdef BUILDING_WASM_MODULE +#include "../../DesktopEditor/graphics/pro/js/wasm/src/serialize.h" +#endif + namespace XPS { class CDocument; @@ -52,135 +56,14 @@ namespace XPS void GetSize(int& nW, int& nH) const; void Draw(IRenderer* pRenderer, bool* pbBreak, int nRasterW, int nRasterH); - #ifdef BUILDING_WASM_MODULE + + #ifdef BUILDING_WASM_MODULE BYTE* GetGlyphs(); BYTE* GetLinks(); - bool CompareWH(int nRasterW, int nRasterH); - 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)); - } - }; private: - CData* m_pGlyphs; + NSWasm::CData* m_pGlyphs; struct CPageLink { double dX; @@ -191,7 +74,7 @@ namespace XPS }; std::vector m_vLinks; int nLastW, nLastH; - #endif + #endif private: