#751 Add bidi visual - Visual Right to Left
This commit is contained in:
8
.nycrc
8
.nycrc
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"check-coverage": true,
|
"check-coverage": true,
|
||||||
"lines": 96.81,
|
"lines": 97.77,
|
||||||
"functions": 93.80,
|
"functions": 93.89,
|
||||||
"branches": 92.63,
|
"branches": 94.55,
|
||||||
"statements": 96.80,
|
"statements": 97.75,
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.ts"
|
"src/**/*.ts"
|
||||||
],
|
],
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// This demo shows right to left for special languages
|
// This demo shows right to left for special languages
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
import { Document, Packer, Paragraph, Table, TableCell, TableRow, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document();
|
||||||
|
|
||||||
@ -36,6 +36,31 @@ doc.addSection({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
new Table({
|
||||||
|
visuallyRightToLeft: true,
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("שלום עולם")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("שלום עולם")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
15
src/file/paragraph/formatting/bidirectional.spec.ts
Normal file
15
src/file/paragraph/formatting/bidirectional.spec.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
|
import { Bidirectional } from "./bidirectional";
|
||||||
|
|
||||||
|
describe("Bidirectional", () => {
|
||||||
|
it("should create", () => {
|
||||||
|
const bidirectional = new Bidirectional();
|
||||||
|
const tree = new Formatter().format(bidirectional);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:bidi": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -141,4 +141,20 @@ describe("TableProperties", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#Set Virtual Right to Left", () => {
|
||||||
|
it("sets the alignment of the table", () => {
|
||||||
|
const tp = new TableProperties({
|
||||||
|
visuallyRightToLeft: true,
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(tp);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:tblPr": [
|
||||||
|
{
|
||||||
|
"w:bidiVisual": {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -9,6 +9,7 @@ import { ITableCellMarginOptions, TableCellMargin } from "./table-cell-margin";
|
|||||||
import { ITableFloatOptions, TableFloatProperties } from "./table-float-properties";
|
import { ITableFloatOptions, TableFloatProperties } from "./table-float-properties";
|
||||||
import { TableLayout, TableLayoutType } from "./table-layout";
|
import { TableLayout, TableLayoutType } from "./table-layout";
|
||||||
import { PreferredTableWidth } from "./table-width";
|
import { PreferredTableWidth } from "./table-width";
|
||||||
|
import { VisuallyRightToLeft } from "./visually-right-to-left";
|
||||||
|
|
||||||
export interface ITablePropertiesOptions {
|
export interface ITablePropertiesOptions {
|
||||||
readonly width?: {
|
readonly width?: {
|
||||||
@ -21,6 +22,7 @@ export interface ITablePropertiesOptions {
|
|||||||
readonly shading?: ITableShadingAttributesProperties;
|
readonly shading?: ITableShadingAttributesProperties;
|
||||||
readonly alignment?: AlignmentType;
|
readonly alignment?: AlignmentType;
|
||||||
readonly cellMargin?: ITableCellMarginOptions;
|
readonly cellMargin?: ITableCellMarginOptions;
|
||||||
|
readonly visuallyRightToLeft?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TableProperties extends IgnoreIfEmptyXmlComponent {
|
export class TableProperties extends IgnoreIfEmptyXmlComponent {
|
||||||
@ -52,5 +54,9 @@ export class TableProperties extends IgnoreIfEmptyXmlComponent {
|
|||||||
if (options.shading) {
|
if (options.shading) {
|
||||||
this.root.push(new TableShading(options.shading));
|
this.root.push(new TableShading(options.shading));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.visuallyRightToLeft) {
|
||||||
|
this.root.push(new VisuallyRightToLeft());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { Formatter } from "export/formatter";
|
||||||
|
import { VisuallyRightToLeft } from "./visually-right-to-left";
|
||||||
|
|
||||||
|
describe("VisuallyRightToLeft", () => {
|
||||||
|
it("should create", () => {
|
||||||
|
const visuallyRightToLeft = new VisuallyRightToLeft();
|
||||||
|
const tree = new Formatter().format(visuallyRightToLeft);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:bidiVisual": {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,8 @@
|
|||||||
|
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_bidiVisual_topic_ID0EOXIQ.html
|
||||||
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
export class VisuallyRightToLeft extends XmlComponent {
|
||||||
|
constructor() {
|
||||||
|
super("w:bidiVisual");
|
||||||
|
}
|
||||||
|
}
|
@ -36,6 +36,7 @@ export interface ITableOptions {
|
|||||||
readonly layout?: TableLayoutType;
|
readonly layout?: TableLayoutType;
|
||||||
readonly borders?: ITableBordersOptions;
|
readonly borders?: ITableBordersOptions;
|
||||||
readonly alignment?: AlignmentType;
|
readonly alignment?: AlignmentType;
|
||||||
|
readonly visuallyRightToLeft?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Table extends XmlComponent {
|
export class Table extends XmlComponent {
|
||||||
@ -48,6 +49,7 @@ export class Table extends XmlComponent {
|
|||||||
layout,
|
layout,
|
||||||
borders,
|
borders,
|
||||||
alignment,
|
alignment,
|
||||||
|
visuallyRightToLeft,
|
||||||
}: ITableOptions) {
|
}: ITableOptions) {
|
||||||
super("w:tbl");
|
super("w:tbl");
|
||||||
|
|
||||||
@ -76,6 +78,7 @@ export class Table extends XmlComponent {
|
|||||||
type: marginUnitType,
|
type: marginUnitType,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
visuallyRightToLeft,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user