Support textdirection (#545)

* add text direction setting

* add text_directionSetting setting function

* snapshots update

* change tex_direction type

* change test snapshots

* change wasm test snap
main
hayato-SMZ 2022-10-14 14:24:13 +09:00 committed by GitHub
parent 5a9c13dd5e
commit 984c0c2005
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 96 additions and 42 deletions

View File

@ -209,10 +209,15 @@ impl Document {
self
}
pub fn columns(mut self, col: usize) -> Self{
pub fn columns(mut self, col: usize) -> Self {
self.section_property.columns = col;
self
}
pub fn text_direction(mut self, direction: String) -> Self {
self.section_property.text_direction = direction;
self
}
}
impl BuildXML for DocumentChild {
@ -281,11 +286,11 @@ mod tests {
);
}
#[test]
#[test]
fn test_document_cols() {
let b = Document::new().columns(2)
let b = Document::new()
.columns(2)
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")))
.build();
assert_eq!(
str::from_utf8(&b).unwrap(),

View File

@ -14,6 +14,7 @@ pub struct SectionProperty {
pub columns: usize,
pub space: usize,
pub title_pg: bool,
pub text_direction: String,
pub doc_grid: DocGrid,
#[serde(skip_serializing_if = "Option::is_none")]
pub header_reference: Option<HeaderReference>,
@ -68,6 +69,11 @@ impl SectionProperty {
self
}
pub fn text_direction(mut self, direction: String) -> Self {
self.text_direction = direction;
self
}
pub fn title_pg(mut self) -> Self {
self.title_pg = true;
self
@ -160,6 +166,7 @@ impl Default for SectionProperty {
columns: 1,
space: 425,
title_pg: false,
text_direction: "lrTb".to_string(),
doc_grid: DocGrid::default(),
// headers
header_reference: None,
@ -195,7 +202,9 @@ impl BuildXML for SectionProperty {
.add_optional_child(&self.footer_reference)
.add_optional_child(&self.first_footer_reference)
.add_optional_child(&self.even_footer_reference);
if !self.text_direction.eq("lrTb") {
b = b.text_direction(&self.text_direction);
}
if let Some(t) = self.section_type {
b = b.type_tag(&t.to_string());
}
@ -216,6 +225,18 @@ mod tests {
use pretty_assertions::assert_eq;
use std::str;
#[test]
fn text_section_text_direction() {
let mut c = SectionProperty::new();
c = c.text_direction("tbRl".to_string());
let b = c.build();
assert_eq!(
str::from_utf8(&b).unwrap(),
r#"<w:sectPr><w:pgSz w:w="11906" w:h="16838" /><w:pgMar w:top="1985" w:right="1701" w:bottom="1701" w:left="1701" w:header="851" w:footer="992" w:gutter="0" /><w:cols w:space="425" w:num="1" /><w:docGrid w:type="lines" w:linePitch="360" /><w:textDirection w:val="tbRl" />
</w:sectPr>"#
)
}
#[test]
fn test_section_property_default() {
let c = SectionProperty::new();

View File

@ -160,7 +160,7 @@ impl XMLBuilder {
open!(open_instr_text, "w:instrText");
closed_with_str!(text_direction, "w:textDirection");
closed!(text_direction, "w:textDirection", "w:val");
closed!(b, "w:b");
closed!(b_cs, "w:bCs");
@ -368,6 +368,7 @@ impl XMLBuilder {
"w:gutter"
);
closed!(columns, "w:cols", "w:space", "w:num");
// closed!(text_direction, "w:val");
closed!(document_grid, "w:docGrid", "w:type", "w:linePitch");
open!(open_insert, "w:ins", "w:id", "w:author", "w:date");

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

View File

@ -534,6 +534,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -1397,6 +1398,7 @@ Object {
"w": 11906,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -1846,6 +1848,7 @@ Object {
"w": 11907,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -4173,6 +4176,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -5480,6 +5484,7 @@ Object {
"w": 11906,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -5843,6 +5848,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -7163,6 +7169,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": true,
},
},
@ -10159,6 +10166,7 @@ Object {
"w": 11906,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -11043,6 +11051,7 @@ Object {
"w": 11906,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -12674,6 +12683,7 @@ Object {
"w": 11906,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -14217,6 +14227,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -15163,6 +15174,7 @@ Object {
"w": 11906,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -15573,6 +15585,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -18118,6 +18131,7 @@ Object {
"w": 11906,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -20296,6 +20310,7 @@ Object {
"w": 11906,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -21416,6 +21431,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -24287,6 +24303,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -27996,6 +28013,7 @@ Object {
"w": 11906,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
"style": "1",
@ -28603,6 +28621,7 @@ Object {
"w": 11906,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -87414,6 +87433,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -90735,6 +90755,7 @@ Object {
"w": 12242,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -107272,6 +107293,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -108291,6 +108313,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -110200,6 +110223,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -114078,6 +114102,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -115097,6 +115122,7 @@ Object {
"w": 11900,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
@ -116144,6 +116170,7 @@ Object {
"w": 11906,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": true,
},
},