Some fixes for 1.0 beta
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@8 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
6c7c7cdbf2
commit
fe1b3e2fc5
15 changed files with 391 additions and 78 deletions
|
@ -0,0 +1,87 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* EPSCleaner.java
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2009 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.0 (2009-03-09)
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
/** This class removes redundant binary information from EPS files created by OOo.
|
||||
* See the issue http://qa.openoffice.org/issues/show_bug.cgi?id=25256
|
||||
* According to this message http://markmail.org/message/dc6rprmtktxuq35v
|
||||
* on dev@openoffice.org the binary data is an EPSI preview in TIFF format
|
||||
* TODO: Is it possible to avoid this export?
|
||||
*/
|
||||
public class EPSCleaner {
|
||||
|
||||
// Signatures for start and end in eps
|
||||
private byte[] psStart;
|
||||
private byte[] psEnd;
|
||||
|
||||
public EPSCleaner() {
|
||||
try {
|
||||
psStart = "%!PS-Adobe".getBytes("US-ASCII");
|
||||
psEnd = "%%EOF".getBytes("US-ASCII");
|
||||
}
|
||||
catch (java.io.UnsupportedEncodingException ex) {
|
||||
// US-ASCII *is* supported :-)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
public byte[] cleanEps(byte[] blob) {
|
||||
int n = blob.length;
|
||||
|
||||
int nStart = 0;
|
||||
for (int i=0; i<n; i++) {
|
||||
if (match(blob,psStart,i)) {
|
||||
nStart=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int nEnd = n;
|
||||
for (int i=nStart; i<n; i++) {
|
||||
if (match(blob,psEnd,i)) {
|
||||
nEnd=i+psEnd.length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
byte[] newBlob = new byte[nEnd-nStart];
|
||||
System.arraycopy(blob,nStart,newBlob,0,nEnd-nStart);
|
||||
return newBlob;
|
||||
}
|
||||
|
||||
private boolean match(byte[] blob, byte[] sig, int nStart) {
|
||||
int n = sig.length;
|
||||
if (nStart+n>=blob.length) { return false; }
|
||||
for (int i=0; i<n; i++) {
|
||||
if (blob[nStart+i]!=sig[i]) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -16,12 +16,14 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2008 by Henrik Just
|
||||
* Copyright: 2002-2009 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.0 (2009-03-08)
|
||||
*/
|
||||
|
||||
// Version 1.0 (2008-11-22)
|
||||
//
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
|
@ -51,12 +53,9 @@ import writer2latex.api.MIMETypes;
|
|||
*/
|
||||
public class GraphicConverterImpl1 implements GraphicConverter {
|
||||
|
||||
// Signatures for start and end in exp
|
||||
private byte[] psStart;
|
||||
private byte[] psEnd;
|
||||
|
||||
|
||||
private XGraphicProvider xGraphicProvider;
|
||||
|
||||
private EPSCleaner epsCleaner;
|
||||
|
||||
public GraphicConverterImpl1(XComponentContext xComponentContext) {
|
||||
try {
|
||||
|
@ -69,13 +68,8 @@ public class GraphicConverterImpl1 implements GraphicConverter {
|
|||
System.err.println("Failed to get XGraphicProvider object");
|
||||
xGraphicProvider = null;
|
||||
}
|
||||
try {
|
||||
psStart = "%!PS-Adobe".getBytes("US-ASCII");
|
||||
psEnd = "%%EOF".getBytes("US-ASCII");
|
||||
}
|
||||
catch (java.io.UnsupportedEncodingException ex) {
|
||||
// US-ASCII *is* supported :-)
|
||||
}
|
||||
|
||||
epsCleaner = new EPSCleaner();
|
||||
|
||||
}
|
||||
|
||||
|
@ -136,7 +130,7 @@ public class GraphicConverterImpl1 implements GraphicConverter {
|
|||
xTarget.closeOutput();
|
||||
xTarget.flush();
|
||||
if (MIMETypes.EPS.equals(sTargetMime)) {
|
||||
return cleanEps(xTarget.getBuffer());
|
||||
return epsCleaner.cleanEps(xTarget.getBuffer());
|
||||
}
|
||||
else {
|
||||
return xTarget.getBuffer();
|
||||
|
@ -156,39 +150,5 @@ public class GraphicConverterImpl1 implements GraphicConverter {
|
|||
}
|
||||
}
|
||||
|
||||
private byte[] cleanEps(byte[] blob) {
|
||||
int n = blob.length;
|
||||
|
||||
int nStart = 0;
|
||||
for (int i=0; i<n; i++) {
|
||||
if (match(blob,psStart,i)) {
|
||||
nStart=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int nEnd = n;
|
||||
for (int i=nStart; i<n; i++) {
|
||||
if (match(blob,psEnd,i)) {
|
||||
nEnd=i+psEnd.length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
byte[] newBlob = new byte[nEnd-nStart];
|
||||
System.arraycopy(blob,nStart,newBlob,0,nEnd-nStart);
|
||||
return newBlob;
|
||||
}
|
||||
|
||||
private boolean match(byte[] blob, byte[] sig, int nStart) {
|
||||
int n = sig.length;
|
||||
if (nStart+n>=blob.length) { return false; }
|
||||
for (int i=0; i<n; i++) {
|
||||
if (blob[nStart+i]!=sig[i]) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.0 (2009-03-02)
|
||||
* Version 1.0 (2009-03-08)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -60,6 +60,7 @@ public class GraphicConverterImpl2 implements GraphicConverter {
|
|||
private XComponentContext xComponentContext;
|
||||
private Hashtable importFilter;
|
||||
private Hashtable exportFilter;
|
||||
private EPSCleaner epsCleaner;
|
||||
|
||||
public GraphicConverterImpl2(XComponentContext xComponentContext) {
|
||||
this.xComponentContext = xComponentContext;
|
||||
|
@ -87,6 +88,8 @@ public class GraphicConverterImpl2 implements GraphicConverter {
|
|||
exportFilter.put(MIMETypes.TIFF,"draw_tif_Export");
|
||||
exportFilter.put(MIMETypes.WMF,"draw_wmf_Export");
|
||||
exportFilter.put(MIMETypes.PDF,"draw_pdf_Export");
|
||||
|
||||
epsCleaner = new EPSCleaner();
|
||||
}
|
||||
|
||||
public boolean supportsConversion(String sSourceMime, String sTargetMime, boolean bCrop, boolean bResize) {
|
||||
|
@ -109,8 +112,6 @@ public class GraphicConverterImpl2 implements GraphicConverter {
|
|||
// Open a hidden sdraw document
|
||||
XMultiComponentFactory xMCF = xComponentContext.getServiceManager();
|
||||
|
||||
org.openoffice.da.comp.w2lcommon.helper.MessageBox msgBox = new org.openoffice.da.comp.w2lcommon.helper.MessageBox(xComponentContext);
|
||||
|
||||
try {
|
||||
// Load the graphic into a new draw document as xDocument
|
||||
// using a named filter
|
||||
|
@ -119,7 +120,6 @@ org.openoffice.da.comp.w2lcommon.helper.MessageBox msgBox = new org.openoffice.d
|
|||
|
||||
XComponentLoader xComponentLoader = (XComponentLoader)
|
||||
UnoRuntime.queryInterface(XComponentLoader.class, desktop);
|
||||
//msgBox.showMessage("Graphics","Trying to load using filter name "+importFilter.get(sSourceMime));
|
||||
|
||||
PropertyValue[] fileProps = new PropertyValue[3];
|
||||
fileProps[0] = new PropertyValue();
|
||||
|
@ -187,30 +187,28 @@ org.openoffice.da.comp.w2lcommon.helper.MessageBox msgBox = new org.openoffice.d
|
|||
|
||||
byte[] result = outputStream.getBuffer();
|
||||
xDocument.dispose();
|
||||
|
||||
return result;
|
||||
|
||||
if (MIMETypes.EPS.equals(sTargetMime)) {
|
||||
return epsCleaner.cleanEps(result);
|
||||
}
|
||||
else {
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
catch (com.sun.star.beans.PropertyVetoException e) {
|
||||
msgBox.showMessage("Exception",e.toString());
|
||||
}
|
||||
catch (com.sun.star.beans.UnknownPropertyException e) {
|
||||
msgBox.showMessage("Exception",e.toString());
|
||||
}
|
||||
catch (com.sun.star.io.IOException e) {
|
||||
msgBox.showMessage("Exception",e.toString());
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException e) {
|
||||
msgBox.showMessage("Exception",e.toString());
|
||||
}
|
||||
catch (com.sun.star.lang.IndexOutOfBoundsException e) {
|
||||
msgBox.showMessage("Exception",e.toString());
|
||||
}
|
||||
catch (com.sun.star.lang.WrappedTargetException e) {
|
||||
msgBox.showMessage("Exception",e.toString());
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
msgBox.showMessage("Exception",e.toString());
|
||||
}
|
||||
|
||||
// Conversion failed, for whatever reason
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue