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:
henrikjust 2009-03-08 13:43:50 +00:00
parent 6c7c7cdbf2
commit fe1b3e2fc5
15 changed files with 391 additions and 78 deletions

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.0 (2009-03-02)
* Version 1.0 (2009-03-08)
*
*/
@ -33,7 +33,7 @@ public class ConverterFactory {
// Version information
private static final String VERSION = "1.0 beta";
private static final String DATE = "2008-03-02";
private static final String DATE = "2008-03-08";
/** Return version information
* @return the Writer2LaTeX version in the form

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.0 (2009-02-17)
* Version 1.0 (2009-03-08)
*
*/
@ -120,7 +120,7 @@ public class BibTeXDocument implements Document {
// BibTeX files are plain ascii
OutputStreamWriter osw = new OutputStreamWriter(os,"ASCII");
osw.write("%% This file was converted to BibTeX by Writer2BibTeX ver. "+ConverterFactory.getVersion()+".\n");
osw.write("%% See http://www.hj-gym.dk/~hj/writer2latex for more info.\n");
osw.write("%% See http://writer2latex.sourceforge.net for more info.\n");
osw.write("\n");
Enumeration enumeration = entries.elements();
while (enumeration.hasMoreElements()) {

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.0 (2009-02-17)
* Version 1.0 (2009-03-08)
*
*/
@ -251,8 +251,8 @@ public class DrawConverter extends ConverterHelper {
}
Element frame = getFrame(node);
//String sName = frame.getAttribute(XMLString.DRAW_NAME);
palette.getFieldCv().addTarget(frame,"|graphics",ldp);
String sName = frame.getAttribute(XMLString.DRAW_NAME);
palette.getFieldCv().addTarget(sName,"|graphic",ldp);
String sAnchor = frame.getAttribute(XMLString.TEXT_ANCHOR_TYPE);
// TODO: Recognize Jex equations (needs further testing of Jex)
@ -421,8 +421,8 @@ public class DrawConverter extends ConverterHelper {
private void handleDrawTextBox(Element node, LaTeXDocumentPortion ldp, Context oc) {
Element frame = getFrame(node);
//String sName = frame.getAttribute(XMLString.DRAW_NAME);
palette.getFieldCv().addTarget(frame,"|frame",ldp);
String sName = frame.getAttribute(XMLString.DRAW_NAME);
palette.getFieldCv().addTarget(sName,"|frame",ldp);
String sAnchor = frame.getAttribute(XMLString.TEXT_ANCHOR_TYPE);
//if (oc.isInFrame() || "as-char".equals(sAnchor)) {
if ("as-char".equals(sAnchor)) {

View file

@ -16,11 +16,11 @@
* 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 (2008-12-15)
* Version 1.0 (2009-03-08)
*
*/
@ -760,7 +760,7 @@ public class DrawConverter extends ConverterHelper {
// We thus have to subtract the borders and padding to get the correct width
StyleWithProperties style = ofr.getFrameStyle(node.getAttribute(XMLString.DRAW_STYLE_NAME));
String sWidth = Misc.getAttribute(node,XMLString.SVG_WIDTH);
String sWidth = node.getAttribute(XMLString.SVG_WIDTH);
if (sWidth.length()>0) {
if (style!=null) {
// Subtract padding
@ -782,7 +782,7 @@ public class DrawConverter extends ConverterHelper {
props.addValue("width",scale(sWidth));
}
String sHeight = Misc.getAttribute(node,XMLString.SVG_HEIGHT);
String sHeight = node.getAttribute(XMLString.SVG_HEIGHT);
if (sHeight.length()>0 && !bOnlyWidth) {
if (style!=null) {
// Subtract padding

View file

@ -16,11 +16,11 @@
* 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 (2008-12-16)
* Version 1.0 (2009-03-05)
*
*/
@ -81,6 +81,20 @@ public class L10n {
case DOCUMENT: return "Document";
}
}
if (sLocale.startsWith("es")) { // spanish
switch (nString) {
case UP: return "Arriba";
case FIRST : return "Primero";
case PREVIOUS : return "Previo";
case NEXT : return "Siguiente";
case LAST : return "\u00daltimo";
case CONTENTS : return "Contenido";
case INDEX : return "\u00cdndice";
case HOME : return "Inicio";
case DIRECTORY: return "Directorio";
case DOCUMENT: return "Documento";
}
}
if (sLocale.startsWith("da")) { // danish
switch (nString) {
case UP: return "Op";