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 2011 ZXing authors | 8 * Copyright 2011 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 { | 43 { |
44 if (m_output != NULL) { | 44 if (m_output != NULL) { |
45 delete m_output; | 45 delete m_output; |
46 m_output = NULL; | 46 m_output = NULL; |
47 } | 47 } |
48 } | 48 } |
49 void CBC_OneDimWriter::SetPrintChecksum(FX_BOOL checksum) | 49 void CBC_OneDimWriter::SetPrintChecksum(FX_BOOL checksum) |
50 { | 50 { |
51 m_bPrintChecksum = checksum; | 51 m_bPrintChecksum = checksum; |
52 } | 52 } |
53 void CBC_OneDimWriter::SetDataLength(FX_INT32 length) | 53 void CBC_OneDimWriter::SetDataLength(int32_t length) |
54 { | 54 { |
55 m_iDataLenth = length; | 55 m_iDataLenth = length; |
56 } | 56 } |
57 void CBC_OneDimWriter::SetCalcChecksum(FX_INT32 state) | 57 void CBC_OneDimWriter::SetCalcChecksum(int32_t state) |
58 { | 58 { |
59 m_bCalcChecksum = state; | 59 m_bCalcChecksum = state; |
60 } | 60 } |
61 FX_BOOL CBC_OneDimWriter::SetFont(CFX_Font * cFont) | 61 FX_BOOL CBC_OneDimWriter::SetFont(CFX_Font * cFont) |
62 { | 62 { |
63 if (cFont == NULL) { | 63 if (cFont == NULL) { |
64 return FALSE; | 64 return FALSE; |
65 } | 65 } |
66 m_pFont = cFont; | 66 m_pFont = cFont; |
67 return TRUE; | 67 return TRUE; |
68 } | 68 } |
69 void CBC_OneDimWriter::SetFontSize(FX_FLOAT size) | 69 void CBC_OneDimWriter::SetFontSize(FX_FLOAT size) |
70 { | 70 { |
71 m_fFontSize = size; | 71 m_fFontSize = size; |
72 } | 72 } |
73 void CBC_OneDimWriter::SetFontStyle(FX_INT32 style) | 73 void CBC_OneDimWriter::SetFontStyle(int32_t style) |
74 { | 74 { |
75 m_iFontStyle = style; | 75 m_iFontStyle = style; |
76 } | 76 } |
77 void CBC_OneDimWriter::SetFontColor(FX_ARGB color) | 77 void CBC_OneDimWriter::SetFontColor(FX_ARGB color) |
78 { | 78 { |
79 m_fontColor = color; | 79 m_fontColor = color; |
80 } | 80 } |
81 FX_WCHAR CBC_OneDimWriter::Upper(FX_WCHAR ch) | 81 FX_WCHAR CBC_OneDimWriter::Upper(FX_WCHAR ch) |
82 { | 82 { |
83 if(ch >= 'a' && ch <= 'z') { | 83 if(ch >= 'a' && ch <= 'z') { |
84 ch = ch - ('a' - 'A'); | 84 ch = ch - ('a' - 'A'); |
85 } | 85 } |
86 return ch; | 86 return ch; |
87 } | 87 } |
88 FX_BYTE* CBC_OneDimWriter::Encode(const CFX_ByteString &contents, BCFORMAT forma
t, | 88 uint8_t* CBC_OneDimWriter::Encode(const CFX_ByteString &contents, BCFORMAT forma
t, |
89 FX_INT32 &outWidth, FX_INT32 &outHeight, FX_IN
T32 hints, FX_INT32 &e) | 89 int32_t &outWidth, int32_t &outHeight, int32_t
hints, int32_t &e) |
90 { | 90 { |
91 FX_BYTE *ret = NULL; | 91 uint8_t *ret = NULL; |
92 outHeight = 1; | 92 outHeight = 1; |
93 if (m_Width >= 20) { | 93 if (m_Width >= 20) { |
94 ret = Encode(contents, outWidth, e); | 94 ret = Encode(contents, outWidth, e); |
95 } else { | 95 } else { |
96 ret = Encode(contents, outWidth, e); | 96 ret = Encode(contents, outWidth, e); |
97 } | 97 } |
98 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 98 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
99 return ret; | 99 return ret; |
100 } | 100 } |
101 FX_BYTE *CBC_OneDimWriter::Encode(const CFX_ByteString &contents, BCFORMAT forma
t, | 101 uint8_t *CBC_OneDimWriter::Encode(const CFX_ByteString &contents, BCFORMAT forma
t, |
102 FX_INT32 &outWidth, FX_INT32 &outHeight, FX_IN
T32 &e) | 102 int32_t &outWidth, int32_t &outHeight, int32_t
&e) |
103 { | 103 { |
104 FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0, e); | 104 uint8_t *ret = Encode(contents, format, outWidth, outHeight, 0, e); |
105 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 105 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
106 return ret; | 106 return ret; |
107 } | 107 } |
108 FX_INT32 CBC_OneDimWriter::AppendPattern(FX_BYTE* target, FX_INT32 pos, const FX
_INT32* pattern , FX_INT32 patternLength, FX_INT32 startColor, FX_INT32 &e) | 108 int32_t CBC_OneDimWriter::AppendPattern(uint8_t* target, int32_t pos, const int3
2_t* pattern , int32_t patternLength, int32_t startColor, int32_t &e) |
109 { | 109 { |
110 if (startColor != 0 && startColor != 1) { | 110 if (startColor != 0 && startColor != 1) { |
111 e = BCExceptionValueMustBeEither0or1; | 111 e = BCExceptionValueMustBeEither0or1; |
112 return 0; | 112 return 0; |
113 } | 113 } |
114 FX_BYTE color = (FX_BYTE) startColor; | 114 uint8_t color = (uint8_t) startColor; |
115 FX_INT32 numAdded = 0; | 115 int32_t numAdded = 0; |
116 for (FX_INT32 i = 0; i < patternLength; i++) { | 116 for (int32_t i = 0; i < patternLength; i++) { |
117 for (FX_INT32 j = 0; j < pattern[i]; j++) { | 117 for (int32_t j = 0; j < pattern[i]; j++) { |
118 target[pos] = color; | 118 target[pos] = color; |
119 pos += 1; | 119 pos += 1; |
120 numAdded += 1; | 120 numAdded += 1; |
121 } | 121 } |
122 color ^= 1; | 122 color ^= 1; |
123 } | 123 } |
124 return numAdded; | 124 return numAdded; |
125 } | 125 } |
126 void CBC_OneDimWriter::CalcTextInfo(const CFX_ByteString &text, FXTEXT_CHARPOS *
charPos, CFX_Font *cFont, FX_FLOAT geWidth, FX_INT32 fontSize, FX_FLOAT &charsLe
n) | 126 void CBC_OneDimWriter::CalcTextInfo(const CFX_ByteString &text, FXTEXT_CHARPOS *
charPos, CFX_Font *cFont, FX_FLOAT geWidth, int32_t fontSize, FX_FLOAT &charsLen
) |
127 { | 127 { |
128 #ifdef FXFM_ENCODING_NONE | 128 #ifdef FXFM_ENCODING_NONE |
129 IFX_FontEncodingEx* encoding = FX_CreateFontEncodingEx(cFont); | 129 IFX_FontEncodingEx* encoding = FX_CreateFontEncodingEx(cFont); |
130 #else | 130 #else |
131 IFX_FontEncoding * encoding = FXGE_CreateUnicodeEncoding(cFont); | 131 IFX_FontEncoding * encoding = FXGE_CreateUnicodeEncoding(cFont); |
132 #endif | 132 #endif |
133 FX_INT32 length = text.GetLength(); | 133 int32_t length = text.GetLength(); |
134 FX_DWORD *pCharCode = FX_Alloc(FX_DWORD, text.GetLength()); | 134 FX_DWORD *pCharCode = FX_Alloc(FX_DWORD, text.GetLength()); |
135 FX_FLOAT charWidth = 0; | 135 FX_FLOAT charWidth = 0; |
136 for (FX_INT32 j = 0; j < text.GetLength(); j++) { | 136 for (int32_t j = 0; j < text.GetLength(); j++) { |
137 pCharCode[j] = encoding->CharCodeFromUnicode(text[j]); | 137 pCharCode[j] = encoding->CharCodeFromUnicode(text[j]); |
138 FX_INT32 glyp_code = encoding->GlyphFromCharCode(pCharCode[j]); | 138 int32_t glyp_code = encoding->GlyphFromCharCode(pCharCode[j]); |
139 FX_INT32 glyp_value = cFont->GetGlyphWidth(glyp_code); | 139 int32_t glyp_value = cFont->GetGlyphWidth(glyp_code); |
140 FX_FLOAT temp = (FX_FLOAT)((glyp_value) * fontSize / 1000.0); | 140 FX_FLOAT temp = (FX_FLOAT)((glyp_value) * fontSize / 1000.0); |
141 charWidth += temp; | 141 charWidth += temp; |
142 } | 142 } |
143 charsLen = charWidth; | 143 charsLen = charWidth; |
144 FX_FLOAT leftPositon = (FX_FLOAT)(geWidth - charsLen) / 2.0f; | 144 FX_FLOAT leftPositon = (FX_FLOAT)(geWidth - charsLen) / 2.0f; |
145 if (leftPositon < 0 && geWidth == 0) { | 145 if (leftPositon < 0 && geWidth == 0) { |
146 leftPositon = 0; | 146 leftPositon = 0; |
147 } | 147 } |
148 FX_FLOAT penX = 0.0; | 148 FX_FLOAT penX = 0.0; |
149 FX_FLOAT penY = (FX_FLOAT)FXSYS_abs(cFont->GetDescent()) * (FX_FLOAT)fontSiz
e / 1000.0f; | 149 FX_FLOAT penY = (FX_FLOAT)FXSYS_abs(cFont->GetDescent()) * (FX_FLOAT)fontSiz
e / 1000.0f; |
150 FX_FLOAT left = leftPositon; | 150 FX_FLOAT left = leftPositon; |
151 FX_FLOAT top = 0.0; | 151 FX_FLOAT top = 0.0; |
152 charPos[0].m_OriginX = penX + left; | 152 charPos[0].m_OriginX = penX + left; |
153 charPos[0].m_OriginY = penY + top; | 153 charPos[0].m_OriginY = penY + top; |
154 charPos[0].m_GlyphIndex = encoding->GlyphFromCharCode(pCharCode[0]); | 154 charPos[0].m_GlyphIndex = encoding->GlyphFromCharCode(pCharCode[0]); |
155 charPos[0].m_FontCharWidth = cFont->GetGlyphWidth(charPos[0].m_GlyphIndex); | 155 charPos[0].m_FontCharWidth = cFont->GetGlyphWidth(charPos[0].m_GlyphIndex); |
156 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 156 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
157 charPos[0].m_ExtGID = charPos[0].m_GlyphIndex; | 157 charPos[0].m_ExtGID = charPos[0].m_GlyphIndex; |
158 #endif | 158 #endif |
159 penX += (FX_FLOAT)(charPos[0].m_FontCharWidth) * (FX_FLOAT)fontSize / 1000.0
f; | 159 penX += (FX_FLOAT)(charPos[0].m_FontCharWidth) * (FX_FLOAT)fontSize / 1000.0
f; |
160 for (FX_INT32 i = 1; i < length; i++) { | 160 for (int32_t i = 1; i < length; i++) { |
161 charPos[i].m_OriginX = penX + left; | 161 charPos[i].m_OriginX = penX + left; |
162 charPos[i].m_OriginY = penY + top; | 162 charPos[i].m_OriginY = penY + top; |
163 charPos[i].m_GlyphIndex = encoding->GlyphFromCharCode(pCharCode[i]); | 163 charPos[i].m_GlyphIndex = encoding->GlyphFromCharCode(pCharCode[i]); |
164 charPos[i].m_FontCharWidth = cFont->GetGlyphWidth(charPos[i].m_GlyphInde
x); | 164 charPos[i].m_FontCharWidth = cFont->GetGlyphWidth(charPos[i].m_GlyphInde
x); |
165 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 165 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
166 charPos[i].m_ExtGID = charPos[i].m_GlyphIndex; | 166 charPos[i].m_ExtGID = charPos[i].m_GlyphIndex; |
167 #endif | 167 #endif |
168 penX += (FX_FLOAT)(charPos[i].m_FontCharWidth) * (FX_FLOAT)fontSize / 10
00.0f; | 168 penX += (FX_FLOAT)(charPos[i].m_FontCharWidth) * (FX_FLOAT)fontSize / 10
00.0f; |
169 } | 169 } |
170 FX_Free (pCharCode); | 170 FX_Free (pCharCode); |
171 delete encoding; | 171 delete encoding; |
172 encoding = NULL; | 172 encoding = NULL; |
173 } | 173 } |
174 void CBC_OneDimWriter::ShowDeviceChars(CFX_RenderDevice *device, const CFX_Matri
x* matrix, const CFX_ByteString str, FX_FLOAT geWidth, FXTEXT_CHARPOS* pCharPos,
FX_FLOAT locX, FX_FLOAT locY, FX_INT32 barWidth) | 174 void CBC_OneDimWriter::ShowDeviceChars(CFX_RenderDevice *device, const CFX_Matri
x* matrix, const CFX_ByteString str, FX_FLOAT geWidth, FXTEXT_CHARPOS* pCharPos,
FX_FLOAT locX, FX_FLOAT locY, int32_t barWidth) |
175 { | 175 { |
176 FX_INT32 iFontSize = (FX_INT32)fabs(m_fFontSize); | 176 int32_t iFontSize = (int32_t)fabs(m_fFontSize); |
177 FX_INT32 iTextHeight = iFontSize + 1; | 177 int32_t iTextHeight = iFontSize + 1; |
178 CFX_FloatRect rect((FX_FLOAT)locX, (FX_FLOAT)locY, (FX_FLOAT)(locX + geWidth
), (FX_FLOAT)(locY + iTextHeight)); | 178 CFX_FloatRect rect((FX_FLOAT)locX, (FX_FLOAT)locY, (FX_FLOAT)(locX + geWidth
), (FX_FLOAT)(locY + iTextHeight)); |
179 if (geWidth != m_Width) { | 179 if (geWidth != m_Width) { |
180 rect.right -= 1; | 180 rect.right -= 1; |
181 } | 181 } |
182 matrix->TransformRect(rect); | 182 matrix->TransformRect(rect); |
183 FX_RECT re = rect.GetOutterRect(); | 183 FX_RECT re = rect.GetOutterRect(); |
184 device->FillRect(&re, m_backgroundColor); | 184 device->FillRect(&re, m_backgroundColor); |
185 CFX_Matrix affine_matrix(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)locX, (FX_FLOAT)(loc
Y + iFontSize)); | 185 CFX_Matrix affine_matrix(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)locX, (FX_FLOAT)(loc
Y + iFontSize)); |
186 if (matrix != NULL) { | 186 if (matrix != NULL) { |
187 affine_matrix.Concat(*matrix); | 187 affine_matrix.Concat(*matrix); |
188 } | 188 } |
189 FX_BOOL ret = device->DrawNormalText(str.GetLength(), | 189 FX_BOOL ret = device->DrawNormalText(str.GetLength(), |
190 pCharPos, | 190 pCharPos, |
191 m_pFont, | 191 m_pFont, |
192 CFX_GEModule::Get()->GetFontCache(), | 192 CFX_GEModule::Get()->GetFontCache(), |
193 (FX_FLOAT)iFontSize, | 193 (FX_FLOAT)iFontSize, |
194 (CFX_AffineMatrix *) &affine_matrix, | 194 (CFX_AffineMatrix *) &affine_matrix, |
195 m_fontColor, FXTEXT_CLEARTYPE); | 195 m_fontColor, FXTEXT_CLEARTYPE); |
196 } | 196 } |
197 void CBC_OneDimWriter::ShowBitmapChars(CFX_DIBitmap *pOutBitmap, const CFX_ByteS
tring str, FX_FLOAT geWidth, FXTEXT_CHARPOS* pCharPos, FX_FLOAT locX, FX_FLOAT l
ocY, FX_INT32 barWidth) | 197 void CBC_OneDimWriter::ShowBitmapChars(CFX_DIBitmap *pOutBitmap, const CFX_ByteS
tring str, FX_FLOAT geWidth, FXTEXT_CHARPOS* pCharPos, FX_FLOAT locX, FX_FLOAT l
ocY, int32_t barWidth) |
198 { | 198 { |
199 FX_INT32 iFontSize = (FX_INT32)fabs(m_fFontSize); | 199 int32_t iFontSize = (int32_t)fabs(m_fFontSize); |
200 FX_INT32 iTextHeight = iFontSize + 1; | 200 int32_t iTextHeight = iFontSize + 1; |
201 CFX_FxgeDevice ge; | 201 CFX_FxgeDevice ge; |
202 ge.Create((int)geWidth, iTextHeight , m_colorSpace); | 202 ge.Create((int)geWidth, iTextHeight , m_colorSpace); |
203 FX_RECT geRect(0, 0, (int)geWidth, iTextHeight); | 203 FX_RECT geRect(0, 0, (int)geWidth, iTextHeight); |
204 ge.FillRect(&geRect, m_backgroundColor); | 204 ge.FillRect(&geRect, m_backgroundColor); |
205 CFX_AffineMatrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize
); | 205 CFX_AffineMatrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize
); |
206 FX_BOOL ret = ge.DrawNormalText(str.GetLength(), | 206 FX_BOOL ret = ge.DrawNormalText(str.GetLength(), |
207 pCharPos, | 207 pCharPos, |
208 m_pFont, | 208 m_pFont, |
209 CFX_GEModule::Get()->GetFontCache(), | 209 CFX_GEModule::Get()->GetFontCache(), |
210 (FX_FLOAT)iFontSize, | 210 (FX_FLOAT)iFontSize, |
211 (CFX_AffineMatrix *) &affine_matrix, | 211 (CFX_AffineMatrix *) &affine_matrix, |
212 m_fontColor, FXTEXT_CLEARTYPE); | 212 m_fontColor, FXTEXT_CLEARTYPE); |
213 CFX_FxgeDevice geBitmap; | 213 CFX_FxgeDevice geBitmap; |
214 geBitmap.Attach(pOutBitmap); | 214 geBitmap.Attach(pOutBitmap); |
215 geBitmap.SetDIBits(ge.GetBitmap(), (int)locX, (int)locY); | 215 geBitmap.SetDIBits(ge.GetBitmap(), (int)locX, (int)locY); |
216 } | 216 } |
217 void CBC_OneDimWriter::ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, CFX
_RenderDevice *device, const CFX_Matrix* matrix, FX_INT32 barWidth, FX_INT32 mul
tiple, FX_INT32 &e) | 217 void CBC_OneDimWriter::ShowChars(FX_WSTR contents, CFX_DIBitmap *pOutBitmap, CFX
_RenderDevice *device, const CFX_Matrix* matrix, int32_t barWidth, int32_t multi
ple, int32_t &e) |
218 { | 218 { |
219 if (device == NULL && pOutBitmap == NULL) { | 219 if (device == NULL && pOutBitmap == NULL) { |
220 e = BCExceptionIllegalArgument; | 220 e = BCExceptionIllegalArgument; |
221 return; | 221 return; |
222 } | 222 } |
223 if (m_pFont == NULL) { | 223 if (m_pFont == NULL) { |
224 e = BCExceptionNullPointer; | 224 e = BCExceptionNullPointer; |
225 return; | 225 return; |
226 } | 226 } |
227 CFX_ByteString str = FX_UTF8Encode(contents); | 227 CFX_ByteString str = FX_UTF8Encode(contents); |
228 FX_INT32 iLen = str.GetLength(); | 228 int32_t iLen = str.GetLength(); |
229 FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen); | 229 FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen); |
230 if (!pCharPos) { | 230 if (!pCharPos) { |
231 return; | 231 return; |
232 } | 232 } |
233 FXSYS_memset32(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen); | 233 FXSYS_memset32(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen); |
234 FX_FLOAT charsLen = 0; | 234 FX_FLOAT charsLen = 0; |
235 FX_FLOAT geWidth = 0; | 235 FX_FLOAT geWidth = 0; |
236 if ( m_locTextLoc == BC_TEXT_LOC_ABOVEEMBED || | 236 if ( m_locTextLoc == BC_TEXT_LOC_ABOVEEMBED || |
237 m_locTextLoc == BC_TEXT_LOC_BELOWEMBED ) { | 237 m_locTextLoc == BC_TEXT_LOC_BELOWEMBED ) { |
238 geWidth = 0; | 238 geWidth = 0; |
239 } else if ( m_locTextLoc == BC_TEXT_LOC_ABOVE || | 239 } else if ( m_locTextLoc == BC_TEXT_LOC_ABOVE || |
240 m_locTextLoc == BC_TEXT_LOC_BELOW ) { | 240 m_locTextLoc == BC_TEXT_LOC_BELOW ) { |
241 geWidth = (FX_FLOAT)barWidth; | 241 geWidth = (FX_FLOAT)barWidth; |
242 } | 242 } |
243 FX_INT32 iFontSize = (FX_INT32)fabs(m_fFontSize); | 243 int32_t iFontSize = (int32_t)fabs(m_fFontSize); |
244 FX_INT32 iTextHeight = iFontSize + 1; | 244 int32_t iTextHeight = iFontSize + 1; |
245 CalcTextInfo(str, pCharPos, m_pFont, geWidth, iFontSize, charsLen); | 245 CalcTextInfo(str, pCharPos, m_pFont, geWidth, iFontSize, charsLen); |
246 if (charsLen < 1) { | 246 if (charsLen < 1) { |
247 return; | 247 return; |
248 } | 248 } |
249 FX_INT32 locX = 0; | 249 int32_t locX = 0; |
250 FX_INT32 locY = 0; | 250 int32_t locY = 0; |
251 switch (m_locTextLoc) { | 251 switch (m_locTextLoc) { |
252 case BC_TEXT_LOC_ABOVEEMBED: | 252 case BC_TEXT_LOC_ABOVEEMBED: |
253 locX = (FX_INT32)(barWidth - charsLen) / 2; | 253 locX = (int32_t)(barWidth - charsLen) / 2; |
254 locY = 0; | 254 locY = 0; |
255 geWidth = charsLen; | 255 geWidth = charsLen; |
256 break; | 256 break; |
257 case BC_TEXT_LOC_ABOVE: | 257 case BC_TEXT_LOC_ABOVE: |
258 locX = 0; | 258 locX = 0; |
259 locY = 0; | 259 locY = 0; |
260 geWidth = (FX_FLOAT)barWidth; | 260 geWidth = (FX_FLOAT)barWidth; |
261 break; | 261 break; |
262 case BC_TEXT_LOC_BELOWEMBED: | 262 case BC_TEXT_LOC_BELOWEMBED: |
263 locX = (FX_INT32)(barWidth - charsLen) / 2; | 263 locX = (int32_t)(barWidth - charsLen) / 2; |
264 locY = m_Height - iTextHeight; | 264 locY = m_Height - iTextHeight; |
265 geWidth = charsLen; | 265 geWidth = charsLen; |
266 break; | 266 break; |
267 case BC_TEXT_LOC_BELOW: | 267 case BC_TEXT_LOC_BELOW: |
268 default: | 268 default: |
269 locX = 0; | 269 locX = 0; |
270 locY = m_Height - iTextHeight; | 270 locY = m_Height - iTextHeight; |
271 geWidth = (FX_FLOAT)barWidth; | 271 geWidth = (FX_FLOAT)barWidth; |
272 break; | 272 break; |
273 } | 273 } |
274 if (device != NULL) { | 274 if (device != NULL) { |
275 ShowDeviceChars(device, matrix, str, geWidth, pCharPos, (FX_FLOAT)locX,
(FX_FLOAT)locY, barWidth); | 275 ShowDeviceChars(device, matrix, str, geWidth, pCharPos, (FX_FLOAT)locX,
(FX_FLOAT)locY, barWidth); |
276 } else { | 276 } else { |
277 ShowBitmapChars(pOutBitmap, str, geWidth, pCharPos, (FX_FLOAT)locX, (FX_
FLOAT)locY, barWidth); | 277 ShowBitmapChars(pOutBitmap, str, geWidth, pCharPos, (FX_FLOAT)locX, (FX_
FLOAT)locY, barWidth); |
278 } | 278 } |
279 FX_Free(pCharPos); | 279 FX_Free(pCharPos); |
280 } | 280 } |
281 void CBC_OneDimWriter::RenderBitmapResult(CFX_DIBitmap *&pOutBitmap, FX_WSTR con
tents, FX_INT32 &e) | 281 void CBC_OneDimWriter::RenderBitmapResult(CFX_DIBitmap *&pOutBitmap, FX_WSTR con
tents, int32_t &e) |
282 { | 282 { |
283 if (m_output == NULL) { | 283 if (m_output == NULL) { |
284 BC_EXCEPTION_CHECK_ReturnVoid(e); | 284 BC_EXCEPTION_CHECK_ReturnVoid(e); |
285 } | 285 } |
286 pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight()); | 286 pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight()); |
287 pOutBitmap->Clear(m_backgroundColor); | 287 pOutBitmap->Clear(m_backgroundColor); |
288 if (!pOutBitmap) { | 288 if (!pOutBitmap) { |
289 e = BCExceptionFailToCreateBitmap; | 289 e = BCExceptionFailToCreateBitmap; |
290 return; | 290 return; |
291 } | 291 } |
292 for (FX_INT32 x = 0; x < m_output->GetWidth(); x++) { | 292 for (int32_t x = 0; x < m_output->GetWidth(); x++) { |
293 for (FX_INT32 y = 0; y < m_output->GetHeight(); y++) { | 293 for (int32_t y = 0; y < m_output->GetHeight(); y++) { |
294 if (m_output->Get(x, y)) { | 294 if (m_output->Get(x, y)) { |
295 pOutBitmap->SetPixel(x, y, m_barColor); | 295 pOutBitmap->SetPixel(x, y, m_barColor); |
296 } | 296 } |
297 } | 297 } |
298 } | 298 } |
299 FX_INT32 i = 0; | 299 int32_t i = 0; |
300 for (; i < contents.GetLength(); i++) | 300 for (; i < contents.GetLength(); i++) |
301 if (contents.GetAt(i) != ' ') { | 301 if (contents.GetAt(i) != ' ') { |
302 break; | 302 break; |
303 } | 303 } |
304 if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) { | 304 if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) { |
305 ShowChars(contents, pOutBitmap, NULL, NULL, m_barWidth, m_multiple, e); | 305 ShowChars(contents, pOutBitmap, NULL, NULL, m_barWidth, m_multiple, e); |
306 BC_EXCEPTION_CHECK_ReturnVoid(e); | 306 BC_EXCEPTION_CHECK_ReturnVoid(e); |
307 } | 307 } |
308 CFX_DIBitmap * pStretchBitmap = pOutBitmap->StretchTo(m_Width, m_Height); | 308 CFX_DIBitmap * pStretchBitmap = pOutBitmap->StretchTo(m_Width, m_Height); |
309 if (pOutBitmap) { | 309 if (pOutBitmap) { |
310 delete pOutBitmap; | 310 delete pOutBitmap; |
311 } | 311 } |
312 pOutBitmap = pStretchBitmap; | 312 pOutBitmap = pStretchBitmap; |
313 } | 313 } |
314 void CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device, const CFX_Ma
trix* matrix, FX_WSTR contents, FX_INT32 &e) | 314 void CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device, const CFX_Ma
trix* matrix, FX_WSTR contents, int32_t &e) |
315 { | 315 { |
316 if (m_output == NULL) { | 316 if (m_output == NULL) { |
317 BC_EXCEPTION_CHECK_ReturnVoid(e); | 317 BC_EXCEPTION_CHECK_ReturnVoid(e); |
318 } | 318 } |
319 CFX_GraphStateData stateData; | 319 CFX_GraphStateData stateData; |
320 CFX_PathData path; | 320 CFX_PathData path; |
321 path.AppendRect(0, 0, (FX_FLOAT)m_Width, (FX_FLOAT)m_Height); | 321 path.AppendRect(0, 0, (FX_FLOAT)m_Width, (FX_FLOAT)m_Height); |
322 device->DrawPath(&path, matrix, &stateData, m_backgroundColor, m_backgroundC
olor, FXFILL_ALTERNATE); | 322 device->DrawPath(&path, matrix, &stateData, m_backgroundColor, m_backgroundC
olor, FXFILL_ALTERNATE); |
323 CFX_Matrix matri(m_outputHScale, 0.0, 0.0, (FX_FLOAT)m_Height, 0.0, 0.0); | 323 CFX_Matrix matri(m_outputHScale, 0.0, 0.0, (FX_FLOAT)m_Height, 0.0, 0.0); |
324 matri.Concat(*matrix); | 324 matri.Concat(*matrix); |
325 for (FX_INT32 x = 0; x < m_output->GetWidth(); x++) { | 325 for (int32_t x = 0; x < m_output->GetWidth(); x++) { |
326 for (FX_INT32 y = 0; y < m_output->GetHeight(); y++) { | 326 for (int32_t y = 0; y < m_output->GetHeight(); y++) { |
327 CFX_PathData rect; | 327 CFX_PathData rect; |
328 rect.AppendRect((FX_FLOAT)x, (FX_FLOAT)y, (FX_FLOAT)(x + 1), (FX_FLO
AT)(y + 1)); | 328 rect.AppendRect((FX_FLOAT)x, (FX_FLOAT)y, (FX_FLOAT)(x + 1), (FX_FLO
AT)(y + 1)); |
329 CFX_GraphStateData stateData; | 329 CFX_GraphStateData stateData; |
330 if (m_output->Get(x, y)) { | 330 if (m_output->Get(x, y)) { |
331 device->DrawPath(&rect, &matri, &stateData, m_barColor, 0, FXFIL
L_WINDING); | 331 device->DrawPath(&rect, &matri, &stateData, m_barColor, 0, FXFIL
L_WINDING); |
332 } | 332 } |
333 } | 333 } |
334 } | 334 } |
335 FX_INT32 i = 0; | 335 int32_t i = 0; |
336 for (; i < contents.GetLength(); i++) | 336 for (; i < contents.GetLength(); i++) |
337 if (contents.GetAt(i) != ' ') { | 337 if (contents.GetAt(i) != ' ') { |
338 break; | 338 break; |
339 } | 339 } |
340 if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) { | 340 if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) { |
341 ShowChars(contents, NULL, device, matrix, m_barWidth, m_multiple, e); | 341 ShowChars(contents, NULL, device, matrix, m_barWidth, m_multiple, e); |
342 BC_EXCEPTION_CHECK_ReturnVoid(e); | 342 BC_EXCEPTION_CHECK_ReturnVoid(e); |
343 } | 343 } |
344 } | 344 } |
345 void CBC_OneDimWriter::RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT32 co
deLength, FX_BOOL isDevice, FX_INT32 &e) | 345 void CBC_OneDimWriter::RenderResult(FX_WSTR contents, uint8_t* code, int32_t cod
eLength, FX_BOOL isDevice, int32_t &e) |
346 { | 346 { |
347 if (codeLength < 1) { | 347 if (codeLength < 1) { |
348 BC_EXCEPTION_CHECK_ReturnVoid(e); | 348 BC_EXCEPTION_CHECK_ReturnVoid(e); |
349 } | 349 } |
350 if (m_ModuleHeight < 20.0) { | 350 if (m_ModuleHeight < 20.0) { |
351 m_ModuleHeight = 20; | 351 m_ModuleHeight = 20; |
352 } | 352 } |
353 FX_INT32 codeOldLength = codeLength; | 353 int32_t codeOldLength = codeLength; |
354 FX_INT32 leftPadding = 0; | 354 int32_t leftPadding = 0; |
355 FX_INT32 rightPadding = 0; | 355 int32_t rightPadding = 0; |
356 if (m_bLeftPadding) { | 356 if (m_bLeftPadding) { |
357 leftPadding = 7; | 357 leftPadding = 7; |
358 } | 358 } |
359 if (m_bRightPadding) { | 359 if (m_bRightPadding) { |
360 rightPadding = 7; | 360 rightPadding = 7; |
361 } | 361 } |
362 codeLength += leftPadding; | 362 codeLength += leftPadding; |
363 codeLength += rightPadding; | 363 codeLength += rightPadding; |
364 m_outputHScale = 1.0; | 364 m_outputHScale = 1.0; |
365 if (m_Width > 0) { | 365 if (m_Width > 0) { |
366 m_outputHScale = (FX_FLOAT)m_Width / (FX_FLOAT)codeLength; | 366 m_outputHScale = (FX_FLOAT)m_Width / (FX_FLOAT)codeLength; |
367 } | 367 } |
368 if (!isDevice) { | 368 if (!isDevice) { |
369 m_outputHScale = FX_MAX(m_outputHScale, m_ModuleWidth); | 369 m_outputHScale = FX_MAX(m_outputHScale, m_ModuleWidth); |
370 } | 370 } |
371 FX_FLOAT dataLengthScale = 1.0; | 371 FX_FLOAT dataLengthScale = 1.0; |
372 if (m_iDataLenth > 0 && contents.GetLength() != 0) { | 372 if (m_iDataLenth > 0 && contents.GetLength() != 0) { |
373 dataLengthScale = FX_FLOAT(contents.GetLength()) / FX_FLOAT(m_iDataLenth
); | 373 dataLengthScale = FX_FLOAT(contents.GetLength()) / FX_FLOAT(m_iDataLenth
); |
374 } | 374 } |
375 if (m_iDataLenth > 0 && contents.GetLength() == 0) { | 375 if (m_iDataLenth > 0 && contents.GetLength() == 0) { |
376 dataLengthScale = FX_FLOAT(1) / FX_FLOAT(m_iDataLenth); | 376 dataLengthScale = FX_FLOAT(1) / FX_FLOAT(m_iDataLenth); |
377 } | 377 } |
378 m_multiple = 1; | 378 m_multiple = 1; |
379 if (!isDevice) { | 379 if (!isDevice) { |
380 m_multiple = (FX_INT32)ceil(m_outputHScale * dataLengthScale); | 380 m_multiple = (int32_t)ceil(m_outputHScale * dataLengthScale); |
381 } | 381 } |
382 FX_INT32 outputHeight = 1; | 382 int32_t outputHeight = 1; |
383 if (!isDevice) { | 383 if (!isDevice) { |
384 if (m_Height == 0) { | 384 if (m_Height == 0) { |
385 outputHeight = FX_MAX(20, m_ModuleHeight); | 385 outputHeight = FX_MAX(20, m_ModuleHeight); |
386 } else { | 386 } else { |
387 outputHeight = m_Height; | 387 outputHeight = m_Height; |
388 } | 388 } |
389 } | 389 } |
390 FX_INT32 outputWidth = codeLength; | 390 int32_t outputWidth = codeLength; |
391 if (!isDevice) { | 391 if (!isDevice) { |
392 outputWidth = (FX_INT32)(codeLength * m_multiple / dataLengthScale); | 392 outputWidth = (int32_t)(codeLength * m_multiple / dataLengthScale); |
393 } | 393 } |
394 m_barWidth = m_Width; | 394 m_barWidth = m_Width; |
395 if (!isDevice) { | 395 if (!isDevice) { |
396 m_barWidth = codeLength * m_multiple; | 396 m_barWidth = codeLength * m_multiple; |
397 } | 397 } |
398 m_output = FX_NEW CBC_CommonBitMatrix; | 398 m_output = FX_NEW CBC_CommonBitMatrix; |
399 m_output->Init(outputWidth, outputHeight); | 399 m_output->Init(outputWidth, outputHeight); |
400 FX_INT32 outputX = leftPadding * m_multiple; | 400 int32_t outputX = leftPadding * m_multiple; |
401 for (FX_INT32 inputX = 0; inputX < codeOldLength; inputX++) { | 401 for (int32_t inputX = 0; inputX < codeOldLength; inputX++) { |
402 if (code[inputX] == 1) { | 402 if (code[inputX] == 1) { |
403 if (outputX >= outputWidth ) { | 403 if (outputX >= outputWidth ) { |
404 break; | 404 break; |
405 } | 405 } |
406 if (outputX + m_multiple > outputWidth && outputWidth - outputX > 0)
{ | 406 if (outputX + m_multiple > outputWidth && outputWidth - outputX > 0)
{ |
407 m_output->SetRegion(outputX, 0, outputWidth - outputX , outputHe
ight, e); | 407 m_output->SetRegion(outputX, 0, outputWidth - outputX , outputHe
ight, e); |
408 break; | 408 break; |
409 } | 409 } |
410 m_output->SetRegion(outputX, 0, m_multiple, outputHeight, e); | 410 m_output->SetRegion(outputX, 0, m_multiple, outputHeight, e); |
411 BC_EXCEPTION_CHECK_ReturnVoid(e); | 411 BC_EXCEPTION_CHECK_ReturnVoid(e); |
412 } | 412 } |
413 outputX += m_multiple; | 413 outputX += m_multiple; |
414 } | 414 } |
415 } | 415 } |
OLD | NEW |