Fix pdf bugs (add build with embedded fonts in changes)

This commit is contained in:
Oleg Korshul
2024-09-23 21:59:36 +03:00
parent b536d6eb41
commit a5c73127fd
8 changed files with 41 additions and 5 deletions

View File

@ -127,7 +127,12 @@ public:
m_pFile = new CPdfFile(m_pApplicationFonts);
if (!m_pFile->LoadFromFile(sFile, L"", sPassword, sPassword))
{
RELEASEOBJECT(m_pFile);
if (4 != ((CPdfFile*)m_pFile)->GetError())
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 0;
}
else
m_nType = 0;
@ -167,7 +172,12 @@ public:
m_pFile = new CPdfFile(m_pApplicationFonts);
if (!m_pFile->LoadFromMemory(data, size, L"", sPassword, sPassword))
{
RELEASEOBJECT(m_pFile);
if (4 != ((CPdfFile*)m_pFile)->GetError())
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 0;
}
else
m_nType = 0;
@ -484,6 +494,14 @@ public:
return NULL;
}
std::wstring GetFontBinaryNative(const std::wstring& sName)
{
if (0 != m_nType)
return L"";
return ((CPdfFile*)m_pFile)->GetEmbeddedFontPath(sName);
}
private:
int GetPagesCount()
{

View File

@ -71,6 +71,19 @@ JSSmart<CJSValue> CDrawingFileEmbed::DestroyPixmap(JSSmart<CJSValue> typedArray)
return NULL;
}
JSSmart<CJSValue> CDrawingFileEmbed::GetFontBinary(JSSmart<CJSValue> Id)
{
if (0 != m_pFile->GetType())
return NULL;
std::wstring sName = Id->toStringW();
std::wstring sFile = m_pFile->GetFontBinaryNative(sName);
if (sFile.empty())
return NULL;
return CJSContext::createUint8Array(sFile);
}
JSSmart<CJSValue> CDrawingFileEmbed::GetGlyphs(JSSmart<CJSValue> nPageIndex)
{
return WasmMemoryToJS(m_pFile->GetGlyphs(nPageIndex->toInt32()));

View File

@ -40,6 +40,7 @@ public:
JSSmart<CJSValue> GetAnnotationsInfo(JSSmart<CJSValue> nPageIndex);
JSSmart<CJSValue> GetAnnotationsAP(JSSmart<CJSValue> nRasterW, JSSmart<CJSValue> nRasterH, JSSmart<CJSValue> nBackgroundColor, JSSmart<CJSValue> nPageIndex, JSSmart<CJSValue> nAnnot, JSSmart<CJSValue> nView);
JSSmart<CJSValue> GetFontBinary(JSSmart<CJSValue> Id);
JSSmart<CJSValue> GetGlyphs(JSSmart<CJSValue> nPageIndex);
JSSmart<CJSValue> DestroyTextInfo();

View File

@ -20,6 +20,7 @@
-(JSValue*) GetButtonIcons : (JSValue*)nBackgroundColor : (JSValue*)nPageIndex : (JSValue*)bBase64 : (JSValue*)nButtonWidget : (JSValue*)nIconView;
-(JSValue*) GetAnnotationsInfo : (JSValue*)nPageIndex;
-(JSValue*) GetAnnotationsAP : (JSValue*)nRasterW : (JSValue*)nRasterH : (JSValue*)nBackgroundColor : (JSValue*)nPageIndex : (JSValue*)nAnnot : (JSValue*)nView;
-(JSValue*) GetFontBinary : (JSValue*)Id;
-(JSValue*) GetGlyphs : (JSValue*)nPageIndex;
-(JSValue*) DestroyTextInfo;
-(JSValue*) IsNeedCMap;
@ -53,6 +54,7 @@ FUNCTION_WRAPPER_JS_7(GetInteractiveFormsAP, GetInteractiveFormsAP)
FUNCTION_WRAPPER_JS_5(GetButtonIcons, GetButtonIcons)
FUNCTION_WRAPPER_JS_1(GetAnnotationsInfo, GetAnnotationsInfo)
FUNCTION_WRAPPER_JS_6(GetAnnotationsAP, GetAnnotationsAP)
FUNCTION_WRAPPER_JS_1(GetFontBinary, GetFontBinary)
FUNCTION_WRAPPER_JS_1(GetGlyphs, GetGlyphs)
FUNCTION_WRAPPER_JS_0(DestroyTextInfo, DestroyTextInfo)
FUNCTION_WRAPPER_JS_0(IsNeedCMap, IsNeedCMap)

View File

@ -23,6 +23,7 @@ namespace NSDrawingFileEmbed
FUNCTION_WRAPPER_V8_5(_GetButtonIcons, GetButtonIcons)
FUNCTION_WRAPPER_V8_1(_GetAnnotationsInfo, GetAnnotationsInfo)
FUNCTION_WRAPPER_V8_6(_GetAnnotationsAP, GetAnnotationsAP)
FUNCTION_WRAPPER_V8_1(_GetFontBinary, GetFontBinary)
FUNCTION_WRAPPER_V8_1(_GetGlyphs, GetGlyphs)
FUNCTION_WRAPPER_V8_0(_DestroyTextInfo, DestroyTextInfo)
FUNCTION_WRAPPER_V8_0(_IsNeedCMap, IsNeedCMap)
@ -51,6 +52,7 @@ namespace NSDrawingFileEmbed
NSV8Objects::Template_Set(result, "GetButtonIcons", _GetButtonIcons);
NSV8Objects::Template_Set(result, "GetAnnotationsInfo", _GetAnnotationsInfo);
NSV8Objects::Template_Set(result, "GetAnnotationsAP", _GetAnnotationsAP);
NSV8Objects::Template_Set(result, "GetFontBinary", _GetFontBinary);
NSV8Objects::Template_Set(result, "GetGlyphs", _GetGlyphs);
NSV8Objects::Template_Set(result, "DestroyTextInfo", _DestroyTextInfo);
NSV8Objects::Template_Set(result, "IsNeedCMap", _IsNeedCMap);

View File

@ -115,7 +115,7 @@ CFile.prototype["loadFromDataWithPassword"] = function(password)
if (0 != this.nativeFile)
this._closeFile();
let isSuccess = this._openFile(arrayBuffer, password);
let isSuccess = this._openFile(undefined, password);
let error = this._getError(); // 0 - ok, 4 - password, else: error
this.type = this._getType();

View File

@ -107,7 +107,7 @@ CFile.prototype._setCMap = function(memoryBuffer)
CFile.prototype._getFontByID = function(ID)
{
return null;
return g_native_drawing_file["GetFontBinary"](ID);
};
CFile.prototype._getInteractiveFormsFonts = function(type)

View File

@ -82,7 +82,7 @@ CFile.prototype._getUint8ClampedArray = function(ptr, len)
// FILE
CFile.prototype._openFile = function(buffer, password)
{
if (this.stream && buffer)
if (buffer)
{
let data = new Uint8Array(buffer);
this.stream_size = data.length;