Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy run #160

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ base64 = "0.22.1"
pico-args = "0.5"
tiny-skia-path = "0.11.4"
xmlwriter = "0.1"
bencher = "0.1"
asibahi marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 4 additions & 2 deletions examples/font2svg.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::too_many_arguments)]

use base64::engine::general_purpose::STANDARD;

use std::io::Write;
Expand Down Expand Up @@ -167,7 +169,7 @@ fn process(args: Args) -> Result<(), Box<dyn std::error::Error>> {
&mut svg,
&mut path_buf,
);
} else if let Some(img) = face.glyph_raster_image(gid, std::u16::MAX) {
} else if let Some(img) = face.glyph_raster_image(gid, u16::MAX) {
svg.start_element("image");
svg.write_attribute("x", &(x + 2.0 + img.x as f64));
svg.write_attribute("y", &(y - img.y as f64));
Expand Down Expand Up @@ -208,7 +210,7 @@ fn process(args: Args) -> Result<(), Box<dyn std::error::Error>> {

println!("Elapsed: {}ms", now.elapsed().as_micros() as f64 / 1000.0);

std::fs::write(&args.svg_path, &svg.end_document())?;
std::fs::write(&args.svg_path, svg.end_document())?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/aat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<'a> StateTable<'a> {
#[inline]
pub fn class(&self, glyph_id: GlyphId) -> Option<u8> {
if glyph_id.0 == 0xFFFF {
return Some(class::DELETED_GLYPH as u8);
return Some(class::DELETED_GLYPH);
}

let idx = glyph_id.0.checked_sub(self.first_glyph.0)?;
Expand All @@ -185,7 +185,7 @@ impl<'a> StateTable<'a> {
#[inline]
pub fn entry(&self, state: u16, mut class: u8) -> Option<StateEntry> {
if u16::from(class) >= self.number_of_classes {
class = class::OUT_OF_BOUNDS as u8;
class = class::OUT_OF_BOUNDS;
}

let entry_idx = self
Expand Down
2 changes: 1 addition & 1 deletion src/delta_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<'a> DeltaSetIndexMap<'a> {
let entry_size = ((entry_format >> 4) & 3) + 1;
let inner_index_bit_count = u32::from((entry_format & 0xF) + 1);

s.advance(usize::try_from(entry_size).ok()? * usize::try_from(index).ok()?);
s.advance(usize::from(entry_size) * usize::try_from(index).ok()?);

let mut n = 0u32;
for b in s.read_bytes(usize::from(entry_size))? {
Expand Down
17 changes: 9 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Font parsing starts with a [`Face`].
#![allow(clippy::collapsible_else_if)]
#![allow(clippy::field_reassign_with_default)]
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::bool_assert_comparison)]

#[cfg(feature = "std")]
#[macro_use]
Expand Down Expand Up @@ -368,19 +369,19 @@ impl RectF {
#[inline]
fn new() -> Self {
RectF {
x_min: core::f32::MAX,
y_min: core::f32::MAX,
x_max: core::f32::MIN,
y_max: core::f32::MIN,
x_min: f32::MAX,
y_min: f32::MAX,
x_max: f32::MIN,
y_max: f32::MIN,
}
}

#[inline]
fn is_default(&self) -> bool {
self.x_min == core::f32::MAX
&& self.y_min == core::f32::MAX
&& self.x_max == core::f32::MIN
&& self.y_max == core::f32::MIN
self.x_min == f32::MAX
&& self.y_min == f32::MAX
&& self.x_max == f32::MIN
&& self.y_max == f32::MIN
}

#[inline]
Expand Down
10 changes: 5 additions & 5 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ impl TryNumFrom<f32> for i32 {

// We can't represent `MIN-1` exactly, but there's no fractional part
// at this magnitude, so we can just use a `MIN` inclusive boundary.
const MIN: f32 = core::i32::MIN as f32;
const MIN: f32 = i32::MIN as f32;
// We can't represent `MAX` exactly, but it will round up to exactly
// `MAX+1` (a power of two) when we cast it.
const MAX_P1: f32 = core::i32::MAX as f32;
const MAX_P1: f32 = i32::MAX as f32;
if v >= MIN && v < MAX_P1 {
Some(v as i32)
} else {
Expand Down Expand Up @@ -372,7 +372,7 @@ impl<'a, T: FromData> LazyArray16<'a, T> {

impl<'a, T: FromData + core::fmt::Debug + Copy> core::fmt::Debug for LazyArray16<'a, T> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_list().entries(self.into_iter()).finish()
f.debug_list().entries(*self).finish()
}
}

Expand Down Expand Up @@ -522,7 +522,7 @@ impl<'a, T: FromData> LazyArray32<'a, T> {

impl<'a, T: FromData + core::fmt::Debug + Copy> core::fmt::Debug for LazyArray32<'a, T> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_list().entries(self.into_iter()).finish()
f.debug_list().entries(*self).finish()
}
}

Expand Down Expand Up @@ -622,7 +622,7 @@ impl<'a, T: FromSlice<'a>> LazyOffsetArray16<'a, T> {

impl<'a, T: FromSlice<'a> + core::fmt::Debug + Copy> core::fmt::Debug for LazyOffsetArray16<'a, T> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_list().entries(self.into_iter()).finish()
f.debug_list().entries(*self).finish()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/tables/cff/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn parse_index<'a, T: IndexSize>(s: &mut Stream<'a>) -> Option<Index<'a>> {

#[inline(never)]
fn parse_index_impl<'a>(count: u32, s: &mut Stream<'a>) -> Option<Index<'a>> {
if count == 0 || count == core::u32::MAX {
if count == 0 || count == u32::MAX {
return Some(Index::default());
}

Expand Down Expand Up @@ -53,7 +53,7 @@ pub fn skip_index<T: IndexSize>(s: &mut Stream) -> Option<()> {

#[inline(never)]
fn skip_index_impl(count: u32, s: &mut Stream) -> Option<()> {
if count == 0 || count == core::u32::MAX {
if count == 0 || count == u32::MAX {
return Some(());
}

Expand Down
2 changes: 0 additions & 2 deletions src/tables/cmap/format2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ impl<'a> Subtable2<'a> {
pub fn glyph_index(&self, code_point: u32) -> Option<GlyphId> {
// This subtable supports code points only in a u16 range.
let code_point = u16::try_from(code_point).ok()?;

let code_point = code_point;
let high_byte = code_point >> 8;
let low_byte = code_point & 0x00FF;

Expand Down
4 changes: 2 additions & 2 deletions src/tables/colr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1897,8 +1897,8 @@ impl VariationData<'_> {

let variation_store = self.variation_store.as_ref().unwrap();

for i in 0..N {
deltas[i] = self
for (i, delta) in deltas.iter_mut().enumerate() {
*delta = self
.delta_map
.and_then(|d| d.map(var_index_base + i as u32))
.and_then(|d| variation_store.parse_delta(d.0, d.1, coordinates))
Expand Down
2 changes: 1 addition & 1 deletion src/tables/cpal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'a> Table<'a> {
/// Returns the number of palettes.
pub fn palettes(&self) -> NonZeroU16 {
// Already checked during parsing.
NonZeroU16::new(self.color_indices.len() as u16).unwrap()
NonZeroU16::new(self.color_indices.len()).unwrap()
}

/// Returns the color at the given index into the given palette.
Expand Down
2 changes: 1 addition & 1 deletion src/tables/feat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<'a> FeatureNames<'a> {

impl<'a> core::fmt::Debug for FeatureNames<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_list().entries(self.into_iter()).finish()
f.debug_list().entries(*self).finish()
}
}

Expand Down
13 changes: 5 additions & 8 deletions src/tables/gvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use core::cmp;
use core::convert::TryFrom;
use core::num::NonZeroU16;

use crate::{glyf, PhantomPoints, PointF};
use crate::parser::{LazyArray16, Offset, Offset16, Offset32, Stream, F2DOT14};
use crate::{glyf, PhantomPoints, PointF};
use crate::{GlyphId, NormalizedCoordinate, OutlineBuilder, Rect, RectF, Transform};

/// 'The TrueType rasterizer dynamically generates 'phantom' points for each glyph
Expand Down Expand Up @@ -525,7 +525,7 @@ mod packed_points {
// Check that points data size is smaller than the storage type
// used by the iterator.
let data_len = s.offset() - start;
if data_len > usize::from(core::u16::MAX) {
if data_len > usize::from(u16::MAX) {
return None;
}

Expand Down Expand Up @@ -792,16 +792,13 @@ mod packed_points {
deltas_are_words: false,
run_count: 100,
}));
for _ in 0..100 {
data.push(2);
}
data.extend([2; 100]);

data.push(gen_control(NewControl {
deltas_are_words: false,
run_count: 50,
}));
for _ in 0..50 {
data.push(2);
}
data.extend([2; 50]);

let points_iter = PackedPointsIter::new(&mut Stream::new(&data))
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion src/tables/kerx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl<'a> Subtable6<'a> {
.value(right)
.unwrap_or(0);

let array_offset = usize::try_from(l + r).ok()?.checked_mul(i16::SIZE)?;
let array_offset = usize::from(l + r).checked_mul(i16::SIZE)?;
let vector_offset: u16 = Stream::read_at(kerning_array_data, array_offset)?;

Stream::read_at(kerning_vector_data, usize::from(vector_offset))
Expand Down
4 changes: 2 additions & 2 deletions src/tables/loca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'a> Table<'a> {
// The number of ranges is `maxp.numGlyphs + 1`.
//
// Check for overflow first.
let mut total = if number_of_glyphs.get() == core::u16::MAX {
let mut total = if number_of_glyphs.get() == u16::MAX {
number_of_glyphs.get()
} else {
number_of_glyphs.get() + 1
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<'a> Table<'a> {
#[inline]
pub fn glyph_range(&self, glyph_id: GlyphId) -> Option<Range<usize>> {
let glyph_id = glyph_id.0;
if glyph_id == core::u16::MAX {
if glyph_id == u16::MAX {
return None;
}

Expand Down
2 changes: 1 addition & 1 deletion src/var_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<'a> ItemVariationStore<'a> {
// if the LONG_WORDS flag is not set, or 2 x that amount if the flag is set.
let mut delta_set_len = word_delta_count + region_index_count;
if has_long_words {
delta_set_len = delta_set_len * 2;
delta_set_len *= 2;
}

s.advance(usize::from(inner_index).checked_mul(usize::from(delta_set_len))?);
Expand Down
2 changes: 2 additions & 0 deletions tests/tables/feat.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::bool_assert_comparison)]

use ttf_parser::feat::Table;
use crate::{convert, Unit::*};

Expand Down
8 changes: 4 additions & 4 deletions tests/tables/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn tables_count_overflow() {
use Unit::*;
let data = convert(&[
Raw(&[0x00, 0x01, 0x00, 0x00]), // magic
UInt16(std::u16::MAX), // numTables
UInt16(u16::MAX), // numTables
UInt16(0), // searchRange
UInt16(0), // entrySelector
UInt16(0), // rangeShift
Expand Down Expand Up @@ -129,10 +129,10 @@ fn font_collection_num_fonts_overflow() {
Raw(&[0x74, 0x74, 0x63, 0x66]), // magic
UInt16(0), // majorVersion
UInt16(0), // minorVersion
UInt32(std::u32::MAX), // numFonts
UInt32(u32::MAX), // numFonts
]);

assert_eq!(fonts_in_collection(&data), Some(std::u32::MAX));
assert_eq!(fonts_in_collection(&data), Some(u32::MAX));
assert_eq!(
Face::parse(&data, 0).unwrap_err(),
FaceParsingError::MalformedFont
Expand All @@ -152,7 +152,7 @@ fn font_index_overflow() {

assert_eq!(fonts_in_collection(&data), Some(1));
assert_eq!(
Face::parse(&data, std::u32::MAX).unwrap_err(),
Face::parse(&data, u32::MAX).unwrap_err(),
FaceParsingError::FaceIndexOutOfBounds
);
}
Expand Down