diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js index fd43b54f2c..e6d567dece 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js @@ -368,10 +368,10 @@ Module["_free"](ext); return res; }; - CFile.prototype["getInteractiveForms"] = function(pageIndex, width, height) + CFile.prototype["getInteractiveForms"] = function(pageIndex, width, height, backgroundColor) { var res = []; - var ext = Module["_GetInteractiveForms"](this.nativeFile, pageIndex, width, height); + var ext = Module["_GetInteractiveForms"](this.nativeFile, pageIndex, width, height, backgroundColor === undefined ? 0xFFFFFF : backgroundColor); if (ext == 0) return res; @@ -407,6 +407,15 @@ rec["y1"] = reader.readDouble(); rec["x2"] = reader.readDouble(); rec["y2"] = reader.readDouble(); + + // Внешний вид аннотации + rec["wAP"] = reader.readInt(); + rec["hAP"] = reader.readInt(); + let np1 = reader.readInt(); + let np2 = reader.readInt(); + // Указатель на память, аналогичный возвращаемому getPagePixmap. Память необходимо освободить + rec["retValueWidget"] = np2 << 32 | np1; + rec["alignment"] = reader.readInt(); rec["type"] = reader.readString(); rec["flag"] = reader.readInt(); diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp index 094003ddec..d3873e772b 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp @@ -150,9 +150,9 @@ WASM_EXPORT BYTE* GetStructure(CGraphicsFileDrawing* pGraphics) { return pGraphics->GetStructure(); } -WASM_EXPORT BYTE* GetInteractiveForms(CGraphicsFileDrawing* pGraphics, int nPageIndex, int nRasterW, int nRasterH) +WASM_EXPORT BYTE* GetInteractiveForms(CGraphicsFileDrawing* pGraphics, int nPageIndex, int nRasterW, int nRasterH, int nBackgroundColor) { - return pGraphics->GetInteractiveForms(nPageIndex, nRasterW, nRasterH); + return pGraphics->GetInteractiveForms(nPageIndex, nRasterW, nRasterH, nBackgroundColor); } WASM_EXPORT void DestroyTextInfo(CGraphicsFileDrawing* pGraphics) { @@ -173,7 +173,7 @@ WASM_EXPORT void SetCMapData(CGraphicsFileDrawing* pGraphics, BYTE* data, int si #ifdef TEST_CPP_BINARY -int READ_INT(BYTE* x) +unsigned int READ_INT(BYTE* x) { return x ? (x[0] | x[1] << 8 | x[2] << 16 | x[3] << 24) : 4; } @@ -183,14 +183,6 @@ int READ_INT(BYTE* x) int main(int argc, char* argv[]) { - /* тест сериализации указателя - 8 байт на x64 - int* p = new int; - *p = 15; - - std::cout << p << std::endl; - std::cout << *p << std::endl; - delete p; - */ // CHECK SYSTEM FONTS CApplicationFontsWorker oWorker; @@ -383,7 +375,7 @@ int main(int argc, char* argv[]) // INTERACTIVE FORMS if (true) { - BYTE* pWidgets = GetInteractiveForms(pGrFile, nTestPage, nWidth, nHeight); + BYTE* pWidgets = GetInteractiveForms(pGrFile, nTestPage, nWidth, nHeight, 0xFFFFFF); nLength = READ_INT(pWidgets); DWORD i = 4; nLength -= 4; @@ -408,6 +400,28 @@ int main(int argc, char* argv[]) nPathLength = READ_INT(pWidgets + i); i += 4; std::cout << "Y2 " << (double)nPathLength / 100.0 << ", "; + int nWidgetWidth = READ_INT(pWidgets + i); + i += 4; + std::cout << "W " << nWidgetWidth << ", "; + int nWidgetHeight = READ_INT(pWidgets + i); + i += 4; + std::cout << "H " << nWidgetHeight << ", "; + unsigned long long npBgraData1 = READ_INT(pWidgets + i); + i += 4; + unsigned long long npBgraData2 = READ_INT(pWidgets + i); + i += 4; + + BYTE* res = (BYTE*)(npBgraData2 << 32 | npBgraData1); + CBgraFrame oFrame; + oFrame.put_Data(res); + oFrame.put_Width(nWidgetWidth); + oFrame.put_Height(nWidgetHeight); + oFrame.put_Stride(4 * nWidgetWidth); + oFrame.put_IsRGBA(true); + oFrame.SaveFile(NSFile::GetProcessDirectory() + L"/res3.png", _CXIMAGE_FORMAT_PNG); + oFrame.ClearNoAttack(); + RELEASEARRAYOBJECTS(res); + nPathLength = READ_INT(pWidgets + i); i += 4; std::cout << "Q " << nPathLength << ", "; diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h index 3f23047e36..21df01079d 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h @@ -110,10 +110,10 @@ public: { return pReader->GetStructure(); } - BYTE* GetInteractiveForms(int nPageIndex, int nRasterW, int nRasterH) + BYTE* GetInteractiveForms(int nPageIndex, int nRasterW, int nRasterH, int nBackgroundColor) { if (nType == 0) - return ((CPdfFile*)pReader)->GetWidgets(nPageIndex, nRasterW, nRasterH); + return ((CPdfFile*)pReader)->GetWidgets(nPageIndex, nRasterW, nRasterH, nBackgroundColor); return NULL; } std::wstring GetInfo() diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index ef20da0d34..00949d49e1 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -811,11 +811,11 @@ BYTE* CPdfFile::GetLinks(int nPageIndex) return NULL; return m_pInternal->pReader->GetLinks(nPageIndex); } -BYTE* CPdfFile::GetWidgets(int nPageIndex, int nRasterW, int nRasterH) +BYTE* CPdfFile::GetWidgets(int nPageIndex, int nRasterW, int nRasterH, int nBackgroundColor) { if (!m_pInternal->pReader) return NULL; - return m_pInternal->pReader->GetWidgets(nPageIndex, nRasterW, nRasterH); + return m_pInternal->pReader->GetWidgets(nPageIndex, nRasterW, nRasterH, nBackgroundColor); } // ------------------------------------------------------------------------ diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index cd7a9f908a..6bfcfbf8b0 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -124,7 +124,7 @@ public: virtual std::wstring GetInfo(); virtual BYTE* GetStructure(); virtual BYTE* GetLinks(int nPageIndex); - BYTE* GetWidgets(int nPageIndex, int nRasterW, int nRasterH); + BYTE* GetWidgets(int nPageIndex, int nRasterW, int nRasterH, int nBackgroundColor); // --- WRITER --- diff --git a/PdfFile/PdfReader.cpp b/PdfFile/PdfReader.cpp index 36937ee39a..5d2a5f11ad 100644 --- a/PdfFile/PdfReader.cpp +++ b/PdfFile/PdfReader.cpp @@ -718,7 +718,7 @@ BYTE* CPdfReader::GetLinks(int nPageIndex) return oLinks.Serialize(); } -BYTE* CPdfReader::GetWidgets(int nPageIndex, int nRasterW, int nRasterH) +BYTE* CPdfReader::GetWidgets(int nPageIndex, int nRasterW, int nRasterH, int nBackgroundColor) { if (!m_pPDFDocument || !m_pPDFDocument->getCatalog()) return NULL; @@ -735,20 +735,44 @@ BYTE* CPdfReader::GetWidgets(int nPageIndex, int nRasterW, int nRasterH) globalParams->setDrawAnnotations(gFalse); globalParams->setDrawFormFields(gTrue); - BYTE* pPixData = m_pRenderer->ConvertToPixels(nPageIndex, nRasterW, nRasterH, true, m_pFontManager, 0, false, 0); + NSGraphics::IGraphicsRenderer* pRenderer = NSGraphics::Create(); + pRenderer->SetFontManager(m_pFontManager); - globalParams->setDrawContent(bDrawContent); - globalParams->setDrawAnnotations(bDrawAnnotations); - globalParams->setDrawFormFields(bDrawFormFileds); + double dPageDpiX, dPageDpiY; + double dWidth, dHeight; + GetPageInfo(nPageIndex, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY); - CBgraFrame oFrame; - oFrame.put_Data(pPixData); - oFrame.put_Width(nRasterW); - oFrame.put_Height(nRasterH); - oFrame.put_Stride(4 * nRasterW); - oFrame.put_IsRGBA(true); - oFrame.SaveFile(NSFile::GetProcessDirectory() + L"/res2.png", _CXIMAGE_FORMAT_PNG); - oFrame.ClearNoAttack(); + int nWidth = (nRasterW > 0) ? nRasterW : (int)((int)dWidth * 96 / dPageDpiX); + int nHeight = (nRasterH > 0) ? nRasterH : (int)((int)dHeight * 96 / dPageDpiY); + + BYTE* pBgraData = new BYTE[nWidth * nHeight * 4]; + if (!pBgraData) + { + RELEASEOBJECT(pRenderer); + globalParams->setDrawContent(bDrawContent); + globalParams->setDrawAnnotations(bDrawAnnotations); + globalParams->setDrawFormFields(bDrawFormFileds); + return NULL; + } + + unsigned int nColor = (unsigned int)nBackgroundColor; + unsigned int nSize = (unsigned int)(nWidth * nHeight); + unsigned int* pTemp = (unsigned int*)pBgraData; + for (unsigned int i = 0; i < nSize; ++i) + *pTemp++ = nColor; + + CBgraFrame* pFrame = new CBgraFrame(); + pFrame->put_Data(pBgraData); + pFrame->put_Width(nWidth); + pFrame->put_Height(nHeight); + pFrame->put_Stride(4 * nWidth); + + pRenderer->CreateFromBgraFrame(pFrame); + pRenderer->SetSwapRGB(true); + pRenderer->put_Width(dWidth * 25.4 / dPageDpiX); + pRenderer->put_Height(dHeight * 25.4 / dPageDpiX); + if (nBackgroundColor != 0xFFFFFF) + pRenderer->CommandLong(c_nDarkMode, 1); NSWasm::CData oRes; oRes.SkipLen(); @@ -782,43 +806,47 @@ BYTE* CPdfReader::GetWidgets(int nPageIndex, int nRasterW, int nRasterH) // Координаты - BBox double dx1, dy1, dx2, dy2; pField->getBBox(&dx1, &dy1, &dx2, &dy2); - double height = m_pPDFDocument->getPageCropHeight(nPageIndex + 1); - double width = m_pPDFDocument->getPageCropWidth (nPageIndex + 1); double dTemp = dy1; - dy1 = height - dy2; - dy2 = height - dTemp; + dy1 = dHeight - dy2; + dy2 = dHeight - dTemp; oRes.AddDouble(dx1); oRes.AddDouble(dy1); oRes.AddDouble(dx2); oRes.AddDouble(dy2); + globalParams->setDrawFormField(i); + bool bBreak = false; + m_pRenderer->DrawPageOnRenderer(pRenderer, nPageIndex, &bBreak); + // Получение пикселей внешнего вида виджета - int nRx1 = dx1 * (double)nRasterW / width; - int nRx2 = dx2 * (double)nRasterW / width + 1; - int nRy1 = dy1 * (double)nRasterH / height; - int nRy2 = dy2 * (double)nRasterH / height + 1; + int nRx1 = dx1 * (double)nWidth / dWidth; + int nRx2 = dx2 * (double)nWidth / dWidth + 1; + int nRy1 = dy1 * (double)nHeight / dHeight; + int nRy2 = dy2 * (double)nHeight / dHeight + 1; if (nRx1 < 0) nRx1 = 0; if (nRy1 < 0) nRy1 = 0; - if (nRx2 > nRasterW) nRx1 = nRasterW; - if (nRy2 > nRasterH) nRy1 = nRasterH; + if (nRx2 > nWidth) nRx1 = nWidth; + if (nRy2 > nHeight) nRy1 = nHeight; BYTE* pSubMatrix = new BYTE[(nRx2 - nRx1) * (nRy2 - nRy1) * 4]; int p = 0; - unsigned int* pTemp = (unsigned int*)pPixData; + unsigned int* pTemp = (unsigned int*)pBgraData; unsigned int* pSubTemp = (unsigned int*)pSubMatrix; for (int y = nRy1; y < nRy2; ++y) + { for (int x = nRx1; x < nRx2; ++x) - pSubTemp[p++] = pTemp[y * nRasterW + x]; + { + pSubTemp[p++] = pTemp[y * nWidth + x]; + pTemp[y * nWidth + x] = 0; + } + } - CBgraFrame oFrame; - oFrame.put_Data(pSubMatrix); - oFrame.put_Width(nRx2 - nRx1); - oFrame.put_Height(nRy2 - nRy1); - oFrame.put_Stride(4 * (nRx2 - nRx1)); - oFrame.put_IsRGBA(true); - oFrame.SaveFile(NSFile::GetProcessDirectory() + L"/res3.png", _CXIMAGE_FORMAT_PNG); - oFrame.ClearNoAttack(); - RELEASEARRAYOBJECTS(pSubMatrix); + oRes.AddInt(nRx2 - nRx1); + oRes.AddInt(nRy2 - nRy1); + unsigned long long npSubMatrix = (unsigned long long)pSubMatrix; + unsigned int npSubMatrix1 = npSubMatrix & 0xFFFFFFFF; + oRes.AddInt(npSubMatrix1); + oRes.AddInt(npSubMatrix >> 32); // Выравнивание текста - Q Object oQ; @@ -1434,7 +1462,13 @@ oObj.free();\ oRes.AddInt(nFlags, nFlagPos); } - RELEASEARRAYOBJECTS(pPixData); + globalParams->setDrawContent(bDrawContent); + globalParams->setDrawAnnotations(bDrawAnnotations); + globalParams->setDrawFormFields(bDrawFormFileds); + globalParams->setDrawFormField(-1); + RELEASEOBJECT(pFrame); + RELEASEOBJECT(pRenderer); + oRes.WriteLen(); BYTE* bRes = oRes.GetBuffer(); oRes.ClearWithoutAttack(); diff --git a/PdfFile/PdfReader.h b/PdfFile/PdfReader.h index 6308abdd5a..107e164446 100644 --- a/PdfFile/PdfReader.h +++ b/PdfFile/PdfReader.h @@ -70,7 +70,7 @@ public: BYTE* GetStructure(); BYTE* GetLinks(int nPageIndex); - BYTE* GetWidgets(int nPageIndex, int nRasterW, int nRasterH); + BYTE* GetWidgets(int nPageIndex, int nRasterW, int nRasterH, int nBackgroundColor); private: IOfficeDrawingFile* m_pRenderer; diff --git a/PdfFile/lib/xpdf/AcroForm.cc b/PdfFile/lib/xpdf/AcroForm.cc index 5e3f7d01f6..c411725259 100644 --- a/PdfFile/lib/xpdf/AcroForm.cc +++ b/PdfFile/lib/xpdf/AcroForm.cc @@ -31,6 +31,7 @@ #include "UTF8.h" #include "PDF417Barcode.h" #include "AcroForm.h" +#include "GlobalParams.h" //------------------------------------------------------------------------ @@ -561,7 +562,10 @@ void AcroForm::scanField(Object *fieldRef) { void AcroForm::draw(int pageNum, Gfx *gfx, GBool printing) { int i; + int formField = globalParams->getDrawFormField(); for (i = 0; i < fields->getLength(); ++i) { + if (formField >= 0 && formField != i) + continue; ((AcroFormField *)fields->get(i))->draw(pageNum, gfx, printing); } } diff --git a/PdfFile/lib/xpdf/GlobalParams.cc b/PdfFile/lib/xpdf/GlobalParams.cc index 8b577a8285..11f3f24e74 100644 --- a/PdfFile/lib/xpdf/GlobalParams.cc +++ b/PdfFile/lib/xpdf/GlobalParams.cc @@ -754,6 +754,7 @@ GlobalParams::GlobalParams(const char *cfgFileName) { printCommands = gFalse; errQuiet = gFalse; debugLogFile = NULL; + drawFormField = -1; cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize); unicodeToUnicodeCache = @@ -3168,7 +3169,14 @@ GBool GlobalParams::getDrawContent() { return draw; } +int GlobalParams::getDrawFormField() { + int formField; + lockGlobalParams; + formField = drawFormField; + unlockGlobalParams; + return formField; +} GString *GlobalParams::getPaperColor() { GString *s; @@ -3732,6 +3740,12 @@ void GlobalParams::setDrawContent(GBool draw) { unlockGlobalParams; } +void GlobalParams::setDrawFormField(int formField) { + lockGlobalParams; + drawFormField = formField; + unlockGlobalParams; +} + void GlobalParams::setOverprintPreview(GBool preview) { lockGlobalParams; overprintPreview = preview; diff --git a/PdfFile/lib/xpdf/GlobalParams.h b/PdfFile/lib/xpdf/GlobalParams.h index 631a6e6621..22c0b66a0a 100644 --- a/PdfFile/lib/xpdf/GlobalParams.h +++ b/PdfFile/lib/xpdf/GlobalParams.h @@ -326,6 +326,7 @@ public: GBool getDrawAnnotations(); GBool getDrawFormFields(); GBool getDrawContent(); + int getDrawFormField(); GBool getOverprintPreview() { return overprintPreview; } GString *getPaperColor(); GString *getMatteColor(); @@ -395,6 +396,7 @@ public: void setDrawAnnotations(GBool draw); void setDrawFormFields(GBool draw); void setDrawContent(GBool draw); + void setDrawFormField(int formField); void setOverprintPreview(GBool preview); void setMapNumericCharNames(GBool map); void setMapUnknownCharNames(GBool map); @@ -594,6 +596,7 @@ private: GBool printCommands; // print the drawing commands GBool errQuiet; // suppress error messages? GString *debugLogFile; // path for debug log file + int drawFormField; CharCodeToUnicodeCache *cidToUnicodeCache; CharCodeToUnicodeCache *unicodeToUnicodeCache;