Merge pull request #237 from dolanmiu/feat/image-wrap
Merge 4.6.0 into master
This commit is contained in:
@ -3,7 +3,7 @@ import { assert } from "chai";
|
||||
import { Utility } from "tests/utility";
|
||||
|
||||
import { IDrawingOptions } from "../drawing";
|
||||
import { TextWrapStyle } from "../text-wrap";
|
||||
import { TextWrappingType } from "../text-wrap";
|
||||
import { Anchor } from "./anchor";
|
||||
|
||||
function createAnchor(drawingOptions: IDrawingOptions): Anchor {
|
||||
@ -136,9 +136,6 @@ describe("Anchor", () => {
|
||||
|
||||
it("should create a Drawing with square text wrapping", () => {
|
||||
anchor = createAnchor({
|
||||
textWrapping: {
|
||||
textWrapStyle: TextWrapStyle.SQUARE,
|
||||
},
|
||||
floating: {
|
||||
verticalPosition: {
|
||||
offset: 0,
|
||||
@ -146,6 +143,9 @@ describe("Anchor", () => {
|
||||
horizontalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
wrap: {
|
||||
type: TextWrappingType.SQUARE,
|
||||
},
|
||||
},
|
||||
});
|
||||
const newJson = Utility.jsonify(anchor);
|
||||
@ -158,9 +158,6 @@ describe("Anchor", () => {
|
||||
|
||||
it("should create a Drawing with no text wrapping", () => {
|
||||
anchor = createAnchor({
|
||||
textWrapping: {
|
||||
textWrapStyle: TextWrapStyle.NONE,
|
||||
},
|
||||
floating: {
|
||||
verticalPosition: {
|
||||
offset: 0,
|
||||
@ -168,6 +165,9 @@ describe("Anchor", () => {
|
||||
horizontalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
wrap: {
|
||||
type: TextWrappingType.NONE,
|
||||
},
|
||||
},
|
||||
});
|
||||
const newJson = Utility.jsonify(anchor);
|
||||
@ -179,9 +179,6 @@ describe("Anchor", () => {
|
||||
|
||||
it("should create a Drawing with tight text wrapping", () => {
|
||||
anchor = createAnchor({
|
||||
textWrapping: {
|
||||
textWrapStyle: TextWrapStyle.TIGHT,
|
||||
},
|
||||
floating: {
|
||||
horizontalPosition: {
|
||||
offset: 0,
|
||||
@ -189,6 +186,9 @@ describe("Anchor", () => {
|
||||
verticalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
wrap: {
|
||||
type: TextWrappingType.TIGHT,
|
||||
},
|
||||
},
|
||||
});
|
||||
const newJson = Utility.jsonify(anchor);
|
||||
@ -200,9 +200,6 @@ describe("Anchor", () => {
|
||||
|
||||
it("should create a Drawing with tight text wrapping", () => {
|
||||
anchor = createAnchor({
|
||||
textWrapping: {
|
||||
textWrapStyle: TextWrapStyle.TOP_AND_BOTTOM,
|
||||
},
|
||||
floating: {
|
||||
verticalPosition: {
|
||||
offset: 0,
|
||||
@ -210,6 +207,9 @@ describe("Anchor", () => {
|
||||
horizontalPosition: {
|
||||
offset: 0,
|
||||
},
|
||||
wrap: {
|
||||
type: TextWrappingType.TOP_AND_BOTTOM,
|
||||
},
|
||||
},
|
||||
});
|
||||
const newJson = Utility.jsonify(anchor);
|
||||
|
@ -4,7 +4,7 @@ import { XmlComponent } from "file/xml-components";
|
||||
import { IDrawingOptions } from "../drawing";
|
||||
import { HorizontalPosition, IFloating, SimplePos, VerticalPosition } from "../floating";
|
||||
import { Graphic } from "../inline/graphic";
|
||||
import { TextWrapStyle, WrapNone, WrapSquare, WrapTight, WrapTopAndBottom } from "../text-wrap";
|
||||
import { TextWrappingType, 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";
|
||||
@ -25,15 +25,22 @@ export class Anchor extends XmlComponent {
|
||||
super("wp:anchor");
|
||||
|
||||
const floating = {
|
||||
margins: {
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
},
|
||||
...defaultOptions,
|
||||
...drawingOptions.floating,
|
||||
};
|
||||
|
||||
this.root.push(
|
||||
new AnchorAttributes({
|
||||
distT: 0,
|
||||
distB: 0,
|
||||
distL: 0,
|
||||
distR: 0,
|
||||
distT: floating.margins.top || 0,
|
||||
distB: floating.margins.bottom || 0,
|
||||
distL: floating.margins.left || 0,
|
||||
distR: floating.margins.right || 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",
|
||||
@ -49,18 +56,18 @@ export class Anchor extends XmlComponent {
|
||||
this.root.push(new Extent(dimensions.emus.x, dimensions.emus.y));
|
||||
this.root.push(new EffectExtent());
|
||||
|
||||
if (drawingOptions.textWrapping !== undefined) {
|
||||
switch (drawingOptions.textWrapping.textWrapStyle) {
|
||||
case TextWrapStyle.SQUARE:
|
||||
this.root.push(new WrapSquare(drawingOptions.textWrapping));
|
||||
if (drawingOptions.floating !== undefined && drawingOptions.floating.wrap !== undefined) {
|
||||
switch (drawingOptions.floating.wrap.type) {
|
||||
case TextWrappingType.SQUARE:
|
||||
this.root.push(new WrapSquare(drawingOptions.floating.wrap, drawingOptions.floating.margins));
|
||||
break;
|
||||
case TextWrapStyle.TIGHT:
|
||||
this.root.push(new WrapTight(drawingOptions.textWrapping.distanceFromText));
|
||||
case TextWrappingType.TIGHT:
|
||||
this.root.push(new WrapTight(drawingOptions.floating.margins));
|
||||
break;
|
||||
case TextWrapStyle.TOP_AND_BOTTOM:
|
||||
this.root.push(new WrapTopAndBottom(drawingOptions.textWrapping.distanceFromText));
|
||||
case TextWrappingType.TOP_AND_BOTTOM:
|
||||
this.root.push(new WrapTopAndBottom(drawingOptions.floating.margins));
|
||||
break;
|
||||
case TextWrapStyle.NONE:
|
||||
case TextWrappingType.NONE:
|
||||
default:
|
||||
this.root.push(new WrapNone());
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import { XmlComponent } from "file/xml-components";
|
||||
import { Anchor } from "./anchor";
|
||||
import { IFloating } from "./floating";
|
||||
import { Inline } from "./inline";
|
||||
import { ITextWrapping } from "./text-wrap";
|
||||
|
||||
export interface IDistance {
|
||||
readonly distT?: number;
|
||||
@ -13,7 +12,6 @@ export interface IDistance {
|
||||
}
|
||||
|
||||
export interface IDrawingOptions {
|
||||
readonly textWrapping?: ITextWrapping;
|
||||
readonly floating?: IFloating;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// http://officeopenxml.com/drwPicFloating-position.php
|
||||
import { ITextWrapping } from "../text-wrap";
|
||||
|
||||
export enum HorizontalPositionRelativeFrom {
|
||||
CHARACTER = "character",
|
||||
@ -50,6 +51,13 @@ export interface IVerticalPositionOptions {
|
||||
readonly offset?: number;
|
||||
}
|
||||
|
||||
export interface IMargins {
|
||||
readonly left?: number;
|
||||
readonly bottom?: number;
|
||||
readonly top?: number;
|
||||
readonly right?: number;
|
||||
}
|
||||
|
||||
export interface IFloating {
|
||||
readonly horizontalPosition: IHorizontalPositionOptions;
|
||||
readonly verticalPosition: IVerticalPositionOptions;
|
||||
@ -57,4 +65,6 @@ export interface IFloating {
|
||||
readonly lockAnchor?: boolean;
|
||||
readonly behindDocument?: boolean;
|
||||
readonly layoutInCell?: boolean;
|
||||
readonly margins?: IMargins;
|
||||
readonly wrap?: ITextWrapping;
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
import { IDistance } from "../drawing";
|
||||
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
export interface IInlineAttributes extends IDistance {}
|
||||
// distT, distB etc have no effect on inline images, only floating
|
||||
export interface IInlineAttributes extends IDistance {
|
||||
readonly distT?: number;
|
||||
readonly distB?: number;
|
||||
readonly distL?: number;
|
||||
readonly distR?: number;
|
||||
}
|
||||
|
||||
export class InlineAttributes extends XmlAttributeComponent<IInlineAttributes> {
|
||||
protected readonly xmlKeys = {
|
||||
|
@ -1,14 +1,14 @@
|
||||
// http://officeopenxml.com/drwPicFloating-textWrap.php
|
||||
import { IDistance } from "../drawing";
|
||||
|
||||
export enum TextWrapStyle {
|
||||
export enum TextWrappingType {
|
||||
NONE,
|
||||
SQUARE,
|
||||
TIGHT,
|
||||
TOP_AND_BOTTOM,
|
||||
}
|
||||
|
||||
export enum WrapTextOption {
|
||||
export enum TextWrappingSide {
|
||||
BOTH_SIDES = "bothSides",
|
||||
LEFT = "left",
|
||||
RIGHT = "right",
|
||||
@ -16,7 +16,7 @@ export enum WrapTextOption {
|
||||
}
|
||||
|
||||
export interface ITextWrapping {
|
||||
readonly textWrapStyle: TextWrapStyle;
|
||||
readonly wrapTextOption?: WrapTextOption;
|
||||
readonly distanceFromText?: IDistance;
|
||||
readonly type: TextWrappingType;
|
||||
readonly side?: TextWrappingSide;
|
||||
readonly margins?: IDistance;
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
// http://officeopenxml.com/drwPicFloating-textWrap.php
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { ITextWrapping, WrapTextOption } from ".";
|
||||
import { ITextWrapping, TextWrappingSide } from ".";
|
||||
import { IDistance } from "../drawing";
|
||||
import { IMargins } from "../floating";
|
||||
|
||||
interface IWrapSquareAttributes extends IDistance {
|
||||
readonly wrapText?: WrapTextOption;
|
||||
readonly wrapText?: TextWrappingSide;
|
||||
readonly distT?: number;
|
||||
readonly distB?: number;
|
||||
readonly distL?: number;
|
||||
readonly distR?: number;
|
||||
}
|
||||
|
||||
class WrapSquareAttributes extends XmlAttributeComponent<IWrapSquareAttributes> {
|
||||
@ -18,13 +23,24 @@ class WrapSquareAttributes extends XmlAttributeComponent<IWrapSquareAttributes>
|
||||
}
|
||||
|
||||
export class WrapSquare extends XmlComponent {
|
||||
constructor(textWrapping: ITextWrapping) {
|
||||
constructor(
|
||||
textWrapping: ITextWrapping,
|
||||
margins: IMargins = {
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
},
|
||||
) {
|
||||
super("wp:wrapSquare");
|
||||
|
||||
this.root.push(
|
||||
new WrapSquareAttributes({
|
||||
wrapText: textWrapping.wrapTextOption || WrapTextOption.BOTH_SIDES,
|
||||
...textWrapping.distanceFromText,
|
||||
wrapText: textWrapping.side || TextWrappingSide.BOTH_SIDES,
|
||||
distT: margins.top,
|
||||
distB: margins.bottom,
|
||||
distL: margins.left,
|
||||
distR: margins.right,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// http://officeopenxml.com/drwPicFloating-textWrap.php
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { IDistance } from "../drawing";
|
||||
|
||||
import { IMargins } from "../floating";
|
||||
|
||||
interface IWrapTightAttributes {
|
||||
readonly distT?: number;
|
||||
@ -16,17 +17,17 @@ class WrapTightAttributes extends XmlAttributeComponent<IWrapTightAttributes> {
|
||||
|
||||
export class WrapTight extends XmlComponent {
|
||||
constructor(
|
||||
distanceFromText: IDistance = {
|
||||
distT: 0,
|
||||
distB: 0,
|
||||
margins: IMargins = {
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
},
|
||||
) {
|
||||
super("wp:wrapTight");
|
||||
|
||||
this.root.push(
|
||||
new WrapTightAttributes({
|
||||
distT: distanceFromText.distT,
|
||||
distB: distanceFromText.distB,
|
||||
distT: margins.top,
|
||||
distB: margins.bottom,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// http://officeopenxml.com/drwPicFloating-textWrap.php
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { IDistance } from "../drawing";
|
||||
|
||||
import { IMargins } from "../floating";
|
||||
|
||||
interface IWrapTopAndBottomAttributes {
|
||||
readonly distT?: number;
|
||||
@ -16,17 +17,17 @@ class WrapTopAndBottomAttributes extends XmlAttributeComponent<IWrapTopAndBottom
|
||||
|
||||
export class WrapTopAndBottom extends XmlComponent {
|
||||
constructor(
|
||||
distanceFromText: IDistance = {
|
||||
distT: 0,
|
||||
distB: 0,
|
||||
margins: IMargins = {
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
},
|
||||
) {
|
||||
super("wp:wrapTopAndBottom");
|
||||
|
||||
this.root.push(
|
||||
new WrapTopAndBottomAttributes({
|
||||
distT: distanceFromText.distT,
|
||||
distB: distanceFromText.distB,
|
||||
distT: margins.top,
|
||||
distB: margins.bottom,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user