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::CharEncoding, XFA_AttributeType::CData, (void*)L"UTF-8"},
36 {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
37 {XFA_Attribute::DataColumnCount, XFA_AttributeType::CData, nullptr},
38 {XFA_Attribute::RowColumnRatio, XFA_AttributeType::CData, nullptr},
39 {XFA_Attribute::DataLength, XFA_AttributeType::CData, nullptr},
40 {XFA_Attribute::EndChar, XFA_AttributeType::CData, nullptr},
41};
42
43} // namespace
44
45// static
46CXFA_Barcode* CXFA_Barcode::FromNode(CXFA_Node* pNode) {
47 return pNode && pNode->GetElementType() == XFA_Element::Barcode
48 ? static_cast<CXFA_Barcode*>(pNode)
49 : nullptr;
50}
51
52CXFA_Barcode::CXFA_Barcode(CXFA_Document* doc, XFA_PacketType packet)
53 : CXFA_Node(doc,
54 packet,
55 {XFA_XDPPACKET::kTemplate, XFA_XDPPACKET::kForm},
56 XFA_ObjectType::Node,
57 XFA_Element::Barcode,
58 {},
59 kBarcodeAttributeData,
60 cppgc::MakeGarbageCollected<CJX_Node>(
61 doc->GetHeap()->GetAllocationHandle(),
62 this)) {}
63
64CXFA_Barcode::~CXFA_Barcode() = default;
65
69
70WideString CXFA_Barcode::GetBarcodeType() {
71 return WideString(JSObject()->GetCData(XFA_Attribute::Type));
72}
73
75 return JSObject()->TryCData(XFA_Attribute::CharEncoding, true);
76}
77
78absl::optional<bool> CXFA_Barcode::GetChecksum() {
79 absl::optional<XFA_AttributeValue> checksum =
80 JSObject()->TryEnum(XFA_Attribute::Checksum, true);
81 if (!checksum.has_value())
82 return absl::nullopt;
83
84 switch (checksum.value()) {
85 case XFA_AttributeValue::None:
86 return {false};
87 case XFA_AttributeValue::Auto:
88 return {true};
89 case XFA_AttributeValue::Checksum_1mod10:
90 case XFA_AttributeValue::Checksum_1mod10_1mod11:
91 case XFA_AttributeValue::Checksum_2mod10:
92 default:
93 break;
94 }
95 return absl::nullopt;
96}
97
99 absl::optional<WideString> wsDataLength =
100 JSObject()->TryCData(XFA_Attribute::DataLength, true);
101 if (!wsDataLength.has_value())
102 return absl::nullopt;
103
104 return FXSYS_wtoi(wsDataLength->c_str());
105}
106
107absl::optional<char> CXFA_Barcode::GetStartChar() {
108 absl::optional<WideString> wsStartEndChar =
109 JSObject()->TryCData(XFA_Attribute::StartChar, true);
110 if (!wsStartEndChar.has_value() || wsStartEndChar->IsEmpty())
111 return absl::nullopt;
112
113 return static_cast<char>(wsStartEndChar.value()[0]);
114}
115
116absl::optional<char> CXFA_Barcode::GetEndChar() {
117 absl::optional<WideString> wsStartEndChar =
118 JSObject()->TryCData(XFA_Attribute::EndChar, true);
119 if (!wsStartEndChar.has_value() || wsStartEndChar->IsEmpty())
120 return absl::nullopt;
121
122 return static_cast<char>(wsStartEndChar.value()[0]);
123}
124
125absl::optional<int32_t> CXFA_Barcode::GetECLevel() {
126 absl::optional<WideString> wsECLevel =
127 JSObject()->TryCData(XFA_Attribute::ErrorCorrectionLevel, true);
128 if (!wsECLevel.has_value())
129 return absl::nullopt;
130 return FXSYS_wtoi(wsECLevel->c_str());
131}
132
134 absl::optional<CXFA_Measurement> moduleWidthHeight =
135 JSObject()->TryMeasure(XFA_Attribute::ModuleWidth, true);
136 if (!moduleWidthHeight.has_value())
137 return absl::nullopt;
138
139 return static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt));
140}
141
143 absl::optional<CXFA_Measurement> moduleWidthHeight =
144 JSObject()->TryMeasure(XFA_Attribute::ModuleHeight, true);
145 if (!moduleWidthHeight.has_value())
146 return absl::nullopt;
147
148 return static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt));
149}
150
151absl::optional<bool> CXFA_Barcode::GetPrintChecksum() {
152 return JSObject()->TryBoolean(XFA_Attribute::PrintCheckDigit, true);
153}
154
156 return JSObject()->TryEnum(XFA_Attribute::TextLocation, true);
157}
158
159absl::optional<bool> CXFA_Barcode::GetTruncate() {
160 return JSObject()->TryBoolean(XFA_Attribute::Truncate, true);
161}
162
164 absl::optional<WideString> wsWideNarrowRatio =
165 JSObject()->TryCData(XFA_Attribute::WideNarrowRatio, true);
166 if (!wsWideNarrowRatio.has_value())
167 return absl::nullopt;
168
169 absl::optional<size_t> ptPos = wsWideNarrowRatio->Find(':');
170 if (!ptPos.has_value())
171 return static_cast<int8_t>(FXSYS_wtoi(wsWideNarrowRatio->c_str()));
172
173 int32_t fB = FXSYS_wtoi(
174 wsWideNarrowRatio
175 ->Last(wsWideNarrowRatio->GetLength() - (ptPos.value() + 1))
176 .c_str());
177 if (!fB)
178 return 0;
179
180 int32_t fA = FXSYS_wtoi(wsWideNarrowRatio->First(ptPos.value()).c_str());
181 float result = static_cast<float>(fA) / static_cast<float>(fB);
182 return static_cast<int8_t>(result);
183}
absl::optional< WideString > GetCharEncoding()
static CXFA_Barcode * FromNode(CXFA_Node *pNode)
absl::optional< bool > GetChecksum()
XFA_FFWidgetType GetDefaultFFWidgetType() const override
absl::optional< XFA_AttributeValue > GetTextLocation()
WideString GetBarcodeType()
~CXFA_Barcode() override
absl::optional< int32_t > GetModuleWidth()
absl::optional< int32_t > GetDataLength()
absl::optional< char > GetEndChar()
absl::optional< bool > GetTruncate()
absl::optional< int32_t > GetModuleHeight()
absl::optional< bool > GetPrintChecksum()
absl::optional< int32_t > GetECLevel()
absl::optional< int8_t > GetWideNarrowRatio()
absl::optional< char > GetStartChar()
XFA_Element GetElementType() const
Definition cxfa_object.h:91
XFA_FFWidgetType
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