correct cmap algorithm
This commit is contained in:
parent
7cbb264410
commit
e56b950cb2
|
@ -67,6 +67,7 @@ impl SegmentToDelta {
|
||||||
debug!("First endcode that is >={c} has index {index} (={})", self.end_code[index]);
|
debug!("First endcode that is >={c} has index {index} (={})", self.end_code[index]);
|
||||||
|
|
||||||
if self.start_code[index] > c {
|
if self.start_code[index] > c {
|
||||||
|
error!("Start code belonging to this index ({}) is too big", self.start_code[index]);
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ impl FontTable for MaximumProfile {
|
||||||
debug!("maxp table version: {:#08x}", version);
|
debug!("maxp table version: {:#08x}", version);
|
||||||
|
|
||||||
match version {
|
match version {
|
||||||
0x00005000 => todo!(),
|
0x00005000 => Ok(MaximumProfile::V0_5(deserialize(reader.by_ref())?)),
|
||||||
0x00010000 => Ok(MaximumProfile::V1_0(deserialize(reader.by_ref())?)),
|
0x00010000 => Ok(MaximumProfile::V1_0(deserialize(reader.by_ref())?)),
|
||||||
_ => { return Err(bincode::ErrorKind::Custom("Invalid maxp table version".into()).into()); }
|
_ => { return Err(bincode::ErrorKind::Custom("Invalid maxp table version".into()).into()); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,28 @@ impl SearchParameters {
|
||||||
for level in 1..=self.entry_selector {
|
for level in 1..=self.entry_selector {
|
||||||
let end_code = array[index];
|
let end_code = array[index];
|
||||||
|
|
||||||
if end_code == target {
|
if end_code >= target && array[index - 1] < target {
|
||||||
|
debug!("binary search found result");
|
||||||
return Some(index);
|
return Some(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut correction = (self.search_range >> (level + 2)) as usize;
|
||||||
|
if correction == 0 {
|
||||||
|
correction = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if end_code < target {
|
if end_code < target {
|
||||||
index += (self.search_range >> (level + 2)) as usize;
|
index += correction;
|
||||||
|
debug!("considered endcode smaller than target, setting index to {index}");
|
||||||
} else {
|
} else {
|
||||||
index -= (self.search_range >> (level + 2)) as usize;
|
let new_index = index - correction;
|
||||||
|
if correction == 1 && array[new_index] < target {
|
||||||
|
debug!("no more candidates");
|
||||||
|
return Some(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
index = new_index;
|
||||||
|
debug!("considered endcode larger than target, setting index to {index}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +52,12 @@ impl SearchParameters {
|
||||||
|
|
||||||
if target > array[(self.search_range as usize >> 1) - 1] {
|
if target > array[(self.search_range as usize >> 1) - 1] {
|
||||||
debug!("{}", array[(self.search_range as usize >> 1) - 1]);
|
debug!("{}", array[(self.search_range as usize >> 1) - 1]);
|
||||||
todo!()
|
|
||||||
|
for i in (self.search_range as usize >> 1)..array.len() {
|
||||||
|
if array[i] >= target {
|
||||||
|
return Some(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.binary_search(array, target)
|
self.binary_search(array, target)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::{collections::HashMap, fs::File, io::{BufReader, Read, Seek, SeekFrom}};
|
use std::{collections::HashMap, fs::File, io::{BufReader, Read, Seek, SeekFrom}};
|
||||||
|
|
||||||
use bincode::Result;
|
use bincode::Result;
|
||||||
|
use log::debug;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::font::deserialize;
|
use crate::font::deserialize;
|
||||||
|
@ -25,6 +26,7 @@ pub struct TableDirectory(pub HashMap<u32, TableDirectoryRecord>);
|
||||||
impl TableDirectory {
|
impl TableDirectory {
|
||||||
pub fn new<R: Read + Seek>(reader: &mut R) -> Result<TableDirectory> {
|
pub fn new<R: Read + Seek>(reader: &mut R) -> Result<TableDirectory> {
|
||||||
let header: TableDirectoryHeader = deserialize(reader.by_ref())?;
|
let header: TableDirectoryHeader = deserialize(reader.by_ref())?;
|
||||||
|
debug!("{header:#x?}");
|
||||||
let mut tables: HashMap<u32, TableDirectoryRecord> = HashMap::with_capacity(header.num_tables as usize);
|
let mut tables: HashMap<u32, TableDirectoryRecord> = HashMap::with_capacity(header.num_tables as usize);
|
||||||
|
|
||||||
reader.seek_relative(3 * size_of::<u16>() as i64)?;
|
reader.seek_relative(3 * size_of::<u16>() as i64)?;
|
||||||
|
|
Loading…
Reference in a new issue