| 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 15 matching lines...) Expand all Loading... |
| 26 #include <memory> | 26 #include <memory> |
| 27 | 27 |
| 28 #include "xfa/fxbarcode/BC_Writer.h" | 28 #include "xfa/fxbarcode/BC_Writer.h" |
| 29 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" | 29 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" |
| 30 | 30 |
| 31 CBC_OneDimWriter::CBC_OneDimWriter() { | 31 CBC_OneDimWriter::CBC_OneDimWriter() { |
| 32 m_locTextLoc = BC_TEXT_LOC_BELOWEMBED; | 32 m_locTextLoc = BC_TEXT_LOC_BELOWEMBED; |
| 33 m_bPrintChecksum = TRUE; | 33 m_bPrintChecksum = TRUE; |
| 34 m_iDataLenth = 0; | 34 m_iDataLenth = 0; |
| 35 m_bCalcChecksum = FALSE; | 35 m_bCalcChecksum = FALSE; |
| 36 m_pFont = NULL; | 36 m_pFont = nullptr; |
| 37 m_fFontSize = 10; | 37 m_fFontSize = 10; |
| 38 m_iFontStyle = 0; | 38 m_iFontStyle = 0; |
| 39 m_fontColor = 0xff000000; | 39 m_fontColor = 0xff000000; |
| 40 m_iContentLen = 0; | 40 m_iContentLen = 0; |
| 41 m_bLeftPadding = FALSE; | 41 m_bLeftPadding = FALSE; |
| 42 m_bRightPadding = FALSE; | 42 m_bRightPadding = FALSE; |
| 43 m_output = NULL; | 43 m_output = nullptr; |
| 44 } | 44 } |
| 45 CBC_OneDimWriter::~CBC_OneDimWriter() { | 45 CBC_OneDimWriter::~CBC_OneDimWriter() { |
| 46 delete m_output; | 46 delete m_output; |
| 47 } | 47 } |
| 48 void CBC_OneDimWriter::SetPrintChecksum(FX_BOOL checksum) { | 48 void CBC_OneDimWriter::SetPrintChecksum(FX_BOOL checksum) { |
| 49 m_bPrintChecksum = checksum; | 49 m_bPrintChecksum = checksum; |
| 50 } | 50 } |
| 51 void CBC_OneDimWriter::SetDataLength(int32_t length) { | 51 void CBC_OneDimWriter::SetDataLength(int32_t length) { |
| 52 m_iDataLenth = length; | 52 m_iDataLenth = length; |
| 53 } | 53 } |
| 54 void CBC_OneDimWriter::SetCalcChecksum(int32_t state) { | 54 void CBC_OneDimWriter::SetCalcChecksum(int32_t state) { |
| 55 m_bCalcChecksum = state; | 55 m_bCalcChecksum = state; |
| 56 } | 56 } |
| 57 FX_BOOL CBC_OneDimWriter::SetFont(CFX_Font* cFont) { | 57 FX_BOOL CBC_OneDimWriter::SetFont(CFX_Font* cFont) { |
| 58 if (cFont == NULL) { | 58 if (!cFont) |
| 59 return FALSE; | 59 return FALSE; |
| 60 } | 60 |
| 61 m_pFont = cFont; | 61 m_pFont = cFont; |
| 62 return TRUE; | 62 return TRUE; |
| 63 } | 63 } |
| 64 void CBC_OneDimWriter::SetFontSize(FX_FLOAT size) { | 64 void CBC_OneDimWriter::SetFontSize(FX_FLOAT size) { |
| 65 m_fFontSize = size; | 65 m_fFontSize = size; |
| 66 } | 66 } |
| 67 void CBC_OneDimWriter::SetFontStyle(int32_t style) { | 67 void CBC_OneDimWriter::SetFontStyle(int32_t style) { |
| 68 m_iFontStyle = style; | 68 m_iFontStyle = style; |
| 69 } | 69 } |
| 70 void CBC_OneDimWriter::SetFontColor(FX_ARGB color) { | 70 void CBC_OneDimWriter::SetFontColor(FX_ARGB color) { |
| 71 m_fontColor = color; | 71 m_fontColor = color; |
| 72 } | 72 } |
| 73 FX_WCHAR CBC_OneDimWriter::Upper(FX_WCHAR ch) { | 73 FX_WCHAR CBC_OneDimWriter::Upper(FX_WCHAR ch) { |
| 74 if (ch >= 'a' && ch <= 'z') { | 74 if (ch >= 'a' && ch <= 'z') { |
| 75 ch = ch - ('a' - 'A'); | 75 ch = ch - ('a' - 'A'); |
| 76 } | 76 } |
| 77 return ch; | 77 return ch; |
| 78 } | 78 } |
| 79 uint8_t* CBC_OneDimWriter::Encode(const CFX_ByteString& contents, | 79 uint8_t* CBC_OneDimWriter::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 hints, | 83 int32_t hints, |
| 84 int32_t& e) { | 84 int32_t& e) { |
| 85 uint8_t* ret = NULL; | 85 uint8_t* ret = nullptr; |
| 86 outHeight = 1; | 86 outHeight = 1; |
| 87 if (m_Width >= 20) { | 87 if (m_Width >= 20) { |
| 88 ret = Encode(contents, outWidth, e); | 88 ret = Encode(contents, outWidth, e); |
| 89 } else { | 89 } else { |
| 90 ret = Encode(contents, outWidth, e); | 90 ret = Encode(contents, outWidth, e); |
| 91 } | 91 } |
| 92 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 92 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 93 return ret; | 93 return ret; |
| 94 } | 94 } |
| 95 uint8_t* CBC_OneDimWriter::Encode(const CFX_ByteString& contents, | 95 uint8_t* CBC_OneDimWriter::Encode(const CFX_ByteString& contents, |
| 96 BCFORMAT format, | 96 BCFORMAT format, |
| 97 int32_t& outWidth, | 97 int32_t& outWidth, |
| 98 int32_t& outHeight, | 98 int32_t& outHeight, |
| 99 int32_t& e) { | 99 int32_t& e) { |
| 100 uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); | 100 uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); |
| 101 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 101 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 102 return ret; | 102 return ret; |
| 103 } | 103 } |
| 104 int32_t CBC_OneDimWriter::AppendPattern(uint8_t* target, | 104 int32_t CBC_OneDimWriter::AppendPattern(uint8_t* target, |
| 105 int32_t pos, | 105 int32_t pos, |
| 106 const int32_t* pattern, | 106 const int32_t* pattern, |
| 107 int32_t patternLength, | 107 int32_t patternLength, |
| 108 int32_t startColor, | 108 int32_t startColor, |
| 109 int32_t& e) { | 109 int32_t& e) { |
| 110 if (startColor != 0 && startColor != 1) { | 110 if (startColor != 0 && startColor != 1) { |
| 111 e = BCExceptionValueMustBeEither0or1; | 111 e = BCExceptionValueMustBeEither0or1; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } else { | 289 } else { |
| 290 ShowBitmapChars(pOutBitmap, str, geWidth, pCharPos, (FX_FLOAT)locX, | 290 ShowBitmapChars(pOutBitmap, str, geWidth, pCharPos, (FX_FLOAT)locX, |
| 291 (FX_FLOAT)locY, barWidth); | 291 (FX_FLOAT)locY, barWidth); |
| 292 } | 292 } |
| 293 FX_Free(pCharPos); | 293 FX_Free(pCharPos); |
| 294 } | 294 } |
| 295 | 295 |
| 296 void CBC_OneDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap, | 296 void CBC_OneDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap, |
| 297 const CFX_WideStringC& contents, | 297 const CFX_WideStringC& contents, |
| 298 int32_t& e) { | 298 int32_t& e) { |
| 299 if (m_output == NULL) { | 299 if (!m_output) |
| 300 BC_EXCEPTION_CHECK_ReturnVoid(e); | 300 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 301 } | 301 |
| 302 pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight()); | 302 pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight()); |
| 303 pOutBitmap->Clear(m_backgroundColor); | 303 pOutBitmap->Clear(m_backgroundColor); |
| 304 if (!pOutBitmap) { | 304 if (!pOutBitmap) { |
| 305 e = BCExceptionFailToCreateBitmap; | 305 e = BCExceptionFailToCreateBitmap; |
| 306 return; | 306 return; |
| 307 } | 307 } |
| 308 for (int32_t x = 0; x < m_output->GetWidth(); x++) { | 308 for (int32_t x = 0; x < m_output->GetWidth(); x++) { |
| 309 for (int32_t y = 0; y < m_output->GetHeight(); y++) { | 309 for (int32_t y = 0; y < m_output->GetHeight(); y++) { |
| 310 if (m_output->Get(x, y)) { | 310 if (m_output->Get(x, y)) { |
| 311 pOutBitmap->SetPixel(x, y, m_barColor); | 311 pOutBitmap->SetPixel(x, y, m_barColor); |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 } | 314 } |
| 315 int32_t i = 0; | 315 int32_t i = 0; |
| 316 for (; i < contents.GetLength(); i++) | 316 for (; i < contents.GetLength(); i++) |
| 317 if (contents.GetAt(i) != ' ') { | 317 if (contents.GetAt(i) != ' ') { |
| 318 break; | 318 break; |
| 319 } | 319 } |
| 320 if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) { | 320 if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) { |
| 321 ShowChars(contents, pOutBitmap, NULL, NULL, m_barWidth, m_multiple, e); | 321 ShowChars(contents, pOutBitmap, nullptr, nullptr, m_barWidth, m_multiple, |
| 322 e); |
| 322 BC_EXCEPTION_CHECK_ReturnVoid(e); | 323 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 323 } | 324 } |
| 324 CFX_DIBitmap* pStretchBitmap = pOutBitmap->StretchTo(m_Width, m_Height); | 325 CFX_DIBitmap* pStretchBitmap = pOutBitmap->StretchTo(m_Width, m_Height); |
| 325 delete pOutBitmap; | 326 delete pOutBitmap; |
| 326 pOutBitmap = pStretchBitmap; | 327 pOutBitmap = pStretchBitmap; |
| 327 } | 328 } |
| 328 | 329 |
| 329 void CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device, | 330 void CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device, |
| 330 const CFX_Matrix* matrix, | 331 const CFX_Matrix* matrix, |
| 331 const CFX_WideStringC& contents, | 332 const CFX_WideStringC& contents, |
| 332 int32_t& e) { | 333 int32_t& e) { |
| 333 if (m_output == NULL) { | 334 if (!m_output) |
| 334 BC_EXCEPTION_CHECK_ReturnVoid(e); | 335 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 335 } | 336 |
| 336 CFX_GraphStateData stateData; | 337 CFX_GraphStateData stateData; |
| 337 CFX_PathData path; | 338 CFX_PathData path; |
| 338 path.AppendRect(0, 0, (FX_FLOAT)m_Width, (FX_FLOAT)m_Height); | 339 path.AppendRect(0, 0, (FX_FLOAT)m_Width, (FX_FLOAT)m_Height); |
| 339 device->DrawPath(&path, matrix, &stateData, m_backgroundColor, | 340 device->DrawPath(&path, matrix, &stateData, m_backgroundColor, |
| 340 m_backgroundColor, FXFILL_ALTERNATE); | 341 m_backgroundColor, FXFILL_ALTERNATE); |
| 341 CFX_Matrix matri(m_outputHScale, 0.0, 0.0, (FX_FLOAT)m_Height, 0.0, 0.0); | 342 CFX_Matrix matri(m_outputHScale, 0.0, 0.0, (FX_FLOAT)m_Height, 0.0, 0.0); |
| 342 matri.Concat(*matrix); | 343 matri.Concat(*matrix); |
| 343 for (int32_t x = 0; x < m_output->GetWidth(); x++) { | 344 for (int32_t x = 0; x < m_output->GetWidth(); x++) { |
| 344 for (int32_t y = 0; y < m_output->GetHeight(); y++) { | 345 for (int32_t y = 0; y < m_output->GetHeight(); y++) { |
| 345 CFX_PathData rect; | 346 CFX_PathData rect; |
| 346 rect.AppendRect((FX_FLOAT)x, (FX_FLOAT)y, (FX_FLOAT)(x + 1), | 347 rect.AppendRect((FX_FLOAT)x, (FX_FLOAT)y, (FX_FLOAT)(x + 1), |
| 347 (FX_FLOAT)(y + 1)); | 348 (FX_FLOAT)(y + 1)); |
| 348 if (m_output->Get(x, y)) { | 349 if (m_output->Get(x, y)) { |
| 349 CFX_GraphStateData data; | 350 CFX_GraphStateData data; |
| 350 device->DrawPath(&rect, &matri, &data, m_barColor, 0, FXFILL_WINDING); | 351 device->DrawPath(&rect, &matri, &data, m_barColor, 0, FXFILL_WINDING); |
| 351 } | 352 } |
| 352 } | 353 } |
| 353 } | 354 } |
| 354 int32_t i = 0; | 355 int32_t i = 0; |
| 355 for (; i < contents.GetLength(); i++) | 356 for (; i < contents.GetLength(); i++) |
| 356 if (contents.GetAt(i) != ' ') { | 357 if (contents.GetAt(i) != ' ') { |
| 357 break; | 358 break; |
| 358 } | 359 } |
| 359 if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) { | 360 if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) { |
| 360 ShowChars(contents, NULL, device, matrix, m_barWidth, m_multiple, e); | 361 ShowChars(contents, nullptr, device, matrix, m_barWidth, m_multiple, e); |
| 361 BC_EXCEPTION_CHECK_ReturnVoid(e); | 362 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 362 } | 363 } |
| 363 } | 364 } |
| 364 void CBC_OneDimWriter::RenderResult(const CFX_WideStringC& contents, | 365 void CBC_OneDimWriter::RenderResult(const CFX_WideStringC& contents, |
| 365 uint8_t* code, | 366 uint8_t* code, |
| 366 int32_t codeLength, | 367 int32_t codeLength, |
| 367 FX_BOOL isDevice, | 368 FX_BOOL isDevice, |
| 368 int32_t& e) { | 369 int32_t& e) { |
| 369 if (codeLength < 1) { | 370 if (codeLength < 1) { |
| 370 BC_EXCEPTION_CHECK_ReturnVoid(e); | 371 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 if (outputX + m_multiple > outputWidth && outputWidth - outputX > 0) { | 430 if (outputX + m_multiple > outputWidth && outputWidth - outputX > 0) { |
| 430 m_output->SetRegion(outputX, 0, outputWidth - outputX, outputHeight, e); | 431 m_output->SetRegion(outputX, 0, outputWidth - outputX, outputHeight, e); |
| 431 break; | 432 break; |
| 432 } | 433 } |
| 433 m_output->SetRegion(outputX, 0, m_multiple, outputHeight, e); | 434 m_output->SetRegion(outputX, 0, m_multiple, outputHeight, e); |
| 434 BC_EXCEPTION_CHECK_ReturnVoid(e); | 435 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 435 } | 436 } |
| 436 outputX += m_multiple; | 437 outputX += m_multiple; |
| 437 } | 438 } |
| 438 } | 439 } |
| OLD | NEW |