Skip to content

Commit 399caa0

Browse files
committed
chore(test): addElement / modifyElement / duotone for images
1 parent 9bf6111 commit 399caa0

File tree

4 files changed

+24
-55
lines changed

4 files changed

+24
-55
lines changed

__tests__/add-external-image.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import Automizer from '../src/automizer';
22
import { ModifyImageHelper, ModifyShapeHelper } from '../src';
33
import { CmToDxa } from '../src/helper/modify-helper';
44

5-
test('Load external media, add image and set image target', async () => {
5+
test('Load external media, add/modify image and set image target', async () => {
66
const automizer = new Automizer({
77
templateDir: `${__dirname}/../__tests__/pptx-templates`,
88
outputDir: `${__dirname}/../__tests__/pptx-output`,
99
mediaDir: `${__dirname}/../__tests__/media`,
1010
removeExistingSlides: true,
11+
cleanup: true,
1112
});
1213

1314
const pres = automizer
@@ -17,16 +18,25 @@ test('Load external media, add image and set image target', async () => {
1718
.load(`SlideWithImages.pptx`, 'images');
1819

1920
pres.addSlide('shapes', 1, (slide) => {
20-
slide.addElement('images', 2, 'imagePNG', [
21+
slide.addElement('images', 2, 'imagePNGduotone', [
2122
ModifyShapeHelper.setPosition({
2223
w: CmToDxa(5),
23-
h: CmToDxa(5),
24+
h: CmToDxa(3),
2425
}),
26+
ModifyImageHelper.setRelationTarget('feather.png'),
27+
]);
28+
});
29+
30+
pres.addSlide('images', 1, (slide) => {
31+
slide.modifyElement('Grafik 5', [
2532
ModifyImageHelper.setRelationTarget('test.png'),
2633
]);
2734
});
2835

2936
const result = await pres.write(`add-external-image.test.pptx`);
3037

31-
// expect(result.images).toBe(5);
38+
// expect a 5x3cm light-blue duotone feather instead of imagePNG cord loop on page 1
39+
// expect imagePNG cord loop on page 2 instead of cut tree jpg
40+
41+
expect(result.images).toBe(3);
3242
});

__tests__/modify-image-duotone.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ test('Add image and set duotone fill', async () => {
1717
pres.addSlide('shapes', 1, (slide) => {
1818
slide.addElement('images', 2, 'imagePNGduotone', [
1919
ModifyImageHelper.setDuotoneFill({
20-
tint: 10000,
20+
tint: 100000,
2121
color: {
2222
type: 'srgbClr',
23-
value: 'ffffff',
23+
value: 'ff0000',
2424
},
2525
}),
2626
]);
2727
});
2828

2929
const result = await pres.write(`modify-image-duotone.test.pptx`);
3030

31-
// expect(result.images).toBe(5);
31+
// Expect cord loop to turn red by duotone overlay
32+
33+
expect(result.images).toBe(1);
3234
});

src/dev.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,7 @@ const run = async () => {
3030
},
3131
}),
3232
]);
33-
34-
slide.modifyElement('Textfeld 1', [
35-
ModifyShapeHelper.setPosition({
36-
w: CmToDxa(5),
37-
h: CmToDxa(5),
38-
}),
39-
// ModifyImageHelper.setRelationTarget('feather.png'),
40-
// ModifyImageHelper.setDuotoneFill({
41-
// tint: 100000,
42-
// color: {
43-
// type: 'srgbClr',
44-
// value: 'ff850c',
45-
// },
46-
// }),
47-
]);
4833
})
49-
// .addSlide('shapes', 1, (slide) => {
50-
// slide.addElement('images', 2, 'imagePNGduotone', [
51-
// ModifyShapeHelper.setPosition({
52-
// w: CmToDxa(5),
53-
// h: CmToDxa(5),
54-
// }),
55-
// ModifyImageHelper.setRelationTarget('feather.png'),
56-
// ModifyImageHelper.setDuotoneFill({
57-
// tint: 100000,
58-
// color: {
59-
// type: 'srgbClr',
60-
// value: 'ff850c',
61-
// },
62-
// }),
63-
// ]);
64-
// })
6534
.write(`modify-shapes.test.pptx`);
6635
};
6736

src/shapes/image.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import { FileHelper } from '../helper/file-helper';
22
import { XmlHelper } from '../helper/xml-helper';
33
import { Shape } from '../classes/shape';
4-
import {
5-
HelperElement,
6-
RelationshipAttribute,
7-
XmlElement,
8-
} from '../types/xml-types';
4+
import { RelationshipAttribute, XmlElement } from '../types/xml-types';
95
import { ImportedElement, ShapeTargetType, Target } from '../types/types';
106
import { IImage } from '../interfaces/iimage';
117
import { RootPresTemplate } from '../interfaces/root-pres-template';
128
import { ElementType } from '../enums/element-type';
139
import IArchive from '../interfaces/iarchive';
14-
import { vd } from '../helper/general-helper';
1510
import { ContentTypeExtension } from '../enums/content-type-map';
1611

1712
export class Image extends Shape implements IImage {
@@ -136,7 +131,7 @@ export class Image extends Shape implements IImage {
136131

137132
await this.copyFiles();
138133
await this.appendTypes();
139-
this.createdRelation = await this.appendToSlideRels();
134+
await this.appendToSlideRels();
140135
}
141136

142137
async copyFiles(): Promise<void> {
@@ -158,33 +153,26 @@ export class Image extends Shape implements IImage {
158153
* remain existing in the .xml.rels file. PowerPoint will not complain, but
159154
* integrity checks will not be valid by this.
160155
*/
161-
async appendToSlideRels(): Promise<XmlElement> {
156+
async appendToSlideRels(): Promise<void> {
162157
const targetRelFile = `ppt/${this.targetType}s/_rels/${this.targetType}${this.targetSlideNumber}.xml.rels`;
163158
this.createdRid = await XmlHelper.getNextRelId(
164159
this.targetArchive,
165160
targetRelFile,
166161
);
167162

168-
// this.target.element.setAttribute('Id', this.createdRid);
169-
// this.target.element.setAttribute(
170-
// 'Target',
171-
// `../media/image${this.targetNumber}.${this.extension}`,
172-
// );
173-
174163
const attributes = {
175164
Id: this.createdRid,
176165
Type: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
177166
Target: `../media/image${this.targetNumber}.${this.extension}`,
178167
} as RelationshipAttribute;
179168

180-
const newRelation = (await XmlHelper.append(
169+
this.createdRelation = await XmlHelper.append(
181170
XmlHelper.createRelationshipChild(
182171
this.targetArchive,
183172
targetRelFile,
184173
attributes,
185174
),
186-
)) as unknown as XmlElement;
187-
return newRelation;
175+
);
188176
}
189177

190178
hasSvgRelation(): boolean {

0 commit comments

Comments
 (0)