Skip to content

Commit bfa57ec

Browse files
committed
Gnu JPDF fixes -- "serif" font; ".pdf" for file names
1 parent fb24f7c commit bfa57ec

5 files changed

Lines changed: 40 additions & 12 deletions

File tree

sources/net.sf.j2s.java.core/src/gnu/jpdf/PDFFont.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class PDFFont extends PDFObject implements Serializable
4242
* The package name was changed to gnu.pdf.
4343
* The formatting was changed a little bit
4444
* It is still licensed under the LGPL.
45+
*
46+
* BH SwingJS: Java "serif" added 2017.12.23
4547
*/
4648

4749
/**
@@ -94,10 +96,10 @@ public PDFFont(String name,String type,String font,int style) {
9496
String f = font.toLowerCase();
9597

9698
// default PDF Font name
97-
// this.font = base14[0][1];
98-
// this.javaFont = base14[0][0];
99-
this.font = font;
100-
this.javaFont = "/" + font;
99+
this.font = base14[0][1];
100+
this.javaFont = base14[0][0];
101+
// this.font = font;
102+
// this.javaFont = "/" + font;
101103

102104
// attempt to translate the font name from Java to PDF
103105
for(int i=0;i<base14.length;i++) {
@@ -198,7 +200,7 @@ protected boolean equals(String type,String font,int style) {
198200
// ITALIC
199201
// BOLD+ITALIC
200202
{
201-
"arial",
203+
"arial", // default
202204
"/Helvetica",
203205
"/Helvetica-Bold",
204206
"/Helvetica-Oblique",
@@ -221,6 +223,12 @@ protected boolean equals(String type,String font,int style) {
221223
"/Times-Bold",
222224
"/Times-Italic",
223225
"/Times-BoldItalic" },
226+
{
227+
"serif", // BH added
228+
"/Times-Roman",
229+
"/Times-Bold",
230+
"/Times-Italic",
231+
"/Times-BoldItalic" },
224232
{
225233
"courier",
226234
"/Courier",

sources/net.sf.j2s.java.core/src/gnu/jpdf/PDFJob.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.awt.PrintJob;
2626
import java.awt.Rectangle;
2727
import java.awt.print.PageFormat;
28+
import java.io.FileOutputStream;
2829
import java.io.IOException;
2930
import java.io.OutputStream;
3031
import java.io.PrintWriter;
@@ -194,9 +195,12 @@ public void end() {
194195
}
195196
}
196197

197-
// This should mark us as dead
198+
System.out.println("GNU JPDF job complete: " + pdfDocument.getPDFInfo().getTitle());
199+
200+
// This should mark us as dead
198201
os = null;
199202
pdfDocument = null;
203+
200204
}
201205

202206

sources/net.sf.j2s.java.core/src/gnu/jpdf/PDFPrinterJob.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,29 @@ public void print(String pathname) throws PrinterException {
144144
System.err.println("Error!! - Invalid output file path: " + pathname);
145145
}
146146

147+
System.out.println("GNU JPDF creating " + file);
148+
147149
PDFGraphics pdfGraphics = null;
148150
printJob = new PDFJob(fileOutputStream);
149151

150152
if (info != null) {
151153
printJob.getPDFDocument().setPDFInfo(info);
152154
}
153155

154-
pageCount = pageable.getNumberOfPages();
156+
pageCount = (pageable == null ? 1 : pageable.getNumberOfPages());
155157
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
156-
pageFormat = pageable.getPageFormat(pageIndex);
158+
if (pageable != null)
159+
pageFormat = pageable.getPageFormat(pageIndex);
157160

158161
pdfGraphics = (PDFGraphics) printJob.getGraphics(pageFormat);
159-
printable = pageable.getPrintable(pageIndex);
162+
if (pageable != null)
163+
printable = pageable.getPrintable(pageIndex);
160164
printable.print(pdfGraphics, pageFormat, pageIndex);
161165
pdfGraphics.dispose();
162166
}
163-
164167
printJob.end();
168+
169+
System.out.println("GNU JPDF created: " + file);
165170

166171
}
167172

sources/net.sf.j2s.java.core/src/gnu/jpdf/PDFTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,17 @@
5959
import javax.swing.Scrollable;
6060

6161
/*
62+
*
63+
* Note that this package does not use PDFPrinterJob, just the simpler PDFJob.
64+
*
65+
*
6266
* SwingJS note: This took an afternoon to integrate into SwingJS -- we were just missing
6367
* a few classes, which were easy enough to get from GrepCode (OpenJDK), and in SwingJS,
6468
* for performance reasons, we do not implement OutputStream.write(byte[]), and we have
6569
* a better way to get a FontMetrics. Other than that, flawless!
6670
*
71+
*
72+
*
6773
* Thank you, GNU Java PDF team!!!
6874
*
6975
* Bob Hanson
@@ -139,6 +145,8 @@ public PDFTest(String outputPdfFile,
139145
System.exit(1);
140146
}
141147

148+
System.out.println("GNU JPDF creating " + file);
149+
142150
// Handle window closing
143151
addWindowListener(new WindowAdapter() {
144152
public void windowClosing(WindowEvent e) {

sources/net.sf.j2s.java.core/src/swingjs/JSPrintJob.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
public class JSPrintJob extends PDFJob {
1717

1818
private String fileName;
19+
private String jobTitle;
1920
private JobAttributes jobAttributes;
2021
private PageAttributes pageAttributes;
2122
private Properties properties;
@@ -46,10 +47,12 @@ public void setProperties(String jobtitle, Properties properties) {
4647
}
4748

4849
private void setFile(String jobtitle) {
49-
fileName = jobtitle;
50+
fileName = jobTitle = jobtitle;
51+
if (fileName != null && !fileName.endsWith(".pdf"))
52+
fileName += ".pdf";
5053
try {
5154
// coerce jsjava to java
52-
os = (java.io.OutputStream) (Object) (jobtitle == null ? new ByteArrayOutputStream() : new FileOutputStream(jobtitle));
55+
os = (java.io.OutputStream) (Object) (fileName == null ? new ByteArrayOutputStream() : new FileOutputStream(fileName));
5356
} catch (FileNotFoundException e) {
5457
}
5558
}

0 commit comments

Comments
 (0)