From 0ec418f043b946134bee1a37c1dde1cc987579df Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 5 May 2017 13:49:32 -0700 Subject: Represent 1D barcodes with CFX_PathData internally. Change-Id: If90483a8fee2e3a5cd90e7fe4600ff98b2703e5d Reviewed-on: https://pdfium-review.googlesource.com/5010 Commit-Queue: Lei Zhang Reviewed-by: Tom Sepez --- fxbarcode/oned/BC_OneDimWriter.cpp | 78 +++++++++++++++++--------------------- fxbarcode/oned/BC_OneDimWriter.h | 6 ++- 2 files changed, 38 insertions(+), 46 deletions(-) diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp index 71f440faf1..5df7dca788 100644 --- a/fxbarcode/oned/BC_OneDimWriter.cpp +++ b/fxbarcode/oned/BC_OneDimWriter.cpp @@ -33,7 +33,6 @@ #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/cfx_unicodeencodingex.h" #include "fxbarcode/BC_Writer.h" -#include "fxbarcode/common/BC_CommonBitMatrix.h" #include "third_party/base/ptr_util.h" CBC_OneDimWriter::CBC_OneDimWriter() { @@ -263,7 +262,7 @@ bool CBC_OneDimWriter::ShowChars(const CFX_WideStringC& contents, bool CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device, const CFX_Matrix* matrix, const CFX_WideStringC& contents) { - if (!m_output) + if (m_output.empty()) return false; CFX_GraphStateData stateData; @@ -272,33 +271,13 @@ bool CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device, static_cast(m_Height)); device->DrawPath(&path, matrix, &stateData, m_backgroundColor, m_backgroundColor, FXFILL_ALTERNATE); - CFX_Matrix matri(m_outputHScale, 0.0, 0.0, static_cast(m_Height), 0.0, - 0.0); - matri.Concat(*matrix); - for (int32_t x = 0; x < m_output->GetWidth(); x++) { - int32_t yStart = 0; - bool drawing = false; - for (int32_t y = 0; y < m_output->GetHeight(); y++) { - bool draw = m_output->Get(x, y); - if (!drawing) { - if (draw) { - drawing = true; - yStart = y; - } - continue; - } - - if (draw && y != m_output->GetHeight() - 1) - continue; - - drawing = false; - int32_t yEnd = draw ? y + 1 : y; - CFX_PathData rect; - rect.AppendRect(static_cast(x), static_cast(yStart), - static_cast((x + 1)), static_cast(yEnd)); - CFX_GraphStateData data; - device->DrawPath(&rect, &matri, &data, m_barColor, 0, FXFILL_WINDING); - } + CFX_Matrix scaledMatrix(m_outputHScale, 0.0, 0.0, + static_cast(m_Height), 0.0, 0.0); + scaledMatrix.Concat(*matrix); + for (auto& rect : m_output) { + CFX_GraphStateData data; + device->DrawPath(&rect, &scaledMatrix, &data, m_barColor, 0, + FXFILL_WINDING); } return m_locTextLoc == BC_TEXT_LOC_NONE || contents.Find(' ') == -1 || @@ -343,26 +322,37 @@ bool CBC_OneDimWriter::RenderResult(const CFX_WideStringC& contents, m_barWidth = m_Width; if (!isDevice) m_barWidth = codeLength * m_multiple; - m_output = pdfium::MakeUnique(); - m_output->Init(outputWidth, outputHeight); - int32_t outputX = leftPadding * m_multiple; - for (int32_t inputX = 0; inputX < codeOldLength; inputX++) { - if (code[inputX] == 1) { - if (outputX >= outputWidth) - return true; - - if (outputX + m_multiple > outputWidth && outputWidth - outputX > 0) { - return m_output->SetRegion(outputX, 0, outputWidth - outputX, - outputHeight); - } - if (!m_output->SetRegion(outputX, 0, m_multiple, outputHeight)) - return false; + + m_output.clear(); + for (int32_t inputX = 0, outputX = leftPadding * m_multiple; + inputX < codeOldLength; ++inputX, outputX += m_multiple) { + if (code[inputX] != 1) + continue; + + if (outputX >= outputWidth) + return true; + + if (outputX + m_multiple > outputWidth && outputWidth - outputX > 0) { + RenderVerticalBars(outputX, outputWidth - outputX, outputHeight); + return true; } - outputX += m_multiple; + + RenderVerticalBars(outputX, m_multiple, outputHeight); } return true; } +void CBC_OneDimWriter::RenderVerticalBars(int32_t outputX, + int32_t width, + int32_t height) { + for (int i = 0; i < width; ++i) { + float x = outputX + i; + CFX_PathData rect; + rect.AppendRect(x, 0.0f, x + 1, static_cast(height)); + m_output.push_back(rect); + } +} + CFX_WideString CBC_OneDimWriter::RenderTextContents( const CFX_WideStringC& contents) { return CFX_WideString(); diff --git a/fxbarcode/oned/BC_OneDimWriter.h b/fxbarcode/oned/BC_OneDimWriter.h index f1cbcf23df..3bd1b611c6 100644 --- a/fxbarcode/oned/BC_OneDimWriter.h +++ b/fxbarcode/oned/BC_OneDimWriter.h @@ -8,13 +8,14 @@ #define FXBARCODE_ONED_BC_ONEDIMWRITER_H_ #include +#include #include "core/fxge/cfx_renderdevice.h" #include "fxbarcode/BC_Library.h" #include "fxbarcode/BC_Writer.h" -class CBC_CommonBitMatrix; class CFX_Font; +class CFX_PathData; class CFX_RenderDevice; class CBC_OneDimWriter : public CBC_Writer { @@ -80,6 +81,7 @@ class CBC_OneDimWriter : public CBC_Writer { int32_t& e); wchar_t Upper(wchar_t ch); + void RenderVerticalBars(int32_t outputX, int32_t width, int32_t height); bool m_bPrintChecksum; int32_t m_iDataLenth; @@ -92,7 +94,7 @@ class CBC_OneDimWriter : public CBC_Writer { int32_t m_iContentLen; bool m_bLeftPadding; bool m_bRightPadding; - std::unique_ptr m_output; + std::vector m_output; int32_t m_barWidth; int32_t m_multiple; float m_outputHScale; -- cgit v1.2.3