faet: Support snap to grid (#742)
parent
d448559c9e
commit
bf385f752d
|
@ -226,6 +226,11 @@ impl Paragraph {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn snap_to_grid(mut self, v: bool) -> Self {
|
||||||
|
self.property = self.property.snap_to_grid(v);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn keep_next(mut self, v: bool) -> Self {
|
pub fn keep_next(mut self, v: bool) -> Self {
|
||||||
self.property = self.property.keep_next(v);
|
self.property = self.property.keep_next(v);
|
||||||
self
|
self
|
||||||
|
|
|
@ -43,6 +43,8 @@ pub struct ParagraphProperty {
|
||||||
pub text_alignment: Option<TextAlignment>,
|
pub text_alignment: Option<TextAlignment>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub adjust_right_ind: Option<AdjustRightInd>,
|
pub adjust_right_ind: Option<AdjustRightInd>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub snap_to_grid: Option<bool>,
|
||||||
// read only
|
// read only
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub(crate) div_id: Option<String>,
|
pub(crate) div_id: Option<String>,
|
||||||
|
@ -99,6 +101,11 @@ impl ParagraphProperty {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn snap_to_grid(mut self, v: bool) -> Self {
|
||||||
|
self.snap_to_grid = Some(v);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn keep_next(mut self, v: bool) -> Self {
|
pub fn keep_next(mut self, v: bool) -> Self {
|
||||||
self.keep_next = Some(v);
|
self.keep_next = Some(v);
|
||||||
self
|
self
|
||||||
|
@ -210,6 +217,12 @@ fn inner_build(p: &ParagraphProperty) -> Vec<u8> {
|
||||||
.add_optional_child(&p.text_alignment)
|
.add_optional_child(&p.text_alignment)
|
||||||
.add_optional_child(&p.adjust_right_ind);
|
.add_optional_child(&p.adjust_right_ind);
|
||||||
|
|
||||||
|
if let Some(v) = p.snap_to_grid {
|
||||||
|
if v {
|
||||||
|
b = b.snap_to_grid()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(v) = p.keep_next {
|
if let Some(v) = p.keep_next {
|
||||||
if v {
|
if v {
|
||||||
b = b.keep_next()
|
b = b.keep_next()
|
||||||
|
|
|
@ -94,6 +94,11 @@ impl ElementReader for ParagraphProperty {
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
XMLElement::SnapToGrid => {
|
||||||
|
if read_bool(&attributes) {
|
||||||
|
p.snap_to_grid = Some(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
XMLElement::KeepNext => {
|
XMLElement::KeepNext => {
|
||||||
if read_bool(&attributes) {
|
if read_bool(&attributes) {
|
||||||
p.keep_next = Some(true);
|
p.keep_next = Some(true);
|
||||||
|
|
|
@ -52,6 +52,7 @@ pub enum XMLElement {
|
||||||
Justification,
|
Justification,
|
||||||
OutlineLvl,
|
OutlineLvl,
|
||||||
Insert,
|
Insert,
|
||||||
|
SnapToGrid,
|
||||||
KeepNext,
|
KeepNext,
|
||||||
KeepLines,
|
KeepLines,
|
||||||
PageBreakBefore,
|
PageBreakBefore,
|
||||||
|
@ -400,6 +401,7 @@ impl FromStr for XMLElement {
|
||||||
"marBottom" => Ok(XMLElement::MarginBottom),
|
"marBottom" => Ok(XMLElement::MarginBottom),
|
||||||
"sym" => Ok(XMLElement::Sym),
|
"sym" => Ok(XMLElement::Sym),
|
||||||
"webSettings" => Ok(XMLElement::WebSettings),
|
"webSettings" => Ok(XMLElement::WebSettings),
|
||||||
|
"snapToGrid" => Ok(XMLElement::SnapToGrid),
|
||||||
"keepNext" => Ok(XMLElement::KeepNext),
|
"keepNext" => Ok(XMLElement::KeepNext),
|
||||||
"keepLines" => Ok(XMLElement::KeepLines),
|
"keepLines" => Ok(XMLElement::KeepLines),
|
||||||
"pageBreakBefore" => Ok(XMLElement::PageBreakBefore),
|
"pageBreakBefore" => Ok(XMLElement::PageBreakBefore),
|
||||||
|
|
|
@ -167,6 +167,7 @@ impl XMLBuilder {
|
||||||
// i.e. <w:szCs ... >
|
// i.e. <w:szCs ... >
|
||||||
closed_with_usize!(sz_cs, "w:szCs");
|
closed_with_usize!(sz_cs, "w:szCs");
|
||||||
closed_with_isize!(adjust_right_ind, "w:adjustRightInd");
|
closed_with_isize!(adjust_right_ind, "w:adjustRightInd");
|
||||||
|
closed!(snap_to_grid, "w:snapToGrid");
|
||||||
closed_with_str!(text_alignment, "w:textAlignment");
|
closed_with_str!(text_alignment, "w:textAlignment");
|
||||||
|
|
||||||
closed!(field_character, "w:fldChar", "w:fldCharType", "w:dirty");
|
closed!(field_character, "w:fldChar", "w:fldCharType", "w:dirty");
|
||||||
|
|
|
@ -82,6 +82,7 @@ export type ParagraphProperty = {
|
||||||
widowControl: boolean;
|
widowControl: boolean;
|
||||||
paragraphPropertyChange?: ParagraphPropertyChange;
|
paragraphPropertyChange?: ParagraphPropertyChange;
|
||||||
outlineLvl?: number | null;
|
outlineLvl?: number | null;
|
||||||
|
snapToGrid?: boolean;
|
||||||
adjustRightInd?: number;
|
adjustRightInd?: number;
|
||||||
tabs?: Tab[];
|
tabs?: Tab[];
|
||||||
frameProperty?: FrameProperty;
|
frameProperty?: FrameProperty;
|
||||||
|
@ -334,6 +335,10 @@ export const setParagraphProperty = <T extends wasm.Paragraph | wasm.Style>(
|
||||||
target = target.keep_lines(true) as T;
|
target = target.keep_lines(true) as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (property.snapToGrid != null) {
|
||||||
|
target = target.snap_to_grid(!!property.snapToGrid) as T;
|
||||||
|
}
|
||||||
|
|
||||||
if (property.keepNext) {
|
if (property.keepNext) {
|
||||||
target = target.keep_next(true) as T;
|
target = target.keep_next(true) as T;
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,6 +208,11 @@ impl Paragraph {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn snap_to_grid(mut self, v: bool) -> Self {
|
||||||
|
self.0 = self.0.snap_to_grid(v);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn keep_lines(mut self, v: bool) -> Self {
|
pub fn keep_lines(mut self, v: bool) -> Self {
|
||||||
self.0 = self.0.keep_lines(v);
|
self.0 = self.0.keep_lines(v);
|
||||||
self
|
self
|
||||||
|
|
|
@ -159,6 +159,11 @@ impl Style {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn snap_to_grid(mut self, v: bool) -> Self {
|
||||||
|
self.0.paragraph_property = self.0.paragraph_property.snap_to_grid(v);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn keep_next(mut self, v: bool) -> Self {
|
pub fn keep_next(mut self, v: bool) -> Self {
|
||||||
self.0.paragraph_property = self.0.paragraph_property.keep_next(v);
|
self.0.paragraph_property = self.0.paragraph_property.keep_next(v);
|
||||||
self
|
self
|
||||||
|
|
Loading…
Reference in New Issue