OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 // Original code is licensed as follows: | 6 // Original code is licensed as follows: |
7 /* | 7 /* |
8 * Copyright 2010 ZXing authors | 8 * Copyright 2010 ZXing authors |
9 * | 9 * |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
11 * you may not use this file except in compliance with the License. | 11 * you may not use this file except in compliance with the License. |
12 * You may obtain a copy of the License at | 12 * You may obtain a copy of the License at |
13 * | 13 * |
14 * http://www.apache.org/licenses/LICENSE-2.0 | 14 * http://www.apache.org/licenses/LICENSE-2.0 |
15 * | 15 * |
16 * Unless required by applicable law or agreed to in writing, software | 16 * Unless required by applicable law or agreed to in writing, software |
17 * distributed under the License is distributed on an "AS IS" BASIS, | 17 * distributed under the License is distributed on an "AS IS" BASIS, |
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
19 * See the License for the specific language governing permissions and | 19 * See the License for the specific language governing permissions and |
20 * limitations under the License. | 20 * limitations under the License. |
21 */ | 21 */ |
22 | 22 |
23 #include "xfa/fxbarcode/BC_Writer.h" | 23 #include "xfa/fxbarcode/BC_Writer.h" |
24 #include "xfa/fxbarcode/oned/BC_OneDimWriter.h" | 24 #include "xfa/fxbarcode/oned/BC_OneDimWriter.h" |
25 #include "xfa/fxbarcode/oned/BC_OnedEAN13Writer.h" | 25 #include "xfa/fxbarcode/oned/BC_OnedEAN13Writer.h" |
26 #include "xfa/fxbarcode/oned/BC_OnedUPCAWriter.h" | 26 #include "xfa/fxbarcode/oned/BC_OnedUPCAWriter.h" |
27 | 27 |
28 CBC_OnedUPCAWriter::CBC_OnedUPCAWriter() { | 28 CBC_OnedUPCAWriter::CBC_OnedUPCAWriter() { |
29 m_subWriter = NULL; | 29 m_subWriter = nullptr; |
30 m_bLeftPadding = TRUE; | 30 m_bLeftPadding = TRUE; |
31 m_bRightPadding = TRUE; | 31 m_bRightPadding = TRUE; |
32 } | 32 } |
33 void CBC_OnedUPCAWriter::Init() { | 33 void CBC_OnedUPCAWriter::Init() { |
34 m_subWriter = new CBC_OnedEAN13Writer; | 34 m_subWriter = new CBC_OnedEAN13Writer; |
35 } | 35 } |
36 CBC_OnedUPCAWriter::~CBC_OnedUPCAWriter() { | 36 CBC_OnedUPCAWriter::~CBC_OnedUPCAWriter() { |
37 delete m_subWriter; | 37 delete m_subWriter; |
38 } | 38 } |
39 | 39 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 int32_t checksum = (odd * 3 + even) % 10; | 77 int32_t checksum = (odd * 3 + even) % 10; |
78 checksum = (10 - checksum) % 10; | 78 checksum = (10 - checksum) % 10; |
79 return (checksum); | 79 return (checksum); |
80 } | 80 } |
81 uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, | 81 uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, |
82 BCFORMAT format, | 82 BCFORMAT format, |
83 int32_t& outWidth, | 83 int32_t& outWidth, |
84 int32_t& outHeight, | 84 int32_t& outHeight, |
85 int32_t& e) { | 85 int32_t& e) { |
86 uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); | 86 uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); |
87 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 87 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
88 return ret; | 88 return ret; |
89 } | 89 } |
90 uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, | 90 uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, |
91 BCFORMAT format, | 91 BCFORMAT format, |
92 int32_t& outWidth, | 92 int32_t& outWidth, |
93 int32_t& outHeight, | 93 int32_t& outHeight, |
94 int32_t hints, | 94 int32_t hints, |
95 int32_t& e) { | 95 int32_t& e) { |
96 if (format != BCFORMAT_UPC_A) { | 96 if (format != BCFORMAT_UPC_A) { |
97 e = BCExceptionOnlyEncodeUPC_A; | 97 e = BCExceptionOnlyEncodeUPC_A; |
98 return NULL; | 98 return nullptr; |
99 } | 99 } |
100 CFX_ByteString toEAN13String = '0' + contents; | 100 CFX_ByteString toEAN13String = '0' + contents; |
101 m_iDataLenth = 13; | 101 m_iDataLenth = 13; |
102 uint8_t* ret = m_subWriter->Encode(toEAN13String, BCFORMAT_EAN_13, outWidth, | 102 uint8_t* ret = m_subWriter->Encode(toEAN13String, BCFORMAT_EAN_13, outWidth, |
103 outHeight, hints, e); | 103 outHeight, hints, e); |
104 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 104 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
105 return ret; | 105 return ret; |
106 } | 106 } |
107 | 107 |
108 void CBC_OnedUPCAWriter::ShowChars(const CFX_WideStringC& contents, | 108 void CBC_OnedUPCAWriter::ShowChars(const CFX_WideStringC& contents, |
109 CFX_DIBitmap* pOutBitmap, | 109 CFX_DIBitmap* pOutBitmap, |
110 CFX_RenderDevice* device, | 110 CFX_RenderDevice* device, |
111 const CFX_Matrix* matrix, | 111 const CFX_Matrix* matrix, |
112 int32_t barWidth, | 112 int32_t barWidth, |
113 int32_t multiple, | 113 int32_t multiple, |
114 int32_t& e) { | 114 int32_t& e) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 CFX_FloatRect rect3( | 164 CFX_FloatRect rect3( |
165 (FX_FLOAT)(leftPosition + 85 * multiple), | 165 (FX_FLOAT)(leftPosition + 85 * multiple), |
166 (FX_FLOAT)(m_Height - iTextHeight), | 166 (FX_FLOAT)(m_Height - iTextHeight), |
167 (FX_FLOAT)((leftPosition + 85 * multiple) + strWidth1 - 0.5), | 167 (FX_FLOAT)((leftPosition + 85 * multiple) + strWidth1 - 0.5), |
168 (FX_FLOAT)m_Height); | 168 (FX_FLOAT)m_Height); |
169 matr3.Concat(*matrix); | 169 matr3.Concat(*matrix); |
170 matr3.TransformRect(rect3); | 170 matr3.TransformRect(rect3); |
171 re = rect3.GetOutterRect(); | 171 re = rect3.GetOutterRect(); |
172 device->FillRect(&re, m_backgroundColor); | 172 device->FillRect(&re, m_backgroundColor); |
173 } | 173 } |
174 if (pOutBitmap == NULL) { | 174 if (!pOutBitmap) |
175 strWidth = strWidth * m_outputHScale; | 175 strWidth = strWidth * m_outputHScale; |
176 } | 176 |
177 CalcTextInfo(tempStr, pCharPos + 1, m_pFont, strWidth, iFontSize, blank); | 177 CalcTextInfo(tempStr, pCharPos + 1, m_pFont, strWidth, iFontSize, blank); |
178 CFX_Matrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize); | 178 CFX_Matrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize); |
179 CFX_FxgeDevice ge; | 179 CFX_FxgeDevice ge; |
180 if (pOutBitmap) { | 180 if (pOutBitmap) { |
181 ge.Create((int)strWidth, iTextHeight, FXDIB_Argb, nullptr); | 181 ge.Create((int)strWidth, iTextHeight, FXDIB_Argb, nullptr); |
182 ge.GetBitmap()->Clear(m_backgroundColor); | 182 ge.GetBitmap()->Clear(m_backgroundColor); |
183 ge.DrawNormalText(iLen, pCharPos + 1, m_pFont, | 183 ge.DrawNormalText(iLen, pCharPos + 1, m_pFont, |
184 CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize, | 184 CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize, |
185 (CFX_Matrix*)&affine_matrix, m_fontColor, | 185 (CFX_Matrix*)&affine_matrix, m_fontColor, |
186 FXTEXT_CLEARTYPE); | 186 FXTEXT_CLEARTYPE); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 affine_matrix1.Concat(*matrix); | 218 affine_matrix1.Concat(*matrix); |
219 } | 219 } |
220 device->DrawNormalText(iLen, pCharPos + 6, m_pFont, | 220 device->DrawNormalText(iLen, pCharPos + 6, m_pFont, |
221 CFX_GEModule::Get()->GetFontCache(), | 221 CFX_GEModule::Get()->GetFontCache(), |
222 (FX_FLOAT)iFontSize, (CFX_Matrix*)&affine_matrix1, | 222 (FX_FLOAT)iFontSize, (CFX_Matrix*)&affine_matrix1, |
223 m_fontColor, FXTEXT_CLEARTYPE); | 223 m_fontColor, FXTEXT_CLEARTYPE); |
224 } | 224 } |
225 tempStr = str.Mid(0, 1); | 225 tempStr = str.Mid(0, 1); |
226 iLen = tempStr.GetLength(); | 226 iLen = tempStr.GetLength(); |
227 strWidth = (FX_FLOAT)multiple * 7; | 227 strWidth = (FX_FLOAT)multiple * 7; |
228 if (pOutBitmap == NULL) { | 228 if (!pOutBitmap) |
229 strWidth = strWidth * m_outputHScale; | 229 strWidth = strWidth * m_outputHScale; |
230 } | 230 |
231 CalcTextInfo(tempStr, pCharPos, m_pFont, strWidth, iFontSize, blank); | 231 CalcTextInfo(tempStr, pCharPos, m_pFont, strWidth, iFontSize, blank); |
232 if (pOutBitmap) { | 232 if (pOutBitmap) { |
233 delete ge.GetBitmap(); | 233 delete ge.GetBitmap(); |
234 ge.Create((int)strWidth, iTextHeight, FXDIB_Argb, nullptr); | 234 ge.Create((int)strWidth, iTextHeight, FXDIB_Argb, nullptr); |
235 ge.GetBitmap()->Clear(m_backgroundColor); | 235 ge.GetBitmap()->Clear(m_backgroundColor); |
236 ge.DrawNormalText(iLen, pCharPos, m_pFont, | 236 ge.DrawNormalText(iLen, pCharPos, m_pFont, |
237 CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize, | 237 CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize, |
238 (CFX_Matrix*)&affine_matrix, m_fontColor, | 238 (CFX_Matrix*)&affine_matrix, m_fontColor, |
239 FXTEXT_CLEARTYPE); | 239 FXTEXT_CLEARTYPE); |
240 geBitmap.SetDIBits(ge.GetBitmap(), 0, m_Height - iTextHeight); | 240 geBitmap.SetDIBits(ge.GetBitmap(), 0, m_Height - iTextHeight); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 FX_Free(pCharPos); | 278 FX_Free(pCharPos); |
279 } | 279 } |
280 | 280 |
281 void CBC_OnedUPCAWriter::RenderResult(const CFX_WideStringC& contents, | 281 void CBC_OnedUPCAWriter::RenderResult(const CFX_WideStringC& contents, |
282 uint8_t* code, | 282 uint8_t* code, |
283 int32_t codeLength, | 283 int32_t codeLength, |
284 FX_BOOL isDevice, | 284 FX_BOOL isDevice, |
285 int32_t& e) { | 285 int32_t& e) { |
286 CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); | 286 CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); |
287 } | 287 } |
OLD | NEW |