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

Overhaul pdfobj #176

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
42 changes: 39 additions & 3 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions dpx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ md-5 = "0.8.0"
sha2 = "0.8.0"
rand = "0.7.2"
chrono = "0.4.9"
indexmap = "1.3.0"
png = "0.15.0"

[features]
default = ['libz-sys']
Expand Down
21 changes: 11 additions & 10 deletions dpx/src/dpx_cid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

use crate::DisplayExt;
use std::ffi::CStr;
use crate::dpx_pdfobj::PdfObjRef;

use crate::dpx_pdfparse::ParsePdfObj;
use crate::mfree;
Expand Down Expand Up @@ -69,9 +70,9 @@ pub struct CIDFont {
pub parent: [i32; 2],
pub csi: *mut CIDSysInfo,
pub options: *mut cid_opt,
pub indirect: *mut pdf_obj,
pub fontdict: *mut pdf_obj,
pub descriptor: *mut pdf_obj,
pub indirect: PdfObjRef,
pub fontdict: PdfObjRef,
pub descriptor: PdfObjRef,
}
#[derive(Copy, Clone)]
#[repr(C)]
Expand Down Expand Up @@ -411,20 +412,20 @@ unsafe fn CIDFont_new() -> *mut CIDFont {
/*
* PDF Font Resource
*/
(*font).indirect = 0 as *mut pdf_obj;
(*font).fontdict = 0 as *mut pdf_obj;
(*font).descriptor = 0 as *mut pdf_obj;
(*font).indirect = 0 as PdfObjRef;
(*font).fontdict = 0 as PdfObjRef;
(*font).descriptor = 0 as PdfObjRef;
font
}
/* It does write PDF objects. */
unsafe fn CIDFont_flush(mut font: *mut CIDFont) {
if !font.is_null() {
pdf_release_obj((*font).indirect);
(*font).indirect = 0 as *mut pdf_obj;
(*font).indirect = 0 as PdfObjRef;
pdf_release_obj((*font).fontdict);
(*font).fontdict = 0 as *mut pdf_obj;
(*font).fontdict = 0 as PdfObjRef;
pdf_release_obj((*font).descriptor);
(*font).descriptor = 0 as *mut pdf_obj
(*font).descriptor = 0 as PdfObjRef
};
}
unsafe fn CIDFont_release(mut font: *mut CIDFont) {
Expand Down Expand Up @@ -498,7 +499,7 @@ pub unsafe extern "C" fn CIDFont_get_parent_id(mut font: *mut CIDFont, mut wmode
(*font).parent[wmode as usize]
}
#[no_mangle]
pub unsafe extern "C" fn CIDFont_get_resource(mut font: *mut CIDFont) -> *mut pdf_obj {
pub unsafe extern "C" fn CIDFont_get_resource(mut font: *mut CIDFont) -> PdfObjRef {
assert!(!font.is_null());
if (*font).indirect.is_null() {
(*font).indirect = pdf_ref_obj((*font).fontdict)
Expand Down
21 changes: 11 additions & 10 deletions dpx/src/dpx_cidtype0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

use crate::DisplayExt;
use std::ffi::CStr;
use crate::dpx_pdfobj::PdfObjRef;

use super::dpx_sfnt::{
sfnt_close, sfnt_find_table_pos, sfnt_locate_table, sfnt_open, sfnt_read_table_directory,
Expand Down Expand Up @@ -165,14 +166,14 @@ pub unsafe extern "C" fn CIDFont_type0_set_flags(mut flags: i32) {
* PDF Reference 3rd. ed., p.340, "Glyph Metrics in CID Fonts".
*/
unsafe fn add_CIDHMetrics(
mut fontdict: *mut pdf_obj,
mut fontdict: PdfObjRef,
mut CIDToGIDMap: *mut u8,
mut last_cid: u16,
mut maxp: *mut tt_maxp_table,
mut head: *mut tt_head_table,
mut hmtx: *mut tt_longMetrics,
) {
let mut an_array: *mut pdf_obj = 0 as *mut pdf_obj;
let mut an_array: PdfObjRef = 0 as PdfObjRef;
let mut start: i32 = 0i32;
let mut prev: i32 = 0i32;
let mut empty: i32 = 1i32;
Expand Down Expand Up @@ -205,14 +206,14 @@ unsafe fn add_CIDHMetrics(
if !an_array.is_null() {
pdf_add_array(&mut *w_array, pdf_new_number(start as f64));
pdf_add_array(&mut *w_array, an_array);
an_array = 0 as *mut pdf_obj;
an_array = 0 as PdfObjRef;
empty = 0i32
}
} else {
if cid != prev + 1i32 && !an_array.is_null() {
pdf_add_array(&mut *w_array, pdf_new_number(start as f64));
pdf_add_array(&mut *w_array, an_array);
an_array = 0 as *mut pdf_obj;
an_array = 0 as PdfObjRef;
empty = 0i32
}
if an_array.is_null() {
Expand Down Expand Up @@ -242,7 +243,7 @@ unsafe fn add_CIDHMetrics(
}
unsafe fn add_CIDVMetrics(
mut sfont: *mut sfnt,
mut fontdict: *mut pdf_obj,
mut fontdict: PdfObjRef,
mut CIDToGIDMap: *mut u8,
mut last_cid: u16,
mut maxp: *mut tt_maxp_table,
Expand Down Expand Up @@ -376,7 +377,7 @@ unsafe fn add_CIDVMetrics(
}
unsafe fn add_CIDMetrics(
mut sfont: *mut sfnt,
mut fontdict: *mut pdf_obj,
mut fontdict: PdfObjRef,
mut CIDToGIDMap: *mut u8,
mut last_cid: u16,
mut need_vmetrics: i32,
Expand Down Expand Up @@ -1147,7 +1148,7 @@ pub unsafe extern "C" fn CIDFont_type0_open(
}
pdf_add_dict(&mut *(*font).descriptor, "FontName", pdf_copy_name(fontname));
pdf_add_dict(&mut *(*font).fontdict, "BaseFont", pdf_copy_name(fontname));
let mut csi_dict: *mut pdf_obj = pdf_new_dict();
let mut csi_dict: PdfObjRef = pdf_new_dict();
pdf_add_dict(
&mut *csi_dict,
"Registry",
Expand Down Expand Up @@ -1609,13 +1610,13 @@ unsafe fn create_ToUnicode_stream(
cffont: &cff_font,
mut font_name: *const i8,
mut used_glyphs: *const i8,
) -> *mut pdf_obj {
let mut stream: *mut pdf_obj = 0 as *mut pdf_obj;
) -> PdfObjRef {
let mut stream: PdfObjRef = 0 as PdfObjRef;
let mut wbuf: [u8; 1024] = [0; 1024];
static mut range_min: [u8; 2] = [0; 2];
static mut range_max: [u8; 2] = [0xff, 0xff];
if font_name.is_null() || used_glyphs.is_null() {
return 0 as *mut pdf_obj;
return 0 as PdfObjRef;
}
let cmap = CMap_new();
let cmap_name = new((strlen(font_name)
Expand Down
11 changes: 6 additions & 5 deletions dpx/src/dpx_cidtype2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

use crate::DisplayExt;
use std::ffi::CStr;
use crate::dpx_pdfobj::PdfObjRef;

use super::dpx_sfnt::{
dfont_open, sfnt_close, sfnt_create_FontFile_stream, sfnt_find_table_pos, sfnt_open,
Expand Down Expand Up @@ -416,15 +417,15 @@ unsafe fn find_tocode_cmap(mut reg: *const i8, mut ord: *const i8, mut select: i
* Mostly same as add_CID[HV]Metrics in cidtype0.c.
*/
unsafe fn add_TTCIDHMetrics(
mut fontdict: *mut pdf_obj,
mut fontdict: PdfObjRef,
mut g: *mut tt_glyphs,
mut used_chars: *mut i8,
mut cidtogidmap: *mut u8,
mut last_cid: u16,
) {
let mut start: i32 = 0i32;
let mut prev: i32 = 0i32;
let mut an_array: *mut pdf_obj = 0 as *mut pdf_obj;
let mut an_array: PdfObjRef = 0 as PdfObjRef;
let mut empty: i32 = 1i32;
let w_array = pdf_new_array();
let dw = if (*g).dw as i32 != 0i32 && (*g).dw as i32 <= (*g).emsize as i32 {
Expand Down Expand Up @@ -459,15 +460,15 @@ unsafe fn add_TTCIDHMetrics(
if !an_array.is_null() {
pdf_add_array(&mut *w_array, pdf_new_number(start as f64));
pdf_add_array(&mut *w_array, an_array);
an_array = 0 as *mut pdf_obj;
an_array = 0 as PdfObjRef;
empty = 0i32
}
} else {
if cid != prev + 1i32 {
if !an_array.is_null() {
pdf_add_array(&mut *w_array, pdf_new_number(start as f64));
pdf_add_array(&mut *w_array, an_array);
an_array = 0 as *mut pdf_obj;
an_array = 0 as PdfObjRef;
empty = 0i32
}
}
Expand All @@ -493,7 +494,7 @@ unsafe fn add_TTCIDHMetrics(
pdf_release_obj(w_array);
}
unsafe fn add_TTCIDVMetrics(
mut fontdict: *mut pdf_obj,
mut fontdict: PdfObjRef,
mut g: *mut tt_glyphs,
mut used_chars: *mut i8,
mut last_cid: u16,
Expand Down
9 changes: 5 additions & 4 deletions dpx/src/dpx_cmap_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

use crate::warn;

use crate::dpx_pdfobj::PdfObjRef;
use super::dpx_cid::{CSI_IDENTITY, CSI_UNICODE};
use super::dpx_cmap::{CMap_get_CIDSysInfo, CMap_is_valid};
use super::dpx_mem::new;
Expand Down Expand Up @@ -129,7 +130,7 @@ unsafe fn write_map(
mut codestr: *mut u8,
mut depth: size_t,
mut wbuf: *mut sbuf,
mut stream: *mut pdf_obj,
mut stream: PdfObjRef,
) -> i32 {
/* Must be greater than 1 */
let mut blocks: [C2RustUnnamed_1; 129] = [C2RustUnnamed_1 { start: 0, count: 0 }; 129];
Expand Down Expand Up @@ -349,18 +350,18 @@ unsafe fn write_map(
count as i32
}
#[no_mangle]
pub unsafe extern "C" fn CMap_create_stream(mut cmap: *mut CMap) -> *mut pdf_obj {
pub unsafe extern "C" fn CMap_create_stream(mut cmap: *mut CMap) -> PdfObjRef {
let mut wbuf: sbuf = sbuf {
buf: 0 as *mut i8,
curptr: 0 as *mut i8,
limptr: 0 as *mut i8,
};
if cmap.is_null() || !CMap_is_valid(cmap) {
warn!("Invalid CMap");
return 0 as *mut pdf_obj;
return 0 as PdfObjRef;
}
if (*cmap).type_0 == 0i32 {
return 0 as *mut pdf_obj;
return 0 as PdfObjRef;
}
let stream = pdf_new_stream(1i32 << 0i32);
let stream_dict = pdf_stream_dict(&mut *stream);
Expand Down
Loading