From 104e66c41026d6d83d4a9e4bfb498f68eb7218e2 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Sun, 8 Jan 2023 15:34:00 -0600 Subject: [PATCH] fixed various bugs with encoding qrcodes --- src/pdf417/encoder/dimensions.rs | 1 + src/qrcode/QRCodeWriterTestCase.rs | 3 ++- src/qrcode/encoder/minimal_encoder.rs | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/pdf417/encoder/dimensions.rs b/src/pdf417/encoder/dimensions.rs index 29a7f1f..c0c68dd 100644 --- a/src/pdf417/encoder/dimensions.rs +++ b/src/pdf417/encoder/dimensions.rs @@ -19,6 +19,7 @@ * * @author qwandor@google.com (Andrew Walbran) */ +#[derive(Copy, Clone, Eq, PartialEq)] pub struct Dimensions { minCols: usize, maxCols: usize, diff --git a/src/qrcode/QRCodeWriterTestCase.rs b/src/qrcode/QRCodeWriterTestCase.rs index 3a1a55d..d5192cf 100644 --- a/src/qrcode/QRCodeWriterTestCase.rs +++ b/src/qrcode/QRCodeWriterTestCase.rs @@ -19,7 +19,8 @@ use std::{collections::HashMap, path::PathBuf}; use image::DynamicImage; use crate::{ - common::BitMatrix, qrcode::QRCodeWriter, BarcodeFormat, EncodeHintType, EncodeHintValue, Writer, + common::BitMatrix, qrcode::QRCodeWriter, BarcodeFormat, DecodeHintType, DecodeHintValue, + EncodeHintType, EncodeHintValue, Writer, }; use super::decoder::ErrorCorrectionLevel; diff --git a/src/qrcode/encoder/minimal_encoder.rs b/src/qrcode/encoder/minimal_encoder.rs index 6fb242a..3f881a4 100644 --- a/src/qrcode/encoder/minimal_encoder.rs +++ b/src/qrcode/encoder/minimal_encoder.rs @@ -1052,7 +1052,14 @@ impl RXingResultNode { .encode_string( // &self.stringToEncode[self.fromPosition as usize // ..(self.fromPosition + self.characterLength as usize)], - self.stringToEncode.get(self.fromPosition).unwrap(), + // self.stringToEncode.get(self.fromPosition).unwrap(), + &(self + .stringToEncode + .iter() + .skip(self.fromPosition) + .take(self.characterLength as usize) + .map(|s| s.as_str()) + .collect::()), self.charsetEncoderIndex, ) .len() as u32 @@ -1080,7 +1087,13 @@ impl RXingResultNode { encoder::appendBytes( // &self.stringToEncode[self.fromPosition as usize // ..(self.fromPosition + self.characterLength as usize)], - self.stringToEncode.get(self.fromPosition).unwrap(), + &(self + .stringToEncode + .iter() + .skip(self.fromPosition) + .take(self.characterLength as usize) + .map(|s| s.as_str()) + .collect::()), //self.stringToEncode.get(self.fromPosition).unwrap(), self.mode, bits, self.encoders.getCharset(self.charsetEncoderIndex),