summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-04-24 09:45:54 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-04-24 14:01:51 +0000
commit67b2a358814beb7135552219cceca8c9b3f137a1 (patch)
tree887ddf983c91bc9284de5f2a1bf75cb727da0639 /xfa/fxfa
parent25694831670ef6172b1b9b71359a6c192e26da20 (diff)
downloadpdfium-67b2a358814beb7135552219cceca8c9b3f137a1.tar.xz
Cleanup the XFA Bacode widget
This Cl cleans up the XFA barcode widget. The custom binary search is removed. Some code shuffled from the header to the cpp file. Nits fixed. Change-Id: Icad0d2b25b07ea36afc5a5922a79f55b82616486 Reviewed-on: https://pdfium-review.googlesource.com/4394 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/app/xfa_ffbarcode.cpp220
-rw-r--r--xfa/fxfa/app/xfa_ffbarcode.h146
-rw-r--r--xfa/fxfa/app/xfa_ffbarcode_unittest.cpp25
-rw-r--r--xfa/fxfa/app/xfa_fftextedit.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.cpp68
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.h24
6 files changed, 248 insertions, 237 deletions
diff --git a/xfa/fxfa/app/xfa_ffbarcode.cpp b/xfa/fxfa/app/xfa_ffbarcode.cpp
index d15ec8c24f..4dcffa5bad 100644
--- a/xfa/fxfa/app/xfa_ffbarcode.cpp
+++ b/xfa/fxfa/app/xfa_ffbarcode.cpp
@@ -21,104 +21,96 @@
namespace {
-const XFA_BARCODETYPEENUMINFO g_XFABarCodeTypeEnumData[] = {
- {0x7fb4a18, L"ean13", XFA_BARCODETYPE_ean13, BC_EAN13},
- {0x8d13a3d, L"code11", XFA_BARCODETYPE_code11, BC_UNKNOWN},
- {0x8d149a8, L"code49", XFA_BARCODETYPE_code49, BC_UNKNOWN},
- {0x8d16347, L"code93", XFA_BARCODETYPE_code93, BC_UNKNOWN},
- {0x91a92e2, L"upsMaxicode", XFA_BARCODETYPE_upsMaxicode, BC_UNKNOWN},
- {0xa7d48dc, L"fim", XFA_BARCODETYPE_fim, BC_UNKNOWN},
- {0xb359fe9, L"msi", XFA_BARCODETYPE_msi, BC_UNKNOWN},
- {0x121f738c, L"code2Of5Matrix", XFA_BARCODETYPE_code2Of5Matrix, BC_UNKNOWN},
- {0x15358616, L"ucc128", XFA_BARCODETYPE_ucc128, BC_UNKNOWN},
- {0x1f4bfa05, L"rfid", XFA_BARCODETYPE_rfid, BC_UNKNOWN},
- {0x1fda71bc, L"rss14Stacked", XFA_BARCODETYPE_rss14Stacked, BC_UNKNOWN},
- {0x22065087, L"ean8add2", XFA_BARCODETYPE_ean8add2, BC_UNKNOWN},
- {0x2206508a, L"ean8add5", XFA_BARCODETYPE_ean8add5, BC_UNKNOWN},
- {0x2278366c, L"codabar", XFA_BARCODETYPE_codabar, BC_CODABAR},
- {0x2a039a8d, L"telepen", XFA_BARCODETYPE_telepen, BC_UNKNOWN},
- {0x323ed337, L"upcApwcd", XFA_BARCODETYPE_upcApwcd, BC_UNKNOWN},
- {0x347a1846, L"postUSIMB", XFA_BARCODETYPE_postUSIMB, BC_UNKNOWN},
- {0x391bb836, L"code128", XFA_BARCODETYPE_code128, BC_CODE128},
- {0x398eddaf, L"dataMatrix", XFA_BARCODETYPE_dataMatrix, BC_DATAMATRIX},
- {0x3cff60a8, L"upcEadd2", XFA_BARCODETYPE_upcEadd2, BC_UNKNOWN},
- {0x3cff60ab, L"upcEadd5", XFA_BARCODETYPE_upcEadd5, BC_UNKNOWN},
- {0x402cb188, L"code2Of5Standard", XFA_BARCODETYPE_code2Of5Standard,
+const BarCodeInfo g_BarCodeData[] = {
+ {0x7fb4a18, L"ean13", BarcodeType::ean13, BC_EAN13},
+ {0x8d13a3d, L"code11", BarcodeType::code11, BC_UNKNOWN},
+ {0x8d149a8, L"code49", BarcodeType::code49, BC_UNKNOWN},
+ {0x8d16347, L"code93", BarcodeType::code93, BC_UNKNOWN},
+ {0x91a92e2, L"upsMaxicode", BarcodeType::upsMaxicode, BC_UNKNOWN},
+ {0xa7d48dc, L"fim", BarcodeType::fim, BC_UNKNOWN},
+ {0xb359fe9, L"msi", BarcodeType::msi, BC_UNKNOWN},
+ {0x121f738c, L"code2Of5Matrix", BarcodeType::code2Of5Matrix, BC_UNKNOWN},
+ {0x15358616, L"ucc128", BarcodeType::ucc128, BC_UNKNOWN},
+ {0x1f4bfa05, L"rfid", BarcodeType::rfid, BC_UNKNOWN},
+ {0x1fda71bc, L"rss14Stacked", BarcodeType::rss14Stacked, BC_UNKNOWN},
+ {0x22065087, L"ean8add2", BarcodeType::ean8add2, BC_UNKNOWN},
+ {0x2206508a, L"ean8add5", BarcodeType::ean8add5, BC_UNKNOWN},
+ {0x2278366c, L"codabar", BarcodeType::codabar, BC_CODABAR},
+ {0x2a039a8d, L"telepen", BarcodeType::telepen, BC_UNKNOWN},
+ {0x323ed337, L"upcApwcd", BarcodeType::upcApwcd, BC_UNKNOWN},
+ {0x347a1846, L"postUSIMB", BarcodeType::postUSIMB, BC_UNKNOWN},
+ {0x391bb836, L"code128", BarcodeType::code128, BC_CODE128},
+ {0x398eddaf, L"dataMatrix", BarcodeType::dataMatrix, BC_DATAMATRIX},
+ {0x3cff60a8, L"upcEadd2", BarcodeType::upcEadd2, BC_UNKNOWN},
+ {0x3cff60ab, L"upcEadd5", BarcodeType::upcEadd5, BC_UNKNOWN},
+ {0x402cb188, L"code2Of5Standard", BarcodeType::code2Of5Standard,
BC_UNKNOWN},
- {0x411764f7, L"aztec", XFA_BARCODETYPE_aztec, BC_UNKNOWN},
- {0x44d4e84c, L"ean8", XFA_BARCODETYPE_ean8, BC_EAN8},
- {0x48468902, L"ucc128sscc", XFA_BARCODETYPE_ucc128sscc, BC_UNKNOWN},
- {0x4880aea4, L"upcAadd2", XFA_BARCODETYPE_upcAadd2, BC_UNKNOWN},
- {0x4880aea7, L"upcAadd5", XFA_BARCODETYPE_upcAadd5, BC_UNKNOWN},
- {0x54f18256, L"code2Of5Industrial", XFA_BARCODETYPE_code2Of5Industrial,
+ {0x411764f7, L"aztec", BarcodeType::aztec, BC_UNKNOWN},
+ {0x44d4e84c, L"ean8", BarcodeType::ean8, BC_EAN8},
+ {0x48468902, L"ucc128sscc", BarcodeType::ucc128sscc, BC_UNKNOWN},
+ {0x4880aea4, L"upcAadd2", BarcodeType::upcAadd2, BC_UNKNOWN},
+ {0x4880aea7, L"upcAadd5", BarcodeType::upcAadd5, BC_UNKNOWN},
+ {0x54f18256, L"code2Of5Industrial", BarcodeType::code2Of5Industrial,
BC_UNKNOWN},
- {0x58e15f25, L"rss14Limited", XFA_BARCODETYPE_rss14Limited, BC_UNKNOWN},
- {0x5c08d1b9, L"postAUSReplyPaid", XFA_BARCODETYPE_postAUSReplyPaid,
+ {0x58e15f25, L"rss14Limited", BarcodeType::rss14Limited, BC_UNKNOWN},
+ {0x5c08d1b9, L"postAUSReplyPaid", BarcodeType::postAUSReplyPaid,
BC_UNKNOWN},
- {0x5fa700bd, L"rss14", XFA_BARCODETYPE_rss14, BC_UNKNOWN},
- {0x631a7e35, L"logmars", XFA_BARCODETYPE_logmars, BC_UNKNOWN},
- {0x6a236236, L"pdf417", XFA_BARCODETYPE_pdf417, BC_PDF417},
- {0x6d098ece, L"upcean2", XFA_BARCODETYPE_upcean2, BC_UNKNOWN},
- {0x6d098ed1, L"upcean5", XFA_BARCODETYPE_upcean5, BC_UNKNOWN},
- {0x76b04eed, L"code3Of9extended", XFA_BARCODETYPE_code3Of9extended,
+ {0x5fa700bd, L"rss14", BarcodeType::rss14, BC_UNKNOWN},
+ {0x631a7e35, L"logmars", BarcodeType::logmars, BC_UNKNOWN},
+ {0x6a236236, L"pdf417", BarcodeType::pdf417, BC_PDF417},
+ {0x6d098ece, L"upcean2", BarcodeType::upcean2, BC_UNKNOWN},
+ {0x6d098ed1, L"upcean5", BarcodeType::upcean5, BC_UNKNOWN},
+ {0x76b04eed, L"code3Of9extended", BarcodeType::code3Of9extended,
BC_UNKNOWN},
- {0x7c7db84a, L"maxicode", XFA_BARCODETYPE_maxicode, BC_UNKNOWN},
- {0x8266f7f7, L"ucc128random", XFA_BARCODETYPE_ucc128random, BC_UNKNOWN},
- {0x83eca147, L"postUSDPBC", XFA_BARCODETYPE_postUSDPBC, BC_UNKNOWN},
- {0x8dd71de0, L"postAUSStandard", XFA_BARCODETYPE_postAUSStandard,
+ {0x7c7db84a, L"maxicode", BarcodeType::maxicode, BC_UNKNOWN},
+ {0x8266f7f7, L"ucc128random", BarcodeType::ucc128random, BC_UNKNOWN},
+ {0x83eca147, L"postUSDPBC", BarcodeType::postUSDPBC, BC_UNKNOWN},
+ {0x8dd71de0, L"postAUSStandard", BarcodeType::postAUSStandard, BC_UNKNOWN},
+ {0x98adad85, L"plessey", BarcodeType::plessey, BC_UNKNOWN},
+ {0x9f84cce6, L"ean13pwcd", BarcodeType::ean13pwcd, BC_UNKNOWN},
+ {0xb514fbe9, L"upcA", BarcodeType::upcA, BC_UPCA},
+ {0xb514fbed, L"upcE", BarcodeType::upcE, BC_UNKNOWN},
+ {0xb5c6a853, L"ean13add2", BarcodeType::ean13add2, BC_UNKNOWN},
+ {0xb5c6a856, L"ean13add5", BarcodeType::ean13add5, BC_UNKNOWN},
+ {0xb81fc512, L"postUKRM4SCC", BarcodeType::postUKRM4SCC, BC_UNKNOWN},
+ {0xbad34b22, L"code128SSCC", BarcodeType::code128SSCC, BC_UNKNOWN},
+ {0xbfbe0cf6, L"postUS5Zip", BarcodeType::postUS5Zip, BC_UNKNOWN},
+ {0xc56618e8, L"pdf417macro", BarcodeType::pdf417macro, BC_UNKNOWN},
+ {0xca730f8a, L"code2Of5Interleaved", BarcodeType::code2Of5Interleaved,
BC_UNKNOWN},
- {0x98adad85, L"plessey", XFA_BARCODETYPE_plessey, BC_UNKNOWN},
- {0x9f84cce6, L"ean13pwcd", XFA_BARCODETYPE_ean13pwcd, BC_UNKNOWN},
- {0xb514fbe9, L"upcA", XFA_BARCODETYPE_upcA, BC_UPCA},
- {0xb514fbed, L"upcE", XFA_BARCODETYPE_upcE, BC_UNKNOWN},
- {0xb5c6a853, L"ean13add2", XFA_BARCODETYPE_ean13add2, BC_UNKNOWN},
- {0xb5c6a856, L"ean13add5", XFA_BARCODETYPE_ean13add5, BC_UNKNOWN},
- {0xb81fc512, L"postUKRM4SCC", XFA_BARCODETYPE_postUKRM4SCC, BC_UNKNOWN},
- {0xbad34b22, L"code128SSCC", XFA_BARCODETYPE_code128SSCC, BC_UNKNOWN},
- {0xbfbe0cf6, L"postUS5Zip", XFA_BARCODETYPE_postUS5Zip, BC_UNKNOWN},
- {0xc56618e8, L"pdf417macro", XFA_BARCODETYPE_pdf417macro, BC_UNKNOWN},
- {0xca730f8a, L"code2Of5Interleaved", XFA_BARCODETYPE_code2Of5Interleaved,
+ {0xd0097ac6, L"rss14Expanded", BarcodeType::rss14Expanded, BC_UNKNOWN},
+ {0xd25a0240, L"postAUSCust2", BarcodeType::postAUSCust2, BC_UNKNOWN},
+ {0xd25a0241, L"postAUSCust3", BarcodeType::postAUSCust3, BC_UNKNOWN},
+ {0xd53ed3e7, L"rss14Truncated", BarcodeType::rss14Truncated, BC_UNKNOWN},
+ {0xe72bcd57, L"code128A", BarcodeType::code128A, BC_UNKNOWN},
+ {0xe72bcd58, L"code128B", BarcodeType::code128B, BC_CODE128_B},
+ {0xe72bcd59, L"code128C", BarcodeType::code128C, BC_CODE128_C},
+ {0xee83c50f, L"rss14StackedOmni", BarcodeType::rss14StackedOmni,
BC_UNKNOWN},
- {0xd0097ac6, L"rss14Expanded", XFA_BARCODETYPE_rss14Expanded, BC_UNKNOWN},
- {0xd25a0240, L"postAUSCust2", XFA_BARCODETYPE_postAUSCust2, BC_UNKNOWN},
- {0xd25a0241, L"postAUSCust3", XFA_BARCODETYPE_postAUSCust3, BC_UNKNOWN},
- {0xd53ed3e7, L"rss14Truncated", XFA_BARCODETYPE_rss14Truncated, BC_UNKNOWN},
- {0xe72bcd57, L"code128A", XFA_BARCODETYPE_code128A, BC_UNKNOWN},
- {0xe72bcd58, L"code128B", XFA_BARCODETYPE_code128B, BC_CODE128_B},
- {0xe72bcd59, L"code128C", XFA_BARCODETYPE_code128C, BC_CODE128_C},
- {0xee83c50f, L"rss14StackedOmni", XFA_BARCODETYPE_rss14StackedOmni,
- BC_UNKNOWN},
- {0xf2a18f7e, L"QRCode", XFA_BARCODETYPE_QRCode, BC_QR_CODE},
- {0xfaeaf37f, L"postUSStandard", XFA_BARCODETYPE_postUSStandard, BC_UNKNOWN},
- {0xfb48155c, L"code3Of9", XFA_BARCODETYPE_code3Of9, BC_CODE39},
+ {0xf2a18f7e, L"QRCode", BarcodeType::QRCode, BC_QR_CODE},
+ {0xfaeaf37f, L"postUSStandard", BarcodeType::postUSStandard, BC_UNKNOWN},
+ {0xfb48155c, L"code3Of9", BarcodeType::code3Of9, BC_CODE39},
};
-const int32_t g_iXFABarcodeTypeCount =
- sizeof(g_XFABarCodeTypeEnumData) / sizeof(XFA_BARCODETYPEENUMINFO);
-const XFA_BARCODETYPEENUMINFO* XFA_GetBarcodeTypeByName(
+} // namespace.
+
+// static
+const BarCodeInfo* CXFA_FFBarcode::GetBarcodeTypeByName(
const CFX_WideStringC& wsName) {
if (wsName.IsEmpty())
return nullptr;
- uint32_t uHash = FX_HashCode_GetW(wsName, true);
- int32_t iStart = 0;
- int32_t iEnd = g_iXFABarcodeTypeCount - 1;
- do {
- int32_t iMid = (iStart + iEnd) / 2;
- const XFA_BARCODETYPEENUMINFO* pInfo = g_XFABarCodeTypeEnumData + iMid;
- if (uHash == pInfo->uHash) {
- return pInfo;
- } else if (uHash < pInfo->uHash) {
- iEnd = iMid - 1;
- } else {
- iStart = iMid + 1;
- }
- } while (iStart <= iEnd);
+ auto* it = std::lower_bound(
+ std::begin(g_BarCodeData), std::end(g_BarCodeData),
+ FX_HashCode_GetW(wsName, true),
+ [](const BarCodeInfo& arg, uint32_t hash) { return arg.uHash < hash; });
+
+ if (it != std::end(g_BarCodeData) && wsName == it->pName)
+ return it;
+
return nullptr;
}
-} // namespace.
-
CXFA_FFBarcode::CXFA_FFBarcode(CXFA_WidgetAcc* pDataAcc)
: CXFA_FFTextEdit(pDataAcc) {}
@@ -169,59 +161,51 @@ void CXFA_FFBarcode::RenderWidget(CFX_Graphics* pGS,
void CXFA_FFBarcode::UpdateWidgetProperty() {
CXFA_FFTextEdit::UpdateWidgetProperty();
+
auto* pBarCodeWidget = static_cast<CFWL_Barcode*>(m_pNormalWidget.get());
CFX_WideString wsType = GetDataAcc()->GetBarcodeType();
- const XFA_BARCODETYPEENUMINFO* pBarcodeTypeInfo =
- XFA_GetBarcodeTypeByName(wsType.AsStringC());
- if (!pBarcodeTypeInfo)
+ const BarCodeInfo* pBarcodeInfo = GetBarcodeTypeByName(wsType.AsStringC());
+ if (!pBarcodeInfo)
return;
- pBarCodeWidget->SetType(pBarcodeTypeInfo->eBCType);
+ pBarCodeWidget->SetType(pBarcodeInfo->eBCType);
+
CXFA_WidgetAcc* pAcc = GetDataAcc();
int32_t intVal;
- char charVal;
- bool boolVal;
- float floatVal;
- if (pAcc->GetBarcodeAttribute_CharEncoding(intVal)) {
+ if (pAcc->GetBarcodeAttribute_CharEncoding(&intVal))
pBarCodeWidget->SetCharEncoding((BC_CHAR_ENCODING)intVal);
- }
- if (pAcc->GetBarcodeAttribute_Checksum(boolVal)) {
+
+ bool boolVal;
+ if (pAcc->GetBarcodeAttribute_Checksum(&boolVal))
pBarCodeWidget->SetCalChecksum(boolVal);
- }
- if (pAcc->GetBarcodeAttribute_DataLength(intVal)) {
+ if (pAcc->GetBarcodeAttribute_DataLength(&intVal))
pBarCodeWidget->SetDataLength(intVal);
- }
- if (pAcc->GetBarcodeAttribute_StartChar(charVal)) {
+
+ char charVal;
+ if (pAcc->GetBarcodeAttribute_StartChar(&charVal))
pBarCodeWidget->SetStartChar(charVal);
- }
- if (pAcc->GetBarcodeAttribute_EndChar(charVal)) {
+ if (pAcc->GetBarcodeAttribute_EndChar(&charVal))
pBarCodeWidget->SetEndChar(charVal);
- }
- if (pAcc->GetBarcodeAttribute_ECLevel(intVal)) {
+ if (pAcc->GetBarcodeAttribute_ECLevel(&intVal))
pBarCodeWidget->SetErrorCorrectionLevel(intVal);
- }
- if (pAcc->GetBarcodeAttribute_ModuleWidth(intVal)) {
+ if (pAcc->GetBarcodeAttribute_ModuleWidth(&intVal))
pBarCodeWidget->SetModuleWidth(intVal);
- }
- if (pAcc->GetBarcodeAttribute_ModuleHeight(intVal)) {
+ if (pAcc->GetBarcodeAttribute_ModuleHeight(&intVal))
pBarCodeWidget->SetModuleHeight(intVal);
- }
- if (pAcc->GetBarcodeAttribute_PrintChecksum(boolVal)) {
+ if (pAcc->GetBarcodeAttribute_PrintChecksum(&boolVal))
pBarCodeWidget->SetPrintChecksum(boolVal);
- }
- if (pAcc->GetBarcodeAttribute_TextLocation(intVal)) {
+ if (pAcc->GetBarcodeAttribute_TextLocation(&intVal))
pBarCodeWidget->SetTextLocation((BC_TEXT_LOC)intVal);
- }
- if (pAcc->GetBarcodeAttribute_Truncate(boolVal)) {
+ if (pAcc->GetBarcodeAttribute_Truncate(&boolVal))
pBarCodeWidget->SetTruncated(boolVal);
- }
- if (pAcc->GetBarcodeAttribute_WideNarrowRatio(floatVal)) {
+
+ float floatVal;
+ if (pAcc->GetBarcodeAttribute_WideNarrowRatio(&floatVal))
pBarCodeWidget->SetWideNarrowRatio(static_cast<int8_t>(floatVal));
- }
- if (pBarcodeTypeInfo->eName == XFA_BARCODETYPE_code3Of9 ||
- pBarcodeTypeInfo->eName == XFA_BARCODETYPE_ean8 ||
- pBarcodeTypeInfo->eName == XFA_BARCODETYPE_ean13 ||
- pBarcodeTypeInfo->eName == XFA_BARCODETYPE_upcA) {
+ if (pBarcodeInfo->eName == BarcodeType::code3Of9 ||
+ pBarcodeInfo->eName == BarcodeType::ean8 ||
+ pBarcodeInfo->eName == BarcodeType::ean13 ||
+ pBarcodeInfo->eName == BarcodeType::upcA) {
pBarCodeWidget->SetPrintChecksum(true);
}
}
diff --git a/xfa/fxfa/app/xfa_ffbarcode.h b/xfa/fxfa/app/xfa_ffbarcode.h
index ad12218f3d..51646236d0 100644
--- a/xfa/fxfa/app/xfa_ffbarcode.h
+++ b/xfa/fxfa/app/xfa_ffbarcode.h
@@ -11,8 +11,82 @@
#include "xfa/fxfa/app/xfa_fftextedit.h"
#include "xfa/fxfa/cxfa_ffpageview.h"
+enum class BarcodeType {
+ aztec,
+ codabar,
+ code11,
+ code128,
+ code128A,
+ code128B,
+ code128C,
+ code128SSCC,
+ code2Of5Industrial,
+ code2Of5Interleaved,
+ code2Of5Matrix,
+ code2Of5Standard,
+ code3Of9,
+ code3Of9extended,
+ code49,
+ code93,
+ dataMatrix,
+ ean13,
+ ean13add2,
+ ean13add5,
+ ean13pwcd,
+ ean8,
+ ean8add2,
+ ean8add5,
+ fim,
+ logmars,
+ maxicode,
+ msi,
+ pdf417,
+ pdf417macro,
+ plessey,
+ postAUSCust2,
+ postAUSCust3,
+ postAUSReplyPaid,
+ postAUSStandard,
+ postUKRM4SCC,
+ postUS5Zip,
+ postUSDPBC,
+ postUSIMB,
+ postUSStandard,
+ QRCode,
+ rfid,
+ rss14,
+ rss14Expanded,
+ rss14Limited,
+ rss14Stacked,
+ rss14StackedOmni,
+ rss14Truncated,
+ telepen,
+ ucc128,
+ ucc128random,
+ ucc128sscc,
+ upcA,
+ upcAadd2,
+ upcAadd5,
+ upcApwcd,
+ upcE,
+ upcEadd2,
+ upcEadd5,
+ upcean2,
+ upcean5,
+ upsMaxicode
+};
+
+struct BarCodeInfo {
+ uint32_t uHash;
+ const wchar_t* pName;
+ BarcodeType eName;
+ BC_TYPE eBCType;
+};
+
class CXFA_FFBarcode : public CXFA_FFTextEdit {
public:
+ static const BarCodeInfo* GetBarcodeTypeByName(const CFX_WideStringC& wsName);
+
explicit CXFA_FFBarcode(CXFA_WidgetAcc* pDataAcc);
~CXFA_FFBarcode() override;
@@ -26,76 +100,4 @@ class CXFA_FFBarcode : public CXFA_FFTextEdit {
bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) override;
};
-enum XFA_BARCODETYPEENUM {
- XFA_BARCODETYPE_aztec,
- XFA_BARCODETYPE_codabar,
- XFA_BARCODETYPE_code11,
- XFA_BARCODETYPE_code128,
- XFA_BARCODETYPE_code128A,
- XFA_BARCODETYPE_code128B,
- XFA_BARCODETYPE_code128C,
- XFA_BARCODETYPE_code128SSCC,
- XFA_BARCODETYPE_code2Of5Industrial,
- XFA_BARCODETYPE_code2Of5Interleaved,
- XFA_BARCODETYPE_code2Of5Matrix,
- XFA_BARCODETYPE_code2Of5Standard,
- XFA_BARCODETYPE_code3Of9,
- XFA_BARCODETYPE_code3Of9extended,
- XFA_BARCODETYPE_code49,
- XFA_BARCODETYPE_code93,
- XFA_BARCODETYPE_dataMatrix,
- XFA_BARCODETYPE_ean13,
- XFA_BARCODETYPE_ean13add2,
- XFA_BARCODETYPE_ean13add5,
- XFA_BARCODETYPE_ean13pwcd,
- XFA_BARCODETYPE_ean8,
- XFA_BARCODETYPE_ean8add2,
- XFA_BARCODETYPE_ean8add5,
- XFA_BARCODETYPE_fim,
- XFA_BARCODETYPE_logmars,
- XFA_BARCODETYPE_maxicode,
- XFA_BARCODETYPE_msi,
- XFA_BARCODETYPE_pdf417,
- XFA_BARCODETYPE_pdf417macro,
- XFA_BARCODETYPE_plessey,
- XFA_BARCODETYPE_postAUSCust2,
- XFA_BARCODETYPE_postAUSCust3,
- XFA_BARCODETYPE_postAUSReplyPaid,
- XFA_BARCODETYPE_postAUSStandard,
- XFA_BARCODETYPE_postUKRM4SCC,
- XFA_BARCODETYPE_postUS5Zip,
- XFA_BARCODETYPE_postUSDPBC,
- XFA_BARCODETYPE_postUSIMB,
- XFA_BARCODETYPE_postUSStandard,
- XFA_BARCODETYPE_QRCode,
- XFA_BARCODETYPE_rfid,
- XFA_BARCODETYPE_rss14,
- XFA_BARCODETYPE_rss14Expanded,
- XFA_BARCODETYPE_rss14Limited,
- XFA_BARCODETYPE_rss14Stacked,
- XFA_BARCODETYPE_rss14StackedOmni,
- XFA_BARCODETYPE_rss14Truncated,
- XFA_BARCODETYPE_telepen,
- XFA_BARCODETYPE_ucc128,
- XFA_BARCODETYPE_ucc128random,
- XFA_BARCODETYPE_ucc128sscc,
- XFA_BARCODETYPE_upcA,
- XFA_BARCODETYPE_upcAadd2,
- XFA_BARCODETYPE_upcAadd5,
- XFA_BARCODETYPE_upcApwcd,
- XFA_BARCODETYPE_upcE,
- XFA_BARCODETYPE_upcEadd2,
- XFA_BARCODETYPE_upcEadd5,
- XFA_BARCODETYPE_upcean2,
- XFA_BARCODETYPE_upcean5,
- XFA_BARCODETYPE_upsMaxicode
-};
-
-struct XFA_BARCODETYPEENUMINFO {
- uint32_t uHash;
- const wchar_t* pName;
- XFA_BARCODETYPEENUM eName;
- BC_TYPE eBCType;
-};
-
#endif // XFA_FXFA_APP_XFA_FFBARCODE_H_
diff --git a/xfa/fxfa/app/xfa_ffbarcode_unittest.cpp b/xfa/fxfa/app/xfa_ffbarcode_unittest.cpp
new file mode 100644
index 0000000000..95e2377cd8
--- /dev/null
+++ b/xfa/fxfa/app/xfa_ffbarcode_unittest.cpp
@@ -0,0 +1,25 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "xfa/fxfa/app/xfa_ffbarcode.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/base/ptr_util.h"
+
+TEST(XFA_FFBarcode, GetBarcodeTypeByName) {
+ EXPECT_EQ(nullptr, CXFA_FFBarcode::GetBarcodeTypeByName(L""));
+ EXPECT_EQ(nullptr, CXFA_FFBarcode::GetBarcodeTypeByName(L"not_found"));
+
+ auto* data = CXFA_FFBarcode::GetBarcodeTypeByName(L"ean13");
+ ASSERT_NE(nullptr, data);
+ EXPECT_EQ(BarcodeType::ean13, data->eName);
+
+ data = CXFA_FFBarcode::GetBarcodeTypeByName(L"pdf417");
+ ASSERT_NE(nullptr, data);
+ EXPECT_EQ(BarcodeType::pdf417, data->eName);
+
+ data = CXFA_FFBarcode::GetBarcodeTypeByName(L"code3Of9");
+ ASSERT_NE(nullptr, data);
+ EXPECT_EQ(BarcodeType::code3Of9, data->eName);
+}
diff --git a/xfa/fxfa/app/xfa_fftextedit.cpp b/xfa/fxfa/app/xfa_fftextedit.cpp
index ccb52d36a6..03f09cc11a 100644
--- a/xfa/fxfa/app/xfa_fftextedit.cpp
+++ b/xfa/fxfa/app/xfa_fftextedit.cpp
@@ -269,7 +269,7 @@ bool CXFA_FFTextEdit::UpdateFWLData() {
if (m_pDataAcc->GetUIType() == XFA_Element::Barcode) {
int32_t nDataLen = 0;
if (eType == XFA_VALUEPICTURE_Edit)
- m_pDataAcc->GetBarcodeAttribute_DataLength(nDataLen);
+ m_pDataAcc->GetBarcodeAttribute_DataLength(&nDataLen);
static_cast<CFWL_Edit*>(m_pNormalWidget.get())->SetLimit(nDataLen);
bUpdate = true;
}
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp
index 2f90f59bdd..361c48a6bc 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.cpp
+++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp
@@ -1182,32 +1182,32 @@ CFX_WideString CXFA_WidgetData::GetBarcodeType() {
: CFX_WideString();
}
-bool CXFA_WidgetData::GetBarcodeAttribute_CharEncoding(int32_t& val) {
+bool CXFA_WidgetData::GetBarcodeAttribute_CharEncoding(int32_t* val) {
CXFA_Node* pUIChild = GetUIChild();
CFX_WideString wsCharEncoding;
if (pUIChild->TryCData(XFA_ATTRIBUTE_CharEncoding, wsCharEncoding)) {
if (wsCharEncoding.CompareNoCase(L"UTF-16")) {
- val = CHAR_ENCODING_UNICODE;
+ *val = CHAR_ENCODING_UNICODE;
return true;
}
if (wsCharEncoding.CompareNoCase(L"UTF-8")) {
- val = CHAR_ENCODING_UTF8;
+ *val = CHAR_ENCODING_UTF8;
return true;
}
}
return false;
}
-bool CXFA_WidgetData::GetBarcodeAttribute_Checksum(bool& val) {
+bool CXFA_WidgetData::GetBarcodeAttribute_Checksum(bool* val) {
CXFA_Node* pUIChild = GetUIChild();
XFA_ATTRIBUTEENUM eChecksum;
if (pUIChild->TryEnum(XFA_ATTRIBUTE_Checksum, eChecksum)) {
switch (eChecksum) {
case XFA_ATTRIBUTEENUM_None:
- val = false;
+ *val = false;
return true;
case XFA_ATTRIBUTEENUM_Auto:
- val = true;
+ *val = true;
return true;
case XFA_ATTRIBUTEENUM_1mod10:
break;
@@ -1222,99 +1222,99 @@ bool CXFA_WidgetData::GetBarcodeAttribute_Checksum(bool& val) {
return false;
}
-bool CXFA_WidgetData::GetBarcodeAttribute_DataLength(int32_t& val) {
+bool CXFA_WidgetData::GetBarcodeAttribute_DataLength(int32_t* val) {
CXFA_Node* pUIChild = GetUIChild();
CFX_WideString wsDataLength;
if (pUIChild->TryCData(XFA_ATTRIBUTE_DataLength, wsDataLength)) {
- val = FXSYS_wtoi(wsDataLength.c_str());
+ *val = FXSYS_wtoi(wsDataLength.c_str());
return true;
}
return false;
}
-bool CXFA_WidgetData::GetBarcodeAttribute_StartChar(char& val) {
+bool CXFA_WidgetData::GetBarcodeAttribute_StartChar(char* val) {
CXFA_Node* pUIChild = GetUIChild();
CFX_WideStringC wsStartEndChar;
if (pUIChild->TryCData(XFA_ATTRIBUTE_StartChar, wsStartEndChar)) {
if (wsStartEndChar.GetLength()) {
- val = (char)wsStartEndChar.GetAt(0);
+ *val = static_cast<char>(wsStartEndChar.GetAt(0));
return true;
}
}
return false;
}
-bool CXFA_WidgetData::GetBarcodeAttribute_EndChar(char& val) {
+bool CXFA_WidgetData::GetBarcodeAttribute_EndChar(char* val) {
CXFA_Node* pUIChild = GetUIChild();
CFX_WideStringC wsStartEndChar;
if (pUIChild->TryCData(XFA_ATTRIBUTE_EndChar, wsStartEndChar)) {
if (wsStartEndChar.GetLength()) {
- val = (char)wsStartEndChar.GetAt(0);
+ *val = static_cast<char>(wsStartEndChar.GetAt(0));
return true;
}
}
return false;
}
-bool CXFA_WidgetData::GetBarcodeAttribute_ECLevel(int32_t& val) {
+bool CXFA_WidgetData::GetBarcodeAttribute_ECLevel(int32_t* val) {
CXFA_Node* pUIChild = GetUIChild();
CFX_WideString wsECLevel;
if (pUIChild->TryCData(XFA_ATTRIBUTE_ErrorCorrectionLevel, wsECLevel)) {
- val = FXSYS_wtoi(wsECLevel.c_str());
+ *val = FXSYS_wtoi(wsECLevel.c_str());
return true;
}
return false;
}
-bool CXFA_WidgetData::GetBarcodeAttribute_ModuleWidth(int32_t& val) {
+bool CXFA_WidgetData::GetBarcodeAttribute_ModuleWidth(int32_t* val) {
CXFA_Node* pUIChild = GetUIChild();
CXFA_Measurement mModuleWidthHeight;
if (pUIChild->TryMeasure(XFA_ATTRIBUTE_ModuleWidth, mModuleWidthHeight)) {
- val = (int32_t)mModuleWidthHeight.ToUnit(XFA_UNIT_Pt);
+ *val = static_cast<int32_t>(mModuleWidthHeight.ToUnit(XFA_UNIT_Pt));
return true;
}
return false;
}
-bool CXFA_WidgetData::GetBarcodeAttribute_ModuleHeight(int32_t& val) {
+bool CXFA_WidgetData::GetBarcodeAttribute_ModuleHeight(int32_t* val) {
CXFA_Node* pUIChild = GetUIChild();
CXFA_Measurement mModuleWidthHeight;
if (pUIChild->TryMeasure(XFA_ATTRIBUTE_ModuleHeight, mModuleWidthHeight)) {
- val = (int32_t)mModuleWidthHeight.ToUnit(XFA_UNIT_Pt);
+ *val = static_cast<int32_t>(mModuleWidthHeight.ToUnit(XFA_UNIT_Pt));
return true;
}
return false;
}
-bool CXFA_WidgetData::GetBarcodeAttribute_PrintChecksum(bool& val) {
+bool CXFA_WidgetData::GetBarcodeAttribute_PrintChecksum(bool* val) {
CXFA_Node* pUIChild = GetUIChild();
bool bPrintCheckDigit;
if (pUIChild->TryBoolean(XFA_ATTRIBUTE_PrintCheckDigit, bPrintCheckDigit)) {
- val = bPrintCheckDigit;
+ *val = bPrintCheckDigit;
return true;
}
return false;
}
-bool CXFA_WidgetData::GetBarcodeAttribute_TextLocation(int32_t& val) {
+bool CXFA_WidgetData::GetBarcodeAttribute_TextLocation(int32_t* val) {
CXFA_Node* pUIChild = GetUIChild();
XFA_ATTRIBUTEENUM eTextLocation;
if (pUIChild->TryEnum(XFA_ATTRIBUTE_TextLocation, eTextLocation)) {
switch (eTextLocation) {
case XFA_ATTRIBUTEENUM_None:
- val = BC_TEXT_LOC_NONE;
+ *val = BC_TEXT_LOC_NONE;
return true;
case XFA_ATTRIBUTEENUM_Above:
- val = BC_TEXT_LOC_ABOVE;
+ *val = BC_TEXT_LOC_ABOVE;
return true;
case XFA_ATTRIBUTEENUM_Below:
- val = BC_TEXT_LOC_BELOW;
+ *val = BC_TEXT_LOC_BELOW;
return true;
case XFA_ATTRIBUTEENUM_AboveEmbedded:
- val = BC_TEXT_LOC_ABOVEEMBED;
+ *val = BC_TEXT_LOC_ABOVEEMBED;
return true;
case XFA_ATTRIBUTEENUM_BelowEmbedded:
- val = BC_TEXT_LOC_BELOWEMBED;
+ *val = BC_TEXT_LOC_BELOWEMBED;
return true;
default:
break;
@@ -1323,17 +1323,17 @@ bool CXFA_WidgetData::GetBarcodeAttribute_TextLocation(int32_t& val) {
return false;
}
-bool CXFA_WidgetData::GetBarcodeAttribute_Truncate(bool& val) {
+bool CXFA_WidgetData::GetBarcodeAttribute_Truncate(bool* val) {
CXFA_Node* pUIChild = GetUIChild();
bool bTruncate;
- if (pUIChild->TryBoolean(XFA_ATTRIBUTE_Truncate, bTruncate)) {
- val = bTruncate;
- return true;
- }
- return false;
+ if (!pUIChild->TryBoolean(XFA_ATTRIBUTE_Truncate, bTruncate))
+ return false;
+
+ *val = bTruncate;
+ return true;
}
-bool CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio(float& val) {
+bool CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio(float* val) {
CXFA_Node* pUIChild = GetUIChild();
CFX_WideString wsWideNarrowRatio;
if (pUIChild->TryCData(XFA_ATTRIBUTE_WideNarrowRatio, wsWideNarrowRatio)) {
@@ -1348,7 +1348,7 @@ bool CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio(float& val) {
if (fB)
fRatio = (float)fA / fB;
}
- val = fRatio;
+ *val = fRatio;
return true;
}
return false;
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.h b/xfa/fxfa/parser/cxfa_widgetdata.h
index fb44745ad9..c38ea3502a 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.h
+++ b/xfa/fxfa/parser/cxfa_widgetdata.h
@@ -135,18 +135,18 @@ class CXFA_WidgetData : public CXFA_Data {
CFX_WideString& wsFormattedValue);
void NormalizeNumStr(const CFX_WideString& wsValue, CFX_WideString& wsOutput);
CFX_WideString GetBarcodeType();
- bool GetBarcodeAttribute_CharEncoding(int32_t& val);
- bool GetBarcodeAttribute_Checksum(bool& val);
- bool GetBarcodeAttribute_DataLength(int32_t& val);
- bool GetBarcodeAttribute_StartChar(char& val);
- bool GetBarcodeAttribute_EndChar(char& val);
- bool GetBarcodeAttribute_ECLevel(int32_t& val);
- bool GetBarcodeAttribute_ModuleWidth(int32_t& val);
- bool GetBarcodeAttribute_ModuleHeight(int32_t& val);
- bool GetBarcodeAttribute_PrintChecksum(bool& val);
- bool GetBarcodeAttribute_TextLocation(int32_t& val);
- bool GetBarcodeAttribute_Truncate(bool& val);
- bool GetBarcodeAttribute_WideNarrowRatio(float& val);
+ bool GetBarcodeAttribute_CharEncoding(int32_t* val);
+ bool GetBarcodeAttribute_Checksum(bool* val);
+ bool GetBarcodeAttribute_DataLength(int32_t* val);
+ bool GetBarcodeAttribute_StartChar(char* val);
+ bool GetBarcodeAttribute_EndChar(char* val);
+ bool GetBarcodeAttribute_ECLevel(int32_t* val);
+ bool GetBarcodeAttribute_ModuleWidth(int32_t* val);
+ bool GetBarcodeAttribute_ModuleHeight(int32_t* val);
+ bool GetBarcodeAttribute_PrintChecksum(bool* val);
+ bool GetBarcodeAttribute_TextLocation(int32_t* val);
+ bool GetBarcodeAttribute_Truncate(bool* val);
+ bool GetBarcodeAttribute_WideNarrowRatio(float* val);
void GetPasswordChar(CFX_WideString& wsPassWord);
bool IsMultiLine();
int32_t GetVerticalScrollPolicy();