diff options
author | Lei Zhang <thestig@chromium.org> | 2017-04-20 15:58:56 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-21 00:54:04 +0000 |
commit | 1badb85e5c3a4b4cd42ca1a2b223d6b3bc67cc4a (patch) | |
tree | 55bf63857592387531797b0f08e0a6effc0f40c9 /fxbarcode/oned/BC_OnedEAN13Writer.cpp | |
parent | aeee187c927c07f47a9e5886a417dcc58badefb6 (diff) | |
download | pdfium-1badb85e5c3a4b4cd42ca1a2b223d6b3bc67cc4a.tar.xz |
Change more fxbarcode to use return values.
Change-Id: Idcc05fb8c5a1448f552b4db5ae131ad82aef4d59
Reviewed-on: https://pdfium-review.googlesource.com/4258
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fxbarcode/oned/BC_OnedEAN13Writer.cpp')
-rw-r--r-- | fxbarcode/oned/BC_OnedEAN13Writer.cpp | 145 |
1 files changed, 58 insertions, 87 deletions
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp index 96b51b0570..7f38661079 100644 --- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp +++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp @@ -20,22 +20,26 @@ * limitations under the License. */ +#include "fxbarcode/oned/BC_OnedEAN13Writer.h" + +#include <memory> +#include <vector> + #include "core/fxge/cfx_fxgedevice.h" #include "core/fxge/cfx_gemodule.h" #include "fxbarcode/BC_Writer.h" #include "fxbarcode/oned/BC_OneDimWriter.h" -#include "fxbarcode/oned/BC_OnedEAN13Writer.h" namespace { -const int32_t FIRST_DIGIT_ENCODINGS[10] = {0x00, 0x0B, 0x0D, 0xE, 0x13, - 0x19, 0x1C, 0x15, 0x16, 0x1A}; -const int32_t START_END_PATTERN[3] = {1, 1, 1}; -const int32_t MIDDLE_PATTERN[5] = {1, 1, 1, 1, 1}; -const int32_t L_PATTERNS[10][4] = { +const int8_t FIRST_DIGIT_ENCODINGS[10] = {0x00, 0x0B, 0x0D, 0xE, 0x13, + 0x19, 0x1C, 0x15, 0x16, 0x1A}; +const int8_t START_END_PATTERN[3] = {1, 1, 1}; +const int8_t MIDDLE_PATTERN[5] = {1, 1, 1, 1, 1}; +const int8_t L_PATTERNS[10][4] = { {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2}, {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2}}; -const int32_t L_AND_G_PATTERNS[20][4] = { +const int8_t L_AND_G_PATTERNS[20][4] = { {3, 2, 1, 1}, {2, 2, 2, 1}, {2, 1, 2, 2}, {1, 4, 1, 1}, {1, 1, 3, 2}, {1, 2, 3, 1}, {1, 1, 1, 4}, {1, 3, 1, 2}, {1, 2, 1, 3}, {3, 1, 1, 2}, {1, 1, 2, 3}, {1, 2, 2, 2}, {2, 2, 1, 2}, {1, 1, 4, 1}, {2, 3, 1, 1}, @@ -87,100 +91,74 @@ int32_t CBC_OnedEAN13Writer::CalcChecksum(const CFX_ByteString& contents) { checksum = (10 - checksum) % 10; return (checksum); } -uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t& e) { - uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); - if (e != BCExceptionNO) - return nullptr; - return ret; -} -uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents, - BCFORMAT format, - int32_t& outWidth, - int32_t& outHeight, - int32_t hints, - int32_t& e) { - if (format != BCFORMAT_EAN_13) { - e = BCExceptionOnlyEncodeEAN_13; - } - uint8_t* ret = - CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e); - if (e != BCExceptionNO) + +uint8_t* CBC_OnedEAN13Writer::EncodeWithHint(const CFX_ByteString& contents, + BCFORMAT format, + int32_t& outWidth, + int32_t& outHeight, + int32_t hints) { + if (format != BCFORMAT_EAN_13) return nullptr; - return ret; + return CBC_OneDimWriter::EncodeWithHint(contents, format, outWidth, outHeight, + hints); } -uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents, - int32_t& outLength, - int32_t& e) { - if (contents.GetLength() != 13) { - e = BCExceptionDigitLengthShould13; + +uint8_t* CBC_OnedEAN13Writer::EncodeImpl(const CFX_ByteString& contents, + int32_t& outLength) { + if (contents.GetLength() != 13) return nullptr; - } + m_iDataLenth = 13; int32_t firstDigit = FXSYS_atoi(contents.Mid(0, 1).c_str()); int32_t parities = FIRST_DIGIT_ENCODINGS[firstDigit]; outLength = m_codeWidth; - uint8_t* result = FX_Alloc(uint8_t, m_codeWidth); + std::unique_ptr<uint8_t, FxFreeDeleter> result( + FX_Alloc(uint8_t, m_codeWidth)); int32_t pos = 0; - pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e); - if (e != BCExceptionNO) { - FX_Free(result); + int32_t e = BCExceptionNO; + pos += AppendPattern(result.get(), pos, START_END_PATTERN, 3, 1, e); + if (e != BCExceptionNO) return nullptr; - } + int32_t i = 0; for (i = 1; i <= 6; i++) { int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str()); if ((parities >> (6 - i) & 1) == 1) { digit += 10; } - pos += AppendPattern(result, pos, L_AND_G_PATTERNS[digit], 4, 0, e); - if (e != BCExceptionNO) { - FX_Free(result); + pos += AppendPattern(result.get(), pos, L_AND_G_PATTERNS[digit], 4, 0, e); + if (e != BCExceptionNO) return nullptr; - } } - pos += AppendPattern(result, pos, MIDDLE_PATTERN, 5, 0, e); - if (e != BCExceptionNO) { - FX_Free(result); + pos += AppendPattern(result.get(), pos, MIDDLE_PATTERN, 5, 0, e); + if (e != BCExceptionNO) return nullptr; - } + for (i = 7; i <= 12; i++) { int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str()); - pos += AppendPattern(result, pos, L_PATTERNS[digit], 4, 1, e); - if (e != BCExceptionNO) { - FX_Free(result); + pos += AppendPattern(result.get(), pos, L_PATTERNS[digit], 4, 1, e); + if (e != BCExceptionNO) return nullptr; - } } - pos += AppendPattern(result, pos, START_END_PATTERN, 3, 1, e); - if (e != BCExceptionNO) { - FX_Free(result); + pos += AppendPattern(result.get(), pos, START_END_PATTERN, 3, 1, e); + if (e != BCExceptionNO) return nullptr; - } - return result; + return result.release(); } -void CBC_OnedEAN13Writer::ShowChars( - const CFX_WideStringC& contents, - CFX_RenderDevice* device, - const CFX_Matrix* matrix, - int32_t barWidth, - int32_t multiple, - int32_t& e) { - if (!device) { - e = BCExceptionIllegalArgument; - return; - } +bool CBC_OnedEAN13Writer::ShowChars(const CFX_WideStringC& contents, + CFX_RenderDevice* device, + const CFX_Matrix* matrix, + int32_t barWidth, + int32_t multiple) { + if (!device) + return false; + int32_t leftPadding = 7 * multiple; int32_t leftPosition = 3 * multiple + leftPadding; CFX_ByteString str = FX_UTF8Encode(contents); int32_t iLen = str.GetLength(); - FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLen); - memset(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLen); - + std::vector<FXTEXT_CHARPOS> charpos(iLen); int32_t iFontSize = (int32_t)fabs(m_fFontSize); int32_t iTextHeight = iFontSize + 1; CFX_ByteString tempStr = str.Mid(1, 6); @@ -214,7 +192,7 @@ void CBC_OnedEAN13Writer::ShowChars( iLen = tempStr.GetLength(); strWidth = (int32_t)(strWidth * m_outputHScale); - CalcTextInfo(tempStr, pCharPos + 1, m_pFont, (float)strWidth, iFontSize, + CalcTextInfo(tempStr, &charpos[1], m_pFont, (float)strWidth, iFontSize, blank); { CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, @@ -222,13 +200,13 @@ void CBC_OnedEAN13Writer::ShowChars( (float)(m_Height - iTextHeight) + iFontSize); if (matrix) affine_matrix1.Concat(*matrix); - device->DrawNormalText(iLen, pCharPos + 1, m_pFont, + device->DrawNormalText(iLen, &charpos[1], m_pFont, static_cast<float>(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } tempStr = str.Mid(7, 6); iLen = tempStr.GetLength(); - CalcTextInfo(tempStr, pCharPos + 7, m_pFont, (float)strWidth, iFontSize, + CalcTextInfo(tempStr, &charpos[7], m_pFont, (float)strWidth, iFontSize, blank); { CFX_Matrix affine_matrix1( @@ -237,7 +215,7 @@ void CBC_OnedEAN13Writer::ShowChars( (float)(m_Height - iTextHeight + iFontSize)); if (matrix) affine_matrix1.Concat(*matrix); - device->DrawNormalText(iLen, pCharPos + 7, m_pFont, + device->DrawNormalText(iLen, &charpos[7], m_pFont, static_cast<float>(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } @@ -246,23 +224,16 @@ void CBC_OnedEAN13Writer::ShowChars( strWidth = multiple * 7; strWidth = (int32_t)(strWidth * m_outputHScale); - CalcTextInfo(tempStr, pCharPos, m_pFont, (float)strWidth, iFontSize, blank); + CalcTextInfo(tempStr, charpos.data(), m_pFont, (float)strWidth, iFontSize, + blank); { CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0.0, (float)(m_Height - iTextHeight + iFontSize)); if (matrix) affine_matrix1.Concat(*matrix); - device->DrawNormalText(iLen, pCharPos, m_pFont, + device->DrawNormalText(iLen, charpos.data(), m_pFont, static_cast<float>(iFontSize), &affine_matrix1, m_fontColor, FXTEXT_CLEARTYPE); } - FX_Free(pCharPos); -} - -void CBC_OnedEAN13Writer::RenderResult(const CFX_WideStringC& contents, - uint8_t* code, - int32_t codeLength, - bool isDevice, - int32_t& e) { - CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); + return true; } |