Skip to content

Commit 60ec79a

Browse files
authored
Merge pull request #127 from singerla/mp70_feat_OLEsupport
Mp70 feat ol esupport
2 parents 5451192 + 4bcbdf2 commit 60ec79a

File tree

8 files changed

+333
-8
lines changed

8 files changed

+333
-8
lines changed

src/classes/has-shapes.ts

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { ElementType } from '../enums/element-type';
3333
import { GenericShape } from '../shapes/generic';
3434
import { XmlSlideHelper } from '../helper/xml-slide-helper';
3535
import { vd } from '../helper/general-helper';
36+
import { OLEObject } from '../shapes/ole';
3637

3738
export default class HasShapes {
3839
/**
@@ -113,7 +114,7 @@ export default class HasShapes {
113114
*/
114115
unsupportedTags = [
115116
'p:custDataLst',
116-
'p:oleObj',
117+
// 'p:oleObj',
117118
// 'mc:AlternateContent',
118119
//'a14:imgProps',
119120
];
@@ -122,7 +123,7 @@ export default class HasShapes {
122123
* @internal
123124
*/
124125
unsupportedRelationTypes = [
125-
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject',
126+
// 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject',
126127
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing',
127128
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/tags',
128129
];
@@ -387,6 +388,13 @@ export default class HasShapes {
387388
this.targetType,
388389
);
389390
break;
391+
case ElementType.OLEObject:
392+
await new OLEObject(info, this.targetType, this.sourceArchive)[info.mode](
393+
this.targetTemplate,
394+
this.targetNumber,
395+
this.targetType,
396+
);
397+
break;
390398
default:
391399
break;
392400
}
@@ -746,7 +754,6 @@ export default class HasShapes {
746754
*/
747755
async copyRelatedContent(): Promise<void> {
748756
const charts = await Chart.getAllOnSlide(this.sourceArchive, this.relsPath);
749-
750757
for (const chart of charts) {
751758
await new Chart(
752759
{
@@ -755,22 +762,37 @@ export default class HasShapes {
755762
sourceArchive: this.sourceArchive,
756763
sourceSlideNumber: this.sourceNumber,
757764
},
758-
this.targetType,
765+
this.targetType
759766
).modifyOnAddedSlide(this.targetTemplate, this.targetNumber);
760767
}
761768

762769
const images = await Image.getAllOnSlide(this.sourceArchive, this.relsPath);
763770
for (const image of images) {
771+
764772
await new Image(
765773
{
766774
mode: 'append',
767775
target: image,
768776
sourceArchive: this.sourceArchive,
769777
sourceSlideNumber: this.sourceNumber,
770778
},
771-
this.targetType,
779+
this.targetType
772780
).modifyOnAddedSlide(this.targetTemplate, this.targetNumber);
773781
}
782+
783+
const oleObjects = await OLEObject.getAllOnSlide(this.sourceArchive, this.relsPath);
784+
for (const oleObject of oleObjects) {
785+
await new OLEObject(
786+
{
787+
mode: 'append',
788+
target: oleObject,
789+
sourceArchive: this.sourceArchive,
790+
sourceSlideNumber: this.sourceNumber,
791+
},
792+
this.targetType,
793+
this.sourceArchive
794+
).modifyOnAddedSlide(this.targetTemplate, this.targetNumber, oleObjects);
795+
}
774796
}
775797

776798
/**
@@ -829,6 +851,21 @@ export default class HasShapes {
829851
} as AnalyzedElementType;
830852
}
831853

854+
const isOLEObject = sourceElement.getElementsByTagName('p:oleObj');
855+
if (isOLEObject.length) {
856+
const target = await XmlHelper.getTargetByRelId(
857+
sourceArchive,
858+
relsPath,
859+
sourceElement,
860+
'oleObject'
861+
);
862+
863+
return {
864+
type: ElementType.OLEObject,
865+
target: target,
866+
} as AnalyzedElementType;
867+
}
868+
832869
return {
833870
type: ElementType.Shape,
834871
} as AnalyzedElementType;

src/classes/slide.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { XmlRelationshipHelper } from '../helper/xml-relationship-helper';
1313
import { IMaster } from '../interfaces/imaster';
1414
import HasShapes from './has-shapes';
1515
import { Master } from './master';
16+
import { ElementType } from '../enums/element-type';
1617

1718
export class Slide extends HasShapes implements ISlide {
1819
targetType: ShapeTargetType = 'slide';

src/classes/template.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class Template implements ITemplate {
9797
new CountHelper('masters', newTemplate),
9898
new CountHelper('layouts', newTemplate),
9999
new CountHelper('themes', newTemplate),
100+
new CountHelper('oleObjects', newTemplate),
100101
];
101102
// TODO: refactor content tracker, let root template have an instance
102103
// newTemplate.content = new ContentTracker();

src/enums/element-type.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ export enum ElementType {
22
Chart = 'Chart',
33
Image = 'Image',
44
Shape = 'Generic',
5+
OLEObject = 'OLEObject',
56
}
67

78
export enum ElementSubtype {
89
chart = 'chart',
910
chartEx = 'chartEx',
11+
oleObject = 'oleObject',
1012
}

src/helper/count-helper.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ICounter } from '../interfaces/icounter';
44
import { RootPresTemplate } from '../interfaces/root-pres-template';
55
import { XmlHelper } from './xml-helper';
66
import { XmlElement } from '../types/xml-types';
7+
import { FileHelper } from './file-helper';
78

89
export class CountHelper implements ICounter {
910
template: RootPresTemplate;
@@ -62,6 +63,9 @@ export class CountHelper implements ICounter {
6263
return CountHelper.countCharts(presentation);
6364
case 'images':
6465
return CountHelper.countImages(presentation);
66+
case 'oleObjects':
67+
return CountHelper.countOleObjects(presentation);
68+
6569
}
6670

6771
throw new Error(`No way to count ${this.name}.`);
@@ -134,6 +138,24 @@ export class CountHelper implements ICounter {
134138
).length;
135139
}
136140

141+
private static async countOleObjects(presentation: IArchive): Promise<number> {
142+
const contentTypesXml = await XmlHelper.getXmlFromArchive(
143+
presentation,
144+
'[Content_Types].xml',
145+
);
146+
const overrides = contentTypesXml.getElementsByTagName('Override');
147+
148+
return Object.keys(overrides)
149+
.map((key) => overrides[key] as XmlElement)
150+
.filter(
151+
(o) =>
152+
o.getAttribute &&
153+
o.getAttribute('ContentType') ===
154+
`application/vnd.openxmlformats-officedocument.oleObject`
155+
).length;
156+
}
157+
158+
137159
private static async countImages(presentation: IArchive): Promise<number> {
138160
const mediaFiles = await presentation.folder('ppt/media');
139161
const count = mediaFiles.filter(

src/helper/xml-helper.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ export class XmlHelper {
166166
}
167167

168168
static async getRelationshipTargetsByPrefix(
169-
archive: IArchive,
170-
path: string,
171-
prefix: string | string[],
169+
archive: IArchive, path: string, prefix: string | string[]
172170
): Promise<Target[]> {
173171
const prefixes = typeof prefix === 'string' ? [prefix] : prefix;
174172

src/helper/xml-slide-helper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const mapUriType = {
1616
'http://schemas.openxmlformats.org/drawingml/2006/table': 'table',
1717
'http://schemas.openxmlformats.org/drawingml/2006/chart': 'chart',
1818
'http://schemas.microsoft.com/office/drawing/2014/chartex': 'chartEx',
19+
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject': 'oleObject',
1920
};
2021

2122
/**
@@ -202,6 +203,9 @@ export class XmlSlideHelper {
202203
const uri = graphicData.getAttribute('uri');
203204
type = mapUriType[uri] ? mapUriType[uri] : type;
204205
break;
206+
case 'oleObj':
207+
type = 'OLEObject';
208+
break;
205209
}
206210

207211
return type as ElementType;

0 commit comments

Comments
 (0)