parent
4165c8b107
commit
dc21e50877
|
@ -24,6 +24,11 @@ impl DocumentRels {
|
||||||
self.custom_xml_count += 1;
|
self.custom_xml_count += 1;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_image(mut self, id: impl Into<String>, path: impl Into<String>) -> Self {
|
||||||
|
self.images.push((id.into(), path.into()));
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuildXML for DocumentRels {
|
impl BuildXML for DocumentRels {
|
||||||
|
|
|
@ -111,7 +111,7 @@ pub struct Docx {
|
||||||
// reader only
|
// reader only
|
||||||
pub themes: Vec<Theme>,
|
pub themes: Vec<Theme>,
|
||||||
// reader only
|
// reader only
|
||||||
pub images: Vec<Image>,
|
pub images: Vec<(String, String, Image)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Docx {
|
impl Default for Docx {
|
||||||
|
@ -208,8 +208,13 @@ impl Docx {
|
||||||
}
|
}
|
||||||
|
|
||||||
// reader only
|
// reader only
|
||||||
pub(crate) fn add_image(mut self, buf: Vec<u8>) -> Self {
|
pub(crate) fn add_image(
|
||||||
self.images.push(Image(buf));
|
mut self,
|
||||||
|
id: impl Into<String>,
|
||||||
|
path: impl Into<String>,
|
||||||
|
buf: Vec<u8>,
|
||||||
|
) -> Self {
|
||||||
|
self.images.push((id.into(), path.into(), Image(buf)));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -411,9 +411,9 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
|
||||||
// Read media
|
// Read media
|
||||||
let media = rels.find_target_path(IMAGE_TYPE);
|
let media = rels.find_target_path(IMAGE_TYPE);
|
||||||
if let Some(paths) = media {
|
if let Some(paths) = media {
|
||||||
for (_, media) in paths {
|
for (id, media) in paths {
|
||||||
if let Ok(data) = read_zip(&mut archive, media.to_str().expect("should have media")) {
|
if let Ok(data) = read_zip(&mut archive, media.to_str().expect("should have media")) {
|
||||||
docx = docx.add_image(data);
|
docx = docx.add_image(id, media.to_str().unwrap().to_string(), data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,8 @@ export type DocxJSON = {
|
||||||
webSettings: WebSettingsJSON;
|
webSettings: WebSettingsJSON;
|
||||||
fontTable: {};
|
fontTable: {};
|
||||||
themes: ThemeJSON[];
|
themes: ThemeJSON[];
|
||||||
// base64 encoded iamges
|
//(id, path, base64 encoded image data)
|
||||||
images: string[];
|
images: [string, string, string][];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SettingsJSON = {
|
export type SettingsJSON = {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "docx-wasm",
|
"name": "docx-wasm",
|
||||||
"version": "0.0.259",
|
"version": "0.0.260",
|
||||||
"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>",
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue