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",
|
||||
]
|
||||
|
||||
[[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]]
|
||||
name = "crc32fast"
|
||||
version = "1.3.2"
|
||||
|
@ -167,6 +177,7 @@ dependencies = [
|
|||
name = "docx-wasm"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"console_error_panic_hook",
|
||||
"docx-rs",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
|
|
@ -230,7 +230,7 @@ impl Docx {
|
|||
path: impl Into<String>,
|
||||
buf: Vec<u8>,
|
||||
) -> 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![]);
|
||||
// For now only png supported
|
||||
dimg.write_to(&mut png, ImageFormat::Png)
|
||||
|
@ -238,6 +238,7 @@ impl Docx {
|
|||
|
||||
self.images
|
||||
.push((id.into(), path.into(), Image(buf), Png(png.into_inner())));
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -987,8 +988,9 @@ fn push_comment_and_comment_extended(
|
|||
comments.push(c.get_comment());
|
||||
let comment_extended = CommentExtended::new(para_id);
|
||||
if let Some(parent_comment_id) = comment.parent_comment_id {
|
||||
let parent_para_id = comment_map.get(&parent_comment_id).unwrap().clone();
|
||||
comments_extended.push(comment_extended.parent_paragraph_id(parent_para_id));
|
||||
if let Some(parent_para_id) = comment_map.get(&parent_comment_id) {
|
||||
comments_extended.push(comment_extended.parent_paragraph_id(parent_para_id.clone()));
|
||||
}
|
||||
} else {
|
||||
comments_extended.push(comment_extended);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ impl ElementReader for TableCell {
|
|||
let mut cell = TableCell::new();
|
||||
loop {
|
||||
let e = r.next();
|
||||
|
||||
match e {
|
||||
Ok(XmlEvent::StartElement {
|
||||
attributes, name, ..
|
||||
|
|
|
@ -11,4 +11,5 @@ crate-type = ["cdylib"]
|
|||
|
||||
[dependencies]
|
||||
wasm-bindgen = "0.2.78"
|
||||
console_error_panic_hook = "0.1.7"
|
||||
docx-rs= { path = "../docx-core" }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "docx-wasm",
|
||||
"version": "0.0.273",
|
||||
"version": "0.0.274-image-test8",
|
||||
"main": "dist/node/index.js",
|
||||
"browser": "dist/web/index.js",
|
||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use super::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
extern crate console_error_panic_hook;
|
||||
|
||||
#[wasm_bindgen]
|
||||
#[derive(Debug)]
|
||||
pub struct Docx(docx_rs::Docx);
|
||||
|
@ -8,6 +10,8 @@ pub struct Docx(docx_rs::Docx);
|
|||
#[wasm_bindgen]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn createDocx() -> Docx {
|
||||
use std::panic;
|
||||
panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||
Docx(docx_rs::Docx::new())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue