Skip to content

Commit

Permalink
Use wmf&emf instead conversion to svg in zip images (for native conve…
Browse files Browse the repository at this point in the history
…rtations)
  • Loading branch information
K0R0L committed Jan 25, 2025
1 parent d3d4e86 commit 63887c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
10 changes: 9 additions & 1 deletion DesktopEditor/doctrenderer/embed/ZipEmbed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,15 @@ JSSmart<CJSValue> CZipEmbed::getImageBuffer(JSSmart<CJSValue> filePath)
return CJSContext::createNull();
}

if (oChecker.eFileType != _CXIMAGE_FORMAT_WMF && oChecker.eFileType != _CXIMAGE_FORMAT_EMF)
bool bIsNeedConvertMetfileToSvg = false;

// Make as wasm module
if (oChecker.eFileType == _CXIMAGE_FORMAT_WMF || oChecker.eFileType == _CXIMAGE_FORMAT_EMF)
oChecker.eFileType = _CXIMAGE_FORMAT_SVG;
else
bIsNeedConvertMetfileToSvg = false;

if (!bIsNeedConvertMetfileToSvg)
{
BYTE* pMemory = NSJSBase::NSAllocator::Alloc(nBufferSize);
memcpy(pMemory, pBuffer->Buffer, nBufferSize);
Expand Down
17 changes: 11 additions & 6 deletions DesktopEditor/fontengine/js/engine/module_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,25 +542,30 @@ ZLib.prototype.getImageBuffer = function(path)
data : null
};
result.type = this.getImageType(path);
if (result.type === 0)
return null;

let fileData = this.getFile(path);
result.data = new Uint8Array(fileData.length);
result.data.set(fileData);

if (result.type != 10 &&
result.type != 21)
{
let fileData = this.getFile(path);
result.data = new Uint8Array(fileData.length);
result.data.set(fileData);
return result;
}

result.type = 24;
// Source was saved as result.data for using original image in native convertations.
// But for js we need svg for metafiles.

let fileData = this.getFile(path);
let encodedData = Module["_Raster_Encode"](this.files[path].p + 4, fileData.length, 24);
let encodedSize = Module["_Raster_GetEncodedSize"](encodedData);
let encodedBuffer = Module["_Raster_GetEncodedBuffer"](encodedData);

let fileDataEnc = new Uint8Array(Module["HEAP8"].buffer, encodedBuffer, encodedSize);
result.data = new Uint8Array(fileDataEnc.length);
result.data.set(fileDataEnc);
result.dataBlob = new Uint8Array(fileDataEnc.length);
result.dataBlob.set(fileDataEnc);

Module["_Raster_DestroyEncodedData"](encodedData);
return result;
Expand Down
2 changes: 1 addition & 1 deletion DesktopEditor/fontengine/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ function onLoadFontsModule(window, undefined)
{
try
{
let blob = new Blob([result.data], {type: blobType});
let blob = new Blob([result.dataBlob ? result.dataBlob : result.data], {type: blobType});
blobUrl = window.URL.createObjectURL(blob);
}
catch (e)
Expand Down

0 comments on commit 63887c9

Please sign in to comment.