2021-03-14 17:00:42 +00:00
|
|
|
// http://officeopenxml.com/WPparagraph-textFrames.php
|
|
|
|
import { HorizontalPositionAlign, VerticalPositionAlign } from "file/shared/alignment";
|
|
|
|
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
2021-09-18 18:07:59 +01:00
|
|
|
import { HeightRule } from "/file";
|
2021-03-14 17:00:42 +00:00
|
|
|
|
|
|
|
export enum DropCapType {
|
|
|
|
NONE = "none",
|
|
|
|
DROP = "drop",
|
|
|
|
MARGIN = "margin",
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum FrameAnchorType {
|
|
|
|
MARGIN = "margin",
|
|
|
|
PAGE = "page",
|
|
|
|
TEXT = "text",
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum FrameWrap {
|
|
|
|
AROUND = "around",
|
|
|
|
AUTO = "auto",
|
|
|
|
NONE = "none",
|
|
|
|
NOT_BESIDE = "notBeside",
|
|
|
|
THROUGH = "through",
|
|
|
|
TIGHT = "tight",
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IFrameOptions {
|
|
|
|
readonly anchorLock?: boolean;
|
|
|
|
readonly dropCap?: DropCapType;
|
|
|
|
readonly width: number;
|
|
|
|
readonly height: number;
|
|
|
|
readonly position: {
|
|
|
|
readonly x: number;
|
|
|
|
readonly y: number;
|
|
|
|
};
|
|
|
|
readonly wrap?: FrameWrap;
|
|
|
|
readonly lines?: number;
|
|
|
|
readonly anchor: {
|
|
|
|
readonly horizontal: FrameAnchorType;
|
|
|
|
readonly vertical: FrameAnchorType;
|
|
|
|
};
|
|
|
|
readonly space?: {
|
|
|
|
readonly horizontal: number;
|
|
|
|
readonly vertical: number;
|
|
|
|
};
|
2021-09-18 18:07:59 +01:00
|
|
|
readonly rule?: HeightRule;
|
2021-03-14 17:00:42 +00:00
|
|
|
readonly alignment: {
|
|
|
|
readonly x: HorizontalPositionAlign;
|
|
|
|
readonly y: VerticalPositionAlign;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export class FramePropertiesAttributes extends XmlAttributeComponent<{
|
|
|
|
readonly anchorLock?: boolean;
|
|
|
|
readonly dropCap?: DropCapType;
|
|
|
|
readonly width: number;
|
|
|
|
readonly height: number;
|
|
|
|
readonly x: number;
|
|
|
|
readonly y: number;
|
|
|
|
readonly wrap?: FrameWrap;
|
|
|
|
readonly lines?: number;
|
|
|
|
readonly anchorHorizontal?: FrameAnchorType;
|
|
|
|
readonly anchorVertical?: FrameAnchorType;
|
|
|
|
readonly spaceHorizontal?: number;
|
|
|
|
readonly spaceVertical?: number;
|
2021-09-18 18:07:59 +01:00
|
|
|
readonly rule?: HeightRule;
|
2021-03-14 17:00:42 +00:00
|
|
|
readonly alignmentX?: HorizontalPositionAlign;
|
|
|
|
readonly alignmentY?: VerticalPositionAlign;
|
|
|
|
}> {
|
|
|
|
protected readonly xmlKeys = {
|
|
|
|
anchorLock: "w:anchorLock",
|
|
|
|
dropCap: "w:dropCap",
|
|
|
|
width: "w:w",
|
|
|
|
height: "w:h",
|
|
|
|
x: "w:x",
|
|
|
|
y: "w:y",
|
|
|
|
anchorHorizontal: "w:hAnchor",
|
|
|
|
anchorVertical: "w:vAnchor",
|
|
|
|
spaceHorizontal: "w:hSpace",
|
|
|
|
spaceVertical: "w:vSpace",
|
|
|
|
rule: "w:hRule",
|
|
|
|
alignmentX: "w:xAlign",
|
|
|
|
alignmentY: "w:yAlign",
|
|
|
|
lines: "w:lines",
|
|
|
|
wrap: "w:wrap",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export class FrameProperties extends XmlComponent {
|
|
|
|
constructor(options: IFrameOptions) {
|
|
|
|
super("w:framePr");
|
|
|
|
this.root.push(
|
|
|
|
new FramePropertiesAttributes({
|
|
|
|
anchorLock: options.anchorLock,
|
|
|
|
dropCap: options.dropCap,
|
|
|
|
width: options.width,
|
|
|
|
height: options.height,
|
|
|
|
x: options.position.x,
|
|
|
|
y: options.position.y,
|
|
|
|
anchorHorizontal: options.anchor.horizontal,
|
|
|
|
anchorVertical: options.anchor.vertical,
|
|
|
|
spaceHorizontal: options.space?.horizontal,
|
|
|
|
spaceVertical: options.space?.vertical,
|
|
|
|
rule: options.rule,
|
|
|
|
alignmentX: options.alignment.x,
|
|
|
|
alignmentY: options.alignment.y,
|
|
|
|
lines: options.lines,
|
|
|
|
wrap: options.wrap,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|