Skip to content

Commit

Permalink
Merge pull request #199 from barabadzhi/update-printpdf
Browse files Browse the repository at this point in the history
Misc updates
  • Loading branch information
fschutt authored Nov 15, 2024
2 parents 5109221 + 7da696b commit 1f08268
Show file tree
Hide file tree
Showing 17 changed files with 955 additions and 464 deletions.
883 changes: 690 additions & 193 deletions Cargo.lock

Large diffs are not rendered by default.

40 changes: 27 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,41 @@ autoexamples = false
edition = "2021"

[dependencies]
lopdf = { version = "0.33.0", default-features = false, features = ["pom_parser"] }
lopdf = { git = "https://github.com/J-F-Liu/lopdf", rev = "ea838e2252201bf0efe648b8954100b13835dae0", default-features = false, features = [
"nom_parser",
] }
time = { version = "0.3.25", default-features = false, features = ["std"] }
allsorts = { version = "0.15", default-features = false, features = ["flate2_rust"] }
pdf-writer = { version = "0.9" }
image = { version = "0.25", default-features = false}
svg2pdf = { version = "0.10" }
allsorts = { version = "0.15", default-features = false, features = [
"flate2_rust",
] }
pdf-writer = { version = "0.12.0" }
image = { version = "0.25", default-features = false }
svg2pdf = { version = "0.12.0" }
# dependencies for wasm demo
azul-css = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false }
azul-css-parser = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false }
azul-core = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false, features = ["std"] }
azul-layout = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false, features = ["std", "text_layout"] }
azul-text-layout = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false }
azulc = { git = "https://github.com/fschutt/azul", rev = "646b5e3030041aaebe06d2344a36bbed000c8674", default-features = false, features = ["std", "xml", "text_layout", "font_loading"] }
azul-css = { git = "https://github.com/fschutt/azul", rev = "6a69b69994d1b4cda89b61922233de88498878ef", default-features = false }
azul-css-parser = { git = "https://github.com/fschutt/azul", rev = "6a69b69994d1b4cda89b61922233de88498878ef", default-features = false }
azul-core = { git = "https://github.com/fschutt/azul", rev = "6a69b69994d1b4cda89b61922233de88498878ef", default-features = false, features = [
"std",
] }
azul-layout = { git = "https://github.com/fschutt/azul", rev = "6a69b69994d1b4cda89b61922233de88498878ef", default-features = false, features = [
"std",
"text_layout",
] }
azul-text-layout = { git = "https://github.com/fschutt/azul", rev = "6a69b69994d1b4cda89b61922233de88498878ef", default-features = false }
azulc = { git = "https://github.com/fschutt/azul", rev = "6a69b69994d1b4cda89b61922233de88498878ef", default-features = false, features = [
"std",
"xml",
"text_layout",
"font_loading",
] }
rust-fontconfig = { version = "0.1.13", default-features = false }
xmlparser = { version = "0.13.6", default-features = false }
serde = { version = "1" }
serde_derive = { version = "1" }
serde_json = { version = "1" }
wasm-bindgen = { version = "0.2" }
base64 = "0.22.1"
flate2 = "1.0.23"
flate2 = "1.0.35"

[features]
default = ["js-sys"]
Expand All @@ -52,7 +66,7 @@ tga = ["image/tga"]
hdr = ["image/hdr"]
dds = ["image/dds"]
webp = ["image/webp"]
rayon = ["image/rayon"] # enables multithreading for decoding images
rayon = ["image/rayon"] # enables multithreading for decoding images
js-sys = ["dep:js-sys"] # enables js-sys features on wasm

