mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-20 03:08:28 +08:00
xps texture in memory
This commit is contained in:
@ -951,7 +951,45 @@ HRESULT CGraphicsRenderer::DrawPath(const LONG& nType)
|
||||
}
|
||||
else
|
||||
{
|
||||
pTextureBrush = new Aggplus::CBrushTexture(m_oBrush.TexturePath, oMode);
|
||||
#ifdef BUILDING_WASM_MODULE
|
||||
if (m_oBrush.TexturePath.find(L"data:") == 0)
|
||||
{
|
||||
bool bIsOnlyOfficeHatch = false;
|
||||
if (m_oBrush.TexturePath.find(L"onlyoffice_hatch") != std::wstring::npos)
|
||||
bIsOnlyOfficeHatch = true;
|
||||
m_oBrush.TexturePath.erase(0, m_oBrush.TexturePath.find(L',') + 1);
|
||||
std::string sBase64MultyByte(m_oBrush.TexturePath.begin(), m_oBrush.TexturePath.end());
|
||||
int nDecodeLen = NSBase64::Base64DecodeGetRequiredLength(sBase64MultyByte.length());
|
||||
BYTE* pImageData = new BYTE[nDecodeLen + 64];
|
||||
if (TRUE == NSBase64::Base64Decode(sBase64MultyByte.c_str(), sBase64MultyByte.length(), pImageData, &nDecodeLen))
|
||||
{
|
||||
CBgraFrame oFrame;
|
||||
if (bIsOnlyOfficeHatch)
|
||||
{
|
||||
int nSize = (int)sqrt(nDecodeLen >> 2);
|
||||
oFrame.put_IsRGBA(true);
|
||||
oFrame.put_Data(pImageData);
|
||||
oFrame.put_Width(nSize);
|
||||
oFrame.put_Height(nSize);
|
||||
oFrame.put_Stride(4 * nSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
oFrame.put_IsRGBA(false);
|
||||
oFrame.Decode(pImageData, nDecodeLen);
|
||||
RELEASEARRAYOBJECTS(pImageData);
|
||||
}
|
||||
// pImage отдается pTextureBrush и освобождается вместе с pBrush
|
||||
Aggplus::CImage* pImage = new Aggplus::CImage();
|
||||
pImage->Create(oFrame.get_Data(), oFrame.get_Width(), oFrame.get_Height(), oFrame.get_Stride());
|
||||
oFrame.ClearNoAttack();
|
||||
pTextureBrush = new Aggplus::CBrushTexture(pImage, oMode);
|
||||
pTextureBrush->m_bReleaseImage = TRUE;
|
||||
}
|
||||
}
|
||||
#else
|
||||
pTextureBrush = new Aggplus::CBrushTexture(m_oBrush.TexturePath, oMode);
|
||||
#endif
|
||||
}
|
||||
|
||||
if( pTextureBrush )
|
||||
|
||||
@ -22,6 +22,13 @@ if not base.is_dir("emsdk"):
|
||||
base.cmd(command_prefix + "emsdk", ["activate", "latest"])
|
||||
os.chdir("../")
|
||||
|
||||
if not base.is_dir("xml"):
|
||||
base.copy_dir("../../../xml", "./xml")
|
||||
base.replaceInFile("./xml/libxml2/libxml.h", "xmlNop(void)", "xmlNop(void* context, char* buffer, int len)")
|
||||
base.replaceInFile("./xml/libxml2/xmlIO.c", "xmlNop(void)", "xmlNop(void* context, char* buffer, int len)")
|
||||
base.replaceInFile("./xml/src/xmllight_private.h", "#include \"../../common/", "#include \"../../../../../common/")
|
||||
base.replaceInFile("./xml/include/xmlutils.h", "#include \"../../common/", "#include \"../../../../../common/")
|
||||
|
||||
# compile
|
||||
compiler_flags = ["-O3",
|
||||
"-fno-rtti",
|
||||
@ -41,14 +48,14 @@ exported_functions = ["_malloc",
|
||||
"_Graphics_GetPageHeight",
|
||||
"_Graphics_GetPageWidth",
|
||||
"_Graphics_GetPage",
|
||||
"_Graphics_TEST",
|
||||
"_Graphics_Load",
|
||||
"_Fonts_Create",
|
||||
"_Fonts_Destroy",
|
||||
"_Fonts_Add",
|
||||
"_Fonts_Remove"]
|
||||
|
||||
libGraphics_src_path = "../../"
|
||||
input_graphics_sources = ["GraphicsRenderer.cpp", "pro/pro_Graphics.cpp", "pro/pro_Fonts.cpp", "Graphics.cpp", "Brush.cpp", "GraphicsPath.cpp", "Image.cpp", "Matrix.cpp", "Clip.cpp"]
|
||||
input_graphics_sources = ["GraphicsRenderer.cpp", "pro/pro_Graphics.cpp", "pro/pro_Fonts.cpp", "Graphics.cpp", "Brush.cpp", "GraphicsPath.cpp", "Image.cpp", "Matrix.cpp", "Clip.cpp", "TemporaryCS.cpp"]
|
||||
|
||||
libFontEngine_src_path = "../../../fontengine/"
|
||||
input_fontengine_sources = ["GlyphString.cpp", "FontManager.cpp", "FontFile.cpp", "FontPath.cpp", "ApplicationFonts.cpp"]
|
||||
@ -68,6 +75,14 @@ input_unicodeconverter_sources = ["UnicodeConverter.cpp"]
|
||||
libIcu_src_path = "../../../../Common/3dParty/icu/icu/source/common/"
|
||||
input_icu_sources = ["ucnv.c", "ustr_wcs.cpp", "ucnv_err.c", "ucnv_bld.cpp", "ustrtrns.cpp", "ucnv_cb.c", "udata.cpp", "ucnv_io.cpp", "uhash.c", "udatamem.c", "cmemory.c", "ustring.cpp", "umutex.cpp", "putil.cpp", "ustr_cnv.cpp", "ucnvmbcs.cpp", "ucnvlat1.c", "ucnv_u16.c", "ucnv_u8.c", "ucnv_u32.c", "ucnv_u7.c", "ucln_cmn.cpp", "ucnv2022.cpp", "ucnv_lmb.c", "ucnvhz.c", "ucnvscsu.c", "ucnvisci.c", "ucnvbocu.cpp", "ucnv_ct.c", "ucnv_cnv.c", "stringpiece.cpp", "charstr.cpp", "umapfile.c", "ucmndata.c", "ucnv_ext.cpp", "uobject.cpp", "umath.c"]
|
||||
|
||||
libXps_src_path = "../../../../XpsFile/"
|
||||
input_xps_sources = ["XpsFile.cpp", "XpsLib/Document.cpp"]
|
||||
|
||||
libOfficeUtils_src_parh = "../../../../OfficeUtils/src/"
|
||||
input_officeutils_sources = ["OfficeUtils.cpp", "ZipBuffer.cpp"]
|
||||
|
||||
input_xml_sources = ["xml/src/xmllight.cpp", "xml/src/xmldom.cpp", "xml/build/qt/libxml2_all.c", "xml/build/qt/libxml2_all2.c"]
|
||||
|
||||
# sources
|
||||
sources = []
|
||||
for item in input_graphics_sources:
|
||||
@ -83,11 +98,18 @@ for item in input_common_sources:
|
||||
for item in input_unicodeconverter_sources:
|
||||
sources.append(libUnicodeConverter_src_path + item)
|
||||
# icu
|
||||
for item in input_xps_sources:
|
||||
sources.append(libXps_src_path + item)
|
||||
for item in input_officeutils_sources:
|
||||
sources.append(libOfficeUtils_src_parh + item)
|
||||
for item in input_xml_sources:
|
||||
sources.append(item)
|
||||
sources.append("raster.o")
|
||||
sources.append("wasm/src/graphics.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")
|
||||
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")
|
||||
compiler_flags.append("-D__linux__ -D_LINUX -DFT2_BUILD_LIBRARY -DHAVE_FCNTL_H -DFT_CONFIG_OPTION_SYSTEM_ZLIB -DBUILDING_WASM_MODULE -DU_COMMON_IMPLEMENTATION")
|
||||
compiler_flags.append("-DHAVE_VA_COPY -DLIBXML_READER_ENABLED -DLIBXML_PUSH_ENABLED -DLIBXML_HTML_ENABLED -DLIBXML_XPATH_ENABLED -DLIBXML_OUTPUT_ENABLED -DLIBXML_C14N_ENABLED -DLIBXML_SAX1_ENABLED -DLIBXML_TREE_ENABLED -DLIBXML_XPTR_ENABLED -DIN_LIBXML -DLIBXML_STATIC")
|
||||
|
||||
# arguments
|
||||
arguments = ""
|
||||
@ -156,4 +178,5 @@ base.copy_file("./wasm/js/code_graphics.js", "./deploy/code_graphics.js")
|
||||
base.delete_file("graphics.js")
|
||||
base.delete_file("graphics.wasm")
|
||||
base.delete_dir("./temp")
|
||||
base.delete_file("raster.o")
|
||||
base.delete_dir("./xml")
|
||||
#base.delete_file("raster.o")
|
||||
|
||||
@ -51,7 +51,7 @@ window.onload = function()
|
||||
|
||||
window.testGraphics = function(data)
|
||||
{
|
||||
window.loadedImage = window.nativeGraphics.testImage(211, 119, 55.8251, 31.2208, data);
|
||||
window.loadedImage = window.nativeGraphics.testImage(data);
|
||||
if (!window.loadedImage)
|
||||
return;
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
this.isInit = false;
|
||||
this.engine = 0;
|
||||
|
||||
this.testImage = function(wF, hF, width, height, dataBuffer)
|
||||
this.testImage = function(dataBuffer)
|
||||
{
|
||||
if (!this.isInit)
|
||||
return null;
|
||||
@ -18,12 +18,9 @@
|
||||
if (this.engine)
|
||||
this.close();
|
||||
|
||||
this.engine = Module["_Graphics_Create"](wF, hF, width, height);
|
||||
this.engine = Module["_Graphics_Create"]();
|
||||
if (0 === this.engine)
|
||||
return null;
|
||||
var fonts = Module["_Fonts_Create"]();
|
||||
if (0 === fonts)
|
||||
return null;
|
||||
|
||||
var imageFileRawDataSize = dataBuffer.byteLength;
|
||||
var imageFileRawData = Module["_Graphics_Malloc"](imageFileRawDataSize);
|
||||
@ -32,22 +29,11 @@
|
||||
|
||||
var uint8DataBuffer = new Uint8Array(dataBuffer);
|
||||
Module["HEAP8"].set(uint8DataBuffer, imageFileRawData);
|
||||
Module["_Graphics_Load"](this.engine, imageFileRawData, imageFileRawDataSize);
|
||||
|
||||
var tmp = "Arial".toUtf8();
|
||||
var pointer = Module["_Graphics_Malloc"](tmp.length);
|
||||
if (0 === pointer)
|
||||
return null;
|
||||
Module["HEAP8"].set(tmp, pointer);
|
||||
|
||||
Module["_Fonts_Add"](fonts, pointer, imageFileRawData, imageFileRawDataSize);
|
||||
Module["_Graphics_TEST"](this.engine);
|
||||
|
||||
Module["_Graphics_Free"](pointer);
|
||||
Module["_Graphics_Free"](imageFileRawData);
|
||||
|
||||
var imageW = Module["_Graphics_GetPageWidth"](this.engine, 1);
|
||||
var imageH = Module["_Graphics_GetPageHeight"](this.engine, 1);
|
||||
var imageRGBA = Module["_Graphics_GetPage"](this.engine, imageW, imageH);
|
||||
var imageW = Module["_Graphics_GetPageWidth"](this.engine, 0);
|
||||
var imageH = Module["_Graphics_GetPageHeight"](this.engine, 0);
|
||||
var imageRGBA = Module["_Graphics_GetPage"](this.engine, 0, imageW, imageH);
|
||||
|
||||
if (imageW <= 0 || imageH <= 0 || 0 === imageRGBA)
|
||||
{
|
||||
@ -65,7 +51,7 @@
|
||||
|
||||
canvasCtx.putImageData(canvasData, 0, 0);
|
||||
|
||||
Module["_Fonts_Destroy"]();
|
||||
Module["_Graphics_Free"](imageFileRawData);
|
||||
this.close();
|
||||
return canvas;
|
||||
}
|
||||
|
||||
@ -667,8 +667,9 @@ 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;
|
||||
DWORD nBytesCount;
|
||||
NSFile::CFileBinary oFile;
|
||||
@ -681,25 +682,26 @@ int main()
|
||||
return 1;
|
||||
}
|
||||
oFile.CloseFile();
|
||||
*/
|
||||
|
||||
Fonts_Add(fonts, "Arial", pData, nBytesCount);
|
||||
//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();
|
||||
Graphics_Destroy(test);
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
RELEASEARRAYOBJECTS(pXpsData);
|
||||
return 1;
|
||||
}
|
||||
oFile.CloseFile();
|
||||
|
||||
Graphics_Load(test, pXpsData, nXpsBytesCount);
|
||||
int nHeight = Graphics_GetPageHeight(test, 1);
|
||||
int nWidth = Graphics_GetPageWidth(test, 1);
|
||||
BYTE* res = Graphics_GetPage(test, 1, nWidth, nHeight);
|
||||
int nHeight = Graphics_GetPageHeight(test, 0);
|
||||
int nWidth = Graphics_GetPageWidth(test, 0);
|
||||
BYTE* res = Graphics_GetPage(test, 0, nWidth, nHeight);
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
std::cout << (int)res[i] << " ";
|
||||
@ -711,9 +713,10 @@ int main()
|
||||
resFrame->put_Stride(-4 * nWidth);
|
||||
|
||||
resFrame->SaveFile(NSFile::GetProcessDirectory() + L"/res.png", _CXIMAGE_FORMAT_PNG);
|
||||
Fonts_Destroy();
|
||||
//Fonts_Destroy();
|
||||
Graphics_Destroy(test);
|
||||
RELEASEARRAYOBJECTS(pData);
|
||||
RELEASEARRAYOBJECTS(pXpsData);
|
||||
RELEASEARRAYOBJECTS(res);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -15,7 +15,7 @@ public:
|
||||
CGraphicsFileDrawing()
|
||||
{
|
||||
pApplicationFonts = NSFonts::NSApplication::Create();
|
||||
pApplicationFonts->Initialize();
|
||||
//pApplicationFonts->Initialize();
|
||||
pReader = new CXpsFile(pApplicationFonts);
|
||||
}
|
||||
~CGraphicsFileDrawing()
|
||||
@ -37,14 +37,14 @@ public:
|
||||
double dPageDpiX, dPageDpiY;
|
||||
double dWidth, dHeight;
|
||||
pReader->GetPageInfo(nPageIndex, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY);
|
||||
return dHeight;
|
||||
return dHeight * 96 / dPageDpiX;
|
||||
}
|
||||
int GetPageWidth (int nPageIndex)
|
||||
{
|
||||
double dPageDpiX, dPageDpiY;
|
||||
double dWidth, dHeight;
|
||||
pReader->GetPageInfo(nPageIndex, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY);
|
||||
return dWidth;
|
||||
return dWidth * 96 / dPageDpiX;
|
||||
}
|
||||
BYTE* GetPage (int nPageIndex, int nRasterW, int nRasterH)
|
||||
{
|
||||
|
||||
@ -206,6 +206,7 @@ BYTE* CXpsFile::ConvertToPixels(int nPageIndex, int nRasterW, int nRasterH)
|
||||
|
||||
RELEASEINTERFACE(pFontManager);
|
||||
RELEASEOBJECT(pRenderer);
|
||||
oFrame.ClearNoAttack();
|
||||
return pBgraData;
|
||||
}
|
||||
void CXpsFile::ConvertToRaster(int nPageIndex, const std::wstring& wsDstPath, int nImageType, const int nRasterW, const int nRasterH)
|
||||
|
||||
@ -160,9 +160,21 @@ namespace XPS
|
||||
return false;
|
||||
}
|
||||
|
||||
pRenderer->put_BrushType(c_BrushTypeTexture);
|
||||
pRenderer->put_BrushTexturePath(m_wsRoot->getFullFilePath(wsPath));
|
||||
return true;
|
||||
IFolder::CBuffer* buffer = NULL;
|
||||
m_wsRoot->read(wsPath, buffer);
|
||||
int nBase64BufferLen = NSBase64::Base64EncodeGetRequiredLength(buffer->Size);
|
||||
BYTE* pbBase64Buffer = new BYTE[nBase64BufferLen + 64];
|
||||
if (true == NSBase64::Base64Encode(buffer->Buffer, buffer->Size, pbBase64Buffer, &nBase64BufferLen))
|
||||
{
|
||||
pRenderer->put_BrushType(c_BrushTypeTexture);
|
||||
pRenderer->put_BrushTexturePath(L"data:," + NSFile::CUtf8Converter::GetUnicodeStringFromUTF8(pbBase64Buffer, nBase64BufferLen));
|
||||
RELEASEARRAYOBJECTS(pbBase64Buffer);
|
||||
RELEASEOBJECT(buffer);
|
||||
return true;
|
||||
}
|
||||
RELEASEARRAYOBJECTS(pbBase64Buffer);
|
||||
RELEASEOBJECT(buffer);
|
||||
return false;
|
||||
}
|
||||
void CImageBrush::SetPaths(IFolder* wsRoot, const wchar_t* wsPage)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user