mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
encoder test pass
This commit is contained in:
@@ -14,28 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// package com.google.zxing.aztec.encoder;
|
||||
|
||||
// import com.google.zxing.BarcodeFormat;
|
||||
// import com.google.zxing.EncodeHintType;
|
||||
// import com.google.zxing.FormatException;
|
||||
// import com.google.zxing.RXingResultPoint;
|
||||
// import com.google.zxing.aztec.AztecDetectorRXingResult;
|
||||
// import com.google.zxing.aztec.AztecWriter;
|
||||
// import com.google.zxing.aztec.decoder.Decoder;
|
||||
// import com.google.zxing.common.BitArray;
|
||||
// import com.google.zxing.common.BitMatrix;
|
||||
// import com.google.zxing.common.DecoderRXingResult;
|
||||
// import org.junit.Assert;
|
||||
// import org.junit.Test;
|
||||
|
||||
// import java.nio.charset.Charset;
|
||||
// import java.nio.charset.StandardCharsets;
|
||||
// import java.util.EnumMap;
|
||||
// import java.util.Map;
|
||||
// import java.util.Random;
|
||||
// import java.util.regex.Pattern;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use encoding::EncodingRef;
|
||||
@@ -168,8 +146,24 @@ fn testAztecWriter() {
|
||||
testWriter("Espa\u{00F1}ol", None, 25, true, 1); // Without ECI (implicit ISO-8859-1)
|
||||
testWriter("Espa\u{00F1}ol", Some(ISO_8859_1), 25, true, 1); // Explicit ISO-8859-1
|
||||
testWriter("\u{20AC} 1 sample data.", Some(WINDOWS_1252), 25, true, 2); // ISO-8859-1 can't encode Euro; Windows-1252 can
|
||||
testWriter("\u{20AC} 1 sample data.", Some(WINDOWS_1252), 5, true, 2); // ISO-8859-1 can't encode Euro; Windows-1252 can
|
||||
testWriter("\u{20AC} 1 sample data.", Some(ISO_8859_15), 25, true, 2);
|
||||
testWriter("\u{20AC} 1 sample data.", Some(ISO_8859_15), 0, true, 2);
|
||||
testWriter(
|
||||
"\u{20AC} 1 sample data.",
|
||||
Some(encoding::all::UTF_16BE),
|
||||
0,
|
||||
true,
|
||||
3,
|
||||
);
|
||||
testWriter("Espa\u{00F1}ol", Some(UTF_8), 25, true, 2);
|
||||
testWriter("\u{20AC} 1 sample data", Some(UTF_8), 0, true, 2);
|
||||
testWriter("\u{20AC} 1 sample data. ", Some(UTF_8), 0, true, 2);
|
||||
testWriter("\u{20AC} 1 sample data .", Some(UTF_8), 0, true, 2);
|
||||
testWriter("\u{20AC} 1 sample data-.", Some(UTF_8), 0, true, 2);
|
||||
testWriter("\u{20AC} 1 sample datA.", Some(UTF_8), 0, true, 2);
|
||||
testWriter("\u{20AC} 1 sample dat1.", Some(UTF_8), 0, true, 2);
|
||||
testWriter("\u{20AC} 1 sample data.", Some(UTF_8), 0, true, 2);
|
||||
testWriter("\u{20AC} 1 sample data.", Some(UTF_8), 25, true, 2);
|
||||
testWriter("\u{20AC} 1 sample data.", Some(UTF_8), 100, true, 3);
|
||||
testWriter("\u{20AC} 1 sample data.", Some(UTF_8), 300, true, 4);
|
||||
|
||||
@@ -122,7 +122,8 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
|
||||
let mut encdr: &'static dyn encoding::Encoding = encoding::all::ISO_8859_1;
|
||||
|
||||
let mut index = 0;
|
||||
while index < end_index {
|
||||
|
||||
'main: while index < end_index {
|
||||
if shift_table == Table::BINARY {
|
||||
if end_index - index < 5 {
|
||||
break;
|
||||
@@ -139,8 +140,8 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
|
||||
for _char_count in 0..length {
|
||||
// for (int charCount = 0; charCount < length; charCount++) {
|
||||
if end_index - index < 8 {
|
||||
index = end_index; // Force outer loop to exit
|
||||
break;
|
||||
//index = end_index; // Force outer loop to exit
|
||||
break 'main;
|
||||
}
|
||||
let code = read_code(corrected_bits, index, 8);
|
||||
decoded_bytes.push(code as u8);
|
||||
@@ -163,18 +164,12 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
|
||||
let mut n = read_code(corrected_bits, index, 3);
|
||||
index += 3;
|
||||
// flush bytes, FLG changes state
|
||||
// try {
|
||||
result.push_str(
|
||||
&encdr
|
||||
.decode(&decoded_bytes, encoding::DecoderTrap::Strict)
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
// result.push_str(&String::from_utf8(decoded_bytes.clone()).unwrap());
|
||||
// result.append(decodedBytes.toString(encoding.name()));
|
||||
// } catch (UnsupportedEncodingException uee) {
|
||||
// throw new IllegalStateException(uee);
|
||||
// }
|
||||
decoded_bytes.clear();
|
||||
match n {
|
||||
0 => result.push(29 as char), // translate FNC1 as ASCII 29
|
||||
@@ -208,35 +203,8 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
|
||||
));
|
||||
}
|
||||
encdr = CharacterSetECI::getCharset(&charset_eci?);
|
||||
// encdr = charsetECI?::getCharset();
|
||||
}
|
||||
}
|
||||
// switch (n) {
|
||||
// case 0:
|
||||
// result.append(29 as char); // translate FNC1 as ASCII 29
|
||||
// break;
|
||||
// case 7:
|
||||
// throw FormatException.getFormatInstance(); // FLG(7) is reserved and illegal
|
||||
// default:
|
||||
// // ECI is decimal integer encoded as 1-6 codes in DIGIT mode
|
||||
// int eci = 0;
|
||||
// if (endIndex - index < 4 * n) {
|
||||
// break;
|
||||
// }
|
||||
// while (n-- > 0) {
|
||||
// int nextDigit = readCode(correctedBits, index, 4);
|
||||
// index += 4;
|
||||
// if (nextDigit < 2 || nextDigit > 11) {
|
||||
// throw FormatException.getFormatInstance(); // Not a decimal digit
|
||||
// }
|
||||
// eci = eci * 10 + (nextDigit - 2);
|
||||
// }
|
||||
// CharacterSetECI charsetECI = CharacterSetECI.getCharacterSetECIByValue(eci);
|
||||
// if (charsetECI == null) {
|
||||
// throw FormatException.getFormatInstance();
|
||||
// }
|
||||
// encoding = charsetECI.getCharset();
|
||||
// }
|
||||
// Go back to whatever mode we had been in
|
||||
shift_table = latch_table;
|
||||
} else if str.starts_with("CTRL_") {
|
||||
@@ -251,6 +219,7 @@ fn get_encoded_data(corrected_bits: &[bool]) -> Result<String, Exceptions> {
|
||||
}
|
||||
} else {
|
||||
// Though stored as a table of strings for convenience, codes actually represent 1 or 2 *bytes*.
|
||||
// let b = encoding::all::ASCII.encode(str, encoding::EncoderTrap::Strict).unwrap();
|
||||
let b = str.as_bytes();
|
||||
//let b = str.getBytes(StandardCharsets.US_ASCII);
|
||||
//decodedBytes.write(b, 0, b.length);
|
||||
@@ -430,7 +399,7 @@ fn correct_bits(
|
||||
// next codewordSize-1 bits are all zeros or all ones
|
||||
corrected_bits.splice(
|
||||
index..index + codeword_size - 1,
|
||||
vec![data_word > 1; codeword_size],
|
||||
vec![data_word > 1; codeword_size-1],
|
||||
);
|
||||
// Arrays.fill(correctedBits, index, index + codewordSize - 1, dataWord > 1);
|
||||
index += codeword_size - 1;
|
||||
|
||||
@@ -278,22 +278,7 @@ impl HighLevelEncoder {
|
||||
b':' if next_char == b' ' => 5,
|
||||
_ => 0,
|
||||
};
|
||||
// switch (text[index]) {
|
||||
// case '\r':
|
||||
// pairCode = nextChar == '\n' ? 2 : 0;
|
||||
// break;
|
||||
// case '.' :
|
||||
// pairCode = nextChar == ' ' ? 3 : 0;
|
||||
// break;
|
||||
// case ',' :
|
||||
// pairCode = nextChar == ' ' ? 4 : 0;
|
||||
// break;
|
||||
// case ':' :
|
||||
// pairCode = nextChar == ' ' ? 5 : 0;
|
||||
// break;
|
||||
// default:
|
||||
// pairCode = 0;
|
||||
// }
|
||||
|
||||
if pair_code > 0 {
|
||||
// We have one of the four special PUNCT pairs. Treat them specially.
|
||||
// Get a new set of states for the two new characters.
|
||||
|
||||
@@ -87,7 +87,6 @@ impl State {
|
||||
let eci_digits = encoding::all::ISO_8859_1
|
||||
.encode(&format!("{}", eci), encoding::EncoderTrap::Strict)
|
||||
.unwrap();
|
||||
dbg!(format!("{}", eci));
|
||||
// let eciDigits = Integer.toString(eci).getBytes(StandardCharsets.ISO_8859_1);
|
||||
token.add(eci_digits.len() as i32, 3); // 1-6: number of ECI digits
|
||||
for eci_digit in &eci_digits {
|
||||
|
||||
Reference in New Issue
Block a user