[Libreoffice-commits] .: 8 commits - oox/source

Jan Holesovsky kendy at kemper.freedesktop.org
Thu Nov 25 12:12:32 PST 2010


 oox/source/xls/excelfilter.cxx |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

New commits:
commit 95eade53cdaa81ff0680cc27daeef661ab4ab9ac
Merge: 00f84d6... 6f6f83d...
Author: Jan Holesovsky <kendy at suse.cz>
Date:   Thu Nov 25 20:59:11 2010 +0100

    Merge branch 'master' of ssh://git.freedesktop.org/git/libreoffice/filters

commit 00f84d6e2f8bd253a86a2c2986c3cf6c10232548
Merge: 5dffb23... 6998013...
Author: Jan Holesovsky <kendy at suse.cz>
Date:   Thu Nov 25 14:26:56 2010 +0100

    Merge remote branch 'origin/libreoffice-3-3'

commit 6998013adf9b17c4c20ea792e7777c609fc044c6
Author: David Tardon <dtardon at redhat.com>
Date:   Wed Nov 24 13:28:09 2010 +0100

    add missing xsl:when start tag
    (cherry picked from commit a720d902988a7fc8e6cbc6e6ab8f82553a56318c)

diff --git a/filter/source/xslt/odf2xhtml/export/xhtml/body.xsl b/filter/source/xslt/odf2xhtml/export/xhtml/body.xsl
index 70cb8b7..3e030ba 100644
--- a/filter/source/xslt/odf2xhtml/export/xhtml/body.xsl
+++ b/filter/source/xslt/odf2xhtml/export/xhtml/body.xsl
@@ -1827,6 +1827,7 @@
 			<xsl:if test="$listStyle/text:list-style/text:list-level-style-number">
 				<xsl:choose>
 					<xsl:when test="$isListHeader">0</xsl:when>
+                    <xsl:when test="$isEmptyList">
 						<!--  An empty list item (no text:h/text:p as child), will not count as item and does not increment the count.  -->
 						<xsl:variable name="tempItemNumber">
 							<xsl:choose>
commit d2d7d4e4141d23d36a49c976b73edcef8cecc5a3
Author: Noel Power <noel.power at novell.com>
Date:   Mon Nov 22 14:20:56 2010 +0000

    remove debugging artifact

diff --git a/oox/source/vml/vmlshapecontext.cxx b/oox/source/vml/vmlshapecontext.cxx
index f8042e3..052577b 100644
--- a/oox/source/vml/vmlshapecontext.cxx
+++ b/oox/source/vml/vmlshapecontext.cxx
@@ -241,7 +241,6 @@ ContextHandlerRef ShapeTypeContext::onCreateContext( sal_Int32 nElement, const A
             mrTypeModel.maFillModel.moRotate = lclDecodeBool( rAttribs, XML_rotate );
         break;
         case VML_TOKEN( imagedata ):
-            mydump( rAttribs );
             mrTypeModel.moGraphicPath = decodeFragmentPath( rAttribs, R_TOKEN( id ) );
             mrTypeModel.moGraphicTitle = rAttribs.getString( O_TOKEN( title ) );
         break;
commit 588a5adeca36921cb23605d896b33f2b3de1345d
Author: Noel Power <noel.power at novell.com>
Date:   Mon Nov 22 12:02:41 2010 +0000

    fix for n#648731 imagedata attribute not imported correctly

diff --git a/oox/source/vml/vmlshapecontext.cxx b/oox/source/vml/vmlshapecontext.cxx
index 4818c20..f8042e3 100644
--- a/oox/source/vml/vmlshapecontext.cxx
+++ b/oox/source/vml/vmlshapecontext.cxx
@@ -241,7 +241,8 @@ ContextHandlerRef ShapeTypeContext::onCreateContext( sal_Int32 nElement, const A
             mrTypeModel.maFillModel.moRotate = lclDecodeBool( rAttribs, XML_rotate );
         break;
         case VML_TOKEN( imagedata ):
-            mrTypeModel.moGraphicPath = decodeFragmentPath( rAttribs, O_TOKEN( relid ) );
+            mydump( rAttribs );
+            mrTypeModel.moGraphicPath = decodeFragmentPath( rAttribs, R_TOKEN( id ) );
             mrTypeModel.moGraphicTitle = rAttribs.getString( O_TOKEN( title ) );
         break;
     }
commit 8df6a51090ad41cad7c0906b166fe3c6f045bf50
Author: Muthu Subramanian K <sumuthu at novell.com>
Date:   Mon Nov 22 15:55:48 2010 +0530

    Missing call to importDocumentProperties() n#655194

diff --git a/oox/source/xls/excelfilter.cxx b/oox/source/xls/excelfilter.cxx
index b5b3dc6..1285029 100644
--- a/oox/source/xls/excelfilter.cxx
+++ b/oox/source/xls/excelfilter.cxx
@@ -129,7 +129,12 @@ bool ExcelFilter::importDocument() throw()
         return false;
         
     WorkbookHelperRoot aHelper( *this );
-    return aHelper.isValid() && importFragment( new OoxWorkbookFragment( aHelper, aWorkbookPath ) );
+    if( aHelper.isValid() && importFragment( new OoxWorkbookFragment( aHelper, aWorkbookPath ) ) )
+    {
+        importDocumentProperties();
+        return true;
+    }
+    return false;
 }
 
 bool ExcelFilter::exportDocument() throw()
commit 1550e55f116cbf412c60bc2b8970b6ae320e7647
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Wed Nov 17 15:35:38 2010 +0100

    some writerperfect cleanup

