mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
move to using Eci enum
Decouples the Eci and CharacterSet concepts within the library. Character sets can now exist independently from Eci encodation schemes.
This commit is contained in:
@@ -19,7 +19,7 @@ use num::{self, bigint::ToBigUint, BigUint};
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::{
|
||||
common::{DecoderRXingResult, ECIStringBuilder, Result},
|
||||
common::{DecoderRXingResult, ECIStringBuilder, Result, Eci},
|
||||
pdf417::PDF417RXingResultMetadata,
|
||||
Exceptions,
|
||||
};
|
||||
@@ -128,7 +128,7 @@ pub fn decode(codewords: &[u32], ecLevel: &str) -> Result<DecoderRXingResult> {
|
||||
codeIndex = numericCompaction(codewords, codeIndex, &mut result)?
|
||||
}
|
||||
ECI_CHARSET => {
|
||||
result.appendECI(codewords[codeIndex])?;
|
||||
result.appendECI(Eci::from(codewords[codeIndex]))?;
|
||||
codeIndex += 1;
|
||||
}
|
||||
ECI_GENERAL_PURPOSE =>
|
||||
@@ -387,7 +387,7 @@ fn textCompaction(
|
||||
subMode,
|
||||
)
|
||||
.ok_or(Exceptions::ILLEGAL_STATE)?;
|
||||
result.appendECI(codewords[codeIndex])?;
|
||||
result.appendECI(Eci::from(codewords[codeIndex]))?;
|
||||
codeIndex += 1;
|
||||
textCompactionData = vec![0; (codewords[0] as usize - codeIndex) * 2];
|
||||
byteCompactionData = vec![0; (codewords[0] as usize - codeIndex) * 2];
|
||||
@@ -616,7 +616,7 @@ fn byteCompaction(
|
||||
//handle leading ECIs
|
||||
while codeIndex < codewords[0] as usize && codewords[codeIndex] == ECI_CHARSET {
|
||||
codeIndex += 1;
|
||||
result.appendECI(codewords[codeIndex])?;
|
||||
result.appendECI(Eci::from(codewords[codeIndex]))?;
|
||||
codeIndex += 1;
|
||||
}
|
||||
|
||||
@@ -654,7 +654,7 @@ fn byteCompaction(
|
||||
if code < TEXT_COMPACTION_MODE_LATCH {
|
||||
result.append_byte(code as u8);
|
||||
} else if code == ECI_CHARSET {
|
||||
result.appendECI(codewords[codeIndex])?;
|
||||
result.appendECI(Eci::from(codewords[codeIndex]))?;
|
||||
codeIndex += 1;
|
||||
} else {
|
||||
codeIndex -= 1;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
use std::{any::TypeId, fmt::Display, str::FromStr};
|
||||
|
||||
use crate::{
|
||||
common::{CharacterSet, ECIInput, MinimalECIInput, Result},
|
||||
common::{CharacterSet, ECIInput, MinimalECIInput, Result, Eci},
|
||||
Exceptions,
|
||||
};
|
||||
|
||||
@@ -205,7 +205,8 @@ pub fn encodeHighLevel(
|
||||
// }
|
||||
|
||||
encodingECI(
|
||||
CharacterSet::get_eci_value(&encoding.ok_or(Exceptions::ILLEGAL_STATE)?) as i32,
|
||||
Eci::from(encoding.ok_or(Exceptions::ILLEGAL_STATE)?),
|
||||
//CharacterSet::get_eci_value(&encoding.ok_or(Exceptions::ILLEGAL_STATE)?) as i32,
|
||||
&mut sb,
|
||||
)?;
|
||||
}
|
||||
@@ -797,17 +798,17 @@ fn determineConsecutiveBinaryCount<T: ECIInput + ?Sized + 'static>(
|
||||
Ok(idx as u32 - startpos)
|
||||
}
|
||||
|
||||
fn encodingECI(eci: i32, sb: &mut String) -> Result<()> {
|
||||
if (0..900).contains(&eci) {
|
||||
fn encodingECI(eci: Eci, sb: &mut String) -> Result<()> {
|
||||
if (0..900).contains(&(eci as i32)) {
|
||||
sb.push(char::from_u32(ECI_CHARSET).ok_or(Exceptions::PARSE)?);
|
||||
sb.push(char::from_u32(eci as u32).ok_or(Exceptions::PARSE)?);
|
||||
} else if eci < 810900 {
|
||||
} else if (eci as i32 )< 810900 {
|
||||
sb.push(char::from_u32(ECI_GENERAL_PURPOSE).ok_or(Exceptions::PARSE)?);
|
||||
sb.push(char::from_u32((eci / 900 - 1) as u32).ok_or(Exceptions::PARSE)?);
|
||||
sb.push(char::from_u32((eci % 900) as u32).ok_or(Exceptions::PARSE)?);
|
||||
} else if eci < 811800 {
|
||||
sb.push(char::from_u32(((eci as i32) / 900 - 1) as u32).ok_or(Exceptions::PARSE)?);
|
||||
sb.push(char::from_u32(((eci as i32) % 900) as u32).ok_or(Exceptions::PARSE)?);
|
||||
} else if (eci as i32) < 811800 {
|
||||
sb.push(char::from_u32(ECI_USER_DEFINED).ok_or(Exceptions::PARSE)?);
|
||||
sb.push(char::from_u32((810900 - eci) as u32).ok_or(Exceptions::PARSE)?);
|
||||
sb.push(char::from_u32((810900 - (eci as i32)) as u32).ok_or(Exceptions::PARSE)?);
|
||||
} else {
|
||||
return Err(Exceptions::writer_with(format!(
|
||||
"ECI number not in valid range from 0..811799, but was {eci}"
|
||||
@@ -838,8 +839,8 @@ impl ECIInput for NoECIInput {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
fn getECIValue(&self, _index: usize) -> Result<i32> {
|
||||
Ok(-1)
|
||||
fn getECIValue(&self, _index: usize) -> Result<Eci> {
|
||||
Ok(Eci::Unknown)
|
||||
}
|
||||
|
||||
fn haveNCharacters(&self, index: usize, n: usize) -> Result<bool> {
|
||||
|
||||
Reference in New Issue
Block a user