feat: Support adjust_right_ind (#691)
* feat: Support adjust_right_ind * beta6 * fix: update spec * fixmain
parent
13b8d9bc44
commit
e182f0e2d3
|
@ -0,0 +1,29 @@
|
|||
use serde::{Serialize, Serializer};
|
||||
|
||||
use crate::documents::BuildXML;
|
||||
use crate::xml_builder::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct AdjustRightInd(pub isize);
|
||||
|
||||
impl AdjustRightInd {
|
||||
pub fn new(val: isize) -> AdjustRightInd {
|
||||
AdjustRightInd(val)
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildXML for AdjustRightInd {
|
||||
fn build(&self) -> Vec<u8> {
|
||||
let b = XMLBuilder::new();
|
||||
b.adjust_right_ind(self.0).build()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for AdjustRightInd {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_i64(self.0 as i64)
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
mod a_graphic;
|
||||
mod a_graphic_data;
|
||||
mod abstract_numbering;
|
||||
mod adjust_right_ind;
|
||||
mod based_on;
|
||||
mod bold;
|
||||
mod bold_cs;
|
||||
|
@ -130,6 +131,7 @@ mod zoom;
|
|||
pub use a_graphic::*;
|
||||
pub use a_graphic_data::*;
|
||||
pub use abstract_numbering::*;
|
||||
pub use adjust_right_ind::*;
|
||||
pub use based_on::*;
|
||||
pub use bold::*;
|
||||
pub use bold_cs::*;
|
||||
|
|
|
@ -33,9 +33,6 @@ pub struct ParagraphProperty {
|
|||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub section_property: Option<SectionProperty>,
|
||||
pub tabs: Vec<Tab>,
|
||||
// read only
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub(crate) div_id: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub paragraph_property_change: Option<ParagraphPropertyChange>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
@ -44,6 +41,11 @@ pub struct ParagraphProperty {
|
|||
pub frame_property: Option<FrameProperty>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub text_alignment: Option<TextAlignment>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub adjust_right_ind: Option<AdjustRightInd>,
|
||||
// read only
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub(crate) div_id: Option<String>,
|
||||
}
|
||||
|
||||
// 17.3.1.26
|
||||
|
@ -152,6 +154,11 @@ impl ParagraphProperty {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn adjust_right_ind(mut self, s: isize) -> Self {
|
||||
self.adjust_right_ind = Some(AdjustRightInd::new(s));
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn hanging_chars(mut self, chars: i32) -> Self {
|
||||
if let Some(indent) = self.indent {
|
||||
self.indent = Some(indent.hanging_chars(chars));
|
||||
|
@ -200,7 +207,8 @@ fn inner_build(p: &ParagraphProperty) -> Vec<u8> {
|
|||
.add_optional_child(&p.outline_lvl)
|
||||
.add_optional_child(&p.paragraph_property_change)
|
||||
.add_optional_child(&p.borders)
|
||||
.add_optional_child(&p.text_alignment);
|
||||
.add_optional_child(&p.text_alignment)
|
||||
.add_optional_child(&p.adjust_right_ind);
|
||||
|
||||
if let Some(v) = p.keep_next {
|
||||
if v {
|
||||
|
|
|
@ -56,6 +56,14 @@ impl ElementReader for ParagraphProperty {
|
|||
}
|
||||
continue;
|
||||
}
|
||||
XMLElement::AdjustRightInd => {
|
||||
if let Some(val) = read_val(&attributes) {
|
||||
if let Ok(v) = isize::from_str(&val) {
|
||||
p = p.adjust_right_ind(v);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
XMLElement::ParagraphStyle => {
|
||||
p = p.style(&attributes[0].value);
|
||||
continue;
|
||||
|
|
|
@ -161,6 +161,7 @@ pub enum XMLElement {
|
|||
PageNumType,
|
||||
FrameProperty,
|
||||
TextAlignment,
|
||||
AdjustRightInd,
|
||||
H,
|
||||
HAnchor,
|
||||
HSpace,
|
||||
|
@ -407,6 +408,7 @@ impl FromStr for XMLElement {
|
|||
"pgNumType" => Ok(XMLElement::PageNumType),
|
||||
"framePr" => Ok(XMLElement::FrameProperty),
|
||||
"textAlignment" => Ok(XMLElement::TextAlignment),
|
||||
"adjustRightInd" => Ok(XMLElement::AdjustRightInd),
|
||||
"h" => Ok(XMLElement::H),
|
||||
"hAnchor" => Ok(XMLElement::HAnchor),
|
||||
"hSpace" => Ok(XMLElement::HSpace),
|
||||
|
|
|
@ -165,7 +165,7 @@ impl XMLBuilder {
|
|||
closed_with_usize!(sz, "w:sz");
|
||||
// i.e. <w:szCs ... >
|
||||
closed_with_usize!(sz_cs, "w:szCs");
|
||||
|
||||
closed_with_isize!(adjust_right_ind, "w:adjustRightInd");
|
||||
closed_with_str!(text_alignment, "w:textAlignment");
|
||||
|
||||
closed!(field_character, "w:fldChar", "w:fldCharType", "w:dirty");
|
||||
|
|
|
@ -522,6 +522,17 @@ macro_rules! closed_with_usize {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! closed_with_isize {
|
||||
($name: ident, $el_name: expr) => {
|
||||
pub(crate) fn $name(mut self, val: isize) -> Self {
|
||||
self.writer
|
||||
.write(XmlEvent::start_element($el_name).attr("w:val", &format!("{}", val)))
|
||||
.expect("should write to buf");
|
||||
self.close()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! closed_w_with_type_el {
|
||||
($name: ident, $el_name: expr) => {
|
||||
pub(crate) fn $name(mut self, w: i32, t: WidthType) -> Self {
|
||||
|
@ -562,20 +573,16 @@ macro_rules! closed_border_el {
|
|||
|
||||
macro_rules! closed_paragraph_border_el {
|
||||
($name: ident, $ el_name: expr) => {
|
||||
pub(crate) fn $name<'a>(
|
||||
mut self,
|
||||
val: &str,
|
||||
space: &str,
|
||||
size: &str,
|
||||
color: &str,
|
||||
) -> Self {
|
||||
self.writer.write(
|
||||
XmlEvent::start_element($el_name)
|
||||
.attr("w:val", val)
|
||||
.attr("w:space", space)
|
||||
.attr("w:sz", size)
|
||||
.attr("w:color", color)
|
||||
).expect(EXPECT_MESSAGE);
|
||||
pub(crate) fn $name<'a>(mut self, val: &str, space: &str, size: &str, color: &str) -> Self {
|
||||
self.writer
|
||||
.write(
|
||||
XmlEvent::start_element($el_name)
|
||||
.attr("w:val", val)
|
||||
.attr("w:space", space)
|
||||
.attr("w:sz", size)
|
||||
.attr("w:color", color),
|
||||
)
|
||||
.expect(EXPECT_MESSAGE);
|
||||
self.close()
|
||||
}
|
||||
};
|
||||
|
|
|
@ -13,3 +13,6 @@ crate-type = ["cdylib"]
|
|||
wasm-bindgen = "0.2.78"
|
||||
console_error_panic_hook = "0.1.7"
|
||||
docx-rs= { path = "../docx-core", features = ["wasm"] }
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
|
@ -7,6 +7,7 @@ import {
|
|||
} from "..";
|
||||
import { LineSpacingJSON } from "./line_spacing";
|
||||
import { FrameProperty as FramePropertyJSON } from "./bindings/FrameProperty";
|
||||
import { TextAlignmentType } from "./bindings/TextAlignmentType";
|
||||
|
||||
export { FrameProperty as FramePropertyJSON } from "./bindings/FrameProperty";
|
||||
|
||||
|
@ -64,6 +65,8 @@ export type ParagraphPropertyJSON = {
|
|||
| "start"
|
||||
| "end"
|
||||
| "unsupported";
|
||||
textAlignment?: TextAlignmentType;
|
||||
adjustRightInd?: number;
|
||||
indent?: IndentJSON | null;
|
||||
lineSpacing?: LineSpacingJSON | null;
|
||||
divId?: string | null;
|
||||
|
|
|
@ -72,6 +72,7 @@ export type ParagraphProperty = {
|
|||
widowControl: boolean;
|
||||
paragraphPropertyChange?: ParagraphPropertyChange;
|
||||
outlineLvl?: number | null;
|
||||
adjustRightInd?: number;
|
||||
};
|
||||
|
||||
export const createDefaultParagraphProperty = (): ParagraphProperty => {
|
||||
|
@ -165,6 +166,11 @@ export class ParagraphPropertyChange {
|
|||
return this;
|
||||
}
|
||||
|
||||
adjustRightInd(v: number) {
|
||||
this._property.adjustRightInd = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
style(id: string) {
|
||||
this._property.styleId = id;
|
||||
return this;
|
||||
|
@ -246,6 +252,10 @@ export const setParagraphProperty = <T extends wasm.Paragraph | wasm.Style>(
|
|||
target = target.text_alignment(textAlignment) as T;
|
||||
}
|
||||
|
||||
if (property.adjustRightInd != null) {
|
||||
target = target.adjust_right_ind(property.adjustRightInd) as T;
|
||||
}
|
||||
|
||||
if (typeof property.indent !== "undefined") {
|
||||
const { indent } = property;
|
||||
let kind;
|
||||
|
|
|
@ -14,6 +14,7 @@ import { BookmarkEnd } from "./bookmark-end";
|
|||
import { Comment } from "./comment";
|
||||
import { CommentEnd } from "./comment-end";
|
||||
import { Hyperlink } from "./hyperlink";
|
||||
import { TextAlignmentType } from "./json/bindings/TextAlignmentType";
|
||||
|
||||
export type ParagraphChild =
|
||||
| Run
|
||||
|
@ -75,6 +76,16 @@ export class Paragraph {
|
|||
return this;
|
||||
}
|
||||
|
||||
textAlignment(type: TextAlignmentType) {
|
||||
this.property.textAlignment = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
adjustRightInd(v: number) {
|
||||
this.property.adjustRightInd = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
style(id: string) {
|
||||
this.property.styleId = id;
|
||||
return this;
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
{
|
||||
"name": "docx-wasm",
|
||||
"version": "0.4.12-beta5",
|
||||
"version": "0.4.12-beta9",
|
||||
"main": "dist/node/index.js",
|
||||
"browser": "dist/web/index.js",
|
||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"wasm-pack:dev": "wasm-pack build --out-dir js/pkg",
|
||||
"wasm-pack:web": "wasm-pack build --release --out-dir dist/web/pkg",
|
||||
"wasm-pack:node": "wasm-pack build --release --out-dir dist/node/pkg --target nodejs",
|
||||
"wasm-pack:web": "wasm-pack build --release --out-dir dist/web/pkg && rm dist/web/pkg/.gitignore",
|
||||
"wasm-pack:node": "wasm-pack build --release --out-dir dist/node/pkg --target nodejs && rm dist/node/pkg/.gitignore",
|
||||
"wasm-pack": "run-s wasm-pack:*",
|
||||
"tsc:web": "tsc -p tsconfig.web.json --sourcemap",
|
||||
"tsc:node": "tsc -p tsconfig.node.json --sourcemap",
|
||||
|
@ -44,8 +44,8 @@
|
|||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"dist/web/pkg/*",
|
||||
"dist/node/pkg/*",
|
||||
"dist/web/pkg",
|
||||
"dist/node/pkg",
|
||||
"js/*"
|
||||
],
|
||||
"module": "dist/web/index.js",
|
||||
|
|
|
@ -136,6 +136,11 @@ impl Paragraph {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn adjust_right_ind(mut self, v: isize) -> Paragraph {
|
||||
self.0.property = self.0.property.adjust_right_ind(v);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn outline_lvl(mut self, level: usize) -> Paragraph {
|
||||
self.0.property = self.0.property.outline_lvl(level);
|
||||
self
|
||||
|
|
|
@ -109,6 +109,11 @@ impl Style {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn adjust_right_ind(mut self, v: isize) -> Self {
|
||||
self.0.paragraph_property = self.0.paragraph_property.adjust_right_ind(v);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn indent(
|
||||
mut self,
|
||||
left: i32,
|
||||
|
|
|
@ -3470,6 +3470,7 @@ Object {
|
|||
"name": "Level 1",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"indent": Object {
|
||||
"end": null,
|
||||
"firstLineChars": null,
|
||||
|
@ -3558,6 +3559,7 @@ Object {
|
|||
"name": "Level 2",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"indent": Object {
|
||||
"end": null,
|
||||
"firstLineChars": null,
|
||||
|
@ -34417,6 +34419,7 @@ Object {
|
|||
"name": "heading 3",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"indent": Object {
|
||||
"end": null,
|
||||
"firstLineChars": null,
|
||||
|
@ -96362,6 +96365,7 @@ Object {
|
|||
"name": "Normal",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "both",
|
||||
"lineSpacing": Object {
|
||||
"line": 360,
|
||||
|
@ -100950,6 +100954,7 @@ Object {
|
|||
"name": "List Number",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"indent": Object {
|
||||
"end": null,
|
||||
"firstLineChars": 0,
|
||||
|
@ -101061,6 +101066,7 @@ Object {
|
|||
"name": "Reference2",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "both",
|
||||
"indent": Object {
|
||||
"end": null,
|
||||
|
@ -101324,6 +101330,7 @@ Object {
|
|||
"name": "Sentence indent2",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "both",
|
||||
"indent": Object {
|
||||
"end": null,
|
||||
|
@ -101493,6 +101500,7 @@ Object {
|
|||
"name": "Definition_sentence",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "both",
|
||||
"indent": Object {
|
||||
"end": null,
|
||||
|
@ -101664,6 +101672,7 @@ Object {
|
|||
"name": "List Number 2",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "both",
|
||||
"lineSpacing": Object {
|
||||
"before": 120,
|
||||
|
@ -101753,6 +101762,7 @@ Object {
|
|||
"name": "Note1",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "both",
|
||||
"lineSpacing": Object {
|
||||
"before": 120,
|
||||
|
@ -101842,6 +101852,7 @@ Object {
|
|||
"name": "Reference1",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"indent": Object {
|
||||
"end": null,
|
||||
"firstLineChars": null,
|
||||
|
@ -101945,6 +101956,7 @@ Object {
|
|||
"name": "Sentence indent1",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "both",
|
||||
"indent": Object {
|
||||
"end": null,
|
||||
|
@ -102039,6 +102051,7 @@ Object {
|
|||
"name": "Bullet1",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "both",
|
||||
"indent": Object {
|
||||
"end": null,
|
||||
|
@ -102137,6 +102150,7 @@ Object {
|
|||
"name": "List Number 3",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"keepNext": true,
|
||||
"lineSpacing": Object {
|
||||
"before": 240,
|
||||
|
@ -102226,6 +102240,7 @@ Object {
|
|||
"name": "Note2",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "both",
|
||||
"lineSpacing": Object {
|
||||
"before": 120,
|
||||
|
@ -102316,6 +102331,7 @@ Object {
|
|||
"name": "Note3",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "both",
|
||||
"lineSpacing": Object {
|
||||
"before": 120,
|
||||
|
@ -102405,6 +102421,7 @@ Object {
|
|||
"name": "Bullet2",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "both",
|
||||
"indent": Object {
|
||||
"end": null,
|
||||
|
@ -102516,6 +102533,7 @@ Object {
|
|||
"name": "Sentence indent3",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "both",
|
||||
"indent": Object {
|
||||
"end": null,
|
||||
|
@ -103562,6 +103580,7 @@ Object {
|
|||
"name": "表紙の日付他",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "right",
|
||||
"keepLines": true,
|
||||
"keepNext": true,
|
||||
|
@ -104958,6 +104977,7 @@ Object {
|
|||
"name": "macro",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"runProperty": Object {},
|
||||
"tabs": Array [
|
||||
Object {
|
||||
|
@ -109644,6 +109664,7 @@ Object {
|
|||
"name": "Default",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"runProperty": Object {},
|
||||
"tabs": Array [],
|
||||
},
|
||||
|
@ -109800,6 +109821,7 @@ Object {
|
|||
"name": "Table Bullet1",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"lineSpacing": Object {
|
||||
"before": 20,
|
||||
"line": 200,
|
||||
|
@ -143496,6 +143518,7 @@ Object {
|
|||
"name": "Char",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "left",
|
||||
"indent": Object {
|
||||
"end": 0,
|
||||
|
@ -143619,6 +143642,7 @@ Object {
|
|||
"name": "Char1 Char Char Znak Znak1",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"indent": Object {
|
||||
"end": 0,
|
||||
"firstLineChars": null,
|
||||
|
@ -143736,6 +143760,7 @@ Object {
|
|||
"name": "Char1",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"indent": Object {
|
||||
"end": 0,
|
||||
"firstLineChars": null,
|
||||
|
@ -167653,6 +167678,7 @@ Object {
|
|||
"name": "Table Grid",
|
||||
"next": null,
|
||||
"paragraphProperty": Object {
|
||||
"adjustRightInd": 0,
|
||||
"alignment": "both",
|
||||
"lineSpacing": Object {
|
||||
"line": 340,
|
||||
|
|
Loading…
Reference in New Issue