mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 14:39:45 -05:00
Playing with pdf render
This commit is contained in:
parent
a11c2af542
commit
eeb0d21013
2 changed files with 81 additions and 30 deletions
|
@ -228,6 +228,10 @@ pub unsafe extern "C" fn draw_shapes(state: *mut State, ptr: *mut Rect, len: usi
|
|||
|
||||
let svg_canvas = skia_safe::svg::Canvas::new(skia_safe::Rect::from_size((10000, 10000)), None);
|
||||
|
||||
let mut memory = Vec::new();
|
||||
let mut document = skia_safe::pdf::new_document(&mut memory, None).begin_page((10000, 10000), None);
|
||||
let pdf_canvas = document.canvas();
|
||||
|
||||
for rect in buf.iter() {
|
||||
let r = skia::Rect::new(rect.left, rect.top, rect.right, rect.bottom);
|
||||
let color = skia::Color::from_argb((rect.a * 255.0) as u8, rect.r as u8, rect.g as u8, rect.b as u8);
|
||||
|
@ -238,16 +242,19 @@ pub unsafe extern "C" fn draw_shapes(state: *mut State, ptr: *mut Rect, len: usi
|
|||
paint.set_color(color);
|
||||
paint.set_anti_alias(true);
|
||||
svg_canvas.draw_rect(r, &paint);
|
||||
pdf_canvas.draw_rect(r, &paint);
|
||||
|
||||
text_paint.set_color(color);
|
||||
state.surface.canvas().draw_str("SKIA TEXT", (rect.left, rect.top), &state.default_font, &text_paint);
|
||||
svg_canvas.draw_str("SKIA TEXT", (rect.left, rect.top), &state.default_font, &text_paint);
|
||||
pdf_canvas.draw_str("SKIA TEXT", (rect.left, rect.top), &state.default_font, &text_paint);
|
||||
|
||||
let mut path = Path::new();
|
||||
path.move_to((rect.left, rect.top));
|
||||
path.line_to((rect.right, rect.bottom));
|
||||
state.surface.canvas().draw_path(&path, &path_paint);
|
||||
svg_canvas.draw_path(&path, &path_paint);
|
||||
pdf_canvas.draw_path(&path, &path_paint);
|
||||
|
||||
// https://github.com/rust-skia/rust-skia/blob/02c89a87649af8d2870fb631aae4a5e171887367/skia-org/src/skparagraph_example.rs#L18
|
||||
let mut font_collection = FontCollection::new();
|
||||
|
@ -264,7 +271,8 @@ pub unsafe extern "C" fn draw_shapes(state: *mut State, ptr: *mut Rect, len: usi
|
|||
paragraph.paint(state.surface.canvas(), (rect.left, rect.top));
|
||||
paragraph.paint(&svg_canvas, (rect.left, rect.top));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// base64 image of the canvas
|
||||
let image = state.surface.image_snapshot();
|
||||
let mut context = state.surface.direct_context();
|
||||
|
@ -277,6 +285,16 @@ pub unsafe extern "C" fn draw_shapes(state: *mut State, ptr: *mut Rect, len: usi
|
|||
let svg = String::from_utf8_lossy(svg_data.as_bytes());
|
||||
println!("svg: {}", svg.replace('\n', ""));
|
||||
|
||||
// PDF
|
||||
document.end_page().close();
|
||||
println!("PDF: ");
|
||||
print!("echo ");
|
||||
for byte in &memory {
|
||||
print!("{:02x}", byte);
|
||||
}
|
||||
println!("| xxd -r -p > output.pdf");
|
||||
*/
|
||||
|
||||
flush(state);
|
||||
std::mem::forget(buf);
|
||||
}
|
||||
|
|
|
@ -4013,16 +4013,34 @@ function dbg(...args) {
|
|||
throw new EmscriptenSjLj;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var convertI32PairToI53Checked = (lo, hi) => {
|
||||
assert(lo == (lo >>> 0) || lo == (lo|0)); // lo should either be a i32 or a u32
|
||||
assert(hi === (hi|0)); // hi should be a i32
|
||||
return ((hi + 0x200000) >>> 0 < 0x400001 - !!lo) ? (lo >>> 0) + hi * 4294967296 : NaN;
|
||||
};
|
||||
function __gmtime_js(time_low, time_high,tmPtr) {
|
||||
var time = convertI32PairToI53Checked(time_low, time_high);
|
||||
|
||||
|
||||
var date = new Date(time * 1000);
|
||||
HEAP32[((tmPtr)>>2)] = date.getUTCSeconds();
|
||||
HEAP32[(((tmPtr)+(4))>>2)] = date.getUTCMinutes();
|
||||
HEAP32[(((tmPtr)+(8))>>2)] = date.getUTCHours();
|
||||
HEAP32[(((tmPtr)+(12))>>2)] = date.getUTCDate();
|
||||
HEAP32[(((tmPtr)+(16))>>2)] = date.getUTCMonth();
|
||||
HEAP32[(((tmPtr)+(20))>>2)] = date.getUTCFullYear()-1900;
|
||||
HEAP32[(((tmPtr)+(24))>>2)] = date.getUTCDay();
|
||||
var start = Date.UTC(date.getUTCFullYear(), 0, 1, 0, 0, 0, 0);
|
||||
var yday = ((date.getTime() - start) / (1000 * 60 * 60 * 24))|0;
|
||||
HEAP32[(((tmPtr)+(28))>>2)] = yday;
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function __mmap_js(len,prot,flags,fd,offset_low, offset_high,allocated,addr) {
|
||||
var offset = convertI32PairToI53Checked(offset_low, offset_high);
|
||||
|
||||
|
@ -7974,6 +7992,8 @@ var wasmImports = {
|
|||
/** @export */
|
||||
_emscripten_throw_longjmp: __emscripten_throw_longjmp,
|
||||
/** @export */
|
||||
_gmtime_js: __gmtime_js,
|
||||
/** @export */
|
||||
_mmap_js: __mmap_js,
|
||||
/** @export */
|
||||
_munmap_js: __munmap_js,
|
||||
|
@ -8844,6 +8864,8 @@ var wasmImports = {
|
|||
/** @export */
|
||||
invoke_iiff,
|
||||
/** @export */
|
||||
invoke_iiffi,
|
||||
/** @export */
|
||||
invoke_iii,
|
||||
/** @export */
|
||||
invoke_iiii,
|
||||
|
@ -9016,10 +9038,10 @@ function invoke_vii(index,a1,a2) {
|
|||
}
|
||||
}
|
||||
|
||||
function invoke_viiii(index,a1,a2,a3,a4) {
|
||||
function invoke_v(index) {
|
||||
var sp = stackSave();
|
||||
try {
|
||||
getWasmTableEntry(index)(a1,a2,a3,a4);
|
||||
getWasmTableEntry(index)();
|
||||
} catch(e) {
|
||||
stackRestore(sp);
|
||||
if (!(e instanceof EmscriptenEH)) throw e;
|
||||
|
@ -9038,6 +9060,17 @@ function invoke_viii(index,a1,a2,a3) {
|
|||
}
|
||||
}
|
||||
|
||||
function invoke_viiii(index,a1,a2,a3,a4) {
|
||||
var sp = stackSave();
|
||||
try {
|
||||
getWasmTableEntry(index)(a1,a2,a3,a4);
|
||||
} catch(e) {
|
||||
stackRestore(sp);
|
||||
if (!(e instanceof EmscriptenEH)) throw e;
|
||||
_setThrew(1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function invoke_iii(index,a1,a2) {
|
||||
var sp = stackSave();
|
||||
try {
|
||||
|
@ -9071,17 +9104,6 @@ function invoke_viiiii(index,a1,a2,a3,a4,a5) {
|
|||
}
|
||||
}
|
||||
|
||||
function invoke_v(index) {
|
||||
var sp = stackSave();
|
||||
try {
|
||||
getWasmTableEntry(index)();
|
||||
} catch(e) {
|
||||
stackRestore(sp);
|
||||
if (!(e instanceof EmscriptenEH)) throw e;
|
||||
_setThrew(1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function invoke_iiiii(index,a1,a2,a3,a4) {
|
||||
var sp = stackSave();
|
||||
try {
|
||||
|
@ -9115,6 +9137,17 @@ function invoke_viiiiffii(index,a1,a2,a3,a4,a5,a6,a7,a8) {
|
|||
}
|
||||
}
|
||||
|
||||
function invoke_iiffi(index,a1,a2,a3,a4) {
|
||||
var sp = stackSave();
|
||||
try {
|
||||
return getWasmTableEntry(index)(a1,a2,a3,a4);
|
||||
} catch(e) {
|
||||
stackRestore(sp);
|
||||
if (!(e instanceof EmscriptenEH)) throw e;
|
||||
_setThrew(1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function invoke_iiiiiii(index,a1,a2,a3,a4,a5,a6) {
|
||||
var sp = stackSave();
|
||||
try {
|
||||
|
@ -9203,6 +9236,17 @@ function invoke_viiiiii(index,a1,a2,a3,a4,a5,a6) {
|
|||
}
|
||||
}
|
||||
|
||||
function invoke_viiiiiii(index,a1,a2,a3,a4,a5,a6,a7) {
|
||||
var sp = stackSave();
|
||||
try {
|
||||
getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7);
|
||||
} catch(e) {
|
||||
stackRestore(sp);
|
||||
if (!(e instanceof EmscriptenEH)) throw e;
|
||||
_setThrew(1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function invoke_iiiiffii(index,a1,a2,a3,a4,a5,a6,a7) {
|
||||
var sp = stackSave();
|
||||
try {
|
||||
|
@ -9324,17 +9368,6 @@ function invoke_diii(index,a1,a2,a3) {
|
|||
}
|
||||
}
|
||||
|
||||
function invoke_viiiiiii(index,a1,a2,a3,a4,a5,a6,a7) {
|
||||
var sp = stackSave();
|
||||
try {
|
||||
getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7);
|
||||
} catch(e) {
|
||||
stackRestore(sp);
|
||||
if (!(e instanceof EmscriptenEH)) throw e;
|
||||
_setThrew(1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function invoke_iiiiiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) {
|
||||
var sp = stackSave();
|
||||
try {
|
||||
|
|
Loading…
Add table
Reference in a new issue