[Libreoffice-commits] .: 3 commits - filter/source writerfilter/debug_setup.mk

David Tardon dtardon at kemper.freedesktop.org
Thu May 26 01:45:47 PDT 2011


 filter/source/xslt/import/wordml/wordml2ooo_page.xsl  |   23 +
 filter/source/xslt/import/wordml/wordml2ooo_props.xsl |  246 +++++++++++--
 filter/source/xsltfilter/XSLTFilter.cxx               |   89 ----
 filter/source/xsltfilter/fla.cxx                      |  330 ------------------
 filter/source/xsltfilter/fla.hxx                      |   56 ---
 filter/source/xsltfilter/makefile.mk                  |    2 
 writerfilter/debug_setup.mk                           |    2 
 7 files changed, 228 insertions(+), 520 deletions(-)

New commits:
commit 5dc6ea5ae71eb56f6ea4c9eb2ec105884c39f991
Author: David Tardon <dtardon at redhat.com>
Date:   Thu May 26 10:44:46 2011 +0200

    we do _not_ want debug stuff for dbglevel 0 or 1

diff --git a/writerfilter/debug_setup.mk b/writerfilter/debug_setup.mk
index 800c55a..71275e6 100644
--- a/writerfilter/debug_setup.mk
+++ b/writerfilter/debug_setup.mk
@@ -1,5 +1,5 @@
 define writerfilter_debug_flags
-$(if $(filter $(strip $(gb_DEBUG)),01),\
+$(if $(filter-out $(strip $(gb_DEBUGLEVEL)),01),\
     -DDEBUG_DOMAINMAPPER \
     -DDEBUG_ELEMENT \
     -DDEBUG_RESOLVE \
commit 40bef961c06b5d777c34978926b2249aa1744ffa
Author: Michael Stahl <michael.x.stahl at oracle.com>
Date:   Wed May 25 08:58:57 2011 +0200

    xslt filter: remove the FLA horror

diff --git a/filter/source/xsltfilter/XSLTFilter.cxx b/filter/source/xsltfilter/XSLTFilter.cxx
index c84a76f..4b6d7d2 100644
--- a/filter/source/xsltfilter/XSLTFilter.cxx
+++ b/filter/source/xsltfilter/XSLTFilter.cxx
@@ -33,9 +33,6 @@
 
 #include <cppuhelper/factory.hxx>
 #include <cppuhelper/servicefactory.hxx>
-#include <cppuhelper/implbase1.hxx>
-#include <cppuhelper/implbase2.hxx>
-#include <cppuhelper/implbase3.hxx>
 #include <cppuhelper/implbase4.hxx>
 #include <cppuhelper/implbase.hxx>
 
@@ -79,7 +76,6 @@
 
 #include <xmloff/attrlist.hxx>
 
-#include <fla.hxx>
 #include <LibXSLTTransformer.hxx>
 
 #define TRANSFORMATION_TIMEOUT_SEC 60
@@ -101,89 +97,6 @@ using namespace ::com::sun::star::task;
 namespace XSLT
 {
     /*
-     * FLABridge provides some obscure attribute mangling to wordml2003 import/export filters.
-     * In the long run, you might want to replace this with an XSLT extension function.
-     */
-    class FLABridge : public WeakImplHelper1< DocumentHandlerAdapter >
-    {
-    private:
-        const sal_Unicode *
-        eval(const sal_Unicode *expr, sal_Int32 exprLen);
-        FLA::Evaluator ev;
-        bool active;
-
-    public:
-        FLABridge(const Reference<XDocumentHandler>& m_rDocumentHandler);
-
-        virtual void SAL_CALL
-        startElement(const OUString& str,
-                const Reference<XAttributeList>& attriblist)
-                throw (SAXException, RuntimeException);
-
-    };
-
-    FLABridge::FLABridge(const Reference<XDocumentHandler>& _rDocumentHandler) : active(false)
-    {
-        DocumentHandlerAdapter::setDelegate(_rDocumentHandler);
-    }
-
-    void
-    FLABridge::startElement(const OUString& str,
-            const Reference<XAttributeList>& attriblist) throw (SAXException,
-            RuntimeException)
-    {
-        if (active)
-            {
-                //		SvXMLAttributeList* _attriblist=SvXMLAttributeList::getImplementation(attriblist);
-                const int len = attriblist->getLength();
-                SvXMLAttributeList *_newattriblist = new SvXMLAttributeList();
-                for (int i = 0; i < len; i++)
-                    {
-                        const OUString& name = attriblist->getNameByIndex(
-                                sal::static_int_cast<sal_Int16>(i));
-                        sal_Int32 pos;
-                        static const OUString _value_(".value", 6,
-                                RTL_TEXTENCODING_ASCII_US);
-                        if ((pos = name.lastIndexOf(L'.')) != -1 && name.match(
-                                _value_, pos))
-                            {
-                                const OUString newName(name, pos);
-                                const OUString
-                                        & value =
-                                                attriblist->getValueByIndex(
-                                                        sal::static_int_cast<
-                                                                sal_Int16>(i));
-                                const OUString newValue(ev.eval(value.getStr(),
-                                        value.getLength()));
-                                if (newValue.getLength() > 0)
-                                    {
-                                        _newattriblist->AddAttribute(newName,
-                                                newValue);
-                                    }
-                            }
-                        else
-                            {
-                                _newattriblist->AddAttribute(
-                                        name,
-                                        attriblist->getValueByIndex(
-                                                sal::static_int_cast<sal_Int16>(
-                                                        i)));
-                            }
-                    };
-                const Reference<XAttributeList> newattriblist(_newattriblist);
-                DocumentHandlerAdapter::startElement(str, newattriblist);
-            }
-        else
-            {
-                if (str.compareToAscii("fla:fla.activate") == 0)
-                    {
-                        active = 1;
-                    }
-                DocumentHandlerAdapter::startElement(str, attriblist);
-            }
-    }
-
-    /*
      * XSLTFilter reads flat XML streams from the XML filter framework and passes
      * them to an XSLT transformation service. XSLT transformation errors are
      * reported to XSLTFilter.
@@ -452,7 +365,7 @@ m_rServiceFactory(r), m_bTerminated(sal_False), m_bError(sal_False)
                         aInput.aInputStream = pipein;
 
                         // set doc handler
-                        xSaxParser->setDocumentHandler(new FLABridge(xHandler));
+                        xSaxParser->setDocumentHandler(xHandler);
 
                         // transform
                         m_tcontrol->start();
diff --git a/filter/source/xsltfilter/fla.cxx b/filter/source/xsltfilter/fla.cxx
deleted file mode 100644
index d8b7391..0000000
--- a/filter/source/xsltfilter/fla.cxx
+++ /dev/null
@@ -1,330 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org.  If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_filter.hxx"
-
-/*
-This file include an implementation of FLA - a simple Funtional Language for Attributes. 
-The language is LISP-like and has the following grammar:
-FLA_Expression ::= '(' FLA_Operation FLA_Attribute+ ')'
-FLA_Attribtute ::= FLA_Constant | FLA_Expression
-FLA_Constant ::= '[' String ']'
-The language currently supports the following operations:
-"+"-Operation, e.g. (+[1][2]) = [3]
-"-"-Operation, e.g. (-[3][2]) = [1]
-"*"-Operation, e.g. (*[3][2]) = [6]
-"/"-Operation, e.g. (-[6][2]) = [3]
-"<"-Operation, e.g. (<[3][4]) = [t] resp. (<[4][3]) = []
-"<="-Operation, e.g. (<=[3][4]) = [t] resp. (<=[4][3]) = []
-">"-Operation, e.g. (>[3][4]) = [] resp. (>[4][3]) = [t]
-">="-Operation, e.g. (>=[3][4]) = [] resp. (>=[4][3]) = [t]
-Variable assignment, e.g. ($var1[4])
-Variable access, e.g. (+($var1[4])($var1)($var1)) = [8]
-Condition, e.g. (?[t][3][4])=[3] resp. (?[][3][4])=4
-Priorized Choice, e.g. (|[4][5])=[4] resp. (|[][5])=[5]; i.e. result is the first occurrence of a non-[].
-*/
-
-#include "fla.hxx"
-#include "sal/main.h"
-
-
-namespace FLA {
-
-
-sal_Int32 Evaluator::evalFunc(const sal_Unicode*op, sal_Int32 opLen, sal_Int32 args, sal_Unicode* argv[10], sal_Unicode *result)
-{
-    if (opLen==1 && op[0]==L'+')
-    {
-        double res=0;
-        for(sal_Int32 i=0;i<args;i++)
-        {
-            double v=rtl_ustr_toDouble(argv[i]);
-            res+=v;
-        }
-        return rtl_ustr_valueOfDouble(result, res);
-    }
-    else if (opLen==1 && op[0]==L'-' && args>0)
-    {
-        double res=rtl_ustr_toDouble(argv[0]);
-        for(sal_Int32 i=1;i<args;i++)
-        {
-            double v=rtl_ustr_toDouble(argv[i]);
-            res-=v;
-        }
-        sal_Int32 _len= rtl_ustr_valueOfDouble(result, res);
-        return _len;
-    }
-    else if (opLen==1 && op[0]==L'*')
-    {
-        double res=1;
-        for(sal_Int32 i=0;i<args;i++)
-        {
-            double v=rtl_ustr_toDouble(argv[i]);
-            res*=v;
-        }
-        return rtl_ustr_valueOfDouble(result, res);
-    }
-    else if (opLen==1 && op[0]==L'/' && args>0)
-    {
-        double res=rtl_ustr_toDouble(argv[0]);
-        for(sal_Int32 i=1;i<args;i++)
-        {
-            double v=rtl_ustr_toDouble(argv[i]);
-            res/=v;
-        }
-        return rtl_ustr_valueOfDouble(result, res);
-    }
-    else if (opLen==1 && op[0]==L'>' && args==2)
-    {
-        double p1=rtl_ustr_toDouble(argv[0]);
-        double p2=rtl_ustr_toDouble(argv[1]);
-        if (p1>p2)
-        {
-            result[0]=L't';
-            return 1;
-        }
-        else 
-        {
-            return 0;
-        }
-    }
-    else if (opLen==1 && op[0]==L'<' && args==2)
-    {
-        double p1=rtl_ustr_toDouble(argv[0]);
-        double p2=rtl_ustr_toDouble(argv[1]);
-        if (p1<p2)
-        {
-            result[0]=L't';
-            return 1;
-        }
-        else 
-        {
-            return 0;
-        }
-    }
-    else if (opLen==2 && op[0]==L'<' && op[1]==L'=' && args==2)
-    {
-        double p1=rtl_ustr_toDouble(argv[0]);
-        double p2=rtl_ustr_toDouble(argv[1]);
-        if (p1<=p2)
-        {
-            result[0]=L't';
-            return 1;
-        }
-        else 
-        {
-            return 0;
-        }
-    }
-    else if (opLen==2 && op[0]==L'>' && op[1]==L'=' && args==2)
-    {
-        double p1=rtl_ustr_toDouble(argv[0]);
-        double p2=rtl_ustr_toDouble(argv[1]);
-        if (p1>=p2)
-        {
-            result[0]=L't';
-            return 1;
-        }
-        else 
-        {
-            return 0;
-        }
-    }
-    else if (opLen>1 && op[0]==L'$' && args==0)
-    {
-        sal_Int32 reg=rtl_ustr_toInt32(op+1, 10);	
-        int i=0; while(i<99 && environment[reg][i]!=L'\0') { result[i]=environment[reg][i]; i++; }
-        result[i]=0;
-        return i;
-    }
-    else if (opLen>1 && op[0]==L'$' && args==1)
-    {
-        sal_Int32 reg=rtl_ustr_toInt32(op+1, 10);	
-        int i=0; while(i<99 && argv[0]!=NULL) { result[i]=argv[0][i]; environment[reg][i]=argv[0][i]; i++; }
-        environment[reg][i]=0; result[i]=0;
-        return i;
-    }
-    else if (opLen==1 && op[0]==L'?' && args==3)
-    {
-        sal_Unicode *source;
-        if (argv[0][0]==L'\0')
-        {
-            source=argv[2];
-        }
-        else
-        {
-            source=argv[1];
-        }
-        int len=0; while (*source!=L'\0') result[len++]=*source++;
-        result[len]=0;
-        return len;
-    }
-    else if (opLen==1 && op[0]==L'|' && args>0)
-    {
-        sal_Unicode *source;
-        int i=0; while (i<args && argv[i][0]==L'\0') i++;
-        if (i<args)
-        {
-            source=argv[i];
-            int len=0; while (*source!=L'\0') result[len++]=*source++;
-            result[len]=0;
-            return len;
-        }
-        else 
-        {
-            result[0]=0;
-            return 0;
-        }
-    }
-    else if (opLen==1 && op[0]==L'.' && args>0)
-    {
-        sal_Unicode *source;
-        int len=0;
-        for(sal_Int32 i=0;i<args;i++)
-        {
-            source=argv[i];
-            while (*source!=L'\0') result[len++]=*source++;
-        }
-        result[len]=0;
-        return len;
-    }
-    else if (opLen==8 && op[0]=='t' && op[1]=='w' && op[2]=='i' && op[3]=='p' && op[4]=='s' && op[5]=='2' && op[6]=='c' && op[7]=='m' && args==1)
-    {
-        double v=rtl_ustr_toDouble(argv[0]);
-        return rtl_ustr_valueOfDouble(result, (v/567.0));
-    }
-    else if (opLen==6 && op[0]=='s' && op[1]=='w' && op[2]=='i' && op[3]=='t' && op[4]=='c' && op[5]=='h' && args>2)
-    {
-        sal_Unicode *source;
-        for(int i=1;i<args-1;i+=2)
-        {
-            if (rtl_ustr_compare(argv[0], argv[i])==0)
-            {
-                source=argv[i+1]; int len=0; while (*source!=L'\0') result[len++]=*source++;
-                result[len]=0;
-                return len;
-            }
-        }
-        source=argv[args-1]; int len=0; while (*source!=L'\0') result[len++]=*source++;
-        result[len]=0;
-        return len;
-//		double v=rtl_ustr_toDouble(argv[0]);
-//		return rtl_ustr_valueOfDouble(result, (v/567.0L));
-    }
-    else
-    {
-        return 0;
-    }
-}
-
-
-sal_Int32 Evaluator::evalExp(const sal_Unicode *expr, sal_Int32 exprLen, sal_Unicode *buf, sal_Int32 *bufLen)
-{
-    sal_Unicode ch;
-    sal_Unicode* argv[10];
-    sal_Int32 args=0;
-    int offset=0; while(offset<exprLen && expr[offset]==' ') offset++;
-    sal_Int32 startBuf=*bufLen;
-    if(expr[offset]==L'(')
-    {
-        offset++;
-        while(offset<exprLen && expr[offset]==' ') offset++;
-        int op=offset;
-        while(offset<exprLen && expr[offset]!=' ' && expr[offset]!='[' && expr[offset]!='('&& expr[offset]!=']' && expr[offset]!=')') offset++;
-        int opLen=offset-op;
-        bool done=false;
-        while(offset<exprLen && !done)
-        {
-            switch(expr[offset])
-            {
-            case '(':
-            case '[':
-                argv[args++]=buf+*bufLen;
-                offset+=evalExp(expr+offset, exprLen, buf, bufLen);
-                buf[(*bufLen)++]=0;
-                break;
-            case ')':
-                offset++;
-                done=true;
-                break;
-            case ' ': /* skip */
-                offset++;
-                break;
-            default: /* skip */
-                offset++;
-                break;
-            };
-        }
-        if (done)
-        {
-            sal_Int32 len=evalFunc(expr+op, opLen, args, argv, buf+startBuf);
-            *bufLen=startBuf+len;
-        }
-
-    }
-    else if(expr[offset]==L'[')
-    {
-        offset++;
-        argv[args++]=buf+*bufLen;
-        while (offset<exprLen && (ch=expr[offset++])!=']')
-        {
-            buf[(*bufLen)++]=ch;
-        }
-        buf[(*bufLen)++]=0;
-    }
-    return offset;
-}
-
-const sal_Unicode *Evaluator::eval(const sal_Unicode *expr, sal_Int32 exprLen)
-{
-
-    sal_Int32 len=0;
-    evalExp(expr, exprLen, _buf, &len);
-    OSL_ASSERT(len<1024);
-    return _buf;
-}
-
-}
-
-/*
-SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
-{
-    FLA::Evaluator ev;
-  for(int i=1;i<argc;i++)
-    {
-        rtl_uString *param=NULL;
-        rtl_uString_newFromAscii(&param, argv[i]);
-        ::rtl::OUString _param(param);
-        const sal_Unicode *res=ev.eval(_param.getStr(), _param.getLength());
-    }
-    return 0;
-}
-*/
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/source/xsltfilter/fla.hxx b/filter/source/xsltfilter/fla.hxx
deleted file mode 100644
index 8418098..0000000
--- a/filter/source/xsltfilter/fla.hxx
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org.  If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-/*
-Function Language for Attributes. See .cxx-File for Syntax. Used in WordML-Filter.
-*/
-#ifndef __FLA_HXX__
-#define __FLA_HXX__
-
-#include <sal/types.h>
-#include <rtl/ustring.hxx>
-namespace FLA {
-
-
-class Evaluator 
-{
-private:
-    sal_Unicode environment[100][10];
-    sal_Unicode _buf[1024];
-    sal_Int32 evalFunc(const sal_Unicode*op, sal_Int32 opLen, sal_Int32 args, sal_Unicode* argv[10], sal_Unicode *result);
-    sal_Int32 evalExp(const sal_Unicode *expr, sal_Int32 exprLen, sal_Unicode *buf, sal_Int32 *bufLen);
-public:
-    const sal_Unicode *eval(const sal_Unicode *expr, sal_Int32 exprLen);
-};
-}
-
-
-
-#endif /* __FLA_HXX__ */
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/source/xsltfilter/makefile.mk b/filter/source/xsltfilter/makefile.mk
index 50faea7..539469f 100644
--- a/filter/source/xsltfilter/makefile.mk
+++ b/filter/source/xsltfilter/makefile.mk
@@ -43,7 +43,7 @@ LIBXSLTINCDIR=external$/libxslt
 CFLAGS+= -I$(SOLARINCDIR)$/$(LIBXSLTINCDIR)
 .ENDIF
 
-SLOFILES=$(SLO)$/XSLTFilter.obj $(SLO)$/LibXSLTTransformer.obj $(SLO)$/fla.obj $(SLO)/OleHandler.obj
+SLOFILES=$(SLO)$/XSLTFilter.obj $(SLO)$/LibXSLTTransformer.obj $(SLO)/OleHandler.obj
 LIBNAME=xsltfilter
 SHL1TARGETDEPN=makefile.mk
 SHL1OBJS=$(SLOFILES)
commit dc37e25ff10fa4d18904a5230f57869d429374af
Author: Michael Stahl <michael.x.stahl at oracle.com>
Date:   Wed May 25 08:56:38 2011 +0200

    wordml import filter: replace FLA usage with plain XSLT

diff --git a/filter/source/xslt/import/wordml/wordml2ooo_page.xsl b/filter/source/xslt/import/wordml/wordml2ooo_page.xsl
index 8514594..5350b61 100644
--- a/filter/source/xslt/import/wordml/wordml2ooo_page.xsl
+++ b/filter/source/xslt/import/wordml/wordml2ooo_page.xsl
@@ -179,7 +179,28 @@
             </style:page-layout-properties>
         <style:header-style>
         <style:header-footer-properties style:dynamic-spacing="true" fo:margin-bottom="0">
-           <xsl:attribute name="fo:min-height.value"><xsl:value-of select="concat('(.(twips2cm(?(>($0(-[', w:pgMar/@w:top, '](|[', w:pgMar/@w:header, '][720])))[0])($0)[0]))[cm])')"/></xsl:attribute>
+           <xsl:variable name="header-margin">
+               <xsl:choose>
+                   <xsl:when test="w:pgMar/@w:header">
+                       <xsl:value-of select="w:pgMar/@w:header"/>
+                   </xsl:when>
+                   <xsl:otherwise>720</xsl:otherwise>
+               </xsl:choose>
+           </xsl:variable>
+           <xsl:variable name="header-margin-diff">
+               <xsl:value-of select="w:pgMar/@w:top - $header-margin"/>
+           </xsl:variable>
+           <xsl:variable name="min-height">
+               <xsl:choose>
+                   <xsl:when test="$header-margin-diff &gt; 0">
+                       <xsl:value-of select="$header-margin-diff div 567.0"/>
+                   </xsl:when>
+                   <xsl:otherwise>0</xsl:otherwise>
+               </xsl:choose>
+           </xsl:variable>
+           <xsl:attribute name="fo:min-height">
+               <xsl:value-of select="concat($min-height, 'cm')"/>
+           </xsl:attribute>
         </style:header-footer-properties>
         </style:header-style>
         </style:page-layout>
diff --git a/filter/source/xslt/import/wordml/wordml2ooo_props.xsl b/filter/source/xslt/import/wordml/wordml2ooo_props.xsl
index 76725f2..86e7b0a 100644
--- a/filter/source/xslt/import/wordml/wordml2ooo_props.xsl
+++ b/filter/source/xslt/import/wordml/wordml2ooo_props.xsl
@@ -9,30 +9,79 @@
 
 <xsl:template name="page-layout-properties">
 
-<xsl:attribute name="fo:margin-top.value">
-  <xsl:value-of select="concat('(.(twips2cm(?[',name(w:hdr),'](?(>=($0[',w:pgMar/@w:top,'])($1(|[',w:pgMar/@w:header,'][720])))($1)($0))[',w:pgMar/@w:top,']))[cm])')"/>
+<!-- NOTE: "div 567.0" converts from twips to cm -->
+<xsl:attribute name="fo:margin-top">
+  <xsl:variable name="header-margin">
+      <xsl:choose>
+          <xsl:when test="w:pgMar/@w:header">
+              <xsl:value-of select="w:pgMar/@w:header"/>
+          </xsl:when>
+          <xsl:otherwise>720</xsl:otherwise>
+      </xsl:choose>
+  </xsl:variable>
+  <xsl:variable name="margin-top">
+      <xsl:choose>
+          <xsl:when test="w:hdr">
+              <xsl:choose>
+                 <xsl:when test="w:pgMar/@w:top &gt;= $header-margin">
+                     <xsl:value-of select="$header-margin"/>
+                 </xsl:when>
+                 <xsl:otherwise>
+                     <xsl:value-of select="w:pgMar/@w:top"/>
+                 </xsl:otherwise>
+              </xsl:choose>
+          </xsl:when>
+          <xsl:otherwise>
+              <xsl:value-of select="w:pgMar/@w:top"/>
+          </xsl:otherwise>
+      </xsl:choose>
+  </xsl:variable>
+  <xsl:value-of select="concat($margin-top div 567.0, 'cm')"/>
 </xsl:attribute>
-<xsl:attribute name="fo:margin-bottom.value">
-  <xsl:value-of select="concat('(.(twips2cm(?[',name(w:ftr),'](|[',w:pgMar/@w:footer,'][720])[',w:pgMar/@w:bottom,']))[cm])')"/>
+<xsl:attribute name="fo:margin-bottom">
+  <xsl:variable name="footer-margin">
+      <xsl:choose>
+          <xsl:when test="w:pgMar/@w:footer">
+              <xsl:value-of select="w:pgMar/@w:footer"/>
+          </xsl:when>
+          <xsl:otherwise>720</xsl:otherwise>
+      </xsl:choose>
+  </xsl:variable>
+  <xsl:variable name="margin-bottom">
+      <xsl:choose>
+          <xsl:when test="w:ftr">
+              <xsl:value-of select="$footer-margin"/>
+          </xsl:when>
+          <xsl:otherwise>
+              <xsl:value-of select="w:pgMar/@w:bottom"/>
+          </xsl:otherwise>
+      </xsl:choose>
+  </xsl:variable>
+  <xsl:value-of select="concat($margin-bottom div 567.0, 'cm')"/>
 </xsl:attribute>
-<xsl:attribute name="fo:margin-left.value">
-  <xsl:value-of select="concat('(.(twips2cm[',w:pgMar/@w:left,'])[cm])')"/>
+<xsl:attribute name="fo:margin-left">
+  <xsl:value-of select="concat(w:pgMar/@w:left div 567.0, 'cm')"/>
 </xsl:attribute>
-<xsl:attribute name="fo:margin-right.value">
-  <xsl:value-of select="concat('(.(twips2cm[',w:pgMar/@w:right,'])[cm])')"/>
+<xsl:attribute name="fo:margin-right">
+  <xsl:value-of select="concat(w:pgMar/@w:right div 567.0, 'cm')"/>
 </xsl:attribute>
 
-<xsl:attribute name="fo:page-width.value">
-  <xsl:value-of select="concat('(.(twips2cm[',w:pgSz/@w:w,'])[cm])')"/>
+<xsl:attribute name="fo:page-width">
+  <xsl:value-of select="concat(w:pgSz/@w:w div 567.0, 'cm')"/>
 </xsl:attribute>
-<xsl:attribute name="fo:page-height.value">
-  <xsl:value-of select="concat('(.(twips2cm[',w:pgSz/@w:h,'])[cm])')"/>
+<xsl:attribute name="fo:page-height">
+  <xsl:value-of select="concat(w:pgSz/@w:h div 567.0, 'cm')"/>
 </xsl:attribute>
-<xsl:attribute name="style:footnote-max-height.value">  
-  <xsl:value-of select="'[0cm]'"/>
+<xsl:attribute name="style:footnote-max-height">
+  <xsl:value-of select="'0cm'"/>
 </xsl:attribute>
-<xsl:attribute name="style:print-orientation.value">
-  <xsl:value-of select="concat('(|[',w:pgSz/@w:orient,'][portrait])')"/>
+<xsl:attribute name="style:print-orientation">
+  <xsl:choose>
+      <xsl:when test="w:pgSz/@w:orient">
+          <xsl:value-of select="w:pgSz/@w:orient"/>
+      </xsl:when>
+      <xsl:otherwise>portrait</xsl:otherwise>
+  </xsl:choose>
 </xsl:attribute>
 <xsl:apply-templates select="//w:bgPict"/>
 <xsl:call-template name="column-properties"/>
@@ -46,27 +95,37 @@
 </an:column-properties>
 <xsl:template name="column-properties">
 <style:columns>
-<xsl:attribute name="fo:column-count.value">
-  <xsl:value-of select="concat('(|[',w:cols/@w:num,'][1])')"/>
+<xsl:attribute name="fo:column-count">
+  <xsl:choose>
+      <xsl:when test="w:cols/@w:num">
+          <xsl:value-of select="w:cols/@w:num"/>
+      </xsl:when>
+      <xsl:otherwise>1</xsl:otherwise>
+  </xsl:choose>
 </xsl:attribute>
 
 <xsl:if test="not(w:cols/w:col)"> 
 <!-- bug in the OASIS spec resp. bug in xmloff  -->
-<xsl:attribute name="fo:column-gap.value">
-  <xsl:value-of select="concat('(.(twips2cm[',w:cols/@w:space,'])[cm])')"/>
+<xsl:attribute name="fo:column-gap">
+  <xsl:value-of select="concat(w:cols/@w:space div 567.0, 'cm')"/>
 </xsl:attribute>
 </xsl:if>
 
 <xsl:for-each select="w:cols/w:col">
   <style:column> 
-     <xsl:attribute name="style:rel-width.value">
-       <xsl:value-of select="concat('(.[', at w:w,'][*])')"/>
+     <xsl:attribute name="style:rel-width">
+       <xsl:value-of select="concat(@w:w, '*')"/>
      </xsl:attribute>
-     <xsl:attribute name="fo:start-indent.value">
-       <xsl:value-of select="'[0cm]'"/>
+     <xsl:attribute name="fo:start-indent">
+       <xsl:value-of select="'0cm'"/>
      </xsl:attribute>
-     <xsl:attribute name="fo:end-indent.value">
-       <xsl:value-of select="concat('(.(twips2cm(|[', at w:space,'][0]))[cm])')"/>
+     <xsl:attribute name="fo:end-indent">
+       <xsl:choose>
+          <xsl:when test="@w:space">
+              <xsl:value-of select="concat(@w:space div 567.0, 'cm')"/>
+          </xsl:when>
+          <xsl:otherwise>0cm</xsl:otherwise>
+       </xsl:choose>
      </xsl:attribute>
   </style:column> 
 </xsl:for-each>
@@ -78,30 +137,132 @@
      context-node-output="style:text-properties">
 </an:text-properties >
 <xsl:template name="text-properties">
-<xsl:attribute name="fo:font-weight.value">
- <xsl:value-of select="concat('(switch(|[',w:b/@val,'][',local-name(w:b),'])[on][bold][off][normal][b][bold][])')"/>
+<xsl:variable name="b-value">
+  <xsl:choose>
+      <xsl:when test="w:b/@val">
+          <xsl:value-of select="w:b/@val"/>
+      </xsl:when>
+      <xsl:otherwise>
+          <xsl:value-of select="local-name(w:b)"/>
+      </xsl:otherwise>
+  </xsl:choose>
+</xsl:variable>
+<!-- could be simplified: is "b" actually a valid value of w:b/@val ? -->
+<xsl:variable name="font-weight">
+  <xsl:choose>
+      <xsl:when test="$b-value = 'on'">bold</xsl:when>
+      <xsl:when test="$b-value = 'off'">normal</xsl:when>
+      <xsl:when test="$b-value = 'b'">bold</xsl:when>
+      <xsl:otherwise></xsl:otherwise>
+  </xsl:choose>
+</xsl:variable>
+<xsl:attribute name="fo:font-weight">
+  <xsl:value-of select="$font-weight"/>
 </xsl:attribute>
-<xsl:attribute name="style:font-weight-asian.value">
- <xsl:value-of select="concat('(switch(|[',w:b/@val,'][',local-name(w:b),'])[on][bold][off][normal][b][bold][])')"/>
+<xsl:attribute name="style:font-weight-asian">
+  <xsl:value-of select="$font-weight"/>
 </xsl:attribute>
-<xsl:attribute name="style:font-weight-complex.value">
- <xsl:value-of select="concat('(switch(|[',w:b-cs/@val,'][',local-name(w:b-cs),'])[on][bold][off][normal][b-cs][bold][])')"/>
+<xsl:attribute name="style:font-weight-complex">
+  <xsl:variable name="b-cs-value">
+    <xsl:choose>
+      <xsl:when test="w:b-cs/@val">
+          <xsl:value-of select="w:b-cs/@val"/>
+      </xsl:when>
+      <xsl:otherwise>
+          <xsl:value-of select="local-name(w:b-cs)"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+  <!-- could be simplified: is "b-cs" actually a valid value of w:b-cs/@val -->
+  <xsl:choose>
+      <xsl:when test="$b-cs-value = 'on'">bold</xsl:when>
+      <xsl:when test="$b-cs-value = 'off'">normal</xsl:when>
+      <xsl:when test="$b-cs-value = 'b-cs'">bold</xsl:when>
+      <xsl:otherwise></xsl:otherwise>
+  </xsl:choose>
 </xsl:attribute>
-<xsl:attribute name="fo:font-style.value">
- <xsl:value-of select="concat('(switch(|[',w:i/@val,'][',local-name(w:i),'])[on][italic][off][normal][i][italic][])')"/>
+<xsl:variable name="i-value">
+  <xsl:choose>
+      <xsl:when test="w:i/@val">
+          <xsl:value-of select="w:i/@val"/>
+      </xsl:when>
+      <xsl:otherwise>
+          <xsl:value-of select="local-name(w:i)"/>
+      </xsl:otherwise>
+  </xsl:choose>
+</xsl:variable>
+<!-- could be simplified: is "i" actually a valid value of w:i/@val ? -->
+<xsl:variable name="font-style">
+  <xsl:choose>
+      <xsl:when test="$i-value = 'on'">italic</xsl:when>
+      <xsl:when test="$i-value = 'off'">normal</xsl:when>
+      <xsl:when test="$i-value = 'i'">italic</xsl:when>
+      <xsl:otherwise></xsl:otherwise>
+  </xsl:choose>
+</xsl:variable>
+<xsl:attribute name="fo:font-style">
+  <xsl:value-of select="$font-style"/>
 </xsl:attribute>
-<xsl:attribute name="style:font-style-asian.value">
- <xsl:value-of select="concat('(switch(|[',w:i/@val,'][',local-name(w:i),'])[on][italic][off][normal][i][italic][])')"/>
+<xsl:attribute name="style:font-style-asian">
+  <xsl:value-of select="$font-style"/>
 </xsl:attribute>
-<xsl:attribute name="style:font-style-complex.value">
- <xsl:value-of select="concat('(switch(|[',w:i-cs/@val,'][',local-name(w:i-cs),'])[on][italic][off][normal][i-cs][italic][])')"/>
+<xsl:attribute name="style:font-style-complex">
+  <xsl:variable name="i-cs-value">
+      <xsl:choose>
+          <xsl:when test="w:i-cs/@val">
+              <xsl:value-of select="w:i-cs/@val"/>
+          </xsl:when>
+          <xsl:otherwise>
+              <xsl:value-of select="local-name(w:i-cs)"/>
+          </xsl:otherwise>
+      </xsl:choose>
+  </xsl:variable>
+  <!-- could be simplified: is "i-cs" actually a valid value of w:i-cs/@val -->
+  <xsl:choose>
+      <xsl:when test="$i-cs-value = 'on'">italic</xsl:when>
+      <xsl:when test="$i-cs-value = 'off'">normal</xsl:when>
+      <xsl:when test="$i-cs-value = 'i-cs'">italic</xsl:when>
+      <xsl:otherwise></xsl:otherwise>
+  </xsl:choose>
 </xsl:attribute>
-<xsl:attribute name="fo:text-transform.value">
- <xsl:value-of select="concat('(switch(|[',w:caps/@val,'][',local-name(w:caps),'])[on][uppercase][off][normal][caps][uppercase][])')"/>
+<xsl:attribute name="fo:text-transform">
+  <xsl:variable name="caps-value">
+      <xsl:choose>
+          <xsl:when test="w:caps/@val">
+              <xsl:value-of select="w:caps/@val"/>
+          </xsl:when>
+          <xsl:otherwise>
+              <xsl:value-of select="local-name(w:caps)"/>
+          </xsl:otherwise>
+      </xsl:choose>
+  </xsl:variable>
+  <!-- could be simplified: is "caps" actually a valid value of w:caps/@val -->
+  <xsl:choose>
+      <xsl:when test="$caps-value = 'on'">uppercase</xsl:when>
+      <xsl:when test="$caps-value = 'off'">normal</xsl:when>
+      <xsl:when test="$caps-value = 'caps'">uppercase</xsl:when>
+      <xsl:otherwise></xsl:otherwise>
+  </xsl:choose>
 </xsl:attribute>
-<xsl:attribute name="fo:font-variant.value">
- <xsl:value-of select="concat('(switch(|[',w:smallCaps/@val,'][',local-name(w:smallCaps),'])[on][small-caps][off][normal][smallCaps][small-caps][])')"/>
+<xsl:attribute name="fo:font-variant">
+  <xsl:variable name="small-caps-value">
+      <xsl:choose>
+          <xsl:when test="w:smallCaps/@val">
+              <xsl:value-of select="w:smallCaps/@val"/>
+          </xsl:when>
+          <xsl:otherwise>
+              <xsl:value-of select="local-name(w:smallCaps)"/>
+          </xsl:otherwise>
+      </xsl:choose>
+  </xsl:variable>
+  <!-- could be simplified: is "smallCaps" actually a valid value of w:smallCaps/@val -->
+  <xsl:choose>
+      <xsl:when test="$small-caps-value = 'on'">small-caps</xsl:when>
+      <xsl:when test="$small-caps-value = 'off'">normal</xsl:when>
+      <xsl:when test="$small-caps-value = 'smallCaps'">small-caps</xsl:when>
+      <xsl:otherwise></xsl:otherwise>
+  </xsl:choose>
 </xsl:attribute>
 </xsl:template>
 
-</xsl:stylesheet>
\ No newline at end of file
+</xsl:stylesheet>


More information about the Libreoffice-commits mailing list