Replacing non ISO-8859-1 characters in PDF417 input with '?' (#1514)

* Replacing non ISO-8859-1 characters in input with '?' when neither a character set nor multi-eci encoding is selected.

* Changed code to raise an exception for characters not encodeable in ISO-8859-1
This commit is contained in:
AlexGeller1 2022-04-27 16:46:49 +02:00 committed by GitHub
parent 8265242784
commit 5f20b8d095
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -171,6 +171,15 @@ final class PDF417HighLevelEncoder {
static String encodeHighLevel(String msg, Compaction compaction, Charset encoding, boolean autoECI)
throws WriterException {
if (encoding == null && !autoECI) {
for (int i = 0; i < msg.length(); i++) {
if (msg.charAt(i) > 255) {
throw new WriterException("Non-encodable character detected: " + msg.charAt(i) + " (Unicode: " +
(int) msg.charAt(i) +
"). Consider specifying EncodeHintType.PDF417_AUTO_ECI and/or EncodeTypeHint.CHARACTER_SET.");
}
}
}
//the codewords 0..928 are encoded as Unicode characters
StringBuilder sb = new StringBuilder(msg.length());