Sending media data down image
This commit is contained in:
@ -8,7 +8,21 @@ import { Anchor } from "./anchor";
|
||||
|
||||
function createDrawing(drawingOptions: IDrawingOptions): Anchor {
|
||||
return new Anchor(
|
||||
1,
|
||||
{
|
||||
referenceId: 1,
|
||||
fileName: "test.png",
|
||||
stream: new Buffer(""),
|
||||
dimensions: {
|
||||
pixels: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
emus: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
pixels: {
|
||||
x: 100,
|
||||
|
@ -1,5 +1,5 @@
|
||||
// http://officeopenxml.com/drwPicFloating.php
|
||||
import { IMediaDataDimensions } from "file/media";
|
||||
import { IMediaData, IMediaDataDimensions } from "file/media";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { IDrawingOptions } from "../drawing";
|
||||
import {
|
||||
@ -34,7 +34,7 @@ const defaultOptions: IFloating = {
|
||||
};
|
||||
|
||||
export class Anchor extends XmlComponent {
|
||||
constructor(referenceId: number, dimensions: IMediaDataDimensions, drawingOptions: IDrawingOptions) {
|
||||
constructor(mediaData: IMediaData, dimensions: IMediaDataDimensions, drawingOptions: IDrawingOptions) {
|
||||
super("wp:anchor");
|
||||
|
||||
const floating = {
|
||||
@ -83,6 +83,6 @@ export class Anchor extends XmlComponent {
|
||||
|
||||
this.root.push(new DocProperties());
|
||||
this.root.push(new GraphicFrameProperties());
|
||||
this.root.push(new Graphic(referenceId, dimensions.emus.x, dimensions.emus.y));
|
||||
this.root.push(new Graphic(mediaData, dimensions.emus.x, dimensions.emus.y));
|
||||
}
|
||||
}
|
||||
|
@ -33,20 +33,16 @@ export class Drawing extends XmlComponent {
|
||||
constructor(imageData: IMediaData, drawingOptions?: IDrawingOptions) {
|
||||
super("w:drawing");
|
||||
|
||||
if (imageData === undefined) {
|
||||
throw new Error("imageData cannot be undefined");
|
||||
}
|
||||
|
||||
const mergedOptions = {
|
||||
...defaultDrawingOptions,
|
||||
...drawingOptions,
|
||||
};
|
||||
|
||||
if (mergedOptions.position === PlacementPosition.INLINE) {
|
||||
this.inline = new Inline(imageData.referenceId, imageData.dimensions);
|
||||
this.inline = new Inline(imageData, imageData.dimensions);
|
||||
this.root.push(this.inline);
|
||||
} else if (mergedOptions.position === PlacementPosition.FLOATING) {
|
||||
this.root.push(new Anchor(imageData.referenceId, imageData.dimensions, mergedOptions));
|
||||
this.root.push(new Anchor(imageData, imageData.dimensions, mergedOptions));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
import { IMediaData } from "file/media";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import { GraphicDataAttributes } from "./graphic-data-attribute";
|
||||
import { Pic } from "./pic";
|
||||
|
||||
export class GraphicData extends XmlComponent {
|
||||
private readonly pic: Pic;
|
||||
|
||||
constructor(referenceId: number, x: number, y: number) {
|
||||
constructor(mediaData: IMediaData, x: number, y: number) {
|
||||
super("a:graphicData");
|
||||
|
||||
this.root.push(
|
||||
@ -14,7 +16,7 @@ export class GraphicData extends XmlComponent {
|
||||
}),
|
||||
);
|
||||
|
||||
this.pic = new Pic(referenceId, x, y);
|
||||
this.pic = new Pic(mediaData, x, y);
|
||||
|
||||
this.root.push(this.pic);
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
import { IMediaData } from "file/media";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import { Blip } from "./blip";
|
||||
import { SourceRectangle } from "./source-rectangle";
|
||||
import { Stretch } from "./stretch";
|
||||
|
||||
export class BlipFill extends XmlComponent {
|
||||
constructor(referenceId: number) {
|
||||
constructor(mediaData: IMediaData) {
|
||||
super("pic:blipFill");
|
||||
this.root.push(new Blip(referenceId));
|
||||
|
||||
this.root.push(new Blip(mediaData));
|
||||
this.root.push(new SourceRectangle());
|
||||
this.root.push(new Stretch());
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { IMediaData } from "file/media";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
interface IBlipProperties {
|
||||
@ -13,11 +14,11 @@ class BlipAttributes extends XmlAttributeComponent<IBlipProperties> {
|
||||
}
|
||||
|
||||
export class Blip extends XmlComponent {
|
||||
constructor(referenceId: number) {
|
||||
constructor(mediaData: IMediaData) {
|
||||
super("a:blip");
|
||||
this.root.push(
|
||||
new BlipAttributes({
|
||||
embed: `rId${referenceId}`,
|
||||
embed: `rId{${mediaData.fileName}}`,
|
||||
cstate: "none",
|
||||
}),
|
||||
);
|
||||
|
@ -1,5 +1,7 @@
|
||||
// http://officeopenxml.com/drwPic.php
|
||||
import { IMediaData } from "file/media";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import { BlipFill } from "./blip/blip-fill";
|
||||
import { NonVisualPicProperties } from "./non-visual-pic-properties/non-visual-pic-properties";
|
||||
import { PicAttributes } from "./pic-attributes";
|
||||
@ -8,7 +10,7 @@ import { ShapeProperties } from "./shape-properties/shape-properties";
|
||||
export class Pic extends XmlComponent {
|
||||
private readonly shapeProperties: ShapeProperties;
|
||||
|
||||
constructor(referenceId: number, x: number, y: number) {
|
||||
constructor(mediaData: IMediaData, x: number, y: number) {
|
||||
super("pic:pic");
|
||||
|
||||
this.root.push(
|
||||
@ -20,7 +22,7 @@ export class Pic extends XmlComponent {
|
||||
this.shapeProperties = new ShapeProperties(x, y);
|
||||
|
||||
this.root.push(new NonVisualPicProperties());
|
||||
this.root.push(new BlipFill(referenceId));
|
||||
this.root.push(new BlipFill(mediaData));
|
||||
this.root.push(new ShapeProperties(x, y));
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
import { IMediaData } from "file/media";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
import { GraphicData } from "./graphic-data";
|
||||
|
||||
interface IGraphicProperties {
|
||||
@ -14,7 +16,7 @@ class GraphicAttributes extends XmlAttributeComponent<IGraphicProperties> {
|
||||
export class Graphic extends XmlComponent {
|
||||
private readonly data: GraphicData;
|
||||
|
||||
constructor(referenceId: number, x: number, y: number) {
|
||||
constructor(mediaData: IMediaData, x: number, y: number) {
|
||||
super("a:graphic");
|
||||
this.root.push(
|
||||
new GraphicAttributes({
|
||||
@ -22,7 +24,7 @@ export class Graphic extends XmlComponent {
|
||||
}),
|
||||
);
|
||||
|
||||
this.data = new GraphicData(referenceId, x, y);
|
||||
this.data = new GraphicData(mediaData, x, y);
|
||||
|
||||
this.root.push(this.data);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// http://officeopenxml.com/drwPicInline.php
|
||||
import { IMediaDataDimensions } from "file/media";
|
||||
import { IMediaData, IMediaDataDimensions } from "file/media";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { DocProperties } from "./../doc-properties/doc-properties";
|
||||
import { EffectExtent } from "./../effect-extent/effect-extent";
|
||||
@ -12,7 +12,7 @@ export class Inline extends XmlComponent {
|
||||
private readonly extent: Extent;
|
||||
private readonly graphic: Graphic;
|
||||
|
||||
constructor(referenceId: number, private readonly dimensions: IMediaDataDimensions) {
|
||||
constructor(readonly mediaData: IMediaData, private readonly dimensions: IMediaDataDimensions) {
|
||||
super("wp:inline");
|
||||
|
||||
this.root.push(
|
||||
@ -25,7 +25,7 @@ export class Inline extends XmlComponent {
|
||||
);
|
||||
|
||||
this.extent = new Extent(dimensions.emus.x, dimensions.emus.y);
|
||||
this.graphic = new Graphic(referenceId, dimensions.emus.x, dimensions.emus.y);
|
||||
this.graphic = new Graphic(mediaData, dimensions.emus.x, dimensions.emus.y);
|
||||
|
||||
this.root.push(this.extent);
|
||||
this.root.push(new EffectExtent());
|
||||
|
Reference in New Issue
Block a user