parent
4165c8b107
commit
dc21e50877
|
@ -24,6 +24,11 @@ impl DocumentRels {
|
|||
self.custom_xml_count += 1;
|
||||
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 {
|
||||
|
|
|
@ -111,7 +111,7 @@ pub struct Docx {
|
|||
// reader only
|
||||
pub themes: Vec<Theme>,
|
||||
// reader only
|
||||
pub images: Vec<Image>,
|
||||
pub images: Vec<(String, String, Image)>,
|
||||
}
|
||||
|
||||
impl Default for Docx {
|
||||
|
@ -208,8 +208,13 @@ impl Docx {
|
|||
}
|
||||
|
||||
// reader only
|
||||
pub(crate) fn add_image(mut self, buf: Vec<u8>) -> Self {
|
||||
self.images.push(Image(buf));
|
||||
pub(crate) fn add_image(
|
||||
mut self,
|
||||
id: impl Into<String>,
|
||||
path: impl Into<String>,
|
||||
buf: Vec<u8>,
|
||||
) -> Self {
|
||||
self.images.push((id.into(), path.into(), Image(buf)));
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
@ -411,9 +411,9 @@ pub fn read_docx(buf: &[u8]) -> Result<Docx, ReaderError> {
|
|||
// Read media
|
||||
let media = rels.find_target_path(IMAGE_TYPE);
|
||||
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")) {
|
||||
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;
|
||||
fontTable: {};
|
||||
themes: ThemeJSON[];
|
||||
// base64 encoded iamges
|
||||
images: string[];
|
||||
//(id, path, base64 encoded image data)
|
||||
images: [string, string, string][];
|
||||
};
|
||||
|
||||
export type SettingsJSON = {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "docx-wasm",
|
||||
"version": "0.0.259",
|
||||
"version": "0.0.260",
|
||||
"main": "dist/node/index.js",
|
||||
"browser": "dist/web/index.js",
|
||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue