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 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "core/fxge/include/cfx_pathdata.h" | 9 #include "core/fxge/include/cfx_pathdata.h" |
10 #include "core/fxge/include/fx_ge.h" | 10 #include "core/fxge/include/fx_ge.h" |
11 #include "third_party/base/numerics/safe_math.h" | 11 #include "third_party/base/numerics/safe_math.h" |
12 #include "xfa/fxbarcode/BC_TwoDimWriter.h" | 12 #include "xfa/fxbarcode/BC_TwoDimWriter.h" |
13 #include "xfa/fxbarcode/BC_Writer.h" | 13 #include "xfa/fxbarcode/BC_Writer.h" |
14 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" | 14 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" |
15 | 15 |
16 CBC_TwoDimWriter::CBC_TwoDimWriter() { | 16 CBC_TwoDimWriter::CBC_TwoDimWriter() : m_iCorrectLevel(1), m_bFixedSize(TRUE) {} |
17 m_iCorrectLevel = 1; | 17 |
18 m_bFixedSize = TRUE; | 18 CBC_TwoDimWriter::~CBC_TwoDimWriter() {} |
19 m_output = nullptr; | 19 |
20 } | |
21 CBC_TwoDimWriter::~CBC_TwoDimWriter() { | |
22 delete m_output; | |
23 } | |
24 void CBC_TwoDimWriter::RenderDeviceResult(CFX_RenderDevice* device, | 20 void CBC_TwoDimWriter::RenderDeviceResult(CFX_RenderDevice* device, |
25 const CFX_Matrix* matrix) { | 21 const CFX_Matrix* matrix) { |
26 CFX_GraphStateData stateData; | 22 CFX_GraphStateData stateData; |
27 CFX_PathData path; | 23 CFX_PathData path; |
28 path.AppendRect(0, 0, (FX_FLOAT)m_Width, (FX_FLOAT)m_Height); | 24 path.AppendRect(0, 0, (FX_FLOAT)m_Width, (FX_FLOAT)m_Height); |
29 device->DrawPath(&path, matrix, &stateData, m_backgroundColor, | 25 device->DrawPath(&path, matrix, &stateData, m_backgroundColor, |
30 m_backgroundColor, FXFILL_ALTERNATE); | 26 m_backgroundColor, FXFILL_ALTERNATE); |
31 int32_t leftPos = 0; | 27 int32_t leftPos = 0; |
32 int32_t topPos = 0; | 28 int32_t topPos = 0; |
33 if (m_bFixedSize) { | 29 if (m_bFixedSize) { |
(...skipping 14 matching lines...) Expand all Loading... |
48 rect.AppendRect((FX_FLOAT)leftPos + x, (FX_FLOAT)topPos + y, | 44 rect.AppendRect((FX_FLOAT)leftPos + x, (FX_FLOAT)topPos + y, |
49 (FX_FLOAT)(leftPos + x + 1), (FX_FLOAT)(topPos + y + 1)); | 45 (FX_FLOAT)(leftPos + x + 1), (FX_FLOAT)(topPos + y + 1)); |
50 if (m_output->Get(x, y)) { | 46 if (m_output->Get(x, y)) { |
51 CFX_GraphStateData data; | 47 CFX_GraphStateData data; |
52 device->DrawPath(&rect, &matri, &data, m_barColor, 0, FXFILL_WINDING); | 48 device->DrawPath(&rect, &matri, &data, m_barColor, 0, FXFILL_WINDING); |
53 } | 49 } |
54 } | 50 } |
55 } | 51 } |
56 } | 52 } |
57 | 53 |
58 int32_t CBC_TwoDimWriter::GetErrorCorrectionLevel() { | 54 int32_t CBC_TwoDimWriter::GetErrorCorrectionLevel() const { |
59 return m_iCorrectLevel; | 55 return m_iCorrectLevel; |
60 } | 56 } |
61 | 57 |
62 void CBC_TwoDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap, | 58 void CBC_TwoDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap, |
63 int32_t& e) { | 59 int32_t& e) { |
64 if (m_bFixedSize) { | 60 if (m_bFixedSize) { |
65 pOutBitmap = CreateDIBitmap(m_Width, m_Height); | 61 pOutBitmap = CreateDIBitmap(m_Width, m_Height); |
66 } else { | 62 } else { |
67 pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight()); | 63 pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight()); |
68 } | 64 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 multiY = multiX; | 125 multiY = multiX; |
130 } | 126 } |
131 int32_t leftPadding = (outputWidth - (inputWidth * multiX)) / 2; | 127 int32_t leftPadding = (outputWidth - (inputWidth * multiX)) / 2; |
132 int32_t topPadding = (outputHeight - (inputHeight * multiY)) / 2; | 128 int32_t topPadding = (outputHeight - (inputHeight * multiY)) / 2; |
133 if (leftPadding < 0) { | 129 if (leftPadding < 0) { |
134 leftPadding = 0; | 130 leftPadding = 0; |
135 } | 131 } |
136 if (topPadding < 0) { | 132 if (topPadding < 0) { |
137 topPadding = 0; | 133 topPadding = 0; |
138 } | 134 } |
139 m_output = new CBC_CommonBitMatrix; | 135 m_output.reset(new CBC_CommonBitMatrix); |
140 m_output->Init(outputWidth, outputHeight); | 136 m_output->Init(outputWidth, outputHeight); |
141 for (int32_t inputY = 0, outputY = topPadding; | 137 for (int32_t inputY = 0, outputY = topPadding; |
142 (inputY < inputHeight) && (outputY < outputHeight - multiY); | 138 (inputY < inputHeight) && (outputY < outputHeight - multiY); |
143 inputY++, outputY += multiY) { | 139 inputY++, outputY += multiY) { |
144 for (int32_t inputX = 0, outputX = leftPadding; | 140 for (int32_t inputX = 0, outputX = leftPadding; |
145 (inputX < inputWidth) && (outputX < outputWidth - multiX); | 141 (inputX < inputWidth) && (outputX < outputWidth - multiX); |
146 inputX++, outputX += multiX) { | 142 inputX++, outputX += multiX) { |
147 if (code[inputX + inputY * inputWidth] == 1) { | 143 if (code[inputX + inputY * inputWidth] == 1) { |
148 m_output->SetRegion(outputX, outputY, multiX, multiY, e); | 144 m_output->SetRegion(outputX, outputY, multiX, multiY, e); |
149 BC_EXCEPTION_CHECK_ReturnVoid(e); | 145 BC_EXCEPTION_CHECK_ReturnVoid(e); |
150 } | 146 } |
151 } | 147 } |
152 } | 148 } |
153 } | 149 } |
OLD | NEW |