Skip to content

Commit

Permalink
Revert "Make WOFF2 brotli decoding optional"
Browse files Browse the repository at this point in the history
This reverts commit cc042e8.
  • Loading branch information
fschutt committed Feb 22, 2025
1 parent 556038e commit f807dd1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 36 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ categories = ["text-processing"]
[dependencies]
bitflags = "1.3"
bitreader = "0.3.6"
brotli-decompressor = "2.3"
byteorder = "1.4"
crc32fast = "1.3.2"
encoding_rs = "0.8.32"
Expand All @@ -40,7 +41,6 @@ unicode-joining-type = "0.7.0"
# specimen
upon = { version = "0.8.1", default-features = false, optional = true }
unicode-blocks = { version = "0.1.9", optional = true }
brotli-decompressor = { version = "2.3", optional = true }

[dev-dependencies]
regex = "1.7.1"
Expand All @@ -56,10 +56,9 @@ regex = "1.7.1"
# harness = false

[features]
default = ["outline", "flate2_zlib", "brotli"]
default = ["outline", "flate2_zlib"]
prince = []
outline = []
brotli = ["brotli-decompressor"]
specimen = ["dep:upon", "dep:unicode-blocks"]
flate2_zlib = ["flate2/zlib"]
flate2_rust = ["flate2/rust_backend"]
2 changes: 0 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pub enum ParseError {
CompressionError,
UnsuitableCmap,
NotImplemented,
BrotliFeatureNotEnabled,
}

impl From<ReadEof> for ParseError {
Expand Down Expand Up @@ -90,7 +89,6 @@ impl fmt::Display for ParseError {
ParseError::CompressionError => write!(f, "compression error"),
ParseError::UnsuitableCmap => write!(f, "no suitable cmap subtable"),
ParseError::NotImplemented => write!(f, "feature not implemented"),
ParseError::BrotliFeatureNotEnabled => write!(f, "allsorts was built without --feature=brotli to include the brotli decompressor for woff2 fonts"),
}
}
}
Expand Down
43 changes: 12 additions & 31 deletions src/woff2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,14 @@ impl<'a> Woff2Font<'a> {

let compressed_metadata = self.scope.offset_length(offset, length)?;

let mut input = brotli_decompressor::Decompressor::new(
Cursor::new(compressed_metadata.data()),
BROTLI_DECODER_BUFFER_SIZE,
);
let mut metadata = String::new();


#[cfg(not(feature = "brotli"))] {
return Err(ParseError::BrotliFeatureNotEnabled);

}

#[cfg(feature = "brotli")] {

let mut input = brotli_decompressor::Decompressor::new(
Cursor::new(compressed_metadata.data()),
BROTLI_DECODER_BUFFER_SIZE,
);

input
input
.read_to_string(&mut metadata)
.map_err(|_err| ParseError::CompressionError)?;
}

Ok(Some(metadata))
}
Expand Down Expand Up @@ -225,22 +214,14 @@ impl<'b> ReadBinary for Woff2Font<'b> {
// Read compressed font table data
let compressed_data =
ctxt.read_slice(usize::try_from(woff_header.total_compressed_size)?)?;

#[cfg(not(feature = "brotli"))] {
return Err(ParseError::BrotliFeatureNotEnabled);
}

let mut input = brotli_decompressor::Decompressor::new(
Cursor::new(compressed_data),
BROTLI_DECODER_BUFFER_SIZE,
);
let mut table_data_block = Vec::new();

#[cfg(feature = "brotli")] {
let mut input = brotli_decompressor::Decompressor::new(
Cursor::new(compressed_data),
BROTLI_DECODER_BUFFER_SIZE,
);
input
.read_to_end(&mut table_data_block)
.map_err(|_err| ParseError::CompressionError)?;
}
input
.read_to_end(&mut table_data_block)
.map_err(|_err| ParseError::CompressionError)?;

Ok(Woff2Font {
scope,
Expand Down

0 comments on commit f807dd1

Please sign in to comment.