diff --git a/writerperfect/source/wpgimp/OdgExporter.cxx b/writerperfect/source/wpgimp/OdgExporter.cxx
deleted file mode 100644
index 36d1394..0000000
--- a/writerperfect/source/wpgimp/OdgExporter.cxx
+++ /dev/null
@@ -1,513 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* libwpg
- * Copyright (C) 2006 Ariya Hidayat (ariya at kde.org)
- * Copyright (C) 2006-2007 Fridrich Strba (fridrich.strba at bluewin.ch)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA  02111-1301 USA
- *
- * For further information visit http://libwpg.sourceforge.net
- */
-
-/* "This product is not manufactured, approved, or supported by
- * Corel Corporation or Corel Corporation Limited."
- */
-
-#include "OdgExporter.hxx"
-#include "filter/DocumentElement.hxx"
-#include "filter/DocumentHandler.hxx"
-#include <rtl/math.hxx>
-
-
-OdgExporter::OdgExporter(DocumentHandler *pHandler):
-    mpHandler(pHandler),
-    m_fillRule(AlternatingFill),
-    m_gradientIndex(1),
-    m_dashIndex(1),
-    m_styleIndex(1)
-{
-}
-
-OdgExporter::~OdgExporter()
-{
-}
-
-void OdgExporter::startDocument(double width, double height)
-{
-    m_gradientIndex = 1;
-    m_dashIndex = 1;
-    m_styleIndex = 1;
-
-    mpHandler->startDocument();
-    TagOpenElement tmpOfficeDocumentContent("office:document");
-    tmpOfficeDocumentContent.addAttribute("xmlns:office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0");
-    tmpOfficeDocumentContent.addAttribute("xmlns:style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
-    tmpOfficeDocumentContent.addAttribute("xmlns:text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0");
-    tmpOfficeDocumentContent.addAttribute("xmlns:draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0");
-    tmpOfficeDocumentContent.addAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");
-    tmpOfficeDocumentContent.addAttribute("xmlns:svg", "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0");
-    tmpOfficeDocumentContent.addAttribute("xmlns:fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
-    tmpOfficeDocumentContent.addAttribute("office:version", "1.0");
-    tmpOfficeDocumentContent.write(mpHandler);
-
-    TagOpenElement("office:styles").write(mpHandler);
-    TagCloseElement("office:styles").write(mpHandler);
-
-    TagOpenElement("office:automatic-styles").write(mpHandler);
-
-    TagOpenElement tmpStylePageLayoutOpenElement("style:page-layout");
-    tmpStylePageLayoutOpenElement.addAttribute("style:name", "PM0");
-    tmpStylePageLayoutOpenElement.write(mpHandler);
-
-    TagOpenElement tmpStylePageLayoutPropertiesOpenElement("style:page-layout-properties");
-    tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-top", "0cm");
-    tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-bottom", "0cm");
-    tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-left", "0cm");
-    tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:margin-right", "0cm");
-    WPXString sValue;
-    sValue = doubleToString(2.54 * width); sValue.append("cm");
-    tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:page-width", sValue);
-    sValue = doubleToString(2.54 * height); sValue.append("cm");
-    tmpStylePageLayoutPropertiesOpenElement.addAttribute("fo:page-height", sValue);
-    tmpStylePageLayoutPropertiesOpenElement.addAttribute("style:print-orientation", "portrait");
-    tmpStylePageLayoutPropertiesOpenElement.write(mpHandler);
-
-    TagCloseElement("style:page-layout-properties").write(mpHandler);
-
-    TagCloseElement("style:page-layout").write(mpHandler);
-
-    TagOpenElement tmpStyleStyleOpenElement("style:style");
-    tmpStyleStyleOpenElement.addAttribute("style:name", "dp1");
-    tmpStyleStyleOpenElement.addAttribute("style:family", "drawing-page");
-    tmpStyleStyleOpenElement.write(mpHandler);
-
-    TagOpenElement tmpStyleDrawingPagePropertiesOpenElement("style:drawing-page-properties");
-    tmpStyleDrawingPagePropertiesOpenElement.addAttribute("draw:background-size", "border");
-    tmpStyleDrawingPagePropertiesOpenElement.addAttribute("draw:fill", "none");
-    tmpStyleDrawingPagePropertiesOpenElement.write(mpHandler);
-
-    TagCloseElement("style:drawing-page-properties").write(mpHandler);
-
-    TagCloseElement("style:style").write(mpHandler);
-}
-
-void OdgExporter::endDocument()
-{
-    TagCloseElement("office:automatic-styles").write(mpHandler);
-
-    TagOpenElement("office:master-styles").write(mpHandler);
-
-    TagOpenElement tmpStyleMasterPageOpenElement("style:master-page");
-    tmpStyleMasterPageOpenElement.addAttribute("style:name", "Default");
-    tmpStyleMasterPageOpenElement.addAttribute("style:page-layout-name", "PM0");
-    tmpStyleMasterPageOpenElement.addAttribute("draw:style-name", "dp1");
-    tmpStyleMasterPageOpenElement.write(mpHandler);
-
-    TagCloseElement("style:master-page").write(mpHandler);
-
-    TagCloseElement("office:master-styles").write(mpHandler);
-
-    TagOpenElement("office:body").write(mpHandler);
-
-    TagOpenElement("office:drawing").write(mpHandler);
-
-    TagOpenElement tmpDrawPageOpenElement("draw:page");
-    tmpDrawPageOpenElement.addAttribute("draw:name", "page1");
-    tmpDrawPageOpenElement.addAttribute("draw:style-name", "dp1");
-    tmpDrawPageOpenElement.addAttribute("draw:master-page-name", "Default");
-    tmpDrawPageOpenElement.write(mpHandler);
-
-    for (std::vector<DocumentElement *>::const_iterator bodyIter = mpBodyElements.begin();
-        bodyIter != mpBodyElements.end(); bodyIter++)
-    {
-        (*bodyIter)->write(mpHandler);
-    }
-
-    TagCloseElement("draw:page").write(mpHandler);
-    TagCloseElement("office:drawing").write(mpHandler);
-    TagCloseElement("office:body").write(mpHandler);
-    TagCloseElement("office:document").write(mpHandler);
-
-    mpHandler->endDocument();
-}
-
-void OdgExporter::setPen(const libwpg::WPGPen& pen)
-{
-    m_pen = pen;
-}
-
-void OdgExporter::setBrush(const libwpg::WPGBrush& brush)
-{
-    m_brush = brush;
-}
-
-void OdgExporter::setFillRule(FillRule rule)
-{
-    m_fillRule = rule;
-}
-
-void OdgExporter::startLayer(unsigned int /* id */)
-{
-}
-
-void OdgExporter::endLayer(unsigned int)
-{
-}
-
-void OdgExporter::drawRectangle(const libwpg::WPGRect& rect, double rx, double /* ry */)
-{
-    writeStyle();
-    TagOpenElement *pDrawRectElement = new TagOpenElement("draw:rect");
-    WPXString sValue;
-    sValue.sprintf("gr%i", m_styleIndex-1);
-    pDrawRectElement->addAttribute("draw:style-name", sValue);
-    sValue = doubleToString(2.54 * rect.x1); sValue.append("cm");
-    pDrawRectElement->addAttribute("svg:x", sValue);
-    sValue = doubleToString(2.54 * rect.y1); sValue.append("cm");
-    pDrawRectElement->addAttribute("svg:y", sValue);
-    sValue = doubleToString(2.54 * (rect.x2-rect.x1)); sValue.append("cm");
-    pDrawRectElement->addAttribute("svg:width", sValue);
-    sValue = doubleToString(2.54 * (rect.y2-rect.y1)); sValue.append("cm");
-    pDrawRectElement->addAttribute("svg:height", sValue);
-    sValue = doubleToString(2.54 * rx); sValue.append("cm");
-    // FIXME: what to do when rx != ry ?
-    pDrawRectElement->addAttribute("draw:corner-radius", sValue);
-    mpBodyElements.push_back(static_cast<DocumentElement *>(pDrawRectElement));
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new TagCloseElement("draw:rect")));
-}
-
-void OdgExporter::drawEllipse(const libwpg::WPGPoint& center, double rx, double ry)
-{
-    writeStyle();
-    TagOpenElement *pDrawEllipseElement = new TagOpenElement("draw:ellipse");
-    WPXString sValue;
-    sValue.sprintf("gr%i", m_styleIndex-1);
-    pDrawEllipseElement->addAttribute("draw:style-name", sValue);
-    sValue = doubleToString(2.54 * (center.x-rx)); sValue.append("cm");
-    pDrawEllipseElement->addAttribute("svg:x", sValue);
-    sValue = doubleToString(2.54 * (center.y-ry)); sValue.append("cm");
-    pDrawEllipseElement->addAttribute("svg:y", sValue);
-    sValue = doubleToString(2 * 2.54 * rx); sValue.append("cm");
-    pDrawEllipseElement->addAttribute("svg:width", sValue);
-    sValue = doubleToString(2 * 2.54 * ry); sValue.append("cm");
-    pDrawEllipseElement->addAttribute("svg:height", sValue);
-    mpBodyElements.push_back(static_cast<DocumentElement *>(pDrawEllipseElement));
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new TagCloseElement("draw:ellipse")));
-}
-
-void OdgExporter::drawPolygon(const libwpg::WPGPointArray& vertices)
-{
-    if(vertices.count() < 2)
-        return;
-
-    if(vertices.count() == 2)
-    {
-        const libwpg::WPGPoint& p1 = vertices[0];
-        const libwpg::WPGPoint& p2 = vertices[1];
-
-        writeStyle();
-        TagOpenElement *pDrawLineElement = new TagOpenElement("draw:line");
-        WPXString sValue;
-        sValue.sprintf("gr%i", m_styleIndex-1);
-        pDrawLineElement->addAttribute("draw:style-name", sValue);
-        pDrawLineElement->addAttribute("draw:text-style-name", "P1");
-        pDrawLineElement->addAttribute("draw:layer", "layout");
-        sValue = doubleToString(2.54 * p1.x); sValue.append("cm");
-        pDrawLineElement->addAttribute("svg:x1", sValue);
-        sValue = doubleToString(2.54 * p1.y); sValue.append("cm");
-        pDrawLineElement->addAttribute("svg:y1", sValue);
-        sValue = doubleToString(2.54 * p2.x); sValue.append("cm");
-        pDrawLineElement->addAttribute("svg:x2", sValue);
-        sValue = doubleToString(2.54 * p2.y); sValue.append("cm");
-        pDrawLineElement->addAttribute("svg:y2", sValue);
-        mpBodyElements.push_back(static_cast<DocumentElement *>(pDrawLineElement));
-        mpBodyElements.push_back(static_cast<DocumentElement *>(new TagCloseElement("draw:line")));
-    }
-    else
-    {
-        // draw as path
-        libwpg::WPGPath path;
-        path.moveTo(vertices[0]);
-        for(unsigned long ii = 1; ii < vertices.count(); ii++)
-            path.lineTo(vertices[ii]);
-        path.closed = true;
-        drawPath(path);
-    }
-}
-
-void OdgExporter::drawPath(const libwpg::WPGPath& path)
-{
-    if(path.count() == 0)
-        return;
-
-    // try to find the bounding box
-    // this is simple convex hull technique, the bounding box might not be
-    // accurate but that should be enough for this purpose
-    libwpg::WPGPoint p = path.element(0).point;
-    libwpg::WPGPoint q = path.element(0).point;
-    for(unsigned k = 0; k < path.count(); k++)
-    {
-        libwpg::WPGPathElement element = path.element(k);
-        p.x = (p.x > element.point.x) ? element.point.x : p.x;
-        p.y = (p.y > element.point.y) ? element.point.y : p.y;
-        q.x = (q.x < element.point.x) ? element.point.x : q.x;
-        q.y = (q.y < element.point.y) ? element.point.y : q.y;
-        if(element.type == libwpg::WPGPathElement::CurveToElement)
-        {
-            p.x = (p.x > element.extra1.x) ? element.extra1.x : p.x;
-            p.y = (p.y > element.extra1.y) ? element.extra1.y : p.y;
-            q.x = (q.x < element.extra1.x) ? element.extra1.x : q.x;
-            q.y = (q.y < element.extra1.y) ? element.extra1.y : q.y;
-            p.x = (p.x > element.extra2.x) ? element.extra2.x : p.x;
-            p.y = (p.y > element.extra2.y) ? element.extra2.y : p.y;
-            q.x = (q.x < element.extra2.x) ? element.extra2.x : q.x;
-            q.y = (q.y < element.extra2.y) ? element.extra2.y : q.y;
-        }
-    }
-    double vw = q.x - p.x;
-    double vh = q.y - p.y;
-
-    writeStyle();
-
-    TagOpenElement *pDrawPathElement = new TagOpenElement("draw:path");
-    WPXString sValue;
-    sValue.sprintf("gr%i", m_styleIndex-1);
-    pDrawPathElement->addAttribute("draw:style-name", sValue);
-    pDrawPathElement->addAttribute("draw:text-style-name", "P1");
-    pDrawPathElement->addAttribute("draw:layer", "layout");
-    sValue = doubleToString(2.54 * p.x); sValue.append("cm");
-    pDrawPathElement->addAttribute("svg:x", sValue);
-    sValue = doubleToString(2.54 * p.y); sValue.append("cm");
-    pDrawPathElement->addAttribute("svg:y", sValue);
-    sValue = doubleToString(2.54 * vw); sValue.append("cm");
-    pDrawPathElement->addAttribute("svg:width", sValue);
-    sValue = doubleToString(2.54 * vh); sValue.append("cm");
-    pDrawPathElement->addAttribute("svg:height", sValue);
-    sValue.sprintf("%i %i %i %i", 0, 0, (int)(vw*2540), (int)(vh*2540));
-    pDrawPathElement->addAttribute("svg:viewBox", sValue);
-
-    sValue.clear();
-    for(unsigned i = 0; i < path.count(); i++)
-    {
-        libwpg::WPGPathElement element = path.element(i);
-        libwpg::WPGPoint point = element.point;
-        WPXString sElement;
-        switch(element.type)
-        {
-            // 2540 is 2.54*1000, 2.54 cm = 1 inch
-            case libwpg::WPGPathElement::MoveToElement:
-                sElement.sprintf("M%i %i", (int)((point.x-p.x)*2540), (int)((point.y-p.y)*2540));
-                break;
-
-            case libwpg::WPGPathElement::LineToElement:
-                sElement.sprintf("L%i %i", (int)((point.x-p.x)*2540), (int)((point.y-p.y)*2540));
-                break;
-
-            case libwpg::WPGPathElement::CurveToElement:
-                sElement.sprintf("C%i %i %i %i %i %i", (int)((element.extra1.x-p.x)*2540),
-                (int)((element.extra1.y-p.y)*2540), (int)((element.extra2.x-p.x)*2540),
-                (int)((element.extra2.y-p.y)*2540), (int)((point.x-p.x)*2540), (int)((point.y-p.y)*2540));
-                break;
-
-            default:
-                break;
-        }
-        sValue.append(sElement);
-    }
-    if(path.closed)
-        sValue.append(" Z");
-    pDrawPathElement->addAttribute("svg:d", sValue);
-    mpBodyElements.push_back(static_cast<DocumentElement *>(pDrawPathElement));
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new TagCloseElement("draw:path")));
-}
-
-void OdgExporter::drawBitmap(const libwpg::WPGBitmap& bitmap)
-{
-    TagOpenElement *pDrawFrameElement = new TagOpenElement("draw:frame");
-    WPXString sValue;
-    sValue = doubleToString(2.54 * bitmap.rect.x1); sValue.append("cm");
-    pDrawFrameElement->addAttribute("svg:x", sValue);
-    sValue = doubleToString(2.54 * bitmap.rect.y1); sValue.append("cm");
-    pDrawFrameElement->addAttribute("svg:y", sValue);
-    sValue = doubleToString(2.54 * bitmap.rect.height()); sValue.append("cm");
-    pDrawFrameElement->addAttribute("svg:height", sValue);
-    sValue = doubleToString(2.54 * bitmap.rect.width()); sValue.append("cm");
-    pDrawFrameElement->addAttribute("svg:width", sValue);
-    mpBodyElements.push_back(static_cast<DocumentElement *>(pDrawFrameElement));
-
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new TagOpenElement("draw:image")));
-
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new TagOpenElement("office:binary-data")));
-
-    libwpg::WPGString base64Binary;
-    bitmap.generateBase64DIB(base64Binary);
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new CharDataElement(base64Binary.cstr())));
-
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new TagCloseElement("office:binary-data")));
-
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new TagCloseElement("draw:image")));
-
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new TagCloseElement("draw:frame")));
-}
-
-void OdgExporter::drawImageObject(const libwpg::WPGBinaryData& binaryData)
-{
-    if (binaryData.mimeType.length() <= 0)
-        return;
-
-    TagOpenElement *pDrawFrameElement = new TagOpenElement("draw:frame");
-    WPXString sValue;
-    sValue = doubleToString(2.54 * binaryData.rect.x1); sValue.append("cm");
-    pDrawFrameElement->addAttribute("svg:x", sValue);
-    sValue = doubleToString(2.54 * binaryData.rect.y1); sValue.append("cm");
-    pDrawFrameElement->addAttribute("svg:y", sValue);
-    sValue = doubleToString(2.54 * binaryData.rect.height()); sValue.append("cm");
-    pDrawFrameElement->addAttribute("svg:height", sValue);
-    sValue = doubleToString(2.54 * binaryData.rect.width()); sValue.append("cm");
-    pDrawFrameElement->addAttribute("svg:width", sValue);
-    mpBodyElements.push_back(static_cast<DocumentElement *>(pDrawFrameElement));
-
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new TagOpenElement("draw:image")));
-
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new TagOpenElement("office:binary-data")));
-
-    libwpg::WPGString base64Binary = binaryData.getBase64Data();;
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new CharDataElement(base64Binary.cstr())));
-
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new TagCloseElement("office:binary-data")));
-
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new TagCloseElement("draw:image")));
-
-    mpBodyElements.push_back(static_cast<DocumentElement *>(new TagCloseElement("draw:frame")));
-}
-
-void OdgExporter::writeStyle()
-{
-    if(!m_pen.solid && (m_pen.dashArray.count() >=2 ) )
-    {
-        // ODG only supports dashes with the same length of spaces inbetween
-        // here we take the first space and assume everything else the same
-        // note that dash length is written in percentage
-        double distance = m_pen.dashArray.at(1);
-        TagOpenElement tmpDrawStrokeDashElement("draw:stroke-dash");
-        tmpDrawStrokeDashElement.addAttribute("draw:style", "rect");
-        WPXString sValue;
-        sValue.sprintf("Dash_%i", m_dashIndex++);
-        tmpDrawStrokeDashElement.addAttribute("draw:name", sValue);
-        sValue.sprintf("%i \%", distance*100);
-        tmpDrawStrokeDashElement.addAttribute("draw:distance", sValue);
-        WPXString sName;
-        for(unsigned i = 0; i < m_pen.dashArray.count()/2; i++)
-        {
-            sName.sprintf("draw:dots%i", i+1);
-            tmpDrawStrokeDashElement.addAttribute(sName.cstr(), "1");
-            sName.sprintf("draw:dots%i-length", i+1);
-            sValue.sprintf("%i\%", 100*m_pen.dashArray.at(i*2));
-            tmpDrawStrokeDashElement.addAttribute(sName.cstr(), sValue);
-        }
-        tmpDrawStrokeDashElement.write(mpHandler);
-        TagCloseElement("draw:stroke-dash").write(mpHandler);
-    }
-
-    if(m_brush.style == libwpg::WPGBrush::Gradient)
-    {
-        TagOpenElement tmpDrawGradientElement("draw:gradient");
-        tmpDrawGradientElement.addAttribute("draw:style", "linear");
-        WPXString sValue;
-        sValue.sprintf("Gradient_%i", m_gradientIndex++);
-        tmpDrawGradientElement.addAttribute("draw:name", sValue);
-
-        // ODG angle unit is 0.1 degree
-        double angle = -m_brush.gradient.angle();
-        while(angle < 0)
-            angle += 360;
-        while(angle > 360)
-            angle -= 360;
-
-        sValue.sprintf("%i", angle*10);
-        tmpDrawGradientElement.addAttribute("draw:angle", sValue);
-
-        libwpg::WPGColor startColor = m_brush.gradient.stopColor(0);
-        libwpg::WPGColor stopColor = m_brush.gradient.stopColor(1);
-        sValue.sprintf("#%.2x%.2x%.2x", (startColor.red & 0xff), (startColor.green & 0xff), (startColor.blue & 0xff));
-        tmpDrawGradientElement.addAttribute("draw:start-color", sValue);
-        sValue.sprintf("#%.2x%.2x%.2x", (stopColor.red & 0xff), (stopColor.green & 0xff), (stopColor.blue & 0xff));
-        tmpDrawGradientElement.addAttribute("draw:end-color", sValue);
-        tmpDrawGradientElement.addAttribute("draw:start-intensity", "100%");
-        tmpDrawGradientElement.addAttribute("draw:end-intensity", "100%");
-        tmpDrawGradientElement.addAttribute("draw:border", "0%");
-        tmpDrawGradientElement.write(mpHandler);
-        TagCloseElement("draw:gradient").write(mpHandler);
-    }
-
-    TagOpenElement tmpStyleStyleElement("style:style");
-    WPXString sValue;
-    sValue.sprintf("gr%i",  m_styleIndex);
-    tmpStyleStyleElement.addAttribute("style:name", sValue);
-    tmpStyleStyleElement.addAttribute("style:family", "graphic");
-    tmpStyleStyleElement.addAttribute("style:parent-style-name", "standard");
-    tmpStyleStyleElement.write(mpHandler);
-
-    TagOpenElement tmpStyleGraphicPropertiesElement("style:graphic-properties");
-
-    if(m_pen.width > 0.0)
-    {
-        sValue = doubleToString(2.54 * m_pen.width); sValue.append("cm");
-        tmpStyleGraphicPropertiesElement.addAttribute("svg:stroke-width", sValue);
-        sValue.sprintf("#%.2x%.2x%.2x", (m_pen.foreColor.red & 0xff),
-                      (m_pen.foreColor.green & 0xff), (m_pen.foreColor.blue & 0xff));
-        tmpStyleGraphicPropertiesElement.addAttribute("svg:stroke-color", sValue);
-
-        if(!m_pen.solid)
-        {
-            tmpStyleGraphicPropertiesElement.addAttribute("draw:stroke", "dash");
-            sValue.sprintf("Dash_%i", m_dashIndex-1);
-            tmpStyleGraphicPropertiesElement.addAttribute("draw:stroke-dash", sValue);
-            }
-    }
-    else
-        tmpStyleGraphicPropertiesElement.addAttribute("draw:stroke", "none");
-
-    if(m_brush.style == libwpg::WPGBrush::NoBrush)
-        tmpStyleGraphicPropertiesElement.addAttribute("draw:fill", "none");
-
-    if(m_brush.style == libwpg::WPGBrush::Solid)
-    {
-        tmpStyleGraphicPropertiesElement.addAttribute("draw:fill", "solid");
-        sValue.sprintf("#%.2x%.2x%.2x", (m_brush.foreColor.red & 0xff),
-                      (m_brush.foreColor.green & 0xff), (m_brush.foreColor.blue & 0xff));
-        tmpStyleGraphicPropertiesElement.addAttribute("draw:fill-color", sValue);
-    }
-
-    if(m_brush.style == libwpg::WPGBrush::Gradient)
-    {
-        tmpStyleGraphicPropertiesElement.addAttribute("draw:fill", "gradient");
-        sValue.sprintf("Gradient_%i", m_gradientIndex-1);
-        tmpStyleGraphicPropertiesElement.addAttribute("draw:fill-gradient-name", sValue);
-    }
-
-    tmpStyleGraphicPropertiesElement.write(mpHandler);
-    TagCloseElement("style:graphic-properties").write(mpHandler);
-
-    TagCloseElement("style:style").write(mpHandler);
-    m_styleIndex++;
-}
-
-WPXString OdgExporter::doubleToString(const double value)
-{
-    return WPXString((char *)::rtl::math::doubleToString(value, rtl_math_StringFormat_F, 4, '.').getStr());
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/wpgimp/OdgExporter.hxx b/writerperfect/source/wpgimp/OdgExporter.hxx
deleted file mode 100644
index 2bfa6b8..0000000
--- a/writerperfect/source/wpgimp/OdgExporter.hxx
+++ /dev/null
@@ -1,81 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* libwpg
- * Copyright (C) 2006 Ariya Hidayat (ariya at kde.org)
- * Copyright (C) 2007 Fridrich Strba (fridrich_strba at bluewin.ch)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA  02111-1301 USA
- *
- * For further information visit http://libwpg.sourceforge.net
- */
-
-/* "This product is not manufactured, approved, or supported by
- * Corel Corporation or Corel Corporation Limited."
- */
-
-#ifndef __ODGEXPORTER_HXX__
-#define __ODGEXPORTER_HXX__
-
-#include <iostream>
-#include <sstream>
-#include <string>
-
-#include <libwpd/WPXString.h>
-#include <libwpg/libwpg.h>
-#include <libwpg/WPGBinaryData.h>
-#include "filter/DocumentElement.hxx"
-#include "filter/DocumentHandler.hxx"
-
-class OdgExporter : public libwpg::WPGPaintInterface {
-public:
-    OdgExporter(DocumentHandler *pHandler);
-    ~OdgExporter();
-
-    void startDocument(double width, double height);
-    void startGraphics(double width, double height) { startDocument(width, height); }
-    void endDocument();
-    void endGraphics() { endDocument(); };
-    void startLayer(unsigned int id);
-    void endLayer(unsigned int id);
-
-    void setPen(const libwpg::WPGPen& pen);
-    void setBrush(const libwpg::WPGBrush& brush);
-    void setFillRule(FillRule rule);
-
-    void drawRectangle(const libwpg::WPGRect& rect, double rx, double ry);
-    void drawEllipse(const libwpg::WPGPoint& center, double rx, double ry);
-    void drawPolygon(const libwpg::WPGPointArray& vertices);
-    void drawPath(const libwpg::WPGPath& path);
-    void drawBitmap(const libwpg::WPGBitmap& bitmap);
-    void drawImageObject(const libwpg::WPGBinaryData& binaryData);
-
-private:
-    std::vector <DocumentElement *> mpBodyElements;
-    std::vector <DocumentElement *> mpStylesElements;
-    DocumentHandler *mpHandler;
-
-    libwpg::WPGPen m_pen;
-    libwpg::WPGBrush m_brush;
-    FillRule m_fillRule;
-    int m_gradientIndex;
-    int m_dashIndex;
-    int m_styleIndex;
-    void writeStyle();
-    WPXString doubleToString(const double value);
-};
-
-#endif // __ODGEXPORTER_HXX__
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/wpgimp/makefile.mk b/writerperfect/source/wpgimp/makefile.mk
index f244046..ccf1d7d 100644
--- a/writerperfect/source/wpgimp/makefile.mk
+++ b/writerperfect/source/wpgimp/makefile.mk
@@ -8,14 +8,10 @@ ENABLE_EXCEPTIONS=true
 
 .IF "$(SYSTEM_LIBWPD)" == "YES"
 INCPRE+=$(LIBWPD_CFLAGS)
-.ELSE
-INCPRE+=$(SOLARVER)$/$(UPD)$/$(INPATH)$/inc$/libwpd
 .ENDIF
 
 .IF "$(SYSTEM_LIBWPG)" == "YES"
 INCPRE+=$(LIBWPG_CFLAGS)
-.ELSE
-INCPRE+=$(SOLARVER)$/$(UPD)$/$(INPATH)$/inc$/libwpg
 .ENDIF
 
 # broken but ... necessary, internal include shafted ...
commit 3c31fb6f22c654e31839ed2dd23e4b2687059610
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Tue Nov 16 13:53:39 2010 +0100

    Use the new stable libwp* releases as default

diff --git a/writerperfect/prj/build.lst b/writerperfect/prj/build.lst
index bf7a656..87b258a 100644
--- a/writerperfect/prj/build.lst
+++ b/writerperfect/prj/build.lst
@@ -1,4 +1,4 @@
-wp      writerperfect : LIBWPG:libwpg LIBWPS:libwps LIBWPD:libwpd sot comphelper xmloff svtools NULL
+wp      writerperfect : LIBWPG:libwpg LIBWPS:libwps LIBWPD:libwpd sot comphelper xmloff svtools sfx2 NULL
 wp	writerperfect			usr1	-	all	wp_mkout NULL
 wp	writerperfect\source\stream	nmake	-	all	wp_stream NULL
 wp	writerperfect\source\filter	nmake	-	all	wp_filter NULL
diff --git a/writerperfect/source/filter/DocumentCollector.cxx b/writerperfect/source/filter/DocumentCollector.cxx
index 879e1d0..5db1900 100644
--- a/writerperfect/source/filter/DocumentCollector.cxx
+++ b/writerperfect/source/filter/DocumentCollector.cxx
@@ -40,6 +40,8 @@
 
 #include "DocumentCollector.hxx"
 #include "DocumentElement.hxx"
+#include "DocumentHandler.hxx"
+#include "InternalHandler.hxx"
 #include "TextRunStyle.hxx"
 #include "FontStyle.hxx"
 #include "ListStyle.hxx"
@@ -48,34 +50,49 @@
 #include "TableStyle.hxx"
 #include "FilterInternal.hxx"
 #include "WriterProperties.hxx"
+#include "OdgExporter.hxx"
 
 _WriterDocumentState::_WriterDocumentState() :
     mbFirstElement(true),
+    mbFirstParagraphInPageSpan(true),
     mbInFakeSection(false),
     mbListElementOpenedAtCurrentLevel(false),
     mbTableCellOpened(false),
     mbHeaderRow(false),
-    mbInNote(false)
+    mbInNote(false),
+    mbInTextBox(false),
+    mbInFrame(false)
 {
 }
 
-DocumentCollector::DocumentCollector(WPSInputStream *pInput, DocumentHandler *pHandler) :
+_WriterListState::_WriterListState() :
+    mpCurrentListStyle(NULL),
+    miCurrentListLevel(0),
+    miLastListLevel(0),
+    miLastListNumber(0),
+    mbListContinueNumbering(false),
+    mbListElementParagraphOpened(false),
+    mbListElementOpened()
+{
+}
+
+DocumentCollector::DocumentCollector(WPXInputStream *pInput, DocumentHandlerInterface *pHandler) :
         mpInput(pInput),
         mpHandler(pHandler),
     mbUsed(false),
+    mWriterDocumentStates(),
+    mWriterListStates(),
     mfSectionSpaceAfter(0.0f),
     miNumListStyles(0),
     mpCurrentContentElements(&mBodyElements),
     mpCurrentPageSpan(NULL),
     miNumPageStyles(0),
-    mpCurrentListStyle(NULL),
-    miCurrentListLevel(0),
-    miLastListLevel(0),
-    miLastListNumber(0),
-    mbListContinueNumbering(false),
-    mbListElementOpened(false),
-    mbListElementParagraphOpened(false)
+    miObjectNumber(0),
+    mbIsFlatXML(true),
+    mpPassword(NULL)
 {
+    mWriterDocumentStates.push(WriterDocumentState());
+    mWriterListStates.push(WriterListState());
 }
 
 DocumentCollector::~DocumentCollector()
@@ -103,7 +120,7 @@ bool DocumentCollector::filter()
 
     WRITER_DEBUG_MSG(("Destroying the body elements\n"));
     for (std::vector<DocumentElement *>::iterator iterBody = mBodyElements.begin(); iterBody != mBodyElements.end(); iterBody++) {
-        delete((*iterBody));
+        delete (*iterBody);
         (*iterBody) = NULL;
     }
 
@@ -116,14 +133,14 @@ bool DocumentCollector::filter()
 
     WRITER_DEBUG_MSG(("Destroying the rest of the styles elements\n"));
     for (std::map<WPXString, ParagraphStyle *, ltstr>::iterator iterTextStyle = mTextStyleHash.begin(); iterTextStyle != mTextStyleHash.end(); iterTextStyle++) {
-        delete iterTextStyle->second;
+        delete (iterTextStyle->second);
     }
     for (std::map<WPXString, SpanStyle *, ltstr>::iterator iterSpanStyle = mSpanStyleHash.begin(); iterSpanStyle != mSpanStyleHash.end(); iterSpanStyle++) {
-        delete iterSpanStyle->second;
+        delete(iterSpanStyle->second);
     }
 
     for (std::map<WPXString, FontStyle *, ltstr>::iterator iterFont = mFontHash.begin(); iterFont != mFontHash.end(); iterFont++) {
-        delete iterFont->second;
+        delete(iterFont->second);
     }
 
     for (std::vector<ListStyle *>::iterator iterListStyles = mListStyles.begin(); iterListStyles != mListStyles.end(); iterListStyles++) {
@@ -133,80 +150,101 @@ bool DocumentCollector::filter()
         delete (*iterSectionStyles);
     }
     for (std::vector<TableStyle *>::iterator iterTableStyles = mTableStyles.begin(); iterTableStyles != mTableStyles.end(); iterTableStyles++) {
-        delete (*iterTableStyles);
+        delete((*iterTableStyles));
     }
 
     for (std::vector<PageSpan *>::iterator iterPageSpans = mPageSpans.begin(); iterPageSpans != mPageSpans.end(); iterPageSpans++) {
         delete (*iterPageSpans);
     }
+    for (std::vector<DocumentElement *>::iterator iterFrameStyles = mFrameStyles.begin(); iterFrameStyles != mFrameStyles.end(); iterFrameStyles++) {
+        delete(*iterFrameStyles);
+    }
+    for (std::vector<DocumentElement *>::iterator iterFrameAutomaticStyles = mFrameAutomaticStyles.begin();
+        iterFrameAutomaticStyles != mFrameAutomaticStyles.end(); iterFrameAutomaticStyles++) {
+        delete(*iterFrameAutomaticStyles);
+    }
+    for (std::vector<DocumentElement *>::iterator iterMetaData = mMetaData.begin(); iterMetaData != mMetaData.end(); iterMetaData++) {
+        delete(*iterMetaData);
+    }
 
      return true;
 }
 
-void DocumentCollector::_writeDefaultStyles(DocumentHandler *pHandler)
+void DocumentCollector::_writeDefaultStyles(DocumentHandlerInterface *pHandler)
 {
-    TagOpenElement stylesOpenElement("office:styles");
-    stylesOpenElement.write(pHandler);
+    TagOpenElement("office:styles").write(pHandler);
 
     TagOpenElement defaultParagraphStyleOpenElement("style:default-style");
     defaultParagraphStyleOpenElement.addAttribute("style:family", "paragraph");
     defaultParagraphStyleOpenElement.write(pHandler);
 
-    TagOpenElement defaultParagraphStylePropertiesOpenElement("style:properties");
-    defaultParagraphStylePropertiesOpenElement.addAttribute("style:family", "paragraph");
-    defaultParagraphStylePropertiesOpenElement.addAttribute("style:tab-stop-distance", "0.5inch");
+    TagOpenElement defaultParagraphStylePropertiesOpenElement("style:paragraph-properties");
+    defaultParagraphStylePropertiesOpenElement.addAttribute("style:tab-stop-distance", "0.5in");
     defaultParagraphStylePropertiesOpenElement.write(pHandler);
-    TagCloseElement defaultParagraphStylePropertiesCloseElement("style:properties");
+    TagCloseElement defaultParagraphStylePropertiesCloseElement("style:paragraph-properties");
     defaultParagraphStylePropertiesCloseElement.write(pHandler);
 
-    TagCloseElement defaultParagraphStyleCloseElement("style:default-style");
-    defaultParagraphStyleCloseElement.write(pHandler);
+    pHandler->endElement("style:default-style");
+
+    TagOpenElement defaultTableRowStyleOpenElement("style:default-style");
+    defaultTableRowStyleOpenElement.addAttribute("style:family", "table-row");
+    defaultTableRowStyleOpenElement.write(pHandler);
+
+    TagOpenElement defaultTableRowPropertiesOpenElement("style:table-row-properties");
+    defaultTableRowPropertiesOpenElement.addAttribute("fo:keep-together", "auto");
+    defaultTableRowPropertiesOpenElement.write(pHandler);
+
+    pHandler->endElement("style:table-row-properties");
+    pHandler->endElement("style:default-style");
 
     TagOpenElement standardStyleOpenElement("style:style");
         standardStyleOpenElement.addAttribute("style:name", "Standard");
         standardStyleOpenElement.addAttribute("style:family", "paragraph");
         standardStyleOpenElement.addAttribute("style:class", "text");
         standardStyleOpenElement.write(pHandler);
-        TagCloseElement standardStyleCloseElement("style:style");
-        standardStyleCloseElement.write(pHandler);
+
+    pHandler->endElement("style:style");
 
         TagOpenElement textBodyStyleOpenElement("style:style");
-        textBodyStyleOpenElement.addAttribute("style:name", "Text Body");
+    textBodyStyleOpenElement.addAttribute("style:name", "Text_Body");
+    textBodyStyleOpenElement.addAttribute("style:display-name", "Text Body");
         textBodyStyleOpenElement.addAttribute("style:family", "paragraph");
         textBodyStyleOpenElement.addAttribute("style:parent-style-name", "Standard");
         textBodyStyleOpenElement.addAttribute("style:class", "text");
         textBodyStyleOpenElement.write(pHandler);
-        TagCloseElement textBodyStyleCloseElement("style:style");
-        textBodyStyleCloseElement.write(pHandler);
+
+    pHandler->endElement("style:style");
 
         TagOpenElement tableContentsStyleOpenElement("style:style");
-        tableContentsStyleOpenElement.addAttribute("style:name", "Table Contents");
+    tableContentsStyleOpenElement.addAttribute("style:name", "Table_Contents");
+    tableContentsStyleOpenElement.addAttribute("style:display-name", "Table Contents");
         tableContentsStyleOpenElement.addAttribute("style:family", "paragraph");
-        tableContentsStyleOpenElement.addAttribute("style:parent-style-name", "Text Body");
+    tableContentsStyleOpenElement.addAttribute("style:parent-style-name", "Text_Body");
         tableContentsStyleOpenElement.addAttribute("style:class", "extra");
         tableContentsStyleOpenElement.write(pHandler);
-        TagCloseElement tableContentsStyleCloseElement("style:style");
-        tableContentsStyleCloseElement.write(pHandler);
+
+    pHandler->endElement("style:style");
 
         TagOpenElement tableHeadingStyleOpenElement("style:style");
-        tableHeadingStyleOpenElement.addAttribute("style:name", "Table Heading");
+    tableHeadingStyleOpenElement.addAttribute("style:name", "Table_Heading");
+    tableHeadingStyleOpenElement.addAttribute("style:display-name", "Table Heading");
         tableHeadingStyleOpenElement.addAttribute("style:family", "paragraph");
-        tableHeadingStyleOpenElement.addAttribute("style:parent-style-name", "Table Contents");
+    tableHeadingStyleOpenElement.addAttribute("style:parent-style-name", "Table_Contents");
         tableHeadingStyleOpenElement.addAttribute("style:class", "extra");
         tableHeadingStyleOpenElement.write(pHandler);
-        TagCloseElement tableHeadingStyleCloseElement("style:style");
-        tableHeadingStyleCloseElement.write(pHandler);
 
-    TagCloseElement stylesCloseElement("office:styles");
-    stylesCloseElement.write(pHandler);
+    pHandler->endElement("style:style");
+
+    for (std::vector<DocumentElement *>::const_iterator iter = mFrameStyles.begin();
+        iter != mFrameStyles.end(); iter++)
+        (*iter)->write(pHandler);
 
+    pHandler->endElement("office:styles");
 }
 
