Merge pull request #1303 from katz/katz/page-text-direction
ability to specify textDirection for SectionProperties
This commit is contained in:
@ -7,6 +7,7 @@ export * from "./page-number";
|
||||
export * from "./page-borders";
|
||||
export * from "./page-margin";
|
||||
export * from "./page-borders";
|
||||
export * from "./page-text-direction";
|
||||
export * from "./line-number";
|
||||
export * from "./section-type";
|
||||
export * from "./header-footer-reference";
|
||||
|
@ -0,0 +1,22 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
import { PageTDirection, PageTextDirection } from "./page-text-direction";
|
||||
|
||||
describe("PageTextDirection", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should set the direction of the text flow to top-to-bottom-right-to-left", () => {
|
||||
const textDirection = new PageTDirection(PageTextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT);
|
||||
|
||||
const tree = new Formatter().format(textDirection);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:textDirection": {
|
||||
_attr: {
|
||||
"w:val": "tbRl",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,22 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export enum PageTextDirection {
|
||||
LEFT_TO_RIGHT_TOP_TO_BOTTOM = "lrTb",
|
||||
TOP_TO_BOTTOM_RIGHT_TO_LEFT = "tbRl",
|
||||
}
|
||||
|
||||
class PageTextDirectionAttributes extends XmlAttributeComponent<{ readonly val: PageTextDirection }> {
|
||||
protected readonly xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
export class PageTDirection extends XmlComponent {
|
||||
constructor(value: PageTextDirection) {
|
||||
super("w:textDirection");
|
||||
|
||||
this.root.push(
|
||||
new PageTextDirectionAttributes({
|
||||
val: value,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import { VerticalAlign } from "file/vertical-align";
|
||||
import { PageOrientation } from "./properties";
|
||||
import { LineNumberRestartFormat } from "./properties/line-number";
|
||||
import { PageBorderOffsetFrom } from "./properties/page-borders";
|
||||
import { PageTextDirection } from "./properties/page-text-direction";
|
||||
import { SectionType } from "./properties/section-type";
|
||||
import { sectionMarginDefaults, sectionPageSizeDefaults, SectionProperties } from "./section-properties";
|
||||
|
||||
@ -258,5 +259,19 @@ describe("SectionProperties", () => {
|
||||
"w:lnNumType": { _attr: { "w:countBy": 2, "w:distance": 4, "w:restart": "continuous", "w:start": 2 } },
|
||||
});
|
||||
});
|
||||
|
||||
it("should create section properties with text flow direction", () => {
|
||||
const properties = new SectionProperties({
|
||||
page: {
|
||||
textDirection: PageTextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(properties);
|
||||
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
|
||||
const type = tree["w:sectPr"].find((item) => item["w:textDirection"] !== undefined);
|
||||
expect(type).to.deep.equal({
|
||||
"w:textDirection": { _attr: { "w:val": "tbRl" } },
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -15,6 +15,7 @@ import { IPageBordersOptions, PageBorders } from "./properties/page-borders";
|
||||
import { IPageMarginAttributes, PageMargin } from "./properties/page-margin";
|
||||
import { IPageNumberTypeAttributes, PageNumberType } from "./properties/page-number";
|
||||
import { IPageSizeAttributes, PageOrientation, PageSize } from "./properties/page-size";
|
||||
import { PageTDirection, PageTextDirection } from "./properties/page-text-direction";
|
||||
import { SectionType, Type } from "./properties/section-type";
|
||||
|
||||
export interface IHeaderFooterGroup<T> {
|
||||
@ -29,6 +30,7 @@ export interface ISectionPropertiesOptions {
|
||||
readonly margin?: IPageMarginAttributes;
|
||||
readonly pageNumbers?: IPageNumberTypeAttributes;
|
||||
readonly borders?: IPageBordersOptions;
|
||||
readonly textDirection?: PageTextDirection;
|
||||
};
|
||||
readonly grid?: IDocGridAttributesProperties;
|
||||
readonly headerWrapperGroup?: IHeaderFooterGroup<HeaderWrapper>;
|
||||
@ -108,6 +110,7 @@ export class SectionProperties extends XmlComponent {
|
||||
} = {},
|
||||
pageNumbers = {},
|
||||
borders,
|
||||
textDirection,
|
||||
} = {},
|
||||
grid: { linePitch = 360 } = {},
|
||||
headerWrapperGroup = {},
|
||||
@ -152,6 +155,10 @@ export class SectionProperties extends XmlComponent {
|
||||
this.root.push(new OnOffElement("w:titlePg", titlePage));
|
||||
}
|
||||
|
||||
if (textDirection) {
|
||||
this.root.push(new PageTDirection(textDirection));
|
||||
}
|
||||
|
||||
this.root.push(new DocumentGrid(linePitch));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user