Menu

Patch for grouped images export in latex

sdaau
2010-02-15
2013-05-28
  • sdaau

    sdaau - 2010-02-15

    Hi,

    I don't know whether (or where) one can submit patches - but I have documents with plenty of grouped images, which do not export with current writer2latex, because for latex export the group (draw:g) element is not handled.

    As there is already a function handling groups in writer2latex/xhtml/DrawConverter.java, I simply copied that function to writer2latex/latex/DrawConverter.java, slightly modified. It outputs commented commented \begin{group} and \end{group} statements when groups are encountered, to facilitate easier changes in the latex code to, say, subfig.

    Hope some may find this useful until that part of the export fully works :)  

    ltxGroupPatch_2010feb15.diff:

    > Index: source/java/writer2latex/api/ConverterFactory.java

    -- source/java/writer2latex/api/ConverterFactory.java (revision 44)
    +++ source/java/writer2latex/api/ConverterFactory.java (working copy)
    @@ -32,8 +32,8 @@
    public class ConverterFactory {

         // Version information
    -    private static final String VERSION = "1.1.1";
    -    private static final String DATE = "2009-12-15";
    +    private static final String VERSION = "1.1.1.1";
    +    private static final String DATE = "2010-02-15";

         /** Return version information
          *  @return the Writer2LaTeX version in the form
    Index: source/java/writer2latex/latex/DrawConverter.java
    ===================================================================
    -- source/java/writer2latex/latex/DrawConverter.java (revision 44)
    +++ source/java/writer2latex/latex/DrawConverter.java (working copy)
    @@ -31,7 +31,7 @@

    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    -//import org.w3c.dom.Node;
    +import org.w3c.dom.Node; //was commented, allowing it for group

    import writer2latex.xmerge.EmbeddedObject;
    import writer2latex.xmerge.EmbeddedXMLObject;
    @@ -131,6 +131,9 @@
                 // OpenDocument: Get the actual draw element in the frame
                 handleDrawElement(Misc.getFirstChildElement(node),ldp,oc);
             }
    +        else if (sName.equals(XMLString.DRAW_G)) { // added from writer2latex/xhtml/DrawConverter.java
    +            handleDrawGroup(node,ldp,oc);
    +        }
             else {
                 // Other drawing objects (eg. shapes) are currently not supported
                 ldp.append("");
    @@ -479,6 +482,33 @@

         }

    +    // copy from writer2latex/xhtml/DrawConverter.java
    +    private void handleDrawGroup(Element node, LaTeXDocumentPortion ldp, Context oc) { //(Element onode, Element hnodeBlock, Element hnodeInline, int nMode) {
    +        // TODO: style-name and z-index should be transferred to children
    + Element nnode = node; // getFrame(node); // (Node) node;
    + String sX = Misc.truncateLength(nnode.getAttribute(XMLString.SVG_X));
    + String sY = Misc.truncateLength(nnode.getAttribute(XMLString.SVG_Y));
    + String sWidth = Misc.truncateLength(nnode.getAttribute(XMLString.SVG_WIDTH));
    + String sHeight = Misc.truncateLength(nnode.getAttribute(XMLString.SVG_HEIGHT));
    + String zInd = Misc.truncateLength(nnode.getAttribute("draw:z-index"));
    + // if (sWidth!=null) { options.addValue("width="+sWidth); }
    + // if (sHeight!=null) { options.addValue("height="+sHeight); }
    + String sAtt = java.util.Arrays.asList(nnode.getAttributes()).toString(); //does not show contents, only .dom.AttributeMap@87816d
    + ldp.nl();
    + ldp.append("%\\begin{group}");  // .append(sAtt)
    + ldp.nl();
    +        Node child = node.getFirstChild(); // Element child = Misc.getFirstChildElement(node); // Node child = onode.getFirstChild();
    +        while (child!=null) {
    +            if (OfficeReader.isDrawElement(child)) {
    +                handleDrawElement((Element) child, ldp, oc); // hnodeBlock, hnodeInline, nMode);
    +            }
    +            child = child.getNextSibling();
    +        }
    + flushFloatingFrames(ldp, oc); // otherwise it will go: begin, then end, then images.
    + ldp.nl();
    + ldp.append("%\\end{group}");
    + ldp.nl();
    +    }
         //-------------------------------------------------
         //handle any pending floating frames
        
    @@ -500,4 +530,4 @@
             floatingFrames.clear();
         }

    -}
    \ No newline at end of file
    +}
    Index: build.xml
    ===================================================================
    -- build.xml (revision 44)
    +++ build.xml (working copy)
    @@ -9,8 +9,8 @@

         <!- set this property to the location of your SO/OOo installation ->
    <!-<property name="OFFICE_HOME" location="c:/Program Files/OpenOffice.org 2.4"/>->
    - <property name="OFFICE_HOME" location="/opt/openoffice.org/basis3.0" />
    - <property name="URE_HOME" location="/opt/openoffice.org/ure" />
    + <property name="OFFICE_HOME" location="/usr/lib/openoffice/basis3.1" />
    + <property name="URE_HOME" location="/usr/lib/ure" />

         <description>writer2latex - build file</description>

     
  • Henrik Just

    Henrik Just - 2010-02-26

    Hi!

    Thanks a lot for your patch!
    I will evaluate it and add support for grouped images to the next release of Writer2LaTeX.

    Best regards
    Henrik

     

Log in to post a comment.