Fix image reader (#512)
* ignore table * ignore unsupported image * fix * fix * fix * fix Co-authored-by: bokuweb <bokuweb@bokuwebnombp.lan>main
parent
3a875e1d40
commit
2e8a7731d6
|
@ -102,6 +102,16 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "console_error_panic_hook"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if 1.0.0",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crc32fast"
|
name = "crc32fast"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
|
@ -167,6 +177,7 @@ dependencies = [
|
||||||
name = "docx-wasm"
|
name = "docx-wasm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"console_error_panic_hook",
|
||||||
"docx-rs",
|
"docx-rs",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
|
@ -230,14 +230,15 @@ impl Docx {
|
||||||
path: impl Into<String>,
|
path: impl Into<String>,
|
||||||
buf: Vec<u8>,
|
buf: Vec<u8>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let dimg = image::load_from_memory(&buf).expect("Should load image from memory.");
|
if let Ok(dimg) = image::load_from_memory(&buf) {
|
||||||
let mut png = std::io::Cursor::new(vec![]);
|
let mut png = std::io::Cursor::new(vec![]);
|
||||||
// For now only png supported
|
// For now only png supported
|
||||||
dimg.write_to(&mut png, ImageFormat::Png)
|
dimg.write_to(&mut png, ImageFormat::Png)
|
||||||
.expect("Unable to write dynamic image");
|
.expect("Unable to write dynamic image");
|
||||||
|
|
||||||
self.images
|
self.images
|
||||||
.push((id.into(), path.into(), Image(buf), Png(png.into_inner())));
|
.push((id.into(), path.into(), Image(buf), Png(png.into_inner())));
|
||||||
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -987,8 +988,9 @@ fn push_comment_and_comment_extended(
|
||||||
comments.push(c.get_comment());
|
comments.push(c.get_comment());
|
||||||
let comment_extended = CommentExtended::new(para_id);
|
let comment_extended = CommentExtended::new(para_id);
|
||||||
if let Some(parent_comment_id) = comment.parent_comment_id {
|
if let Some(parent_comment_id) = comment.parent_comment_id {
|
||||||
let parent_para_id = comment_map.get(&parent_comment_id).unwrap().clone();
|
if let Some(parent_para_id) = comment_map.get(&parent_comment_id) {
|
||||||
comments_extended.push(comment_extended.parent_paragraph_id(parent_para_id));
|
comments_extended.push(comment_extended.parent_paragraph_id(parent_para_id.clone()));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
comments_extended.push(comment_extended);
|
comments_extended.push(comment_extended);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ impl ElementReader for TableCell {
|
||||||
let mut cell = TableCell::new();
|
let mut cell = TableCell::new();
|
||||||
loop {
|
loop {
|
||||||
let e = r.next();
|
let e = r.next();
|
||||||
|
|
||||||
match e {
|
match e {
|
||||||
Ok(XmlEvent::StartElement {
|
Ok(XmlEvent::StartElement {
|
||||||
attributes, name, ..
|
attributes, name, ..
|
||||||
|
|
|
@ -11,4 +11,5 @@ crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasm-bindgen = "0.2.78"
|
wasm-bindgen = "0.2.78"
|
||||||
|
console_error_panic_hook = "0.1.7"
|
||||||
docx-rs= { path = "../docx-core" }
|
docx-rs= { path = "../docx-core" }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "docx-wasm",
|
"name": "docx-wasm",
|
||||||
"version": "0.0.273",
|
"version": "0.0.274-image-test8",
|
||||||
"main": "dist/node/index.js",
|
"main": "dist/node/index.js",
|
||||||
"browser": "dist/web/index.js",
|
"browser": "dist/web/index.js",
|
||||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
extern crate console_error_panic_hook;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Docx(docx_rs::Docx);
|
pub struct Docx(docx_rs::Docx);
|
||||||
|
@ -8,6 +10,8 @@ pub struct Docx(docx_rs::Docx);
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn createDocx() -> Docx {
|
pub fn createDocx() -> Docx {
|
||||||
|
use std::panic;
|
||||||
|
panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||||
Docx(docx_rs::Docx::new())
|
Docx(docx_rs::Docx::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue