| 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 2012 ZXing authors | 8 * Copyright 2012 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 18 matching lines...) Expand all Loading... |
| 29 #include "BC_PDF417BarcodeMatrix.h" | 29 #include "BC_PDF417BarcodeMatrix.h" |
| 30 #include "BC_PDF417Writer.h" | 30 #include "BC_PDF417Writer.h" |
| 31 CBC_PDF417Writer::CBC_PDF417Writer() | 31 CBC_PDF417Writer::CBC_PDF417Writer() |
| 32 { | 32 { |
| 33 m_bFixedSize = FALSE; | 33 m_bFixedSize = FALSE; |
| 34 } | 34 } |
| 35 CBC_PDF417Writer::~CBC_PDF417Writer() | 35 CBC_PDF417Writer::~CBC_PDF417Writer() |
| 36 { | 36 { |
| 37 m_bTruncated = TRUE; | 37 m_bTruncated = TRUE; |
| 38 } | 38 } |
| 39 FX_BOOL»CBC_PDF417Writer:: SetErrorCorrectionLevel(FX_INT32 level) | 39 FX_BOOL»CBC_PDF417Writer:: SetErrorCorrectionLevel(int32_t level) |
| 40 { | 40 { |
| 41 if (level < 0 || level > 8) { | 41 if (level < 0 || level > 8) { |
| 42 return FALSE; | 42 return FALSE; |
| 43 } | 43 } |
| 44 m_iCorrectLevel = level; | 44 m_iCorrectLevel = level; |
| 45 return TRUE; | 45 return TRUE; |
| 46 } | 46 } |
| 47 void CBC_PDF417Writer::SetTruncated(FX_BOOL truncated) | 47 void CBC_PDF417Writer::SetTruncated(FX_BOOL truncated) |
| 48 { | 48 { |
| 49 m_bTruncated = truncated; | 49 m_bTruncated = truncated; |
| 50 } | 50 } |
| 51 FX_BYTE* CBC_PDF417Writer::Encode(const CFX_ByteString &contents, BCFORMAT forma
t, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e) | 51 uint8_t* CBC_PDF417Writer::Encode(const CFX_ByteString &contents, BCFORMAT forma
t, int32_t &outWidth, int32_t &outHeight, int32_t &e) |
| 52 { | 52 { |
| 53 if ( format != BCFORMAT_PDF_417) { | 53 if ( format != BCFORMAT_PDF_417) { |
| 54 return NULL; | 54 return NULL; |
| 55 } | 55 } |
| 56 CFX_WideString encodeContents = contents.UTF8Decode(); | 56 CFX_WideString encodeContents = contents.UTF8Decode(); |
| 57 return Encode(encodeContents, outWidth, outHeight, e ); | 57 return Encode(encodeContents, outWidth, outHeight, e ); |
| 58 } | 58 } |
| 59 FX_BYTE* CBC_PDF417Writer::Encode(const CFX_ByteString &contents, BCFORMAT forma
t, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e) | 59 uint8_t* CBC_PDF417Writer::Encode(const CFX_ByteString &contents, BCFORMAT forma
t, int32_t &outWidth, int32_t &outHeight, int32_t hints, int32_t &e) |
| 60 { | 60 { |
| 61 return NULL; | 61 return NULL; |
| 62 } | 62 } |
| 63 FX_BYTE* CBC_PDF417Writer::Encode(const CFX_WideString &contents, FX_INT32 &outW
idth, FX_INT32 &outHeight, FX_INT32 &e) | 63 uint8_t* CBC_PDF417Writer::Encode(const CFX_WideString &contents, int32_t &outWi
dth, int32_t &outHeight, int32_t &e) |
| 64 { | 64 { |
| 65 CBC_PDF417 encoder; | 65 CBC_PDF417 encoder; |
| 66 FX_INT32 col = (m_Width / m_ModuleWidth - 69) / 17; | 66 int32_t col = (m_Width / m_ModuleWidth - 69) / 17; |
| 67 FX_INT32 row = m_Height / (m_ModuleWidth * 20); | 67 int32_t row = m_Height / (m_ModuleWidth * 20); |
| 68 if (row >= 3 && row <= 90 && col >= 1 && col <= 30) { | 68 if (row >= 3 && row <= 90 && col >= 1 && col <= 30) { |
| 69 encoder.setDimensions(col, col, row, row); | 69 encoder.setDimensions(col, col, row, row); |
| 70 } else if (col >= 1 && col <= 30) { | 70 } else if (col >= 1 && col <= 30) { |
| 71 encoder.setDimensions(col, col, 90, 3); | 71 encoder.setDimensions(col, col, 90, 3); |
| 72 } else if (row >= 3 && row <= 90) { | 72 } else if (row >= 3 && row <= 90) { |
| 73 encoder.setDimensions(30, 1, row, row); | 73 encoder.setDimensions(30, 1, row, row); |
| 74 } | 74 } |
| 75 encoder.generateBarcodeLogic(contents, m_iCorrectLevel, e); | 75 encoder.generateBarcodeLogic(contents, m_iCorrectLevel, e); |
| 76 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 76 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 77 FX_INT32 lineThickness = 2; | 77 int32_t lineThickness = 2; |
| 78 FX_INT32 aspectRatio = 4; | 78 int32_t aspectRatio = 4; |
| 79 CBC_BarcodeMatrix* barcodeMatrix = encoder.getBarcodeMatrix(); | 79 CBC_BarcodeMatrix* barcodeMatrix = encoder.getBarcodeMatrix(); |
| 80 CFX_ByteArray originalScale; | 80 CFX_ByteArray originalScale; |
| 81 originalScale.Copy(barcodeMatrix->getScaledMatrix(lineThickness, aspectRatio
* lineThickness)); | 81 originalScale.Copy(barcodeMatrix->getScaledMatrix(lineThickness, aspectRatio
* lineThickness)); |
| 82 FX_INT32 width = outWidth; | 82 int32_t width = outWidth; |
| 83 FX_INT32 height = outHeight; | 83 int32_t height = outHeight; |
| 84 outWidth = barcodeMatrix->getWidth(); | 84 outWidth = barcodeMatrix->getWidth(); |
| 85 outHeight = barcodeMatrix->getHeight(); | 85 outHeight = barcodeMatrix->getHeight(); |
| 86 FX_BOOL rotated = FALSE; | 86 FX_BOOL rotated = FALSE; |
| 87 if ((height > width) ^ (outWidth < outHeight)) { | 87 if ((height > width) ^ (outWidth < outHeight)) { |
| 88 rotateArray(originalScale, outHeight, outWidth); | 88 rotateArray(originalScale, outHeight, outWidth); |
| 89 rotated = TRUE; | 89 rotated = TRUE; |
| 90 FX_INT32 temp = outHeight; | 90 int32_t temp = outHeight; |
| 91 outHeight = outWidth; | 91 outHeight = outWidth; |
| 92 outWidth = temp; | 92 outWidth = temp; |
| 93 } | 93 } |
| 94 FX_INT32 scaleX = width / outWidth; | 94 int32_t scaleX = width / outWidth; |
| 95 FX_INT32 scaleY = height / outHeight; | 95 int32_t scaleY = height / outHeight; |
| 96 FX_INT32 scale; | 96 int32_t scale; |
| 97 if (scaleX < scaleY) { | 97 if (scaleX < scaleY) { |
| 98 scale = scaleX; | 98 scale = scaleX; |
| 99 } else { | 99 } else { |
| 100 scale = scaleY; | 100 scale = scaleY; |
| 101 } | 101 } |
| 102 if (scale > 1) { | 102 if (scale > 1) { |
| 103 originalScale.RemoveAll(); | 103 originalScale.RemoveAll(); |
| 104 originalScale.Copy(barcodeMatrix->getScaledMatrix(scale * lineThickness,
scale * aspectRatio * lineThickness)); | 104 originalScale.Copy(barcodeMatrix->getScaledMatrix(scale * lineThickness,
scale * aspectRatio * lineThickness)); |
| 105 if (rotated) { | 105 if (rotated) { |
| 106 rotateArray(originalScale, outHeight, outWidth); | 106 rotateArray(originalScale, outHeight, outWidth); |
| 107 FX_INT32 temp = outHeight; | 107 int32_t temp = outHeight; |
| 108 outHeight = outWidth; | 108 outHeight = outWidth; |
| 109 outWidth = temp; | 109 outWidth = temp; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 FX_BYTE* result = (FX_BYTE*)FX_Alloc(FX_BYTE, outHeight * outWidth); | 112 uint8_t* result = (uint8_t*)FX_Alloc(uint8_t, outHeight * outWidth); |
| 113 FXSYS_memcpy32(result, originalScale.GetData(), outHeight * outWidth); | 113 FXSYS_memcpy32(result, originalScale.GetData(), outHeight * outWidth); |
| 114 return result; | 114 return result; |
| 115 } | 115 } |
| 116 void CBC_PDF417Writer::rotateArray(CFX_ByteArray& bitarray, FX_INT32 height, FX_
INT32 width) | 116 void CBC_PDF417Writer::rotateArray(CFX_ByteArray& bitarray, int32_t height, int3
2_t width) |
| 117 { | 117 { |
| 118 CFX_ByteArray temp; | 118 CFX_ByteArray temp; |
| 119 temp.Copy(bitarray); | 119 temp.Copy(bitarray); |
| 120 for (FX_INT32 ii = 0; ii < height; ii++) { | 120 for (int32_t ii = 0; ii < height; ii++) { |
| 121 FX_INT32 inverseii = height - ii - 1; | 121 int32_t inverseii = height - ii - 1; |
| 122 for (FX_INT32 jj = 0; jj < width; jj++) { | 122 for (int32_t jj = 0; jj < width; jj++) { |
| 123 bitarray[jj * height + inverseii] = temp[ii * width + jj]; | 123 bitarray[jj * height + inverseii] = temp[ii * width + jj]; |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 } | 126 } |
| OLD | NEW |