faet: Support snap to grid (#742)

main
bokuweb 2024-07-17 16:28:29 +09:00 committed by GitHub
parent d448559c9e
commit bf385f752d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 41 additions and 0 deletions

View File

@ -226,6 +226,11 @@ impl Paragraph {
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 {
self.property = self.property.keep_next(v);
self

View File

@ -43,6 +43,8 @@ pub struct ParagraphProperty {
pub text_alignment: Option<TextAlignment>,
#[serde(skip_serializing_if = "Option::is_none")]
pub adjust_right_ind: Option<AdjustRightInd>,
#[serde(skip_serializing_if = "Option::is_none")]
pub snap_to_grid: Option<bool>,
// read only
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) div_id: Option<String>,
@ -99,6 +101,11 @@ impl ParagraphProperty {
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 {
self.keep_next = Some(v);
self
@ -210,6 +217,12 @@ fn inner_build(p: &ParagraphProperty) -> Vec<u8> {
.add_optional_child(&p.text_alignment)
.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 v {
b = b.keep_next()

View File

@ -94,6 +94,11 @@ impl ElementReader for ParagraphProperty {
}
continue;
}
XMLElement::SnapToGrid => {
if read_bool(&attributes) {
p.snap_to_grid = Some(true);
}
}
XMLElement::KeepNext => {
if read_bool(&attributes) {
p.keep_next = Some(true);

View File

@ -52,6 +52,7 @@ pub enum XMLElement {
Justification,
OutlineLvl,
Insert,
SnapToGrid,
KeepNext,
KeepLines,
PageBreakBefore,
@ -400,6 +401,7 @@ impl FromStr for XMLElement {
"marBottom" => Ok(XMLElement::MarginBottom),
"sym" => Ok(XMLElement::Sym),
"webSettings" => Ok(XMLElement::WebSettings),
"snapToGrid" => Ok(XMLElement::SnapToGrid),
"keepNext" => Ok(XMLElement::KeepNext),
"keepLines" => Ok(XMLElement::KeepLines),
"pageBreakBefore" => Ok(XMLElement::PageBreakBefore),

View File

@ -167,6 +167,7 @@ impl XMLBuilder {
// i.e. <w:szCs ... >
closed_with_usize!(sz_cs, "w:szCs");
closed_with_isize!(adjust_right_ind, "w:adjustRightInd");
closed!(snap_to_grid, "w:snapToGrid");
closed_with_str!(text_alignment, "w:textAlignment");
closed!(field_character, "w:fldChar", "w:fldCharType", "w:dirty");

View File

@ -82,6 +82,7 @@ export type ParagraphProperty = {
widowControl: boolean;
paragraphPropertyChange?: ParagraphPropertyChange;
outlineLvl?: number | null;
snapToGrid?: boolean;
adjustRightInd?: number;
tabs?: Tab[];
frameProperty?: FrameProperty;
@ -334,6 +335,10 @@ export const setParagraphProperty = <T extends wasm.Paragraph | wasm.Style>(
target = target.keep_lines(true) as T;
}
if (property.snapToGrid != null) {
target = target.snap_to_grid(!!property.snapToGrid) as T;
}
if (property.keepNext) {
target = target.keep_next(true) as T;
}

View File

@ -208,6 +208,11 @@ impl Paragraph {
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 {
self.0 = self.0.keep_lines(v);
self

View File

@ -159,6 +159,11 @@ impl Style {
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 {
self.0.paragraph_property = self.0.paragraph_property.keep_next(v);
self