From f8b9847e282fbfe41d853cd6070be1518e2eced3 Mon Sep 17 00:00:00 2001 From: Kulikova Svetlana Date: Mon, 6 Feb 2023 17:40:42 +0300 Subject: [PATCH] Text, ComboBox, ListBox --- .../pro/js/wasm/js/drawingfile_base.js | 28 +++++++- .../graphics/pro/js/wasm/src/drawingfile.cpp | 42 ++++++++++- .../graphics/pro/js/wasm/src/serialize.h | 5 ++ PdfFile/PdfReader.cpp | 70 ++++++++++++++++--- 4 files changed, 130 insertions(+), 15 deletions(-) diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js index c5764adff8..db66d32c08 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js @@ -397,11 +397,33 @@ rec["flag"] = reader.readInt(); var flags = reader.readInt(); + // Альтернативное имя поля, используется во всплывающей подсказке и сообщениях об ошибке - TU + if (flags & (1 << 0) + rec["userName"] = reader.readString(); + if (rec["type"] == "checkbox" || rec["type"] == "radiobutton") { - if (flags & (1 << 0) - // Альтернативное имя поля, используется во всплывающей подсказке и сообщениях об ошибке - TU - rec["userName"] = reader.readString(); + } + else if (rec["type"] == "text") + { + if (flags & (1 << 1) + rec["value"] = reader.readString(); + if (flags & (1 << 2) + rec["maxLen"] = reader.readInt(); + } + else if (rec["type"] == "combobox" || rec["type"] == "listbox") + { + if (flags & (1 << 1) + rec["value"] = reader.readString(); + if (flags & (1 << 2) + { + var n = reader.readInt(); + rec["opt"] = []; + for (int i = 0; i < n; ++i) + { + rec["opt"].push(reader.readInt()); + } + } } res.push(rec); diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp index 2c2c30543b..1327d5f9b4 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp @@ -411,15 +411,53 @@ int main() i += 4; std::cout << "Flags " << nPathLength << ", "; int nFlags = nPathLength; + if (nFlags & (1 << 0)) + { + nPathLength = READ_INT(pWidgets + i); + i += 4; + std::cout << "TU " << std::string((char*)(pWidgets + i), nPathLength) << ", "; + i += nPathLength; + } if (sType == "checkbox" || sType == "radiobutton") { - if (nFlags & (1 << 0)) + } + else if (sType == "text") + { + if (nFlags & (1 << 1)) { nPathLength = READ_INT(pWidgets + i); i += 4; - std::cout << "TU " << std::string((char*)(pWidgets + i), nPathLength) << ", "; + std::cout << "Value " << std::string((char*)(pWidgets + i), nPathLength) << ", "; i += nPathLength; } + if (nFlags & (1 << 2)) + { + nPathLength = READ_INT(pWidgets + i); + i += 4; + std::cout << "MaxLen " << nPathLength << ", "; + } + } + else if (sType == "combobox" || sType == "listbox") + { + if (nFlags & (1 << 1)) + { + nPathLength = READ_INT(pWidgets + i); + i += 4; + std::cout << "Value " << std::string((char*)(pWidgets + i), nPathLength) << ", "; + i += nPathLength; + } + if (nFlags & (1 << 2)) + { + int nOptLength = READ_INT(pWidgets + i); + i += 4; + for (int j = 0; j < nOptLength; ++j) + { + nPathLength = READ_INT(pWidgets + i); + i += 4; + std::cout << std::to_string(j) << "Opt " << std::string((char*)(pWidgets + i), nPathLength) << ", "; + i += nPathLength; + } + } } std::cout << std::endl; } diff --git a/DesktopEditor/graphics/pro/js/wasm/src/serialize.h b/DesktopEditor/graphics/pro/js/wasm/src/serialize.h index 788421a75a..3048fabc2e 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/serialize.h +++ b/DesktopEditor/graphics/pro/js/wasm/src/serialize.h @@ -77,6 +77,11 @@ namespace NSWasm m_pDataCur += 4; m_lSizeCur += 4; } + void AddInt(unsigned int value, size_t pos) + { + if (pos < m_lSizeCur) + memcpy(m_pData + pos, &value, sizeof(unsigned int)); + } void AddDouble(double value) { // такой точности хватит diff --git a/PdfFile/PdfReader.cpp b/PdfFile/PdfReader.cpp index a40a33f843..34812857d7 100644 --- a/PdfFile/PdfReader.cpp +++ b/PdfFile/PdfReader.cpp @@ -78,6 +78,7 @@ CPdfReader::CPdfReader(NSFonts::IApplicationFonts* pAppFonts) globalParams->setupBaseFonts(NULL); SetCMapFile(NSFile::GetProcessDirectory() + L"/cmap.bin"); #else + globalParams->setDrawFormFields(gFalse); SetCMapMemory(NULL, 0); #endif @@ -792,17 +793,27 @@ BYTE* CPdfReader::GetWidgets() continue; } + int nFlagPos = oRes.GetSize(); + oRes.AddInt(nFlags); + + // 1 - Альтернативное имя поля, используется во всплывающей подсказке и сообщениях об ошибке - TU Object oTU; - // Альтернативное имя поля, используется во всплывающей подсказке и сообщениях об ошибке - TU if (oField.dictLookup("TU", &oTU) && oTU.isString()) { TextString* s = new TextString(oTU.getString()); sTU = NSStringExt::CConverter::GetUtf8FromUTF32(s->getUnicode(), s->getLength()); nFlags |= (1 << 0); + oRes.WriteString((BYTE*)sTU.c_str(), (unsigned int)sTU.length()); delete s; } oTU.free(); + // Значение поля - V + int nValueLength; + Unicode* pValue = pField->getValue(&nValueLength); + std::string sValue = NSStringExt::CConverter::GetUtf8FromUTF32(pValue, nValueLength); + gfree(pValue); + // Запись данных необходимых каждому типу switch (oType) { @@ -811,11 +822,6 @@ BYTE* CPdfReader::GetWidgets() { // 2 - Включено - int nValueLength; - Unicode* pValue = pField->getValue(&nValueLength); - std::string sValue = NSStringExt::CConverter::GetUtf8FromUTF32(pValue, nValueLength); - gfree(pValue); - if (sValue != "Off") nFlags |= (1 << 1); @@ -860,14 +866,61 @@ BYTE* CPdfReader::GetWidgets() case acroFormFieldText: case acroFormFieldBarcode: { + // 2 - Значение + // 3 - Максимальное количество символов + + if (!sValue.empty()) + { + nFlags |= (1 << 1); + oRes.WriteString((BYTE*)sValue.c_str(), (unsigned int)sValue.length()); + } + // Максимальное количество символов в Tx - MaxLen int nMaxLen = pField->getMaxLen(); + if (nMaxLen > 0) + { + nFlags |= (1 << 2); + oRes.AddInt(nMaxLen); + } break; } case acroFormFieldComboBox: case acroFormFieldListBox: { + // 2 - Значение + // 3 - Список значений + + if (!sValue.empty()) + { + nFlags |= (1 << 1); + oRes.WriteString((BYTE*)sValue.c_str(), (unsigned int)sValue.length()); + } + + Object oOpt; + if (oField.dictLookup("Opt", &oOpt) && oOpt.isArray()) + { + nFlags |= (1 << 2); + int nOptLength = oOpt.arrayGetLength(); + oRes.AddInt(nOptLength); + for (int j = 0; j < nOptLength; ++j) + { + Object oOptJ; + if (!oOpt.arrayGet(j, &oOptJ) || !oOptJ.isString()) + { + oOptJ.free(); + continue; + } + + TextString* s = new TextString(oOptJ.getString()); + std::string sOpt = NSStringExt::CConverter::GetUtf8FromUTF32(s->getUnicode(), s->getLength()); + oRes.WriteString((BYTE*)sOpt.c_str(), (unsigned int)sOpt.length()); + delete s; + oOptJ.free(); + } + } + oOpt.free(); + break; } case acroFormFieldSignature: @@ -881,10 +934,7 @@ BYTE* CPdfReader::GetWidgets() } oFieldRef.free(); oField.free(); - // 1 - Альтернативное имя - oRes.AddInt(nFlags); - if (nFlags & (1 << 0)) - oRes.WriteString((BYTE*)sTU.c_str(), (unsigned int)sTU.length()); + oRes.AddInt(nFlags, nFlagPos); } oRes.WriteLen();