Skip to content

Commit

Permalink
Fix some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed May 20, 2024
1 parent 0f0cd76 commit 5c123aa
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 61 deletions.
15 changes: 0 additions & 15 deletions src/cff/argstack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ impl<'a> ArgumentsStack<'a> {
self.data.len()
}

#[inline]
pub fn is_empty(&self) -> bool {
self.data.len() == 0
}

#[inline]
pub fn push(&mut self, n: Number<'a>) -> Result<()> {
if self.len() == MAX_OPERANDS_LEN {
Expand All @@ -33,11 +28,6 @@ impl<'a> ArgumentsStack<'a> {
}
}

#[inline]
pub fn at(&self, index: usize) -> Number {
self.data[index].clone()
}

#[inline]
pub fn pop(&mut self) -> Option<Number> {
self.data.pop()
Expand All @@ -49,9 +39,4 @@ impl<'a> ArgumentsStack<'a> {
std::mem::swap(&mut self.data, &mut ret_vec);
ret_vec
}

#[inline]
pub fn clear(&mut self) {
self.data.clear()
}
}
36 changes: 0 additions & 36 deletions src/cff/charstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use operators::*;
use std::fmt::{Debug, Formatter};

pub type CharString<'a> = &'a [u8];
pub type OwnedCharString = Vec<u8>;

pub struct Decompiler<'a> {
gsubr_handler: SubroutineHandler<'a>,
Expand Down Expand Up @@ -190,14 +189,6 @@ impl Debug for Program<'_> {
}

impl<'a> Program<'a> {
pub fn instructions(&self) -> &[Instruction<'a>] {
self.0.as_ref()
}

pub fn pop(&mut self) -> Option<Instruction> {
self.0.pop()
}

pub fn push(&mut self, instruction: Instruction<'a>) {
self.0.push(instruction);
}
Expand All @@ -221,33 +212,6 @@ impl<'a> Program<'a> {

w.finish()
}

pub fn len(&self) -> usize {
self.0.len()
}
}

pub fn calc_subroutine_bias(len: u32) -> u16 {
if len < 1240 {
107
} else if len < 33900 {
1131
} else {
32768
}
}

pub fn unapply_bias(index: i32, bias: u16) -> Option<u32> {
let bias = i32::from(bias);

let index = index.checked_add(bias)?;
u32::try_from(index).ok()
}

pub fn apply_bias(index: i32, bias: u16) -> Option<i32> {
let bias = i32::from(bias);

index.checked_sub(bias)
}

#[allow(dead_code)]
Expand Down
2 changes: 1 addition & 1 deletion src/cff/dict/font_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::cff::dict::DictionaryParser;
use crate::cff::index::{create_index, parse_index, Index};
use crate::cff::remapper::{FontDictRemapper, SidRemapper};
use crate::cff::types::{Number, StringId};
use crate::cff::{dict, CIDWriteContext, FontWriteContext};
use crate::cff::{dict, FontWriteContext};
use crate::read::Reader;
use crate::write::Writer;
use crate::Error::{MalformedFont, SubsetError};
Expand Down
2 changes: 1 addition & 1 deletion src/cff/dict/top_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::cff::dict::DictionaryParser;
use crate::cff::index::{create_index, parse_index};
use crate::cff::remapper::SidRemapper;
use crate::cff::types::{Number, StringId};
use crate::cff::{dict, FontWriteContext};
use crate::cff::FontWriteContext;
use crate::read::Reader;
use crate::write::Writer;
use crate::Error::SubsetError;
Expand Down
14 changes: 6 additions & 8 deletions src/cff/remapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@ mod tests {
let mut sid_remapper = SidRemapper::new();
assert_eq!(sid_remapper.remap(StringId(5)), StringId(5));
assert_eq!(sid_remapper.remap(StringId(100)), StringId(100));
assert_eq!(sid_remapper.remap(StringId(400)), StringId(392));
assert_eq!(sid_remapper.remap(StringId(395)), StringId(393));
assert_eq!(sid_remapper.remap(StringId(502)), StringId(394));
assert_eq!(sid_remapper.remap(StringId(400)), StringId(391));
assert_eq!(sid_remapper.remap(StringId(395)), StringId(392));
assert_eq!(sid_remapper.remap(StringId(502)), StringId(393));
assert_eq!(sid_remapper.remap(StringId(156)), StringId(156));
assert_eq!(sid_remapper.remap(StringId(480)), StringId(395));
assert_eq!(sid_remapper.remap(StringId(400)), StringId(392));
// TODO: Add edge case

assert_eq!(sid_remapper.get(StringId(395)), Some(StringId(393)));
assert_eq!(sid_remapper.remap(StringId(480)), StringId(394));
assert_eq!(sid_remapper.remap(StringId(400)), StringId(391));
assert_eq!(sid_remapper.get(StringId(395)), Some(StringId(392)));

assert_eq!(
sid_remapper.sids().collect::<Vec<_>>(),
Expand Down

0 comments on commit 5c123aa

Please sign in to comment.