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 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 22 matching lines...) Expand all Loading... |
33 m_iDataLenth = 8; | 33 m_iDataLenth = 8; |
34 m_codeWidth = 3 + | 34 m_codeWidth = 3 + |
35 (7 * 4) + | 35 (7 * 4) + |
36 5 + | 36 5 + |
37 (7 * 4) + | 37 (7 * 4) + |
38 3; | 38 3; |
39 } | 39 } |
40 CBC_OnedEAN8Writer::~CBC_OnedEAN8Writer() | 40 CBC_OnedEAN8Writer::~CBC_OnedEAN8Writer() |
41 { | 41 { |
42 } | 42 } |
43 void CBC_OnedEAN8Writer::SetDataLength(FX_INT32 length) | 43 void CBC_OnedEAN8Writer::SetDataLength(int32_t length) |
44 { | 44 { |
45 m_iDataLenth = 8; | 45 m_iDataLenth = 8; |
46 } | 46 } |
47 FX_BOOL CBC_OnedEAN8Writer::SetTextLocation(BC_TEXT_LOC location) | 47 FX_BOOL CBC_OnedEAN8Writer::SetTextLocation(BC_TEXT_LOC location) |
48 { | 48 { |
49 if ( location == BC_TEXT_LOC_BELOWEMBED) { | 49 if ( location == BC_TEXT_LOC_BELOWEMBED) { |
50 m_locTextLoc = location; | 50 m_locTextLoc = location; |
51 return TRUE; | 51 return TRUE; |
52 } | 52 } |
53 return FALSE; | 53 return FALSE; |
54 } | 54 } |
55 FX_BOOL CBC_OnedEAN8Writer::CheckContentValidity(FX_WSTR contents) | 55 FX_BOOL CBC_OnedEAN8Writer::CheckContentValidity(FX_WSTR contents) |
56 { | 56 { |
57 for (FX_INT32 i = 0; i < contents.GetLength(); i++) { | 57 for (int32_t i = 0; i < contents.GetLength(); i++) { |
58 if (contents.GetAt(i) >= '0' && contents.GetAt(i) <= '9') { | 58 if (contents.GetAt(i) >= '0' && contents.GetAt(i) <= '9') { |
59 continue; | 59 continue; |
60 } else { | 60 } else { |
61 return FALSE; | 61 return FALSE; |
62 } | 62 } |
63 } | 63 } |
64 return TRUE; | 64 return TRUE; |
65 } | 65 } |
66 CFX_WideString CBC_OnedEAN8Writer::FilterContents(FX_WSTR contents) | 66 CFX_WideString CBC_OnedEAN8Writer::FilterContents(FX_WSTR contents) |
67 { | 67 { |
68 CFX_WideString filtercontents; | 68 CFX_WideString filtercontents; |
69 FX_WCHAR ch; | 69 FX_WCHAR ch; |
70 for (FX_INT32 i = 0; i < contents.GetLength(); i++) { | 70 for (int32_t i = 0; i < contents.GetLength(); i++) { |
71 ch = contents.GetAt(i); | 71 ch = contents.GetAt(i); |
72 if(ch > 175) { | 72 if(ch > 175) { |
73 i++; | 73 i++; |
74 continue; | 74 continue; |
75 } | 75 } |
76 if (ch >= '0' && ch <= '9') { | 76 if (ch >= '0' && ch <= '9') { |
77 filtercontents += ch; | 77 filtercontents += ch; |
78 } | 78 } |
79 } | 79 } |
80 return filtercontents; | 80 return filtercontents; |
81 } | 81 } |
82 FX_INT32 CBC_OnedEAN8Writer::CalcChecksum(const CFX_ByteString &contents) | 82 int32_t CBC_OnedEAN8Writer::CalcChecksum(const CFX_ByteString &contents) |
83 { | 83 { |
84 FX_INT32 odd = 0; | 84 int32_t odd = 0; |
85 FX_INT32 even = 0; | 85 int32_t even = 0; |
86 FX_INT32 j = 1; | 86 int32_t j = 1; |
87 for(FX_INT32 i = contents.GetLength() - 1; i >= 0; i--) { | 87 for(int32_t i = contents.GetLength() - 1; i >= 0; i--) { |
88 if(j % 2) { | 88 if(j % 2) { |
89 odd += FXSYS_atoi(contents.Mid(i, 1)); | 89 odd += FXSYS_atoi(contents.Mid(i, 1)); |
90 } else { | 90 } else { |
91 even += FXSYS_atoi(contents.Mid(i, 1)); | 91 even += FXSYS_atoi(contents.Mid(i, 1)); |
92 } | 92 } |
93 j++; | 93 j++; |
94 } | 94 } |
95 FX_INT32 checksum = (odd * 3 + even) % 10; | 95 int32_t checksum = (odd * 3 + even) % 10; |
96 checksum = (10 - checksum) % 10; | 96 checksum = (10 - checksum) % 10; |
97 return (checksum); | 97 return (checksum); |
98 } | 98 } |
99 FX_BYTE *CBC_OnedEAN8Writer::Encode(const CFX_ByteString &contents, BCFORMAT for
mat, FX_INT32 &outWidth, FX_INT32 &outHeight , FX_INT32 &e) | 99 uint8_t *CBC_OnedEAN8Writer::Encode(const CFX_ByteString &contents, BCFORMAT for
mat, int32_t &outWidth, int32_t &outHeight , int32_t &e) |
100 { | 100 { |
101 FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0, e); | 101 uint8_t *ret = Encode(contents, format, outWidth, outHeight, 0, e); |
102 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 102 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
103 return ret; | 103 return ret; |
104 } | 104 } |
105 FX_BYTE *CBC_OnedEAN8Writer::Encode(const CFX_ByteString &contents, BCFORMAT for
mat, | 105 uint8_t *CBC_OnedEAN8Writer::Encode(const CFX_ByteString &contents, BCFORMAT for
mat, |
106 FX_INT32 &outWidth, FX_INT32 &outHeight, FX_
INT32 hints , FX_INT32 &e) | 106 int32_t &outWidth, int32_t &outHeight, int32
_t hints , int32_t &e) |
107 { | 107 { |
108 if (format != BCFORMAT_EAN_8) { | 108 if (format != BCFORMAT_EAN_8) { |
109 e = BCExceptionOnlyEncodeEAN_8; | 109 e = BCExceptionOnlyEncodeEAN_8; |
110 return NULL; | 110 return NULL; |
111 } | 111 } |
112 FX_BYTE *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeigh
t, hints, e); | 112 uint8_t *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeigh
t, hints, e); |
113 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 113 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
114 return ret; | 114 return ret; |
115 } | 115 } |
116 FX_BYTE *CBC_OnedEAN8Writer::Encode(const CFX_ByteString &contents, FX_INT32 &ou
tLength , FX_INT32 &e) | 116 uint8_t *CBC_OnedEAN8Writer::Encode(const CFX_ByteString &contents, int32_t &out
Length , int32_t &e) |
117 { | 117 { |
118 if (contents.GetLength() != 8) { | 118 if (contents.GetLength() != 8) { |
119 e = BCExceptionDigitLengthMustBe8; | 119 e = BCExceptionDigitLengthMustBe8; |
120 return NULL; | 120 return NULL; |
121 } | 121 } |
122 outLength = m_codeWidth; | 122 outLength = m_codeWidth; |
123 FX_BYTE *result = FX_Alloc(FX_BYTE, m_codeWidth); | 123 uint8_t *result = FX_Alloc(uint8_t, m_codeWidth); |
124 FX_INT32 pos = 0; | 124 int32_t pos = 0; |
125 pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1,
e); | 125 pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1,
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 FX_INT32 i = 0; | 130 int32_t i = 0; |
131 for (i = 0; i <= 3; i++) { | 131 for (i = 0; i <= 3; i++) { |
132 FX_INT32 digit = FXSYS_atoi(contents.Mid(i, 1)); | 132 int32_t digit = FXSYS_atoi(contents.Mid(i, 1)); |
133 pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4
, 0, e); | 133 pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4
, 0, e); |
134 if (e != BCExceptionNO) { | 134 if (e != BCExceptionNO) { |
135 FX_Free (result); | 135 FX_Free (result); |
136 return NULL; | 136 return NULL; |
137 } | 137 } |
138 } | 138 } |
139 pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e)
; | 139 pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e)
; |
140 if (e != BCExceptionNO) { | 140 if (e != BCExceptionNO) { |
141 FX_Free (result); | 141 FX_Free (result); |
142 return NULL; | 142 return NULL; |
143 } | 143 } |
144 for (i = 4; i <= 7; i++) { | 144 for (i = 4; i <= 7; i++) { |
145 FX_INT32 digit = FXSYS_atoi(contents.Mid(i, 1)); | 145 int32_t digit = FXSYS_atoi(contents.Mid(i, 1)); |
146 pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4
, 1, e); | 146 pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4
, 1, e); |
147 if (e != BCExceptionNO) { | 147 if (e != BCExceptionNO) { |
148 FX_Free (result); | 148 FX_Free (result); |
149 return NULL; | 149 return NULL; |
150 } | 150 } |
151 } | 151 } |
152 pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1,
e); | 152 pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1,
e); |
153 if (e != BCExceptionNO) { | 153 if (e != BCExceptionNO) { |
154 FX_Free (result); | 154 FX_Free (result); |
155 return NULL; | 155 return NULL; |
156 } | 156 } |
157 return result; | 157 return result; |
158 } | 158 } |
159 void CBC_OnedEAN8Writer::ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, C
FX_RenderDevice* device, const CFX_Matrix* matrix, FX_INT32 barWidth, FX_INT32 m
ultiple, FX_INT32 &e) | 159 void CBC_OnedEAN8Writer::ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, C
FX_RenderDevice* device, const CFX_Matrix* matrix, int32_t barWidth, int32_t mul
tiple, int32_t &e) |
160 { | 160 { |
161 if (device == NULL && pOutBitmap == NULL) { | 161 if (device == NULL && pOutBitmap == NULL) { |
162 e = BCExceptionIllegalArgument; | 162 e = BCExceptionIllegalArgument; |
163 return; | 163 return; |
164 } | 164 } |
165 FX_INT32 leftPosition = 3 * multiple; | 165 int32_t leftPosition = 3 * multiple; |
166 CFX_ByteString str = FX_UTF8Encode(contents); | 166 CFX_ByteString str = FX_UTF8Encode(contents); |
167 FX_INT32 iLength = str.GetLength(); | 167 int32_t iLength = str.GetLength(); |
168 FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLength); | 168 FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLength); |
169 if (!pCharPos) { | 169 if (!pCharPos) { |
170 return; | 170 return; |
171 } | 171 } |
172 FXSYS_memset32(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLength); | 172 FXSYS_memset32(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLength); |
173 CFX_ByteString tempStr = str.Mid(0, 4); | 173 CFX_ByteString tempStr = str.Mid(0, 4); |
174 FX_INT32 iLen = tempStr.GetLength(); | 174 int32_t iLen = tempStr.GetLength(); |
175 FX_INT32 strWidth = 7 * multiple * 4; | 175 int32_t strWidth = 7 * multiple * 4; |
176 FX_FLOAT blank = 0.0; | 176 FX_FLOAT blank = 0.0; |
177 CFX_FxgeDevice geBitmap; | 177 CFX_FxgeDevice geBitmap; |
178 if (pOutBitmap != NULL) { | 178 if (pOutBitmap != NULL) { |
179 geBitmap.Attach(pOutBitmap); | 179 geBitmap.Attach(pOutBitmap); |
180 } | 180 } |
181 FX_FLOAT charsWidth = 0; | 181 FX_FLOAT charsWidth = 0; |
182 FX_INT32 iFontSize = (FX_INT32)fabs(m_fFontSize); | 182 int32_t iFontSize = (int32_t)fabs(m_fFontSize); |
183 FX_INT32 iTextHeight = iFontSize + 1; | 183 int32_t iTextHeight = iFontSize + 1; |
184 if (pOutBitmap == NULL) { | 184 if (pOutBitmap == NULL) { |
185 CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); | 185 CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); |
186 CFX_FloatRect rect((FX_FLOAT)leftPosition, (FX_FLOAT)(m_Height - iTextHe
ight), (FX_FLOAT)(leftPosition + strWidth - 0.5), (FX_FLOAT)m_Height); | 186 CFX_FloatRect rect((FX_FLOAT)leftPosition, (FX_FLOAT)(m_Height - iTextHe
ight), (FX_FLOAT)(leftPosition + strWidth - 0.5), (FX_FLOAT)m_Height); |
187 matr.Concat(*matrix); | 187 matr.Concat(*matrix); |
188 matr.TransformRect(rect); | 188 matr.TransformRect(rect); |
189 FX_RECT re = rect.GetOutterRect(); | 189 FX_RECT re = rect.GetOutterRect(); |
190 device->FillRect(&re, m_backgroundColor); | 190 device->FillRect(&re, m_backgroundColor); |
191 CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); | 191 CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0); |
192 CFX_FloatRect rect1((FX_FLOAT)(leftPosition + 33 * multiple), (FX_FLOAT)
(m_Height - iTextHeight), (FX_FLOAT)(leftPosition + 33 * multiple + strWidth - 0
.5), (FX_FLOAT)m_Height); | 192 CFX_FloatRect rect1((FX_FLOAT)(leftPosition + 33 * multiple), (FX_FLOAT)
(m_Height - iTextHeight), (FX_FLOAT)(leftPosition + 33 * multiple + strWidth - 0
.5), (FX_FLOAT)m_Height); |
193 matr1.Concat(*matrix); | 193 matr1.Concat(*matrix); |
194 matr1.TransformRect(rect1); | 194 matr1.TransformRect(rect1); |
195 re = rect1.GetOutterRect(); | 195 re = rect1.GetOutterRect(); |
196 device->FillRect(&re, m_backgroundColor); | 196 device->FillRect(&re, m_backgroundColor); |
197 } | 197 } |
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, m_pFont, (FX_FLOAT)strWidth, iFontSize, blan
k); | 201 CalcTextInfo(tempStr, pCharPos, m_pFont, (FX_FLOAT)strWidth, iFontSize, blan
k); |
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 delete ge.GetBitmap(); | 205 delete ge.GetBitmap(); |
206 ge.Create(strWidth, iTextHeight, FXDIB_Argb); | 206 ge.Create(strWidth, iTextHeight, FXDIB_Argb); |
207 ge.GetBitmap()->Clear(m_backgroundColor); | 207 ge.GetBitmap()->Clear(m_backgroundColor); |
208 ge.DrawNormalText(iLen, | 208 ge.DrawNormalText(iLen, |
209 pCharPos, | 209 pCharPos, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 FX_BOOL ret = device->DrawNormalText(iLen, | 248 FX_BOOL ret = device->DrawNormalText(iLen, |
249 pCharPos + 4, | 249 pCharPos + 4, |
250 m_pFont, | 250 m_pFont, |
251 CFX_GEModule::Get()->GetFontCache()
, | 251 CFX_GEModule::Get()->GetFontCache()
, |
252 (FX_FLOAT)iFontSize , | 252 (FX_FLOAT)iFontSize , |
253 (CFX_AffineMatrix *) &affine_matrix
1, | 253 (CFX_AffineMatrix *) &affine_matrix
1, |
254 m_fontColor, FXTEXT_CLEARTYPE); | 254 m_fontColor, FXTEXT_CLEARTYPE); |
255 } | 255 } |
256 FX_Free(pCharPos); | 256 FX_Free(pCharPos); |
257 } | 257 } |
258 void CBC_OnedEAN8Writer::RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32
codeLength, FX_BOOL isDevice, FX_INT32 &e) | 258 void CBC_OnedEAN8Writer::RenderResult(FX_WSTR contents, uint8_t* code, int32_t c
odeLength, FX_BOOL isDevice, int32_t &e) |
259 { | 259 { |
260 CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); | 260 CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); |
261 } | 261 } |
OLD | NEW |