diff options
8 files changed, 16 insertions, 266 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java index d9263d72..1336d7b6 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java @@ -187,12 +187,11 @@ public class PositioningComposite extends StateComposite { * @param transparency * transparency of the signature placeholder (0 - 255) */ - public void setPlaceholder(final Image placeholder, final int width, final int height, - final int transparency) { + public void setPlaceholder(final Image placeholder, final int transparency) { EventQueue.invokeLater(() -> { if (this.viewer == null) return; - this.viewer.setSignaturePlaceholder(placeholder, width, height, transparency); + this.viewer.setSignaturePlaceholder(placeholder, transparency); }); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java index 34837b2d..879a3e98 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SignaturePanel.java @@ -150,10 +150,11 @@ public class SignaturePanel extends JPanel { * @param height height of the placeholder in page space
* @param transparency transparency of the signature placeholder (0 - 255)
*/
- public void setSignaturePlaceholder(Image placeholder, int width, int height, int transparency) {
+ public void setSignaturePlaceholder(Image placeholder, int transparency) {
this.sigPlaceholder = placeholder;
- this.sigPageWidth = width;
- this.sigPageHeight = height;
+ // TODO figure out why this is divided by 4 (factor ported from old code)
+ this.sigPageWidth = placeholder.getWidth(null) / 4;
+ this.sigPageHeight = placeholder.getHeight(null) / 4;
this.sigPlaceholderTransparency = transparency;
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java index 3d351292..34155668 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java @@ -15,6 +15,7 @@ */ package at.asit.pdfover.gui.composites.configuration; +import java.awt.image.BufferedImage; // Imports import java.io.File; import java.io.IOException; @@ -62,7 +63,6 @@ import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.controls.ErrorMarker; import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; import at.asit.pdfover.gui.utils.ImageConverter; -import at.asit.pdfover.gui.utils.SignaturePlaceholderCache; import at.asit.pdfover.gui.workflow.config.ConfigurationManager; import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory; import at.asit.pdfover.gui.workflow.states.State; @@ -434,7 +434,7 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase { logo = new ImageData(image); param.emblem = new Emblem(image); } - img = SignaturePlaceholderCache.getSWTPlaceholder(param); + img = ImageConverter.convertToSWT((BufferedImage) param.getPlaceholder()); } catch (Exception e) { log.error("Failed to load image for display...", e); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/ImageConverter.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/ImageConverter.java index 11187c31..09582f75 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/ImageConverter.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/ImageConverter.java @@ -100,6 +100,9 @@ public class ImageConverter { * @return SWT Image data */ public static ImageData convertToSWT(final BufferedImage bufferedImage) { + if (bufferedImage == null) + return null; + if (bufferedImage.getColorModel() instanceof DirectColorModel) { DirectColorModel colorModel = (DirectColorModel) bufferedImage .getColorModel(); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SignaturePlaceholderCache.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SignaturePlaceholderCache.java deleted file mode 100644 index 92efea0a..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SignaturePlaceholderCache.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.utils; - -// Imports -import java.awt.Image; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Properties; - -import javax.imageio.ImageIO; - -import at.asit.pdfover.commons.Profile; -import org.eclipse.swt.graphics.ImageData; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.Util; -import at.asit.pdfover.commons.Constants; -import at.asit.pdfover.signator.Emblem; -import at.asit.pdfover.signer.pdfas.PdfAs4SignatureParameter; - -/** - * - */ -public class SignaturePlaceholderCache { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory.getLogger(SignaturePlaceholderCache.class); - - private static void saveImage(BufferedImage image, String fileDir, String fileName, String fileExt) throws IOException { - File file = new File(fileDir, fileName + "." + fileExt); - ImageIO.write(image, fileExt, file); // ignore returned boolean - } - - private static Image loadImage(String fileDir, String fileName, String fileExt) throws IOException { - return Util.readImageWithEXIFRotation(new File(fileDir, fileName + "." + fileExt)); - } - - /** - * Get placeholder as AWT Image - * @param param SignatureParameter - * @return the placeholder AWT Image - */ - public static Image getPlaceholder(PdfAs4SignatureParameter param) { - final String fileDir = Constants.CONFIG_DIRECTORY; - final String imgFileName = Constants.PLACEHOLDER_CACHE_FILENAME; - final String imgFileExt = "png"; - final String propFileName = Constants.PLACEHOLDER_CACHE_PROPS_FILENAME; - - final String sigLangProp = "LANG"; - final String sigEmblProp = "EMBL"; - final String sigEHshProp = "EHSH"; - final String sigPdfAProp = "PDFA"; - final String sigNoteProp = "NOTE"; - final String sigProfProp = "PROF"; - - String sigLang = param.signatureLanguage; - String sigEmbl = ""; - String sigEHsh = ""; - if (param.emblem != null) { - Emblem embl = param.emblem; - sigEmbl = embl.getOriginalFileName(); - sigEHsh = embl.getOriginalFileHash(); - } - String sigPdfA = param.enablePDFACompat ? Constants.TRUE : Constants.FALSE; - String sigNote = param.getProperty("SIG_NOTE"); - if (sigNote == null) - sigNote = ""; - String profile = param.signatureProfileName; - if (profile == null){ - // set default value - profile = Profile.getDefaultProfile(); - } - Properties sigProps = new Properties(); - // compare cache, try to load if match - try { - InputStream in = new FileInputStream(new File(fileDir, propFileName)); - sigProps.load(in); - if (sigLang.equals(sigProps.getProperty(sigLangProp)) && - sigEmbl.equals(sigProps.getProperty(sigEmblProp)) && - sigEHsh.equals(sigProps.getProperty(sigEHshProp)) && - sigNote.equals(sigProps.getProperty(sigNoteProp)) && - sigPdfA.equals(sigProps.getProperty(sigPdfAProp)) && - profile.equals(sigProps.getProperty(sigProfProp))) { - log.debug("Placeholder cache hit"); - return loadImage(fileDir, imgFileName, imgFileExt); - } - log.debug("Placeholder cache miss (" + - sigLang + "|" + sigProps.getProperty(sigLangProp) + " - " +// - sigEmbl + "|" + sigProps.getProperty(sigEmblProp) + " - " + - sigEHsh + "|" + sigProps.getProperty(sigEHshProp) + " - " + - sigNote + "|" + sigProps.getProperty(sigNoteProp) + " - " + - sigPdfA + "|" + sigProps.getProperty(sigPdfAProp) + " - " + - profile + "|" + sigProps.getProperty(sigProfProp) + ")"); - } catch (Exception e) { - log.warn("Can't load signature Placeholder", e); - } - - // create new cache - try { - sigProps.setProperty(sigLangProp, sigLang); - sigProps.setProperty(sigEmblProp, sigEmbl); - sigProps.setProperty(sigEHshProp, sigEHsh); - sigProps.setProperty(sigNoteProp, sigNote); - sigProps.setProperty(sigPdfAProp, sigPdfA); - sigProps.setProperty(sigProfProp, profile); - OutputStream out = new FileOutputStream(new File(fileDir, propFileName)); - sigProps.store(out, null); - Image img = param.getPlaceholder(); - saveImage((BufferedImage) img, fileDir, imgFileName, imgFileExt); - return img; - } catch (IOException e) { - log.error("Can't save signature Placeholder", e); - return param.getPlaceholder(); - } - } - - /** - * Get placeholder as SWT ImageData - * @param param SignatureParameter - * @return the placeholder SWT ImageData - */ - public static ImageData getSWTPlaceholder(PdfAs4SignatureParameter param) { - return ImageConverter.convertToSWT((BufferedImage) getPlaceholder(param)); - } -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java index 4dfb514c..3bcf18bc 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java @@ -31,7 +31,6 @@ import at.asit.pdfover.gui.composites.PositioningComposite; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.commons.Messages; -import at.asit.pdfover.gui.utils.SignaturePlaceholderCache; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; import at.asit.pdfover.gui.workflow.config.ConfigurationManager; @@ -117,9 +116,7 @@ public class PositioningState extends State { param.enablePDFACompat = config.getSignaturePdfACompat(); this.positionComposite.setPlaceholder( - SignaturePlaceholderCache.getPlaceholder(param), - param.getPlaceholderDimension().getWidth(), - param.getPlaceholderDimension().getHeight(), + param.getPlaceholder(), config.getPlaceholderTransparency()); if (this.previousPosition != null && !this.previousPosition.useAutoPositioning()) this.positionComposite.setPosition( diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureDimension.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureDimension.java deleted file mode 100644 index 877c9386..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureDimension.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.signator; - -//Imports - -/** - * The dimensions of the visible signature block - */ -public class SignatureDimension { - - /** - * The visible Signature block width - */ - protected int width; - - /** - * The visible Signature block height - */ - protected int height; - - /** - * Constructor - * @param width The width of the signature block - * @param height The height of the signature block - */ - public SignatureDimension(int width, int height) { - setDimension(width, height); - } - - /** - * Sets the the dimension of the signature block - * @param width The width - * @param height The height - */ - public void setDimension(int width, int height) - { - setWidth(width); - setHeight(height); - } - - /** - * Sets the width for the dimension - * @param width - */ - public void setWidth(int width) { - this.width = width; - } - - /** - * Gets the width of the visible Signature block - * @return the width - */ - public int getWidth() { - return this.width; - } - - /** - * Sets the height for the dimension - * @param height - */ - public void setHeight(int height) { - this.height = height; - } - - /** - * Gets the height of the visible Signature block - * @return the height - */ - public int getHeight() { - return this.height; - } -} diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java index 8a011291..aba1e9ac 100644 --- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java @@ -30,7 +30,6 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.signator.BKUs; import at.asit.pdfover.signator.DocumentSource; import at.asit.pdfover.signator.Emblem; -import at.asit.pdfover.signator.SignatureDimension; import at.asit.pdfover.signator.SignaturePosition; import at.gv.egiz.pdfas.lib.api.Configuration; import at.gv.egiz.pdfas.lib.api.PdfAs; @@ -79,19 +78,8 @@ public class PdfAs4SignatureParameter { private HashMap<String, String> genericProperties = new HashMap<String, String>(); - /** - * This parameters are defining the signature block size - */ - private int sig_w = 229; - private int sig_h = 77; - public String signatureProfileName = Profile.getDefaultProfile(); - // TODO why is this stored separately? - public SignatureDimension getPlaceholderDimension() { - return new SignatureDimension(this.sig_w, this.sig_h); - } - public Image getPlaceholder() { String sigProfile = getPdfAsSignatureProfileId(); @@ -108,19 +96,13 @@ public class PdfAs4SignatureParameter { if (sigNote != null) { conf.setValue("sig_obj." + sigProfile + ".value.SIG_NOTE", sigNote); } - SignParameter param = PdfAsFactory - .createSignParameter(conf, null, null); + SignParameter param = PdfAsFactory.createSignParameter(conf, null, null); param.setSignatureProfileId(sigProfile); - Image img = pdfas.generateVisibleSignaturePreview(param, cert, 72 * 4); - this.sig_w = img.getWidth(null) / 4; - this.sig_h = img.getHeight(null) / 4; - - return img; + + return pdfas.generateVisibleSignaturePreview(param, cert, 72 * 4); } catch (Exception e) { log.error("Failed to get signature placeholder", e); - return new BufferedImage(getPlaceholderDimension().getWidth(), - getPlaceholderDimension().getHeight(), - BufferedImage.TYPE_INT_RGB); + return new BufferedImage(229, 77, BufferedImage.TYPE_INT_RGB); } } |