1 // Copyright 2014 PDFium Authors. All rights reserved.
\r
2 // Use of this source code is governed by a BSD-style license that can be
\r
3 // found in the LICENSE file.
\r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
\r
8 #include "include/BC_Writer.h"
\r
9 #include "include/BC_OneDimWriter.h"
\r
10 #include "include/BC_OnedEAN13Writer.h"
\r
11 #include "include/BC_OnedUPCAWriter.h"
\r
12 CBC_OnedUPCAWriter::CBC_OnedUPCAWriter()
\r
15 m_bLeftPadding = TRUE;
\r
16 m_bRightPadding = TRUE;
\r
18 void CBC_OnedUPCAWriter::Init()
\r
20 m_subWriter = FX_NEW CBC_OnedEAN13Writer;
\r
22 CBC_OnedUPCAWriter::~CBC_OnedUPCAWriter()
\r
24 if(m_subWriter != NULL) {
\r
29 FX_BOOL CBC_OnedUPCAWriter::CheckContentValidity(FX_WSTR contents)
\r
32 for (i = 0; i < contents.GetLength(); i++) {
\r
33 if (contents.GetAt(i) >= '0' && contents.GetAt(i) <= '9') {
\r
41 CFX_WideString CBC_OnedUPCAWriter::FilterContents(FX_WSTR contents)
\r
43 CFX_WideString filtercontents;
\r
45 for (FX_INT32 i = 0; i < contents.GetLength(); i++) {
\r
46 ch = contents.GetAt(i);
\r
51 if (ch >= '0' && ch <= '9') {
\r
52 filtercontents += ch;
\r
55 return filtercontents;
\r
57 FX_INT32 CBC_OnedUPCAWriter::CalcChecksum(const CFX_ByteString &contents)
\r
62 for(FX_INT32 i = contents.GetLength() - 1; i >= 0; i--) {
\r
64 odd += FXSYS_atoi(contents.Mid(i, 1));
\r
66 even += FXSYS_atoi(contents.Mid(i, 1));
\r
70 FX_INT32 checksum = (odd * 3 + even) % 10;
\r
71 checksum = (10 - checksum) % 10;
\r
74 FX_BYTE *CBC_OnedUPCAWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e)
\r
76 FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0, e);
\r
77 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
\r
80 FX_BYTE *CBC_OnedUPCAWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e)
\r
82 if (format != BCFORMAT_UPC_A) {
\r
83 e = BCExceptionOnlyEncodeUPC_A;
\r
86 CFX_ByteString toEAN13String = '0' + contents;
\r
88 FX_BYTE *ret = m_subWriter->Encode(toEAN13String, BCFORMAT_EAN_13, outWidth, outHeight, hints, e);
\r
89 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
\r
92 void CBC_OnedUPCAWriter::ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, CFX_RenderDevice* device, const CFX_Matrix* matrix, FX_INT32 barWidth, FX_INT32 multiple, FX_INT32 &e)
\r
94 if (device == NULL && pOutBitmap == NULL) {
\r
95 e = BCExceptionIllegalArgument;
\r
98 FX_INT32 leftPadding = 7 * multiple;
\r
99 FX_INT32 leftPosition = 10 * multiple + leftPadding;
\r
100 CFX_ByteString str = FX_UTF8Encode(contents);
\r
101 FX_INT32 iLen = str.GetLength();
\r
102 FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen);
\r
106 FXSYS_memset32(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen);
\r
107 CFX_ByteString tempStr = str.Mid(1, 5);
\r
108 FX_FLOAT strWidth = (FX_FLOAT)35 * multiple;
\r
109 FX_FLOAT blank = 0.0;
\r
110 CFX_FxgeDevice geBitmap;
\r
111 if (pOutBitmap != NULL) {
\r
112 geBitmap.Attach(pOutBitmap);
\r
114 FX_FLOAT charsWidth = 0;
\r
115 iLen = tempStr.GetLength();
\r
116 FX_INT32 iFontSize = (FX_INT32)fabs(m_fFontSize);
\r
117 FX_INT32 iTextHeight = iFontSize + 1;
\r
118 if (pOutBitmap == NULL) {
\r
119 CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
\r
120 CFX_FloatRect rect((FX_FLOAT)leftPosition, (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)(leftPosition + strWidth - 0.5), (FX_FLOAT)m_Height);
\r
121 matr.Concat(*matrix);
\r
122 matr.TransformRect(rect);
\r
123 FX_RECT re = rect.GetOutterRect();
\r
124 device->FillRect(&re, m_backgroundColor);
\r
125 CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
\r
126 CFX_FloatRect rect1((FX_FLOAT)(leftPosition + 40 * multiple), (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)((leftPosition + 40 * multiple) + strWidth - 0.5), (FX_FLOAT)m_Height);
\r
127 matr1.Concat(*matrix);
\r
128 matr1.TransformRect(rect1);
\r
129 re = rect1.GetOutterRect();
\r
130 device->FillRect(&re, m_backgroundColor);
\r
131 FX_FLOAT strWidth1 = (FX_FLOAT)multiple * 7;
\r
132 CFX_Matrix matr2(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
\r
133 CFX_FloatRect rect2(0.0, (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)strWidth1 - 1, (FX_FLOAT)m_Height);
\r
134 matr2.Concat(*matrix);
\r
135 matr2.TransformRect(rect2);
\r
136 re = rect2.GetOutterRect();
\r
137 device->FillRect(&re, m_backgroundColor);
\r
138 CFX_Matrix matr3(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
\r
139 CFX_FloatRect rect3((FX_FLOAT)(leftPosition + 85 * multiple), (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)((leftPosition + 85 * multiple) + strWidth1 - 0.5), (FX_FLOAT)m_Height);
\r
140 matr3.Concat(*matrix);
\r
141 matr3.TransformRect(rect3);
\r
142 re = rect3.GetOutterRect();
\r
143 device->FillRect(&re, m_backgroundColor);
\r
145 if (pOutBitmap == NULL) {
\r
146 strWidth = strWidth * m_outputHScale;
\r
148 CalcTextInfo(tempStr, pCharPos + 1, m_pFont, strWidth, iFontSize, blank);
\r
149 CFX_AffineMatrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize);
\r
151 if(pOutBitmap != NULL) {
\r
152 ge.Create((int)strWidth, iTextHeight, FXDIB_Argb);
\r
153 ge.GetBitmap()->Clear(m_backgroundColor);
\r
154 ge.DrawNormalText(iLen,
\r
157 CFX_GEModule::Get()->GetFontCache(),
\r
158 (FX_FLOAT)iFontSize ,
\r
159 (CFX_AffineMatrix *) &affine_matrix,
\r
160 m_fontColor, FXTEXT_CLEARTYPE);
\r
161 geBitmap.SetDIBits(ge.GetBitmap(), leftPosition, m_Height - iTextHeight);
\r
163 CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)leftPosition * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
\r
164 if (matrix != NULL) {
\r
165 affine_matrix1.Concat(*matrix);
\r
167 device->DrawNormalText(iLen,
\r
170 CFX_GEModule::Get()->GetFontCache(),
\r
171 (FX_FLOAT)iFontSize ,
\r
172 (CFX_AffineMatrix *) &affine_matrix1,
\r
173 m_fontColor, FXTEXT_CLEARTYPE);
\r
175 tempStr = str.Mid(6, 5);
\r
176 iLen = tempStr.GetLength();
\r
178 CalcTextInfo(tempStr, pCharPos + 6, m_pFont, strWidth, iFontSize, blank);
\r
179 if(pOutBitmap != NULL) {
\r
180 FX_RECT rect2(0, 0, (int)strWidth, iTextHeight);
\r
181 ge.FillRect(&rect2, m_backgroundColor);
\r
182 ge.DrawNormalText(iLen,
\r
185 CFX_GEModule::Get()->GetFontCache(),
\r
186 (FX_FLOAT)iFontSize ,
\r
187 (CFX_AffineMatrix *) &affine_matrix,
\r
188 m_fontColor, FXTEXT_CLEARTYPE);
\r
189 geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 40 * multiple, m_Height - iTextHeight);
\r
191 CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)(leftPosition + 40 * multiple) * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
\r
192 if (matrix != NULL) {
\r
193 affine_matrix1.Concat(*matrix);
\r
195 device->DrawNormalText(iLen,
\r
198 CFX_GEModule::Get()->GetFontCache(),
\r
199 (FX_FLOAT)iFontSize ,
\r
200 (CFX_AffineMatrix *) &affine_matrix1,
\r
201 m_fontColor, FXTEXT_CLEARTYPE);
\r
203 tempStr = str.Mid(0, 1);
\r
204 iLen = tempStr.GetLength();
\r
205 strWidth = (FX_FLOAT)multiple * 7;
\r
206 if (pOutBitmap == NULL) {
\r
207 strWidth = strWidth * m_outputHScale;
\r
209 CalcTextInfo(tempStr, pCharPos, m_pFont, strWidth, iFontSize, blank);
\r
210 if(pOutBitmap != NULL) {
\r
211 delete ge.GetBitmap();
\r
212 ge.Create((int)strWidth, iTextHeight, FXDIB_Argb);
\r
213 ge.GetBitmap()->Clear(m_backgroundColor);
\r
214 ge.DrawNormalText(iLen,
\r
217 CFX_GEModule::Get()->GetFontCache(),
\r
218 (FX_FLOAT)iFontSize ,
\r
219 (CFX_AffineMatrix *) &affine_matrix,
\r
220 m_fontColor, FXTEXT_CLEARTYPE);
\r
221 geBitmap.SetDIBits(ge.GetBitmap(), 0, m_Height - iTextHeight);
\r
223 CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
\r
224 if (matrix != NULL) {
\r
225 affine_matrix1.Concat(*matrix);
\r
227 device->DrawNormalText(iLen,
\r
230 CFX_GEModule::Get()->GetFontCache(),
\r
231 (FX_FLOAT)iFontSize ,
\r
232 (CFX_AffineMatrix *) &affine_matrix1,
\r
233 m_fontColor, FXTEXT_CLEARTYPE);
\r
235 tempStr = str.Mid(11, 1);
\r
236 iLen = tempStr.GetLength();
\r
237 CalcTextInfo(tempStr, pCharPos + 11, m_pFont, strWidth, iFontSize, blank);
\r
238 if (pOutBitmap != NULL) {
\r
239 delete ge.GetBitmap();
\r
240 ge.Create((int)strWidth, iTextHeight, FXDIB_Argb);
\r
241 ge.GetBitmap()->Clear(m_backgroundColor);
\r
242 ge.DrawNormalText(iLen,
\r
245 CFX_GEModule::Get()->GetFontCache(),
\r
246 (FX_FLOAT)iFontSize ,
\r
247 (CFX_AffineMatrix *) &affine_matrix,
\r
248 m_fontColor, FXTEXT_CLEARTYPE);
\r
249 geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 85 * multiple, m_Height - iTextHeight);
\r
251 CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)(leftPosition + 85 * multiple) * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
\r
252 if (matrix != NULL) {
\r
253 affine_matrix1.Concat(*matrix);
\r
255 device->DrawNormalText(iLen,
\r
258 CFX_GEModule::Get()->GetFontCache(),
\r
259 (FX_FLOAT)iFontSize ,
\r
260 (CFX_AffineMatrix *) &affine_matrix1,
\r
261 m_fontColor, FXTEXT_CLEARTYPE);
\r
265 void CBC_OnedUPCAWriter::RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 codeLength, FX_BOOL isDevice, FX_INT32 &e)
\r
267 CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e);
\r