Skip to content

Commit

Permalink
Replace unmaitained encoding crate with encoding_rs (#222)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukáš Tyrychtr <ltyrycht@redhat.com>
  • Loading branch information
tyrylu and Lukáš Tyrychtr authored Mar 26, 2023
1 parent 74fcd67 commit 99cb2a4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ chrono = { version = "^0.4", optional = true, features = [
"std",
"clock",
], default-features = false }
encoding = "^0.2"
encoding_rs = "0.8.32"
flate2 = "^1.0"
image = { version = "^0.24", optional = true }
itoa = "^1.0"
Expand Down
7 changes: 3 additions & 4 deletions src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use super::encodings::{self, bytes_to_string, string_to_bytes};
use super::{Bookmark, Dictionary, Object, ObjectId};
use crate::xref::{Xref, XrefType};
use crate::{Error, Result, Stream};
use encoding::all::UTF_16BE;
use encoding::types::{DecoderTrap, EncoderTrap, Encoding};
use encoding_rs::UTF_16BE;
use log::info;
use std::cmp::max;
use std::collections::{BTreeMap, HashMap};
Expand Down Expand Up @@ -433,7 +432,7 @@ impl Document {
"MacRomanEncoding" => bytes_to_string(encodings::MAC_ROMAN_ENCODING, bytes),
"MacExpertEncoding" => bytes_to_string(encodings::MAC_EXPERT_ENCODING, bytes),
"WinAnsiEncoding" => bytes_to_string(encodings::WIN_ANSI_ENCODING, bytes),
"UniGB-UCS2-H" | "UniGB−UTF16−H" => UTF_16BE.decode(bytes, DecoderTrap::Ignore).unwrap(),
"UniGB-UCS2-H" | "UniGB−UTF16−H" => UTF_16BE.decode(bytes).0.to_string(),
"Identity-H" => "?Identity-H Unimplemented?".to_string(), // Unimplemented
_ => String::from_utf8_lossy(bytes).to_string(),
}
Expand All @@ -449,7 +448,7 @@ impl Document {
"MacRomanEncoding" => string_to_bytes(encodings::MAC_ROMAN_ENCODING, text),
"MacExpertEncoding" => string_to_bytes(encodings::MAC_EXPERT_ENCODING, text),
"WinAnsiEncoding" => string_to_bytes(encodings::WIN_ANSI_ENCODING, text),
"UniGB-UCS2-H" | "UniGB−UTF16−H" => UTF_16BE.encode(text, EncoderTrap::Ignore).unwrap(),
"UniGB-UCS2-H" | "UniGB−UTF16−H" => UTF_16BE.encode(text).0.to_vec(),
"Identity-H" => vec![], // Unimplemented
_ => text.as_bytes().to_vec(),
}
Expand Down

2 comments on commit 99cb2a4

@jymchng
Copy link

@jymchng jymchng commented on 99cb2a4 Apr 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to fix replace_text(...) for pdfs made with Microsoft Word? #223 #217

@J-F-Liu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

Please sign in to comment.