Skip to content

Commit 808080e

Browse files
committed
Organis imports, use Arrays.sort
1 parent 0b735bc commit 808080e

1 file changed

Lines changed: 25 additions & 44 deletions

File tree

src/main/java/processing/pdf/PGraphicsPDF.java

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,33 @@
2121
package processing.pdf;
2222

2323
import com.itextpdf.awt.DefaultFontMapper;
24-
import com.itextpdf.text.Rectangle;
24+
import com.itextpdf.awt.PdfGraphics2D;
2525
import com.itextpdf.text.Document;
2626
import com.itextpdf.text.DocumentException;
27+
import com.itextpdf.text.Rectangle;
2728
import com.itextpdf.text.pdf.ByteBuffer;
2829
import com.itextpdf.text.pdf.PdfContentByte;
29-
import com.itextpdf.awt.PdfGraphics2D;
3030
import com.itextpdf.text.pdf.PdfWriter;
3131
import java.awt.Font;
3232
import java.awt.Graphics2D;
3333
import java.awt.Image;
34-
import java.io.*;
35-
import java.util.*;
34+
import java.io.BufferedOutputStream;
35+
import java.io.File;
36+
import java.io.FileNotFoundException;
37+
import java.io.FileOutputStream;
38+
import java.io.OutputStream;
39+
import java.util.Arrays;
40+
import java.util.HashMap;
3641
import java.util.logging.Level;
3742
import java.util.logging.Logger;
38-
39-
//import com.lowagie.text.*;
40-
//import com.lowagie.text.pdf.*;
41-
//import com.lowagie.text.pdf.ByteBuffer;
42-
4343
import processing.awt.PGraphicsJava2D;
44-
import processing.core.*;
44+
import processing.core.PApplet;
45+
import processing.core.PConstants;
46+
import processing.core.PFont;
47+
import processing.core.PImage;
48+
import processing.core.PStyle;
49+
import processing.core.PSurface;
50+
import processing.core.PSurfaceNone;
4551

4652
/**
4753
* Thin wrapper for the iText PDF library that handles writing PDF files. The
@@ -75,12 +81,9 @@ public class PGraphicsPDF extends PGraphicsJava2D {
7581
static protected DefaultFontMapper mapper;
7682
static protected String[] fontList;
7783

78-
79-
/*
80-
public PGraphicsPDF() {
81-
// PDF always likes native fonts. Always.
82-
hint(ENABLE_NATIVE_FONTS);
83-
}
84+
/**
85+
*
86+
* @param path
8487
*/
8588
@Override
8689
public void setPath(String path) {
@@ -105,15 +108,6 @@ public void setOutput(OutputStream output) {
105108
this.output = output;
106109
}
107110

108-
// /**
109-
// * all the init stuff happens in here, in case someone calls size()
110-
// * along the way and wants to hork things up.
111-
// */
112-
// protected void allocate() {
113-
// // can't do anything here, because this will be called by the
114-
// // superclass PGraphics, and the file/path object won't be set yet
115-
// // (since super() called right at the beginning of the constructor)
116-
// }
117111
@Override
118112
public PSurface createSurface() {
119113
return surface = new PSurfaceNone(this);
@@ -127,19 +121,17 @@ protected void defaultSettings() { // ignore
127121

128122
@Override
129123
public void beginDraw() {
130-
// long t0 = System.currentTimeMillis();
131-
132124
if (document == null) {
133-
// https://github.com/processing/processing/issues/5801#issuecomment-466632459
134125
ByteBuffer.HIGH_PRECISION = true;
135-
136126
document = new Document(new Rectangle(width, height));
137127
boolean missingPath = false;
138128
try {
139129
if (file != null) {
140-
//BufferedOutputStream output = new BufferedOutputStream(stream, 16384);
141-
output = new BufferedOutputStream(new FileOutputStream(file), 16384);
142-
130+
try {
131+
output = new BufferedOutputStream(new FileOutputStream(file), 16384);
132+
} catch (FileNotFoundException ex) {
133+
Logger.getLogger(PGraphicsPDF.class.getName()).log(Level.SEVERE, null, ex);
134+
}
143135
} else if (output == null) {
144136
missingPath = true;
145137
throw new RuntimeException("PGraphicsPDF requires a path "
@@ -160,12 +152,7 @@ public void beginDraw() {
160152
} else {
161153
throw new RuntimeException("Problem saving the PDF file.", re);
162154
}
163-
164-
} catch (FileNotFoundException fnfe) {
165-
throw new RuntimeException("Can't save the PDF file to " + path, fnfe);
166-
167155
}
168-
169156
g2 = new PdfGraphics2D(content, width, height);
170157
}
171158

@@ -174,23 +161,17 @@ public void beginDraw() {
174161
checkSettings();
175162
resetMatrix(); // reset model matrix
176163
vertexCount = 0;
177-
178-
// Also need to push the matrix since the matrix doesn't reset on each run
179-
// http://dev.processing.org/bugs/show_bug.cgi?id=1227
180164
pushMatrix();
181165
}
182166

183167
static protected DefaultFontMapper getMapper() {
184168
if (mapper == null) {
185-
// long t = System.currentTimeMillis();
186169
mapper = new DefaultFontMapper();
187-
188170
if (PApplet.platform == PConstants.LINUX) {
189171
checkDir("/usr/share/fonts/", mapper);
190172
checkDir("/usr/local/share/fonts/", mapper);
191173
checkDir(System.getProperty("user.home") + "/.fonts", mapper);
192174
}
193-
// System.out.println("mapping " + (System.currentTimeMillis() - t));
194175
}
195176
return mapper;
196177
}
@@ -596,7 +577,7 @@ static public String[] listFonts() {
596577
// //System.out.println(entry.getKey() + "-->" + entry.getValue());
597578
// fontList[count++] = (String) entry.getKey();
598579
// }
599-
fontList = PApplet.sort(fontList);
580+
Arrays.sort(fontList);
600581
}
601582
return fontList;
602583
}

0 commit comments

Comments
 (0)