2022-06-26 23:26:42 +01:00
|
|
|
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
|
|
|
import { twipsMeasureValue } from "@util/values";
|
2021-05-25 03:41:12 +03:00
|
|
|
|
|
|
|
// <xsd:simpleType name="ST_PageOrientation">
|
|
|
|
// <xsd:restriction base="xsd:string">
|
|
|
|
// <xsd:enumeration value="portrait"/>
|
|
|
|
// <xsd:enumeration value="landscape"/>
|
|
|
|
// </xsd:restriction>
|
|
|
|
// </xsd:simpleType>
|
|
|
|
export enum PageOrientation {
|
|
|
|
PORTRAIT = "portrait",
|
|
|
|
LANDSCAPE = "landscape",
|
|
|
|
}
|
|
|
|
|
|
|
|
// <xsd:complexType name="CT_PageSz">
|
|
|
|
// <xsd:attribute name="w" type="s:ST_TwipsMeasure"/>
|
|
|
|
// <xsd:attribute name="h" type="s:ST_TwipsMeasure"/>
|
|
|
|
// <xsd:attribute name="orient" type="ST_PageOrientation" use="optional"/>
|
|
|
|
// <xsd:attribute name="code" type="ST_DecimalNumber" use="optional"/>
|
|
|
|
// </xsd:complexType>
|
|
|
|
export interface IPageSizeAttributes {
|
|
|
|
readonly width?: number | string;
|
|
|
|
readonly height?: number | string;
|
|
|
|
readonly orientation?: PageOrientation;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class PageSizeAttributes extends XmlAttributeComponent<IPageSizeAttributes> {
|
|
|
|
protected readonly xmlKeys = {
|
|
|
|
width: "w:w",
|
|
|
|
height: "w:h",
|
|
|
|
orientation: "w:orient",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export class PageSize extends XmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor(width: number | string, height: number | string, orientation: PageOrientation) {
|
2021-05-25 03:41:12 +03:00
|
|
|
super("w:pgSz");
|
|
|
|
|
|
|
|
const flip = orientation === PageOrientation.LANDSCAPE;
|
|
|
|
|
|
|
|
const widthTwips = twipsMeasureValue(width);
|
|
|
|
const heightTwips = twipsMeasureValue(height);
|
|
|
|
|
|
|
|
this.root.push(
|
|
|
|
new PageSizeAttributes({
|
|
|
|
width: flip ? heightTwips : widthTwips,
|
|
|
|
height: flip ? widthTwips : heightTwips,
|
|
|
|
orientation: orientation,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|