mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
Add DOT_SIZE encode hint and implement it for Data Matrix
This commit is contained in:
@@ -78,6 +78,7 @@ impl Writer for DataMatrixWriter {
|
|||||||
let mut shape = &SymbolShapeHint::FORCE_NONE;
|
let mut shape = &SymbolShapeHint::FORCE_NONE;
|
||||||
let mut minSize = None;
|
let mut minSize = None;
|
||||||
let mut maxSize = None;
|
let mut maxSize = None;
|
||||||
|
let mut dotsize = None;
|
||||||
if !hints.is_empty() {
|
if !hints.is_empty() {
|
||||||
if let Some(EncodeHintValue::DataMatrixShape(rq)) =
|
if let Some(EncodeHintValue::DataMatrixShape(rq)) =
|
||||||
hints.get(&EncodeHintType::DATA_MATRIX_SHAPE)
|
hints.get(&EncodeHintType::DATA_MATRIX_SHAPE)
|
||||||
@@ -94,6 +95,11 @@ impl Writer for DataMatrixWriter {
|
|||||||
if let Some(EncodeHintValue::MinSize(rq)) = requestedMaxSize {
|
if let Some(EncodeHintValue::MinSize(rq)) = requestedMaxSize {
|
||||||
maxSize = Some(*rq);
|
maxSize = Some(*rq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let requestedDotSize = hints.get(&EncodeHintType::DOT_SIZE);
|
||||||
|
if let Some(EncodeHintValue::DotSizePixels(size)) = requestedDotSize {
|
||||||
|
dotsize = Some(*size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//1. step: Data encodation
|
//1. step: Data encodation
|
||||||
@@ -178,7 +184,7 @@ impl Writer for DataMatrixWriter {
|
|||||||
placement.place()?;
|
placement.place()?;
|
||||||
|
|
||||||
//4. step: low-level encoding
|
//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,
|
symbolInfo: &SymbolInfo,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
|
dotsize: Option<u32>,
|
||||||
) -> Result<BitMatrix> {
|
) -> Result<BitMatrix> {
|
||||||
let symbolWidth = symbolInfo.getSymbolDataWidth()?;
|
let symbolWidth = symbolInfo.getSymbolDataWidth()?;
|
||||||
let symbolHeight = symbolInfo.getSymbolDataHeight()?;
|
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 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 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.
|
* @param matrix The input matrix.
|
||||||
* @return The output matrix.
|
* @return The output matrix.
|
||||||
*/
|
*/
|
||||||
@@ -261,9 +270,16 @@ impl DataMatrixWriter {
|
|||||||
matrix: &ByteMatrix,
|
matrix: &ByteMatrix,
|
||||||
reqWidth: u32,
|
reqWidth: u32,
|
||||||
reqHeight: u32,
|
reqHeight: u32,
|
||||||
|
dotsize: Option<u32>,
|
||||||
) -> Result<BitMatrix> {
|
) -> Result<BitMatrix> {
|
||||||
let matrixWidth = matrix.getWidth();
|
let matrixWidth = matrix.getWidth();
|
||||||
let matrixHeight = matrix.getHeight();
|
let matrixHeight = matrix.getHeight();
|
||||||
|
|
||||||
|
let (reqWidth, reqHeight) = match dotsize {
|
||||||
|
Some(m) => (matrixWidth * m, matrixHeight * m),
|
||||||
|
None => (reqWidth, reqHeight),
|
||||||
|
};
|
||||||
|
|
||||||
let outputWidth = reqWidth.max(matrixWidth);
|
let outputWidth = reqWidth.max(matrixWidth);
|
||||||
let outputHeight = reqHeight.max(matrixHeight);
|
let outputHeight = reqHeight.max(matrixHeight);
|
||||||
|
|
||||||
|
|||||||
@@ -185,6 +185,11 @@ pub enum EncodeHintType {
|
|||||||
* Will translate the numeric values received by the Telepen writer into the Telepen Alphanumeric form.
|
* Will translate the numeric values received by the Telepen writer into the Telepen Alphanumeric form.
|
||||||
*/
|
*/
|
||||||
TELEPEN_AS_NUMERIC,
|
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))]
|
#[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}.
|
* Translate the numeric values received by the Telepen reader into the Telepen Alphaumeric form; use {@link Boolean#TRUE}.
|
||||||
*/
|
*/
|
||||||
TelepenAsNumeric(bool),
|
TelepenAsNumeric(bool),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The size of a unit dot of a square 2D code (QR code, DataMatrix or Aztec) in pixels.
|
||||||
|
*/
|
||||||
|
DotSizePixels(u32),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user