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 #ifndef XFA_INCLUDE_FXBARCODE_BC_BARCODE_H_ | |
8 #define XFA_INCLUDE_FXBARCODE_BC_BARCODE_H_ | |
9 | |
10 #include "core/include/fxcrt/fx_string.h" | |
11 #include "core/include/fxcrt/fx_system.h" | |
12 #include "core/include/fxge/fx_dib.h" | |
13 | |
14 class CBC_Reader; | |
15 class CBC_Writer; | |
16 class CFX_Font; | |
17 class CFX_RenderDevice; | |
18 | |
19 enum BC_TEXT_LOC { | |
20 BC_TEXT_LOC_NONE = 0, | |
21 BC_TEXT_LOC_ABOVE, | |
22 BC_TEXT_LOC_BELOW, | |
23 BC_TEXT_LOC_ABOVEEMBED, | |
24 BC_TEXT_LOC_BELOWEMBED | |
25 }; | |
26 | |
27 enum BC_CHAR_ENCODING { CHAR_ENCODING_UTF8 = 0, CHAR_ENCODING_UNICODE }; | |
28 | |
29 enum BC_TYPE { | |
30 BC_UNKNOWN = -1, | |
31 BC_CODE39 = 0, | |
32 BC_CODABAR, | |
33 BC_CODE128, | |
34 BC_CODE128_B, | |
35 BC_CODE128_C, | |
36 BC_EAN8, | |
37 BC_UPCA, | |
38 BC_EAN13, | |
39 BC_QR_CODE, | |
40 BC_PDF417, | |
41 BC_DATAMATRIX | |
42 }; | |
43 | |
44 void BC_Library_Init(); | |
45 void BC_Library_Destory(); | |
46 | |
47 class CBC_CodeBase { | |
48 public: | |
49 CBC_CodeBase(); | |
50 virtual ~CBC_CodeBase(); | |
51 virtual BC_TYPE GetType() = 0; | |
52 virtual FX_BOOL Encode(const CFX_WideStringC& contents, | |
53 FX_BOOL isDevice, | |
54 int32_t& e) = 0; | |
55 virtual FX_BOOL RenderDevice(CFX_RenderDevice* device, | |
56 const CFX_Matrix* matirx, | |
57 int32_t& e) = 0; | |
58 virtual FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) = 0; | |
59 virtual CFX_WideString Decode(uint8_t* buf, | |
60 int32_t width, | |
61 int32_t hight, | |
62 int32_t& e) = 0; | |
63 virtual CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e) = 0; | |
64 | |
65 virtual FX_BOOL SetCharEncoding(int32_t encoding); | |
66 virtual FX_BOOL SetModuleHeight(int32_t moduleHeight); | |
67 virtual FX_BOOL SetModuleWidth(int32_t moduleWidth); | |
68 | |
69 virtual FX_BOOL SetHeight(int32_t height); | |
70 virtual FX_BOOL SetWidth(int32_t width); | |
71 virtual void SetBackgroundColor(FX_ARGB backgroundColor); | |
72 virtual void SetBarcodeColor(FX_ARGB foregroundColor); | |
73 | |
74 protected: | |
75 CBC_Writer* m_pBCWriter; | |
76 CBC_Reader* m_pBCReader; | |
77 }; | |
78 class CBC_OneCode : public CBC_CodeBase { | |
79 public: | |
80 CBC_OneCode(); | |
81 virtual ~CBC_OneCode(); | |
82 virtual BC_TYPE GetType() = 0; | |
83 virtual FX_BOOL Encode(const CFX_WideStringC& contents, | |
84 FX_BOOL isDevice, | |
85 int32_t& e) = 0; | |
86 virtual FX_BOOL RenderDevice(CFX_RenderDevice* device, | |
87 const CFX_Matrix* matirx, | |
88 int32_t& e) = 0; | |
89 virtual FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) = 0; | |
90 virtual CFX_WideString Decode(uint8_t* buf, | |
91 int32_t width, | |
92 int32_t hight, | |
93 int32_t& e) = 0; | |
94 virtual CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e) = 0; | |
95 virtual FX_BOOL CheckContentValidity(const CFX_WideStringC& contents); | |
96 virtual CFX_WideString FilterContents(const CFX_WideStringC& contents); | |
97 virtual void SetPrintChecksum(FX_BOOL checksum); | |
98 virtual void SetDataLength(int32_t length); | |
99 virtual void SetCalChecksum(FX_BOOL calc); | |
100 virtual FX_BOOL SetFont(CFX_Font* cFont); | |
101 virtual void SetFontSize(FX_FLOAT size); | |
102 virtual void SetFontStyle(int32_t style); | |
103 virtual void SetFontColor(FX_ARGB color); | |
104 }; | |
105 class CBC_Code39 : public CBC_OneCode { | |
106 public: | |
107 CBC_Code39(); | |
108 CBC_Code39(FX_BOOL usingCheckDigit); | |
109 CBC_Code39(FX_BOOL usingCheckDigit, FX_BOOL extendedMode); | |
110 virtual ~CBC_Code39(); | |
111 FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); | |
112 FX_BOOL RenderDevice(CFX_RenderDevice* device, | |
113 const CFX_Matrix* matirx, | |
114 int32_t& e); | |
115 FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); | |
116 CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); | |
117 CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); | |
118 BC_TYPE GetType() { return BC_CODE39; } | |
119 FX_BOOL SetTextLocation(BC_TEXT_LOC location); | |
120 FX_BOOL SetWideNarrowRatio(int32_t ratio); | |
121 | |
122 private: | |
123 CFX_WideString m_renderContents; | |
124 }; | |
125 class CBC_Codabar : public CBC_OneCode { | |
126 public: | |
127 CBC_Codabar(); | |
128 virtual ~CBC_Codabar(); | |
129 FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); | |
130 FX_BOOL RenderDevice(CFX_RenderDevice* device, | |
131 const CFX_Matrix* matirx, | |
132 int32_t& e); | |
133 FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); | |
134 CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); | |
135 CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); | |
136 BC_TYPE GetType() { return BC_CODABAR; } | |
137 FX_BOOL SetStartChar(FX_CHAR start); | |
138 FX_BOOL SetEndChar(FX_CHAR end); | |
139 FX_BOOL SetTextLocation(BC_TEXT_LOC location); | |
140 FX_BOOL SetWideNarrowRatio(int32_t ratio); | |
141 | |
142 private: | |
143 CFX_WideString m_renderContents; | |
144 }; | |
145 class CBC_Code128 : public CBC_OneCode { | |
146 public: | |
147 CBC_Code128(BC_TYPE type); | |
148 virtual ~CBC_Code128(); | |
149 FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); | |
150 FX_BOOL RenderDevice(CFX_RenderDevice* device, | |
151 const CFX_Matrix* matirx, | |
152 int32_t& e); | |
153 FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); | |
154 CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); | |
155 CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); | |
156 BC_TYPE GetType() { return BC_CODE128; } | |
157 FX_BOOL SetTextLocation(BC_TEXT_LOC loction); | |
158 | |
159 private: | |
160 CFX_WideString m_renderContents; | |
161 }; | |
162 class CBC_EAN8 : public CBC_OneCode { | |
163 public: | |
164 CBC_EAN8(); | |
165 virtual ~CBC_EAN8(); | |
166 FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); | |
167 FX_BOOL RenderDevice(CFX_RenderDevice* device, | |
168 const CFX_Matrix* matirx, | |
169 int32_t& e); | |
170 FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); | |
171 CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); | |
172 CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); | |
173 BC_TYPE GetType() { return BC_EAN8; } | |
174 | |
175 private: | |
176 CFX_WideString Preprocess(const CFX_WideStringC& contents); | |
177 CFX_WideString m_renderContents; | |
178 }; | |
179 class CBC_EAN13 : public CBC_OneCode { | |
180 public: | |
181 CBC_EAN13(); | |
182 virtual ~CBC_EAN13(); | |
183 FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); | |
184 FX_BOOL RenderDevice(CFX_RenderDevice* device, | |
185 const CFX_Matrix* matirx, | |
186 int32_t& e); | |
187 FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); | |
188 CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); | |
189 CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); | |
190 BC_TYPE GetType() { return BC_EAN13; } | |
191 | |
192 private: | |
193 CFX_WideString Preprocess(const CFX_WideStringC& contents); | |
194 CFX_WideString m_renderContents; | |
195 }; | |
196 class CBC_UPCA : public CBC_OneCode { | |
197 public: | |
198 CBC_UPCA(); | |
199 virtual ~CBC_UPCA(); | |
200 FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); | |
201 FX_BOOL RenderDevice(CFX_RenderDevice* device, | |
202 const CFX_Matrix* matirx, | |
203 int32_t& e); | |
204 FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); | |
205 CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); | |
206 CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); | |
207 BC_TYPE GetType() { return BC_UPCA; } | |
208 | |
209 private: | |
210 CFX_WideString Preprocess(const CFX_WideStringC& contents); | |
211 CFX_WideString m_renderContents; | |
212 }; | |
213 class CBC_QRCode : public CBC_CodeBase { | |
214 public: | |
215 CBC_QRCode(); | |
216 virtual ~CBC_QRCode(); | |
217 FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); | |
218 FX_BOOL RenderDevice(CFX_RenderDevice* device, | |
219 const CFX_Matrix* matirx, | |
220 int32_t& e); | |
221 FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); | |
222 CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); | |
223 CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); | |
224 BC_TYPE GetType() { return BC_QR_CODE; } | |
225 FX_BOOL SetVersion(int32_t version); | |
226 FX_BOOL SetErrorCorrectionLevel(int32_t level); | |
227 }; | |
228 class CBC_PDF417I : public CBC_CodeBase { | |
229 public: | |
230 CBC_PDF417I(); | |
231 virtual ~CBC_PDF417I(); | |
232 FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); | |
233 FX_BOOL RenderDevice(CFX_RenderDevice* device, | |
234 const CFX_Matrix* matirx, | |
235 int32_t& e); | |
236 FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); | |
237 CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); | |
238 CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); | |
239 BC_TYPE GetType() { return BC_PDF417; } | |
240 FX_BOOL SetErrorCorrectionLevel(int32_t level); | |
241 void SetTruncated(FX_BOOL truncated); | |
242 }; | |
243 class CBC_DataMatrix : public CBC_CodeBase { | |
244 public: | |
245 CBC_DataMatrix(); | |
246 virtual ~CBC_DataMatrix(); | |
247 FX_BOOL Encode(const CFX_WideStringC& contents, FX_BOOL isDevice, int32_t& e); | |
248 FX_BOOL RenderDevice(CFX_RenderDevice* device, | |
249 const CFX_Matrix* matirx, | |
250 int32_t& e); | |
251 FX_BOOL RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e); | |
252 CFX_WideString Decode(uint8_t* buf, int32_t width, int32_t hight, int32_t& e); | |
253 CFX_WideString Decode(CFX_DIBitmap* pBitmap, int32_t& e); | |
254 BC_TYPE GetType() { return BC_DATAMATRIX; } | |
255 }; | |
256 | |
257 #endif // XFA_INCLUDE_FXBARCODE_BC_BARCODE_H_ | |
OLD | NEW |