diff --git a/DesktopEditor/fontengine/FontManager.cpp b/DesktopEditor/fontengine/FontManager.cpp index 4094116a5d..bb2a0c1976 100644 --- a/DesktopEditor/fontengine/FontManager.cpp +++ b/DesktopEditor/fontengine/FontManager.cpp @@ -81,25 +81,14 @@ int CFontStream::CreateFromFile(const std::wstring& strFileName, BYTE* pDataUse) return true; } -int CFontStream::CreateFromMemory(BYTE* pData, LONG lSize, BYTE* pDataUse) +int CFontStream::CreateFromMemory(BYTE* pData, LONG lSize) { + m_pData = pData; m_lSize = lSize; - - if (NULL == pDataUse) - m_pData = new BYTE[m_lSize]; - else - { - m_bIsAttach = true; - m_pData = pDataUse; - } - - memcpy(m_pData, pData, m_lSize); + m_bIsAttach = true; if (!m_pData) { - if (!m_bIsAttach) - RELEASEARRAYOBJECTS(m_pData); - m_lSize = 0; return FALSE; } @@ -143,8 +132,11 @@ void CApplicationFontStreams::CheckStreams(std::map &mapFiles if (mapFiles.find(iter->first) != mapFiles.end()) { + if (m_pMemoryStorage) + m_pMemoryStorage->Remove(U_TO_UTF8(iter->first)); + else + RELEASEINTERFACE(pFile); iter = m_mapStreams.erase(iter); - RELEASEINTERFACE(pFile); } else iter++; @@ -155,8 +147,13 @@ void CApplicationFontStreams::Clear() { for (std::map::iterator iter = m_mapStreams.begin(); iter != m_mapStreams.end(); ++iter) { - CFontStream* pFile = iter->second; - RELEASEINTERFACE(pFile); + if (m_pMemoryStorage) + m_pMemoryStorage->Remove(U_TO_UTF8(iter->first)); + else + { + CFontStream* pFile = iter->second; + RELEASEINTERFACE(pFile); + } } m_mapStreams.clear(); } diff --git a/DesktopEditor/fontengine/FontManager.h b/DesktopEditor/fontengine/FontManager.h index 9f21531e1f..7ec2f4d80b 100644 --- a/DesktopEditor/fontengine/FontManager.h +++ b/DesktopEditor/fontengine/FontManager.h @@ -49,13 +49,23 @@ public: public: virtual int CreateFromFile(const std::wstring& strFileName, BYTE* pDataUse = NULL); - virtual int CreateFromMemory(BYTE* pData, LONG lSize, BYTE* pDataUse = NULL); + virtual int CreateFromMemory(BYTE* pData, LONG lSize); }; class CGlobalFontsMemoryStorage { private: std::map m_mapStreams; + + void string_replaceA(std::string& text, const std::string& replaceFrom, const std::string& replaceTo) + { + size_t posn = 0; + while (std::string::npos != (posn = text.find(replaceFrom, posn))) + { + text.replace(posn, replaceFrom.length(), replaceTo); + posn += replaceTo.length(); + } + } public: CGlobalFontsMemoryStorage(){} ~CGlobalFontsMemoryStorage() @@ -67,17 +77,21 @@ public: void Add(const std::string& id, BYTE* data, LONG size) { - std::map::iterator it = m_mapStreams.find(id); + std::string sFileA = id; + string_replaceA(sFileA, "\\", "/"); + std::map::iterator it = m_mapStreams.find(sFileA); if (it == m_mapStreams.end()) { CFontStream* pStream = (CFontStream*)NSFonts::NSStream::Create(); pStream->CreateFromMemory(data, size); - m_mapStreams.insert({id, pStream}); + m_mapStreams.insert({sFileA, pStream}); } } void Remove(const std::string& id) { - std::map::iterator it = m_mapStreams.find(id); + std::string sFileA = id; + string_replaceA(sFileA, "\\", "/"); + std::map::iterator it = m_mapStreams.find(sFileA); if (it != m_mapStreams.end()) { RELEASEOBJECT(it->second); @@ -88,6 +102,7 @@ public: CFontStream* Get(const std::wstring& sFile) { std::string sFileA = U_TO_UTF8(sFile); + string_replaceA(sFileA, "\\", "/"); std::map::iterator it = m_mapStreams.find(sFileA); return it != m_mapStreams.end() ? it->second : NULL; } @@ -96,8 +111,8 @@ public: class CApplicationFontStreams : public NSFonts::IApplicationFontStreams { private: - // этот мап нужно периодически опрашивать и удалять неиспользуемые стримы - std::map m_mapStreams; + // этот мап нужно периодически опрашивать и удалять неиспользуемые стримы + std::map m_mapStreams; public: static CGlobalFontsMemoryStorage* m_pMemoryStorage; diff --git a/DesktopEditor/graphics/pro/Fonts.h b/DesktopEditor/graphics/pro/Fonts.h index dc316dff27..a4f820340a 100644 --- a/DesktopEditor/graphics/pro/Fonts.h +++ b/DesktopEditor/graphics/pro/Fonts.h @@ -426,7 +426,7 @@ namespace NSFonts public: virtual int CreateFromFile(const std::wstring& strFileName, unsigned char* pDataUse = NULL) = 0; - virtual int CreateFromMemory(BYTE* pData, LONG lSize, unsigned char* pDataUse = NULL) = 0; + virtual int CreateFromMemory(BYTE* pData, LONG lSize) = 0; }; class GRAPHICS_DECL IApplicationFontStreams : public NSBase::CBaseRefCounter diff --git a/DesktopEditor/graphics/pro/js/graphics_make.py b/DesktopEditor/graphics/pro/js/graphics_make.py index c6f024133c..cc1ac19f4b 100644 --- a/DesktopEditor/graphics/pro/js/graphics_make.py +++ b/DesktopEditor/graphics/pro/js/graphics_make.py @@ -117,7 +117,7 @@ for item in input_xml_sources: for item in input_pdf_sources: sources.append(libPdf_src_path + item) sources.append("raster.o") -sources.append("wasm/src/graphics.cpp") +sources.append("wasm/src/wasmgraphics.cpp") compiler_flags.append("-I../../../agg-2.4/include -I../../../cximage/jasper/include -I../../../cximage/jpeg -I../../../cximage/png -I../../../freetype-2.10.4/include -I../../../freetype-2.10.4/include/freetype -I../../../../OfficeUtils/src/zlib-1.2.11 -I../../../../Common/3dParty/icu/icu/source/common -I../../../xml/libxml2/include -I../../../xml/build/qt -I../../../../OfficeUtils/src/zlib-1.2.11/contrib/minizip -I../../../../OfficeUtils/src/zlib-1.2.11") compiler_flags.append("-D__linux__ -D_LINUX -DFT2_BUILD_LIBRARY -DHAVE_FCNTL_H -DFT_CONFIG_OPTION_SYSTEM_ZLIB -DBUILDING_WASM_MODULE -DU_COMMON_IMPLEMENTATION") diff --git a/DesktopEditor/graphics/pro/js/wasm/js/graphics.js b/DesktopEditor/graphics/pro/js/wasm/js/graphics.js index 442e09435f..c057b6870d 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/graphics.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/graphics.js @@ -56,8 +56,8 @@ canvasCtx.putImageData(canvasData, 0, 0); Module["_Graphics_Free"](imageFileRawData); - Module["_Fonts_Destroy"](); this.close(); + Module["_Fonts_Destroy"](); return canvas; } diff --git a/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.cpp b/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.cpp index 083b3f4120..e33d951015 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/wasmgraphics.cpp @@ -667,7 +667,7 @@ int main() //void* test = Graphics_Create(265, 265, 70.1146, 70.1146); //void* test = Graphics_Create(211, 119, 55.8251, 31.2208); void* test = Graphics_Create(); - //void* fonts = Fonts_Create(); + void* fonts = Fonts_Create(); /* BYTE* pData = NULL; @@ -682,16 +682,15 @@ int main() return 1; } oFile.CloseFile(); - */ - //Fonts_Add(fonts, "Arial", pData, nBytesCount); + */ BYTE* pXpsData = NULL; DWORD nXpsBytesCount; NSFile::CFileBinary oFile; if (!oFile.ReadAllBytes(NSFile::GetProcessDirectory() + L"/test.xps", &pXpsData, nXpsBytesCount)) { - //Fonts_Destroy(); + Fonts_Destroy(); Graphics_Destroy(test); RELEASEARRAYOBJECTS(pXpsData); return 1; @@ -712,11 +711,12 @@ int main() resFrame->put_Width(nWidth); resFrame->put_Height(nHeight); resFrame->put_Stride(-4 * nWidth); + resFrame->put_IsRGBA(true); resFrame->SaveFile(NSFile::GetProcessDirectory() + L"/res.png", _CXIMAGE_FORMAT_PNG); resFrame->ClearNoAttack(); - //Fonts_Destroy(); Graphics_Destroy(test); + Fonts_Destroy(); RELEASEARRAYOBJECTS(pXpsData); RELEASEARRAYOBJECTS(res); RELEASEOBJECT(resFrame); diff --git a/XpsFile/XpsFile.cpp b/XpsFile/XpsFile.cpp index 2055948ba3..5b72e0d334 100644 --- a/XpsFile/XpsFile.cpp +++ b/XpsFile/XpsFile.cpp @@ -197,7 +197,7 @@ BYTE* CXpsFile::ConvertToPixels(int nPageIndex, int nRasterW, int nRasterH) oFrame.put_Stride(-4 * nWidth); pRenderer->CreateFromBgraFrame(&oFrame); - pRenderer->SetSwapRGB(false); + pRenderer->SetSwapRGB(true); pRenderer->put_Width(dWidth); pRenderer->put_Height(dHeight); diff --git a/XpsFile/XpsLib/Page.cpp b/XpsFile/XpsLib/Page.cpp index 14ac0db333..8235070e16 100644 --- a/XpsFile/XpsLib/Page.cpp +++ b/XpsFile/XpsLib/Page.cpp @@ -464,10 +464,14 @@ namespace XPS IFolder::CBuffer* buffer = NULL; m_wsRootPath->read(wsFontPath, buffer); m_pFontList->Check(wsFontName, buffer->Buffer, buffer->Size); - if (CApplicationFontStreams::m_pMemoryStorage) - CApplicationFontStreams::m_pMemoryStorage->Add(U_TO_UTF8(wsFontPath), buffer->Buffer, buffer->Size); m_wsRootPath->write(wsFontPath, buffer->Buffer, buffer->Size); - delete buffer; + RELEASEOBJECT(buffer); + if (CApplicationFontStreams::m_pMemoryStorage) + { + m_wsRootPath->read(wsFontPath, buffer); + CApplicationFontStreams::m_pMemoryStorage->Add(U_TO_UTF8(wsFontPath), buffer->Buffer, buffer->Size); + RELEASEOBJECT(buffer); + } } wsFontPath = NormalizePath(wsFontPath); pRenderer->put_FontPath(wsFontPath);