-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add ptab * feat: wasm object * fix: suppoert ptab * spec: add read test for ptab * rc10 * rc11 * rc12
- Loading branch information
Showing
22 changed files
with
573 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use std::io::Read; | ||
use std::str::FromStr; | ||
|
||
use xml::attribute::OwnedAttribute; | ||
use xml::reader::{EventReader, XmlEvent}; | ||
|
||
use crate::{PositionalTabAlignmentType, PositionalTabRelativeTo, TabLeaderType}; | ||
|
||
use super::*; | ||
|
||
fn read_leader(attributes: &[OwnedAttribute]) -> Result<TabLeaderType, ReaderError> { | ||
for a in attributes { | ||
let local_name = &a.name.local_name; | ||
if local_name == "leader" { | ||
let v = a.value.to_owned(); | ||
if let Ok(t) = TabLeaderType::from_str(&v) { | ||
return Ok(t); | ||
} | ||
} | ||
} | ||
Err(ReaderError::TypeError(crate::TypeError::FromStrError)) | ||
} | ||
|
||
fn read_alignment( | ||
attributes: &[OwnedAttribute], | ||
) -> Result<PositionalTabAlignmentType, ReaderError> { | ||
for a in attributes { | ||
let local_name = &a.name.local_name; | ||
if local_name == "alignment" { | ||
let v = a.value.to_owned(); | ||
if let Ok(t) = PositionalTabAlignmentType::from_str(&v) { | ||
return Ok(t); | ||
} | ||
} | ||
} | ||
Err(ReaderError::TypeError(crate::TypeError::FromStrError)) | ||
} | ||
|
||
fn read_relative_to(attributes: &[OwnedAttribute]) -> Result<PositionalTabRelativeTo, ReaderError> { | ||
for a in attributes { | ||
let local_name = &a.name.local_name; | ||
if local_name == "alignment" { | ||
let v = a.value.to_owned(); | ||
if let Ok(t) = PositionalTabRelativeTo::from_str(&v) { | ||
return Ok(t); | ||
} | ||
} | ||
} | ||
Err(ReaderError::TypeError(crate::TypeError::FromStrError)) | ||
} | ||
|
||
impl ElementReader for PositionalTab { | ||
fn read<R: Read>( | ||
r: &mut EventReader<R>, | ||
attrs: &[OwnedAttribute], | ||
) -> Result<Self, ReaderError> { | ||
let mut tab = PositionalTab::default(); | ||
if let Ok(t) = read_alignment(attrs) { | ||
tab = tab.alignment(t); | ||
} | ||
if let Ok(v) = read_relative_to(attrs) { | ||
tab = tab.relative_to(v); | ||
} | ||
if let Ok(leader) = read_leader(attrs) { | ||
tab = tab.leader(leader); | ||
} | ||
loop { | ||
let e = r.next(); | ||
match e { | ||
Ok(XmlEvent::EndElement { name, .. }) => { | ||
let e = XMLElement::from_str(&name.local_name).unwrap(); | ||
if e == XMLElement::PTab { | ||
return Ok(tab); | ||
} | ||
} | ||
Err(_) => return Err(ReaderError::XMLReadError), | ||
_ => {} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
|
||
export type PositionalTabRelativeTo = "Indent" | "Margin"; | ||
export type PositionalTabRelativeTo = "indent" | "margin"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { PositionalTabAlignmentType } from "./json/bindings/PositionalTabAlignmentType"; | ||
import { PositionalTabRelativeTo } from "./json/bindings/PositionalTabRelativeTo"; | ||
import { TabLeaderType } from "./json/bindings/TabLeaderType"; | ||
import { | ||
createPositionalTab, | ||
PositionalTabAlignmentType as _PositionalTabAlignmentType, | ||
PositionalTabRelativeTo as _PositionalTabRelativeTo, | ||
TabLeaderType as _TabLeaderType, | ||
} from "./pkg/docx_wasm"; | ||
import { convertTabLeader } from "./tab-leader"; | ||
|
||
export class PositionalTab { | ||
_alignment: PositionalTabAlignmentType = "left"; | ||
_relativeTo: PositionalTabRelativeTo = "margin"; | ||
_leader: TabLeaderType = "none"; | ||
|
||
alignment(t: PositionalTabAlignmentType) { | ||
this._alignment = t; | ||
return this; | ||
} | ||
|
||
relativeTo(t: PositionalTabRelativeTo) { | ||
this._relativeTo = t; | ||
return this; | ||
} | ||
|
||
leader(l: TabLeaderType) { | ||
this._leader = l; | ||
return this; | ||
} | ||
|
||
buildWasmObject() { | ||
const alignment = (() => { | ||
if (this._alignment === "left") return _PositionalTabAlignmentType.Left; | ||
if (this._alignment === "center") | ||
return _PositionalTabAlignmentType.Center; | ||
if (this._alignment === "right") return _PositionalTabAlignmentType.Right; | ||
return _PositionalTabAlignmentType.Left; | ||
})(); | ||
|
||
const relativeTo = (() => { | ||
if (this._relativeTo === "indent") return _PositionalTabRelativeTo.Indent; | ||
return _PositionalTabRelativeTo.Margin; | ||
})(); | ||
|
||
const leader = convertTabLeader(this._leader); | ||
|
||
return createPositionalTab(alignment, relativeTo, leader); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as wasm from "./pkg"; | ||
import { TabLeaderType } from "./json/bindings/TabLeaderType"; | ||
|
||
export const convertTabLeader = (leader: TabLeaderType) => { | ||
switch (leader) { | ||
case "dot": | ||
return wasm.TabLeaderType.Dot; | ||
break; | ||
case "heavy": | ||
return wasm.TabLeaderType.Heavy; | ||
case "hyphen": | ||
return wasm.TabLeaderType.Hyphen; | ||
case "middleDot": | ||
return wasm.TabLeaderType.MiddleDot; | ||
case "none": | ||
return wasm.TabLeaderType.None; | ||
case "underscore": | ||
return wasm.TabLeaderType.Underscore; | ||
default: | ||
return wasm.TabLeaderType.None; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "docx-wasm", | ||
"version": "0.4.18-rc9", | ||
"version": "0.4.18-rc12", | ||
"main": "dist/node/index.js", | ||
"browser": "dist/web/index.js", | ||
"author": "bokuweb <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.