OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
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/src/fxfa/app/xfa_ffbarcode.h" | |
8 | |
9 #include "core/include/fxcrt/fx_ext.h" | |
10 #include "xfa/include/fwl/core/fwl_app.h" | |
11 #include "xfa/include/fwl/lightwidget/barcode.h" | |
12 #include "xfa/src/fxfa/app/xfa_fffield.h" | |
13 #include "xfa/src/fxfa/app/xfa_ffpageview.h" | |
14 #include "xfa/src/fxfa/app/xfa_fftextedit.h" | |
15 #include "xfa/src/fxfa/app/xfa_ffwidget.h" | |
16 #include "xfa/src/fxfa/app/xfa_fwladapter.h" | |
17 | |
18 static XFA_LPCBARCODETYPEENUMINFO XFA_GetBarcodeTypeByName( | |
19 const CFX_WideStringC& wsName); | |
20 CXFA_FFBarcode::CXFA_FFBarcode(CXFA_FFPageView* pPageView, | |
21 CXFA_WidgetAcc* pDataAcc) | |
22 : CXFA_FFTextEdit(pPageView, pDataAcc) {} | |
23 CXFA_FFBarcode::~CXFA_FFBarcode() {} | |
24 FX_BOOL CXFA_FFBarcode::LoadWidget() { | |
25 CFWL_Barcode* pFWLBarcode = CFWL_Barcode::Create(); | |
26 if (pFWLBarcode) { | |
27 pFWLBarcode->Initialize(); | |
28 } | |
29 m_pNormalWidget = pFWLBarcode; | |
30 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); | |
31 m_pNormalWidget->SetPrivateData(pWidget, this, NULL); | |
32 IFWL_NoteDriver* pNoteDriver = FWL_GetApp()->GetNoteDriver(); | |
33 pNoteDriver->RegisterEventTarget(pWidget, pWidget); | |
34 m_pOldDelegate = m_pNormalWidget->SetDelegate(this); | |
35 m_pNormalWidget->LockUpdate(); | |
36 CFX_WideString wsText; | |
37 m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); | |
38 pFWLBarcode->SetText(wsText); | |
39 UpdateWidgetProperty(); | |
40 m_pNormalWidget->UnlockUpdate(); | |
41 return CXFA_FFField::LoadWidget(); | |
42 } | |
43 void CXFA_FFBarcode::RenderWidget(CFX_Graphics* pGS, | |
44 CFX_Matrix* pMatrix, | |
45 FX_DWORD dwStatus, | |
46 int32_t iRotate) { | |
47 if (!IsMatchVisibleStatus(dwStatus)) { | |
48 return; | |
49 } | |
50 CFX_Matrix mtRotate; | |
51 GetRotateMatrix(mtRotate); | |
52 if (pMatrix) { | |
53 mtRotate.Concat(*pMatrix); | |
54 } | |
55 CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); | |
56 CXFA_Border borderUI = m_pDataAcc->GetUIBorder(); | |
57 DrawBorder(pGS, borderUI, m_rtUI, &mtRotate); | |
58 RenderCaption(pGS, &mtRotate); | |
59 CFX_RectF rtWidget; | |
60 m_pNormalWidget->GetWidgetRect(rtWidget); | |
61 CFX_Matrix mt; | |
62 mt.Set(1, 0, 0, 1, rtWidget.left, rtWidget.top); | |
63 mt.Concat(mtRotate); | |
64 m_pNormalWidget->DrawWidget(pGS, &mt); | |
65 } | |
66 void CXFA_FFBarcode::UpdateWidgetProperty() { | |
67 CXFA_FFTextEdit::UpdateWidgetProperty(); | |
68 CFWL_Barcode* pBarCodeWidget = (CFWL_Barcode*)m_pNormalWidget; | |
69 CFX_WideString wsType = GetDataAcc()->GetBarcodeType(); | |
70 XFA_LPCBARCODETYPEENUMINFO pBarcodeTypeInfo = | |
71 XFA_GetBarcodeTypeByName(wsType); | |
72 pBarCodeWidget->SetType(pBarcodeTypeInfo->eBCType); | |
73 CXFA_WidgetAcc* pAcc = GetDataAcc(); | |
74 int32_t intVal; | |
75 FX_CHAR charVal; | |
76 FX_BOOL boolVal; | |
77 FX_FLOAT floatVal; | |
78 if (pAcc->GetBarcodeAttribute_CharEncoding(intVal)) { | |
79 pBarCodeWidget->SetCharEncoding((BC_CHAR_ENCODING)intVal); | |
80 } | |
81 if (pAcc->GetBarcodeAttribute_Checksum(intVal)) { | |
82 pBarCodeWidget->SetCalChecksum(intVal); | |
83 } | |
84 if (pAcc->GetBarcodeAttribute_DataLength(intVal)) { | |
85 pBarCodeWidget->SetDataLength(intVal); | |
86 } | |
87 if (pAcc->GetBarcodeAttribute_StartChar(charVal)) { | |
88 pBarCodeWidget->SetStartChar(charVal); | |
89 } | |
90 if (pAcc->GetBarcodeAttribute_EndChar(charVal)) { | |
91 pBarCodeWidget->SetEndChar(charVal); | |
92 } | |
93 if (pAcc->GetBarcodeAttribute_ECLevel(intVal)) { | |
94 pBarCodeWidget->SetErrorCorrectionLevel(intVal); | |
95 } | |
96 if (pAcc->GetBarcodeAttribute_ModuleWidth(intVal)) { | |
97 pBarCodeWidget->SetModuleWidth(intVal); | |
98 } | |
99 if (pAcc->GetBarcodeAttribute_ModuleHeight(intVal)) { | |
100 pBarCodeWidget->SetModuleHeight(intVal); | |
101 } | |
102 if (pAcc->GetBarcodeAttribute_PrintChecksum(boolVal)) { | |
103 pBarCodeWidget->SetPrintChecksum(boolVal); | |
104 } | |
105 if (pAcc->GetBarcodeAttribute_TextLocation(intVal)) { | |
106 pBarCodeWidget->SetTextLocation((BC_TEXT_LOC)intVal); | |
107 } | |
108 if (pAcc->GetBarcodeAttribute_Truncate(boolVal)) { | |
109 pBarCodeWidget->SetTruncated(boolVal); | |
110 } | |
111 if (pAcc->GetBarcodeAttribute_WideNarrowRatio(floatVal)) { | |
112 pBarCodeWidget->SetWideNarrowRatio((int32_t)floatVal); | |
113 } | |
114 if (pBarcodeTypeInfo->eName == XFA_BARCODETYPE_code3Of9 || | |
115 pBarcodeTypeInfo->eName == XFA_BARCODETYPE_ean8 || | |
116 pBarcodeTypeInfo->eName == XFA_BARCODETYPE_ean13 || | |
117 pBarcodeTypeInfo->eName == XFA_BARCODETYPE_upcA) { | |
118 pBarCodeWidget->SetPrintChecksum(TRUE); | |
119 } | |
120 } | |
121 FX_BOOL CXFA_FFBarcode::OnLButtonDown(FX_DWORD dwFlags, | |
122 FX_FLOAT fx, | |
123 FX_FLOAT fy) { | |
124 CFWL_Barcode* pBarCodeWidget = (CFWL_Barcode*)m_pNormalWidget; | |
125 if (!pBarCodeWidget || pBarCodeWidget->IsProtectedType()) { | |
126 return FALSE; | |
127 } | |
128 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) { | |
129 return FALSE; | |
130 } | |
131 return CXFA_FFTextEdit::OnLButtonDown(dwFlags, fx, fy); | |
132 } | |
133 FX_BOOL CXFA_FFBarcode::OnRButtonDown(FX_DWORD dwFlags, | |
134 FX_FLOAT fx, | |
135 FX_FLOAT fy) { | |
136 CFWL_Barcode* pBarCodeWidget = (CFWL_Barcode*)m_pNormalWidget; | |
137 if (!pBarCodeWidget || pBarCodeWidget->IsProtectedType()) { | |
138 return FALSE; | |
139 } | |
140 return CXFA_FFTextEdit::OnRButtonDown(dwFlags, fx, fy); | |
141 } | |
142 extern const XFA_BARCODETYPEENUMINFO g_XFABarCodeTypeEnumData[] = { | |
143 {0x7fb4a18, L"ean13", XFA_BARCODETYPE_ean13, BC_EAN13}, | |
144 {0x8d13a3d, L"code11", XFA_BARCODETYPE_code11, BC_UNKNOWN}, | |
145 {0x8d149a8, L"code49", XFA_BARCODETYPE_code49, BC_UNKNOWN}, | |
146 {0x8d16347, L"code93", XFA_BARCODETYPE_code93, BC_UNKNOWN}, | |
147 {0x91a92e2, L"upsMaxicode", XFA_BARCODETYPE_upsMaxicode, BC_UNKNOWN}, | |
148 {0xa7d48dc, L"fim", XFA_BARCODETYPE_fim, BC_UNKNOWN}, | |
149 {0xb359fe9, L"msi", XFA_BARCODETYPE_msi, BC_UNKNOWN}, | |
150 {0x121f738c, L"code2Of5Matrix", XFA_BARCODETYPE_code2Of5Matrix, BC_UNKNOWN}, | |
151 {0x15358616, L"ucc128", XFA_BARCODETYPE_ucc128, BC_UNKNOWN}, | |
152 {0x1f4bfa05, L"rfid", XFA_BARCODETYPE_rfid, BC_UNKNOWN}, | |
153 {0x1fda71bc, L"rss14Stacked", XFA_BARCODETYPE_rss14Stacked, BC_UNKNOWN}, | |
154 {0x22065087, L"ean8add2", XFA_BARCODETYPE_ean8add2, BC_UNKNOWN}, | |
155 {0x2206508a, L"ean8add5", XFA_BARCODETYPE_ean8add5, BC_UNKNOWN}, | |
156 {0x2278366c, L"codabar", XFA_BARCODETYPE_codabar, BC_CODABAR}, | |
157 {0x2a039a8d, L"telepen", XFA_BARCODETYPE_telepen, BC_UNKNOWN}, | |
158 {0x323ed337, L"upcApwcd", XFA_BARCODETYPE_upcApwcd, BC_UNKNOWN}, | |
159 {0x347a1846, L"postUSIMB", XFA_BARCODETYPE_postUSIMB, BC_UNKNOWN}, | |
160 {0x391bb836, L"code128", XFA_BARCODETYPE_code128, BC_CODE128}, | |
161 {0x398eddaf, L"dataMatrix", XFA_BARCODETYPE_dataMatrix, BC_DATAMATRIX}, | |
162 {0x3cff60a8, L"upcEadd2", XFA_BARCODETYPE_upcEadd2, BC_UNKNOWN}, | |
163 {0x3cff60ab, L"upcEadd5", XFA_BARCODETYPE_upcEadd5, BC_UNKNOWN}, | |
164 {0x402cb188, L"code2Of5Standard", XFA_BARCODETYPE_code2Of5Standard, | |
165 BC_UNKNOWN}, | |
166 {0x411764f7, L"aztec", XFA_BARCODETYPE_aztec, BC_UNKNOWN}, | |
167 {0x44d4e84c, L"ean8", XFA_BARCODETYPE_ean8, BC_EAN8}, | |
168 {0x48468902, L"ucc128sscc", XFA_BARCODETYPE_ucc128sscc, BC_UNKNOWN}, | |
169 {0x4880aea4, L"upcAadd2", XFA_BARCODETYPE_upcAadd2, BC_UNKNOWN}, | |
170 {0x4880aea7, L"upcAadd5", XFA_BARCODETYPE_upcAadd5, BC_UNKNOWN}, | |
171 {0x54f18256, L"code2Of5Industrial", XFA_BARCODETYPE_code2Of5Industrial, | |
172 BC_UNKNOWN}, | |
173 {0x58e15f25, L"rss14Limited", XFA_BARCODETYPE_rss14Limited, BC_UNKNOWN}, | |
174 {0x5c08d1b9, L"postAUSReplyPaid", XFA_BARCODETYPE_postAUSReplyPaid, | |
175 BC_UNKNOWN}, | |
176 {0x5fa700bd, L"rss14", XFA_BARCODETYPE_rss14, BC_UNKNOWN}, | |
177 {0x631a7e35, L"logmars", XFA_BARCODETYPE_logmars, BC_UNKNOWN}, | |
178 {0x6a236236, L"pdf417", XFA_BARCODETYPE_pdf417, BC_PDF417}, | |
179 {0x6d098ece, L"upcean2", XFA_BARCODETYPE_upcean2, BC_UNKNOWN}, | |
180 {0x6d098ed1, L"upcean5", XFA_BARCODETYPE_upcean5, BC_UNKNOWN}, | |
181 {0x76b04eed, L"code3Of9extended", XFA_BARCODETYPE_code3Of9extended, | |
182 BC_UNKNOWN}, | |
183 {0x7c7db84a, L"maxicode", XFA_BARCODETYPE_maxicode, BC_UNKNOWN}, | |
184 {0x8266f7f7, L"ucc128random", XFA_BARCODETYPE_ucc128random, BC_UNKNOWN}, | |
185 {0x83eca147, L"postUSDPBC", XFA_BARCODETYPE_postUSDPBC, BC_UNKNOWN}, | |
186 {0x8dd71de0, L"postAUSStandard", XFA_BARCODETYPE_postAUSStandard, | |
187 BC_UNKNOWN}, | |
188 {0x98adad85, L"plessey", XFA_BARCODETYPE_plessey, BC_UNKNOWN}, | |
189 {0x9f84cce6, L"ean13pwcd", XFA_BARCODETYPE_ean13pwcd, BC_UNKNOWN}, | |
190 {0xb514fbe9, L"upcA", XFA_BARCODETYPE_upcA, BC_UPCA}, | |
191 {0xb514fbed, L"upcE", XFA_BARCODETYPE_upcE, BC_UNKNOWN}, | |
192 {0xb5c6a853, L"ean13add2", XFA_BARCODETYPE_ean13add2, BC_UNKNOWN}, | |
193 {0xb5c6a856, L"ean13add5", XFA_BARCODETYPE_ean13add5, BC_UNKNOWN}, | |
194 {0xb81fc512, L"postUKRM4SCC", XFA_BARCODETYPE_postUKRM4SCC, BC_UNKNOWN}, | |
195 {0xbad34b22, L"code128SSCC", XFA_BARCODETYPE_code128SSCC, BC_UNKNOWN}, | |
196 {0xbfbe0cf6, L"postUS5Zip", XFA_BARCODETYPE_postUS5Zip, BC_UNKNOWN}, | |
197 {0xc56618e8, L"pdf417macro", XFA_BARCODETYPE_pdf417macro, BC_UNKNOWN}, | |
198 {0xca730f8a, L"code2Of5Interleaved", XFA_BARCODETYPE_code2Of5Interleaved, | |
199 BC_UNKNOWN}, | |
200 {0xd0097ac6, L"rss14Expanded", XFA_BARCODETYPE_rss14Expanded, BC_UNKNOWN}, | |
201 {0xd25a0240, L"postAUSCust2", XFA_BARCODETYPE_postAUSCust2, BC_UNKNOWN}, | |
202 {0xd25a0241, L"postAUSCust3", XFA_BARCODETYPE_postAUSCust3, BC_UNKNOWN}, | |
203 {0xd53ed3e7, L"rss14Truncated", XFA_BARCODETYPE_rss14Truncated, BC_UNKNOWN}, | |
204 {0xe72bcd57, L"code128A", XFA_BARCODETYPE_code128A, BC_UNKNOWN}, | |
205 {0xe72bcd58, L"code128B", XFA_BARCODETYPE_code128B, BC_CODE128_B}, | |
206 {0xe72bcd59, L"code128C", XFA_BARCODETYPE_code128C, BC_CODE128_C}, | |
207 {0xee83c50f, L"rss14StackedOmni", XFA_BARCODETYPE_rss14StackedOmni, | |
208 BC_UNKNOWN}, | |
209 {0xf2a18f7e, L"QRCode", XFA_BARCODETYPE_QRCode, BC_QR_CODE}, | |
210 {0xfaeaf37f, L"postUSStandard", XFA_BARCODETYPE_postUSStandard, BC_UNKNOWN}, | |
211 {0xfb48155c, L"code3Of9", XFA_BARCODETYPE_code3Of9, BC_CODE39}, | |
212 }; | |
213 extern const int32_t g_iXFABarcodeTypeCount = | |
214 sizeof(g_XFABarCodeTypeEnumData) / sizeof(XFA_BARCODETYPEENUMINFO); | |
215 static XFA_LPCBARCODETYPEENUMINFO XFA_GetBarcodeTypeByName( | |
216 const CFX_WideStringC& wsName) { | |
217 int32_t iLength = wsName.GetLength(); | |
218 if (iLength == 0) { | |
219 return NULL; | |
220 } | |
221 uint32_t uHash = FX_HashCode_String_GetW(wsName.GetPtr(), iLength, TRUE); | |
222 int32_t iStart = 0, iEnd = g_iXFABarcodeTypeCount - 1; | |
223 do { | |
224 int32_t iMid = (iStart + iEnd) / 2; | |
225 XFA_LPCBARCODETYPEENUMINFO pInfo = g_XFABarCodeTypeEnumData + iMid; | |
226 if (uHash == pInfo->uHash) { | |
227 return pInfo; | |
228 } else if (uHash < pInfo->uHash) { | |
229 iEnd = iMid - 1; | |
230 } else { | |
231 iStart = iMid + 1; | |
232 } | |
233 } while (iStart <= iEnd); | |
234 return NULL; | |
235 } | |
OLD | NEW |