parent
f58fbacdcf
commit
54990d5eb1
|
@ -190,7 +190,7 @@ mod tests {
|
|||
let t = Table::new(vec![]).set_grid(vec![100, 200, 300]);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&t).unwrap(),
|
||||
r#"{"rows":[],"grid":[100,200,300],"hasNumbering":false,"property":{"width":{"width":0,"widthType":"Auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":{"val":0,"widthType":"DXA"},"left":{"val":55,"widthType":"DXA"},"bottom":{"val":0,"widthType":"DXA"},"right":{"val":55,"widthType":"DXA"}},"indent":null,"style":null,"layout":null}}"#
|
||||
r#"{"rows":[],"grid":[100,200,300],"hasNumbering":false,"property":{"width":{"width":0,"widthType":"auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":{"val":0,"widthType":"dxa"},"left":{"val":55,"widthType":"dxa"},"bottom":{"val":0,"widthType":"dxa"},"right":{"val":55,"widthType":"dxa"}},"indent":null,"style":null,"layout":null}}"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ impl Default for CellMargin {
|
|||
fn default() -> CellMargin {
|
||||
CellMargin {
|
||||
val: 55,
|
||||
width_type: WidthType::DXA,
|
||||
width_type: WidthType::Dxa,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,12 +40,12 @@ impl Default for TableCellMargins {
|
|||
TableCellMargins {
|
||||
top: CellMargin {
|
||||
val: 0,
|
||||
width_type: WidthType::DXA,
|
||||
width_type: WidthType::Dxa,
|
||||
},
|
||||
left: CellMargin::default(),
|
||||
bottom: CellMargin {
|
||||
val: 0,
|
||||
width_type: WidthType::DXA,
|
||||
width_type: WidthType::Dxa,
|
||||
},
|
||||
right: CellMargin::default(),
|
||||
}
|
||||
|
@ -59,10 +59,10 @@ impl TableCellMargins {
|
|||
|
||||
pub fn margin(self, top: usize, right: usize, bottom: usize, left: usize) -> TableCellMargins {
|
||||
TableCellMargins {
|
||||
top: CellMargin::new(top, WidthType::DXA),
|
||||
left: CellMargin::new(left, WidthType::DXA),
|
||||
bottom: CellMargin::new(bottom, WidthType::DXA),
|
||||
right: CellMargin::new(right, WidthType::DXA),
|
||||
top: CellMargin::new(top, WidthType::Dxa),
|
||||
left: CellMargin::new(left, WidthType::Dxa),
|
||||
bottom: CellMargin::new(bottom, WidthType::Dxa),
|
||||
right: CellMargin::new(right, WidthType::Dxa),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -166,10 +166,10 @@ mod tests {
|
|||
let c = TableCellProperty::new()
|
||||
.vertical_merge(VMergeType::Continue)
|
||||
.grid_span(3)
|
||||
.width(200, WidthType::DXA);
|
||||
.width(200, WidthType::Dxa);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&c).unwrap(),
|
||||
r#"{"width":{"width":200,"widthType":"DXA"},"borders":null,"gridSpan":3,"verticalMerge":"continue","verticalAlign":null,"textDirection":null,"shading":null}"#
|
||||
r#"{"width":{"width":200,"widthType":"dxa"},"borders":null,"gridSpan":3,"verticalMerge":"continue","verticalAlign":null,"textDirection":null,"shading":null}"#
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ impl TableCellWidth {
|
|||
impl BuildXML for TableCellWidth {
|
||||
fn build(&self) -> Vec<u8> {
|
||||
XMLBuilder::new()
|
||||
.table_cell_width(self.width as i32, WidthType::DXA)
|
||||
.table_cell_width(self.width as i32, WidthType::Dxa)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_table_width() {
|
||||
let b = TableCellWidth::new(20, WidthType::DXA).build();
|
||||
let b = TableCellWidth::new(20, WidthType::Dxa).build();
|
||||
assert_eq!(
|
||||
str::from_utf8(&b).unwrap(),
|
||||
r#"<w:tcW w:w="20" w:type="dxa" />"#
|
||||
|
|
|
@ -17,7 +17,7 @@ impl BuildXML for TableGrid {
|
|||
fn build(&self) -> Vec<u8> {
|
||||
let mut base = XMLBuilder::new().open_table_grid();
|
||||
for g in &self.grid {
|
||||
base = base.grid_column(*g as i32, WidthType::DXA);
|
||||
base = base.grid_column(*g as i32, WidthType::Dxa);
|
||||
}
|
||||
base.close().build()
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ impl TableIndent {
|
|||
impl BuildXML for TableIndent {
|
||||
fn build(&self) -> Vec<u8> {
|
||||
XMLBuilder::new()
|
||||
.table_indent(self.width, WidthType::DXA)
|
||||
.table_indent(self.width, WidthType::Dxa)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_table_indent() {
|
||||
let b = TableIndent::new(20, WidthType::DXA).build();
|
||||
let b = TableIndent::new(20, WidthType::Dxa).build();
|
||||
assert_eq!(
|
||||
str::from_utf8(&b).unwrap(),
|
||||
r#"<w:tblInd w:w="20" w:type="dxa" />"#
|
||||
|
|
|
@ -46,7 +46,7 @@ impl TableProperty {
|
|||
}
|
||||
|
||||
pub fn indent(mut self, v: i32) -> TableProperty {
|
||||
self.indent = Some(TableIndent::new(v, WidthType::DXA));
|
||||
self.indent = Some(TableIndent::new(v, WidthType::Dxa));
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ mod tests {
|
|||
let p = TableProperty::new().indent(100);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&p).unwrap(),
|
||||
r#"{"width":{"width":0,"widthType":"Auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":{"val":0,"widthType":"DXA"},"left":{"val":55,"widthType":"DXA"},"bottom":{"val":0,"widthType":"DXA"},"right":{"val":55,"widthType":"DXA"}},"indent":{"width":100,"widthType":"DXA"},"style":null,"layout":null}"#
|
||||
r#"{"width":{"width":0,"widthType":"auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":{"val":0,"widthType":"dxa"},"left":{"val":55,"widthType":"dxa"},"bottom":{"val":0,"widthType":"dxa"},"right":{"val":55,"widthType":"dxa"}},"indent":{"width":100,"widthType":"dxa"},"style":null,"layout":null}"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ impl TableWidth {
|
|||
impl BuildXML for TableWidth {
|
||||
fn build(&self) -> Vec<u8> {
|
||||
XMLBuilder::new()
|
||||
.table_width(self.width as i32, WidthType::DXA)
|
||||
.table_width(self.width as i32, WidthType::Dxa)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_table_width() {
|
||||
let b = TableWidth::new(20, WidthType::DXA).build();
|
||||
let b = TableWidth::new(20, WidthType::Dxa).build();
|
||||
assert_eq!(
|
||||
str::from_utf8(&b).unwrap(),
|
||||
r#"<w:tblW w:w="20" w:type="dxa" />"#
|
||||
|
|
|
@ -103,7 +103,7 @@ mod tests {
|
|||
t,
|
||||
Table::without_borders(vec![])
|
||||
.set_grid(vec![3212, 3213, 3213])
|
||||
.width(9638, WidthType::DXA)
|
||||
.width(9638, WidthType::Dxa)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ mod tests {
|
|||
cell,
|
||||
TableCell::new()
|
||||
.add_paragraph(Paragraph::new().add_run(Run::new()))
|
||||
.width(6425, WidthType::DXA)
|
||||
.width(6425, WidthType::Dxa)
|
||||
.grid_span(2)
|
||||
.vertical_merge(VMergeType::Restart)
|
||||
.set_border(TableCellBorder::new(TableCellBorderPosition::Top))
|
||||
|
@ -123,7 +123,7 @@ mod tests {
|
|||
cell,
|
||||
TableCell::new()
|
||||
.add_paragraph(Paragraph::new().add_run(Run::new()))
|
||||
.width(6425, WidthType::DXA)
|
||||
.width(6425, WidthType::Dxa)
|
||||
.vertical_merge(VMergeType::Continue),
|
||||
);
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ mod tests {
|
|||
cell,
|
||||
TableCell::new()
|
||||
.add_paragraph(Paragraph::new().add_run(Run::new()))
|
||||
.width(6425, WidthType::DXA)
|
||||
.width(6425, WidthType::Dxa)
|
||||
.vertical_align(VAlignType::Bottom),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -7,8 +7,9 @@ use std::str::FromStr;
|
|||
|
||||
#[wasm_bindgen]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum WidthType {
|
||||
DXA,
|
||||
Dxa,
|
||||
Auto,
|
||||
Pct,
|
||||
Nil,
|
||||
|
@ -18,7 +19,7 @@ pub enum WidthType {
|
|||
impl fmt::Display for WidthType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
WidthType::DXA => write!(f, "dxa"),
|
||||
WidthType::Dxa => write!(f, "dxa"),
|
||||
WidthType::Auto => write!(f, "auto"),
|
||||
WidthType::Pct => write!(f, "pct"),
|
||||
WidthType::Nil => write!(f, "nil"),
|
||||
|
@ -30,11 +31,12 @@ impl fmt::Display for WidthType {
|
|||
impl FromStr for WidthType {
|
||||
type Err = errors::TypeError;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
// https://github.com/bokuweb/docx-rs/issues/451
|
||||
match s {
|
||||
"dxa" => Ok(WidthType::DXA),
|
||||
"auto" => Ok(WidthType::Auto),
|
||||
"pct" => Ok(WidthType::Pct),
|
||||
"nil" => Ok(WidthType::Nil),
|
||||
"DXA" | "dxa" => Ok(WidthType::Dxa),
|
||||
"Auto" | "auto" => Ok(WidthType::Auto),
|
||||
"Pct" | "pct" => Ok(WidthType::Pct),
|
||||
"Nil" | "nil" => Ok(WidthType::Nil),
|
||||
_ => Ok(WidthType::Unsupported),
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -30,7 +30,7 @@ import {
|
|||
PageMargin,
|
||||
PageOrientationType,
|
||||
} from "./section-property";
|
||||
import { DocGridType, DocxJSON, WidthType } from "./json";
|
||||
import { DocGridType, DocxJSON } from "./json";
|
||||
|
||||
import * as wasm from "./pkg";
|
||||
import { Level } from "./level";
|
||||
|
@ -62,18 +62,22 @@ const convertBorderType = (t: BorderType) => {
|
|||
}
|
||||
};
|
||||
|
||||
const convertWidthType = (t: WidthType) => {
|
||||
const convertWidthType = (t: string) => {
|
||||
switch (t) {
|
||||
case "nil":
|
||||
case "Nil":
|
||||
return wasm.WidthType.Nil;
|
||||
case "Pct":
|
||||
case "pct":
|
||||
return wasm.WidthType.Pct;
|
||||
case "DXA":
|
||||
return wasm.WidthType.DXA;
|
||||
case "dxa":
|
||||
return wasm.WidthType.Dxa;
|
||||
case "Auto":
|
||||
case "auto":
|
||||
return wasm.WidthType.Auto;
|
||||
default:
|
||||
return wasm.WidthType.DXA;
|
||||
return wasm.WidthType.Dxa;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ import { DeleteJSON, InsertJSON } from "..";
|
|||
|
||||
export type TableCellChildJSON = ParagraphJSON;
|
||||
|
||||
export type WidthType = "DXA" | "Auto" | "Pct" | "nil";
|
||||
export type WidthType = "dxa" | "auto" | "pct" | "nil";
|
||||
|
||||
export { TextDirectionType } from "../table-cell";
|
||||
|
||||
export { HeightRule } from "../table-row";
|
||||
|
|
|
@ -19,10 +19,10 @@ export type TableProperty = {
|
|||
|
||||
export const createDefaultTableCellMargins = () => {
|
||||
return {
|
||||
top: { val: 0, type: "DXA" },
|
||||
left: { val: 55, type: "DXA" },
|
||||
bottom: { val: 0, type: "DXA" },
|
||||
right: { val: 55, type: "DXA" },
|
||||
top: { val: 0, type: "dxa" },
|
||||
left: { val: 55, type: "dxa" },
|
||||
bottom: { val: 0, type: "dxa" },
|
||||
right: { val: 55, type: "dxa" },
|
||||
} as const;
|
||||
};
|
||||
|
||||
|
@ -69,10 +69,10 @@ export class Table {
|
|||
|
||||
cellMargins(top: number, right: number, bottom: number, left: number) {
|
||||
this.property.cellMargins = {
|
||||
top: { val: top, type: "DXA" },
|
||||
left: { val: left, type: "DXA" },
|
||||
bottom: { val: bottom, type: "DXA" },
|
||||
right: { val: right, type: "DXA" },
|
||||
top: { val: top, type: "dxa" },
|
||||
left: { val: left, type: "dxa" },
|
||||
bottom: { val: bottom, type: "dxa" },
|
||||
right: { val: right, type: "dxa" },
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ impl Table {
|
|||
}
|
||||
|
||||
pub fn width(mut self, w: usize) -> Table {
|
||||
self.0 = self.0.width(w, docx_rs::WidthType::DXA);
|
||||
self.0 = self.0.width(w, docx_rs::WidthType::Dxa);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ impl TableCell {
|
|||
}
|
||||
|
||||
pub fn width(mut self, v: usize) -> TableCell {
|
||||
self.0.property = self.0.property.width(v, docx_rs::WidthType::DXA);
|
||||
self.0.property = self.0.property.width(v, docx_rs::WidthType::Dxa);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue