Esempio n. 1
0
std::vector<uint8_t> CBC_PDF417Writer::Encode(WideStringView contents,
                                              int32_t* pOutWidth,
                                              int32_t* pOutHeight) {
  std::vector<uint8_t> results;
  CBC_PDF417 encoder;
  int32_t col = (m_Width / m_ModuleWidth - 69) / 17;
  int32_t row = m_Height / (m_ModuleWidth * 20);
  if (row >= 3 && row <= 90 && col >= 1 && col <= 30)
    encoder.setDimensions(col, 1, row, 3);
  else if (col >= 1 && col <= 30)
    encoder.setDimensions(col, col, 90, 3);
  else if (row >= 3 && row <= 90)
    encoder.setDimensions(30, 1, row, row);
  if (!encoder.GenerateBarcodeLogic(contents, error_correction_level()))
    return results;

  CBC_BarcodeMatrix* barcodeMatrix = encoder.getBarcodeMatrix();
  std::vector<uint8_t> matrixData = barcodeMatrix->toBitArray();
  int32_t matrixWidth = barcodeMatrix->getWidth();
  int32_t matrixHeight = barcodeMatrix->getHeight();

  if (matrixWidth < matrixHeight) {
    RotateArray(&matrixData, matrixHeight, matrixWidth);
    std::swap(matrixWidth, matrixHeight);
  }
  *pOutWidth = matrixWidth;
  *pOutHeight = matrixHeight;
  results = pdfium::Vector2D<uint8_t>(*pOutWidth, *pOutHeight);
  memcpy(results.data(), matrixData.data(), *pOutWidth * *pOutHeight);
  return results;
}
Esempio n. 2
0
uint8_t* CBC_PDF417Writer::Encode(const CFX_WideString& contents,
                                  int32_t& outWidth,
                                  int32_t& outHeight,
                                  int32_t& e) {
  CBC_PDF417 encoder;
  int32_t col = (m_Width / m_ModuleWidth - 69) / 17;
  int32_t row = m_Height / (m_ModuleWidth * 20);
  if (row >= 3 && row <= 90 && col >= 1 && col <= 30) {
    encoder.setDimensions(col, col, row, row);
  } else if (col >= 1 && col <= 30) {
    encoder.setDimensions(col, col, 90, 3);
  } else if (row >= 3 && row <= 90) {
    encoder.setDimensions(30, 1, row, row);
  }
  encoder.generateBarcodeLogic(contents, m_iCorrectLevel, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
  int32_t lineThickness = 2;
  int32_t aspectRatio = 4;
  CBC_BarcodeMatrix* barcodeMatrix = encoder.getBarcodeMatrix();
  CFX_ByteArray originalScale;
  originalScale.Copy(barcodeMatrix->getScaledMatrix(
      lineThickness, aspectRatio * lineThickness));
  int32_t width = outWidth;
  int32_t height = outHeight;
  outWidth = barcodeMatrix->getWidth();
  outHeight = barcodeMatrix->getHeight();
  bool rotated = false;
  if ((height > width) ^ (outWidth < outHeight)) {
    rotateArray(originalScale, outHeight, outWidth);
    rotated = true;
    int32_t temp = outHeight;
    outHeight = outWidth;
    outWidth = temp;
  }
  int32_t scaleX = width / outWidth;
  int32_t scaleY = height / outHeight;
  int32_t scale;
  if (scaleX < scaleY) {
    scale = scaleX;
  } else {
    scale = scaleY;
  }
  if (scale > 1) {
    originalScale.RemoveAll();
    originalScale.Copy(barcodeMatrix->getScaledMatrix(
        scale * lineThickness, scale * aspectRatio * lineThickness));
    if (rotated) {
      rotateArray(originalScale, outHeight, outWidth);
      int32_t temp = outHeight;
      outHeight = outWidth;
      outWidth = temp;
    }
  }
  uint8_t* result = FX_Alloc2D(uint8_t, outHeight, outWidth);
  FXSYS_memcpy(result, originalScale.GetData(), outHeight * outWidth);
  return result;
}