Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cxfa_barcode.cpp
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "xfa/fxfa/parser/cxfa_barcode.h"
8
9#include "fxjs/xfa/cjx_node.h"
10#include "xfa/fxfa/parser/cxfa_document.h"
11#include "xfa/fxfa/parser/cxfa_measurement.h"
12
13namespace {
14
15const CXFA_Node::AttributeData kBarcodeAttributeData[] = {
17 {XFA_Attribute::DataRowCount, XFA_AttributeType::CData, nullptr},
20 (void*)XFA_AttributeValue::None},
21 {XFA_Attribute::Type, XFA_AttributeType::CData, (void*)nullptr},
23 (void*)XFA_AttributeValue::Below},
24 {XFA_Attribute::ModuleWidth, XFA_AttributeType::Measure, (void*)L"0.25mm"},
25 {XFA_Attribute::PrintCheckDigit, XFA_AttributeType::Boolean, (void*)0},
26 {XFA_Attribute::ModuleHeight, XFA_AttributeType::Measure, (void*)L"5mm"},
27 {XFA_Attribute::StartChar, XFA_AttributeType::CData, nullptr},
28 {XFA_Attribute::Truncate, XFA_AttributeType::Boolean, (void*)0},
29 {XFA_Attribute::WideNarrowRatio, XFA_AttributeType::CData, (void*)L"3:1"},
30 {XFA_Attribute::ErrorCorrectionLevel, XFA_AttributeType::CData, nullptr},
32 (void*)XFA_AttributeValue::UsCarrier},
34 (void*)XFA_AttributeValue::None},
35 {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
36 {XFA_Attribute::DataColumnCount, XFA_AttributeType::CData, nullptr},
37 {XFA_Attribute::RowColumnRatio, XFA_AttributeType::CData, nullptr},
38 {XFA_Attribute::DataLength, XFA_AttributeType::CData, nullptr},
39 {XFA_Attribute::EndChar, XFA_AttributeType::CData, nullptr},
40};
41
42} // namespace
43
44// static
45CXFA_Barcode* CXFA_Barcode::FromNode(CXFA_Node* pNode) {
46 return pNode && pNode->GetElementType() == XFA_Element::Barcode
47 ? static_cast<CXFA_Barcode*>(pNode)
48 : nullptr;
49}
50
51CXFA_Barcode::CXFA_Barcode(CXFA_Document* doc, XFA_PacketType packet)
52 : CXFA_Node(doc,
53 packet,
54 {XFA_XDPPACKET::kTemplate, XFA_XDPPACKET::kForm},
55 XFA_ObjectType::Node,
56 XFA_Element::Barcode,
57 {},
58 kBarcodeAttributeData,
59 cppgc::MakeGarbageCollected<CJX_Node>(
60 doc->GetHeap()->GetAllocationHandle(),
61 this)) {}
62
63CXFA_Barcode::~CXFA_Barcode() = default;
64
68
69WideString CXFA_Barcode::GetBarcodeType() {
70 return WideString(JSObject()->GetCData(XFA_Attribute::Type));
71}
72
73std::optional<bool> CXFA_Barcode::GetChecksum() {
74 std::optional<XFA_AttributeValue> checksum =
75 JSObject()->TryEnum(XFA_Attribute::Checksum, true);
76 if (!checksum.has_value())
77 return std::nullopt;
78
79 switch (checksum.value()) {
80 case XFA_AttributeValue::None:
81 return {false};
82 case XFA_AttributeValue::Auto:
83 return {true};
84 case XFA_AttributeValue::Checksum_1mod10:
85 case XFA_AttributeValue::Checksum_1mod10_1mod11:
86 case XFA_AttributeValue::Checksum_2mod10:
87 default:
88 break;
89 }
90 return std::nullopt;
91}
92
93std::optional<int32_t> CXFA_Barcode::GetDataLength() {
94 std::optional<WideString> wsDataLength =
95 JSObject()->TryCData(XFA_Attribute::DataLength, true);
96 if (!wsDataLength.has_value())
97 return std::nullopt;
98
99 return FXSYS_wtoi(wsDataLength->c_str());
100}
101
102std::optional<char> CXFA_Barcode::GetStartChar() {
103 std::optional<WideString> wsStartEndChar =
104 JSObject()->TryCData(XFA_Attribute::StartChar, true);
105 if (!wsStartEndChar.has_value() || wsStartEndChar->IsEmpty())
106 return std::nullopt;
107
108 return static_cast<char>(wsStartEndChar.value()[0]);
109}
110
111std::optional<char> CXFA_Barcode::GetEndChar() {
112 std::optional<WideString> wsStartEndChar =
113 JSObject()->TryCData(XFA_Attribute::EndChar, true);
114 if (!wsStartEndChar.has_value() || wsStartEndChar->IsEmpty())
115 return std::nullopt;
116
117 return static_cast<char>(wsStartEndChar.value()[0]);
118}
119
120std::optional<int32_t> CXFA_Barcode::GetECLevel() {
121 std::optional<WideString> wsECLevel =
122 JSObject()->TryCData(XFA_Attribute::ErrorCorrectionLevel, true);
123 if (!wsECLevel.has_value())
124 return std::nullopt;
125 return FXSYS_wtoi(wsECLevel->c_str());
126}
127
128std::optional<int32_t> CXFA_Barcode::GetModuleWidth() {
129 std::optional<CXFA_Measurement> moduleWidthHeight =
130 JSObject()->TryMeasure(XFA_Attribute::ModuleWidth, true);
131 if (!moduleWidthHeight.has_value())
132 return std::nullopt;
133
134 return static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt));
135}
136
137std::optional<int32_t> CXFA_Barcode::GetModuleHeight() {
138 std::optional<CXFA_Measurement> moduleWidthHeight =
139 JSObject()->TryMeasure(XFA_Attribute::ModuleHeight, true);
140 if (!moduleWidthHeight.has_value())
141 return std::nullopt;
142
143 return static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt));
144}
145
146std::optional<bool> CXFA_Barcode::GetPrintChecksum() {
147 return JSObject()->TryBoolean(XFA_Attribute::PrintCheckDigit, true);
148}
149
150std::optional<XFA_AttributeValue> CXFA_Barcode::GetTextLocation() {
151 return JSObject()->TryEnum(XFA_Attribute::TextLocation, true);
152}
153
154std::optional<bool> CXFA_Barcode::GetTruncate() {
155 return JSObject()->TryBoolean(XFA_Attribute::Truncate, true);
156}
157
158std::optional<int8_t> CXFA_Barcode::GetWideNarrowRatio() {
159 std::optional<WideString> wsWideNarrowRatio =
160 JSObject()->TryCData(XFA_Attribute::WideNarrowRatio, true);
161 if (!wsWideNarrowRatio.has_value())
162 return std::nullopt;
163
164 std::optional<size_t> ptPos = wsWideNarrowRatio->Find(':');
165 if (!ptPos.has_value())
166 return static_cast<int8_t>(FXSYS_wtoi(wsWideNarrowRatio->c_str()));
167
168 int32_t fB = FXSYS_wtoi(
169 wsWideNarrowRatio
170 ->Last(wsWideNarrowRatio->GetLength() - (ptPos.value() + 1))
171 .c_str());
172 if (!fB)
173 return 0;
174
175 int32_t fA = FXSYS_wtoi(wsWideNarrowRatio->First(ptPos.value()).c_str());
176 float result = static_cast<float>(fA) / static_cast<float>(fB);
177 return static_cast<int8_t>(result);
178}
std::optional< int32_t > GetDataLength()
std::optional< int32_t > GetModuleWidth()
std::optional< bool > GetPrintChecksum()
std::optional< bool > GetTruncate()
std::optional< bool > GetChecksum()
static CXFA_Barcode * FromNode(CXFA_Node *pNode)
XFA_FFWidgetType GetDefaultFFWidgetType() const override
WideString GetBarcodeType()
~CXFA_Barcode() override
std::optional< char > GetStartChar()
std::optional< int32_t > GetECLevel()
std::optional< int32_t > GetModuleHeight()
std::optional< int8_t > GetWideNarrowRatio()
std::optional< char > GetEndChar()
std::optional< XFA_AttributeValue > GetTextLocation()
XFA_Element GetElementType() const
Definition cxfa_object.h:91
XFA_FFWidgetType
XFA_Unit
Definition fxfa_basic.h:91
XFA_AttributeType
Definition fxfa_basic.h:83
XFA_Attribute
Definition fxfa_basic.h:67
XFA_Element
Definition fxfa_basic.h:75
XFA_AttributeValue
Definition fxfa_basic.h:60
XFA_PacketType
Definition fxfa_basic.h:44
fxcrt::WideString WideString
Definition widestring.h:207