[ooo-build-commit] .: filter/source writerperfect/source

Fridrich Strba fridrich at kemper.freedesktop.org
Tue Sep 14 23:45:57 PDT 2010


 filter/source/config/fragments/filters/MS_Works.xcu                |   13 
 filter/source/config/fragments/filters/WordPerfectGraphics.xcu     |   13 
 filter/source/config/fragments/types/draw_WordPerfect_Graphics.xcu |   12 
 filter/source/config/fragments/types/writer_MS_Works_Document.xcu  |   12 
 writerperfect/source/wpgimp/OdgExporter.cxx                        |  510 ++++++++++
 writerperfect/source/wpgimp/OdgExporter.hxx                        |   78 +
 writerperfect/source/wpgimp/WPGImportFilter.cxx                    |  302 +++++
 writerperfect/source/wpgimp/WPGImportFilter.hxx                    |  128 ++
 writerperfect/source/wpgimp/makefile.mk                            |   35 
 writerperfect/source/wpgimp/wpgimport_genericfilter.cxx            |  101 +
 writerperfect/source/wpsimp/MSWorksCollector.cxx                   |   48 
 writerperfect/source/wpsimp/MSWorksCollector.hxx                   |   41 
 writerperfect/source/wpsimp/MSWorksImportFilter.cxx                |  277 +++++
 writerperfect/source/wpsimp/MSWorksImportFilter.hxx                |  129 ++
 writerperfect/source/wpsimp/makefile.mk                            |   29 
 writerperfect/source/wpsimp/msworks_genericfilter.cxx              |  101 +
 16 files changed, 1829 insertions(+)

New commits:
commit 0f2ebd417c72a38f52b3afc23b2aab277efed3a7
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Wed Sep 15 08:28:44 2010 +0200

    Committing the files for WPG and WPS importer I forgot to commit yesterday

diff --git a/filter/source/config/fragments/filters/MS_Works.xcu b/filter/source/config/fragments/filters/MS_Works.xcu
new file mode 100644
index 0000000..29d11f7
--- /dev/null
+++ b/filter/source/config/fragments/filters/MS_Works.xcu
@@ -0,0 +1,13 @@
+    <node oor:name="MS_Works" oor:op="replace">
+        <prop oor:name="Flags"><value>IMPORT ALIEN USESOPTIONS 3RDPARTYFILTER</value></prop>
+        <prop oor:name="UIComponent"/>
+        <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.MSWorksImportFilter</value></prop>
+        <prop oor:name="UserData"><value>WPS</value></prop>
+        <prop oor:name="UIName">
+            <value xml:lang="x-default">Microsoft Works Document</value>
+        </prop>
+        <prop oor:name="FileFormatVersion"><value>0</value></prop>
+        <prop oor:name="Type"><value>writer_MS_Works_Document</value></prop>
+        <prop oor:name="TemplateName"/>
+        <prop oor:name="DocumentService"><value>com.sun.star.text.TextDocument</value></prop>
+    </node>
diff --git a/filter/source/config/fragments/filters/WordPerfectGraphics.xcu b/filter/source/config/fragments/filters/WordPerfectGraphics.xcu
new file mode 100644
index 0000000..9e5d002
--- /dev/null
+++ b/filter/source/config/fragments/filters/WordPerfectGraphics.xcu
@@ -0,0 +1,13 @@
+    <node oor:name="WordPerfect Graphics" oor:op="replace">
+        <prop oor:name="Flags"><value>IMPORT ALIEN USESOPTIONS 3RDPARTYFILTER PREFERRED</value></prop>
+        <prop oor:name="UIComponent"/>
+        <prop oor:name="FilterService"><value>com.sun.star.comp.Draw.WPGImportFilter</value></prop>
+        <prop oor:name="UserData"><value></value></prop>
+        <prop oor:name="UIName">
+            <value xml:lang="x-default">WordPerfect Graphics</value>
+        </prop>
+        <prop oor:name="FileFormatVersion"><value>0</value></prop>
+        <prop oor:name="Type"><value>draw_WordPerfect_Graphics</value></prop>
+        <prop oor:name="TemplateName"/>
+        <prop oor:name="DocumentService"><value>com.sun.star.drawing.DrawingDocument</value></prop>
+    </node>
diff --git a/filter/source/config/fragments/types/draw_WordPerfect_Graphics.xcu b/filter/source/config/fragments/types/draw_WordPerfect_Graphics.xcu
new file mode 100644
index 0000000..4968294
--- /dev/null
+++ b/filter/source/config/fragments/types/draw_WordPerfect_Graphics.xcu
@@ -0,0 +1,12 @@
+        <node oor:name="draw_WordPerfect_Graphics" oor:op="replace" >
+            <prop oor:name="DetectService"><value>com.sun.star.comp.Draw.WPGImportFilter</value></prop>
+            <prop oor:name="URLPattern"/>
+            <prop oor:name="Extensions"><value>wpg</value></prop>
+            <prop oor:name="MediaType"><value>image/x-wpg</value></prop>
+            <prop oor:name="Preferred"><value>true</value></prop>
+            <prop oor:name="PreferredFilter"><value>WordPerfect Graphics</value></prop>
+            <prop oor:name="UIName">
+                <value>WordPerfect Graphics</value>
+            </prop>
+            <prop oor:name="ClipboardFormat"/>
+        </node>
diff --git a/filter/source/config/fragments/types/writer_MS_Works_Document.xcu b/filter/source/config/fragments/types/writer_MS_Works_Document.xcu
new file mode 100644
index 0000000..0b074d8
--- /dev/null
+++ b/filter/source/config/fragments/types/writer_MS_Works_Document.xcu
@@ -0,0 +1,12 @@
+    <node oor:name="writer_MS_Works_Document" oor:op="replace" >
+        <prop oor:name="DetectService"><value>com.sun.star.comp.Writer.MSWorksImportFilter</value></prop>
+        <prop oor:name="URLPattern"/>
+        <prop oor:name="Extensions"><value>wps</value></prop>
+        <prop oor:name="MediaType"/>
+        <prop oor:name="Preferred"><value>true</value></prop>
+        <prop oor:name="PreferredFilter"><value>MS_Works</value></prop>
+        <prop oor:name="UIName">
+            <value>Microsoft Works Document</value>
+        </prop>
+        <prop oor:name="ClipboardFormat"/>
+    </node>
diff --git a/writerperfect/source/wpgimp/OdgExporter.cxx b/writerperfect/source/wpgimp/OdgExporter.cxx
new file mode 100644
index 0000000..d87ce08
--- /dev/null
+++ b/writerperfect/source/wpgimp/OdgExporter.cxx
@@ -0,0 +1,510 @@
+/* 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());
+}
diff --git a/writerperfect/source/wpgimp/OdgExporter.hxx b/writerperfect/source/wpgimp/OdgExporter.hxx
new file mode 100644
index 0000000..881acb4
--- /dev/null
+++ b/writerperfect/source/wpgimp/OdgExporter.hxx
@@ -0,0 +1,78 @@
+/* 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__
diff --git a/writerperfect/source/wpgimp/WPGImportFilter.cxx b/writerperfect/source/wpgimp/WPGImportFilter.cxx
new file mode 100644
index 0000000..5d890be
--- /dev/null
+++ b/writerperfect/source/wpgimp/WPGImportFilter.cxx
@@ -0,0 +1,302 @@
+/* WPGImportFilter: Sets up the filter, and calls OdgExporter
+ * to do the actual filtering
+ *
+ * Copyright (C) 2000 by Sun Microsystems, Inc.
+ * Copyright (C) 2002-2004 William Lachance (wlach at interlog.com)
+ * Copyright (C) 2004 Net Integration Technologies (http://www.net-itech.com)
+ * Copyright (C) 2004-2006 Fridrich Strba <fridrich.strba at bluewin.ch>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ *  Contributor(s): Martin Gallwey (gallwey at sun.com)
+ *
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#include <osl/diagnose.h>
+#include <rtl/tencinfo.h>
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/InputSource.hpp>
+#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XSeekable.hpp>
+#include <com/sun/star/uno/Reference.h>
+
+#include <xmloff/attrlist.hxx>
+
+#include "filter/DocumentHandler.hxx"
+#include "OdgExporter.hxx"
+#include "WPGImportFilter.hxx"
+#include "stream/WPXSvStream.h"
+
+#include <iostream>
+
+using namespace ::com::sun::star::uno;
+using com::sun::star::uno::Reference;
+using com::sun::star::io::XInputStream;
+using com::sun::star::io::XSeekable;
+using com::sun::star::uno::Sequence;
+using namespace ::rtl;
+using rtl::OString;
+using rtl::OUString;
+using com::sun::star::uno::Sequence;
+using com::sun::star::uno::Reference;
+using com::sun::star::uno::Any;
+using com::sun::star::uno::UNO_QUERY;
+using com::sun::star::uno::XInterface;
+using com::sun::star::uno::Exception;
+using com::sun::star::uno::RuntimeException;
+using com::sun::star::lang::XMultiServiceFactory;
+using com::sun::star::beans::PropertyValue;
+using com::sun::star::document::XFilter;
+using com::sun::star::document::XExtendedFilterDetection;
+
+using com::sun::star::io::XInputStream;
+using com::sun::star::document::XImporter;
+using com::sun::star::xml::sax::InputSource;
+using com::sun::star::xml::sax::XAttributeList;
+using com::sun::star::xml::sax::XDocumentHandler;
+using com::sun::star::xml::sax::XParser;
+
+
+sal_Bool SAL_CALL WPGImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+    throw (RuntimeException)
+{
+#ifdef DEBUG
+    std::cerr << "WPGImportFilter::filter" << std::endl;
+#endif
+    sal_Int32 nLength = aDescriptor.getLength();
+    const PropertyValue * pValue = aDescriptor.getConstArray();
+    OUString sURL;
+    Reference < XInputStream > xInputStream;
+    for ( sal_Int32 i = 0 ; i < nLength; i++)
+    {
+        if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "InputStream" ) ) )
+        pValue[i].Value >>= xInputStream;
+        else if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "URL" ) ) )
+        pValue[i].Value >>= sURL;
+    }
+    if ( !xInputStream.is() )
+    {
+        OSL_ASSERT( 0 );
+        return sal_False;
+    }
+    OString sFileName;
+    sFileName = OUStringToOString(sURL, RTL_TEXTENCODING_INFO_ASCII);
+
+    // An XML import service: what we push sax messages to..
+    OUString sXMLImportService ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Draw.XMLOasisImporter" ) );
+    Reference < XDocumentHandler > xInternalHandler( mxMSF->createInstance( sXMLImportService ), UNO_QUERY );
+
+    // The XImporter sets up an empty target document for XDocumentHandler to write to..
+    Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY);
+    xImporter->setTargetDocument( mxDoc );
+
+    // OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here
+    // writes to in-memory target doc
+    DocumentHandler xHandler(xInternalHandler);
+
+    WPXInputStream* input = new WPXSvInputStream( xInputStream );
+
+    if (input->isOLEStream())
+    {
+        WPXInputStream* olestream = input->getDocumentOLEStream();
+        if (olestream)
+        {
+            delete input;
+            input = olestream;
+        }
+    }
+
+    OdgExporter exporter(&xHandler);
+    bool tmpParseResult = libwpg::WPGraphics::parse(input, &exporter);
+    if (input)
+        delete input;
+    xInputStream->closeInput();
+    return tmpParseResult;
+}
+
+void SAL_CALL WPGImportFilter::cancel(  )
+    throw (RuntimeException)
+{
+#ifdef DEBUG
+    std::cerr << "WPGImportFilter::cancel" << std::endl;
+#endif
+}
+
+// XImporter
+void SAL_CALL WPGImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc )
+    throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
+{
+#ifdef DEBUG
+    std::cerr << "WPGImportFilter::setTargetDocument" << std::endl;
+#endif
+    meType = FILTER_IMPORT;
+    mxDoc = xDoc;
+}
+
+// XExtendedFilterDetection
+OUString SAL_CALL WPGImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor )
+    throw( com::sun::star::uno::RuntimeException )
+{
+#ifdef DEBUG
+    std::cerr << "WPGImportFilter::detect" << std::endl;
+#endif
+    OUString sTypeName = OUString( RTL_CONSTASCII_USTRINGPARAM ( "" ) );
+    sal_Int32 nLength = Descriptor.getLength();
+    sal_Int32 location = nLength;
+    const PropertyValue * pValue = Descriptor.getConstArray();
+    Reference < XInputStream > xInputStream;
+    for ( sal_Int32 i = 0 ; i < nLength; i++)
+    {
+        if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "TypeName" ) ) )
+            location=i;
+        else if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "InputStream" ) ) )
+            pValue[i].Value >>= xInputStream;
+    }
+
+    WPXInputStream* input = new WPXSvInputStream( xInputStream );
+
+    if (input->isOLEStream())
+    {
+        WPXInputStream* olestream = input->getDocumentOLEStream();
+        if (olestream)
+        {
+            delete input;
+            input = olestream;
+        }
+    }
+
+    if (libwpg::WPGraphics::isSupported(input))
+        sTypeName = OUString( RTL_CONSTASCII_USTRINGPARAM ( "draw_WordPerfect_Graphics" ) );
+
+    if (input)
+        delete input;
+
+    if (!sTypeName.equalsAscii(""))
+    {
+        if ( location == Descriptor.getLength() )
+        {
+            Descriptor.realloc(nLength+1);
+            Descriptor[location].Name = ::rtl::OUString::createFromAscii( "TypeName" );
+        }
+
+        Descriptor[location].Value <<=sTypeName;
+    }
+    return sTypeName;
+}
+
+
+// XInitialization
+void SAL_CALL WPGImportFilter::initialize( const Sequence< Any >& aArguments )
+    throw (Exception, RuntimeException)
+{
+#ifdef DEBUG
+    std::cerr << "WPGImportFilter::initialize" << std::endl;
+#endif
+    Sequence < PropertyValue > aAnySeq;
+    sal_Int32 nLength = aArguments.getLength();
+    if ( nLength && ( aArguments[0] >>= aAnySeq ) )
+    {
+        const PropertyValue * pValue = aAnySeq.getConstArray();
+        nLength = aAnySeq.getLength();
+        for ( sal_Int32 i = 0 ; i < nLength; i++)
+        {
+            if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Type" ) ) )
+            {
+                pValue[i].Value >>= msFilterName;
+                break;
+            }
+        }
+    }
+}
+OUString WPGImportFilter_getImplementationName ()
+    throw (RuntimeException)
+{
+#ifdef DEBUG
+    std::cerr << "WPGImportFilter_getImplementationName" << std::endl;
+#endif
+    return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Draw.WPGImportFilter" ) );
+}
+
+#define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
+#define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
+sal_Bool SAL_CALL WPGImportFilter_supportsService( const OUString& ServiceName )
+    throw (RuntimeException)
+{
+#ifdef DEBUG
+    std::cerr << "WPGImportFilter_supportsService" << std::endl;
+#endif
+    return (ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME1 ) ) ||
+        ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME2 ) ) );
+}
+Sequence< OUString > SAL_CALL WPGImportFilter_getSupportedServiceNames(  )
+    throw (RuntimeException)
+{
+#ifdef DEBUG
+    std::cerr << "WPGImportFilter_getSupportedServiceNames" << std::endl;
+#endif
+    Sequence < OUString > aRet(2);
+    OUString* pArray = aRet.getArray();
+    pArray[0] =  OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME1 ) );
+    pArray[1] =  OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME2 ) );
+    return aRet;
+}
+#undef SERVICE_NAME2
+#undef SERVICE_NAME1
+
+Reference< XInterface > SAL_CALL WPGImportFilter_createInstance( const Reference< XMultiServiceFactory > & rSMgr)
+    throw( Exception )
+{
+#ifdef DEBUG
+    std::cerr << "WPGImportFilter_createInstance" << std::endl;
+#endif
+    return (cppu::OWeakObject*) new WPGImportFilter( rSMgr );
+}
+
+// XServiceInfo
+OUString SAL_CALL WPGImportFilter::getImplementationName(  )
+    throw (RuntimeException)
+{
+#ifdef DEBUG
+    std::cerr << "WPGImportFilter::getImplementationName" << std::endl;
+#endif
+    return WPGImportFilter_getImplementationName();
+}
+sal_Bool SAL_CALL WPGImportFilter::supportsService( const OUString& rServiceName )
+    throw (RuntimeException)
+{
+#ifdef DEBUG
+    std::cerr << "WPGImportFilter::supportsService" << std::endl;
+#endif
+    return WPGImportFilter_supportsService( rServiceName );
+}
+Sequence< OUString > SAL_CALL WPGImportFilter::getSupportedServiceNames(  )
+    throw (RuntimeException)
+{
+#ifdef DEBUG
+    std::cerr << "WPGImportFilter::getSupportedServiceNames" << std::endl;
+#endif
+    return WPGImportFilter_getSupportedServiceNames();
+}
diff --git a/writerperfect/source/wpgimp/WPGImportFilter.hxx b/writerperfect/source/wpgimp/WPGImportFilter.hxx
new file mode 100644
index 0000000..e200b2b
--- /dev/null
+++ b/writerperfect/source/wpgimp/WPGImportFilter.hxx
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2000 by Sun Microsystems, Inc.
+ * Copyright (C) 2002-2004 William Lachance (wlach at interlog.com)
+ * Copyright (C) 2004 Net Integration Technologies (http://www.net-itech.com)
+ * Copyright (C) 2004 Fridrich Strba <fridrich.strba at bluewin.ch>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ *  Contributor(s): Martin Gallwey (gallwey at sun.com)
+ *
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+#ifndef _WPGIMPORTFILTER_HXX
+#define _WPGIMPORTFILTER_HXX
+
+#ifndef _COM_SUN_STAR_DOCUMENT_XFILTER_HPP_
+#include <com/sun/star/document/XFilter.hpp>
+#endif
+#ifndef _COM_SUN_STAR_DOCUMENT_XIMPORTER_HPP_
+#include <com/sun/star/document/XImporter.hpp>
+#endif
+#ifndef _COM_SUN_STAR_DOCUMENT_XEXTENDEDFILTERDETECTION_HPP_
+#include <com/sun/star/document/XExtendedFilterDetection.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
+#include <com/sun/star/lang/XInitialization.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#endif
+#ifndef _CPPUHELPER_IMPLBASE5_HXX_
+#include <cppuhelper/implbase5.hxx>
+#endif
+
+#include <stdio.h>
+
+enum FilterType
+{
+    FILTER_IMPORT,
+    FILTER_EXPORT
+};
+/* This component will be instantiated for both import or export. Whether it calls
+ * setSourceDocument or setTargetDocument determines which Impl function the filter
+ * member calls */
+class WPGImportFilter : public cppu::WeakImplHelper5
+<
+    com::sun::star::document::XFilter,
+    com::sun::star::document::XImporter,
+    com::sun::star::document::XExtendedFilterDetection,
+    com::sun::star::lang::XInitialization,
+    com::sun::star::lang::XServiceInfo
+>
+{
+protected:
+    // oo.org declares
+    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
+    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mxDoc;
+    ::rtl::OUString msFilterName;
+    ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > mxHandler;
+
+    FilterType meType;
+
+public:
+    WPGImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF)
+    : mxMSF( rxMSF ) {}
+    virtual ~WPGImportFilter() {}
+
+    // XFilter
+    virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+        throw (::com::sun::star::uno::RuntimeException);
+    virtual void SAL_CALL cancel(  )
+        throw (::com::sun::star::uno::RuntimeException);
+
+    // XImporter
+    virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
+        throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
+
+    //XExtendedFilterDetection
+    virtual ::rtl::OUString SAL_CALL detect( com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& Descriptor )
+        throw( com::sun::star::uno::RuntimeException );
+
+    // XInitialization
+    virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
+        throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+
+    // XServiceInfo
+    virtual ::rtl::OUString SAL_CALL getImplementationName(  )
+        throw (::com::sun::star::uno::RuntimeException);
+    virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
+        throw (::com::sun::star::uno::RuntimeException);
+    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
+        throw (::com::sun::star::uno::RuntimeException);
+
+};
+
+::rtl::OUString WPGImportFilter_getImplementationName()
+    throw ( ::com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL WPGImportFilter_supportsService( const ::rtl::OUString& ServiceName )
+    throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL WPGImportFilter_getSupportedServiceNames(  )
+    throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
+SAL_CALL WPGImportFilter_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
+    throw ( ::com::sun::star::uno::Exception );
+
+#endif
diff --git a/writerperfect/source/wpgimp/makefile.mk b/writerperfect/source/wpgimp/makefile.mk
new file mode 100644
index 0000000..3bb58c1
--- /dev/null
+++ b/writerperfect/source/wpgimp/makefile.mk
@@ -0,0 +1,35 @@
+PRJ=..$/..
+
+PRJNAME=writerperfect
+TARGET=wpgimp
+ENABLE_EXCEPTIONS=true
+
+.INCLUDE :  settings.mk
+
+.IF "$(SYSTEM_LIBWPD)" == "YES"
+INCPRE+=$(LIBWPD_CFLAGS)
+.ELSE
+INCPRE+=$(SOLARVER)$/$(UPD)$/$(INPATH)$/inc$/libwpd
+.ENDIF
+
+.IF "$(SYSTEM_LIBWPS)" == "YES"
+INCPRE+=$(LIBWPS_CFLAGS)
+.ELSE
+INCPRE+=$(SOLARVER)$/$(UPD)$/$(INPATH)$/inc$/libwps
+.ENDIF
+
+.IF "$(SYSTEM_LIBWPG)" == "YES"
+INCPRE+=$(LIBWPG_CFLAGS)
+.ELSE
+INCPRE+=$(SOLARVER)$/$(UPD)$/$(INPATH)$/inc$/libwpg
+.ENDIF
+
+# broken but ... necessary, internal include shafted ...
+INCPRE+= -I..
+
+SLOFILES= \
+    $(SLO)$/OdgExporter.obj  \
+    $(SLO)$/WPGImportFilter.obj \
+    $(SLO)$/wpgimport_genericfilter.obj
+
+.INCLUDE :  target.mk
diff --git a/writerperfect/source/wpgimp/wpgimport_genericfilter.cxx b/writerperfect/source/wpgimp/wpgimport_genericfilter.cxx
new file mode 100644
index 0000000..4666abd
--- /dev/null
+++ b/writerperfect/source/wpgimp/wpgimport_genericfilter.cxx
@@ -0,0 +1,101 @@
+/* genericfilter: mostly generic code for registering the filter
+ *
+ * Portions of this code Copyright 2000 by Sun Microsystems, Inc.
+ * Rest is Copyright (C) 2002 William Lachance (wlach at interlog.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+#include <stdio.h>
+
+#include <osl/mutex.hxx>
+#include <osl/thread.h>
+#include <cppuhelper/factory.hxx>
+
+#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#endif
+
+#include "WPGImportFilter.hxx"
+
+using namespace ::rtl;
+using namespace ::cppu;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::registry;
+
+extern "C"
+{
+//==================================================================================================
+void SAL_CALL component_getImplementationEnvironment(
+    const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */ )
+{
+    *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+}
+//==================================================================================================
+sal_Bool SAL_CALL component_writeInfo(
+    void * /* pServiceManager */, void * pRegistryKey )
+{
+    if (pRegistryKey)
+    {
+        try
+        {
+            sal_Int32 nPos = 0;
+            Reference< XRegistryKey > xNewKey(
+                reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( WPGImportFilter_getImplementationName() ) );
+            xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
+
+            const Sequence< OUString > & rSNL = WPGImportFilter_getSupportedServiceNames();
+            const OUString * pArray = rSNL.getConstArray();
+            for ( nPos = rSNL.getLength(); nPos--; )
+                xNewKey->createKey( pArray[nPos] );
+
+            return sal_True;
+        }
+        catch (InvalidRegistryException &)
+        {
+            OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
+        }
+    }
+    return sal_False;
+}
+//==================================================================================================
+void * SAL_CALL component_getFactory(
+    const sal_Char * pImplName, void * pServiceManager, void * /* pRegistryKey */ )
+{
+    void * pRet = 0;
+
+    OUString implName = OUString::createFromAscii( pImplName );
+    if ( pServiceManager && implName.equals(WPGImportFilter_getImplementationName()) )
+    {
+        Reference< XSingleServiceFactory > xFactory( createSingleFactory(
+            reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+            OUString::createFromAscii( pImplName ),
+            WPGImportFilter_createInstance, WPGImportFilter_getSupportedServiceNames() ) );
+
+        if (xFactory.is())
+        {
+            xFactory->acquire();
+            pRet = xFactory.get();
+        }
+    }
+
+    return pRet;
+}
+}
diff --git a/writerperfect/source/wpsimp/MSWorksCollector.cxx b/writerperfect/source/wpsimp/MSWorksCollector.cxx
new file mode 100644
index 0000000..f562365
--- /dev/null
+++ b/writerperfect/source/wpsimp/MSWorksCollector.cxx
@@ -0,0 +1,48 @@
+/* MSWorksCollector: Collects sections and runs of text from a
+ * wordperfect file (and styles to go along with them) and writes them
+ * to a Writer target document
+ *
+ * Copyright (C) 2006 Fridrich Strba (fridrich.strba at bluewin.ch)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ * For further information visit http://libwpd.sourceforge.net
+ *
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#include "MSWorksCollector.hxx"
+#include <libwps/WPSDocument.h>
+
+MSWorksCollector::MSWorksCollector(WPSInputStream *pInput, DocumentHandler *pHandler) :
+    DocumentCollector(pInput, pHandler)
+{
+}
+
+MSWorksCollector::~MSWorksCollector()
+{
+}
+
+bool MSWorksCollector::parseSourceDocument(WPSInputStream &input)
+{
+        WPSResult result = WPSDocument::parse(&input, static_cast<WPXHLListenerImpl *>(this));
+        if (result != WPS_OK)
+                return false;
+
+    return true;
+}
diff --git a/writerperfect/source/wpsimp/MSWorksCollector.hxx b/writerperfect/source/wpsimp/MSWorksCollector.hxx
new file mode 100644
index 0000000..3b137c4
--- /dev/null
+++ b/writerperfect/source/wpsimp/MSWorksCollector.hxx
@@ -0,0 +1,41 @@
+/* MSWorksCollector: Collects sections and runs of text from a
+ * wordperfect file (and styles to go along with them) and writes them
+ * to a Writer target document
+ *
+ * Copyright (C) 2006 Fridrich Strba (fridrich.strba at bluewin.ch)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ * For further information visit http://libwpd.sourceforge.net
+ *
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#ifndef _MSWORKSCOLLECTOR_HXX
+#define _MSWORKSCOLLECTOR_HXX
+
+#include "filter/DocumentCollector.hxx"
+
+class MSWorksCollector : public DocumentCollector
+{
+public:
+    MSWorksCollector(WPSInputStream *pInput, DocumentHandler *pHandler);
+    virtual ~MSWorksCollector();
+    bool parseSourceDocument(WPSInputStream &input);
+};
+#endif
diff --git a/writerperfect/source/wpsimp/MSWorksImportFilter.cxx b/writerperfect/source/wpsimp/MSWorksImportFilter.cxx
new file mode 100644
index 0000000..eed5f00
--- /dev/null
+++ b/writerperfect/source/wpsimp/MSWorksImportFilter.cxx
@@ -0,0 +1,277 @@
+/* MSWorksImportFilter: Sets up the filter, and calls DocumentCollector
+ * to do the actual filtering
+ *
+ * Copyright (C) 2000 by Sun Microsystems, Inc.
+ * Copyright (C) 2002-2004 William Lachance (wlach at interlog.com)
+ * Copyright (C) 2004 Net Integration Technologies (http://www.net-itech.com)
+ * Copyright (C) 2004 Fridrich Strba <fridrich.strba at bluewin.ch>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ *  Contributor(s): Martin Gallwey (gallwey at sun.com)
+ *
+ */
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#include <osl/diagnose.h>
+#include <rtl/tencinfo.h>
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/InputSource.hpp>
+#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/ucb/XCommandEnvironment.hpp>
+
+#include <xmloff/attrlist.hxx>
+#include <ucbhelper/content.hxx>
+
+#include "filter/FilterInternal.hxx"
+#include "filter/DocumentHandler.hxx"
+#include "filter/DocumentCollector.hxx"
+#include "stream/WPXSvStream.h"
+
+#include <libwps/WPSDocument.h>
+#include "MSWorksImportFilter.hxx"
+#include "MSWorksCollector.hxx"
+
+// using namespace ::rtl;
+using rtl::OString;
+using rtl::OUString;
+using com::sun::star::uno::Sequence;
+using com::sun::star::uno::Reference;
+using com::sun::star::uno::Any;
+using com::sun::star::uno::UNO_QUERY;
+using com::sun::star::uno::XInterface;
+using com::sun::star::uno::Exception;
+using com::sun::star::uno::RuntimeException;
+using com::sun::star::lang::XMultiServiceFactory;
+using com::sun::star::beans::PropertyValue;
+using com::sun::star::document::XFilter;
+using com::sun::star::document::XExtendedFilterDetection;
+using com::sun::star::ucb::XCommandEnvironment;
+
+using com::sun::star::io::XInputStream;
+using com::sun::star::document::XImporter;
+using com::sun::star::xml::sax::InputSource;
+using com::sun::star::xml::sax::XAttributeList;
+using com::sun::star::xml::sax::XDocumentHandler;
+using com::sun::star::xml::sax::XParser;
+
+void callHandler(Reference < XDocumentHandler > xDocHandler);
+
+sal_Bool SAL_CALL MSWorksImportFilter::importImpl( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+    throw (RuntimeException)
+{
+    WRITER_DEBUG_MSG(("MSWorksImportFilter::importImpl: Got here!\n"));
+
+    sal_Int32 nLength = aDescriptor.getLength();
+    const PropertyValue * pValue = aDescriptor.getConstArray();
+    OUString sURL;
+    Reference < XInputStream > xInputStream;
+    for ( sal_Int32 i = 0 ; i < nLength; i++)
+    {
+        if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "InputStream" ) ) )
+        pValue[i].Value >>= xInputStream;
+        else if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "URL" ) ) )
+        pValue[i].Value >>= sURL;
+    }
+    if ( !xInputStream.is() )
+    {
+        OSL_ASSERT( 0 );
+        return sal_False;
+    }
+    OString sFileName;
+    sFileName = OUStringToOString(sURL, RTL_TEXTENCODING_INFO_ASCII);
+
+    // An XML import service: what we push sax messages to..
+    OUString sXMLImportService ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.XMLImporter" ) );
+    Reference < XDocumentHandler > xInternalHandler( mxMSF->createInstance( sXMLImportService ), UNO_QUERY );
+
+    // The XImporter sets up an empty target document for XDocumentHandler to write to..
+    Reference < XImporter > xImporter(xInternalHandler, UNO_QUERY);
+    xImporter->setTargetDocument(mxDoc);
+
+        // OO Document Handler: abstract class to handle document SAX messages, concrete implementation here
+        // writes to in-memory target doc
+        DocumentHandler xHandler(xInternalHandler);
+
+    WPXSvInputStream input( xInputStream );
+
+    MSWorksCollector collector(&input, &xHandler);
+    collector.filter();
+
+    return true;
+}
+
+sal_Bool SAL_CALL MSWorksImportFilter::filter( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+    throw (RuntimeException)
+{
+    WRITER_DEBUG_MSG(("MSWorksImportFilter::filter: Got here!\n"));
+    return importImpl ( aDescriptor );
+}
+void SAL_CALL MSWorksImportFilter::cancel(  )
+    throw (RuntimeException)
+{
+    WRITER_DEBUG_MSG(("MSWorksImportFilter::cancel: Got here!\n"));
+}
+
+// XImporter
+void SAL_CALL MSWorksImportFilter::setTargetDocument( const Reference< ::com::sun::star::lang::XComponent >& xDoc )
+    throw (::com::sun::star::lang::IllegalArgumentException, RuntimeException)
+{
+    WRITER_DEBUG_MSG(("MSWorksImportFilter::getTargetDocument: Got here!\n"));
+    meType = FILTER_IMPORT;
+    mxDoc = xDoc;
+}
+
+// XExtendedFilterDetection
+OUString SAL_CALL MSWorksImportFilter::detect( com::sun::star::uno::Sequence< PropertyValue >& Descriptor )
+    throw( com::sun::star::uno::RuntimeException )
+{
+    WRITER_DEBUG_MSG(("MSWorksImportFilter::detect: Got here!\n"));
+
+    WPSConfidence confidence = WPS_CONFIDENCE_NONE;
+    OUString sTypeName = OUString( RTL_CONSTASCII_USTRINGPARAM ( "" ) );
+    sal_Int32 nLength = Descriptor.getLength();
+    sal_Int32 location = nLength;
+    OUString sURL;
+    const PropertyValue * pValue = Descriptor.getConstArray();
+    Reference < XInputStream > xInputStream;
+    for ( sal_Int32 i = 0 ; i < nLength; i++)
+    {
+        if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "TypeName" ) ) )
+            location=i;
+        else if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "InputStream" ) ) )
+            pValue[i].Value >>= xInputStream;
+        else if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "URL" ) ) )
+            pValue[i].Value >>= sURL;
+    }
+
+        Reference< com::sun::star::ucb::XCommandEnvironment > xEnv;
+        if (!xInputStream.is())
+        {
+        try
+        {
+            ::ucbhelper::Content aContent(sURL, xEnv);
+                    xInputStream = aContent.openStream();
+        }
+        catch ( ... )
+        {
+            return ::rtl::OUString();
+        }
+
+                if (!xInputStream.is())
+                    return ::rtl::OUString();
+        }
+
+    WPXSvInputStream input( xInputStream );
+
+    if (input.atEOS())
+        return ::rtl::OUString();
+
+    confidence = WPSDocument::isFileFormatSupported(&input, false);
+
+    if ((confidence == WPS_CONFIDENCE_EXCELLENT) || (confidence == WPS_CONFIDENCE_GOOD))
+        sTypeName = OUString( RTL_CONSTASCII_USTRINGPARAM ( "writer_MS_Works_Document" ) );
+
+    if (sTypeName.getLength())
+    {
+        if ( location == Descriptor.getLength() )
+        {
+            Descriptor.realloc(nLength+1);
+            Descriptor[location].Name = ::rtl::OUString::createFromAscii( "TypeName" );
+        }
+
+        Descriptor[location].Value <<=sTypeName;
+    }
+
+    return sTypeName;
+}
+
+
+// XInitialization
+void SAL_CALL MSWorksImportFilter::initialize( const Sequence< Any >& aArguments )
+    throw (Exception, RuntimeException)
+{
+    WRITER_DEBUG_MSG(("MSWorksImportFilter::initialize: Got here!\n"));
+    Sequence < PropertyValue > aAnySeq;
+    sal_Int32 nLength = aArguments.getLength();
+    if ( nLength && ( aArguments[0] >>= aAnySeq ) )
+    {
+        const PropertyValue * pValue = aAnySeq.getConstArray();
+        nLength = aAnySeq.getLength();
+        for ( sal_Int32 i = 0 ; i < nLength; i++)
+        {
+            if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Type" ) ) )
+            {
+                pValue[i].Value >>= msFilterName;
+                break;
+            }
+        }
+    }
+}
+OUString MSWorksImportFilter_getImplementationName ()
+    throw (RuntimeException)
+{
+    return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.MSWorksImportFilter" ) );
+}
+
+#define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
+#define SERVICE_NAME2 "com.sun.star.document.ExtendedTypeDetection"
+sal_Bool SAL_CALL MSWorksImportFilter_supportsService( const OUString& ServiceName )
+    throw (RuntimeException)
+{
+    return (ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME1 ) ) ||
+        ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME2 ) ) );
+}
+Sequence< OUString > SAL_CALL MSWorksImportFilter_getSupportedServiceNames(  )
+    throw (RuntimeException)
+{
+    Sequence < OUString > aRet(2);
+        OUString* pArray = aRet.getArray();
+        pArray[0] =  OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME1 ) );
+    pArray[1] =  OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME2 ) );
+        return aRet;
+}
+#undef SERVICE_NAME2
+#undef SERVICE_NAME1
+
+Reference< XInterface > SAL_CALL MSWorksImportFilter_createInstance( const Reference< XMultiServiceFactory > & rSMgr)
+    throw( Exception )
+{
+    return (cppu::OWeakObject*) new MSWorksImportFilter( rSMgr );
+}
+
+// XServiceInfo
+OUString SAL_CALL MSWorksImportFilter::getImplementationName(  )
+    throw (RuntimeException)
+{
+    return MSWorksImportFilter_getImplementationName();
+}
+sal_Bool SAL_CALL MSWorksImportFilter::supportsService( const OUString& rServiceName )
+    throw (RuntimeException)
+{
+    return MSWorksImportFilter_supportsService( rServiceName );
+}
+Sequence< OUString > SAL_CALL MSWorksImportFilter::getSupportedServiceNames(  )
+    throw (RuntimeException)
+{
+    return MSWorksImportFilter_getSupportedServiceNames();
+}
diff --git a/writerperfect/source/wpsimp/MSWorksImportFilter.hxx b/writerperfect/source/wpsimp/MSWorksImportFilter.hxx
new file mode 100644
index 0000000..aca9b18
--- /dev/null
+++ b/writerperfect/source/wpsimp/MSWorksImportFilter.hxx
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2000 by Sun Microsystems, Inc.
+ * Copyright (C) 2002-2004 William Lachance (wlach at interlog.com)
+ * Copyright (C) 2004 Net Integration Technologies (http://www.net-itech.com)
+ * Copyright (C) 2004 Fridrich Strba <fridrich.strba at bluewin.ch>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ *  Contributor(s): Martin Gallwey (gallwey at sun.com)
+ *
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+#ifndef _WORDPERFECTIMPORTFILTER_HXX
+#define _WORDPERFECTIMPORTFILTER_HXX
+
+#ifndef _COM_SUN_STAR_DOCUMENT_XFILTER_HPP_
+#include <com/sun/star/document/XFilter.hpp>
+#endif
+#ifndef _COM_SUN_STAR_DOCUMENT_XIMPORTER_HPP_
+#include <com/sun/star/document/XImporter.hpp>
+#endif
+#ifndef _COM_SUN_STAR_DOCUMENT_XEXTENDEDFILTERDETECTION_HPP_
+#include <com/sun/star/document/XExtendedFilterDetection.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
+#include <com/sun/star/lang/XInitialization.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#endif
+#ifndef _CPPUHELPER_IMPLBASE5_HXX_
+#include <cppuhelper/implbase5.hxx>
+#endif
+
+enum FilterType
+{
+    FILTER_IMPORT,
+    FILTER_EXPORT
+};
+/* This component will be instantiated for both import or export. Whether it calls
+ * setSourceDocument or setTargetDocument determines which Impl function the filter
+ * member calls */
+class MSWorksImportFilter : public cppu::WeakImplHelper5
+<
+    com::sun::star::document::XFilter,
+    com::sun::star::document::XImporter,
+    com::sun::star::document::XExtendedFilterDetection,
+    com::sun::star::lang::XInitialization,
+    com::sun::star::lang::XServiceInfo
+>
+{
+protected:
+    // oo.org declares
+    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
+    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mxDoc;
+    ::rtl::OUString msFilterName;
+    ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > mxHandler;
+
+    FilterType meType;
+
+    sal_Bool SAL_CALL importImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+        throw (::com::sun::star::uno::RuntimeException);
+
+public:
+    MSWorksImportFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF)
+        : mxMSF( rxMSF ) {}
+    virtual ~MSWorksImportFilter() {}
+
+    // XFilter
+        virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+        throw (::com::sun::star::uno::RuntimeException);
+        virtual void SAL_CALL cancel(  )
+        throw (::com::sun::star::uno::RuntimeException);
+
+    // XImporter
+        virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
+        throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
+
+    //XExtendedFilterDetection
+    virtual ::rtl::OUString SAL_CALL detect( com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& Descriptor )
+        throw( com::sun::star::uno::RuntimeException );
+
+    // XInitialization
+        virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
+        throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+
+    // XServiceInfo
+        virtual ::rtl::OUString SAL_CALL getImplementationName(  )
+        throw (::com::sun::star::uno::RuntimeException);
+        virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
+        throw (::com::sun::star::uno::RuntimeException);
+        virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
+        throw (::com::sun::star::uno::RuntimeException);
+
+};
+
+::rtl::OUString MSWorksImportFilter_getImplementationName()
+    throw ( ::com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL MSWorksImportFilter_supportsService( const ::rtl::OUString& ServiceName )
+    throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL MSWorksImportFilter_getSupportedServiceNames(  )
+    throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
+SAL_CALL MSWorksImportFilter_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
+    throw ( ::com::sun::star::uno::Exception );
+
+#endif
diff --git a/writerperfect/source/wpsimp/makefile.mk b/writerperfect/source/wpsimp/makefile.mk
new file mode 100644
index 0000000..da17e80
--- /dev/null
+++ b/writerperfect/source/wpsimp/makefile.mk
@@ -0,0 +1,29 @@
+PRJ=..$/..
+
+PRJNAME=writerperfect
+TARGET=wpsimp
+ENABLE_EXCEPTIONS=true
+
+.INCLUDE :  settings.mk
+
+.IF "$(SYSTEM_LIBWPD)" == "YES"
+INCPRE+=$(LIBWPD_CFLAGS)
+.ELSE
+INCPRE+=$(SOLARVER)$/$(UPD)$/$(INPATH)$/inc$/libwpd
+.ENDIF
+
+.IF "$(SYSTEM_LIBWPS)" == "YES"
+INCPRE+=$(LIBWPS_CFLAGS)
+.ELSE
+INCPRE+=$(SOLARVER)$/$(UPD)$/$(INPATH)$/inc$/libwps
+.ENDIF
+
+# broken but ... necessary, internal include shafted ...
+INCPRE+= -I..
+
+SLOFILES= \
+    $(SLO)$/MSWorksCollector.obj  \
+    $(SLO)$/MSWorksImportFilter.obj  \
+    $(SLO)$/msworks_genericfilter.obj
+
+.INCLUDE :  target.mk
diff --git a/writerperfect/source/wpsimp/msworks_genericfilter.cxx b/writerperfect/source/wpsimp/msworks_genericfilter.cxx
new file mode 100644
index 0000000..f77b9c2
--- /dev/null
+++ b/writerperfect/source/wpsimp/msworks_genericfilter.cxx
@@ -0,0 +1,101 @@
+/* genericfilter: mostly generic code for registering the filter
+ *
+ * Portions of this code Copyright 2000 by Sun Microsystems, Inc.
+ * Rest is Copyright (C) 2002 William Lachance (wlach at interlog.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+#include <stdio.h>
+
+#include <osl/mutex.hxx>
+#include <osl/thread.h>
+#include <cppuhelper/factory.hxx>
+
+#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#endif
+
+#include "MSWorksImportFilter.hxx"
+
+using namespace ::rtl;
+using namespace ::cppu;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::registry;
+
+extern "C"
+{
+//==================================================================================================
+void SAL_CALL component_getImplementationEnvironment(
+    const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */ )
+{
+    *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+}
+//==================================================================================================
+sal_Bool SAL_CALL component_writeInfo(
+    void * /* pServiceManager */, void * pRegistryKey )
+{
+    if (pRegistryKey)
+    {
+        try
+        {
+            sal_Int32 nPos = 0;
+            Reference< XRegistryKey > xNewKey(
+                reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( MSWorksImportFilter_getImplementationName() ) );
+            xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
+
+            const Sequence< OUString > & rSNL = MSWorksImportFilter_getSupportedServiceNames();
+            const OUString * pArray = rSNL.getConstArray();
+            for ( nPos = rSNL.getLength(); nPos--; )
+                xNewKey->createKey( pArray[nPos] );
+
+            return sal_True;
+        }
+        catch (InvalidRegistryException &)
+        {
+            OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
+        }
+    }
+    return sal_False;
+}
+//==================================================================================================
+void * SAL_CALL component_getFactory(
+    const sal_Char * pImplName, void * pServiceManager, void * /* pRegistryKey */ )
+{
+    void * pRet = 0;
+
+    OUString implName = OUString::createFromAscii( pImplName );
+    if ( pServiceManager && implName.equals(MSWorksImportFilter_getImplementationName()) )
+    {
+        Reference< XSingleServiceFactory > xFactory( createSingleFactory(
+            reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+            OUString::createFromAscii( pImplName ),
+            MSWorksImportFilter_createInstance, MSWorksImportFilter_getSupportedServiceNames() ) );
+
+        if (xFactory.is())
+        {
+            xFactory->acquire();
+            pRet = xFactory.get();
+        }
+    }
+
+    return pRet;
+}
+}


More information about the ooo-build-commit mailing list