-void DocumentCollector::_writeMasterPages(DocumentHandler *pHandler)
+void DocumentCollector::_writeMasterPages(DocumentHandlerInterface *pHandler)
 {
-        WPXPropertyList xBlankAttrList;
-
-    pHandler->startElement("office:master-styles", xBlankAttrList);
+    TagOpenElement("office:master-styles").write(mpHandler);
     int pageNumber = 1;
     for (unsigned int i=0; i<mPageSpans.size(); i++)
     {
@@ -218,65 +256,79 @@ void DocumentCollector::_writeMasterPages(DocumentHandler *pHandler)
     pHandler->endElement("office:master-styles");
 }
 
-void DocumentCollector::_writePageMasters(DocumentHandler *pHandler)
+void DocumentCollector::_writePageLayouts(DocumentHandlerInterface *pHandler)
 {
     for (unsigned int i=0; i<mPageSpans.size(); i++)
     {
-        mPageSpans[i]->writePageMaster(i, pHandler);
+        mPageSpans[i]->writePageLayout(i, pHandler);
     }
 }
 
-bool DocumentCollector::_writeTargetDocument(DocumentHandler *pHandler)
+bool DocumentCollector::_writeTargetDocument(DocumentHandlerInterface *pHandler)
 {        
     WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Printing out the header stuff..\n"));
-    WPXPropertyList xBlankAttrList;
 
     WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Start Document\n"));
     mpHandler->startDocument();
 
     WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: preamble\n"));
         WPXPropertyList docContentPropList;
-    docContentPropList.insert("xmlns:office", "http://openoffice.org/2000/office");
-    docContentPropList.insert("xmlns:style", "http://openoffice.org/2000/style");
-    docContentPropList.insert("xmlns:text", "http://openoffice.org/2000/text");
-    docContentPropList.insert("xmlns:table", "http://openoffice.org/2000/table");
-    docContentPropList.insert("xmlns:draw", "http://openoffice.org/2000/draw");
-    docContentPropList.insert("xmlns:fo", "http://www.w3.org/1999/XSL/Format");
+    docContentPropList.insert("xmlns:office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0");
+    docContentPropList.insert("xmlns:meta", "urn:oasis:names:tc:opendocument:xmlns:meta:1.0");
+    docContentPropList.insert("xmlns:dc", "http://purl.org/dc/elements/1.1/");
+    docContentPropList.insert("xmlns:config", "urn:oasis:names:tc:opendocument:xmlns:config:1.0");
+    docContentPropList.insert("xmlns:text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0");
+    docContentPropList.insert("xmlns:table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0");
+    docContentPropList.insert("xmlns:draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0");
+    docContentPropList.insert("xmlns:fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
     docContentPropList.insert("xmlns:xlink", "http://www.w3.org/1999/xlink");
     docContentPropList.insert("xmlns:number", "http://openoffice.org/2000/datastyle");
-    docContentPropList.insert("xmlns:svg", "http://www.w3.org/2000/svg");
-    docContentPropList.insert("xmlns:chart", "http://openoffice.org/2000/chart");
-    docContentPropList.insert("xmlns:dr3d", "http://openoffice.org/2000/dr3d");
+    docContentPropList.insert("xmlns:svg", "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0");
+    docContentPropList.insert("xmlns:chart", "urn:oasis:names:tc:opendocument:xmlns:chart:1.0");
+    docContentPropList.insert("xmlns:dr3d", "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0");
     docContentPropList.insert("xmlns:math", "http://www.w3.org/1998/Math/MathML");
-    docContentPropList.insert("xmlns:form", "http://openoffice.org/2000/form");
-    docContentPropList.insert("xmlns:script", "http://openoffice.org/2000/script");
-    docContentPropList.insert("office:class", "text");
+    docContentPropList.insert("xmlns:form", "urn:oasis:names:tc:opendocument:xmlns:form:1.0");
+    docContentPropList.insert("xmlns:script", "urn:oasis:names:tc:opendocument:xmlns:script:1.0");
+    docContentPropList.insert("xmlns:style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
     docContentPropList.insert("office:version", "1.0");
-        mpHandler->startElement("office:document-content", docContentPropList);
+    docContentPropList.insert("office:mimetype", "application/vnd.oasis.opendocument.text");
+    mpHandler->startElement("office:document", docContentPropList);
+
+    // write out the metadata
+    TagOpenElement("office:meta").write(mpHandler);
+    for (std::vector<DocumentElement *>::const_iterator iterMetaData = mMetaData.begin(); iterMetaData != mMetaData.end(); iterMetaData++) {
+        (*iterMetaData)->write(mpHandler);
+    }
+    mpHandler->endElement("office:meta");
 
     // write out the font styles
-    mpHandler->startElement("office:font-decls", xBlankAttrList);
+    TagOpenElement("office:font-face-decls").write(mpHandler);
     for (std::map<WPXString, FontStyle *, ltstr>::iterator iterFont = mFontHash.begin(); iterFont != mFontHash.end(); iterFont++) {
         iterFont->second->write(mpHandler);
     }
-    TagOpenElement symbolFontOpen("style:font-decl");
+    TagOpenElement symbolFontOpen("style:font-face");
     symbolFontOpen.addAttribute("style:name", "StarSymbol");
-    symbolFontOpen.addAttribute("fo:font-family", "StarSymbol");
+    symbolFontOpen.addAttribute("svg:font-family", "StarSymbol");
     symbolFontOpen.addAttribute("style:font-charset", "x-symbol");
     symbolFontOpen.write(mpHandler);
-        mpHandler->endElement("style:font-decl");
-
-    mpHandler->endElement("office:font-decls");
+    mpHandler->endElement("style:font-face");
 
+    mpHandler->endElement("office:font-face-decls");
 
      WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Writing out the styles..\n"));
 
     // write default styles
     _writeDefaultStyles(mpHandler);
 
-    mpHandler->startElement("office:automatic-styles", xBlankAttrList);
+    TagOpenElement("office:automatic-styles").write(mpHandler);
 
-    for (std::map<WPXString, ParagraphStyle *, ltstr>::iterator iterTextStyle = mTextStyleHash.begin(); 
+    for (std::vector<DocumentElement *>::const_iterator iterFrameAutomaticStyles = mFrameAutomaticStyles.begin();
+        iterFrameAutomaticStyles != mFrameAutomaticStyles.end(); iterFrameAutomaticStyles++)
+    {
+        (*iterFrameAutomaticStyles)->write(pHandler);
+    }
+
+    for (std::map<WPXString, ParagraphStyle *, ltstr>::const_iterator iterTextStyle = mTextStyleHash.begin();
              iterTextStyle != mTextStyleHash.end(); iterTextStyle++) 
         {
         // writing out the paragraph styles
@@ -288,29 +340,29 @@ bool DocumentCollector::_writeTargetDocument(DocumentHandler *pHandler)
     }
 
         // span styles..
-    for (std::map<WPXString, SpanStyle *, ltstr>::iterator iterSpanStyle = mSpanStyleHash.begin(); 
+    for (std::map<WPXString, SpanStyle *, ltstr>::const_iterator iterSpanStyle = mSpanStyleHash.begin();
              iterSpanStyle != mSpanStyleHash.end(); iterSpanStyle++) 
         {
                 (iterSpanStyle->second)->write(pHandler);
     }
 
      // writing out the sections styles
-    for (std::vector<SectionStyle *>::iterator iterSectionStyles = mSectionStyles.begin(); iterSectionStyles != mSectionStyles.end(); iterSectionStyles++) {
+    for (std::vector<SectionStyle *>::const_iterator iterSectionStyles = mSectionStyles.begin(); iterSectionStyles != mSectionStyles.end(); iterSectionStyles++) {
         (*iterSectionStyles)->write(pHandler);
     }
 
     // writing out the lists styles
-    for (std::vector<ListStyle *>::iterator iterListStyles = mListStyles.begin(); iterListStyles != mListStyles.end(); iterListStyles++) {
+    for (std::vector<ListStyle *>::const_iterator iterListStyles = mListStyles.begin(); iterListStyles != mListStyles.end(); iterListStyles++) {
         (*iterListStyles)->write(pHandler);
     }
 
      // writing out the table styles
-    for (std::vector<TableStyle *>::iterator iterTableStyles = mTableStyles.begin(); iterTableStyles != mTableStyles.end(); iterTableStyles++) {
+    for (std::vector<TableStyle *>::const_iterator iterTableStyles = mTableStyles.begin(); iterTableStyles != mTableStyles.end(); iterTableStyles++) {
         (*iterTableStyles)->write(pHandler);
     }
 
     // writing out the page masters
-    _writePageMasters(pHandler);
+    _writePageLayouts(pHandler);
 
 
     pHandler->endElement("office:automatic-styles");
@@ -319,15 +371,17 @@ bool DocumentCollector::_writeTargetDocument(DocumentHandler *pHandler)
 
      WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Writing out the document..\n"));
      // writing out the document
-    pHandler->startElement("office:body", xBlankAttrList);
+    TagOpenElement("office:body").write(mpHandler);
+    TagOpenElement("office:text").write(mpHandler);
 
-    for (std::vector<DocumentElement *>::iterator iterBodyElements = mBodyElements.begin(); iterBodyElements != mBodyElements.end(); iterBodyElements++) {
+    for (std::vector<DocumentElement *>::const_iterator iterBodyElements = mBodyElements.begin(); iterBodyElements != mBodyElements.end(); iterBodyElements++) {
         (*iterBodyElements)->write(pHandler);
     }
      WRITER_DEBUG_MSG(("WriterWordPerfect: Document Body: Finished writing all doc els..\n"));
 
+    pHandler->endElement("office:text");
     pHandler->endElement("office:body");
-    pHandler->endElement("office:document-content");
+    pHandler->endElement("office:document");
 
     pHandler->endDocument();
 
@@ -375,11 +429,31 @@ void DocumentCollector::_allocateFontName(const WPXString & sFontName)
     }
 }
 
+void DocumentCollector::setDocumentMetaData(const WPXPropertyList &propList)
+{
+        WPXPropertyList::Iter i(propList);
+        for (i.rewind(); i.next(); )
+        {
+                // filter out libwpd elements
+                if (strncmp(i.key(), "libwpd", 6) != 0 && strncmp(i.key(), "dcterms", 7) != 0)
+        {
+            mMetaData.push_back(new TagOpenElement(i.key()));
+            WPXString sStringValue(i()->getStr(), true);
+            mMetaData.push_back(new CharDataElement(sStringValue.cstr()));
+            mMetaData.push_back(new TagCloseElement(i.key()));
+        }
+        }
+
+}
+
 void DocumentCollector::openPageSpan(const WPXPropertyList &propList)
 {
     PageSpan *pPageSpan = new PageSpan(propList);
     mPageSpans.push_back(pPageSpan);
     mpCurrentPageSpan = pPageSpan;
+    miNumPageStyles++;
+
+    mWriterDocumentStates.top().mbFirstParagraphInPageSpan = true;
 }
 
 void DocumentCollector::openHeader(const WPXPropertyList &propList)
@@ -419,16 +493,20 @@ void DocumentCollector::closeFooter()
 void DocumentCollector::openSection(const WPXPropertyList &propList, const WPXPropertyListVector &columns)
 {
         int iNumColumns = columns.count();
-    float fSectionMarginLeft = 0.0f;
-    float fSectionMarginRight = 0.0f;
+    double fSectionMarginLeft = 0.0;
+    double fSectionMarginRight = 0.0;
     if (propList["fo:margin-left"])
-        fSectionMarginLeft = propList["fo:margin-left"]->getFloat();
+        fSectionMarginLeft = propList["fo:margin-left"]->getDouble();
     if (propList["fo:margin-right"])
-        fSectionMarginRight = propList["fo:margin-right"]->getFloat();
+        fSectionMarginRight = propList["fo:margin-right"]->getDouble();
 
     if (iNumColumns > 1 || fSectionMarginLeft != 0 || fSectionMarginRight != 0)
     {
-        mfSectionSpaceAfter = propList["fo:margin-bottom"]->getFloat();
+        if (propList["fo:margin-bottom"])
+            mfSectionSpaceAfter = propList["fo:margin-bottom"]->getDouble();
+        else if (propList["libwpd:margin-bottom"])
+            mfSectionSpaceAfter =  propList["libwpd:margin-bottom"]->getDouble();
+
         WPXString sSectionName;
         sSectionName.sprintf("Section%i", mSectionStyles.size());
         
@@ -438,29 +516,20 @@ void DocumentCollector::openSection(const WPXPropertyList &propList, const WPXPr
         TagOpenElement *pSectionOpenElement = new TagOpenElement("text:section");
         pSectionOpenElement->addAttribute("text:style-name", pSectionStyle->getName());
         pSectionOpenElement->addAttribute("text:name", pSectionStyle->getName());
-        mpCurrentContentElements->push_back(static_cast<DocumentElement *>(pSectionOpenElement));
+        mpCurrentContentElements->push_back(pSectionOpenElement);
     }
     else
-        mWriterDocumentState.mbInFakeSection = true;
+        mWriterDocumentStates.top().mbInFakeSection = true;
 }
 
 void DocumentCollector::closeSection()
 {
-    if (!mWriterDocumentState.mbInFakeSection)
-        mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:section")));
+    if (!mWriterDocumentStates.top().mbInFakeSection)
+        mpCurrentContentElements->push_back(new TagCloseElement("text:section"));
     else
-        mWriterDocumentState.mbInFakeSection = false;
+        mWriterDocumentStates.top().mbInFakeSection = false;
 
-    // open as many paragraphs as needed to simulate section space after
-    // WLACH_REFACTORING: disable this for now..
-    #if 0
-    for (float f=0.0f; f<mfSectionSpaceAfter; f+=1.0f) {
-        vector<WPXTabStop> dummyTabStops;
-        openParagraph(WPX_PARAGRAPH_JUSTIFICATION_LEFT, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, dummyTabStops, false, false);
-        closeParagraph();
-    }
-    #endif
-    mfSectionSpaceAfter = 0.0f;
+    mfSectionSpaceAfter = 0.0;
 }
 
 void DocumentCollector::openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops)
@@ -471,7 +540,7 @@ void DocumentCollector::openParagraph(const WPXPropertyList &propList, const WPX
     WPXPropertyList *pPersistPropList = new WPXPropertyList(propList);
     ParagraphStyle *pStyle = NULL;
 
-    if (mWriterDocumentState.mbFirstElement && mpCurrentContentElements == &mBodyElements)
+    if (mWriterDocumentStates.top().mbFirstElement && mpCurrentContentElements == &mBodyElements)
     {
         // we don't have to go through the fuss of determining if the paragraph style is 
         // unique in this case, because if we are the first document element, then we
@@ -483,26 +552,36 @@ void DocumentCollector::openParagraph(const WPXPropertyList &propList, const WPX
         sName.sprintf("FS");
 
         WPXString sParagraphHashKey("P|FS");
-        pPersistPropList->insert("style:master-page-name", "Page Style 1");
+        pPersistPropList->insert("style:master-page-name", "Page_Style_1");
                 pStyle = new ParagraphStyle(pPersistPropList, tabStops, sName);
         mTextStyleHash[sParagraphHashKey] = pStyle;
-        mWriterDocumentState.mbFirstElement = false;
+        mWriterDocumentStates.top().mbFirstElement = false;
+        mWriterDocumentStates.top().mbFirstParagraphInPageSpan = false;
      }
     else
     {
-        if (mWriterDocumentState.mbTableCellOpened)
+        if (mWriterDocumentStates.top().mbFirstParagraphInPageSpan && mpCurrentContentElements == &mBodyElements)
         {
-            if (mWriterDocumentState.mbHeaderRow)
-                pPersistPropList->insert("style:parent-style-name", "Table Heading");
+            WPXString sPageStyleName;
+            sPageStyleName.sprintf("Page_Style_%i", miNumPageStyles);
+            pPersistPropList->insert("style:master-page-name", sPageStyleName);
+            mWriterDocumentStates.top().mbFirstParagraphInPageSpan = false;
+        }
+
+        if (mWriterDocumentStates.top().mbTableCellOpened)
+        {
+            if (mWriterDocumentStates.top().mbHeaderRow)
+                pPersistPropList->insert("style:parent-style-name", "Table_Heading");
             else
-                pPersistPropList->insert("style:parent-style-name", "Table Contents");
+                pPersistPropList->insert("style:parent-style-name", "Table_Contents");
         }
         else
             pPersistPropList->insert("style:parent-style-name", "Standard");
 
                 WPXString sKey = getParagraphStyleKey(*pPersistPropList, tabStops);
 
-        if (mTextStyleHash.find(sKey) == mTextStyleHash.end()) {
+        if (mTextStyleHash.find(sKey) == mTextStyleHash.end())
+        {
             WPXString sName;
             sName.sprintf("S%i", mTextStyleHash.size()); 
             
@@ -519,12 +598,12 @@ void DocumentCollector::openParagraph(const WPXPropertyList &propList, const WPX
     // create a document element corresponding to the paragraph, and append it to our list of document elements
     TagOpenElement *pParagraphOpenElement = new TagOpenElement("text:p");
     pParagraphOpenElement->addAttribute("text:style-name", pStyle->getName());
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(pParagraphOpenElement));
+    mpCurrentContentElements->push_back(pParagraphOpenElement);
 }
 
 void DocumentCollector::closeParagraph()
 {
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:p")));
+    mpCurrentContentElements->push_back(new TagCloseElement("text:p"));
 }
 
 void DocumentCollector::openSpan(const WPXPropertyList &propList)
@@ -552,12 +631,12 @@ void DocumentCollector::openSpan(const WPXPropertyList &propList)
     // create a document element corresponding to the paragraph, and append it to our list of document elements
     TagOpenElement *pSpanOpenElement = new TagOpenElement("text:span");
     pSpanOpenElement->addAttribute("text:style-name", sName.cstr());
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(pSpanOpenElement));
+    mpCurrentContentElements->push_back(pSpanOpenElement);
 }
 
 void DocumentCollector::closeSpan()
 {
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:span")));
+    mpCurrentContentElements->push_back(new TagCloseElement("text:span"));
 }
 
 void DocumentCollector::defineOrderedListLevel(const WPXPropertyList &propList)
@@ -567,8 +646,8 @@ void DocumentCollector::defineOrderedListLevel(const WPXPropertyList &propList)
                 id = propList["libwpd:id"]->getInt();
 
      OrderedListStyle *pOrderedListStyle = NULL;
-    if (mpCurrentListStyle && mpCurrentListStyle->getListID() == id)
-        pOrderedListStyle = static_cast<OrderedListStyle *>(mpCurrentListStyle); // FIXME: using a dynamic cast here causes oo to crash?!
+    if (mWriterListStates.top().mpCurrentListStyle && mWriterListStates.top().mpCurrentListStyle->getListID() == id)
+        pOrderedListStyle = static_cast<OrderedListStyle *>(mWriterListStates.top().mpCurrentListStyle); // FIXME: using a dynamic cast here causes oo to crash?!
 
     // this rather appalling conditional makes sure we only start a new list (rather than continue an old
     // one) if: (1) we have no prior list OR (2) the prior list is actually definitively different
@@ -576,27 +655,27 @@ void DocumentCollector::defineOrderedListLevel(const WPXPropertyList &propList)
     // is starting a new list at level 1 (and only level 1)
     if (pOrderedListStyle == NULL || pOrderedListStyle->getListID() != id  ||
         (propList["libwpd:level"] && propList["libwpd:level"]->getInt()==1 && 
-             (propList["text:start-value"] && (unsigned int)(propList["text:start-value"]->getInt()) != (miLastListNumber+1))))
+         (propList["text:start-value"] && propList["text:start-value"]->getInt() != (mWriterListStates.top().miLastListNumber+1))))
     {
         WRITER_DEBUG_MSG(("Attempting to create a new ordered list style (listid: %i)\n", id));
         WPXString sName;
         sName.sprintf("OL%i", miNumListStyles);
         miNumListStyles++;
-        pOrderedListStyle = new OrderedListStyle(sName.cstr(), propList["libwpd:id"]->getInt());
-        mListStyles.push_back(static_cast<ListStyle *>(pOrderedListStyle));
-        mpCurrentListStyle = static_cast<ListStyle *>(pOrderedListStyle);
-        mbListContinueNumbering = false;
-        miLastListNumber = 0;
+        pOrderedListStyle = new OrderedListStyle(sName.cstr(), id);
+        mListStyles.push_back(pOrderedListStyle);
+        mWriterListStates.top().mpCurrentListStyle = pOrderedListStyle;
+        mWriterListStates.top().mbListContinueNumbering = false;
+        mWriterListStates.top().miLastListNumber = 0;
     }
     else
-        mbListContinueNumbering = true;
+        mWriterListStates.top().mbListContinueNumbering = true;
 
     // Iterate through ALL list styles with the same WordPerfect list id and define a level if it is not already defined
     // This solves certain problems with lists that start and finish without reaching certain levels and then begin again
     // and reach those levels. See gradguide0405_PC.wpd in the regression suite
     for (std::vector<ListStyle *>::iterator iterOrderedListStyles = mListStyles.begin(); iterOrderedListStyles != mListStyles.end(); iterOrderedListStyles++)
     {
-        if ((* iterOrderedListStyles)->getListID() == propList["libwpd:id"]->getInt())
+        if ((* iterOrderedListStyles)->getListID() == id)
             (* iterOrderedListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList);
     }
 }
@@ -608,106 +687,114 @@ void DocumentCollector::defineUnorderedListLevel(const WPXPropertyList &propList
                 id = propList["libwpd:id"]->getInt();
 
      UnorderedListStyle *pUnorderedListStyle = NULL;
-    if (mpCurrentListStyle && mpCurrentListStyle->getListID() == id)
-        pUnorderedListStyle = static_cast<UnorderedListStyle *>(mpCurrentListStyle); // FIXME: using a dynamic cast here causes oo to crash?!
+    if (mWriterListStates.top().mpCurrentListStyle && mWriterListStates.top().mpCurrentListStyle->getListID() == id)
+        pUnorderedListStyle = static_cast<UnorderedListStyle *>(mWriterListStates.top().mpCurrentListStyle); // FIXME: using a dynamic cast here causes oo to crash?!
 
     if (pUnorderedListStyle == NULL) {
         WRITER_DEBUG_MSG(("Attempting to create a new unordered list style (listid: %i)\n", id));
         WPXString sName;
         sName.sprintf("UL%i", miNumListStyles);
+        miNumListStyles++;
         pUnorderedListStyle = new UnorderedListStyle(sName.cstr(), id);
-        mListStyles.push_back(static_cast<ListStyle *>(pUnorderedListStyle));
-        mpCurrentListStyle = static_cast<ListStyle *>(pUnorderedListStyle);
+        mListStyles.push_back(pUnorderedListStyle);
+        mWriterListStates.top().mpCurrentListStyle = pUnorderedListStyle;
     }
 
     // See comment in DocumentCollector::defineOrderedListLevel
     for (std::vector<ListStyle *>::iterator iterUnorderedListStyles = mListStyles.begin(); iterUnorderedListStyles != mListStyles.end(); iterUnorderedListStyles++)
     {
-        if ((* iterUnorderedListStyles)->getListID() == propList["libwpd:id"]->getInt())
+        if ((* iterUnorderedListStyles)->getListID() == id)
             (* iterUnorderedListStyles)->updateListLevel((propList["libwpd:level"]->getInt() - 1), propList);
     }
 }
 
 void DocumentCollector::openOrderedListLevel(const WPXPropertyList & /* propList */)
 {
-    miCurrentListLevel++;
-    TagOpenElement *pListLevelOpenElement = new TagOpenElement("text:ordered-list");
+    if (mWriterListStates.top().mbListElementParagraphOpened)
+    {
+        mpCurrentContentElements->push_back(new TagCloseElement("text:p"));
+        mWriterListStates.top().mbListElementParagraphOpened = false;
+    }
+    TagOpenElement *pListLevelOpenElement = new TagOpenElement("text:list");
     _openListLevel(pListLevelOpenElement);
 
-    if (mbListContinueNumbering) {
+    if (mWriterListStates.top().mbListContinueNumbering) {
         pListLevelOpenElement->addAttribute("text:continue-numbering", "true");
     }
 
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(pListLevelOpenElement));
+    mpCurrentContentElements->push_back(pListLevelOpenElement);
 }
 
 void DocumentCollector::openUnorderedListLevel(const WPXPropertyList & /* propList */)
 {
-    miCurrentListLevel++;
-    TagOpenElement *pListLevelOpenElement = new TagOpenElement("text:unordered-list");
+    if (mWriterListStates.top().mbListElementParagraphOpened)
+    {
+        mpCurrentContentElements->push_back(new TagCloseElement("text:p"));
+        mWriterListStates.top().mbListElementParagraphOpened = false;
+    }
+    TagOpenElement *pListLevelOpenElement = new TagOpenElement("text:list");
     _openListLevel(pListLevelOpenElement);
 
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(pListLevelOpenElement));
+    mpCurrentContentElements->push_back(pListLevelOpenElement);
 }
 
 void DocumentCollector::_openListLevel(TagOpenElement *pListLevelOpenElement)
 {
-      if (!mbListElementOpened && miCurrentListLevel > 1)
-      {
-          mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagOpenElement("text:list-item")));
-      }
-    else if (mbListElementParagraphOpened)
+    if (!mWriterListStates.top().mbListElementOpened.empty() &&
+        !mWriterListStates.top().mbListElementOpened.top())
     {
-        mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:p")));
-        mbListElementParagraphOpened = false;
+        mpCurrentContentElements->push_back(new TagOpenElement("text:list-item"));
+        mWriterListStates.top().mbListElementOpened.top() = true;
     }
 
-    if (miCurrentListLevel==1) {
-        pListLevelOpenElement->addAttribute("text:style-name", mpCurrentListStyle->getName());
+    mWriterListStates.top().mbListElementOpened.push(false);
+    if (mWriterListStates.top().mbListElementOpened.size() == 1) {
+        pListLevelOpenElement->addAttribute("text:style-name", mWriterListStates.top().mpCurrentListStyle->getName());
     }
-
-    mbListElementOpened = false;
 }
 
 void DocumentCollector::closeOrderedListLevel()
 {
-    _closeListLevel("ordered-list");
+    _closeListLevel();
 }
 
 void DocumentCollector::closeUnorderedListLevel()
 {
-    _closeListLevel("unordered-list");
+    _closeListLevel();
 }
 
-void DocumentCollector::_closeListLevel(const char *szListType)
+void DocumentCollector::_closeListLevel()
 {
-    if (mbListElementOpened)
-        mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:list-item")));
-
-    miCurrentListLevel--;
+    if (mWriterListStates.top().mbListElementOpened.top())
+    {
+        mpCurrentContentElements->push_back(new TagCloseElement("text:list-item"));
+        mWriterListStates.top().mbListElementOpened.top() = false;
+    }
 
-    WPXString sCloseElement;
-    sCloseElement.sprintf("text:%s", szListType);
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement(sCloseElement.cstr())));
+    mpCurrentContentElements->push_back(new TagCloseElement("text:list"));
 
-    if (miCurrentListLevel > 0)
-        mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:list-item")));
-    mbListElementOpened = false;
+    if (!mWriterListStates.top().mbListElementOpened.empty())
+    {
+        mWriterListStates.top().mbListElementOpened.pop();
+    }
 }
 
 void DocumentCollector::openListElement(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops)
 {
-    miLastListLevel = miCurrentListLevel;
-    if (miCurrentListLevel == 1)
-        miLastListNumber++;
+    mWriterListStates.top().miLastListLevel = mWriterListStates.top().miCurrentListLevel;
+    if (mWriterListStates.top().miCurrentListLevel == 1)
+        mWriterListStates.top().miLastListNumber++;
 
-    if (mbListElementOpened)
-        mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:list-item")));
+    if (mWriterListStates.top().mbListElementOpened.top())
+    {
+        mpCurrentContentElements->push_back(new TagCloseElement("text:list-item"));
+        mWriterListStates.top().mbListElementOpened.top() = false;
+    }
 
     ParagraphStyle *pStyle = NULL;
 
     WPXPropertyList *pPersistPropList = new WPXPropertyList(propList);
-    pPersistPropList->insert("style:list-style-name", mpCurrentListStyle->getName());
+    pPersistPropList->insert("style:list-style-name", mWriterListStates.top().mpCurrentListStyle->getName());
     pPersistPropList->insert("style:parent-style-name", "Standard");
 
         WPXString sKey = getParagraphStyleKey(*pPersistPropList, tabStops);
@@ -727,17 +814,18 @@ void DocumentCollector::openListElement(const WPXPropertyList &propList, const W
                 delete pPersistPropList;
         }
 
-    TagOpenElement *pOpenListElement = new TagOpenElement("text:list-item");
-    TagOpenElement *pOpenListElementParagraph = new TagOpenElement("text:p");
+    mpCurrentContentElements->push_back(new TagOpenElement("text:list-item"));
 
+    TagOpenElement *pOpenListElementParagraph = new TagOpenElement("text:p");
     pOpenListElementParagraph->addAttribute("text:style-name", pStyle->getName());
+    mpCurrentContentElements->push_back(pOpenListElementParagraph);
 
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(pOpenListElement));
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(pOpenListElementParagraph));
+    if (mpCurrentContentElements == &mBodyElements)
+        mWriterDocumentStates.top().mbFirstParagraphInPageSpan = false;
         
-    mbListElementOpened = true;
-    mbListElementParagraphOpened = true;
-    mbListContinueNumbering = false;
+    mWriterListStates.top().mbListElementOpened.top() = true;
+    mWriterListStates.top().mbListElementParagraphOpened = true;
+    mWriterListStates.top().mbListContinueNumbering = false;
 }
 
 void DocumentCollector::closeListElement()
@@ -746,69 +834,100 @@ void DocumentCollector::closeListElement()
     // could contain another list level in OOo's implementation of lists). that is done in the closeListLevel
     // code (or when we open another list element)
 
-    if (mbListElementParagraphOpened)
+    if (mWriterListStates.top().mbListElementParagraphOpened)
     {
-        mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:p")));
-        mbListElementParagraphOpened = false;
+        mpCurrentContentElements->push_back(new TagCloseElement("text:p"));
+        mWriterListStates.top().mbListElementParagraphOpened = false;
     }
 }
 
 void DocumentCollector::openFootnote(const WPXPropertyList &propList)
 {
-    TagOpenElement *pOpenFootNote = new TagOpenElement("text:footnote");
+    mWriterListStates.push(WriterListState());
+    TagOpenElement *pOpenFootNote = new TagOpenElement("text:note");
+    pOpenFootNote->addAttribute("text:note-class", "footnote");
     if (propList["libwpd:number"])
     {
         WPXString tmpString("ftn");
         tmpString.append(propList["libwpd:number"]->getStr());
         pOpenFootNote->addAttribute("text:id", tmpString);
     }
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(pOpenFootNote));
+    mpCurrentContentElements->push_back(pOpenFootNote);
 
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagOpenElement("text:footnote-citation")));
+    mpCurrentContentElements->push_back(new TagOpenElement("text:note-citation"));
         if (propList["libwpd:number"])
-                mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new CharDataElement(propList["libwpd:number"]->getStr().cstr())));
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:footnote-citation")));
+    mpCurrentContentElements->push_back(new CharDataElement(propList["libwpd:number"]->getStr().cstr()));
+    mpCurrentContentElements->push_back(new TagCloseElement("text:note-citation"));
 
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagOpenElement("text:footnote-body")));
+    mpCurrentContentElements->push_back(new TagOpenElement("text:note-body"));
     
-    mWriterDocumentState.mbInNote = true;
+    mWriterDocumentStates.top().mbInNote = true;
 }
 
 void DocumentCollector::closeFootnote()
 {
-    mWriterDocumentState.mbInNote = false;
+    mWriterDocumentStates.top().mbInNote = false;
+    if (mWriterListStates.size() > 1)
+        mWriterListStates.pop();
 
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:footnote-body")));
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:footnote")));
+    mpCurrentContentElements->push_back(new TagCloseElement("text:note-body"));
+    mpCurrentContentElements->push_back(new TagCloseElement("text:note"));
 }
 
 void DocumentCollector::openEndnote(const WPXPropertyList &propList)
 {
-    TagOpenElement *pOpenEndNote = new TagOpenElement("text:endnote");
+    mWriterListStates.push(WriterListState());
+    TagOpenElement *pOpenEndNote = new TagOpenElement("text:note");
+    pOpenEndNote->addAttribute("text:note-class", "endnote");
     if (propList["libwpd:number"])
     {
         WPXString tmpString("edn");
         tmpString.append(propList["libwpd:number"]->getStr());
         pOpenEndNote->addAttribute("text:id", tmpString);
     }
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(pOpenEndNote));
+    mpCurrentContentElements->push_back(pOpenEndNote);
 
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagOpenElement("text:endnote-citation")));
+    mpCurrentContentElements->push_back(new TagOpenElement("text:note-citation"));
         if (propList["libwpd:number"])
-                mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new CharDataElement(propList["libwpd:number"]->getStr().cstr())));
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:endnote-citation")));
+    mpCurrentContentElements->push_back(new CharDataElement(propList["libwpd:number"]->getStr().cstr()));
+    mpCurrentContentElements->push_back(new TagCloseElement("text:note-citation"));
 
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagOpenElement("text:endnote-body")));
+    mpCurrentContentElements->push_back(new TagOpenElement("text:note-body"));
 
+    mWriterDocumentStates.top().mbInNote = true;
 }
+
 void DocumentCollector::closeEndnote()
 {
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:endnote-body")));
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:endnote")));
+    mWriterDocumentStates.top().mbInNote = false;
+    if (mWriterListStates.size() > 1)
+        mWriterListStates.pop();
+
+    mpCurrentContentElements->push_back(new TagCloseElement("text:note-body"));
+    mpCurrentContentElements->push_back(new TagCloseElement("text:note"));
+}
+
+void DocumentCollector::openComment(const WPXPropertyList & /*propList*/)
+{
+    mWriterListStates.push(WriterListState());
+    mpCurrentContentElements->push_back(new TagOpenElement("office:annotation"));
+
+    mWriterDocumentStates.top().mbInNote = true;
+}
+
+void DocumentCollector::closeComment()
+{
+    mWriterDocumentStates.top().mbInNote = false;
+    if (mWriterListStates.size() > 1)
+        mWriterListStates.pop();
+
+    mpCurrentContentElements->push_back(new TagCloseElement("office:annotation"));
 }
 
 void DocumentCollector::openTable(const WPXPropertyList &propList, const WPXPropertyListVector &columns)
 {
+    if (!mWriterDocumentStates.top().mbInNote)
+    {
     WPXString sTableName;
     sTableName.sprintf("Table%i", mTableStyles.size());
 
@@ -817,11 +936,11 @@ void DocumentCollector::openTable(const WPXPropertyList &propList, const WPXProp
         // WLACH_REFACTORING: characterize this behaviour, probably should nip it at the bud within libwpd
     TableStyle *pTableStyle = new TableStyle(propList, columns, sTableName.cstr());
 
-    if (mWriterDocumentState.mbFirstElement && mpCurrentContentElements == &mBodyElements)
+    if (mWriterDocumentStates.top().mbFirstElement && mpCurrentContentElements == &mBodyElements)
     {
-        WPXString sMasterPageName("Page Style 1");
+        WPXString sMasterPageName("Page_Style_1");
         pTableStyle->setMasterPageName(sMasterPageName);
-        mWriterDocumentState.mbFirstElement = false;
+        mWriterDocumentStates.top().mbFirstElement = false;
     }
 
     mTableStyles.push_back(pTableStyle);
@@ -832,7 +951,7 @@ void DocumentCollector::openTable(const WPXPropertyList &propList, const WPXProp
 
     pTableOpenElement->addAttribute("table:name", sTableName.cstr());
     pTableOpenElement->addAttribute("table:style-name", sTableName.cstr());
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(pTableOpenElement));
+    mpCurrentContentElements->push_back(pTableOpenElement);
 
     for (int i=0; i<pTableStyle->getNumColumns(); i++) 
         {
@@ -846,13 +965,16 @@ void DocumentCollector::openTable(const WPXPropertyList &propList, const WPXProp
         mpCurrentContentElements->push_back(pTableColumnCloseElement);
     }
 }
+}
 
 void DocumentCollector::openTableRow(const WPXPropertyList &propList)
 {
+    if (!mWriterDocumentStates.top().mbInNote)
+    {
     if (propList["libwpd:is-header-row"] && (propList["libwpd:is-header-row"]->getInt()))
     {
-        mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagOpenElement("table:table-header-rows")));
-        mWriterDocumentState.mbHeaderRow = true;
+        mpCurrentContentElements->push_back(new TagOpenElement("table:table-header-rows"));
+        mWriterDocumentStates.top().mbHeaderRow = true;
     }
 
     WPXString sTableRowStyleName;
@@ -862,21 +984,27 @@ void DocumentCollector::openTableRow(const WPXPropertyList &propList)
     
     TagOpenElement *pTableRowOpenElement = new TagOpenElement("table:table-row");
     pTableRowOpenElement->addAttribute("table:style-name", sTableRowStyleName);
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(pTableRowOpenElement));
+    mpCurrentContentElements->push_back(pTableRowOpenElement);
+    }
 }
 
 void DocumentCollector::closeTableRow()
 {
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("table:table-row")));
-    if (mWriterDocumentState.mbHeaderRow)
+    if (!mWriterDocumentStates.top().mbInNote)
     {
-        mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("table:table-header-rows")));
-        mWriterDocumentState.mbHeaderRow = false;
+        mpCurrentContentElements->push_back(new TagCloseElement("table:table-row"));
+        if (mWriterDocumentStates.top().mbHeaderRow)
+        {
+            mpCurrentContentElements->push_back(new TagCloseElement("table:table-header-rows"));
+            mWriterDocumentStates.top().mbHeaderRow = false;
+        }
     }
 }
 
 void DocumentCollector::openTableCell(const WPXPropertyList &propList)
 {
+    if (!mWriterDocumentStates.top().mbInNote)
+    {
     WPXString sTableCellStyleName;
     sTableCellStyleName.sprintf( "%s.Cell%i", mpCurrentTableStyle->getName().cstr(), mpCurrentTableStyle->getNumTableCellStyles());
     TableCellStyle *pTableCellStyle = new TableCellStyle(propList, sTableCellStyleName.cstr());
@@ -890,39 +1018,72 @@ void DocumentCollector::openTableCell(const WPXPropertyList &propList)
         if (propList["table:number-rows-spanned"])
                 pTableCellOpenElement->addAttribute("table:number-rows-spanned",
                                                     propList["table:number-rows-spanned"]->getStr().cstr());
-    pTableCellOpenElement->addAttribute("table:value-type", "string");
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(pTableCellOpenElement));
+        // pTableCellOpenElement->addAttribute("table:value-type", "string");
+        mpCurrentContentElements->push_back(pTableCellOpenElement);
 
-    mWriterDocumentState.mbTableCellOpened = true;
+        mWriterDocumentStates.top().mbTableCellOpened = true;
+    }
 }
 
 void DocumentCollector::closeTableCell()
 {
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("table:table-cell")));
-    mWriterDocumentState.mbTableCellOpened = false;
+    if (!mWriterDocumentStates.top().mbInNote)
+    {
+        mpCurrentContentElements->push_back(new TagCloseElement("table:table-cell"));
+        mWriterDocumentStates.top().mbTableCellOpened = false;
+    }
 }
 
 void DocumentCollector::insertCoveredTableCell(const WPXPropertyList & /* propList */)
 {
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagOpenElement("table:covered-table-cell")));
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("table:covered-table-cell")));
+    if (!mWriterDocumentStates.top().mbInNote)
+    {
+        mpCurrentContentElements->push_back(new TagOpenElement("table:covered-table-cell"));
+        mpCurrentContentElements->push_back(new TagCloseElement("table:covered-table-cell"));
+    }
 }
 
 void DocumentCollector::closeTable()
 {
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("table:table")));
+    if (!mWriterDocumentStates.top().mbInNote)
+    {
+        mpCurrentContentElements->push_back(new TagCloseElement("table:table"));
+    }
 }
 
+
 void DocumentCollector::insertTab()
 {
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagOpenElement("text:tab-stop")));
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:tab-stop")));
+    mpCurrentContentElements->push_back(new TagOpenElement("text:tab"));
+    mpCurrentContentElements->push_back(new TagCloseElement("text:tab"));
+}
+
+void DocumentCollector::insertSpace()
+{
+    mpCurrentContentElements->push_back(new TagOpenElement("text:s"));
+    mpCurrentContentElements->push_back(new TagCloseElement("text:s"));
 }
 
 void DocumentCollector::insertLineBreak()
 {
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagOpenElement("text:line-break")));
-    mpCurrentContentElements->push_back(static_cast<DocumentElement *>(new TagCloseElement("text:line-break")));
+    mpCurrentContentElements->push_back(new TagOpenElement("text:line-break"));
+    mpCurrentContentElements->push_back(new TagCloseElement("text:line-break"));
+}
+
+void DocumentCollector::insertField(const WPXString &type, const WPXPropertyList &propList)
+{
+    if (!type.len())
+        return;
+
+    TagOpenElement *openElement = new TagOpenElement(type.cstr());
+    if (type == "text:page-number")
+        openElement->addAttribute("text:select-page", "current");
+
+    if (propList["style:num-format"])
+        openElement->addAttribute("style:num-format", propList["style:num-format"]->getStr());
+
+    mpCurrentContentElements->push_back(openElement);
+    mpCurrentContentElements->push_back(new TagCloseElement(type.cstr()));
 }
 
 void DocumentCollector::insertText(const WPXString &text)
@@ -931,4 +1092,221 @@ void DocumentCollector::insertText(const WPXString &text)
     mpCurrentContentElements->push_back(pText);
 }
 
+void DocumentCollector::openFrame(const WPXPropertyList &propList)
+{
+    mWriterListStates.push(WriterListState());
+
+    // First, let's create a Frame Style for this box
+    TagOpenElement *frameStyleOpenElement = new TagOpenElement("style:style");
+    WPXString frameStyleName;
+    frameStyleName.sprintf("GraphicFrame_%i", miObjectNumber);
+    frameStyleOpenElement->addAttribute("style:name", frameStyleName);
+    frameStyleOpenElement->addAttribute("style:family", "graphic");
+
+    mFrameStyles.push_back(frameStyleOpenElement);
+
+    TagOpenElement *frameStylePropertiesOpenElement = new TagOpenElement("style:graphic-properties");
+
+    if (propList["text:anchor-type"])
+        frameStylePropertiesOpenElement->addAttribute("text:anchor-type", propList["text:anchor-type"]->getStr());
+    else
+        frameStylePropertiesOpenElement->addAttribute("text:anchor-type","paragraph");
+
+    if (propList["text:anchor-page-number"])
+        frameStylePropertiesOpenElement->addAttribute("text:anchor-page-number", propList["text:anchor-page-number"]->getStr());
+
+    if (propList["svg:x"])
+        frameStylePropertiesOpenElement->addAttribute("svg:x", propList["svg:x"]->getStr());
+
+    if (propList["svg:y"])
+        frameStylePropertiesOpenElement->addAttribute("svg:y", propList["svg:y"]->getStr());
+
+    if (propList["svg:width"])
+        frameStylePropertiesOpenElement->addAttribute("svg:width", propList["svg:width"]->getStr());
+
+    if (propList["svg:height"])
+        frameStylePropertiesOpenElement->addAttribute("svg:height", propList["svg:height"]->getStr());
+
+    if (propList["style:rel-width"])
+        frameStylePropertiesOpenElement->addAttribute("style:rel-width", propList["style:rel-width"]->getStr());
+
+    if (propList["style:rel-height"])
+        frameStylePropertiesOpenElement->addAttribute("style:rel-height", propList["style:rel-height"]->getStr());
+
+    if (propList["fo:max-width"])
+        frameStylePropertiesOpenElement->addAttribute("fo:max-width", propList["fo:max-width"]->getStr());
+
+    if (propList["fo:max-height"])
+        frameStylePropertiesOpenElement->addAttribute("fo:max-height", propList["fo:max-height"]->getStr());
+
+    if (propList["style:wrap"])
+        frameStylePropertiesOpenElement->addAttribute("style:wrap", propList["style:wrap"]->getStr());
+
+    mFrameStyles.push_back(frameStylePropertiesOpenElement);
+
+    mFrameStyles.push_back(new TagCloseElement("style:graphic-properties"));
+
+    mFrameStyles.push_back(new TagCloseElement("style:style"));
+
+    // Now, let's create an automatic style for this frame
+    TagOpenElement *frameAutomaticStyleElement = new TagOpenElement("style:style");
+    WPXString frameAutomaticStyleName;
+    frameAutomaticStyleName.sprintf("fr%i", miObjectNumber);
+    frameAutomaticStyleElement->addAttribute("style:name", frameAutomaticStyleName);
+    frameAutomaticStyleElement->addAttribute("style:family", "graphic");
+    frameAutomaticStyleElement->addAttribute("style:parent-style-name", frameStyleName);
+
+    mFrameAutomaticStyles.push_back(frameAutomaticStyleElement);
+
+    TagOpenElement *frameAutomaticStylePropertiesElement = new TagOpenElement("style:graphic-properties");
+    if (propList["style:horizontal-pos"])
+        frameAutomaticStylePropertiesElement->addAttribute("style:horizontal-pos", propList["style:horizontal-pos"]->getStr());
+    else
+        frameAutomaticStylePropertiesElement->addAttribute("style:horizontal-pos", "left");
+
+    if (propList["style:horizontal-rel"])
+        frameAutomaticStylePropertiesElement->addAttribute("style:horizontal-rel", propList["style:horizontal-rel"]->getStr());
+    else
+        frameAutomaticStylePropertiesElement->addAttribute("style:horizontal-rel", "paragraph");
+
+    if (propList["style:vertical-pos"])
+        frameAutomaticStylePropertiesElement->addAttribute("style:vertical-pos", propList["style:vertical-pos"]->getStr());
+    else
+        frameAutomaticStylePropertiesElement->addAttribute("style:vertical-pos", "top");
+
+    if (propList["style:vertical-rel"])
+        frameAutomaticStylePropertiesElement->addAttribute("style:vertical-rel", propList["style:vertical-rel"]->getStr());
+    else
+        frameAutomaticStylePropertiesElement->addAttribute("style:vertical-rel", "page-content");
+
+    if (propList["fo:max-width"])
+        frameAutomaticStylePropertiesElement->addAttribute("fo:max-width", propList["fo:max-width"]->getStr());
+
+    if (propList["fo:max-height"])
+        frameAutomaticStylePropertiesElement->addAttribute("fo:max-height", propList["fo:max-height"]->getStr());
+
+    frameAutomaticStylePropertiesElement->addAttribute("draw:ole-draw-aspect", "1");
+
+    mFrameAutomaticStyles.push_back(frameAutomaticStylePropertiesElement);
+
+    mFrameAutomaticStyles.push_back(new TagCloseElement("style:graphic-properties"));
+
+    mFrameAutomaticStyles.push_back(new TagCloseElement("style:style"));
+
+    // And write the frame itself
+    TagOpenElement *drawFrameOpenElement = new TagOpenElement("draw:frame");
+
+    drawFrameOpenElement->addAttribute("draw:style-name", frameAutomaticStyleName);
+    WPXString objectName;
+    objectName.sprintf("Object%i", miObjectNumber++);
+    drawFrameOpenElement->addAttribute("draw:name", objectName);
+    if (propList["text:anchor-type"])
+        drawFrameOpenElement->addAttribute("text:anchor-type", propList["text:anchor-type"]->getStr());
+    else
+        drawFrameOpenElement->addAttribute("text:anchor-type","paragraph");
+
+    if (propList["text:anchor-page-number"])
+        drawFrameOpenElement->addAttribute("text:anchor-page-number", propList["text:anchor-page-number"]->getStr());
+
+    if (propList["svg:x"])
+        drawFrameOpenElement->addAttribute("svg:x", propList["svg:x"]->getStr());
+
+    if (propList["svg:y"])
+        drawFrameOpenElement->addAttribute("svg:y", propList["svg:y"]->getStr());
+
+    if (propList["svg:width"])
+        drawFrameOpenElement->addAttribute("svg:width", propList["svg:width"]->getStr());
+
+    if (propList["svg:height"])
+        drawFrameOpenElement->addAttribute("svg:height", propList["svg:height"]->getStr());
+
+    if (propList["style:rel-width"])
+        drawFrameOpenElement->addAttribute("style:rel-width", propList["style:rel-width"]->getStr());
+
+    if (propList["style:rel-height"])
+        drawFrameOpenElement->addAttribute("style:rel-height", propList["style:rel-height"]->getStr());
+
+    mpCurrentContentElements->push_back(drawFrameOpenElement);
+
+    mWriterDocumentStates.top().mbInFrame = true;
+}
+
+void DocumentCollector::closeFrame()
+{
+    if (mWriterListStates.size() > 1)
+        mWriterListStates.pop();
+
+    mpCurrentContentElements->push_back(new TagCloseElement("draw:frame"));
+
+    mWriterDocumentStates.top().mbInFrame = false;
+}
+
+void DocumentCollector::insertBinaryObject(const WPXPropertyList &propList, const WPXBinaryData &data)
+{
+    if (!data.size())
+        return;
+    if (!mWriterDocumentStates.top().mbInFrame) // Embedded objects without a frame simply don't make sense for us
+        return;
+    if (!propList["libwpd:mimetype"])
+        return;
+
+    if (propList["libwpd:mimetype"]->getStr() == "image/x-wpg")
+    {
+        std::vector<DocumentElement *> tmpContentElements;
+        InternalHandler tmpHandler(&tmpContentElements);
+        OdgExporter exporter(&tmpHandler);
+
+        libwpg::WPGFileFormat fileFormat = libwpg::WPG_AUTODETECT;
+
+        if (!libwpg::WPGraphics::isSupported(const_cast<WPXInputStream *>(data.getDataStream())))
+            fileFormat = libwpg::WPG_WPG1;
+
+        if (libwpg::WPGraphics::parse(const_cast<WPXInputStream *>(data.getDataStream()), &exporter, fileFormat) && !tmpContentElements.empty())
+        {
+            mpCurrentContentElements->push_back(new TagOpenElement("draw:object"));
+            for (std::vector<DocumentElement *>::const_iterator iter = tmpContentElements.begin(); iter != tmpContentElements.end(); iter++)
+                mpCurrentContentElements->push_back(*iter);
+            mpCurrentContentElements->push_back(new TagCloseElement("draw:object"));
+        }
+    }
+    else
+    {
+        mpCurrentContentElements->push_back(new TagOpenElement("draw:image"));
+
+        mpCurrentContentElements->push_back(new TagOpenElement("office:binary-data"));
+
+        WPXString binaryBase64Data = data.getBase64Data();
+
+        mpCurrentContentElements->push_back(new CharDataElement(binaryBase64Data.cstr()));
+
+        mpCurrentContentElements->push_back(new TagCloseElement("office:binary-data"));
+
+        mpCurrentContentElements->push_back(new TagCloseElement("draw:image"));
+    }
+}
+
+void DocumentCollector::openTextBox(const WPXPropertyList & /*propList*/)
+{
+    if (!mWriterDocumentStates.top().mbInFrame) // Text box without a frame simply doesn't make sense for us
+        return;
+    mWriterListStates.push(WriterListState());
+    mWriterDocumentStates.push(WriterDocumentState());
+    mpCurrentContentElements->push_back(new TagOpenElement("draw:text-box"));
+    mWriterDocumentStates.top().mbInTextBox = true;
+    mWriterDocumentStates.top().mbFirstElement = false;
+}
+
+void DocumentCollector::closeTextBox()
+{
+    if (!mWriterDocumentStates.top().mbInTextBox)
+        return;
+    if (mWriterListStates.size() > 1)
+        mWriterListStates.pop();
+    if (mWriterDocumentStates.size() > 1)
+        mWriterDocumentStates.pop();
+
+    mpCurrentContentElements->push_back(new TagCloseElement("draw:text-box"));
+}
+
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/filter/DocumentCollector.hxx b/writerperfect/source/filter/DocumentCollector.hxx
index 218cc68..619bc1d 100644
--- a/writerperfect/source/filter/DocumentCollector.hxx
+++ b/writerperfect/source/filter/DocumentCollector.hxx
@@ -46,8 +46,9 @@
 #include <stack>
 #include <string.h>
 
+#include "DocumentHandlerInterface.hxx"
+
 class DocumentElement;
-class DocumentHandler;
 class TagOpenElement;
 class FontStyle;
 class ListStyle;
@@ -64,11 +65,29 @@ struct _WriterDocumentState
     _WriterDocumentState();
 
     bool mbFirstElement;
+    bool mbFirstParagraphInPageSpan;
     bool mbInFakeSection;
     bool mbListElementOpenedAtCurrentLevel;
     bool mbTableCellOpened;
     bool mbHeaderRow;
     bool mbInNote;
+    bool mbInTextBox;
+    bool mbInFrame;
+};
+
+// list state
+typedef struct _WriterListState WriterListState;
+struct _WriterListState
+{
+    _WriterListState();
+
+    ListStyle *mpCurrentListStyle;
+    unsigned int miCurrentListLevel;
+    unsigned int miLastListLevel;
+    unsigned int miLastListNumber;
+    bool mbListContinueNumbering;
+    bool mbListElementParagraphOpened;
+    std::stack<bool> mbListElementOpened;
 };
 
 enum WriterListType { unordered, ordered };
@@ -81,20 +100,23 @@ struct ltstr
   }
 };
 
-class DocumentCollector : public WPXHLListenerImpl
+class DocumentCollector : public WPXDocumentInterface
 {
 public:
-    DocumentCollector(WPSInputStream *pInput, DocumentHandler *pHandler);
+    DocumentCollector(WPXInputStream *pInput, DocumentHandlerInterface *pHandler);
     virtual ~DocumentCollector();
     bool filter();
 
-     virtual void setDocumentMetaData(const WPXPropertyList & /* propList */) {}
+    // WPXDocumentInterface's callbacks
+    virtual void setDocumentMetaData(const WPXPropertyList &propList);
     virtual void startDocument() {}
     virtual void endDocument() {}
 
+    virtual void definePageStyle(const WPXPropertyList&) {}
     virtual void openPageSpan(const WPXPropertyList &propList);
     virtual void closePageSpan() {}
 
+    virtual void defineSectionStyle(const WPXPropertyList&, const WPXPropertyListVector&) {}
     virtual void openSection(const WPXPropertyList &propList, const WPXPropertyListVector &columns);
     virtual void closeSection();
 
@@ -103,16 +125,19 @@ public:
     virtual void openFooter(const WPXPropertyList &propList);
     virtual void closeFooter();
 
+    virtual void defineParagraphStyle(const WPXPropertyList&, const WPXPropertyListVector&) {}
     virtual void openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops);
     virtual void closeParagraph();
 
+    virtual void defineCharacterStyle(const WPXPropertyList&) {}
     virtual void openSpan(const WPXPropertyList &propList);
     virtual void closeSpan();
 
-
     virtual void insertTab();
+    virtual void insertSpace();
     virtual void insertText(const WPXString &text);
      virtual void insertLineBreak();
+    virtual void insertField(const WPXString &type, const WPXPropertyList &propList);
 
     virtual void defineOrderedListLevel(const WPXPropertyList &propList);
     virtual void defineUnorderedListLevel(const WPXPropertyList &propList);
@@ -127,6 +152,10 @@ public:
     virtual void closeFootnote();
     virtual void openEndnote(const WPXPropertyList &propList);
     virtual void closeEndnote();
+    virtual void openComment(const WPXPropertyList &propList);
+    virtual void closeComment();
+    virtual void openTextBox(const WPXPropertyList &propList);
+    virtual void closeTextBox();
 
      virtual void openTable(const WPXPropertyList &propList, const WPXPropertyListVector &columns);
      virtual void openTableRow(const WPXPropertyList &propList);
@@ -135,25 +164,34 @@ public:
     virtual void closeTableCell();
     virtual void insertCoveredTableCell(const WPXPropertyList &propList);
      virtual void closeTable();
-    virtual bool parseSourceDocument(WPSInputStream &input) = 0;
+
+    virtual void openFrame(const WPXPropertyList & propList);
+    virtual void closeFrame();
+
+    virtual void insertBinaryObject(const WPXPropertyList &propList, const WPXBinaryData &data);
+    virtual void insertEquation(const WPXPropertyList & /* propList */, const WPXString & /* data */) {}
+
+    virtual bool parseSourceDocument(WPXInputStream &input) = 0;
 
 protected:
     void _resetDocumentState();
-    bool _writeTargetDocument(DocumentHandler *pHandler);
-    void _writeDefaultStyles(DocumentHandler *pHandler);
-    void _writeMasterPages(DocumentHandler *pHandler);
-    void _writePageMasters(DocumentHandler *pHandler);
+    bool _writeTargetDocument(DocumentHandlerInterface *pHandler);
+    void _writeDefaultStyles(DocumentHandlerInterface *pHandler);
+    void _writeMasterPages(DocumentHandlerInterface *pHandler);
+    void _writePageLayouts(DocumentHandlerInterface *pHandler);
     void _allocateFontName(const WPXString &);
 
 private:
     void _openListLevel(TagOpenElement *pListLevelOpenElement);
-    void _closeListLevel(const char *szListType);
+    void _closeListLevel();
 
-        WPSInputStream *mpInput;
-        DocumentHandler *mpHandler;
+    WPXInputStream *mpInput;
+    DocumentHandlerInterface *mpHandler;
     bool mbUsed; // whether or not it has been before (you can only use me once!)
 
-    WriterDocumentState mWriterDocumentState;
+    std::stack<WriterDocumentState> mWriterDocumentStates;
+

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list