Merge pull request #117 from dolanmiu/feat/refactor-bidi

Feat/refactor bidi
This commit is contained in:
Dolan
2018-08-09 23:05:58 +01:00
committed by GitHub
9 changed files with 38 additions and 27 deletions

View File

@ -4,18 +4,18 @@ var doc = new docx.Document();
var paragraph1 = new docx.Paragraph().bidi(); var paragraph1 = new docx.Paragraph().bidirectional();
var textRun1 = new docx.TextRun("שלום עולם").rtl(); var textRun1 = new docx.TextRun("שלום עולם").rightToLeft();
paragraph1.addRun(textRun1); paragraph1.addRun(textRun1);
doc.addParagraph(paragraph1); doc.addParagraph(paragraph1);
var paragraph2 = new docx.Paragraph().bidi(); var paragraph2 = new docx.Paragraph().bidirectional();
var textRun2 = new docx.TextRun("שלום עולם").bold().rtl(); var textRun2 = new docx.TextRun("שלום עולם").bold().rightToLeft();
paragraph2.addRun(textRun2); paragraph2.addRun(textRun2);
doc.addParagraph(paragraph2); doc.addParagraph(paragraph2);
var paragraph3 = new docx.Paragraph().bidi(); var paragraph3 = new docx.Paragraph().bidirectional();
var textRun3 = new docx.TextRun("שלום עולם").italic().rtl(); var textRun3 = new docx.TextRun("שלום עולם").italic().rightToLeft();
paragraph3.addRun(textRun3); paragraph3.addRun(textRun3);
doc.addParagraph(paragraph3); doc.addParagraph(paragraph3);

View File

@ -1,6 +1,6 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
export class Bidi extends XmlComponent { export class Bidirectional extends XmlComponent {
constructor() { constructor() {
super("w:bidi"); super("w:bidi");
} }

View File

@ -339,9 +339,9 @@ describe("Paragraph", () => {
}); });
}); });
describe("#bidi", () => { describe("#bidirectional", () => {
it("set paragraph right to left layout", () => { it("set paragraph right to left layout", () => {
paragraph.bidi(); paragraph.bidirectional();
const tree = new Formatter().format(paragraph); const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:p": [{ "w:pPr": [{ "w:bidi": [] }] }], "w:p": [{ "w:pPr": [{ "w:bidi": [] }] }],

View File

@ -5,7 +5,7 @@ import { Num } from "file/numbering/num";
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
import { Alignment } from "./formatting/alignment"; import { Alignment } from "./formatting/alignment";
import { Bidi } from "./formatting/bidi"; import { Bidirectional } from "./formatting/bidirectional";
import { ThematicBreak } from "./formatting/border"; import { ThematicBreak } from "./formatting/border";
import { Indent } from "./formatting/indent"; import { Indent } from "./formatting/indent";
import { KeepLines, KeepNext } from "./formatting/keep"; import { KeepLines, KeepNext } from "./formatting/keep";
@ -217,8 +217,8 @@ export class Paragraph extends XmlComponent {
return this; return this;
} }
public bidi(): Paragraph { public bidirectional(): Paragraph {
this.properties.push(new Bidi()); this.properties.push(new Bidirectional());
return this; return this;
} }
} }

View File

@ -14,7 +14,7 @@ export class Bold extends XmlComponent {
} }
} }
export class BoldCs extends XmlComponent { export class BoldComplexScript extends XmlComponent {
constructor() { constructor() {
super("w:bCs"); super("w:bCs");
this.root.push( this.root.push(
@ -36,7 +36,7 @@ export class Italics extends XmlComponent {
} }
} }
export class ItalicsCs extends XmlComponent { export class ItalicsComplexScript extends XmlComponent {
constructor() { constructor() {
super("w:iCs"); super("w:iCs");
this.root.push( this.root.push(
@ -146,7 +146,7 @@ export class Size extends XmlComponent {
} }
} }
export class SizeCs extends XmlComponent { export class SizeComplexScript extends XmlComponent {
constructor(size: number) { constructor(size: number) {
super("w:szCs"); super("w:szCs");
this.root.push( this.root.push(
@ -157,7 +157,7 @@ export class SizeCs extends XmlComponent {
} }
} }
export class RTL extends XmlComponent { export class RightToLeft extends XmlComponent {
constructor() { constructor() {
super("w:rtl"); super("w:rtl");
this.root.push( this.root.push(

View File

@ -147,7 +147,7 @@ describe("Run", () => {
describe("#rtl", () => { describe("#rtl", () => {
it("should set the run to the RTL mode", () => { it("should set the run to the RTL mode", () => {
run.rtl(); run.rightToLeft();
const tree = new Formatter().format(run); const tree = new Formatter().format(run);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:rtl": [{ _attr: { "w:val": true } }] }] }], "w:r": [{ "w:rPr": [{ "w:rtl": [{ _attr: { "w:val": true } }] }] }],

View File

@ -1,7 +1,18 @@
// http://officeopenxml.com/WPtext.php // http://officeopenxml.com/WPtext.php
import { Break } from "./break"; import { Break } from "./break";
import { Caps, SmallCaps } from "./caps"; import { Caps, SmallCaps } from "./caps";
import { Bold, BoldCs, Color, DoubleStrike, Italics, ItalicsCs, RTL, Size, SizeCs, Strike } from "./formatting"; import {
Bold,
BoldComplexScript,
Color,
DoubleStrike,
Italics,
ItalicsComplexScript,
RightToLeft,
Size,
SizeComplexScript,
Strike,
} from "./formatting";
import { Begin, End, Page, Separate } from "./page-number"; import { Begin, End, Page, Separate } from "./page-number";
import { RunProperties } from "./properties"; import { RunProperties } from "./properties";
import { RunFonts } from "./run-fonts"; import { RunFonts } from "./run-fonts";
@ -23,13 +34,13 @@ export class Run extends XmlComponent {
public bold(): Run { public bold(): Run {
this.properties.push(new Bold()); this.properties.push(new Bold());
this.properties.push(new BoldCs()); this.properties.push(new BoldComplexScript());
return this; return this;
} }
public italic(): Run { public italic(): Run {
this.properties.push(new Italics()); this.properties.push(new Italics());
this.properties.push(new ItalicsCs()); this.properties.push(new ItalicsComplexScript());
return this; return this;
} }
@ -45,12 +56,12 @@ export class Run extends XmlComponent {
public size(size: number): Run { public size(size: number): Run {
this.properties.push(new Size(size)); this.properties.push(new Size(size));
this.properties.push(new SizeCs(size)); this.properties.push(new SizeComplexScript(size));
return this; return this;
} }
public rtl(): Run { public rightToLeft(): Run {
this.properties.push(new RTL()); this.properties.push(new RightToLeft());
return this; return this;
} }

View File

@ -1,5 +1,5 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
import { Size, SizeCs } from "../../paragraph/run/formatting"; import { Size, SizeComplexScript } from "../../paragraph/run/formatting";
import { RunProperties } from "../../paragraph/run/properties"; import { RunProperties } from "../../paragraph/run/properties";
import { RunFonts } from "../../paragraph/run/run-fonts"; import { RunFonts } from "../../paragraph/run/run-fonts";
@ -14,7 +14,7 @@ export class RunPropertiesDefaults extends XmlComponent {
public size(size: number): RunPropertiesDefaults { public size(size: number): RunPropertiesDefaults {
this.properties.push(new Size(size)); this.properties.push(new Size(size));
this.properties.push(new SizeCs(size)); this.properties.push(new SizeComplexScript(size));
return this; return this;
} }

View File

@ -74,7 +74,7 @@ export class ParagraphStyle extends Style {
public size(twips: number): ParagraphStyle { public size(twips: number): ParagraphStyle {
this.addRunProperty(new formatting.Size(twips)); this.addRunProperty(new formatting.Size(twips));
this.addRunProperty(new formatting.SizeCs(twips)); this.addRunProperty(new formatting.SizeComplexScript(twips));
return this; return this;
} }
@ -283,7 +283,7 @@ export class CharacterStyle extends Style {
public size(twips: number): CharacterStyle { public size(twips: number): CharacterStyle {
this.addRunProperty(new formatting.Size(twips)); this.addRunProperty(new formatting.Size(twips));
this.addRunProperty(new formatting.SizeCs(twips)); this.addRunProperty(new formatting.SizeComplexScript(twips));
return this; return this;
} }
} }