#269 Text Frame (Text Box)
This commit is contained in:
111
src/file/paragraph/frame/frame-properties.ts
Normal file
111
src/file/paragraph/frame/frame-properties.ts
Normal file
@ -0,0 +1,111 @@
|
||||
// http://officeopenxml.com/WPparagraph-textFrames.php
|
||||
import { HorizontalPositionAlign, VerticalPositionAlign } from "file/shared/alignment";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
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;
|
||||
};
|
||||
readonly rule?: number;
|
||||
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;
|
||||
readonly rule?: number;
|
||||
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,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user