diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8c907c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*/target/ +*/bin +.DS_Store diff --git a/de.vonloesch.pdf4eclipse.feature/feature.xml b/de.vonloesch.pdf4eclipse.feature/feature.xml index d5fa6d4..0191832 100644 --- a/de.vonloesch.pdf4eclipse.feature/feature.xml +++ b/de.vonloesch.pdf4eclipse.feature/feature.xml @@ -1,8 +1,8 @@ @@ -131,12 +131,6 @@ This Agreement is governed by the laws of the State of New York and the intellec version="0.0.0" unpack="false"/> - - + + 4.0.0 + + parent + de.vonloesch.pdf4eclipse + 1.0.1-SNAPSHOT + ../pom.xml + + de.vonloesch.pdf4eclipse + de.vonloesch.pdf4eclipse.feature + 1.1.0-SNAPSHOT + eclipse-feature + diff --git a/de.vonloesch.pdf4eclipse.help/META-INF/MANIFEST.MF b/de.vonloesch.pdf4eclipse.help/META-INF/MANIFEST.MF index 6358441..3cb2c51 100644 --- a/de.vonloesch.pdf4eclipse.help/META-INF/MANIFEST.MF +++ b/de.vonloesch.pdf4eclipse.help/META-INF/MANIFEST.MF @@ -2,5 +2,5 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Help Bundle-SymbolicName: de.vonloesch.pdf4eclipse.help; singleton:=true -Bundle-Version: 1.1.0 +Bundle-Version: 1.1.0.qualifier Require-Bundle: org.eclipse.help diff --git a/de.vonloesch.pdf4eclipse.help/pom.xml b/de.vonloesch.pdf4eclipse.help/pom.xml new file mode 100644 index 0000000..50d8a80 --- /dev/null +++ b/de.vonloesch.pdf4eclipse.help/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + + parent + de.vonloesch.pdf4eclipse + 1.0.1-SNAPSHOT + ../pom.xml + + + de.vonloesch.pdf4eclipse.help + eclipse-plugin + 1.1.0-SNAPSHOT + \ No newline at end of file diff --git a/de.vonloesch.pdf4eclipse.p2repository/.project b/de.vonloesch.pdf4eclipse.p2repository/.project new file mode 100644 index 0000000..eb6708b --- /dev/null +++ b/de.vonloesch.pdf4eclipse.p2repository/.project @@ -0,0 +1,17 @@ + + + de.vonloesch.pdf4eclipse.p2repository + + + + + + org.eclipse.pde.UpdateSiteBuilder + + + + + + org.eclipse.pde.UpdateSiteNature + + diff --git a/de.vonloesch.pdf4eclipse.p2repository/category.xml b/de.vonloesch.pdf4eclipse.p2repository/category.xml new file mode 100644 index 0000000..68b27e0 --- /dev/null +++ b/de.vonloesch.pdf4eclipse.p2repository/category.xml @@ -0,0 +1,11 @@ + + + + + + + + PDF4Eclipse Category + + + diff --git a/de.vonloesch.pdf4eclipse.p2repository/pom.xml b/de.vonloesch.pdf4eclipse.p2repository/pom.xml new file mode 100644 index 0000000..35bd435 --- /dev/null +++ b/de.vonloesch.pdf4eclipse.p2repository/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + parent + de.vonloesch.pdf4eclipse + 1.0.1-SNAPSHOT + ../pom.xml + + de.vonloesch.pdf4eclipse + de.vonloesch.pdf4eclipse.p2repository + 1.0.0-SNAPSHOT + eclipse-repository + + diff --git a/de.vonloesch.pdf4eclipse/.classpath b/de.vonloesch.pdf4eclipse/.classpath index 0cbffb3..1e35e0f 100644 --- a/de.vonloesch.pdf4eclipse/.classpath +++ b/de.vonloesch.pdf4eclipse/.classpath @@ -1,9 +1,9 @@ - - - - - - - - - + + + + + + + + + diff --git a/de.vonloesch.pdf4eclipse/.gitignore b/de.vonloesch.pdf4eclipse/.gitignore new file mode 100644 index 0000000..5e56e04 --- /dev/null +++ b/de.vonloesch.pdf4eclipse/.gitignore @@ -0,0 +1 @@ +/bin diff --git a/de.vonloesch.pdf4eclipse/.project b/de.vonloesch.pdf4eclipse/.project index b3c6af0..e2531de 100644 --- a/de.vonloesch.pdf4eclipse/.project +++ b/de.vonloesch.pdf4eclipse/.project @@ -1,28 +1,34 @@ - - - de.vonloesch.pdf4Eclipse - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - + + + de.vonloesch.pdf4Eclipse + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/de.vonloesch.pdf4eclipse/.settings/org.eclipse.m2e.core.prefs b/de.vonloesch.pdf4eclipse/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..ec12694 --- /dev/null +++ b/de.vonloesch.pdf4eclipse/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,5 @@ +#Wed Feb 08 14:49:27 PST 2012 +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/de.vonloesch.pdf4eclipse/OSGI-INF/l10n/bundle.properties b/de.vonloesch.pdf4eclipse/OSGI-INF/l10n/bundle.properties index 9f7b588..5019032 100644 --- a/de.vonloesch.pdf4eclipse/OSGI-INF/l10n/bundle.properties +++ b/de.vonloesch.pdf4eclipse/OSGI-INF/l10n/bundle.properties @@ -8,9 +8,11 @@ command.description.0 = Set the zoom level command.name.0 = Zoom commandParameter.name = zoomlevel command.name.1 = Toggle highlight +command.name.2 = Toggle auto-trimming command.tooltip = Zoom out command.tooltip.0 = Fit page to window command.tooltip.1 = Fit page to window width command.tooltip.2 = Zoom in command.tooltip.3 = Toggle link highlighting +command.tooltip.4 = Trim Page Margins context.name = PDF viewer \ No newline at end of file diff --git a/de.vonloesch.pdf4eclipse/build.properties b/de.vonloesch.pdf4eclipse/build.properties index 16e1348..da2be38 100644 --- a/de.vonloesch.pdf4eclipse/build.properties +++ b/de.vonloesch.pdf4eclipse/build.properties @@ -6,4 +6,5 @@ bin.includes = plugin.xml,\ icons/,\ lib/,\ OSGI-INF/l10n/bundle.properties - + lib/jbig2.jar,\ + lib/PDFrenderer.jar diff --git a/de.vonloesch.pdf4eclipse/icons/autotrim.png b/de.vonloesch.pdf4eclipse/icons/autotrim.png new file mode 100644 index 0000000..720a56f Binary files /dev/null and b/de.vonloesch.pdf4eclipse/icons/autotrim.png differ diff --git a/de.vonloesch.pdf4eclipse/lib/jbig2.jar b/de.vonloesch.pdf4eclipse/lib/jbig2.jar new file mode 100644 index 0000000..23ef424 Binary files /dev/null and b/de.vonloesch.pdf4eclipse/lib/jbig2.jar differ diff --git a/de.vonloesch.pdf4eclipse/plugin.xml b/de.vonloesch.pdf4eclipse/plugin.xml index fad2752..6b0110b 100644 --- a/de.vonloesch.pdf4eclipse/plugin.xml +++ b/de.vonloesch.pdf4eclipse/plugin.xml @@ -56,6 +56,27 @@ + + + + + + + + + + @@ -133,7 +154,7 @@ @@ -149,7 +170,7 @@ @@ -190,6 +211,18 @@ + + + + + + diff --git a/de.vonloesch.pdf4eclipse/pom.xml b/de.vonloesch.pdf4eclipse/pom.xml new file mode 100644 index 0000000..76f4d29 --- /dev/null +++ b/de.vonloesch.pdf4eclipse/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + + parent + de.vonloesch.pdf4eclipse + 1.0.1-SNAPSHOT + ../pom.xml + + + de.vonloesch.pdf4Eclipse + eclipse-plugin + 1.1.0-SNAPSHOT + \ No newline at end of file diff --git a/de.vonloesch.pdf4eclipse/src/de/vonloesch/pdf4eclipse/PDFPageViewer.java b/de.vonloesch.pdf4eclipse/src/de/vonloesch/pdf4eclipse/PDFPageViewer.java index f6b5c18..a24bb27 100644 --- a/de.vonloesch.pdf4eclipse/src/de/vonloesch/pdf4eclipse/PDFPageViewer.java +++ b/de.vonloesch.pdf4eclipse/src/de/vonloesch/pdf4eclipse/PDFPageViewer.java @@ -7,6 +7,7 @@ * * Contributors: * Boris von Loesch - initial API and implementation + * Robert Bamler - auto-trimming of page margins ******************************************************************************/ package de.vonloesch.pdf4eclipse; @@ -16,6 +17,7 @@ import java.awt.geom.Rectangle2D.Double; import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; +import java.awt.image.DataBufferInt; import java.awt.image.DirectColorModel; import java.awt.image.IndexColorModel; import java.awt.image.WritableRaster; @@ -39,6 +41,7 @@ import org.eclipse.swt.widgets.Display; import de.vonloesch.pdf4eclipse.editors.PDFEditor; +import de.vonloesch.pdf4eclipse.editors.handlers.ToggleAutoTrimHandler; import de.vonloesch.pdf4eclipse.editors.handlers.ToggleLinkHighlightHandler; import de.vonloesch.pdf4eclipse.model.IPDFLinkAnnotation; import de.vonloesch.pdf4eclipse.model.IPDFPage; @@ -72,6 +75,11 @@ public class PDFPageViewer extends Canvas implements PaintListener, IPreferenceC private float zoomFactor; + private boolean autoTrimOn = true; + private Point trimOffset = new Point(0, 0); + private float horizontalTrimFactor = 1.0f; + private float verticalTrimFactor = 1.0f; + //private org.eclipse.swt.graphics.Image swtImage; /** @@ -178,6 +186,7 @@ public void run() { prefs.addPreferenceChangeListener(this); highlightLinks = prefs.getBoolean(ToggleLinkHighlightHandler.PREF_LINKHIGHTLIGHT_ID, true); + autoTrimOn = prefs.getBoolean(ToggleAutoTrimHandler.PREF_AUTOTRIM_ID, true); } @@ -299,13 +308,17 @@ public void showPage(IPDFPage page) { highlight = null; boolean resize = false; - int newW = Math.round(zoomFactor*page.getWidth()); - int newH = Math.round(zoomFactor*page.getHeight()); + // always round _down_ so that the fit-to-screen commands work properly + int newW = (int) (zoomFactor*page.getWidth()); + int newH = (int) (zoomFactor*page.getHeight()); Point sz = getSize(); if (sz.x == 0 || sz.y == 0) return; currentImage = page.getImage(newH, newW); + if (autoTrimOn) { + trimCurrentImage(); + } newW = currentImage.getWidth(null); newH = currentImage.getHeight(null); @@ -329,16 +342,97 @@ public void showPage(IPDFPage page) { } } + private void trimCurrentImage() { + if (currentImage==null) + return; + + int origw = currentImage.getWidth(null); + int origh = currentImage.getHeight(null); + if (origw<1 || origh<1) + return; + + BufferedImage img = new BufferedImage(origw, origh, BufferedImage.TYPE_INT_ARGB); + img.getGraphics().drawImage(currentImage, 0, 0, origw, origh, 0, 0, origw, origh, null); + + int[] srcbuf = ((DataBufferInt) img.getRaster().getDataBuffer()).getData(); + + // detect upper margin + int trimy1 = origh; + int referenceColor = srcbuf[0]; + for (int i=0; i!=srcbuf.length; i++) { + if (srcbuf[i] != referenceColor) { + trimy1 = i/origw; + break; + } + } + + // detect lower margin + int trimy2 = 0; + referenceColor = srcbuf[srcbuf.length-1]; + for (int i=srcbuf.length-1; i!=trimy1*origw-1; i--) { + if (srcbuf[i] != referenceColor) { + trimy2 = i/origw + 1; + break; + } + } + + // detect left margin + int trimx1 = 0; + referenceColor = srcbuf[0]; + int offset = trimy1*origw; + int end = trimy2*origw; + trimx1loop: + while (trimx1 != origw) { + for (int i=offset+trimx1; i