Remove dependence on fxfa/parser on fx_barcode.
Move the mapping between parser values and BC_Library types up
one level to fxfa/ itself, which already has knowledge of both.
Change-Id: I544500533a52e57fcae6595ef15e3ee0d6e2e174
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/59218
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/cxfa_ffbarcode.cpp b/xfa/fxfa/cxfa_ffbarcode.cpp
index 0d813a6..08fda05 100644
--- a/xfa/fxfa/cxfa_ffbarcode.cpp
+++ b/xfa/fxfa/cxfa_ffbarcode.cpp
@@ -89,6 +89,31 @@
{0xfb48155c, "code3Of9", BarcodeType::code3Of9, BC_CODE39},
};
+Optional<BC_CHAR_ENCODING> CharEncodingFromString(const WideString& value) {
+ if (value.CompareNoCase(L"UTF-16"))
+ return CHAR_ENCODING_UNICODE;
+ if (value.CompareNoCase(L"UTF-8"))
+ return CHAR_ENCODING_UTF8;
+ return {};
+}
+
+Optional<BC_TEXT_LOC> TextLocFromAttribute(XFA_AttributeValue value) {
+ switch (value) {
+ case XFA_AttributeValue::None:
+ return BC_TEXT_LOC_NONE;
+ case XFA_AttributeValue::Above:
+ return BC_TEXT_LOC_ABOVE;
+ case XFA_AttributeValue::Below:
+ return BC_TEXT_LOC_BELOW;
+ case XFA_AttributeValue::AboveEmbedded:
+ return BC_TEXT_LOC_ABOVEEMBED;
+ case XFA_AttributeValue::BelowEmbedded:
+ return BC_TEXT_LOC_BELOWEMBED;
+ default:
+ return {};
+ }
+}
+
} // namespace.
// static
@@ -162,9 +187,13 @@
auto* pBarCodeWidget = static_cast<CFWL_Barcode*>(m_pNormalWidget.get());
pBarCodeWidget->SetType(info->eBCType);
- Optional<BC_CHAR_ENCODING> encoding = barcode_->GetCharEncoding();
- if (encoding)
- pBarCodeWidget->SetCharEncoding(*encoding);
+ Optional<WideString> encoding_string = barcode_->GetCharEncoding();
+ if (encoding_string) {
+ Optional<BC_CHAR_ENCODING> encoding =
+ CharEncodingFromString(*encoding_string);
+ if (encoding)
+ pBarCodeWidget->SetCharEncoding(*encoding);
+ }
Optional<bool> calcChecksum = barcode_->GetChecksum();
if (calcChecksum)
@@ -198,9 +227,12 @@
if (printCheck)
pBarCodeWidget->SetPrintChecksum(*printCheck);
- Optional<BC_TEXT_LOC> textLoc = barcode_->GetTextLocation();
- if (textLoc)
- pBarCodeWidget->SetTextLocation(*textLoc);
+ Optional<XFA_AttributeValue> text_attr = barcode_->GetTextLocation();
+ if (text_attr) {
+ Optional<BC_TEXT_LOC> textLoc = TextLocFromAttribute(*text_attr);
+ if (textLoc)
+ pBarCodeWidget->SetTextLocation(*textLoc);
+ }
// Truncated is currently not a supported flag.
diff --git a/xfa/fxfa/parser/BUILD.gn b/xfa/fxfa/parser/BUILD.gn
index 770cd52..c03e503 100644
--- a/xfa/fxfa/parser/BUILD.gn
+++ b/xfa/fxfa/parser/BUILD.gn
@@ -685,7 +685,6 @@
"../../../core/fxcodec",
"../../../core/fxcrt",
"../../../core/fxge",
- "../../../fxbarcode",
"../../../fxjs",
"../../fde",
"../../fgas",
diff --git a/xfa/fxfa/parser/cxfa_barcode.cpp b/xfa/fxfa/parser/cxfa_barcode.cpp
index d84acd5..ae3f9e2 100644
--- a/xfa/fxfa/parser/cxfa_barcode.cpp
+++ b/xfa/fxfa/parser/cxfa_barcode.cpp
@@ -62,16 +62,8 @@
return WideString(JSObject()->GetCData(XFA_Attribute::Type));
}
-Optional<BC_CHAR_ENCODING> CXFA_Barcode::GetCharEncoding() {
- Optional<WideString> wsCharEncoding =
- JSObject()->TryCData(XFA_Attribute::CharEncoding, true);
- if (!wsCharEncoding)
- return {};
- if (wsCharEncoding->CompareNoCase(L"UTF-16"))
- return {CHAR_ENCODING_UNICODE};
- if (wsCharEncoding->CompareNoCase(L"UTF-8"))
- return {CHAR_ENCODING_UTF8};
- return {};
+Optional<WideString> CXFA_Barcode::GetCharEncoding() {
+ return JSObject()->TryCData(XFA_Attribute::CharEncoding, true);
}
Optional<bool> CXFA_Barcode::GetChecksum() {
@@ -151,27 +143,8 @@
return JSObject()->TryBoolean(XFA_Attribute::PrintCheckDigit, true);
}
-Optional<BC_TEXT_LOC> CXFA_Barcode::GetTextLocation() {
- Optional<XFA_AttributeValue> textLocation =
- JSObject()->TryEnum(XFA_Attribute::TextLocation, true);
- if (!textLocation)
- return {};
-
- switch (*textLocation) {
- case XFA_AttributeValue::None:
- return {BC_TEXT_LOC_NONE};
- case XFA_AttributeValue::Above:
- return {BC_TEXT_LOC_ABOVE};
- case XFA_AttributeValue::Below:
- return {BC_TEXT_LOC_BELOW};
- case XFA_AttributeValue::AboveEmbedded:
- return {BC_TEXT_LOC_ABOVEEMBED};
- case XFA_AttributeValue::BelowEmbedded:
- return {BC_TEXT_LOC_BELOWEMBED};
- default:
- break;
- }
- return {};
+Optional<XFA_AttributeValue> CXFA_Barcode::GetTextLocation() {
+ return JSObject()->TryEnum(XFA_Attribute::TextLocation, true);
}
Optional<bool> CXFA_Barcode::GetTruncate() {
diff --git a/xfa/fxfa/parser/cxfa_barcode.h b/xfa/fxfa/parser/cxfa_barcode.h
index bf503e5..219e8b3 100644
--- a/xfa/fxfa/parser/cxfa_barcode.h
+++ b/xfa/fxfa/parser/cxfa_barcode.h
@@ -7,7 +7,6 @@
#ifndef XFA_FXFA_PARSER_CXFA_BARCODE_H_
#define XFA_FXFA_PARSER_CXFA_BARCODE_H_
-#include "fxbarcode/BC_Library.h"
#include "third_party/base/optional.h"
#include "xfa/fxfa/parser/cxfa_node.h"
@@ -19,7 +18,7 @@
XFA_FFWidgetType GetDefaultFFWidgetType() const override;
WideString GetBarcodeType();
- Optional<BC_CHAR_ENCODING> GetCharEncoding();
+ Optional<WideString> GetCharEncoding();
Optional<bool> GetChecksum();
Optional<int32_t> GetDataLength();
Optional<char> GetStartChar();
@@ -28,7 +27,7 @@
Optional<int32_t> GetModuleWidth();
Optional<int32_t> GetModuleHeight();
Optional<bool> GetPrintChecksum();
- Optional<BC_TEXT_LOC> GetTextLocation();
+ Optional<XFA_AttributeValue> GetTextLocation();
Optional<bool> GetTruncate();
Optional<int8_t> GetWideNarrowRatio();
};