Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp

Issue 2048983002: Get rid of NULLs in xfa/fxbarcode/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp ('k') | xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2009 ZXing authors 8 * Copyright 2009 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");
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 int32_t checksum = (odd * 3 + even) % 10; 75 int32_t checksum = (odd * 3 + even) % 10;
76 checksum = (10 - checksum) % 10; 76 checksum = (10 - checksum) % 10;
77 return (checksum); 77 return (checksum);
78 } 78 }
79 uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents, 79 uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents,
80 BCFORMAT format, 80 BCFORMAT format,
81 int32_t& outWidth, 81 int32_t& outWidth,
82 int32_t& outHeight, 82 int32_t& outHeight,
83 int32_t& e) { 83 int32_t& e) {
84 uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); 84 uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e);
85 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 85 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
86 return ret; 86 return ret;
87 } 87 }
88 uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents, 88 uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents,
89 BCFORMAT format, 89 BCFORMAT format,
90 int32_t& outWidth, 90 int32_t& outWidth,
91 int32_t& outHeight, 91 int32_t& outHeight,
92 int32_t hints, 92 int32_t hints,
93 int32_t& e) { 93 int32_t& e) {
94 if (format != BCFORMAT_EAN_13) { 94 if (format != BCFORMAT_EAN_13) {
95 e = BCExceptionOnlyEncodeEAN_13; 95 e = BCExceptionOnlyEncodeEAN_13;
96 } 96 }
97 uint8_t* ret = 97 uint8_t* ret =
98 CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e); 98 CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e);
99 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 99 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
100 return ret; 100 return ret;
101 } 101 }
102 uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents, 102 uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents,
103 int32_t& outLength, 103 int32_t& outLength,
104 int32_t& e) { 104 int32_t& e) {
105 if (contents.GetLength() != 13) { 105 if (contents.GetLength() != 13) {
106 e = BCExceptionDigitLengthShould13; 106 e = BCExceptionDigitLengthShould13;
107 return NULL; 107 return nullptr;
108 } 108 }
109 m_iDataLenth = 13; 109 m_iDataLenth = 13;
110 int32_t firstDigit = FXSYS_atoi(contents.Mid(0, 1).c_str()); 110 int32_t firstDigit = FXSYS_atoi(contents.Mid(0, 1).c_str());
111 int32_t parities = CBC_OnedEAN13Reader::FIRST_DIGIT_ENCODINGS[firstDigit]; 111 int32_t parities = CBC_OnedEAN13Reader::FIRST_DIGIT_ENCODINGS[firstDigit];
112 outLength = m_codeWidth; 112 outLength = m_codeWidth;
113 uint8_t* result = FX_Alloc(uint8_t, m_codeWidth); 113 uint8_t* result = FX_Alloc(uint8_t, m_codeWidth);
114 int32_t pos = 0; 114 int32_t pos = 0;
115 pos += 115 pos +=
116 AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e); 116 AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
117 if (e != BCExceptionNO) { 117 if (e != BCExceptionNO) {
118 FX_Free(result); 118 FX_Free(result);
119 return NULL; 119 return nullptr;
120 } 120 }
121 int32_t i = 0; 121 int32_t i = 0;
122 for (i = 1; i <= 6; i++) { 122 for (i = 1; i <= 6; i++) {
123 int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str()); 123 int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str());
124 if ((parities >> (6 - i) & 1) == 1) { 124 if ((parities >> (6 - i) & 1) == 1) {
125 digit += 10; 125 digit += 10;
126 } 126 }
127 pos += AppendPattern(result, pos, CBC_OneDimReader::L_AND_G_PATTERNS[digit], 127 pos += AppendPattern(result, pos, CBC_OneDimReader::L_AND_G_PATTERNS[digit],
128 4, 0, e); 128 4, 0, e);
129 if (e != BCExceptionNO) { 129 if (e != BCExceptionNO) {
130 FX_Free(result); 130 FX_Free(result);
131 return NULL; 131 return nullptr;
132 } 132 }
133 } 133 }
134 pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e); 134 pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e);
135 if (e != BCExceptionNO) { 135 if (e != BCExceptionNO) {
136 FX_Free(result); 136 FX_Free(result);
137 return NULL; 137 return nullptr;
138 } 138 }
139 for (i = 7; i <= 12; i++) { 139 for (i = 7; i <= 12; i++) {
140 int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str()); 140 int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str());
141 pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 1, 141 pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 1,
142 e); 142 e);
143 if (e != BCExceptionNO) { 143 if (e != BCExceptionNO) {
144 FX_Free(result); 144 FX_Free(result);
145 return NULL; 145 return nullptr;
146 } 146 }
147 } 147 }
148 pos += 148 pos +=
149 AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e); 149 AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
150 if (e != BCExceptionNO) { 150 if (e != BCExceptionNO) {
151 FX_Free(result); 151 FX_Free(result);
152 return NULL; 152 return nullptr;
153 } 153 }
154 return result; 154 return result;
155 } 155 }
156 156
157 void CBC_OnedEAN13Writer::ShowChars(const CFX_WideStringC& contents, 157 void CBC_OnedEAN13Writer::ShowChars(const CFX_WideStringC& contents,
158 CFX_DIBitmap* pOutBitmap, 158 CFX_DIBitmap* pOutBitmap,
159 CFX_RenderDevice* device, 159 CFX_RenderDevice* device,
160 const CFX_Matrix* matrix, 160 const CFX_Matrix* matrix,
161 int32_t barWidth, 161 int32_t barWidth,
162 int32_t multiple, 162 int32_t multiple,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 FX_Free(pCharPos); 294 FX_Free(pCharPos);
295 } 295 }
296 296
297 void CBC_OnedEAN13Writer::RenderResult(const CFX_WideStringC& contents, 297 void CBC_OnedEAN13Writer::RenderResult(const CFX_WideStringC& contents,
298 uint8_t* code, 298 uint8_t* code,
299 int32_t codeLength, 299 int32_t codeLength,
300 FX_BOOL isDevice, 300 FX_BOOL isDevice,
301 int32_t& e) { 301 int32_t& e) {
302 CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); 302 CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e);
303 } 303 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/oned/BC_OnedCode39Writer.cpp ('k') | xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698