-
Notifications
You must be signed in to change notification settings - Fork 384
/
PPTXRender.java
203 lines (175 loc) · 5.85 KB
/
PPTXRender.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*******************************************************************************
* Copyright (c) 2013 Actuate Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributors:
* Actuate Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.birt.report.engine.emitter.pptx;
import java.io.OutputStream;
import java.util.logging.Level;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.report.engine.api.CompressionMode;
import org.eclipse.birt.report.engine.api.DocxRenderOption;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.RenderOption;
import org.eclipse.birt.report.engine.api.script.IReportContext;
import org.eclipse.birt.report.engine.content.IReportContent;
import org.eclipse.birt.report.engine.emitter.EmitterUtil;
import org.eclipse.birt.report.engine.emitter.IEmitterServices;
import org.eclipse.birt.report.engine.emitter.ppt.util.PPTUtil;
import org.eclipse.birt.report.engine.emitter.pptx.writer.Slide;
import org.eclipse.birt.report.engine.layout.emitter.IPageDevice;
import org.eclipse.birt.report.engine.layout.emitter.PageDeviceRender;
import org.eclipse.birt.report.engine.nLayout.area.IContainerArea;
import org.eclipse.birt.report.engine.nLayout.area.IImageArea;
import org.eclipse.birt.report.engine.nLayout.area.ITextArea;
import org.eclipse.birt.report.engine.nLayout.area.impl.BlockTextArea;
import org.eclipse.birt.report.engine.nLayout.area.impl.PageArea;
import org.eclipse.birt.report.engine.nLayout.area.impl.TableArea;
import org.eclipse.birt.report.engine.nLayout.area.style.TextStyle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
/**
* The PPT render class.
*/
public class PPTXRender extends PageDeviceRender {
private OutputStream out = null;
private final String tempFileDir;
/** The default output PPT file name. */
public static final String REPORT_FILE = "Report.pptx"; //$NON-NLS-1$
private RenderOption renderOption = null;
public PPTXRender(IEmitterServices services) throws EngineException {
initialize(services);
tempFileDir = services.getReportEngine().getConfig().getTempDir();
}
@Override
public IPageDevice createPageDevice(String title, String author,
String subject, String description, IReportContext context,
IReportContent report) throws Exception {
try {
int compressionMode = getCompressionMode(renderOption).getValue();
PPTXPageDevice pageDevice = new PPTXPageDevice(out, title, author,
description, subject, tempFileDir, compressionMode);
return pageDevice;
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage());
}
return null;
}
private CompressionMode getCompressionMode(RenderOption renderOption) {
CompressionMode compressionMode = CompressionMode.BEST_COMPRESSION;
Object mode = renderOption
.getOption(DocxRenderOption.OPTION_COMPRESSION_MODE);
if (mode instanceof CompressionMode) {
compressionMode = (CompressionMode) mode;
}
return compressionMode;
}
/**
* Returns the output format, always is "ppt".
*
* @return the output format
*/
@Override
public String getOutputFormat() {
return "pptx";
}
/**
* Initializes the PPTEmitter.
*
* @param services
* the emitter services object.
* @throws BirtException
*/
public void initialize(IEmitterServices services) throws EngineException {
this.services = services;
renderOption = (RenderOption) services.getRenderOption();
reportRunnable = services.getReportRunnable();
if (reportRunnable != null) {
reportDesign = (ReportDesignHandle) reportRunnable
.getDesignHandle();
}
this.context = services.getReportContext();
this.out = EmitterUtil.getOuputStream(services, REPORT_FILE);
}
@Override
public void visitImage(IImageArea imageArea) {
PPTXPage page = (PPTXPage) pageGraphic;
page.setLink(PPTUtil.getHyperlink(imageArea, services, reportRunnable,
context));
super.visitImage(imageArea);
page.setLink(null);
}
@Override
public void visitText(ITextArea textArea) {
PPTXPage page = (PPTXPage) pageGraphic;
page.setLink(PPTUtil.getHyperlink(textArea, services, reportRunnable,
context));
super.visitText(textArea);
page.setLink(null);
}
@Override
protected void drawTextAt(ITextArea text, int x, int y, int width,
int height, TextStyle textStyle) {
pageGraphic.drawText(text.getLogicalOrderText(), x, y, width, height,
textStyle);
}
@Override
public void visitContainer(IContainerArea container) {
if (container instanceof PageArea) {
new SlideWriter(this).outputSlide((PageArea) container);
} else if (container instanceof TableArea) {
new TableWriter(this).outputTable((TableArea) container);
} else if (container instanceof BlockTextArea) {
new TextWriter(this).outputText((BlockTextArea) container);
} else {
startContainer(container);
visitChildren(container);
endContainer(container);
}
}
@Override
protected void visitPage(PageArea page) {
super.visitPage(page);
}
protected void visitTable(TableArea table) {
startContainer(table);
visitChildren(table);
endContainer(table);
}
protected void visitText(BlockTextArea text) {
startContainer(text);
visitChildren(text);
endContainer(text);
}
public PPTXPage getGraphic( )
{
return (PPTXPage)pageGraphic;
}
public Slide getSlide( )
{
return ((PPTXPage) pageGraphic).getSlide( );
}
public int getCurrentX()
{
return currentX;
}
public int getCurrentY()
{
return currentY;
}
public void setCurrentX( int x )
{
currentX = x;
}
public void setCurrentY( int y )
{
currentY = y;
}
public float getScale()
{
return scale;
}
}