Add DOT_SIZE encode hint and implement it for Data Matrix

This commit is contained in:
starovoid
2024-03-12 12:30:41 +03:00
parent b57d7e35fa
commit 01a05688dd
2 changed files with 28 additions and 2 deletions

View File

@@ -78,6 +78,7 @@ impl Writer for DataMatrixWriter {
let mut shape = &SymbolShapeHint::FORCE_NONE;
let mut minSize = None;
let mut maxSize = None;
let mut dotsize = None;
if !hints.is_empty() {
if let Some(EncodeHintValue::DataMatrixShape(rq)) =
hints.get(&EncodeHintType::DATA_MATRIX_SHAPE)
@@ -94,6 +95,11 @@ impl Writer for DataMatrixWriter {
if let Some(EncodeHintValue::MinSize(rq)) = requestedMaxSize {
maxSize = Some(*rq);
}
let requestedDotSize = hints.get(&EncodeHintType::DOT_SIZE);
if let Some(EncodeHintValue::DotSizePixels(size)) = requestedDotSize {
dotsize = Some(*size);
}
}
//1. step: Data encodation
@@ -178,7 +184,7 @@ impl Writer for DataMatrixWriter {
placement.place()?;
//4. step: low-level encoding
Self::encodeLowLevel(&placement, symbolInfo, width as u32, height as u32)
Self::encodeLowLevel(&placement, symbolInfo, width as u32, height as u32, dotsize)
}
}
@@ -195,6 +201,7 @@ impl DataMatrixWriter {
symbolInfo: &SymbolInfo,
width: u32,
height: u32,
dotsize: Option<u32>,
) -> Result<BitMatrix> {
let symbolWidth = symbolInfo.getSymbolDataWidth()?;
let symbolHeight = symbolInfo.getSymbolDataHeight()?;
@@ -246,7 +253,7 @@ impl DataMatrixWriter {
}
}
Self::convertByteMatrixToBitMatrix(&matrix, width, height)
Self::convertByteMatrixToBitMatrix(&matrix, width, height, dotsize)
}
/**
@@ -254,6 +261,8 @@ impl DataMatrixWriter {
*
* @param reqHeight The requested height of the image (in pixels) with the Datamatrix code
* @param reqWidth The requested width of the image (in pixels) with the Datamatrix code
* @param dotsize The requested size of unit dot (in pixels). Using this parameter cancels
* reqWidth and reqHeight.
* @param matrix The input matrix.
* @return The output matrix.
*/
@@ -261,9 +270,16 @@ impl DataMatrixWriter {
matrix: &ByteMatrix,
reqWidth: u32,
reqHeight: u32,
dotsize: Option<u32>,
) -> Result<BitMatrix> {
let matrixWidth = matrix.getWidth();
let matrixHeight = matrix.getHeight();
let (reqWidth, reqHeight) = match dotsize {
Some(m) => (matrixWidth * m, matrixHeight * m),
None => (reqWidth, reqHeight),
};
let outputWidth = reqWidth.max(matrixWidth);
let outputHeight = reqHeight.max(matrixHeight);

View File

@@ -185,6 +185,11 @@ pub enum EncodeHintType {
* Will translate the numeric values received by the Telepen writer into the Telepen Alphanumeric form.
*/
TELEPEN_AS_NUMERIC,
/**
* The size of a unit dot of a square 2D code (QR code, DataMatrix or Aztec).
*/
DOT_SIZE,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -343,4 +348,9 @@ pub enum EncodeHintValue {
* Translate the numeric values received by the Telepen reader into the Telepen Alphaumeric form; use {@link Boolean#TRUE}.
*/
TelepenAsNumeric(bool),
/**
* The size of a unit dot of a square 2D code (QR code, DataMatrix or Aztec) in pixels.
*/
DotSizePixels(u32),
}