[package.metadata.docs.rs]
Expand Down
22 changes: 11 additions & 11 deletions defaultfonts/mapping.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const FONTS: &[(usize, u16, u16, char);1483] = &[
(8, 3, 0, ' '),
(8, 16, 1, '­'),
(8, 16, 1, '\u{AD}'),
(8, 98, 2, 'Ä'),
(8, 99, 3, 'Å'),
(8, 100, 4, 'Ç'),
Expand Down Expand Up @@ -123,7 +123,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[
(8, 257, 121, '·'),
(8, 1127, 122, '¤'),
(9, 3, 0, ' '),
(9, 16, 1, '­'),
(9, 16, 1, '\u{AD}'),
(9, 98, 2, 'Ä'),
(9, 99, 3, 'Å'),
(9, 100, 4, 'Ç'),
Expand Down Expand Up @@ -246,7 +246,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[
(9, 256, 121, '¯'),
(9, 750, 122, '¤'),
(10, 3, 0, ' '),
(10, 16, 1, '­'),
(10, 16, 1, '\u{AD}'),
(10, 98, 2, 'Ä'),
(10, 99, 3, 'Å'),
(10, 100, 4, 'Ç'),
Expand Down Expand Up @@ -499,7 +499,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[
(4, 108, 10, 'ª'),
(4, 109, 11, '«'),
(4, 110, 12, '¬'),
(4, 111, 13, '­'),
(4, 111, 13, '\u{AD}'),
(4, 112, 14, '®'),
(4, 113, 15, '¯'),
(4, 114, 16, '°'),
Expand Down Expand Up @@ -622,7 +622,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[
(5, 108, 10, 'ª'),
(5, 109, 11, '«'),
(5, 110, 12, '¬'),
(5, 111, 13, '­'),
(5, 111, 13, '\u{AD}'),
(5, 112, 14, '®'),
(5, 113, 15, '¯'),
(5, 114, 16, '°'),
Expand Down Expand Up @@ -745,7 +745,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[
(6, 108, 10, 'ª'),
(6, 109, 11, '«'),
(6, 110, 12, '¬'),
(6, 111, 13, '­'),
(6, 111, 13, '\u{AD}'),
(6, 112, 14, '®'),
(6, 113, 15, '¯'),
(6, 114, 16, '°'),
Expand Down Expand Up @@ -868,7 +868,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[
(7, 108, 10, 'ª'),
(7, 109, 11, '«'),
(7, 110, 12, '¬'),
(7, 111, 13, '­'),
(7, 111, 13, '\u{AD}'),
(7, 112, 14, '®'),
(7, 113, 15, '¯'),
(7, 114, 16, '°'),
Expand Down Expand Up @@ -992,7 +992,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[
(12, 147, 17, '™'),
(12, 151, 18, '¬'),
(0, 3, 0, ' '),
(0, 16, 1, '­'),
(0, 16, 1, '\u{AD}'),
(0, 98, 2, 'Ä'),
(0, 99, 3, 'Å'),
(0, 100, 4, 'Ç'),
Expand Down Expand Up @@ -1115,7 +1115,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[
(0, 256, 121, '¯'),
(0, 862, 122, '¤'),
(1, 3, 0, ' '),
(1, 16, 1, '­'),
(1, 16, 1, '\u{AD}'),
(1, 98, 2, 'Ä'),
(1, 99, 3, 'Å'),
(1, 100, 4, 'Ç'),
Expand Down Expand Up @@ -1238,7 +1238,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[
(1, 256, 121, '¯'),
(1, 862, 122, '¤'),
(2, 3, 0, ' '),
(2, 16, 1, '­'),
(2, 16, 1, '\u{AD}'),
(2, 98, 2, 'Ä'),
(2, 99, 3, 'Å'),
(2, 100, 4, 'Ç'),
Expand Down Expand Up @@ -1358,7 +1358,7 @@ const FONTS: &[(usize, u16, u16, char);1483] = &[
(2, 218, 118, '¯'),
(2, 219, 119, '·'),
(3, 3, 0, ' '),
(3, 16, 1, '­'),
(3, 16, 1, '\u{AD}'),
(3, 98, 2, 'Ä'),
(3, 99, 3, 'Å'),
(3, 100, 4, 'Ç'),
Expand Down
2 changes: 1 addition & 1 deletion examples/html.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use printpdf::*;

const HTML_STRINGS: &[&str;1] = &[
const HTML_STRINGS: &[&str; 1] = &[
// "<div style='background:red;padding:10px;'><div style='background:yellow;padding:20px;'></div></div>",
"<p style='color:red;font-family:sans-serif'>Hello!</p>",
];
Expand Down
6 changes: 3 additions & 3 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ fn main() {
let transform = XObjectTransform {
rotate: Some(XObjectRotation {
angle_ccw_degrees: i as f32 * 36.0,
rotation_center_x: rotation_center_x,
rotation_center_y: rotation_center_y,
rotation_center_x,
rotation_center_y,
}),
translate_x: Some(Mm(i as f32 * 20.0 % 50.0).into()),
translate_y: Some(Mm(i as f32 * 30.0).into()),
Expand All @@ -155,7 +155,7 @@ fn main() {

ops.extend_from_slice(&[Op::UseXObject {
id: xobject_id.clone(),
transform: transform,
transform,
}]);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/subset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn main() {
env!("CARGO_MANIFEST_DIR"),
name.get_id()
),
&printpdf::compress(&subset.bytes),
printpdf::compress(&subset.bytes),
);
for (old_gid, (new_gid, char)) in subset.glyph_mapping.iter() {
target_map.push(format!(
Expand Down
9 changes: 2 additions & 7 deletions src/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,15 @@ impl Actions {
}
}

#[derive(Debug, PartialEq, Clone, Copy)]
#[derive(Debug, PartialEq, Clone, Copy, Default)]
pub enum HighlightingMode {
None,
#[default]
Invert,
Outline,
Push,
}

impl Default for HighlightingMode {
fn default() -> Self {
HighlightingMode::Invert
}
}

impl HighlightingMode {
pub fn get_id(&self) -> &'static str {
use self::HighlightingMode::*;
Expand Down
58 changes: 25 additions & 33 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,10 @@ impl ParsedFont {

for (glyph_id, unicode) in glyph_ids.iter() {
// end the current (beginbfchar endbfchar) block if necessary
if (*glyph_id >> 8) as u16 != cur_first_bit || current_cmap_block.len() >= 100 {
if (*glyph_id >> 8) != cur_first_bit || current_cmap_block.len() >= 100 {
all_cmap_blocks.push(current_cmap_block.clone());
current_cmap_block = Vec::new();
cur_first_bit = (*glyph_id >> 8) as u16;
cur_first_bit = *glyph_id >> 8;
}

current_cmap_block.push((*glyph_id, *unicode as u32));
Expand Down Expand Up @@ -429,7 +429,7 @@ impl ParsedFont {
} else {
// non-subsequent GID
widths_list.push(Integer(current_low_gid as i64));
widths_list.push(Array(current_width_vec.drain(..).collect()));
widths_list.push(Array(std::mem::take(&mut current_width_vec)));

current_width_vec.push(Integer((width as f32 * percentage_font_scaling) as i64));
current_low_gid = *gid;
Expand All @@ -439,7 +439,7 @@ impl ParsedFont {

// push the last widths, because the loop is delayed by one iteration
widths_list.push(Integer(current_low_gid as i64));
widths_list.push(Array(current_width_vec.drain(..).collect()));
widths_list.push(Array(std::mem::take(&mut current_width_vec)));

widths_list
/*
Expand Down Expand Up @@ -534,14 +534,6 @@ struct GlyphOutlineBuilder {
operations: Vec<GlyphOutlineOperation>,
}

impl Default for GlyphOutlineBuilder {
fn default() -> Self {
GlyphOutlineBuilder {
operations: Vec::new(),
}
}
}

/*
impl ttf_parser::OutlineBuilder for GlyphOutlineBuilder {
fn move_to(&mut self, x: f32, y: f32) { self.operations.push(GlyphOutlineOperation::MoveTo(OutlineMoveTo { x, y })); }
Expand Down Expand Up @@ -569,7 +561,7 @@ pub struct OwnedGlyph {
}

impl OwnedGlyph {
fn from_glyph_data<'a>(glyph: &Glyph<'a>, horz_advance: u16) -> Option<Self> {
fn from_glyph_data(glyph: &Glyph<'_>, horz_advance: u16) -> Option<Self> {
let bbox = glyph.bounding_box()?;
Some(Self {
bounding_box: OwnedGlyphBoundingBox {
Expand Down Expand Up @@ -615,7 +607,7 @@ impl ParsedFont {
let loca_table = loca_table
.as_ref()
.and_then(|loca_data| {
ReadScope::new(&loca_data.as_ref()?)
ReadScope::new(loca_data.as_ref()?)
.read_dep::<LocaTable<'_>>((num_glyphs, index_to_loc))
.ok()
})
Expand All @@ -627,7 +619,7 @@ impl ParsedFont {
let mut glyf_table = glyf_table
.as_ref()
.and_then(|glyf_data| {
ReadScope::new(&glyf_data.as_ref()?)
ReadScope::new(glyf_data.as_ref()?)
.read_dep::<GlyfTable<'_>>(&loca_table)
.ok()
})
Expand Down Expand Up @@ -656,7 +648,7 @@ impl ParsedFont {
// not parsing glyph outlines can save lots of memory
let glyph_records_decoded = glyf_table
.records_mut()
.into_iter()
.iter_mut()
.enumerate()
.filter_map(|(glyph_index, glyph_record)| {
if glyph_index > (u16::MAX as usize) {
Expand Down Expand Up @@ -1096,20 +1088,20 @@ impl FontMetrics {
fs_selection: os2_table.fs_selection,
us_first_char_index: os2_table.us_first_char_index,
us_last_char_index: os2_table.us_last_char_index,
s_typo_ascender: os2_table.s_typo_ascender.into(),
s_typo_descender: os2_table.s_typo_descender.into(),
s_typo_line_gap: os2_table.s_typo_line_gap.into(),
us_win_ascent: os2_table.us_win_ascent.into(),
us_win_descent: os2_table.us_win_descent.into(),
ul_code_page_range1: os2_table.ul_code_page_range1.into(),
ul_code_page_range2: os2_table.ul_code_page_range2.into(),
sx_height: os2_table.sx_height.into(),
s_cap_height: os2_table.s_cap_height.into(),
us_default_char: os2_table.us_default_char.into(),
us_break_char: os2_table.us_break_char.into(),
us_max_context: os2_table.us_max_context.into(),
us_lower_optical_point_size: os2_table.us_lower_optical_point_size.into(),
us_upper_optical_point_size: os2_table.us_upper_optical_point_size.into(),
s_typo_ascender: os2_table.s_typo_ascender,
s_typo_descender: os2_table.s_typo_descender,
s_typo_line_gap: os2_table.s_typo_line_gap,
us_win_ascent: os2_table.us_win_ascent,
us_win_descent: os2_table.us_win_descent,
ul_code_page_range1: os2_table.ul_code_page_range1,
ul_code_page_range2: os2_table.ul_code_page_range2,
sx_height: os2_table.sx_height,
s_cap_height: os2_table.s_cap_height,
us_default_char: os2_table.us_default_char,
us_break_char: os2_table.us_break_char,
us_max_context: os2_table.us_max_context,
us_lower_optical_point_size: os2_table.us_lower_optical_point_size,
us_upper_optical_point_size: os2_table.us_upper_optical_point_size,
}
}

Expand All @@ -1124,7 +1116,7 @@ impl FontMetrics {
let use_typo = if !self.use_typo_metrics() {
None
} else {
self.s_typo_ascender.into()
self.s_typo_ascender
};
match use_typo {
Some(s) => s,
Expand All @@ -1137,7 +1129,7 @@ impl FontMetrics {
let use_typo = if !self.use_typo_metrics() {
None
} else {
self.s_typo_descender.into()
self.s_typo_descender
};
match use_typo {
Some(s) => s,
Expand All @@ -1149,7 +1141,7 @@ impl FontMetrics {
let use_typo = if !self.use_typo_metrics() {
None
} else {
self.s_typo_line_gap.into()
self.s_typo_line_gap
};
match use_typo {
Some(s) => s,
Expand Down
Loading

0 comments on commit 1f08268

Please sign in to comment.