| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "barcode.h" | |
| 8 #include "include/BC_Writer.h" | |
| 9 #include "include/BC_CommonBitMatrix.h" | |
| 10 #include "include/BC_TwoDimWriter.h" | |
| 11 CBC_TwoDimWriter::CBC_TwoDimWriter() | |
| 12 { | |
| 13 m_iCorrectLevel = 1; | |
| 14 m_bFixedSize = TRUE; | |
| 15 m_output = NULL; | |
| 16 } | |
| 17 CBC_TwoDimWriter::~CBC_TwoDimWriter() | |
| 18 { | |
| 19 if (m_output != NULL) { | |
| 20 delete m_output; | |
| 21 m_output = NULL; | |
| 22 } | |
| 23 } | |
| 24 void CBC_TwoDimWriter::RenderDeviceResult(CFX_RenderDevice* device, const CFX_Ma
trix* matrix) | |
| 25 { | |
| 26 CFX_GraphStateData stateData; | |
| 27 CFX_PathData path; | |
| 28 path.AppendRect(0, 0, (FX_FLOAT)m_Width, (FX_FLOAT)m_Height); | |
| 29 device->DrawPath(&path, matrix, &stateData, m_backgroundColor, m_backgroundC
olor, FXFILL_ALTERNATE); | |
| 30 FX_INT32 leftPos = 0; | |
| 31 FX_INT32 topPos = 0; | |
| 32 if ( m_bFixedSize) { | |
| 33 leftPos = (m_Width - m_output->GetWidth()) / 2; | |
| 34 topPos = (m_Height - m_output->GetHeight()) / 2; | |
| 35 } | |
| 36 CFX_Matrix matri = *matrix; | |
| 37 if (m_Width < m_output->GetWidth() && m_Height < m_output->GetHeight()) { | |
| 38 CFX_Matrix matriScale((FX_FLOAT)m_Width / (FX_FLOAT)m_output->GetWidth()
, 0.0, 0.0, (FX_FLOAT)m_Height / (FX_FLOAT)m_output->GetHeight(), 0.0, 0.0); | |
| 39 matriScale.Concat(*matrix); | |
| 40 matri = matriScale; | |
| 41 } | |
| 42 for (FX_INT32 x = 0; x < m_output->GetWidth(); x++) { | |
| 43 for (FX_INT32 y = 0; y < m_output->GetHeight(); y++) { | |
| 44 CFX_PathData rect; | |
| 45 rect.AppendRect((FX_FLOAT)leftPos + x, (FX_FLOAT)topPos + y, (FX_FLO
AT)(leftPos + x + 1), (FX_FLOAT)(topPos + y + 1)); | |
| 46 CFX_GraphStateData stateData; | |
| 47 if(m_output->Get(x, y)) { | |
| 48 device->DrawPath(&rect, &matri, &stateData, m_barColor, 0, FXFIL
L_WINDING); | |
| 49 } | |
| 50 } | |
| 51 } | |
| 52 } | |
| 53 void CBC_TwoDimWriter::RenderBitmapResult(CFX_DIBitmap *&pOutBitmap, FX_INT32& e
) | |
| 54 { | |
| 55 if (m_bFixedSize) { | |
| 56 pOutBitmap = CreateDIBitmap(m_Width, m_Height); | |
| 57 } else { | |
| 58 pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight())
; | |
| 59 } | |
| 60 if (!pOutBitmap) { | |
| 61 e = BCExceptionFailToCreateBitmap; | |
| 62 return; | |
| 63 } | |
| 64 pOutBitmap->Clear(m_backgroundColor); | |
| 65 FX_INT32 leftPos = 0; | |
| 66 FX_INT32 topPos = 0; | |
| 67 if ( m_bFixedSize) { | |
| 68 leftPos = (m_Width - m_output->GetWidth()) / 2; | |
| 69 topPos = (m_Height - m_output->GetHeight()) / 2; | |
| 70 } | |
| 71 for (FX_INT32 x = 0; x < m_output->GetWidth(); x++) { | |
| 72 for (FX_INT32 y = 0; y < m_output->GetHeight(); y++) { | |
| 73 if (m_output->Get(x, y)) { | |
| 74 pOutBitmap->SetPixel(leftPos + x, topPos + y, m_barColor); | |
| 75 } | |
| 76 } | |
| 77 } | |
| 78 if (!m_bFixedSize) { | |
| 79 CFX_DIBitmap * pStretchBitmap = pOutBitmap->StretchTo(m_Width, m_Height)
; | |
| 80 if (pOutBitmap) { | |
| 81 delete pOutBitmap; | |
| 82 } | |
| 83 pOutBitmap = pStretchBitmap; | |
| 84 } | |
| 85 } | |
| 86 void CBC_TwoDimWriter::RenderResult(FX_BYTE *code, FX_INT32 codeWidth, FX_INT32
codeHeight, FX_INT32 &e) | |
| 87 { | |
| 88 FX_INT32 inputWidth = codeWidth; | |
| 89 FX_INT32 inputHeight = codeHeight; | |
| 90 FX_INT32 tempWidth = inputWidth + (1 << 1); | |
| 91 FX_INT32 tempHeight = inputHeight + (1 << 1); | |
| 92 FX_FLOAT moduleHSize = (FX_FLOAT)FX_MIN(m_ModuleWidth, m_ModuleHeight); | |
| 93 if (moduleHSize > 8) { | |
| 94 moduleHSize = 8; | |
| 95 } else if (moduleHSize < 1) { | |
| 96 moduleHSize = 1; | |
| 97 } | |
| 98 FX_INT32 outputWidth = (FX_INT32)FX_MAX(tempWidth * moduleHSize, tempWidth); | |
| 99 FX_INT32 outputHeight = (FX_INT32)FX_MAX(tempHeight * moduleHSize, tempHeigh
t); | |
| 100 FX_INT32 multiX = 1; | |
| 101 FX_INT32 multiY = 1; | |
| 102 if (m_bFixedSize) { | |
| 103 if (m_Width < outputWidth || m_Height < outputHeight) { | |
| 104 e = BCExceptionBitmapSizeError; | |
| 105 return; | |
| 106 } | |
| 107 } else { | |
| 108 if (m_Width > outputWidth || m_Height > outputHeight) { | |
| 109 outputWidth = (FX_INT32)(outputWidth * ceil ( (FX_FLOAT)m_Width / (F
X_FLOAT)outputWidth)); | |
| 110 outputHeight = (FX_INT32)(outputHeight * ceil ( (FX_FLOAT)m_Height /
(FX_FLOAT)outputHeight)); | |
| 111 } | |
| 112 } | |
| 113 multiX = (FX_INT32)ceil((FX_FLOAT)outputWidth / (FX_FLOAT)tempWidth); | |
| 114 multiY = (FX_INT32)ceil((FX_FLOAT)outputHeight / (FX_FLOAT) tempHeight); | |
| 115 if (m_bFixedSize) { | |
| 116 multiX = FX_MIN(multiX, multiY); | |
| 117 multiY = multiX; | |
| 118 } | |
| 119 FX_INT32 leftPadding = (outputWidth - (inputWidth * multiX)) / 2; | |
| 120 FX_INT32 topPadding = (outputHeight - (inputHeight * multiY)) / 2; | |
| 121 if (leftPadding < 0) { | |
| 122 leftPadding = 0; | |
| 123 } | |
| 124 if (topPadding < 0) { | |
| 125 topPadding = 0; | |
| 126 } | |
| 127 m_output = FX_NEW CBC_CommonBitMatrix; | |
| 128 m_output->Init(outputWidth, outputHeight); | |
| 129 for (FX_INT32 inputY = 0, outputY = topPadding; (inputY < inputHeight) && (o
utputY < outputHeight - multiY); inputY++, outputY += multiY) { | |
| 130 for (FX_INT32 inputX = 0, outputX = leftPadding; (inputX < inputWidth) &
& (outputX < outputWidth - multiX); inputX++, outputX += multiX) { | |
| 131 if (code[inputX + inputY * inputWidth] == 1) { | |
| 132 m_output->SetRegion(outputX, outputY, multiX, multiY, e); | |
| 133 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
| 134 } | |
| 135 } | |
| 136 } | |
| 137 } | |
| OLD | NEW |