Skip to content

Commit

Permalink
stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Sep 14, 2019
1 parent d8460f5 commit b0d9501
Show file tree
Hide file tree
Showing 18 changed files with 452 additions and 552 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dpx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license = "GPL"

[dependencies]
tectonic_bridge = { version = "0.0.1-dev", path = "../bridge" }
lazy_static = "1.4"
libc = "0.2"
libpng-sys = "1"
libz-sys = { version = "1", optional = true}
Expand Down
2 changes: 1 addition & 1 deletion dpx/src/dpx_dvi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2713,7 +2713,7 @@ unsafe extern "C" fn do_glyphs(mut do_actual_text: i32) {
if (*font).rgba_color != 0xffffffffu32 {
let mut color: pdf_color = pdf_color {
num_components: 0,
spot_color_name: 0 as *mut i8,
spot_color_name: None,
values: [0.; 4],
};
pdf_color_rgbcolor(
Expand Down
2 changes: 1 addition & 1 deletion dpx/src/dpx_epdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub type __off64_t = i64;
pub type size_t = u64;
pub type rust_input_handle_t = *mut libc::c_void;

use super::dpx_pdfdev::{pdf_coord, pdf_rect, pdf_tmatrix};
use super::dpx_pdfdev::{pdf_coord, pdf_tmatrix};

use crate::dpx_pdfximage::{load_options, pdf_ximage, xform_info};
pub const OP_CURVETO2: C2RustUnnamed_0 = 15;
Expand Down
2 changes: 1 addition & 1 deletion dpx/src/dpx_mpost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3416,7 +3416,7 @@ unsafe extern "C" fn do_operator(mut token: *const i8, mut x_user: f64, mut y_us
let mut cp = pdf_coord::new();
let mut color: pdf_color = pdf_color {
num_components: 0,
spot_color_name: 0 as *mut i8,
spot_color_name: None,
values: [0.; 4],
};
opcode = get_opcode(token);
Expand Down
90 changes: 52 additions & 38 deletions dpx/src/dpx_pdfcolor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,25 @@ extern "C" {
fn MD5_final(outbuf: *mut u8, ctx: *mut MD5_CONTEXT);
}
pub type size_t = u64;
#[derive(Copy, Clone)]

use std::ffi::{CStr, CString};

#[derive(Clone)]
#[repr(C)]
pub struct pdf_color {
pub num_components: i32,
pub spot_color_name: *mut i8,
pub spot_color_name: Option<CString>,
pub values: [f64; 4],
}
impl pdf_color {
pub const fn new() -> Self {
Self {
num_components: 0,
spot_color_name: None,
values: [0.; 4],
}
}
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct pdf_colorspace {
Expand Down Expand Up @@ -160,9 +172,9 @@ pub struct C2RustUnnamed_1 {
pub major: i32,
pub minor: i32,
}
#[derive(Copy, Clone)]
#[derive(Clone)]
#[repr(C)]
pub struct C2RustUnnamed_2 {
pub struct ColorStack {
pub current: i32,
pub stroke: [pdf_color; 128],
pub fill: [pdf_color; 128],
Expand Down Expand Up @@ -225,7 +237,7 @@ pub unsafe extern "C" fn pdf_color_rgbcolor(color: &mut pdf_color, r: f64, g: f6
color.values[1] = g;
color.values[2] = b;
color.num_components = 3i32;
color.spot_color_name = 0 as *mut i8;
color.spot_color_name = None;
0i32
}
#[no_mangle]
Expand Down Expand Up @@ -257,20 +269,32 @@ pub unsafe extern "C" fn pdf_color_cmykcolor(
color.values[2] = y;
color.values[3] = k;
color.num_components = 4i32;
color.spot_color_name = 0 as *mut i8;
color.spot_color_name = None;
0i32
}
#[no_mangle]
pub unsafe extern "C" fn pdf_color_graycolor(color: &mut pdf_color, mut g: f64) -> i32 {
pub unsafe extern "C" fn pdf_color_graycolor(color: &mut pdf_color, g: f64) -> i32 {
if g < 0.0f64 || g > 1.0f64 {
warn!("Invalid color value specified: gray={}", g);
return -1i32;
}
color.values[0] = g;
color.num_components = 1i32;
color.spot_color_name = 0 as *mut i8;
color.spot_color_name = None;
0i32
}
pub fn pdf_color_graycolor_new(g: f64) -> Result<pdf_color, i32> {
if g < 0. || g > 1. {
warn!("Invalid color value specified: gray={}", g);
return Err(-1);
}
Ok(pdf_color {
values: [g, 0., 0., 0.],
num_components: 1,
spot_color_name: None,
})
}

#[no_mangle]
pub unsafe extern "C" fn pdf_color_spotcolor(
color: &mut pdf_color,
Expand All @@ -284,20 +308,12 @@ pub unsafe extern "C" fn pdf_color_spotcolor(
color.values[0] = c;
color.values[1] = 0.0f64;
color.num_components = 2i32;
color.spot_color_name = name;
color.spot_color_name = Some(CStr::from_ptr(name).to_owned());
0i32
}
#[no_mangle]
pub unsafe extern "C" fn pdf_color_copycolor(
mut color1: *mut pdf_color,
mut color2: *const pdf_color,
) {
assert!(!color1.is_null() && !color2.is_null());
memcpy(
color1 as *mut libc::c_void,
color2 as *const libc::c_void,
::std::mem::size_of::<pdf_color>() as u64,
);
pub unsafe extern "C" fn pdf_color_copycolor(color1: &mut pdf_color, color2: &pdf_color) {
*color1 = color2.clone();
}
/* Brighten up a color. f == 0 means no change, f == 1 means white. */
#[no_mangle]
Expand Down Expand Up @@ -367,7 +383,7 @@ pub unsafe extern "C" fn pdf_color_to_string(
len = sprintf(
buffer,
b" /%s %c%c %g %c%c\x00" as *const u8 as *const i8,
color.spot_color_name,
color.spot_color_name.as_ref().unwrap().as_ptr(),
'C' as i32 | mask as i32,
'S' as i32 | mask as i32,
(color.values[0] / 0.001f64 + 0.5f64).floor() * 0.001f64,
Expand Down Expand Up @@ -438,8 +454,11 @@ pub unsafe extern "C" fn pdf_color_compare(color1: &pdf_color, color2: &pdf_colo
return -1i32;
}
}
if !color1.spot_color_name.is_null() && !color2.spot_color_name.is_null() {
return strcmp(color1.spot_color_name, color2.spot_color_name);
if color1.spot_color_name.is_some() && color2.spot_color_name.is_some() {
return strcmp(
color1.spot_color_name.as_ref().unwrap().as_ptr(),
color2.spot_color_name.as_ref().unwrap().as_ptr(),
);
}
0i32
}
Expand Down Expand Up @@ -490,28 +509,23 @@ pub unsafe extern "C" fn pdf_color_is_valid(color: &pdf_color) -> bool {
}
}
if pdf_color_type(color) == -2i32 {
if color.spot_color_name.is_null()
|| *color.spot_color_name.offset(0) as i32 == '\u{0}' as i32
if color.spot_color_name.is_none()
|| *color.spot_color_name.as_ref().unwrap().as_ptr().offset(0) as i32 == '\u{0}' as i32
{
warn!("Invalid spot color: empty name");
return false;
}
}
true
}
static mut color_stack: C2RustUnnamed_2 = C2RustUnnamed_2 {
/*static mut color_stack: ColorStack = ColorStack {
current: 0,
stroke: [pdf_color {
num_components: 0,
spot_color_name: 0 as *const i8 as *mut i8,
values: [0.; 4],
}; 128],
fill: [pdf_color {
num_components: 0,
spot_color_name: 0 as *const i8 as *mut i8,
values: [0.; 4],
}; 128],
};
stroke: unsafe { core::mem::zeroed() },//[pdf_color::new(); 128],
fill: unsafe { core::mem::zeroed() },//[pdf_color::new(); 128],
};*/
static mut color_stack: ColorStack =
unsafe { std::mem::transmute([0u8; std::mem::size_of::<ColorStack>()]) };

#[no_mangle]
pub unsafe extern "C" fn pdf_color_clear_stack() {
if color_stack.current > 0 {
Expand All @@ -523,8 +537,8 @@ pub unsafe extern "C" fn pdf_color_clear_stack() {
if !(fresh4 != 0) {
break;
}
free(color_stack.stroke[color_stack.current as usize].spot_color_name as *mut libc::c_void);
free(color_stack.fill[color_stack.current as usize].spot_color_name as *mut libc::c_void);
// free(color_stack.stroke[color_stack.current as usize].spot_color_name as *mut libc::c_void);
// free(color_stack.fill[color_stack.current as usize].spot_color_name as *mut libc::c_void);
}
color_stack.current = 0;
pdf_color_graycolor(&mut color_stack.stroke[0], 0.0f64);
Expand Down
10 changes: 10 additions & 0 deletions dpx/src/dpx_pdfdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ impl pdf_tmatrix {
f: 0.,
}
}
pub const fn identity() -> Self {
Self {
a: 1.,
b: 0.,
c: 0.,
d: 1.,
e: 0.,
f: 0.,
}
}
}
#[derive(Copy, Clone, Default)]
#[repr(C)]
Expand Down
4 changes: 2 additions & 2 deletions dpx/src/dpx_pdfdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3181,8 +3181,8 @@ unsafe extern "C" fn pdf_doc_finish_page(mut p: *mut pdf_doc) {
static mut bgcolor: pdf_color = {
let mut init = pdf_color {
num_components: 1i32,
spot_color_name: 0 as *const i8 as *mut i8,
values: [1.0f64, 0., 0., 0.],
spot_color_name: None,
values: [1., 0., 0., 0.],
};
init
};
Expand Down
Loading

0 comments on commit b0d9501

Please sign in to comment.