summaryrefslogtreecommitdiff
path: root/xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.cpp
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2015-08-04 13:00:21 -0700
committerNico Weber <thakis@chromium.org>2015-08-04 13:00:21 -0700
commit9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f (patch)
treec97037f398d714665aefccb6eb54d0969ad7030c /xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.cpp
parent780cee82236d1b3b0f9b01a22424e4b8ec9a6f12 (diff)
downloadpdfium-9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f.tar.xz
XFA: clang-format all pdfium code.
No behavior change. Generated by: find . -name '*.cpp' -o -name '*.h' | \ grep -E -v 'third_party|thirdparties|lpng_v163|tiff_v403' | \ xargs ../../buildtools/mac/clang-format -i Then manually merged https://codereview.chromium.org/1269223002/ See thread "tabs vs spaces" on pdfium@googlegroups.com for discussion. BUG=none
Diffstat (limited to 'xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.cpp')
-rw-r--r--xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.cpp434
1 files changed, 223 insertions, 211 deletions
diff --git a/xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.cpp
index a247a0670b..0c551ccc6b 100644
--- a/xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/xfa/src/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -28,234 +28,246 @@
#include "BC_OneDimWriter.h"
#include "BC_OneDimReader.h"
#include "BC_OnedEAN8Writer.h"
-CBC_OnedEAN8Writer::CBC_OnedEAN8Writer()
-{
- m_iDataLenth = 8;
- m_codeWidth = 3 +
- (7 * 4) +
- 5 +
- (7 * 4) +
- 3;
+CBC_OnedEAN8Writer::CBC_OnedEAN8Writer() {
+ m_iDataLenth = 8;
+ m_codeWidth = 3 + (7 * 4) + 5 + (7 * 4) + 3;
}
-CBC_OnedEAN8Writer::~CBC_OnedEAN8Writer()
-{
+CBC_OnedEAN8Writer::~CBC_OnedEAN8Writer() {}
+void CBC_OnedEAN8Writer::SetDataLength(int32_t length) {
+ m_iDataLenth = 8;
}
-void CBC_OnedEAN8Writer::SetDataLength(int32_t length)
-{
- m_iDataLenth = 8;
+FX_BOOL CBC_OnedEAN8Writer::SetTextLocation(BC_TEXT_LOC location) {
+ if (location == BC_TEXT_LOC_BELOWEMBED) {
+ m_locTextLoc = location;
+ return TRUE;
+ }
+ return FALSE;
}
-FX_BOOL CBC_OnedEAN8Writer::SetTextLocation(BC_TEXT_LOC location)
-{
- if ( location == BC_TEXT_LOC_BELOWEMBED) {
- m_locTextLoc = location;
- return TRUE;
+FX_BOOL CBC_OnedEAN8Writer::CheckContentValidity(
+ const CFX_WideStringC& contents) {
+ for (int32_t i = 0; i < contents.GetLength(); i++) {
+ if (contents.GetAt(i) >= '0' && contents.GetAt(i) <= '9') {
+ continue;
+ } else {
+ return FALSE;
}
- return FALSE;
+ }
+ return TRUE;
}
-FX_BOOL CBC_OnedEAN8Writer::CheckContentValidity(const CFX_WideStringC& contents)
-{
- for (int32_t i = 0; i < contents.GetLength(); i++) {
- if (contents.GetAt(i) >= '0' && contents.GetAt(i) <= '9') {
- continue;
- } else {
- return FALSE;
- }
+CFX_WideString CBC_OnedEAN8Writer::FilterContents(
+ const CFX_WideStringC& contents) {
+ CFX_WideString filtercontents;
+ FX_WCHAR ch;
+ for (int32_t i = 0; i < contents.GetLength(); i++) {
+ ch = contents.GetAt(i);
+ if (ch > 175) {
+ i++;
+ continue;
}
- return TRUE;
-}
-CFX_WideString CBC_OnedEAN8Writer::FilterContents(const CFX_WideStringC& contents)
-{
- CFX_WideString filtercontents;
- FX_WCHAR ch;
- for (int32_t i = 0; i < contents.GetLength(); i++) {
- ch = contents.GetAt(i);
- if(ch > 175) {
- i++;
- continue;
- }
- if (ch >= '0' && ch <= '9') {
- filtercontents += ch;
- }
+ if (ch >= '0' && ch <= '9') {
+ filtercontents += ch;
}
- return filtercontents;
+ }
+ return filtercontents;
}
-int32_t CBC_OnedEAN8Writer::CalcChecksum(const CFX_ByteString &contents)
-{
- int32_t odd = 0;
- int32_t even = 0;
- int32_t j = 1;
- for(int32_t i = contents.GetLength() - 1; i >= 0; i--) {
- if(j % 2) {
- odd += FXSYS_atoi(contents.Mid(i, 1));
- } else {
- even += FXSYS_atoi(contents.Mid(i, 1));
- }
- j++;
+int32_t CBC_OnedEAN8Writer::CalcChecksum(const CFX_ByteString& contents) {
+ int32_t odd = 0;
+ int32_t even = 0;
+ int32_t j = 1;
+ for (int32_t i = contents.GetLength() - 1; i >= 0; i--) {
+ if (j % 2) {
+ odd += FXSYS_atoi(contents.Mid(i, 1));
+ } else {
+ even += FXSYS_atoi(contents.Mid(i, 1));
}
- int32_t checksum = (odd * 3 + even) % 10;
- checksum = (10 - checksum) % 10;
- return (checksum);
+ j++;
+ }
+ int32_t checksum = (odd * 3 + even) % 10;
+ checksum = (10 - checksum) % 10;
+ return (checksum);
}
-uint8_t *CBC_OnedEAN8Writer::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);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- return ret;
+uint8_t* CBC_OnedEAN8Writer::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);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
}
-uint8_t *CBC_OnedEAN8Writer::Encode(const CFX_ByteString &contents, BCFORMAT format,
- int32_t &outWidth, int32_t &outHeight, int32_t hints , int32_t &e)
-{
- if (format != BCFORMAT_EAN_8) {
- e = BCExceptionOnlyEncodeEAN_8;
- return NULL;
- }
- uint8_t *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- return ret;
+uint8_t* CBC_OnedEAN8Writer::Encode(const CFX_ByteString& contents,
+ BCFORMAT format,
+ int32_t& outWidth,
+ int32_t& outHeight,
+ int32_t hints,
+ int32_t& e) {
+ if (format != BCFORMAT_EAN_8) {
+ e = BCExceptionOnlyEncodeEAN_8;
+ return NULL;
+ }
+ uint8_t* ret =
+ CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ return ret;
}
-uint8_t *CBC_OnedEAN8Writer::Encode(const CFX_ByteString &contents, int32_t &outLength , int32_t &e)
-{
- if (contents.GetLength() != 8) {
- e = BCExceptionDigitLengthMustBe8;
- return NULL;
- }
- outLength = m_codeWidth;
- uint8_t *result = FX_Alloc(uint8_t, m_codeWidth);
- int32_t pos = 0;
- pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
+uint8_t* CBC_OnedEAN8Writer::Encode(const CFX_ByteString& contents,
+ int32_t& outLength,
+ int32_t& e) {
+ if (contents.GetLength() != 8) {
+ e = BCExceptionDigitLengthMustBe8;
+ return NULL;
+ }
+ outLength = m_codeWidth;
+ uint8_t* result = FX_Alloc(uint8_t, m_codeWidth);
+ int32_t pos = 0;
+ pos +=
+ AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
+ if (e != BCExceptionNO) {
+ FX_Free(result);
+ return NULL;
+ }
+ int32_t i = 0;
+ for (i = 0; i <= 3; i++) {
+ int32_t digit = FXSYS_atoi(contents.Mid(i, 1));
+ pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 0,
+ e);
if (e != BCExceptionNO) {
- FX_Free (result);
- return NULL;
- }
- int32_t i = 0;
- for (i = 0; i <= 3; i++) {
- int32_t digit = FXSYS_atoi(contents.Mid(i, 1));
- pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 0, e);
- if (e != BCExceptionNO) {
- FX_Free (result);
- return NULL;
- }
+ FX_Free(result);
+ return NULL;
}
- pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e);
+ }
+ pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e);
+ if (e != BCExceptionNO) {
+ FX_Free(result);
+ return NULL;
+ }
+ for (i = 4; i <= 7; i++) {
+ int32_t digit = FXSYS_atoi(contents.Mid(i, 1));
+ pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 1,
+ e);
if (e != BCExceptionNO) {
- FX_Free (result);
- return NULL;
+ FX_Free(result);
+ return NULL;
}
- for (i = 4; i <= 7; i++) {
- int32_t digit = FXSYS_atoi(contents.Mid(i, 1));
- pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 1, e);
- if (e != BCExceptionNO) {
- FX_Free (result);
- return NULL;
- }
- }
- pos += AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
- if (e != BCExceptionNO) {
- FX_Free (result);
- return NULL;
- }
- return result;
+ }
+ pos +=
+ AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e);
+ if (e != BCExceptionNO) {
+ FX_Free(result);
+ return NULL;
+ }
+ return result;
}
-void CBC_OnedEAN8Writer::ShowChars(const CFX_WideStringC& contents, CFX_DIBitmap *pOutBitmap, CFX_RenderDevice* device, const CFX_Matrix* matrix, int32_t barWidth, int32_t multiple, int32_t &e)
-{
- if (device == NULL && pOutBitmap == NULL) {
- e = BCExceptionIllegalArgument;
- return;
- }
- int32_t leftPosition = 3 * multiple;
- CFX_ByteString str = FX_UTF8Encode(contents);
- int32_t iLength = str.GetLength();
- FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLength);
- if (!pCharPos) {
- return;
- }
- FXSYS_memset(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLength);
- CFX_ByteString tempStr = str.Mid(0, 4);
- int32_t iLen = tempStr.GetLength();
- int32_t strWidth = 7 * multiple * 4;
- FX_FLOAT blank = 0.0;
- CFX_FxgeDevice geBitmap;
- if (pOutBitmap != NULL) {
- geBitmap.Attach(pOutBitmap);
- }
- FX_FLOAT charsWidth = 0;
- int32_t iFontSize = (int32_t)fabs(m_fFontSize);
- int32_t iTextHeight = iFontSize + 1;
- if (pOutBitmap == NULL) {
- CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
- CFX_FloatRect rect((FX_FLOAT)leftPosition, (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)(leftPosition + strWidth - 0.5), (FX_FLOAT)m_Height);
- matr.Concat(*matrix);
- matr.TransformRect(rect);
- FX_RECT re = rect.GetOutterRect();
- device->FillRect(&re, m_backgroundColor);
- CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
- CFX_FloatRect rect1((FX_FLOAT)(leftPosition + 33 * multiple), (FX_FLOAT)(m_Height - iTextHeight), (FX_FLOAT)(leftPosition + 33 * multiple + strWidth - 0.5), (FX_FLOAT)m_Height);
- matr1.Concat(*matrix);
- matr1.TransformRect(rect1);
- re = rect1.GetOutterRect();
- device->FillRect(&re, m_backgroundColor);
- }
- if (pOutBitmap == NULL) {
- strWidth = (int32_t)(strWidth * m_outputHScale);
- }
- CalcTextInfo(tempStr, pCharPos, m_pFont, (FX_FLOAT)strWidth, iFontSize, blank);
- CFX_AffineMatrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize);
- CFX_FxgeDevice ge;
- if (pOutBitmap != NULL) {
- delete ge.GetBitmap();
- ge.Create(strWidth, iTextHeight, FXDIB_Argb);
- ge.GetBitmap()->Clear(m_backgroundColor);
- ge.DrawNormalText(iLen,
- pCharPos,
- m_pFont,
- CFX_GEModule::Get()->GetFontCache(),
- (FX_FLOAT)iFontSize ,
- (CFX_AffineMatrix *) &affine_matrix,
- m_fontColor, FXTEXT_CLEARTYPE);
- geBitmap.SetDIBits(ge.GetBitmap(), leftPosition, m_Height - iTextHeight);
- } else {
- CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)leftPosition * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
- affine_matrix1.Concat(*matrix);
- FX_BOOL ret = device->DrawNormalText(iLen,
- pCharPos,
- m_pFont,
- CFX_GEModule::Get()->GetFontCache(),
- (FX_FLOAT)iFontSize,
- (CFX_AffineMatrix *) &affine_matrix1,
- m_fontColor, FXTEXT_CLEARTYPE);
- }
- tempStr = str.Mid(4, 4);
- iLen = tempStr.GetLength();
- charsWidth = 0.0f;
- CalcTextInfo(tempStr, pCharPos + 4, m_pFont, (FX_FLOAT)strWidth, iFontSize, blank);
- if (pOutBitmap != NULL) {
- delete ge.GetBitmap();
- ge.Create(strWidth, iTextHeight, FXDIB_Argb);
- ge.GetBitmap()->Clear(m_backgroundColor);
- ge.DrawNormalText(iLen,
- pCharPos + 4,
- m_pFont,
- CFX_GEModule::Get()->GetFontCache(),
- (FX_FLOAT)iFontSize ,
- (CFX_AffineMatrix *) &affine_matrix,
- m_fontColor, FXTEXT_CLEARTYPE);
- geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 33 * multiple, m_Height - iTextHeight);
- } else {
- CFX_AffineMatrix affine_matrix1(1.0, 0.0, 0.0, -1.0, (FX_FLOAT)(leftPosition + 33 * multiple) * m_outputHScale, (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
- if (matrix != NULL) {
- affine_matrix1.Concat(*matrix);
- }
- FX_BOOL ret = device->DrawNormalText(iLen,
- pCharPos + 4,
- m_pFont,
- CFX_GEModule::Get()->GetFontCache(),
- (FX_FLOAT)iFontSize ,
- (CFX_AffineMatrix *) &affine_matrix1,
- m_fontColor, FXTEXT_CLEARTYPE);
+void CBC_OnedEAN8Writer::ShowChars(const CFX_WideStringC& contents,
+ CFX_DIBitmap* pOutBitmap,
+ CFX_RenderDevice* device,
+ const CFX_Matrix* matrix,
+ int32_t barWidth,
+ int32_t multiple,
+ int32_t& e) {
+ if (device == NULL && pOutBitmap == NULL) {
+ e = BCExceptionIllegalArgument;
+ return;
+ }
+ int32_t leftPosition = 3 * multiple;
+ CFX_ByteString str = FX_UTF8Encode(contents);
+ int32_t iLength = str.GetLength();
+ FXTEXT_CHARPOS* pCharPos = FX_Alloc(FXTEXT_CHARPOS, iLength);
+ if (!pCharPos) {
+ return;
+ }
+ FXSYS_memset(pCharPos, 0, sizeof(FXTEXT_CHARPOS) * iLength);
+ CFX_ByteString tempStr = str.Mid(0, 4);
+ int32_t iLen = tempStr.GetLength();
+ int32_t strWidth = 7 * multiple * 4;
+ FX_FLOAT blank = 0.0;
+ CFX_FxgeDevice geBitmap;
+ if (pOutBitmap != NULL) {
+ geBitmap.Attach(pOutBitmap);
+ }
+ FX_FLOAT charsWidth = 0;
+ int32_t iFontSize = (int32_t)fabs(m_fFontSize);
+ int32_t iTextHeight = iFontSize + 1;
+ if (pOutBitmap == NULL) {
+ CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
+ CFX_FloatRect rect(
+ (FX_FLOAT)leftPosition, (FX_FLOAT)(m_Height - iTextHeight),
+ (FX_FLOAT)(leftPosition + strWidth - 0.5), (FX_FLOAT)m_Height);
+ matr.Concat(*matrix);
+ matr.TransformRect(rect);
+ FX_RECT re = rect.GetOutterRect();
+ device->FillRect(&re, m_backgroundColor);
+ CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
+ CFX_FloatRect rect1(
+ (FX_FLOAT)(leftPosition + 33 * multiple),
+ (FX_FLOAT)(m_Height - iTextHeight),
+ (FX_FLOAT)(leftPosition + 33 * multiple + strWidth - 0.5),
+ (FX_FLOAT)m_Height);
+ matr1.Concat(*matrix);
+ matr1.TransformRect(rect1);
+ re = rect1.GetOutterRect();
+ device->FillRect(&re, m_backgroundColor);
+ }
+ if (pOutBitmap == NULL) {
+ strWidth = (int32_t)(strWidth * m_outputHScale);
+ }
+ CalcTextInfo(tempStr, pCharPos, m_pFont, (FX_FLOAT)strWidth, iFontSize,
+ blank);
+ CFX_AffineMatrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (FX_FLOAT)iFontSize);
+ CFX_FxgeDevice ge;
+ if (pOutBitmap != NULL) {
+ delete ge.GetBitmap();
+ ge.Create(strWidth, iTextHeight, FXDIB_Argb);
+ ge.GetBitmap()->Clear(m_backgroundColor);
+ ge.DrawNormalText(iLen, pCharPos, m_pFont,
+ CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize,
+ (CFX_AffineMatrix*)&affine_matrix, m_fontColor,
+ FXTEXT_CLEARTYPE);
+ geBitmap.SetDIBits(ge.GetBitmap(), leftPosition, m_Height - iTextHeight);
+ } else {
+ CFX_AffineMatrix affine_matrix1(
+ 1.0, 0.0, 0.0, -1.0, (FX_FLOAT)leftPosition * m_outputHScale,
+ (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
+ affine_matrix1.Concat(*matrix);
+ FX_BOOL ret = device->DrawNormalText(
+ iLen, pCharPos, m_pFont, CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize, (CFX_AffineMatrix*)&affine_matrix1, m_fontColor,
+ FXTEXT_CLEARTYPE);
+ }
+ tempStr = str.Mid(4, 4);
+ iLen = tempStr.GetLength();
+ charsWidth = 0.0f;
+ CalcTextInfo(tempStr, pCharPos + 4, m_pFont, (FX_FLOAT)strWidth, iFontSize,
+ blank);
+ if (pOutBitmap != NULL) {
+ delete ge.GetBitmap();
+ ge.Create(strWidth, iTextHeight, FXDIB_Argb);
+ ge.GetBitmap()->Clear(m_backgroundColor);
+ ge.DrawNormalText(iLen, pCharPos + 4, m_pFont,
+ CFX_GEModule::Get()->GetFontCache(), (FX_FLOAT)iFontSize,
+ (CFX_AffineMatrix*)&affine_matrix, m_fontColor,
+ FXTEXT_CLEARTYPE);
+ geBitmap.SetDIBits(ge.GetBitmap(), leftPosition + 33 * multiple,
+ m_Height - iTextHeight);
+ } else {
+ CFX_AffineMatrix affine_matrix1(
+ 1.0, 0.0, 0.0, -1.0,
+ (FX_FLOAT)(leftPosition + 33 * multiple) * m_outputHScale,
+ (FX_FLOAT)(m_Height - iTextHeight + iFontSize));
+ if (matrix != NULL) {
+ affine_matrix1.Concat(*matrix);
}
- FX_Free(pCharPos);
+ FX_BOOL ret = device->DrawNormalText(
+ iLen, pCharPos + 4, m_pFont, CFX_GEModule::Get()->GetFontCache(),
+ (FX_FLOAT)iFontSize, (CFX_AffineMatrix*)&affine_matrix1, m_fontColor,
+ FXTEXT_CLEARTYPE);
+ }
+ FX_Free(pCharPos);
}
-void CBC_OnedEAN8Writer::RenderResult(const CFX_WideStringC& contents, uint8_t* code, int32_t codeLength, FX_BOOL isDevice, int32_t &e)
-{
- CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e);
+void CBC_OnedEAN8Writer::RenderResult(const CFX_WideStringC& contents,
+ uint8_t* code,
+ int32_t codeLength,
+ FX_BOOL isDevice,
+ int32_t& e) {
+ CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e);
}