n#775899 initial docx import of w:vertAnchor inside w:tblpPr

Change-Id: I5c848a8d4c860a83d6729b8db40f744afad906d5
diff --git a/writerfilter/Library_writerfilter.mk b/writerfilter/Library_writerfilter.mk
index f768dce..3c30b36 100644
--- a/writerfilter/Library_writerfilter.mk
+++ b/writerfilter/Library_writerfilter.mk
@@ -122,6 +122,7 @@ $(eval $(call gb_Library_add_exception_objects,writerfilter,\
    writerfilter/source/dmapper/SettingsTable \
    writerfilter/source/dmapper/StyleSheetTable \
    writerfilter/source/dmapper/TDefTableHandler \
    writerfilter/source/dmapper/TablePositionHandler \
    writerfilter/source/dmapper/TablePropertiesHandler \
    writerfilter/source/dmapper/TblStylePrHandler \
    writerfilter/source/dmapper/ThemeTable \
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 7fcd9e3..e0d8316 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -23,6 +23,7 @@
#include <com/sun/star/table/TableBorder.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
#include <com/sun/star/text/HoriOrientation.hpp>
#include <com/sun/star/text/RelOrientation.hpp>
#include <dmapperLoggers.hxx>

#ifdef DEBUG_DMAPPER_TABLE_HANDLER
@@ -691,11 +692,24 @@ void DomainMapperTableHandler::endTable()

    if (m_pTableSeq->getLength() > 0)
    {
        uno::Reference<text::XTextRange> xStart;
        uno::Reference<text::XTextRange> xEnd;
        // If we want to make this table a floating one.
        bool bFloating = !m_rDMapper_Impl.getTableManager().getTableVertAnchor().isEmpty();
        // Additional checks: if we can do this.
        if (bFloating && (*m_pTableSeq)[0].getLength() > 0 && (*m_pTableSeq)[0][0].getLength() > 0)
        {
            xStart = (*m_pTableSeq)[0][0][0];
            uno::Sequence< uno::Sequence< uno::Reference<text::XTextRange> > >& rLastRow = (*m_pTableSeq)[m_pTableSeq->getLength() - 1];
            uno::Sequence< uno::Reference<text::XTextRange> >& rLastCell = rLastRow[rLastRow.getLength() - 1];
            xEnd = rLastCell[1];
        }
        uno::Reference<text::XTextTable> xTable;
        try
        {
            if (m_xText.is())
            {
                uno::Reference<text::XTextTable> xTable = m_xText->convertToTable(*m_pTableSeq,
                xTable = m_xText->convertToTable(*m_pTableSeq,
                        aCellProperties,
                        aRowProperties,
                        aTableInfo.aTableProperties);
@@ -723,6 +737,55 @@ void DomainMapperTableHandler::endTable()
            (void) e;
#endif
        }

        // If we have a table with a start and an end position, we should make it a floating one.
        if (xTable.is() && xStart.is() && xEnd.is())
        {
            uno::Reference<beans::XPropertySet> xTableProperties(xTable, uno::UNO_QUERY);
            uno::Sequence< beans::PropertyValue > aFrameProperties(16);
            beans::PropertyValue* pFrameProperties = aFrameProperties.getArray();
            pFrameProperties[0].Name = "Width";
            pFrameProperties[0].Value = xTableProperties->getPropertyValue("Width");

            pFrameProperties[1].Name = "LeftBorderDistance";
            pFrameProperties[1].Value <<= sal_Int32(0);
            pFrameProperties[2].Name = "RightBorderDistance";
            pFrameProperties[2].Value <<= sal_Int32(0);
            pFrameProperties[3].Name = "TopBorderDistance";
            pFrameProperties[3].Value <<= sal_Int32(0);
            pFrameProperties[4].Name = "BottomBorderDistance";
            pFrameProperties[4].Value <<= sal_Int32(0);

            pFrameProperties[5].Name = "LeftMargin";
            pFrameProperties[5].Value <<= sal_Int32(0);
            pFrameProperties[6].Name = "RightMargin";
            pFrameProperties[6].Value <<= sal_Int32(0);
            pFrameProperties[7].Name = "TopMargin";
            pFrameProperties[7].Value <<= sal_Int32(0);
            pFrameProperties[8].Name = "BottomMargin";
            pFrameProperties[8].Value <<= sal_Int32(0);

            table::BorderLine2 aEmptyBorder;
            pFrameProperties[9].Name = "TopBorder";
            pFrameProperties[9].Value <<= aEmptyBorder;
            pFrameProperties[10].Name = "BottomBorder";
            pFrameProperties[10].Value <<= aEmptyBorder;
            pFrameProperties[11].Name = "LeftBorder";
            pFrameProperties[11].Value <<= aEmptyBorder;
            pFrameProperties[12].Name = "RightBorder";
            pFrameProperties[12].Value <<= aEmptyBorder;

            pFrameProperties[13].Name = "HoriOrient";
            pFrameProperties[13].Value <<= text::HoriOrientation::NONE;
            pFrameProperties[14].Name = "HoriOrientRelation";
            pFrameProperties[14].Value <<= text::RelOrientation::FRAME;
            // A non-zero left margin would move the table out of the frame, move the frame itself instead.
            pFrameProperties[15].Name = "HoriOrientPosition";
            pFrameProperties[15].Value <<= xTableProperties->getPropertyValue("LeftMargin");
            xTableProperties->setPropertyValue("LeftMargin", uno::makeAny(sal_Int32(0)));

            uno::Reference< text::XTextContent > xFrame = m_xText->convertToTextFrame(xStart, xEnd, aFrameProperties);
        }
    }

    m_aTableProperties.reset();
diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
index 46cf115..bdcaa70 100644
--- a/writerfilter/source/dmapper/DomainMapperTableManager.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
@@ -23,6 +23,7 @@
#include <CellMarginHandler.hxx>
#include <ConversionHelper.hxx>
#include <MeasureHandler.hxx>
#include <TablePositionHandler.hxx>
#include <TDefTableHandler.hxx>
#include <com/sun/star/text/HoriOrientation.hpp>
#include <com/sun/star/text/SizeType.hpp>
@@ -297,6 +298,17 @@ bool DomainMapperTableManager::sprm(Sprm & rSprm)
                    cellProps( pProps );
                }
                break;
            case NS_ooxml::LN_CT_TblPrBase_tblpPr:
                {
                    writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
                    if (pProperties.get())
                    {
                        TablePositionHandlerPtr pHandler( new TablePositionHandler );
                        pProperties->resolve(*pHandler);
                        m_sTableVertAnchor = pHandler->getVertAnchor();
                    }
                }
                break;
            default:
                bRet = false;

@@ -318,6 +330,11 @@ boost::shared_ptr< vector< sal_Int32 > > DomainMapperTableManager::getCurrentSpa
    return m_aGridSpans.back( );
}

const OUString& DomainMapperTableManager::getTableVertAnchor() const
{
    return m_sTableVertAnchor;
}

void DomainMapperTableManager::startLevel( )
{
    DomainMapperTableManager_Base_t::startLevel( );
@@ -512,6 +529,7 @@ void DomainMapperTableManager::clearData()
{
    m_nRow = m_nCell = m_nCellBorderIndex = m_nHeaderRepeat = m_nTableWidth = 0;
    m_sTableStyleName = OUString();
    m_sTableVertAnchor = OUString();
    m_pTableStyleTextProperies.reset();
}

diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.hxx b/writerfilter/source/dmapper/DomainMapperTableManager.hxx
index e41f50f..a005c2e 100644
--- a/writerfilter/source/dmapper/DomainMapperTableManager.hxx
+++ b/writerfilter/source/dmapper/DomainMapperTableManager.hxx
@@ -43,6 +43,7 @@ class DomainMapperTableManager : public DomainMapperTableManager_Base_t
    bool            m_bOOXML;
    bool            m_bImplicitMerges;
    OUString m_sTableStyleName;
    OUString m_sTableVertAnchor;
    PropertyMapPtr  m_pTableStyleTextProperies;

    ::std::vector< IntVectorPtr >  m_aTableGrid;
@@ -74,6 +75,7 @@ public:
    IntVectorPtr getCurrentSpans( );

    const OUString& getTableStyleName() const { return m_sTableStyleName; }
    const OUString& getTableVertAnchor() const;
    /// copy the text properties of the table style and its parent into pContext
    void    CopyTextProperties(PropertyMapPtr pContext, StyleSheetTablePtr pStyleSheetTable);

diff --git a/writerfilter/source/dmapper/TablePositionHandler.cxx b/writerfilter/source/dmapper/TablePositionHandler.cxx
new file mode 100644
index 0000000..e7d872a
--- /dev/null
+++ b/writerfilter/source/dmapper/TablePositionHandler.cxx
@@ -0,0 +1,61 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
#include <TablePositionHandler.hxx>
#include <PropertyMap.hxx>
#include <doctok/resourceids.hxx>
#include <ConversionHelper.hxx>
#include <ooxml/resourceids.hxx>
#include <com/sun/star/text/SizeType.hpp>
#include "dmapperLoggers.hxx"

namespace writerfilter {
namespace dmapper {

using namespace ::com::sun::star;

TablePositionHandler::TablePositionHandler() :
LoggedProperties(dmapper_logger, "TablePositionHandler")
{
}

TablePositionHandler::~TablePositionHandler()
{
}


void TablePositionHandler::lcl_attribute(Id rName, Value& rVal)
{
    switch (rName)
    {
        case NS_ooxml::LN_CT_TblPPr_vertAnchor:
            m_aVertAnchor = rVal.getString();
        break;
        default:
#ifdef DEBUG_DOMAINMAPPER
            dmapper_logger->element("unhandled");
#endif
            break;
    }
}


void TablePositionHandler::lcl_sprm(Sprm& /*rSprm*/)
{
}


OUString TablePositionHandler::getVertAnchor() const
{
    return m_aVertAnchor;
}

} // namespace dmapper
} // namespace writerfilter

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/TablePositionHandler.hxx b/writerfilter/source/dmapper/TablePositionHandler.hxx
new file mode 100644
index 0000000..ea4b154
--- /dev/null
+++ b/writerfilter/source/dmapper/TablePositionHandler.hxx
@@ -0,0 +1,42 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
#ifndef INCLUDED_POSITIONHANDLER_HXX
#define INCLUDED_POSITIONHANDLER_HXX

#include <WriterFilterDllApi.hxx>
#include <resourcemodel/LoggedResources.hxx>
#include <boost/shared_ptr.hpp>

namespace writerfilter {
    namespace dmapper {

        /// Handler for floating table positioning
        class WRITERFILTER_DLLPRIVATE TablePositionHandler
            : public LoggedProperties
        {
            OUString m_aVertAnchor;

            // Properties
            virtual void lcl_attribute(Id Name, Value & val);
            virtual void lcl_sprm(Sprm & sprm);

            public:
            TablePositionHandler();
            virtual ~TablePositionHandler();

            OUString getVertAnchor() const;
        };

        typedef boost::shared_ptr<TablePositionHandler> TablePositionHandlerPtr;
    } // namespace dmapper
} // namespace writerfilter

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index 10965f2..c98a6918 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -22825,6 +22825,9 @@
      <attribute name="w" tokenid="ooxml:CT_TblWidth_w"/>
      <attribute name="type" tokenid="ooxml:CT_TblWidth_type"/>
    </resource>
    <resource name="CT_TblPPr" resource="Properties" tag="table">
      <attribute name="vertAnchor" tokenid="ooxml:CT_TblPPr_vertAnchor"/>
    </resource>
    <resource name="CT_TblGridCol" resource="Value" tag="table">
      <attribute name="w" tokenid="ooxml:CT_TblGridCol_w" action="setValue"/>
      <action name="start" action="setDefaultIntegerValue"/>