From 01a05688dd55061e51281e55a29b1afc29db1083 Mon Sep 17 00:00:00 2001 From: starovoid Date: Tue, 12 Mar 2024 12:30:41 +0300 Subject: [PATCH] Add DOT_SIZE encode hint and implement it for Data Matrix --- src/datamatrix/data_matrix_writer.rs | 20 ++++++++++++++++++-- src/encode_hints.rs | 10 ++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/datamatrix/data_matrix_writer.rs b/src/datamatrix/data_matrix_writer.rs index e14c904..04de95b 100644 --- a/src/datamatrix/data_matrix_writer.rs +++ b/src/datamatrix/data_matrix_writer.rs @@ -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, ) -> Result { 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, ) -> Result { 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); diff --git a/src/encode_hints.rs b/src/encode_hints.rs index 07cf387..74f6143 100644 --- a/src/encode_hints.rs +++ b/src/encode_hints.rs @@ -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), }