diff options
author | tkellner <tkellner@3a0b52a2-8410-0410-bc02-ff6273a87459> | 2012-10-31 16:36:41 +0000 |
---|---|---|
committer | tkellner <tkellner@3a0b52a2-8410-0410-bc02-ff6273a87459> | 2012-10-31 16:36:41 +0000 |
commit | 84787c7868dcd55883e066c2046144833524a00d (patch) | |
tree | 98ba05de805ada7e14c490030c868ed0e7be0b52 /trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java | |
parent | b0b3d5e20859073097d95cefa92da52f7e620d8d (diff) | |
download | pdf-over-84787c7868dcd55883e066c2046144833524a00d.tar.gz pdf-over-84787c7868dcd55883e066c2046144833524a00d.tar.bz2 pdf-over-84787c7868dcd55883e066c2046144833524a00d.zip |
Use specified font, scale emblem in placeholder
git-svn-id: https://svn.iaik.tugraz.at/svn/egiz/prj/current/12PDF-OVER-4.0@12709 3a0b52a2-8410-0410-bc02-ff6273a87459
Diffstat (limited to 'trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java')
-rw-r--r-- | trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java index 39c64371..a15a00e2 100644 --- a/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java +++ b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java @@ -144,16 +144,18 @@ public class PdfAsSignatureParameter extends SignatureParameter { log.info("Width: " + width + " Height: " + height); BufferedImage image = new BufferedImage((int) width, (int) height, BufferedImage.TYPE_INT_RGB); - Graphics graphic = image.getGraphics(); + Graphics g = image.getGraphics(); - graphic.setColor(table.getStyle().getBgColor()); - graphic.fillRect(0, 0, (int) width, (int) height); + g.setColor(table.getStyle().getBgColor()); + g.fillRect(0, 0, (int) width, (int) height); - graphic.setColor(Color.black); - graphic.drawRect(0, 0, (int) width, (int) height); + g.setColor(Color.black); + g.drawRect(0, 0, (int) width, (int) height); this.drawTable(0, 0, (int) width, (int) height, table, - table.getStyle(), graphic, heights); + table.getStyle(), g, heights); + + g.dispose(); // save(image, "png"); @@ -177,6 +179,7 @@ public class PdfAsSignatureParameter extends SignatureParameter { * @param ext */ @SuppressWarnings("unused") + @Deprecated private static void save(BufferedImage image, String ext) { String fileName = "savingAnImage"; File file = new File(fileName + "." + ext); @@ -222,7 +225,7 @@ public class PdfAsSignatureParameter extends SignatureParameter { @SuppressWarnings("rawtypes") private int drawTable(int xoff, int yoff, int width, int height, - Table table, Style parentstyle, Graphics graphic, float[] heights) { + Table table, Style parentstyle, Graphics g, float[] heights) { Style style = parentstyle; if (table.getStyle() != null) { style = table.getStyle(); @@ -230,19 +233,20 @@ public class PdfAsSignatureParameter extends SignatureParameter { log.debug(String.format("Table@ %dx%d", xoff, yoff)); - Font oldFont = graphic.getFont(); + Font oldFont = g.getFont(); Font font = PdfAsSignatureParameter.getFont(style); + g.setFont(font); // draw background // graphic.setColor(style.getBgColor()); // graphic.fillRect(xoff, yoff, width, height); - graphic.setColor(Color.black); + g.setColor(Color.black); // draw border if (style.getBorder() > 0) { - graphic.setColor(Color.black); - graphic.drawRect(xoff, yoff, width, height); + g.setColor(Color.black); + g.drawRect(xoff, yoff, width, height); } float[] colWidths = table.getColsRelativeWith(); float sum = 0; @@ -268,11 +272,11 @@ public class PdfAsSignatureParameter extends SignatureParameter { } if (entry.getType() == 0 || entry.getType() == 1) { // Text - graphic.drawRect((int) (xoff + offset), + g.drawRect((int) (xoff + offset), (int) (yoff + roffset), (int) (colWidths[j] * perUnit), rsize); - graphic.drawString(entry.getValue().toString(), (int) (xoff + g.drawString(entry.getValue().toString(), (int) (xoff + offset + padding), (int) (yoff + padding + roffset + font.getSize() * this.perUnitHeight)); } else if (entry.getType() == 2) { @@ -291,13 +295,15 @@ public class PdfAsSignatureParameter extends SignatureParameter { + "/" + entry.getValue().toString())); } - Image img = image.getScaledInstance(80, 80, - Image.SCALE_DEFAULT); + int imgWidth = 40; + int imgHeight = 40; + Image img = image.getScaledInstance(imgWidth, imgHeight, + Image.SCALE_SMOOTH); - graphic.drawImage( + g.drawImage( img, - (int) (xoff + offset + padding + (((colWidths[j] * perUnit) - 80 - padding)) / 2), - (int) (yoff + roffset + padding + ((rsize - 80 - padding) / 2)), + (int) (xoff + offset + padding + (((colWidths[j] * perUnit) - imgWidth - padding)) / 2), + (int) (yoff + roffset + padding + ((rsize - imgHeight - padding) / 2)), null); } catch (IOException e) { log.warn("Failed to paint emblem to placeholder image"); @@ -314,7 +320,7 @@ public class PdfAsSignatureParameter extends SignatureParameter { (int) (colWidths[j] * perUnit), // (int)this.getTableHeight((Table) // entry.getValue(), style), - rsize, (Table) entry.getValue(), style, graphic, + rsize, (Table) entry.getValue(), style, g, cheights); /* * if (rsize < tsize) { rsize = tsize; } @@ -324,7 +330,7 @@ public class PdfAsSignatureParameter extends SignatureParameter { roffset += rsize; } - graphic.setFont(oldFont); + g.setFont(oldFont); return (int) roffset; } |