r692 - in trunk: . faxtomail-ui-swing faxtomail-ui-swing/src/license faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor
Author: kmorin Date: 2014-11-18 15:21:43 +0000 (Tue, 18 Nov 2014) New Revision: 692 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/692 Log: fixes #5965 Probl?\195?\168me de taille et de d?\195?\169calage des annotations sur certains pdf fixes #6101 baisse qualit?\195?\169 sur les docs annot?\195?\169 Modified: trunk/faxtomail-ui-swing/pom.xml trunk/faxtomail-ui-swing/src/license/THIRD-PARTY.properties trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java trunk/pom.xml Modified: trunk/faxtomail-ui-swing/pom.xml =================================================================== --- trunk/faxtomail-ui-swing/pom.xml 2014-11-17 16:58:10 UTC (rev 691) +++ trunk/faxtomail-ui-swing/pom.xml 2014-11-18 15:21:43 UTC (rev 692) @@ -225,6 +225,7 @@ <artifactId>itextpdf</artifactId> </dependency> + <!-- for pdf printing --> <dependency> <groupId>org.swinglabs</groupId> <artifactId>pdf-renderer</artifactId> @@ -252,6 +253,12 @@ <artifactId>activation</artifactId> </dependency> + <!-- for pdf edition --> + <dependency> + <groupId>org.jpedal</groupId> + <artifactId>jpedal-lgpl</artifactId> + </dependency> + </dependencies> <!-- TODO --> Modified: trunk/faxtomail-ui-swing/src/license/THIRD-PARTY.properties =================================================================== --- trunk/faxtomail-ui-swing/src/license/THIRD-PARTY.properties 2014-11-17 16:58:10 UTC (rev 691) +++ trunk/faxtomail-ui-swing/src/license/THIRD-PARTY.properties 2014-11-18 15:21:43 UTC (rev 692) @@ -6,6 +6,7 @@ # - Apache License 2.0 # - Apache License, version 2.0 # - BSD License +# - Bouncy Castle Licence # - CDDL # - Common Development and Distribution License # - Common Development and Distribution License (CDDL) v1.0 @@ -24,8 +25,10 @@ # - GNU Library or Lesser General Public License # - GPLv2+CE # - General Public License (GPL) +# - JDL (Java Distribution License) # - LGPL # - LGPL 2.1 +# - LGPL Open Source license # - Lesser General Public License (LGPL) # - Lesser General Public License (LGPL) v 3.0 # - MIT License @@ -40,10 +43,11 @@ # Please fill the missing licenses for dependencies : # # -#Mon Nov 17 17:38:01 CET 2014 +#Tue Nov 18 15:49:51 CET 2014 commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0 dom4j--dom4j--1.6.1=BSD License gui.ava--html2image--2.0.1=GNU Lesser General Public License, Version 2.1 +javax.media--jai_codec--1.1.3=Apache License javax.media.jai--com.springsource.javax.media.jai.codec--1.1.3=Apache License javax.media.jai--com.springsource.javax.media.jai.core--1.1.3=Apache License org.nuiton.thirdparty--sdoc--0.5.0-beta-patchcl=Lesser General Public License (LGPL) v 3.0 Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java 2014-11-17 16:58:10 UTC (rev 691) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java 2014-11-18 15:21:43 UTC (rev 692) @@ -32,30 +32,20 @@ import java.awt.event.MouseEvent; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; -import java.awt.image.RenderedImage; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStreamReader; import java.io.RandomAccessFile; -import java.net.URL; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; -import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.List; -import javax.imageio.ImageIO; -import javax.media.jai.PlanarImage; import javax.swing.JComponent; import javax.swing.JPanel; -import com.sun.pdfview.PDFFile; -import com.sun.pdfview.PDFPage; import jaxx.runtime.swing.ComponentMover; import jaxx.runtime.swing.ComponentResizer; import jaxx.runtime.swing.JAXXButtonGroup; @@ -64,6 +54,9 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jpedal.PdfDecoder; +import org.jpedal.exception.PdfException; +import org.jpedal.fonts.FontMappings; import org.nuiton.jaxx.application.swing.util.Cancelable; import org.nuiton.jaxx.application.swing.util.CloseableUI; @@ -90,7 +83,8 @@ protected ComponentMover cm = new ComponentMover(); protected ComponentResizer cr = new ComponentResizer(); - protected PDFFile pdf; + protected PdfDecoder pdfDecoder; +// protected PDFFile pdf; @Override public void afterInit(PDFEditorUI pdfEditorUI) { @@ -113,6 +107,9 @@ String value = (String) actionGroup.getSelectedValue(); model.setSelectedComponent(PDFEditorUIModel.EditionComponent.valueOf(value)); + pdfDecoder = new PdfDecoder(true); + FontMappings.setFontReplacements(); + ui.getContainer().addContainerListener(new ContainerListener() { @Override public void componentAdded(ContainerEvent e) { @@ -179,35 +176,32 @@ } catch (IOException e) { if (log.isErrorEnabled()) { - log.error("", e); + log.error("error while converting file to pdf", e); } getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.convertToPdf.error")); } catch (DocumentException e) { if (log.isErrorEnabled()) { - log.error("", e); + log.error("error while converting file to pdf", e); } getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.convertToPdf.error")); } } if (FaxToMailUIUtil.isFileAPDF(attachmentFile)) { - RandomAccessFile raf = null; try { - raf = new RandomAccessFile(file, "r"); - FileChannel channel = raf.getChannel(); - ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); - pdf = new PDFFile(buf); + pdfDecoder.closePdfFile(); + pdfDecoder.openPdfFile(file.getPath()); + pdfDecoder.setExtractionMode(0, 0, 1f); + pdfDecoder.setCenterOnScaling(true); - model.setPageNumber(pdf.getNumPages()); + model.setPageNumber(pdfDecoder.getPageCount()); model.setCurrentPageIndex(1); - raf.close(); - } catch (IOException e) { + + } catch (PdfException e) { if (log.isErrorEnabled()) { - log.error("", e); + log.error("error while converting file to pdf", e); } getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.readPdf.error")); - } finally { - IOUtils.closeQuietly(raf); } } getUI().setCursor(Cursor.getDefaultCursor()); @@ -265,7 +259,7 @@ @Override public void onCloseUI() { - + pdfDecoder.closePdfFile(); } public void addEditionComponent(MouseEvent event) { @@ -338,192 +332,190 @@ } protected void updatePageNumber(Integer pageNb, Integer prevPageNb) { - if (pdf != null) { - if (pageNb != null) { - if (prevPageNb != null) { - PDFEditorUIModel.Page p = getModel().getPage(prevPageNb); - for (JPanel panel : p.getNotes()) { - panel.setVisible(false); - } - for (JPanel panel : p.getCrosses()) { - panel.setVisible(false); - } - for (JPanel panel : p.getLines()) { - panel.setVisible(false); - } - for (JPanel panel : p.getHighlighters()) { - panel.setVisible(false); - } + if (pageNb != null) { + if (prevPageNb != null) { + PDFEditorUIModel.Page p = getModel().getPage(prevPageNb); + for (JPanel panel : p.getNotes()) { + panel.setVisible(false); } - - displayPage(pageNb, getModel().getZoom(), getModel().getRotation()); + for (JPanel panel : p.getCrosses()) { + panel.setVisible(false); + } + for (JPanel panel : p.getLines()) { + panel.setVisible(false); + } + for (JPanel panel : p.getHighlighters()) { + panel.setVisible(false); + } } + + displayPage(pageNb, getModel().getZoom(), getModel().getRotation()); } } protected void displayPage(int pageNb, float previousZoom, int previousRotation) { - PDFPage page = pdf.getPage(pageNb); - // create the image - Rectangle2D bBox = page.getBBox(); - Rectangle rect = new Rectangle(0, 0, (int) bBox.getWidth(), - (int) bBox.getHeight()); - float zoom = getModel().getZoom(); - int rotation = getModel().getRotation(); + try { + float zoom = getModel().getZoom(); + int rotation = getModel().getRotation(); - int width = (int) (zoom * rect.width); - int height = (int) (zoom * rect.height); - Image image = page.getImage(width, height, // width & height - rect, // clip rect - null, // null for the ImageObserver - true, // fill background with white - true // block until drawing is done - ); + pdfDecoder.setExtractionMode(0, 0, zoom); + BufferedImage image = pdfDecoder.getPageAsImage(pageNb); - JPanel container = getUI().getContainer(); - Dimension containerSize = new Dimension(rotation % 180 == 0 ? width : height, - rotation % 180 == 0 ? height : width); - container.setPreferredSize(containerSize); - container.setMinimumSize(containerSize); - container.setMaximumSize(containerSize); - container.setSize(containerSize); + int width = (int) (zoom * image.getWidth()); + int height = (int) (zoom * image.getHeight()); - JImagePanel documentPanel = ui.getDocumentPanel(); - documentPanel.setRotation(rotation); - documentPanel.setImage(image); + JPanel container = getUI().getContainer(); + Dimension containerSize = new Dimension(rotation % 180 == 0 ? width : height, + rotation % 180 == 0 ? height : width); + container.setPreferredSize(containerSize); + container.setMinimumSize(containerSize); + container.setMaximumSize(containerSize); + container.setSize(containerSize); - Insets insets = container.getInsets(); - rect = container.getBounds(); + JImagePanel documentPanel = ui.getDocumentPanel(); + documentPanel.setRotation(rotation); + documentPanel.setImage(image); - float zoomRatio = zoom / previousZoom; - int rotationDiff = rotation - previousRotation; + Insets insets = container.getInsets(); + Rectangle rect = container.getBounds(); - PDFEditorUIModel.Page p = getModel().getPage(pageNb); + float zoomRatio = zoom / previousZoom; + int rotationDiff = rotation - previousRotation; - for (PDFEditorNoteUI panel : p.getNotes()) { - panel.setVisible(true); + PDFEditorUIModel.Page p = getModel().getPage(pageNb); - panel.setZoom(zoom); - Rectangle bounds = panel.getBounds(); - int x, y; + for (PDFEditorNoteUI panel : p.getNotes()) { + panel.setVisible(true); - if (rotationDiff == 0) { - x = bounds.x; - y = bounds.y; + panel.setZoom(zoom); + Rectangle bounds = panel.getBounds(); + int x, y; - } else if (rotationDiff == 90 || rotationDiff == -270) { - x = rect.width - bounds.height / 2 - bounds.width / 2 - bounds.y; - y = bounds.x + bounds.width / 2 - bounds.height / 2; + if (rotationDiff == 0) { + x = bounds.x; + y = bounds.y; - } else { - x = bounds.y + bounds.height / 2 - bounds.width / 2; - y = rect.height - bounds.height / 2 - bounds.width / 2 - bounds.x; + } else if (rotationDiff == 90 || rotationDiff == -270) { + x = rect.width - bounds.height / 2 - bounds.width / 2 - bounds.y; + y = bounds.x + bounds.width / 2 - bounds.height / 2; + + } else { + x = bounds.y + bounds.height / 2 - bounds.width / 2; + y = rect.height - bounds.height / 2 - bounds.width / 2 - bounds.x; + } + + panel.setBounds((int) (zoomRatio * x) + insets.left, + (int) (zoomRatio * y) + insets.top, + (int) (zoomRatio * bounds.width), (int) (zoomRatio * bounds.height)); + } - panel.setBounds((int)(zoomRatio * x) + insets.left, - (int)(zoomRatio * y) + insets.top, - (int)(zoomRatio * bounds.width), (int)(zoomRatio * bounds.height)); + boolean orientation180 = Math.abs(rotationDiff) % 180 == 0; - } + for (PDFEditorCrossUI panel : p.getCrosses()) { + panel.setVisible(true); - boolean orientation180 = Math.abs(rotationDiff) % 180 == 0; + Rectangle bounds = panel.getBounds(); - for (PDFEditorCrossUI panel : p.getCrosses()) { - panel.setVisible(true); + int newWidth = orientation180 ? bounds.width : bounds.height; + int newHeight = orientation180 ? bounds.height : bounds.width; - Rectangle bounds = panel.getBounds(); + int x, y; - int newWidth = orientation180 ? bounds.width : bounds.height; - int newHeight = orientation180 ? bounds.height : bounds.width; + if (rotationDiff == 0) { + x = bounds.x; + y = bounds.y; - int x, y; + } else if (rotationDiff == 90 || rotationDiff == -270) { + x = rect.width - newWidth - bounds.y; + y = bounds.x; - if (rotationDiff == 0) { - x = bounds.x; - y = bounds.y; + } else { + x = bounds.y; + y = rect.height - newHeight - bounds.x; + } - } else if (rotationDiff == 90 || rotationDiff == -270) { - x = rect.width - newWidth - bounds.y; - y = bounds.x; + panel.setBounds((int) (zoomRatio * x) + insets.left, + (int) (zoomRatio * y) + insets.top, + (int) (zoomRatio * newWidth), (int) (zoomRatio * newHeight)); - } else { - x = bounds.y; - y = rect.height - newHeight - bounds.x; } - panel.setBounds((int) (zoomRatio * x) + insets.left, - (int) (zoomRatio * y) + insets.top, - (int) (zoomRatio * newWidth), (int) (zoomRatio * newHeight)); + List<PDFEditorLineUI> lines = p.getLines(); + cr.deregisterComponent(lines.toArray(new PDFEditorLineUI[lines.size()])); - } + for (PDFEditorLineUI panel : lines) { + panel.setVisible(true); - List<PDFEditorLineUI> lines = p.getLines(); - cr.deregisterComponent(lines.toArray(new PDFEditorLineUI[lines.size()])); + Rectangle bounds = panel.getBounds(); - for (PDFEditorLineUI panel : lines) { - panel.setVisible(true); + boolean horizontal = panel.isHorizontal(); + panel.setHorizontal(orientation180 ? horizontal : !horizontal); - Rectangle bounds = panel.getBounds(); + int newWidth = orientation180 ? bounds.width : bounds.height; + int newHeight = orientation180 ? bounds.height : bounds.width; - boolean horizontal = panel.isHorizontal(); - panel.setHorizontal(orientation180 ? horizontal : ! horizontal); + int x, y; - int newWidth = orientation180 ? bounds.width : bounds.height; - int newHeight = orientation180 ? bounds.height : bounds.width; + if (rotationDiff == 0) { + x = bounds.x; + y = bounds.y; - int x, y; + } else if (rotationDiff == 90 || rotationDiff == -270) { + x = rect.width - newWidth - bounds.y; + y = bounds.x; - if (rotationDiff == 0) { - x = bounds.x; - y = bounds.y; + } else { + x = bounds.y; + y = rect.height - newHeight - bounds.x; + } - } else if (rotationDiff == 90 || rotationDiff == -270) { - x = rect.width - newWidth - bounds.y; - y = bounds.x; + panel.setBounds((int) (zoomRatio * x) + insets.left, + (int) (zoomRatio * y) + insets.top, + (int) (zoomRatio * newWidth), (int) (zoomRatio * newHeight)); - } else { - x = bounds.y; - y = rect.height - newHeight - bounds.x; + cr.registerComponent(panel.isHorizontal() ? ComponentResizer.DIRECTION_HORIZONTAL : ComponentResizer.DIRECTION_VERTICAL, + panel); } - panel.setBounds((int) (zoomRatio * x) + insets.left, - (int) (zoomRatio * y) + insets.top, - (int) (zoomRatio * newWidth), (int) (zoomRatio * newHeight)); + for (PDFEditorHighlighterUI panel : p.getHighlighters()) { + panel.setVisible(true); - cr.registerComponent(panel.isHorizontal() ? ComponentResizer.DIRECTION_HORIZONTAL : ComponentResizer.DIRECTION_VERTICAL, - panel); - } + Rectangle bounds = panel.getBounds(); - for (PDFEditorHighlighterUI panel : p.getHighlighters()) { - panel.setVisible(true); + int newWidth = orientation180 ? bounds.width : bounds.height; + int newHeight = orientation180 ? bounds.height : bounds.width; - Rectangle bounds = panel.getBounds(); + int x, y; - int newWidth = orientation180 ? bounds.width : bounds.height; - int newHeight = orientation180 ? bounds.height : bounds.width; + if (rotationDiff == 0) { + x = bounds.x; + y = bounds.y; - int x, y; + } else if (rotationDiff == 90 || rotationDiff == -270) { + x = rect.width - newWidth - bounds.y; + y = bounds.x; - if (rotationDiff == 0) { - x = bounds.x; - y = bounds.y; + } else { + x = bounds.y; + y = rect.height - newHeight - bounds.x; + } - } else if (rotationDiff == 90 || rotationDiff == -270) { - x = rect.width - newWidth - bounds.y; - y = bounds.x; + panel.setBounds((int) (zoomRatio * x) + insets.left, + (int) (zoomRatio * y) + insets.top, + (int) (zoomRatio * newWidth), (int) (zoomRatio * newHeight)); - } else { - x = bounds.y; - y = rect.height - newHeight - bounds.x; } - panel.setBounds((int) (zoomRatio * x) + insets.left, - (int) (zoomRatio * y) + insets.top, - (int) (zoomRatio * newWidth), (int) (zoomRatio * newHeight)); + container.updateUI(); + } catch (PdfException e) { + if (log.isErrorEnabled()) { + log.error("error while displaying pdf", e); + } + getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.readPdf.error")); } - - container.updateUI(); } public File convertFileToPdf(AttachmentFile attachmentFile) throws IOException, DocumentException { Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-11-17 16:58:10 UTC (rev 691) +++ trunk/pom.xml 2014-11-18 15:21:43 UTC (rev 692) @@ -111,7 +111,7 @@ <h2Version>1.3.176</h2Version> <guavaVersion>18.0</guavaVersion> - <jaxxVersion>2.17-SNAPSHOT</jaxxVersion> + <jaxxVersion>2.16</jaxxVersion> <!-- do not upgrade to 1.6.5-1 --> <swingXVersion>1.6.4</swingXVersion> <xworkVersion>2.3.16.3</xworkVersion> @@ -642,6 +642,12 @@ <version>1.8.1</version> </dependency> + <dependency> + <groupId>org.jpedal</groupId> + <artifactId>jpedal-lgpl</artifactId> + <version>4.74b27</version> + </dependency> + </dependencies> </dependencyManagement>
participants (1)
-
kmorin@users.forge.codelutin.com