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

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

Issue 1172793002: Merge to XFA: Use stdint.h types throughout PDFium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 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/src/fxbarcode/oned/BC_OnedEAN13Writer.h ('k') | xfa/src/fxbarcode/oned/BC_OnedEAN8Reader.h » ('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 24 matching lines...) Expand all
35 (7 * 6) + 35 (7 * 6) +
36 5 + 36 5 +
37 (7 * 6) + 37 (7 * 6) +
38 3; 38 3;
39 } 39 }
40 CBC_OnedEAN13Writer::~CBC_OnedEAN13Writer() 40 CBC_OnedEAN13Writer::~CBC_OnedEAN13Writer()
41 { 41 {
42 } 42 }
43 FX_BOOL CBC_OnedEAN13Writer::CheckContentValidity(FX_WSTR contents) 43 FX_BOOL CBC_OnedEAN13Writer::CheckContentValidity(FX_WSTR contents)
44 { 44 {
45 for (FX_INT32 i = 0; i < contents.GetLength(); i++) { 45 for (int32_t i = 0; i < contents.GetLength(); i++) {
46 if (contents.GetAt(i) >= '0' && contents.GetAt(i) <= '9') { 46 if (contents.GetAt(i) >= '0' && contents.GetAt(i) <= '9') {
47 continue; 47 continue;
48 } else { 48 } else {
49 return FALSE; 49 return FALSE;
50 } 50 }
51 } 51 }
52 return TRUE; 52 return TRUE;
53 } 53 }
54 CFX_WideString CBC_OnedEAN13Writer::FilterContents(FX_WSTR contents) 54 CFX_WideString CBC_OnedEAN13Writer::FilterContents(FX_WSTR contents)
55 { 55 {
56 CFX_WideString filtercontents; 56 CFX_WideString filtercontents;
57 FX_WCHAR ch; 57 FX_WCHAR ch;
58 for (FX_INT32 i = 0; i < contents.GetLength(); i++) { 58 for (int32_t i = 0; i < contents.GetLength(); i++) {
59 ch = contents.GetAt(i); 59 ch = contents.GetAt(i);
60 if(ch > 175) { 60 if(ch > 175) {
61 i++; 61 i++;
62 continue; 62 continue;
63 } 63 }
64 if (ch >= '0' && ch <= '9') { 64 if (ch >= '0' && ch <= '9') {
65 filtercontents += ch; 65 filtercontents += ch;
66 } 66 }
67 } 67 }
68 return filtercontents; 68 return filtercontents;
69 } 69 }
70 FX_INT32 CBC_OnedEAN13Writer::CalcChecksum(const CFX_ByteString &contents) 70 int32_t CBC_OnedEAN13Writer::CalcChecksum(const CFX_ByteString &contents)
71 { 71 {
72 FX_INT32 odd = 0; 72 int32_t odd = 0;
73 FX_INT32 even = 0; 73 int32_t even = 0;
74 FX_INT32 j = 1; 74 int32_t j = 1;
75 for(FX_INT32 i = contents.GetLength() - 1; i >= 0; i--) { 75 for(int32_t i = contents.GetLength() - 1; i >= 0; i--) {
76 if(j % 2) { 76 if(j % 2) {
77 odd += FXSYS_atoi(contents.Mid(i, 1)); 77 odd += FXSYS_atoi(contents.Mid(i, 1));
78 } else { 78 } else {
79 even += FXSYS_atoi(contents.Mid(i, 1)); 79 even += FXSYS_atoi(contents.Mid(i, 1));
80 } 80 }
81 j++; 81 j++;
82 } 82 }
83 FX_INT32 checksum = (odd * 3 + even) % 10; 83 int32_t checksum = (odd * 3 + even) % 10;
84 checksum = (10 - checksum) % 10; 84 checksum = (10 - checksum) % 10;
85 return (checksum); 85 return (checksum);
86 } 86 }
87 FX_BYTE *CBC_OnedEAN13Writer::Encode(const CFX_ByteString &contents, BCFORMAT fo rmat, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e) 87 uint8_t *CBC_OnedEAN13Writer::Encode(const CFX_ByteString &contents, BCFORMAT fo rmat, int32_t &outWidth, int32_t &outHeight, int32_t &e)
88 { 88 {
89 FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0, e); 89 uint8_t *ret = Encode(contents, format, outWidth, outHeight, 0, e);
90 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 90 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
91 return ret; 91 return ret;
92 } 92 }
93 FX_BYTE *CBC_OnedEAN13Writer::Encode(const CFX_ByteString &contents, BCFORMAT fo rmat, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e) 93 uint8_t *CBC_OnedEAN13Writer::Encode(const CFX_ByteString &contents, BCFORMAT fo rmat, int32_t &outWidth, int32_t &outHeight, int32_t hints, int32_t &e)
94 { 94 {
95 if(format != BCFORMAT_EAN_13) { 95 if(format != BCFORMAT_EAN_13) {
96 e = BCExceptionOnlyEncodeEAN_13; 96 e = BCExceptionOnlyEncodeEAN_13;
97 } 97 }
98 FX_BYTE *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeigh t, hints, e); 98 uint8_t *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeigh t, hints, e);
99 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 99 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
100 return ret; 100 return ret;
101 } 101 }
102 FX_BYTE *CBC_OnedEAN13Writer::Encode(const CFX_ByteString &contents, FX_INT32 &o utLength, FX_INT32 &e) 102 uint8_t *CBC_OnedEAN13Writer::Encode(const CFX_ByteString &contents, int32_t &ou tLength, int32_t &e)
103 { 103 {
104 if (contents.GetLength() != 13) { 104 if (contents.GetLength() != 13) {
105 e = BCExceptionDigitLengthShould13; 105 e = BCExceptionDigitLengthShould13;
106 return NULL; 106 return NULL;
107 } 107 }
108 m_iDataLenth = 13; 108 m_iDataLenth = 13;
109 FX_INT32 firstDigit = FXSYS_atoi(contents.Mid(0, 1)); 109 int32_t firstDigit = FXSYS_atoi(contents.Mid(0, 1));
110 FX_INT32 parities = CBC_OnedEAN13Reader::FIRST_DIGIT_ENCODINGS[firstDigit]; 110 int32_t parities = CBC_OnedEAN13Reader::FIRST_DIGIT_ENCODINGS[firstDigit];
111 outLength = m_codeWidth; 111 outLength = m_codeWidth;
112 FX_BYTE *result = FX_Alloc(FX_BYTE, m_codeWidth); 112 uint8_t *result = FX_Alloc(uint8_t, m_codeWidth);
113 FX_INT32 pos = 0; 113 int32_t pos = 0;
114 pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e); 114 pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
115 if (e != BCExceptionNO) { 115 if (e != BCExceptionNO) {
116 FX_Free (result); 116 FX_Free (result);
117 return NULL; 117 return NULL;
118 } 118 }
119 FX_INT32 i = 0; 119 int32_t i = 0;
120 for ( i = 1; i <= 6; i++) { 120 for ( i = 1; i <= 6; i++) {
121 FX_INT32 digit = FXSYS_atoi(contents.Mid(i, 1)); 121 int32_t digit = FXSYS_atoi(contents.Mid(i, 1));
122 if ((parities >> (6 - i) & 1) == 1) { 122 if ((parities >> (6 - i) & 1) == 1) {
123 digit += 10; 123 digit += 10;
124 } 124 }
125 pos += AppendPattern(result, pos, CBC_OneDimReader::L_AND_G_PATTERNS[dig it], 4, 0, e); 125 pos += AppendPattern(result, pos, CBC_OneDimReader::L_AND_G_PATTERNS[dig it], 4, 0, e);
126 if (e != BCExceptionNO) { 126 if (e != BCExceptionNO) {
127 FX_Free (result); 127 FX_Free (result);
128 return NULL; 128 return NULL;
129 } 129 }
130 } 130 }
131 pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e) ; 131 pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e) ;
132 if (e != BCExceptionNO) { 132 if (e != BCExceptionNO) {
133 FX_Free (result); 133 FX_Free (result);
134 return NULL; 134 return NULL;
135 } 135 }
136 for (i = 7; i <= 12; i++) { 136 for (i = 7; i <= 12; i++) {
137 FX_INT32 digit = FXSYS_atoi(contents.Mid(i, 1)); 137 int32_t digit = FXSYS_atoi(contents.Mid(i, 1));
138 pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4 , 1, e); 138 pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4 , 1, e);
139 if (e != BCExceptionNO) { 139 if (e != BCExceptionNO) {
140 FX_Free (result); 140 FX_Free (result);
141 return NULL; 141 return NULL;
142 } 142 }
143 } 143 }
144 pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e); 144 pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
145 if (e != BCExceptionNO) { 145 if (e != BCExceptionNO) {
146 FX_Free (result); 146 FX_Free (result);
147 return NULL; 147 return NULL;
148 } 148 }
149 return result; 149 return result;
150 } 150 }
151 void CBC_OnedEAN13Writer::ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, CFX_RenderDevice* device, const CFX_Matrix* matrix, FX_INT32 barWidth, FX_INT32 multiple, FX_INT32 &e) 151 void CBC_OnedEAN13Writer::ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, CFX_RenderDevice* device, const CFX_Matrix* matrix, int32_t barWidth, int32_t mu ltiple, int32_t &e)
152 { 152 {
153 if (device == NULL && pOutBitmap == NULL) { 153 if (device == NULL && pOutBitmap == NULL) {
154 e = BCExceptionIllegalArgument; 154 e = BCExceptionIllegalArgument;
155 return; 155 return;
156 } 156 }
157 FX_INT32 leftPadding = 7 * multiple; 157 int32_t leftPadding = 7 * multiple;
158 FX_INT32 leftPosition = 3 * multiple + leftPadding; 158 int32_t leftPosition = 3 * multiple + leftPadding;
159 CFX_ByteString str = FX_UTF8Encode(contents); 159 CFX_ByteString str = FX_UTF8Encode(contents);
160 FX_INT32 iLen = str.GetLength(); 160 int32_t iLen = str.GetLength();
161 FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen); 161 FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen);
162 if (!pCharPos) { 162 if (!pCharPos) {
163 return; 163 return;
164 } 164 }
165 FXSYS_memset32(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen); 165 FXSYS_memset32(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen);
166 CFX_FxgeDevice geBitmap; 166 CFX_FxgeDevice geBitmap;
167 if (pOutBitmap != NULL) { 167 if (pOutBitmap != NULL) {
168 geBitmap.Attach(pOutBitmap); 168 geBitmap.Attach(pOutBitmap);
169 } 169 }
170 FX_INT32 iFontSize = (FX_INT32)fabs(m_fFontSize); 170 int32_t iFontSize = (int32_t)fabs(m_fFontSize);
171 FX_INT32 iTextHeight = iFontSize + 1; 171 int32_t iTextHeight = iFontSize + 1;
172 CFX_ByteString tempStr = str.Mid(1, 6); 172 CFX_ByteString tempStr = str.Mid(1, 6);
173 FX_INT32 strWidth = multiple * 42; 173 int32_t strWidth = multiple * 42;
174 if (pOutBitmap == NULL) { 174 if (pOutBitmap == NULL) {
175 CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); 175 CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
176 CFX_FloatRect rect((FX_FLOAT)leftPosition, (FX_FLOAT)(m_Height - iTextHe ight), (FX_FLOAT)(leftPosition + strWidth - 0.5), (FX_FLOAT)m_Height); 176 CFX_FloatRect rect((FX_FLOAT)leftPosition, (FX_FLOAT)(m_Height - iTextHe ight), (FX_FLOAT)(leftPosition + strWidth - 0.5), (FX_FLOAT)m_Height);
177 matr.Concat(*matrix); 177 matr.Concat(*matrix);
178 matr.TransformRect(rect); 178 matr.TransformRect(rect);
179 FX_RECT re = rect.GetOutterRect(); 179 FX_RECT re = rect.GetOutterRect();
180 device->FillRect(&re, m_backgroundColor); 180 device->FillRect(&re, m_backgroundColor);
181 CFX_FloatRect rect1((FX_FLOAT)(leftPosition + 47 * multiple), (FX_FLOAT) (m_Height - iTextHeight), (FX_FLOAT)(leftPosition + 47 * multiple + strWidth - 0 .5), (FX_FLOAT)m_Height); 181 CFX_FloatRect rect1((FX_FLOAT)(leftPosition + 47 * multiple), (FX_FLOAT) (m_Height - iTextHeight), (FX_FLOAT)(leftPosition + 47 * multiple + strWidth - 0 .5), (FX_FLOAT)m_Height);
182 CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); 182 CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
183 matr1.Concat(*matrix); 183 matr1.Concat(*matrix);
184 matr1.TransformRect(rect1); 184 matr1.TransformRect(rect1);
185 re = rect1.GetOutterRect(); 185 re = rect1.GetOutterRect();
186 device->FillRect(&re, m_backgroundColor); 186 device->FillRect(&re, m_backgroundColor);
187 FX_INT32 strWidth1 = multiple * 7; 187 int32_t strWidth1 = multiple * 7;
188 CFX_Matrix matr2(m_outputHScale, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f); 188 CFX_Matrix matr2(m_outputHScale, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
189 CFX_FloatRect rect2(0.0f, (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT) strWidth1 - 0.5f, (FX_FLOAT)m_Height); 189 CFX_FloatRect rect2(0.0f, (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT) strWidth1 - 0.5f, (FX_FLOAT)m_Height);
190 matr2.Concat(*matrix); 190 matr2.Concat(*matrix);
191 matr2.TransformRect(rect2); 191 matr2.TransformRect(rect2);
192 re = rect2.GetOutterRect(); 192 re = rect2.GetOutterRect();
193 device->FillRect(&re, m_backgroundColor); 193 device->FillRect(&re, m_backgroundColor);
194 } 194 }
195 FX_FLOAT blank = 0.0; 195 FX_FLOAT blank = 0.0;
196 FX_FLOAT charsWidth = 0; 196 FX_FLOAT charsWidth = 0;
197 iLen = tempStr.GetLength(); 197 iLen = tempStr.GetLength();
198 if (pOutBitmap == NULL) { 198 if (pOutBitmap == NULL) {
199 strWidth = (FX_INT32)(strWidth * m_outputHScale); 199 strWidth = (int32_t)(strWidth * m_outputHScale);
200 } 200 }
201 CalcTextInfo(tempStr, pCharPos + 1, m_pFont, (FX_FLOAT)strWidth, iFontSize, blank); 201 CalcTextInfo(tempStr, pCharPos + 1, m_pFont, (FX_FLOAT)strWidth, iFontSize, blank);
202 CFX_AffineMatrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize ); 202 CFX_AffineMatrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize );
203 CFX_FxgeDevice ge; 203 CFX_FxgeDevice ge;
204 if (pOutBitmap != NULL) { 204 if (pOutBitmap != NULL) {
205 ge.Create(strWidth, iTextHeight, FXDIB_Argb); 205 ge.Create(strWidth, iTextHeight, FXDIB_Argb);
206 FX_RECT rect(0, 0, strWidth, iTextHeight); 206 FX_RECT rect(0, 0, strWidth, iTextHeight);
207 ge.FillRect(&rect, m_backgroundColor); 207 ge.FillRect(&rect, m_backgroundColor);
208 ge.DrawNormalText(iLen, 208 ge.DrawNormalText(iLen,
209 pCharPos + 1, 209 pCharPos + 1,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 m_pFont, 251 m_pFont,
252 CFX_GEModule::Get()->GetFontCache(), 252 CFX_GEModule::Get()->GetFontCache(),
253 (FX_FLOAT)iFontSize , 253 (FX_FLOAT)iFontSize ,
254 (CFX_AffineMatrix *) &affine_matrix1, 254 (CFX_AffineMatrix *) &affine_matrix1,
255 m_fontColor, FXTEXT_CLEARTYPE); 255 m_fontColor, FXTEXT_CLEARTYPE);
256 } 256 }
257 tempStr = str.Mid(0, 1); 257 tempStr = str.Mid(0, 1);
258 iLen = tempStr.GetLength(); 258 iLen = tempStr.GetLength();
259 strWidth = multiple * 7; 259 strWidth = multiple * 7;
260 if (pOutBitmap == NULL) { 260 if (pOutBitmap == NULL) {
261 strWidth = (FX_INT32)(strWidth * m_outputHScale); 261 strWidth = (int32_t)(strWidth * m_outputHScale);
262 } 262 }
263 CalcTextInfo(tempStr, pCharPos, m_pFont, (FX_FLOAT)strWidth, iFontSize, blan k); 263 CalcTextInfo(tempStr, pCharPos, m_pFont, (FX_FLOAT)strWidth, iFontSize, blan k);
264 if(pOutBitmap != NULL) { 264 if(pOutBitmap != NULL) {
265 delete ge.GetBitmap(); 265 delete ge.GetBitmap();
266 ge.Create(strWidth, iTextHeight, FXDIB_Argb); 266 ge.Create(strWidth, iTextHeight, FXDIB_Argb);
267 ge.GetBitmap()->Clear(m_backgroundColor); 267 ge.GetBitmap()->Clear(m_backgroundColor);
268 ge.DrawNormalText(iLen, 268 ge.DrawNormalText(iLen,
269 pCharPos, 269 pCharPos,
270 m_pFont, 270 m_pFont,
271 CFX_GEModule::Get()->GetFontCache(), 271 CFX_GEModule::Get()->GetFontCache(),
272 (FX_FLOAT)iFontSize , 272 (FX_FLOAT)iFontSize ,
273 (CFX_AffineMatrix *) &affine_matrix, 273 (CFX_AffineMatrix *) &affine_matrix,
274 m_fontColor, FXTEXT_CLEARTYPE); 274 m_fontColor, FXTEXT_CLEARTYPE);
275 geBitmap.SetDIBits(ge.GetBitmap(), 0, m_Height - iTextHeight); 275 geBitmap.SetDIBits(ge.GetBitmap(), 0, m_Height - iTextHeight);
276 } else { 276 } else {
277 CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)(m_H eight - iTextHeight + iFontSize)); 277 CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)(m_H eight - iTextHeight + iFontSize));
278 if (matrix != NULL) { 278 if (matrix != NULL) {
279 affine_matrix1.Concat(*matrix); 279 affine_matrix1.Concat(*matrix);
280 } 280 }
281 device->DrawNormalText(iLen, 281 device->DrawNormalText(iLen,
282 pCharPos, 282 pCharPos,
283 m_pFont, 283 m_pFont,
284 CFX_GEModule::Get()->GetFontCache(), 284 CFX_GEModule::Get()->GetFontCache(),
285 (FX_FLOAT)iFontSize , 285 (FX_FLOAT)iFontSize ,
286 (CFX_AffineMatrix *) &affine_matrix1, 286 (CFX_AffineMatrix *) &affine_matrix1,
287 m_fontColor, FXTEXT_CLEARTYPE); 287 m_fontColor, FXTEXT_CLEARTYPE);
288 } 288 }
289 FX_Free(pCharPos); 289 FX_Free(pCharPos);
290 } 290 }
291 void CBC_OnedEAN13Writer::RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e) 291 void CBC_OnedEAN13Writer::RenderResult(FX_WSTR contents, uint8_t* code, int32_t codeLength, FX_BOOL isDevice, int32_t &e)
292 { 292 {
293 CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); 293 CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e);
294 } 294 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/oned/BC_OnedEAN13Writer.h ('k') | xfa/src/fxbarcode/oned/BC_OnedEAN8Reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698