diff --git a/DesktopEditor/graphics/pro/js/drawingfile.json b/DesktopEditor/graphics/pro/js/drawingfile.json index b8521a7c21..b5d73d545c 100644 --- a/DesktopEditor/graphics/pro/js/drawingfile.json +++ b/DesktopEditor/graphics/pro/js/drawingfile.json @@ -31,6 +31,7 @@ "_GetLinks", "_GetStructure", "_GetInteractiveFormsInfo", + "_GetInteractiveFormsFonts", "_GetInteractiveFormsAP", "_GetButtonIcons", "_GetAnnotationsInfo", @@ -39,6 +40,7 @@ "_InitializeFontsBase64", "_InitializeFontsRanges", "_SetFontBinary", + "_GetFontBinary", "_IsFontBinaryExist", "_DestroyTextInfo", "_IsNeedCMap", diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp index 909c4b4c59..2d5c838c7f 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp @@ -57,6 +57,21 @@ WASM_EXPORT void SetFontBinary(char* path, BYTE* data, int size) pStorage->Add(UTF8_TO_U(sPathA), data, size, true); } } +WASM_EXPORT void GetFontBinary(char* path, BYTE*& data, int& size) +{ + NSFonts::IFontsMemoryStorage* pStorage = NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage(); + if (pStorage) + { + std::string sPathA(path); + NSFonts::IFontStream* pStream = pStorage->Get(UTF8_TO_U(sPathA)); + if (pStream) + { + long lLength = 0; + pStream->GetMemory(data, lLength); + size = lLength; + } + } +} WASM_EXPORT int IsFontBinaryExist(char* path) { NSFonts::IFontsMemoryStorage* pStorage = NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage(); @@ -156,6 +171,10 @@ WASM_EXPORT BYTE* GetInteractiveFormsInfo(CGraphicsFileDrawing* pGraphics) { return pGraphics->GetInteractiveFormsInfo(); } +WASM_EXPORT BYTE* GetInteractiveFormsFonts(CGraphicsFileDrawing* pGraphics) +{ + return pGraphics->GetWidgetFontsID(); +} WASM_EXPORT BYTE* GetInteractiveFormsAP(CGraphicsFileDrawing* pGraphics, int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nWidget, int nView, int nButtonView) { const char* sView = NULL; diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h index 7d2dccf469..aea2993e95 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h @@ -123,6 +123,12 @@ public: return ((CPdfFile*)pReader)->GetWidgets(); return NULL; } + BYTE* GetWidgetFontsID() + { + if (nType == 0) + return ((CPdfFile*)pReader)->GetWidgetFonts(); + return NULL; + } BYTE* GetAnnots(int nPageIndex = -1) { if (nType == 0) diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp index 20dfa05b8e..4065c3a654 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp @@ -651,10 +651,11 @@ void ReadAnnotAP(BYTE* pWidgetsAP, int& i) int nAPLength = READ_INT(pWidgetsAP + i); i += 4; + if (nAPLength > 0) + std::cout << "APName "; for (int j = 0; j < nAPLength; ++j) { - std::cout << std::endl; nPathLength = READ_INT(pWidgetsAP + i); i += 4; std::string sAPName = std::string((char*)(pWidgetsAP + i), nPathLength); @@ -665,7 +666,7 @@ void ReadAnnotAP(BYTE* pWidgetsAP, int& i) sAPName += nPathLength ? ("." + std::string((char*)(pWidgetsAP + i), nPathLength)) : ""; i += nPathLength; - std::cout << "APName " << sAPName << ", "; + std::cout << sAPName << ", "; unsigned long long npBgraData1 = READ_INT(pWidgetsAP + i); i += 4; unsigned long long npBgraData2 = READ_INT(pWidgetsAP + i); @@ -774,7 +775,7 @@ int main(int argc, char* argv[]) std::cout << " Page " << nTestPage << " width " << nWidth << " height " << nHeight << " dpi " << dpi << " rotate " << rotate << std::endl; nLength = READ_INT(pInfo + nPagesCount * 16 + 12); - std::cout << "json "<< std::string((char*)(pInfo + nPagesCount * 16 + 16), nLength) << std::endl;; + std::cout << "json "<< std::string((char*)(pInfo + nPagesCount * 16 + 16), nLength) << std::endl << std::endl; } } @@ -886,9 +887,33 @@ int main(int argc, char* argv[]) // INTERACTIVE FORMS if (true) { + BYTE* pFonts = GetInteractiveFormsFontsID(pGrFile); + nLength = READ_INT(pFonts); + int i = 4; + nLength -= 4; + + while (i < nLength) + { + int nFontsLength = READ_INT(pFonts + i); + i += 4; + std::cout << "Fonts"; + + for (int j = 0; j < nFontsLength; ++j) + { + int nPathLength = READ_INT(pFonts + i); + i += 4; + std::cout << " " << std::string((char*)(pFonts + i), nPathLength); + i += nPathLength; + } + std::cout << std::endl; + } + + if (pFonts) + free(pFonts); + BYTE* pWidgets = GetInteractiveFormsInfo(pGrFile); nLength = READ_INT(pWidgets); - int i = 4; + i = 4; nLength -= 4; if (i < nLength) diff --git a/PdfFile/PdfReader.cpp b/PdfFile/PdfReader.cpp index 6cd2f80ae9..80e215df0e 100644 --- a/PdfFile/PdfReader.cpp +++ b/PdfFile/PdfReader.cpp @@ -896,35 +896,51 @@ BYTE* CPdfReader::GetWidgetFonts() NSWasm::CData oRes; oRes.SkipLen(); - Object oObj1, oObj2; + int nFontsID = 0; + int nFontsPos = oRes.GetSize(); + oRes.AddInt(nFontsID); + std::vector arrFontsRef; for (int i = 0, nNum = pAcroForms->getNumFields(); i < nNum; ++i) { AcroFormField* pField = pAcroForms->getField(i); - Object oFieldRef, oField; - if (!pField || !pField->getFieldRef(&oFieldRef)->isRef() || !oFieldRef.fetch(xref, &oField)->isDict()) - { - oField.free(); oFieldRef.free(); + if (!pField) continue; - } - - GfxFont* gfxFont = NULL; - GfxFontDict *gfxFontDict = NULL; // Шрифт и размер шрифта - из DA Ref fontID; double dFontSize = 0; pField->getFont(&fontID, &dFontSize); - if (fontID.num > 0) + if (fontID.num < 0 || std::find(arrFontsRef.begin(), arrFontsRef.end(), fontID.num) != arrFontsRef.end()) + continue; + + Object oObj, oField, oFont; + pField->getFieldRef(&oObj); + oObj.fetch(xref, &oField); + oObj.free(); + + bool bFindResources = false; + if (oField.dictLookup("DR", &oObj)->isDict() && oObj.dictLookup("Font", &oFont)->isDict()) + { + for (int i = 0; i < oFont.dictGetLength(); ++i) + { + Object oFontRef; + if (oFont.dictGetValNF(i, &oFontRef)->isRef() && oFontRef.getRef() == fontID) + { + bFindResources = true; + oFontRef.free(); + break; + } + oFontRef.free(); + } + } + oFont.free(); oField.free(); + + if (!bFindResources) { - Object oObj, oField, oFont; - pField->getFieldRef(&oObj); - oObj.fetch(xref, &oField); oObj.free(); - - bool bFindResources = false; - - if (oField.dictLookup("DR", &oObj)->isDict() && oObj.dictLookup("Font", &oFont)->isDict()) + Object* oAcroForm = pAcroForms->getAcroFormObj(); + if (oAcroForm->isDict() && oAcroForm->dictLookup("DR", &oObj)->isDict() && oObj.dictLookup("Font", &oFont)->isDict()) { for (int i = 0; i < oFont.dictGetLength(); ++i) { @@ -938,61 +954,50 @@ BYTE* CPdfReader::GetWidgetFonts() oFontRef.free(); } } - oFont.free(); oField.free(); + oFont.free(); + } - if (!bFindResources) + GfxFont* gfxFont = NULL; + GfxFontDict *gfxFontDict = NULL; + if (bFindResources) + { + Object oFontRef; + if (oObj.dictLookupNF("Font", &oFontRef)->isRef()) { - oObj.free(); - Object* oAcroForm = pAcroForms->getAcroFormObj(); - if (oAcroForm->isDict() && oAcroForm->dictLookup("DR", &oObj)->isDict() && oObj.dictLookup("Font", &oFont)->isDict()) + if (oFontRef.fetch(xref, &oFont)->isDict()) { - for (int i = 0; i < oFont.dictGetLength(); ++i) - { - Object oFontRef; - if (oFont.dictGetValNF(i, &oFontRef)->isRef() && oFontRef.getRef() == fontID) - { - bFindResources = true; - oFontRef.free(); - break; - } - oFontRef.free(); - } + Ref r = oFontRef.getRef(); + gfxFontDict = new GfxFontDict(xref, &r, oFont.getDict()); + gfxFont = gfxFontDict->lookupByRef(fontID); } oFont.free(); } - - if (bFindResources) + else if (oFontRef.isDict()) { - Object oFontRef; - if (oObj.dictLookupNF("Font", &oFontRef)->isRef()) - { - if (oFontRef.fetch(xref, &oFont)->isDict()) - { - Ref r = oFontRef.getRef(); - gfxFontDict = new GfxFontDict(xref, &r, oFont.getDict()); - gfxFont = gfxFontDict->lookupByRef(fontID); - } - oFont.free(); - } - else if (oFontRef.isDict()) - { - gfxFontDict = new GfxFontDict(xref, NULL, oFontRef.getDict()); - gfxFont = gfxFontDict->lookupByRef(fontID); - } - oFontRef.free(); + gfxFontDict = new GfxFontDict(xref, NULL, oFontRef.getDict()); + gfxFont = gfxFontDict->lookupByRef(fontID); } - oObj.free(); + oFontRef.free(); } + oObj.free(); std::wstring wsFileName, wsFontName; if (gfxFont) GetFont(xref, m_pFontManager, m_pFontList, gfxFont, wsFileName, wsFontName); - std::string m_sFontName = U_TO_UTF8(wsFileName); + if (wsFileName.length() > 17 && wsFileName.substr(0, 17) == L"storage_internal_") + { + std::string sFileName = U_TO_UTF8(wsFileName); + oRes.WriteString(sFileName); + nFontsID++; + arrFontsRef.push_back(fontID.num); + } RELEASEOBJECT(gfxFontDict); } + oRes.AddInt(nFontsID, nFontsPos); + oRes.WriteLen(); BYTE* bRes = oRes.GetBuffer(); oRes.ClearWithoutAttack();