update json (#458)
parent
9d58871287
commit
6f787af9af
|
@ -1,22 +1,56 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use serde::Serialize;
|
use serde::{ser::*, Serialize};
|
||||||
|
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
use crate::types::*;
|
use crate::types::*;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, PartialEq, Default)]
|
#[derive(Debug, Clone, PartialEq, Default)]
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct Drawing {
|
pub struct Drawing {
|
||||||
pub data: Option<DrawingData>,
|
pub data: Option<DrawingData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, PartialEq)]
|
impl Serialize for Drawing {
|
||||||
#[serde(rename_all = "camelCase")]
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
match self.data {
|
||||||
|
Some(DrawingData::Pic(ref pic)) => {
|
||||||
|
let mut t = serializer.serialize_struct("Drawing", 2)?;
|
||||||
|
t.serialize_field("type", "pic")?;
|
||||||
|
t.serialize_field("data", pic)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
let t = serializer.serialize_struct("Drawing", 2)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum DrawingData {
|
pub enum DrawingData {
|
||||||
Pic(Pic),
|
Pic(Pic),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Serialize for DrawingData {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
match *self {
|
||||||
|
DrawingData::Pic(ref pic) => {
|
||||||
|
let mut t = serializer.serialize_struct("Pic", 2)?;
|
||||||
|
t.serialize_field("type", "pic")?;
|
||||||
|
t.serialize_field("data", pic)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Drawing {
|
impl Drawing {
|
||||||
pub fn new() -> Drawing {
|
pub fn new() -> Drawing {
|
||||||
Default::default()
|
Default::default()
|
||||||
|
|
|
@ -5,23 +5,8 @@ use crate::documents::*;
|
||||||
use crate::types::*;
|
use crate::types::*;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Serialize, PartialEq)]
|
#[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[ts(export)]
|
||||||
pub enum PicAlign {
|
|
||||||
Left,
|
|
||||||
Right,
|
|
||||||
Bottom,
|
|
||||||
Top,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Serialize, PartialEq)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub enum DrawingPosition {
|
|
||||||
Offset(i32),
|
|
||||||
Align(PicAlign),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, PartialEq)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Pic {
|
pub struct Pic {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
@ -62,8 +47,7 @@ pub struct Pic {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pic {
|
impl Pic {
|
||||||
pub fn
|
pub fn new(buf: Vec<u8>) -> Pic {
|
||||||
new(buf: Vec<u8>) -> Pic {
|
|
||||||
let id = create_pic_rid(generate_pic_id());
|
let id = create_pic_rid(generate_pic_id());
|
||||||
let dimg = image::load_from_memory(&buf).unwrap();
|
let dimg = image::load_from_memory(&buf).unwrap();
|
||||||
let size = dimg.dimensions();
|
let size = dimg.dimensions();
|
||||||
|
|
|
@ -6,6 +6,7 @@ use std::str::FromStr;
|
||||||
use xml::attribute::OwnedAttribute;
|
use xml::attribute::OwnedAttribute;
|
||||||
use xml::reader::{EventReader, XmlEvent};
|
use xml::reader::{EventReader, XmlEvent};
|
||||||
|
|
||||||
|
use crate::types::*;
|
||||||
use crate::{DrawingPositionType, RelativeFromHType, RelativeFromVType};
|
use crate::{DrawingPositionType, RelativeFromHType, RelativeFromVType};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -3,9 +3,29 @@ use serde::Serialize;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[derive(Debug, Clone, Copy, Serialize, PartialEq)]
|
#[derive(Debug, Clone, Copy, Serialize, PartialEq, ts_rs::TS)]
|
||||||
|
#[ts(export)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub enum DrawingPositionType {
|
pub enum DrawingPositionType {
|
||||||
Anchor,
|
Anchor,
|
||||||
Inline,
|
Inline,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
#[derive(Debug, Clone, Copy, Serialize, PartialEq, ts_rs::TS)]
|
||||||
|
#[ts(export)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub enum PicAlign {
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Bottom,
|
||||||
|
Top,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, Serialize, PartialEq, ts_rs::TS)]
|
||||||
|
#[ts(export)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub enum DrawingPosition {
|
||||||
|
Offset(i32),
|
||||||
|
Align(PicAlign),
|
||||||
|
}
|
||||||
|
|
|
@ -8,7 +8,8 @@ use std::str::FromStr;
|
||||||
|
|
||||||
// @See: 20.4.3.4 ST_RelFromH (Horizontal Relative Positioning)
|
// @See: 20.4.3.4 ST_RelFromH (Horizontal Relative Positioning)
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Serialize, ts_rs::TS)]
|
||||||
|
#[ts(export)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub enum RelativeFromHType {
|
pub enum RelativeFromHType {
|
||||||
/// Specifies that the horizontal positioning shall be
|
/// Specifies that the horizontal positioning shall be
|
||||||
|
@ -80,7 +81,8 @@ impl FromStr for RelativeFromHType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Serialize, ts_rs::TS)]
|
||||||
|
#[ts(export)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub enum RelativeFromVType {
|
pub enum RelativeFromVType {
|
||||||
BottomMargin,
|
BottomMargin,
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,3 @@
|
||||||
|
import type { PicAlign } from "./PicAlign";
|
||||||
|
|
||||||
|
export type DrawingPosition = { offset: number } | { align: PicAlign };
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
export type DrawingPositionType = "anchor" | "inline";
|
|
@ -0,0 +1,6 @@
|
||||||
|
import type { DrawingPosition } from "./DrawingPosition";
|
||||||
|
import type { DrawingPositionType } from "./DrawingPositionType";
|
||||||
|
import type { RelativeFromHType } from "./RelativeFromHType";
|
||||||
|
import type { RelativeFromVType } from "./RelativeFromVType";
|
||||||
|
|
||||||
|
export interface Pic { id: string, image: Array<number>, size: [number, number], positionType: DrawingPositionType, simplePos: boolean, simplePosX: number, simplePosY: number, layoutInCell: boolean, relativeHeight: number, allowOverlap: boolean, positionH: DrawingPosition, positionV: DrawingPosition, relativeFromH: RelativeFromHType, relativeFromV: RelativeFromVType, distT: number, distB: number, distL: number, distR: number, }
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
export type PicAlign = "left" | "right" | "bottom" | "top";
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
export type RelativeFromHType = "character" | "column" | "insideMargin" | "leftMargin" | "margin" | "outsizeMargin" | "page" | "rightMargin";
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
export type RelativeFromVType = "bottomMargin" | "insideMargin" | "line" | "margin" | "outsizeMargin" | "page" | "paragraph" | "topMargin";
|
|
@ -3,12 +3,10 @@ import { TextBoxContentJSON } from "./textbox-content";
|
||||||
export type DrawingJSON = {
|
export type DrawingJSON = {
|
||||||
type: "drawing";
|
type: "drawing";
|
||||||
data: {
|
data: {
|
||||||
children: DrawingChildJSON[];
|
type: "pic";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DrawingChildJSON = WpAnchorJSON;
|
|
||||||
|
|
||||||
export type WpAnchorJSON = {
|
export type WpAnchorJSON = {
|
||||||
type: "anchor";
|
type: "anchor";
|
||||||
data: {
|
data: {
|
||||||
|
|
|
@ -47,6 +47,8 @@ export type DocxJSON = {
|
||||||
webSettings: WebSettingsJSON;
|
webSettings: WebSettingsJSON;
|
||||||
fontTable: {};
|
fontTable: {};
|
||||||
themes: ThemeJSON[];
|
themes: ThemeJSON[];
|
||||||
|
// base64 encoded iamges
|
||||||
|
images: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SettingsJSON = {
|
export type SettingsJSON = {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "docx-wasm",
|
"name": "docx-wasm",
|
||||||
"version": "0.0.249",
|
"version": "0.0.250",
|
||||||
"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>",
|
||||||
|
|
|
@ -11724,7 +11724,6 @@ Object {
|
||||||
Object {
|
Object {
|
||||||
"data": Object {
|
"data": Object {
|
||||||
"data": Object {
|
"data": Object {
|
||||||
"pic": Object {
|
|
||||||
"allowOverlap": true,
|
"allowOverlap": true,
|
||||||
"distB": 0,
|
"distB": 0,
|
||||||
"distL": 0,
|
"distL": 0,
|
||||||
|
@ -11750,7 +11749,7 @@ Object {
|
||||||
1699947,
|
1699947,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
"type": "pic",
|
||||||
},
|
},
|
||||||
"type": "drawing",
|
"type": "drawing",
|
||||||
},
|
},
|
||||||
|
@ -11794,7 +11793,6 @@ Object {
|
||||||
Object {
|
Object {
|
||||||
"data": Object {
|
"data": Object {
|
||||||
"data": Object {
|
"data": Object {
|
||||||
"pic": Object {
|
|
||||||
"allowOverlap": true,
|
"allowOverlap": true,
|
||||||
"distB": 0,
|
"distB": 0,
|
||||||
"distL": 114300,
|
"distL": 114300,
|
||||||
|
@ -11820,7 +11818,7 @@ Object {
|
||||||
1685925,
|
1685925,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
"type": "pic",
|
||||||
},
|
},
|
||||||
"type": "drawing",
|
"type": "drawing",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue