2022-12-29 09:57:15 +00:00
|
|
|
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
|
|
|
import { PositiveUniversalMeasure, 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>
|
2022-12-29 09:57:15 +00:00
|
|
|
export type IPageSizeAttributes = {
|
|
|
|
readonly width?: number | PositiveUniversalMeasure;
|
|
|
|
readonly height?: number | PositiveUniversalMeasure;
|
2021-05-25 03:41:12 +03:00
|
|
|
readonly orientation?: PageOrientation;
|
2022-12-29 09:57:15 +00:00
|
|
|
};
|
2021-05-25 03:41:12 +03:00
|
|
|
|
|
|
|
export class PageSize extends XmlComponent {
|
2022-12-29 09:57:15 +00:00
|
|
|
public constructor(width: number | PositiveUniversalMeasure, height: number | PositiveUniversalMeasure, 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(
|
2022-12-29 09:57:15 +00:00
|
|
|
new NextAttributeComponent<IPageSizeAttributes>({
|
|
|
|
width: { key: "w:w", value: flip ? heightTwips : widthTwips },
|
|
|
|
height: { key: "w:h", value: flip ? widthTwips : heightTwips },
|
|
|
|
orientation: { key: "w:orient", value: orientation },
|
2021-05-25 03:41:12 +03:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|