2018-06-08 16:03:04 +02:00
|
|
|
// http://officeopenxml.com/drwPicFloating.php
|
|
|
|
import { IMediaDataDimensions } from "file/media";
|
|
|
|
import { XmlComponent } from "file/xml-components";
|
2018-06-09 23:49:01 +01:00
|
|
|
import { IDrawingOptions } from "../drawing";
|
2018-06-08 16:03:04 +02:00
|
|
|
import {
|
|
|
|
HorizontalPosition,
|
2018-06-09 23:49:01 +01:00
|
|
|
HorizontalPositionRelativeFrom,
|
|
|
|
IFloating,
|
|
|
|
SimplePos,
|
2018-06-08 16:03:04 +02:00
|
|
|
VerticalPosition,
|
|
|
|
VerticalPositionRelativeFrom,
|
|
|
|
} from "../floating";
|
2018-06-09 23:49:01 +01:00
|
|
|
import { Graphic } from "../inline/graphic";
|
|
|
|
import { TextWrapStyle, WrapNone, WrapSquare, WrapTight, WrapTopAndBottom } from "../text-wrap";
|
|
|
|
import { DocProperties } from "./../doc-properties/doc-properties";
|
|
|
|
import { EffectExtent } from "./../effect-extent/effect-extent";
|
|
|
|
import { Extent } from "./../extent/extent";
|
|
|
|
import { GraphicFrameProperties } from "./../graphic-frame/graphic-frame-properties";
|
|
|
|
import { AnchorAttributes } from "./anchor-attributes";
|
2018-06-08 16:03:04 +02:00
|
|
|
|
2018-06-09 23:49:01 +01:00
|
|
|
const defaultOptions: IFloating = {
|
2018-06-08 16:03:04 +02:00
|
|
|
allowOverlap: true,
|
|
|
|
behindDocument: false,
|
|
|
|
lockAnchor: false,
|
|
|
|
layoutInCell: true,
|
|
|
|
verticalPosition: {
|
|
|
|
relative: VerticalPositionRelativeFrom.PARAGRAPH,
|
|
|
|
offset: 0,
|
|
|
|
},
|
|
|
|
horizontalPosition: {
|
|
|
|
relative: HorizontalPositionRelativeFrom.COLUMN,
|
|
|
|
offset: 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export class Anchor extends XmlComponent {
|
2018-06-09 23:49:01 +01:00
|
|
|
constructor(referenceId: number, dimensions: IMediaDataDimensions, drawingOptions: IDrawingOptions) {
|
2018-06-08 16:03:04 +02:00
|
|
|
super("wp:anchor");
|
|
|
|
|
|
|
|
const floating = {
|
|
|
|
...defaultOptions,
|
|
|
|
...drawingOptions.floating,
|
|
|
|
};
|
|
|
|
this.root.push(
|
|
|
|
new AnchorAttributes({
|
|
|
|
distT: 0,
|
|
|
|
distB: 0,
|
|
|
|
distL: 0,
|
|
|
|
distR: 0,
|
|
|
|
simplePos: "0", // note: word doesn't fully support - so we use 0
|
|
|
|
allowOverlap: floating.allowOverlap === true ? "1" : "0",
|
|
|
|
behindDoc: floating.behindDocument === true ? "1" : "0",
|
|
|
|
locked: floating.lockAnchor === true ? "1" : "0",
|
|
|
|
layoutInCell: floating.layoutInCell === true ? "1" : "0",
|
|
|
|
relativeHeight: dimensions.emus.y,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
this.root.push(new SimplePos());
|
|
|
|
this.root.push(new HorizontalPosition(floating.horizontalPosition));
|
|
|
|
this.root.push(new VerticalPosition(floating.verticalPosition));
|
|
|
|
this.root.push(new Extent(dimensions.emus.x, dimensions.emus.y));
|
|
|
|
this.root.push(new EffectExtent());
|
|
|
|
|
2018-08-06 03:49:27 +01:00
|
|
|
if (drawingOptions.textWrapping !== undefined) {
|
2018-06-08 16:03:04 +02:00
|
|
|
switch (drawingOptions.textWrapping.textWrapStyle) {
|
|
|
|
case TextWrapStyle.SQUARE:
|
|
|
|
this.root.push(new WrapSquare(drawingOptions.textWrapping));
|
|
|
|
break;
|
|
|
|
case TextWrapStyle.TIGHT:
|
|
|
|
this.root.push(new WrapTight(drawingOptions.textWrapping.distanceFromText));
|
|
|
|
break;
|
|
|
|
case TextWrapStyle.TOP_AND_BOTTOM:
|
|
|
|
this.root.push(new WrapTopAndBottom(drawingOptions.textWrapping.distanceFromText));
|
|
|
|
break;
|
|
|
|
case TextWrapStyle.NONE:
|
|
|
|
default:
|
|
|
|
this.root.push(new WrapNone());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.root.push(new WrapNone());
|
|
|
|
}
|
|
|
|
|
|
|
|
this.root.push(new DocProperties());
|
|
|
|
this.root.push(new GraphicFrameProperties());
|
|
|
|
this.root.push(new Graphic(referenceId, dimensions.emus.x, dimensions.emus.y));
|
|
|
|
}
|
|
|
|
}
|