Skip to content

Commit 8d04940

Browse files
committed
Implement #2093
1 parent fbf025e commit 8d04940

File tree

7 files changed

+220
-204
lines changed

7 files changed

+220
-204
lines changed

modules/PreviewAPI/src/main/java/org/gephi/preview/PDFRenderTargetBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ public RenderTarget buildRenderTarget(PreviewModel previewModel) {
9090
float marginTop = properties.getFloatValue(PDFTarget.MARGIN_TOP);
9191
final PDRectangle pageSize = properties.getValue(PDFTarget.PAGESIZE);
9292
boolean landscape = properties.getBooleanValue(PDFTarget.LANDSCAPE);
93-
Color backgroundColor = properties.getColorValue(PreviewProperty.BACKGROUND_COLOR);
93+
boolean transparentBackground = properties.getBooleanValue(PDFTarget.TRANSPARENT_BACKGROUND);
94+
Color backgroundColor = transparentBackground ? null : properties.getColorValue(PreviewProperty.BACKGROUND_COLOR);
9495
PDPageContentStream cb = properties.getValue(PDFTarget.PDF_CONTENT_BYTE);
9596
PDDocument doc = properties.getValue(PDFTarget.PDF_DOCUMENT);
9697
PDFRenderTargetImpl renderTarget = new PDFRenderTargetImpl(

modules/PreviewAPI/src/main/java/org/gephi/preview/api/PDFTarget.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public interface PDFTarget extends RenderTarget {
7272
String LANDSCAPE = "pdf.landscape";
7373
String PAGESIZE = "pdf.pagesize";
7474
String PDF_DOCUMENT = "pdf.document";
75+
String TRANSPARENT_BACKGROUND = "pdf.transparent.background";
7576

7677
/**
7778
* Returns the <code>PDPageContentStream</code> instance of the PDFTarget. PDPageContentStream

modules/PreviewExport/src/main/java/org/gephi/io/exporter/preview/PDFExporter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class PDFExporter implements ByteExporter, VectorExporter, LongTask {
8282
private float marginRight = 18f;
8383
private boolean landscape = false;
8484
private PDRectangle pageSize = PDRectangle.A4;
85+
private boolean transparentBackground = false;
8586

8687
@Override
8788
public boolean execute() {
@@ -108,6 +109,7 @@ public boolean execute() {
108109
props.putValue(PDFTarget.MARGIN_RIGHT, marginRight);
109110
props.putValue(PDFTarget.PDF_CONTENT_BYTE, contentStream);
110111
props.putValue(PDFTarget.PDF_DOCUMENT, doc);
112+
props.putValue(PDFTarget.TRANSPARENT_BACKGROUND, transparentBackground);
111113
target = (PDFTarget) controller.getRenderTarget(RenderTarget.PDF_TARGET, workspace);
112114
if (target instanceof LongTask) {
113115
((LongTask) target).setProgressTicket(progress);
@@ -176,6 +178,14 @@ public void setPageSize(PDRectangle pageSize) {
176178
this.pageSize = pageSize;
177179
}
178180

181+
public boolean isTransparentBackground() {
182+
return transparentBackground;
183+
}
184+
185+
public void setTransparentBackground(boolean transparentBackground) {
186+
this.transparentBackground = transparentBackground;
187+
}
188+
179189
@Override
180190
public void setOutputStream(OutputStream stream) {
181191
this.stream = stream;

modules/PreviewExportUI/src/main/java/org/gephi/ui/exporter/preview/UIExporterPDF.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ private static class ExporterPDFSettings extends AbstractExporterSettings {
106106
private final static String LANDSCAPE = "PDF_landscape";
107107
private final static String PAGE_SIZE_WIDTH = "PDF_pageSizeWidth";
108108
private final static String PAGE_SIZE_HEIGHT = "PDF_pageSizeHeight";
109+
private final static String TRANSPARENT_BACKGROUND = "PDF_transparentBackground";
109110
// Default
110111
private final static PDFExporter DEFAULT = new PDFExporter();
111112

@@ -118,6 +119,7 @@ private void load(PDFExporter exporter) {
118119
float width = get(PAGE_SIZE_WIDTH, DEFAULT.getPageSize().getWidth());
119120
float height = get(PAGE_SIZE_HEIGHT, DEFAULT.getPageSize().getHeight());
120121
exporter.setPageSize(new PDRectangle(width, height));
122+
exporter.setTransparentBackground(get(TRANSPARENT_BACKGROUND, DEFAULT.isTransparentBackground()));
121123
}
122124

123125
private void save(PDFExporter exporter) {
@@ -128,6 +130,7 @@ private void save(PDFExporter exporter) {
128130
put(LANDSCAPE, exporter.isLandscape());
129131
put(PAGE_SIZE_WIDTH, exporter.getPageSize().getWidth());
130132
put(PAGE_SIZE_HEIGHT, exporter.getPageSize().getHeight());
133+
put(TRANSPARENT_BACKGROUND, exporter.isTransparentBackground());
131134
}
132135
}
133136
}

modules/PreviewExportUI/src/main/java/org/gephi/ui/exporter/preview/UIExporterPDFPanel.form

Lines changed: 71 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.1" encoding="UTF-8" ?>
1+
<?xml version="1.0" encoding="UTF-8" ?>
22

33
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
44
<NonVisualComponents>
@@ -23,67 +23,75 @@
2323
<Group type="102" attributes="0">
2424
<EmptySpace max="-2" attributes="0"/>
2525
<Group type="103" groupAlignment="0" attributes="0">
26-
<Group type="102" attributes="0">
27-
<Component id="labelUnit" min="-2" max="-2" attributes="0"/>
28-
<EmptySpace min="-2" pref="62" max="-2" attributes="0"/>
29-
<Component id="unitLink" min="-2" max="-2" attributes="0"/>
30-
</Group>
3126
<Group type="102" alignment="0" attributes="0">
3227
<Group type="103" groupAlignment="0" attributes="0">
3328
<Component id="labelPageSize" alignment="0" min="-2" max="-2" attributes="0"/>
3429
<Component id="labelOrientation" alignment="0" min="-2" max="-2" attributes="0"/>
3530
<Component id="labelMargins" alignment="0" min="-2" max="-2" attributes="0"/>
31+
<Component id="labelBackground" alignment="0" min="-2" max="-2" attributes="0"/>
3632
</Group>
3733
<EmptySpace min="-2" pref="27" max="-2" attributes="0"/>
3834
<Group type="103" groupAlignment="0" attributes="0">
39-
<Group type="102" alignment="0" attributes="0">
40-
<Group type="103" groupAlignment="1" max="-2" attributes="0">
41-
<Component id="landscapeRadio" alignment="0" max="32767" attributes="1"/>
42-
<Component id="portraitRadio" alignment="0" max="32767" attributes="1"/>
35+
<Component id="pageSizeCombo" pref="217" max="32767" attributes="0"/>
36+
<Component id="transparentBackgroundCheckbox" alignment="0" max="32767" attributes="0"/>
37+
<Group type="102" attributes="0">
38+
<Group type="103" groupAlignment="0" attributes="0">
4339
<Group type="102" alignment="0" attributes="0">
44-
<Group type="103" groupAlignment="0" attributes="0">
45-
<Component id="labelHeight" min="-2" max="-2" attributes="0"/>
46-
<Component id="labelWidth" min="-2" max="-2" attributes="0"/>
40+
<Group type="103" groupAlignment="1" max="-2" attributes="0">
41+
<Component id="landscapeRadio" alignment="0" max="32767" attributes="1"/>
42+
<Component id="portraitRadio" alignment="0" max="32767" attributes="1"/>
43+
<Group type="102" alignment="0" attributes="0">
44+
<Group type="103" groupAlignment="0" attributes="0">
45+
<Component id="labelHeight" min="-2" max="-2" attributes="0"/>
46+
<Component id="labelWidth" min="-2" max="-2" attributes="0"/>
47+
</Group>
48+
<EmptySpace type="separate" max="-2" attributes="0"/>
49+
<Group type="103" groupAlignment="0" attributes="0">
50+
<Component id="heightTextField" alignment="1" min="-2" pref="95" max="-2" attributes="1"/>
51+
<Component id="widthTextField" alignment="0" min="-2" pref="95" max="-2" attributes="1"/>
52+
</Group>
53+
</Group>
4754
</Group>
48-
<EmptySpace type="separate" max="-2" attributes="0"/>
55+
<EmptySpace min="-2" pref="10" max="-2" attributes="0"/>
4956
<Group type="103" groupAlignment="0" attributes="0">
50-
<Component id="heightTextField" alignment="1" min="-2" pref="95" max="-2" attributes="1"/>
51-
<Component id="widthTextField" alignment="0" min="-2" pref="95" max="-2" attributes="1"/>
57+
<Component id="widthUnitLabel" min="-2" max="-2" attributes="1"/>
58+
<Component id="heightUnitLabel" alignment="0" min="-2" max="-2" attributes="1"/>
5259
</Group>
5360
</Group>
54-
</Group>
55-
<EmptySpace min="-2" pref="10" max="-2" attributes="0"/>
56-
<Group type="103" groupAlignment="0" attributes="0">
57-
<Component id="widthUnitLabel" min="-2" max="-2" attributes="1"/>
58-
<Component id="heightUnitLabel" alignment="0" min="-2" max="-2" attributes="1"/>
59-
</Group>
60-
</Group>
61-
<Component id="pageSizeCombo" pref="224" max="32767" attributes="0"/>
62-
<Group type="102" alignment="0" attributes="0">
63-
<Group type="103" groupAlignment="0" attributes="0">
64-
<Group type="102" alignment="0" attributes="0">
65-
<Component id="labelTop" min="-2" max="-2" attributes="0"/>
66-
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
67-
<Component id="topMarginTextField" min="-2" pref="34" max="-2" attributes="0"/>
68-
<EmptySpace type="separate" max="-2" attributes="0"/>
69-
<Component id="labelLeft" min="-2" max="-2" attributes="0"/>
70-
</Group>
7161
<Group type="102" alignment="0" attributes="0">
72-
<Component id="labelBottom" min="-2" max="-2" attributes="0"/>
73-
<EmptySpace type="unrelated" max="-2" attributes="0"/>
74-
<Component id="bottomMarginTextField" min="-2" pref="34" max="-2" attributes="0"/>
75-
<EmptySpace type="separate" max="-2" attributes="0"/>
76-
<Component id="labelRight" min="-2" max="-2" attributes="0"/>
62+
<Group type="103" groupAlignment="0" attributes="0">
63+
<Group type="102" alignment="0" attributes="0">
64+
<Component id="labelTop" min="-2" max="-2" attributes="0"/>
65+
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
66+
<Component id="topMarginTextField" min="-2" pref="34" max="-2" attributes="0"/>
67+
<EmptySpace type="separate" max="-2" attributes="0"/>
68+
<Component id="labelLeft" min="-2" max="-2" attributes="0"/>
69+
</Group>
70+
<Group type="102" alignment="0" attributes="0">
71+
<Component id="labelBottom" min="-2" max="-2" attributes="0"/>
72+
<EmptySpace type="unrelated" max="-2" attributes="0"/>
73+
<Component id="bottomMarginTextField" min="-2" pref="34" max="-2" attributes="0"/>
74+
<EmptySpace type="separate" max="-2" attributes="0"/>
75+
<Component id="labelRight" min="-2" max="-2" attributes="0"/>
76+
</Group>
77+
</Group>
78+
<EmptySpace min="-2" pref="21" max="-2" attributes="0"/>
79+
<Group type="103" groupAlignment="1" attributes="0">
80+
<Component id="leftMarginTextField" min="-2" pref="34" max="-2" attributes="0"/>
81+
<Component id="rightMargintextField" min="-2" pref="34" max="-2" attributes="0"/>
82+
</Group>
7783
</Group>
7884
</Group>
79-
<EmptySpace min="-2" pref="21" max="-2" attributes="0"/>
80-
<Group type="103" groupAlignment="1" attributes="0">
81-
<Component id="leftMarginTextField" min="-2" pref="34" max="-2" attributes="0"/>
82-
<Component id="rightMargintextField" min="-2" pref="34" max="-2" attributes="0"/>
83-
</Group>
85+
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
8486
</Group>
8587
</Group>
8688
</Group>
89+
<Group type="102" attributes="0">
90+
<Component id="labelUnit" min="-2" max="-2" attributes="0"/>
91+
<EmptySpace min="-2" pref="62" max="-2" attributes="0"/>
92+
<Component id="unitLink" min="-2" max="-2" attributes="0"/>
93+
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
94+
</Group>
8795
</Group>
8896
<EmptySpace max="-2" attributes="0"/>
8997
</Group>
@@ -136,7 +144,12 @@
136144
<Component id="labelRight" alignment="3" min="-2" max="-2" attributes="0"/>
137145
<Component id="rightMargintextField" alignment="3" min="-2" max="-2" attributes="0"/>
138146
</Group>
139-
<EmptySpace max="32767" attributes="0"/>
147+
<EmptySpace type="separate" max="-2" attributes="0"/>
148+
<Group type="103" groupAlignment="0" attributes="0">
149+
<Component id="transparentBackgroundCheckbox" min="-2" max="-2" attributes="0"/>
150+
<Component id="labelBackground" min="-2" max="-2" attributes="0"/>
151+
</Group>
152+
<EmptySpace pref="19" max="32767" attributes="0"/>
140153
</Group>
141154
</Group>
142155
</DimensionLayout>
@@ -311,5 +324,19 @@
311324
<Property name="focusPainted" type="boolean" value="false"/>
312325
</Properties>
313326
</Component>
327+
<Component class="javax.swing.JCheckBox" name="transparentBackgroundCheckbox">
328+
<Properties>
329+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
330+
<ResourceString bundle="org/gephi/ui/exporter/preview/Bundle.properties" key="UIExporterPDFPanel.transparentBackgroundCheckbox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
331+
</Property>
332+
</Properties>
333+
</Component>
334+
<Component class="javax.swing.JLabel" name="labelBackground">
335+
<Properties>
336+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
337+
<ResourceString bundle="org/gephi/ui/exporter/preview/Bundle.properties" key="UIExporterPDFPanel.labelBackground.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
338+
</Property>
339+
</Properties>
340+
</Component>
314341
</SubComponents>
315342
</Form>

0 commit comments

Comments
 (0)