sw/qa/extras/rtfimport/data/fdo72031.rtf | 1 sw/qa/extras/rtfimport/rtfimport.cxx | 9 unusedcode.easy | 1 writerfilter/CppunitTest_writerfilter_misc.mk | 1 writerfilter/Library_writerfilter.mk | 1 writerfilter/inc/resourcemodel/TableManager.hxx | 1148 --------------- writerfilter/inc/resourcemodel/TagLogger.hxx | 3 writerfilter/source/dmapper/DomainMapperTableHandler.hxx | 2 writerfilter/source/dmapper/DomainMapperTableManager.cxx | 8 writerfilter/source/dmapper/DomainMapperTableManager.hxx | 12 writerfilter/source/dmapper/DomainMapper_Impl.hxx | 1 writerfilter/source/dmapper/TableManager.cxx | 500 ++++++ writerfilter/source/dmapper/TableManager.hxx | 641 ++++++++ writerfilter/source/dmapper/TablePropertiesHandler.hxx | 9 writerfilter/source/resourcemodel/TagLogger.cxx | 11 writerfilter/source/rtftok/rtfdocumentimpl.cxx | 105 - writerfilter/source/rtftok/rtfsdrimport.cxx | 2 writerfilter/source/rtftok/rtfsprm.cxx | 6 writerfilter/source/rtftok/rtfsprm.hxx | 10 19 files changed, 1224 insertions(+), 1247 deletions(-)
New commits: commit 61672791db2fa5650b7021639bcaacfc534c75b5 Author: Miklos Vajna <[email protected]> Date: Sat Nov 29 15:40:58 2014 +0100 Avoid having TableManager as a template class It was always used with T=css::uno::Reference<css::text::XTextRange> Change-Id: If79413cf68ad5d5f6fc7aba1c065f49e5781d71d diff --git a/writerfilter/Library_writerfilter.mk b/writerfilter/Library_writerfilter.mk index 3ce1dd7..df2d1e1 100644 --- a/writerfilter/Library_writerfilter.mk +++ b/writerfilter/Library_writerfilter.mk @@ -101,6 +101,7 @@ $(eval $(call gb_Library_add_exception_objects,writerfilter,\ writerfilter/source/dmapper/SettingsTable \ writerfilter/source/dmapper/StyleSheetTable \ writerfilter/source/dmapper/TDefTableHandler \ + writerfilter/source/dmapper/TableManager \ writerfilter/source/dmapper/TablePositionHandler \ writerfilter/source/dmapper/TablePropertiesHandler \ writerfilter/source/dmapper/TextEffectsHandler \ diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx b/writerfilter/source/dmapper/DomainMapperTableManager.cxx index 1085a94..58771ca 100644 --- a/writerfilter/source/dmapper/DomainMapperTableManager.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx @@ -133,7 +133,7 @@ bool DomainMapperTableManager::sprm(Sprm & rSprm) dmapper_logger->chars(sSprm); dmapper_logger->endElement(); #endif - bool bRet = DomainMapperTableManager_Base_t::sprm(rSprm); + bool bRet = TableManager::sprm(rSprm); if( !bRet ) { bRet = m_pTablePropsHandler->sprm( rSprm ); @@ -521,7 +521,7 @@ void DomainMapperTableManager::setIsInShape(bool bIsInShape) void DomainMapperTableManager::startLevel( ) { - DomainMapperTableManager_Base_t::startLevel( ); + TableManager::startLevel( ); // If requested, pop the value that was pushed too early. boost::optional<sal_Int32> oCurrentWidth; @@ -576,7 +576,7 @@ void DomainMapperTableManager::endLevel( ) m_aTmpPosition.pop_back( ); m_aTmpTableProperties.pop_back( ); - DomainMapperTableManager_Base_t::endLevel( ); + TableManager::endLevel( ); #ifdef DEBUG_WRITERFILTER dmapper_logger->startElement("dmappertablemanager.endLevel"); PropertyMapPtr pProps = getTableProps(); @@ -826,7 +826,7 @@ void DomainMapperTableManager::endOfRowAction() } // Now that potentially opened table is closed, save the table properties - DomainMapperTableManager_Base_t::insertTableProps( pTmpTableProperties ); + TableManager::insertTableProps( pTmpTableProperties ); m_aTmpTableProperties.pop_back(); TablePropertyMapPtr pEmptyTableProps( new TablePropertyMap() ); diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.hxx b/writerfilter/source/dmapper/DomainMapperTableManager.hxx index 599c432..6333c3b 100644 --- a/writerfilter/source/dmapper/DomainMapperTableManager.hxx +++ b/writerfilter/source/dmapper/DomainMapperTableManager.hxx @@ -34,7 +34,7 @@ namespace dmapper { class DomainMapper; -class DomainMapperTableManager : public DomainMapperTableManager_Base_t +class DomainMapperTableManager : public TableManager { typedef boost::shared_ptr< std::vector<sal_Int32> > IntVectorPtr; @@ -111,7 +111,7 @@ public: if ( m_pStyleProps.get( ) ) m_pStyleProps->InsertProps(pProps); else - DomainMapperTableManager_Base_t::cellProps( pProps ); + TableManager::cellProps( pProps ); }; virtual void cellPropsByCell(unsigned int i, TablePropertyMapPtr pProps) SAL_OVERRIDE @@ -119,7 +119,7 @@ public: if ( m_pStyleProps.get( ) ) m_pStyleProps->InsertProps(pProps); else - DomainMapperTableManager_Base_t::cellPropsByCell( i, pProps ); + TableManager::cellPropsByCell( i, pProps ); }; virtual void insertRowProps(TablePropertyMapPtr pProps) SAL_OVERRIDE @@ -127,7 +127,7 @@ public: if ( m_pStyleProps.get( ) ) m_pStyleProps->InsertProps(pProps); else - DomainMapperTableManager_Base_t::insertRowProps( pProps ); + TableManager::insertRowProps( pProps ); }; virtual void insertTableProps(TablePropertyMapPtr pProps) SAL_OVERRIDE @@ -160,7 +160,7 @@ public: bool isInCell() { - return DomainMapperTableManager_Base_t::isInCell(); + return TableManager::isInCell(); } void setIsInShape(bool bIsInShape); diff --git a/writerfilter/source/dmapper/TableManager.cxx b/writerfilter/source/dmapper/TableManager.cxx new file mode 100644 index 0000000..a2de7ce --- /dev/null +++ b/writerfilter/source/dmapper/TableManager.cxx @@ -0,0 +1,500 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <TableManager.hxx> + +namespace writerfilter +{ +namespace dmapper +{ + +void TableManager::clearData() +{ +} + +void TableManager::openCell(const css::uno::Reference<css::text::XTextRange>& rHandle, TablePropertyMapPtr pProps) +{ +#ifdef DEBUG_WRITERFILTER + mpTableLogger->startElement("tablemanager.openCell"); + mpTableLogger->chars(toString(rHandle)); + mpTableLogger->endElement(); +#endif + + if (mTableDataStack.size() > 0) + { + TableData<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); + + pTableData->addCell(rHandle, pProps); + } +} + +bool TableManager::isIgnore() const +{ + return isRowEnd(); +} + +void TableManager::endOfRowAction() +{ +} + +void TableManager::endOfCellAction() +{ +} + +void TableManager::insertTableProps(TablePropertyMapPtr pProps) +{ +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->startElement("tablemanager.insertTableProps"); +#endif + + if (getTableProps().get() && getTableProps() != pProps) + getTableProps()->InsertProps(pProps); + else + setTableProps(pProps); + +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->endElement(); +#endif +} + +void TableManager::insertRowProps(TablePropertyMapPtr pProps) +{ +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->startElement("tablemanager.insertRowProps"); +#endif + + if (getRowProps().get()) + getRowProps()->InsertProps(pProps); + else + setRowProps(pProps); + +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->endElement(); +#endif +} + +void TableManager::cellPropsByCell(unsigned int i, TablePropertyMapPtr pProps) +{ +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->startElement("tablemanager.cellPropsByCell"); +#endif + + mTableDataStack.top()->insertCellProperties(i, pProps); + +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->endElement(); +#endif +} + +void TableManager::cellProps(TablePropertyMapPtr pProps) +{ +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->startElement("tablemanager.cellProps"); +#endif + + if (getCellProps().get()) + getCellProps()->InsertProps(pProps); + else + setCellProps(pProps); + +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->endElement(); +#endif +} + +void TableManager::utext(const sal_uInt8* data, size_t len) +{ + // optimization: cell/row end characters are the last characters in a run + + if (len > 0) + { + sal_Unicode nChar = data[(len - 1) * 2] + (data[(len - 1) * 2 + 1] << 8); + if (nChar == 0x7) + handle0x7(); + } +} + +void TableManager::text(const sal_uInt8* data, size_t len) +{ + // optimization: cell/row end characters are the last characters in a run + if (len > 0) + { + if (data[len - 1] == 0x7) + handle0x7(); + } +} + +void TableManager::handle0x7() +{ +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->startElement("tablemanager.handle0x7"); +#endif + + if (mnTableDepthNew < 1) + mnTableDepthNew = 1; + + if (isInCell()) + endCell(); + else + endRow(); + +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->endElement(); +#endif +} + +void TableManager::props(TablePropertyMapPtr pProps) +{ + setProps(pProps); +} + +bool TableManager::sprm(Sprm& rSprm) +{ + bool bRet = true; + switch (rSprm.getId()) + { + case NS_ooxml::LN_tblDepth: + { + Value::Pointer_t pValue = rSprm.getValue(); + + cellDepth(pValue->getInt()); + } + break; + case NS_ooxml::LN_inTbl: + inCell(); + break; + case NS_ooxml::LN_tblCell: + endCell(); + break; + case NS_ooxml::LN_tblRow: + endRow(); + break; + default: + bRet = false; + } + return bRet; +} + +void TableManager::closeCell(const css::uno::Reference<css::text::XTextRange>& rHandle) +{ +#ifdef DEBUG_WRITERFILTER + mpTableLogger->startElement("tablemanager.closeCell"); + mpTableLogger->chars(toString(rHandle)); + mpTableLogger->endElement(); +#endif + + if (mTableDataStack.size() > 0) + { + TableData<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); + + pTableData->endCell(rHandle); + } +} + +void TableManager::ensureOpenCell(TablePropertyMapPtr pProps) +{ +#ifdef DEBUG_WRITERFILTER + mpTableLogger->startElement("tablemanager.ensureOpenCell"); +#endif + + if (mTableDataStack.size() > 0) + { + TableData<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); + + if (pTableData.get() != nullptr) + { + if (!pTableData->isCellOpen()) + openCell(getHandle(), pProps); + else + pTableData->insertCellProperties(pProps); + } + } +#ifdef DEBUG_WRITERFILTER + mpTableLogger->endElement(); +#endif +} + +void TableManager::endParagraphGroup() +{ + sal_Int32 nTableDepthDifference = mnTableDepthNew - mnTableDepth; + + TablePropertyMapPtr pEmptyProps; + + while (nTableDepthDifference > 0) + { + ensureOpenCell(pEmptyProps); + startLevel(); + + --nTableDepthDifference; + } + while (nTableDepthDifference < 0) + { + endLevel(); + + ++nTableDepthDifference; + } + + mnTableDepth = mnTableDepthNew; + + if (mnTableDepth > 0) + { + TableData<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); + + if (isRowEnd()) + { + endOfRowAction(); + mTableDataStack.top()->endRow(getRowProps()); + resetRowProps(); + } + + else if (isInCell()) + { + ensureOpenCell(getCellProps()); + + if (isCellEnd()) + { + endOfCellAction(); + closeCell(getHandle()); + } + } + resetCellProps(); + } +} + +void TableManager::startParagraphGroup() +{ + mState.resetCellSpecifics(); + mnTableDepthNew = 0; +} + +void TableManager::resolveCurrentTable() +{ +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->startElement("tablemanager.resolveCurrentTable"); +#endif + + if (mpTableDataHandler.get() != nullptr) + { + try + { + TableData<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); + + unsigned int nRows = pTableData->getRowCount(); + + mpTableDataHandler->startTable(nRows, pTableData->getDepth(), getTableProps()); + + for (unsigned int nRow = 0; nRow < nRows; ++nRow) + { + RowData<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>::Pointer_t pRowData = pTableData->getRow(nRow); + + unsigned int nCells = pRowData->getCellCount(); + + mpTableDataHandler->startRow(nCells, pRowData->getProperties()); + + for (unsigned int nCell = 0; nCell < nCells; ++nCell) + { + mpTableDataHandler->startCell(pRowData->getCellStart(nCell), pRowData->getCellProperties(nCell)); + + mpTableDataHandler->endCell(pRowData->getCellEnd(nCell)); + } + + mpTableDataHandler->endRow(); + } + + mpTableDataHandler->endTable(mTableDataStack.size() - 1); + } + catch (css::uno::Exception const& e) + { + SAL_WARN("writerfilter", "resolving of current table failed with: " << e.Message); + } + } + resetTableProps(); + clearData(); + +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->endElement(); +#endif +} + +void TableManager::endLevel() +{ + if (mpTableDataHandler.get() != nullptr) + resolveCurrentTable(); + + // Store the unfinished row as it will be used for the next table + if (mbKeepUnfinishedRow) + mpUnfinishedRow = mTableDataStack.top()->getCurrentRow(); + mState.endLevel(); + mTableDataStack.pop(); + +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + { + TableData<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>::Pointer_t pTableData; + + if (mTableDataStack.size() > 0) + pTableData = mTableDataStack.top(); + + mpTableLogger->startElement("tablemanager.endLevel"); + mpTableLogger->attribute("level", mTableDataStack.size()); + + if (pTableData.get() != nullptr) + mpTableLogger->attribute("openCell", pTableData->isCellOpen() ? "yes" : "no"); + + mpTableLogger->endElement(); + } +#endif +} + +void TableManager::startLevel() +{ +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + { + TableData<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>::Pointer_t pTableData; + + if (mTableDataStack.size() > 0) + pTableData = mTableDataStack.top(); + + mpTableLogger->startElement("tablemanager.startLevel"); + mpTableLogger->attribute("level", mTableDataStack.size()); + + if (pTableData.get() != nullptr) + mpTableLogger->attribute("openCell", pTableData->isCellOpen() ? "yes" : "no"); + + mpTableLogger->endElement(); + } +#endif + + TableData<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>::Pointer_t + pTableData(new TableData<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>(mTableDataStack.size())); + + // If we have an unfinished row stored here, then push it to the new TableData + if (mpUnfinishedRow) + { + for (unsigned int i = 0; i < mpUnfinishedRow->getCellCount(); ++i) + { + pTableData->addCell(mpUnfinishedRow->getCellStart(i), mpUnfinishedRow->getCellProperties(i)); + pTableData->endCell(mpUnfinishedRow->getCellEnd(i)); + } + mpUnfinishedRow.reset(); + } + + mTableDataStack.push(pTableData); + mState.startLevel(); +} + +bool TableManager::isInTable() +{ + bool bInTable = false; + if (!mTableDataStack.empty()) + bInTable = mTableDataStack.top()->getDepth() > 0; + return bInTable; +} + +void TableManager::handle(const css::uno::Reference<css::text::XTextRange>& rHandle) +{ +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger) + { + mpTableLogger->startElement("tablemanager.handle"); + mpTableLogger->chars(toString(rHandle)); + mpTableLogger->endElement(); + } +#endif + + setHandle(rHandle); +} + +void TableManager::setHandler(TableDataHandler<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>::Pointer_t pTableDataHandler) +{ + mpTableDataHandler = pTableDataHandler; +} + +void TableManager::endRow() +{ +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->element("tablemanager.endRow"); +#endif + + setRowEnd(true); +} + +void TableManager::endCell() +{ +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->element("tablemanager.endCell"); +#endif + + setCellEnd(true); +} + +void TableManager::inCell() +{ +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + mpTableLogger->element("tablemanager.inCell"); +#endif + setInCell(true); + + if (mnTableDepthNew < 1) + mnTableDepthNew = 1; +} + +void TableManager::cellDepth(sal_uInt32 nDepth) +{ +#ifdef DEBUG_WRITERFILTER + if (mpTableLogger != nullptr) + { + mpTableLogger->startElement("tablemanager.cellDepth"); + mpTableLogger->attribute("depth", nDepth); + mpTableLogger->endElement(); + } +#endif + + mnTableDepthNew = nDepth; +} + +TableManager::TableManager() + : mnTableDepthNew(0), mnTableDepth(0), mbKeepUnfinishedRow(false) +{ + setRowEnd(false); + setInCell(false); + setCellEnd(false); +} + +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TableManager.hxx b/writerfilter/source/dmapper/TableManager.hxx index 5f8b1f6..33d804d 100644 --- a/writerfilter/source/dmapper/TableManager.hxx +++ b/writerfilter/source/dmapper/TableManager.hxx @@ -96,7 +96,6 @@ protected: ~TableDataHandler() {} }; -template <typename T> /** The table manager. @@ -283,7 +282,7 @@ class TableManager /** handle for the current position in document */ - T mCurHandle; + css::uno::Reference<css::text::XTextRange> mCurHandle; TableManagerState mState; @@ -378,18 +377,18 @@ protected: mState.resetTableProps(); } - T getHandle() + css::uno::Reference<css::text::XTextRange> getHandle() { return mCurHandle; } - void setHandle(const T & rHandle) + void setHandle(const css::uno::Reference<css::text::XTextRange>& rHandle) { mCurHandle = rHandle; } private: - typedef boost::shared_ptr<T> T_p; + typedef boost::shared_ptr< css::uno::Reference<css::text::XTextRange> > T_p; /** depth of the current cell @@ -406,11 +405,11 @@ private: for each level of nested tables there is one frame in the stack */ - std::stack<typename TableData<T, TablePropertyMapPtr>::Pointer_t > mTableDataStack; - typename RowData<T, TablePropertyMapPtr>::Pointer_t mpUnfinishedRow; + std::stack<typename TableData<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>::Pointer_t > mTableDataStack; + typename RowData<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>::Pointer_t mpUnfinishedRow; bool mbKeepUnfinishedRow; - typedef typename TableDataHandler<T, TablePropertyMapPtr>::Pointer_t TableDataHandlerPointer_t; + typedef typename TableDataHandler<css::uno::Reference<css::text::XTextRange>, TablePropertyMapPtr>::Pointer_t TableDataHandlerPointer_t; /** handler for resolveCurrentTable @@ -448,12 +447,12 @@ private: Open a cell at current level. */ - void openCell(const T & handle, TablePropertyMapPtr pProps); + void openCell(const css::uno::Reference<css::text::XTextRange>& handle, TablePropertyMapPtr pProps); /** Close a cell at current level. */ - void closeCell(const T & handle); + void closeCell(const css::uno::Reference<css::text::XTextRange>& handle); /** Ensure a cell is open at the current level. @@ -512,7 +511,7 @@ public: @param rHandle the handle */ - virtual void handle(const T & rHandle); + virtual void handle(const css::uno::Reference<css::text::XTextRange>& rHandle); /** Start a new table level. @@ -633,504 +632,6 @@ public: #endif }; -template <typename T> -TableManager<T>::TableManager() -: mnTableDepthNew(0), mnTableDepth(0), mbKeepUnfinishedRow( false ) -{ - setRowEnd(false); - setInCell(false); - setCellEnd(false); -} - -template <typename T> -void TableManager<T>::cellDepth(sal_uInt32 nDepth) -{ -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - { - mpTableLogger->startElement("tablemanager.cellDepth"); - mpTableLogger->attribute("depth", nDepth); - mpTableLogger->endElement(); - } -#endif - - mnTableDepthNew = nDepth; -} - -template <typename T> -void TableManager<T>::inCell() -{ -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->element("tablemanager.inCell"); -#endif - setInCell(true); - - if (mnTableDepthNew < 1) - mnTableDepthNew = 1; -} - -template <typename T> -void TableManager<T>::endCell() -{ -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->element("tablemanager.endCell"); -#endif - - setCellEnd(true); -} - -template <typename T> -void TableManager<T>::endRow() -{ -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->element("tablemanager.endRow"); -#endif - - setRowEnd(true); -} - -template <typename T> -void TableManager<T>::setHandler(typename TableDataHandler<T, TablePropertyMapPtr>::Pointer_t pTableDataHandler) -{ - mpTableDataHandler = pTableDataHandler; -} - -template <typename T> -void TableManager<T>::handle(const T & rHandle) -{ -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger) - { - mpTableLogger->startElement("tablemanager.handle"); - mpTableLogger->chars(toString(rHandle)); - mpTableLogger->endElement(); - } -#endif - - setHandle(rHandle); -} - -template <typename T> -bool TableManager<T>::isInTable() -{ - bool bInTable = false; - if ( !mTableDataStack.empty() ) - bInTable = mTableDataStack.top()->getDepth() > 0; - return bInTable; -} - -template <typename T> -void TableManager<T>::startLevel() -{ -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - { - typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData; - - if (mTableDataStack.size() > 0) - pTableData = mTableDataStack.top(); - - mpTableLogger->startElement("tablemanager.startLevel"); - mpTableLogger->attribute("level", mTableDataStack.size()); - - if (pTableData.get() != nullptr) - mpTableLogger->attribute("openCell", - pTableData->isCellOpen() ? "yes" : "no"); - - mpTableLogger->endElement(); - } -#endif - - typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData(new TableData<T, TablePropertyMapPtr>(mTableDataStack.size())); - - // If we have an unfinished row stored here, then push it to the new TableData - if ( mpUnfinishedRow ) - { - for (unsigned int i = 0; i < mpUnfinishedRow->getCellCount(); ++i) - { - pTableData->addCell( mpUnfinishedRow->getCellStart(i), - mpUnfinishedRow->getCellProperties(i) ); - pTableData->endCell( mpUnfinishedRow->getCellEnd(i) ); - } - mpUnfinishedRow.reset(); - } - - mTableDataStack.push(pTableData); - mState.startLevel(); -} - -template <typename T> -void TableManager<T>::endLevel() -{ - if (mpTableDataHandler.get() != nullptr) - resolveCurrentTable(); - - // Store the unfinished row as it will be used for the next table - if ( mbKeepUnfinishedRow ) - mpUnfinishedRow = mTableDataStack.top()->getCurrentRow(); - mState.endLevel(); - mTableDataStack.pop(); - -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - { - typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData; - - if (mTableDataStack.size() > 0) - pTableData = mTableDataStack.top(); - - mpTableLogger->startElement("tablemanager.endLevel"); - mpTableLogger->attribute("level", mTableDataStack.size()); - - if (pTableData.get() != nullptr) - mpTableLogger->attribute("openCell", pTableData->isCellOpen() ? "yes" : "no"); - - mpTableLogger->endElement(); - } -#endif -} - -template <typename T> -void TableManager<T>::startParagraphGroup() -{ - mState.resetCellSpecifics(); - mnTableDepthNew = 0; -} - -template <typename T> -void TableManager<T>::endParagraphGroup() -{ - sal_Int32 nTableDepthDifference = mnTableDepthNew - mnTableDepth; - - TablePropertyMapPtr pEmptyProps; - - while (nTableDepthDifference > 0) - { - ensureOpenCell(pEmptyProps); - startLevel(); - - --nTableDepthDifference; - } - while (nTableDepthDifference < 0) - { - endLevel(); - - ++nTableDepthDifference; - } - - mnTableDepth = mnTableDepthNew; - - if (mnTableDepth > 0) - { - typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); - - if (isRowEnd()) - { - endOfRowAction(); - mTableDataStack.top()->endRow(getRowProps()); - resetRowProps(); - } - - else if (isInCell()) - { - ensureOpenCell(getCellProps()); - - if (isCellEnd()) - { - endOfCellAction(); - closeCell(getHandle()); - } - } - resetCellProps(); - } -} - -template <typename T> -bool TableManager<T>::sprm(Sprm & rSprm) -{ - bool bRet = true; - switch (rSprm.getId()) - { - case NS_ooxml::LN_tblDepth: - { - Value::Pointer_t pValue = rSprm.getValue(); - - cellDepth(pValue->getInt()); - } - break; - case NS_ooxml::LN_inTbl: - inCell(); - break; - case NS_ooxml::LN_tblCell: - endCell(); - break; - case NS_ooxml::LN_tblRow: - endRow(); - break; - default: - bRet = false; - } - return bRet; -} -template <typename T> -void TableManager<T>::props(TablePropertyMapPtr pProps) -{ - setProps(pProps); -} - -template <typename T> -void TableManager<T>::handle0x7() -{ -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->startElement("tablemanager.handle0x7"); -#endif - - if (mnTableDepthNew < 1) - mnTableDepthNew = 1; - - if (isInCell()) - endCell(); - else - endRow(); - -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->endElement(); -#endif -} - -template <typename T> -void TableManager<T>::text(const sal_uInt8 * data, size_t len) -{ - // optimization: cell/row end characters are the last characters in a run - if (len > 0) - { - if (data[len - 1] == 0x7) - handle0x7(); - } -} - -template <typename T> -void TableManager<T>::utext(const sal_uInt8 * data, size_t len) -{ - // optimization: cell/row end characters are the last characters in a run - - if (len > 0) - { - sal_Unicode nChar = data[(len - 1) * 2] + (data[(len - 1) * 2 + 1] << 8); - if (nChar == 0x7) - handle0x7(); - } -} - -template <typename T> -void TableManager<T>::cellProps(TablePropertyMapPtr pProps) -{ -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->startElement("tablemanager.cellProps"); -#endif - - if(getCellProps().get()) - getCellProps()->InsertProps(pProps); - else - setCellProps(pProps); - -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->endElement(); -#endif -} - -template <typename T> -void TableManager<T>::cellPropsByCell(unsigned int i, TablePropertyMapPtr pProps) -{ -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->startElement("tablemanager.cellPropsByCell"); -#endif - - mTableDataStack.top()->insertCellProperties(i, pProps); - -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->endElement(); -#endif -} - -template <typename T> -void TableManager<T>::insertRowProps(TablePropertyMapPtr pProps) -{ -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->startElement("tablemanager.insertRowProps"); -#endif - - if( getRowProps().get() ) - getRowProps()->InsertProps(pProps); - else - setRowProps(pProps); - -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->endElement(); -#endif -} - -template <typename T> -void TableManager<T>::insertTableProps(TablePropertyMapPtr pProps) -{ -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->startElement("tablemanager.insertTableProps"); -#endif - - if( getTableProps().get() && getTableProps() != pProps) - getTableProps()->InsertProps(pProps); - else - setTableProps(pProps); - -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->endElement(); -#endif -} - -template <typename T> -void TableManager<T>::resolveCurrentTable() -{ -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->startElement("tablemanager.resolveCurrentTable"); -#endif - - if (mpTableDataHandler.get() != nullptr) - { - try - { - typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); - - unsigned int nRows = pTableData->getRowCount(); - - mpTableDataHandler->startTable(nRows, pTableData->getDepth(), getTableProps()); - - for (unsigned int nRow = 0; nRow < nRows; ++nRow) - { - typename RowData<T, TablePropertyMapPtr>::Pointer_t pRowData = pTableData->getRow(nRow); - - unsigned int nCells = pRowData->getCellCount(); - - mpTableDataHandler->startRow(nCells, pRowData->getProperties()); - - for (unsigned int nCell = 0; nCell < nCells; ++nCell) - { - mpTableDataHandler->startCell(pRowData->getCellStart(nCell), pRowData->getCellProperties(nCell)); - - mpTableDataHandler->endCell(pRowData->getCellEnd(nCell)); - } - - mpTableDataHandler->endRow(); - } - - mpTableDataHandler->endTable(mTableDataStack.size() - 1); - } - catch (css::uno::Exception const& e) - { - SAL_WARN("writerfilter", "resolving of current table failed with: " << e.Message); - } - } - resetTableProps(); - clearData(); - -#ifdef DEBUG_WRITERFILTER - if (mpTableLogger != nullptr) - mpTableLogger->endElement(); -#endif -} - -template <typename T> -void TableManager<T>::endOfCellAction() -{ -} - -template <typename T> -void TableManager<T>::endOfRowAction() -{ -} - -template <typename T> -bool TableManager<T>::isIgnore() const -{ - return isRowEnd(); -} - -template <typename T> -void TableManager<T>::clearData() -{ -} - -template <typename T> -void TableManager<T>::openCell(const T & rHandle, TablePropertyMapPtr pProps) -{ -#ifdef DEBUG_WRITERFILTER - mpTableLogger->startElement("tablemanager.openCell"); - mpTableLogger->chars(toString(rHandle)); - mpTableLogger->endElement(); -#endif - - if (mTableDataStack.size() > 0) - { - typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); - - pTableData->addCell(rHandle, pProps); - } -} - -template <typename T> -void TableManager<T>::closeCell(const T & rHandle) -{ -#ifdef DEBUG_WRITERFILTER - mpTableLogger->startElement("tablemanager.closeCell"); - mpTableLogger->chars(toString(rHandle)); - mpTableLogger->endElement(); -#endif - - if (mTableDataStack.size() > 0) - { - typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); - - pTableData->endCell(rHandle); - } -} - -template <typename T> -void TableManager<T>::ensureOpenCell(TablePropertyMapPtr pProps) -{ -#ifdef DEBUG_WRITERFILTER - mpTableLogger->startElement("tablemanager.ensureOpenCell"); -#endif - - if (mTableDataStack.size() > 0) - { - typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); - - if (pTableData.get() != nullptr) - { - if (!pTableData->isCellOpen()) - openCell(getHandle(), pProps); - else - pTableData->insertCellProperties(pProps); - } - } -#ifdef DEBUG_WRITERFILTER - mpTableLogger->endElement(); -#endif -} - } } diff --git a/writerfilter/source/dmapper/TablePropertiesHandler.hxx b/writerfilter/source/dmapper/TablePropertiesHandler.hxx index c0b95d4..e9d5c4e 100644 --- a/writerfilter/source/dmapper/TablePropertiesHandler.hxx +++ b/writerfilter/source/dmapper/TablePropertiesHandler.hxx @@ -34,16 +34,13 @@ namespace dmapper { class DomainMapper; -typedef ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > Handle_t; -typedef TableManager<Handle_t> DomainMapperTableManager_Base_t; - class TablePropertiesHandler { private: std::vector< PropertyMapPtr > m_rPropertiesStack; PropertyMapPtr m_pCurrentProperties; std::vector<css::beans::PropertyValue>* m_pCurrentInteropGrabBag; - DomainMapperTableManager_Base_t *m_pTableManager; + TableManager* m_pTableManager; bool m_bOOXML; public: @@ -52,7 +49,7 @@ public: bool sprm(Sprm & sprm); - inline void SetTableManager( DomainMapperTableManager_Base_t *pTableManager ) + inline void SetTableManager( TableManager* pTableManager ) { m_pTableManager = pTableManager; }; commit 45234fd21ad76b7732be4e5783cc7dd5dcf2daa2 Author: Miklos Vajna <[email protected]> Date: Sat Nov 29 14:40:40 2014 +0100 TableManager is only used with PropertiesPointer=TablePropertyMapPtr Change-Id: Ie036cafd769328d9d5cc42265534ed8f7c0d0f2c diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index 8daf26e..bdebc23 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -309,7 +309,6 @@ class DomainMapper; class DomainMapper_Impl { public: - typedef TableManager< ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange >, PropertyMapPtr > TableManager_t; typedef TableDataHandler< ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange >, TablePropertyMapPtr > TableDataHandler_t; typedef std::map < OUString, BookmarkInsertPosition > BookmarkMap_t; diff --git a/writerfilter/source/dmapper/TableManager.hxx b/writerfilter/source/dmapper/TableManager.hxx index 6bac58d3..5f8b1f6 100644 --- a/writerfilter/source/dmapper/TableManager.hxx +++ b/writerfilter/source/dmapper/TableManager.hxx @@ -32,9 +32,12 @@ #include <resourcemodel/TagLogger.hxx> #include <rtl/strbuf.hxx> +#include <PropertyMap.hxx> namespace writerfilter { +namespace dmapper +{ /** Class to handle events generated by TableManager::resolveCurrentTable @@ -93,7 +96,7 @@ protected: ~TableDataHandler() {} }; -template <typename T, typename PropertiesPointer> +template <typename T> /** The table manager. @@ -113,22 +116,22 @@ class TableManager /** properties at the current point in document */ - PropertiesPointer mpProps; + TablePropertyMapPtr mpProps; /** properties of the current cell */ - PropertiesPointer mpCellProps; + TablePropertyMapPtr mpCellProps; /** properties of the current row */ - PropertiesPointer mpRowProps; + TablePropertyMapPtr mpRowProps; /** properties of the current table */ - std::stack<PropertiesPointer> mTableProps; + std::stack<TablePropertyMapPtr> mTableProps; /** true if at the end of a row @@ -160,7 +163,7 @@ class TableManager void startLevel() { - PropertiesPointer pProps; + TablePropertyMapPtr pProps; mTableProps.push(pProps); } @@ -184,12 +187,12 @@ class TableManager mpProps.reset(); } - void setProps(PropertiesPointer pProps) + void setProps(TablePropertyMapPtr pProps) { mpProps = pProps; } - PropertiesPointer getProps() + TablePropertyMapPtr getProps() { return mpProps; } @@ -199,12 +202,12 @@ class TableManager mpCellProps.reset(); } - void setCellProps(PropertiesPointer pProps) + void setCellProps(TablePropertyMapPtr pProps) { mpCellProps = pProps; } - PropertiesPointer getCellProps() + TablePropertyMapPtr getCellProps() { return mpCellProps; } @@ -214,12 +217,12 @@ class TableManager mpRowProps.reset(); } - void setRowProps(PropertiesPointer pProps) + void setRowProps(TablePropertyMapPtr pProps) { mpRowProps = pProps; } - PropertiesPointer getRowProps() + TablePropertyMapPtr getRowProps() { return mpRowProps; } @@ -230,15 +233,15 @@ class TableManager mTableProps.top().reset(); } - void setTableProps(PropertiesPointer pProps) + void setTableProps(TablePropertyMapPtr pProps) { if (mTableProps.size() > 0) mTableProps.top() = pProps; } - PropertiesPointer getTableProps() + TablePropertyMapPtr getTableProps() { - PropertiesPointer pResult; + TablePropertyMapPtr pResult; if (mTableProps.size() > 0) pResult = mTableProps.top(); @@ -285,12 +288,12 @@ class TableManager TableManagerState mState; protected: - PropertiesPointer getProps() + TablePropertyMapPtr getProps() { return mState.getProps(); } - void setProps(PropertiesPointer pProps) + void setProps(TablePropertyMapPtr pProps) { mState.setProps(pProps); } @@ -300,12 +303,12 @@ protected: mState.resetProps(); } - PropertiesPointer getCellProps() + TablePropertyMapPtr getCellProps() { return mState.getCellProps(); } - void setCellProps(PropertiesPointer pProps) + void setCellProps(TablePropertyMapPtr pProps) { mState.setCellProps(pProps); } @@ -315,12 +318,12 @@ protected: mState.resetCellProps(); } - PropertiesPointer getRowProps() + TablePropertyMapPtr getRowProps() { return mState.getRowProps(); } - void setRowProps(PropertiesPointer pProps) + void setRowProps(TablePropertyMapPtr pProps) { mState.setRowProps(pProps); } @@ -360,12 +363,12 @@ protected: return mState.isRowEnd(); } - PropertiesPointer getTableProps() + TablePropertyMapPtr getTableProps() { return mState.getTableProps(); } - void setTableProps(PropertiesPointer pProps) + void setTableProps(TablePropertyMapPtr pProps) { mState.setTableProps(pProps); } @@ -403,11 +406,11 @@ private: for each level of nested tables there is one frame in the stack */ - std::stack<typename TableData<T, PropertiesPointer>::Pointer_t > mTableDataStack; - typename RowData<T, PropertiesPointer>::Pointer_t mpUnfinishedRow; + std::stack<typename TableData<T, TablePropertyMapPtr>::Pointer_t > mTableDataStack; + typename RowData<T, TablePropertyMapPtr>::Pointer_t mpUnfinishedRow; bool mbKeepUnfinishedRow; - typedef typename TableDataHandler<T, PropertiesPointer>::Pointer_t TableDataHandlerPointer_t; + typedef typename TableDataHandler<T, TablePropertyMapPtr>::Pointer_t TableDataHandlerPointer_t; /** handler for resolveCurrentTable @@ -445,7 +448,7 @@ private: Open a cell at current level. */ - void openCell(const T & handle, PropertiesPointer pProps); + void openCell(const T & handle, TablePropertyMapPtr pProps); /** Close a cell at current level. @@ -455,7 +458,7 @@ private: /** Ensure a cell is open at the current level. */ - void ensureOpenCell(PropertiesPointer pProps); + void ensureOpenCell(TablePropertyMapPtr pProps); protected: @@ -561,7 +564,7 @@ public: @param pProps the properites */ - virtual void props(PropertiesPointer pProps); + virtual void props(TablePropertyMapPtr pProps); /** Handle occurrence of character 0x7. @@ -589,7 +592,7 @@ public: @param pProps the properties */ - virtual void cellProps(PropertiesPointer pProps); + virtual void cellProps(TablePropertyMapPtr pProps); /** Handle properties of a certain cell in the current row. @@ -597,21 +600,21 @@ public: @paran i index of the cell in the current row @param pProps the properties */ - virtual void cellPropsByCell(unsigned int i, PropertiesPointer pProps); + virtual void cellPropsByCell(unsigned int i, TablePropertyMapPtr pProps); /** Handle properties of the current row. @param pProps the properties */ - virtual void insertRowProps(PropertiesPointer pProps); + virtual void insertRowProps(TablePropertyMapPtr pProps); /** Handle properties of the current table. @param pProps the properties */ - virtual void insertTableProps(PropertiesPointer pProps); + virtual void insertTableProps(TablePropertyMapPtr pProps); /** Return if table manager has detected paragraph to ignore. @@ -630,8 +633,8 @@ public: #endif }; -template <typename T, typename PropertiesPointer> -TableManager<T, PropertiesPointer>::TableManager() +template <typename T> +TableManager<T>::TableManager() : mnTableDepthNew(0), mnTableDepth(0), mbKeepUnfinishedRow( false ) { setRowEnd(false); @@ -639,8 +642,8 @@ TableManager<T, PropertiesPointer>::TableManager() setCellEnd(false); } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::cellDepth(sal_uInt32 nDepth) +template <typename T> +void TableManager<T>::cellDepth(sal_uInt32 nDepth) { #ifdef DEBUG_WRITERFILTER if (mpTableLogger != nullptr) @@ -654,8 +657,8 @@ void TableManager<T, PropertiesPointer>::cellDepth(sal_uInt32 nDepth) mnTableDepthNew = nDepth; } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::inCell() +template <typename T> +void TableManager<T>::inCell() { #ifdef DEBUG_WRITERFILTER if (mpTableLogger != nullptr) @@ -667,8 +670,8 @@ void TableManager<T, PropertiesPointer>::inCell() mnTableDepthNew = 1; } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::endCell() +template <typename T> +void TableManager<T>::endCell() { #ifdef DEBUG_WRITERFILTER if (mpTableLogger != nullptr) @@ -678,8 +681,8 @@ void TableManager<T, PropertiesPointer>::endCell() setCellEnd(true); } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::endRow() +template <typename T> +void TableManager<T>::endRow() { #ifdef DEBUG_WRITERFILTER if (mpTableLogger != nullptr) @@ -689,15 +692,14 @@ void TableManager<T, PropertiesPointer>::endRow() setRowEnd(true); } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::setHandler -(typename TableDataHandler<T, PropertiesPointer>::Pointer_t pTableDataHandler) +template <typename T> +void TableManager<T>::setHandler(typename TableDataHandler<T, TablePropertyMapPtr>::Pointer_t pTableDataHandler) { mpTableDataHandler = pTableDataHandler; } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::handle(const T & rHandle) +template <typename T> +void TableManager<T>::handle(const T & rHandle) { #ifdef DEBUG_WRITERFILTER if (mpTableLogger) @@ -711,8 +713,8 @@ void TableManager<T, PropertiesPointer>::handle(const T & rHandle) setHandle(rHandle); } -template <typename T, typename PropertiesPointer> -bool TableManager<T, PropertiesPointer>::isInTable() +template <typename T> +bool TableManager<T>::isInTable() { bool bInTable = false; if ( !mTableDataStack.empty() ) @@ -720,13 +722,13 @@ bool TableManager<T, PropertiesPointer>::isInTable() return bInTable; } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::startLevel() +template <typename T> +void TableManager<T>::startLevel() { #ifdef DEBUG_WRITERFILTER if (mpTableLogger != nullptr) { - typename TableData<T, PropertiesPointer>::Pointer_t pTableData; + typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData; if (mTableDataStack.size() > 0) pTableData = mTableDataStack.top(); @@ -742,8 +744,7 @@ void TableManager<T, PropertiesPointer>::startLevel() } #endif - typename TableData<T, PropertiesPointer>::Pointer_t pTableData - (new TableData<T, PropertiesPointer>(mTableDataStack.size())); + typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData(new TableData<T, TablePropertyMapPtr>(mTableDataStack.size())); // If we have an unfinished row stored here, then push it to the new TableData if ( mpUnfinishedRow ) @@ -761,8 +762,8 @@ void TableManager<T, PropertiesPointer>::startLevel() mState.startLevel(); } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::endLevel() +template <typename T> +void TableManager<T>::endLevel() { if (mpTableDataHandler.get() != nullptr) resolveCurrentTable(); @@ -776,7 +777,7 @@ void TableManager<T, PropertiesPointer>::endLevel() #ifdef DEBUG_WRITERFILTER if (mpTableLogger != nullptr) { - typename TableData<T, PropertiesPointer>::Pointer_t pTableData; + typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData; if (mTableDataStack.size() > 0) pTableData = mTableDataStack.top(); @@ -785,27 +786,26 @@ void TableManager<T, PropertiesPointer>::endLevel() mpTableLogger->attribute("level", mTableDataStack.size()); if (pTableData.get() != nullptr) - mpTableLogger->attribute("openCell", - pTableData->isCellOpen() ? "yes" : "no"); + mpTableLogger->attribute("openCell", pTableData->isCellOpen() ? "yes" : "no"); mpTableLogger->endElement(); } #endif } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::startParagraphGroup() +template <typename T> +void TableManager<T>::startParagraphGroup() { mState.resetCellSpecifics(); mnTableDepthNew = 0; } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::endParagraphGroup() +template <typename T> +void TableManager<T>::endParagraphGroup() { sal_Int32 nTableDepthDifference = mnTableDepthNew - mnTableDepth; - PropertiesPointer pEmptyProps; + TablePropertyMapPtr pEmptyProps; while (nTableDepthDifference > 0) { @@ -825,8 +825,7 @@ void TableManager<T, PropertiesPointer>::endParagraphGroup() if (mnTableDepth > 0) { - typename TableData<T, PropertiesPointer>::Pointer_t pTableData = - mTableDataStack.top(); + typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); if (isRowEnd()) { @@ -849,8 +848,8 @@ void TableManager<T, PropertiesPointer>::endParagraphGroup() } } -template <typename T, typename PropertiesPointer> -bool TableManager<T, PropertiesPointer>::sprm(Sprm & rSprm) +template <typename T> +bool TableManager<T>::sprm(Sprm & rSprm) { bool bRet = true; switch (rSprm.getId()) @@ -876,14 +875,14 @@ bool TableManager<T, PropertiesPointer>::sprm(Sprm & rSprm) } return bRet; } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::props(PropertiesPointer pProps) +template <typename T> +void TableManager<T>::props(TablePropertyMapPtr pProps) { setProps(pProps); } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::handle0x7() +template <typename T> +void TableManager<T>::handle0x7() { #ifdef DEBUG_WRITERFILTER if (mpTableLogger != nullptr) @@ -904,8 +903,8 @@ void TableManager<T, PropertiesPointer>::handle0x7() #endif } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::text(const sal_uInt8 * data, size_t len) +template <typename T> +void TableManager<T>::text(const sal_uInt8 * data, size_t len) { // optimization: cell/row end characters are the last characters in a run if (len > 0) @@ -915,8 +914,8 @@ void TableManager<T, PropertiesPointer>::text(const sal_uInt8 * data, size_t len } } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::utext(const sal_uInt8 * data, size_t len) +template <typename T> +void TableManager<T>::utext(const sal_uInt8 * data, size_t len) { // optimization: cell/row end characters are the last characters in a run @@ -928,8 +927,8 @@ void TableManager<T, PropertiesPointer>::utext(const sal_uInt8 * data, size_t le } } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::cellProps(PropertiesPointer pProps) +template <typename T> +void TableManager<T>::cellProps(TablePropertyMapPtr pProps) { #ifdef DEBUG_WRITERFILTER if (mpTableLogger != nullptr) @@ -947,9 +946,8 @@ void TableManager<T, PropertiesPointer>::cellProps(PropertiesPointer pProps) #endif } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::cellPropsByCell -(unsigned int i, PropertiesPointer pProps) +template <typename T> +void TableManager<T>::cellPropsByCell(unsigned int i, TablePropertyMapPtr pProps) { #ifdef DEBUG_WRITERFILTER if (mpTableLogger != nullptr) @@ -964,8 +962,8 @@ void TableManager<T, PropertiesPointer>::cellPropsByCell #endif } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::insertRowProps(PropertiesPointer pProps) +template <typename T> +void TableManager<T>::insertRowProps(TablePropertyMapPtr pProps) { #ifdef DEBUG_WRITERFILTER if (mpTableLogger != nullptr) @@ -983,8 +981,8 @@ void TableManager<T, PropertiesPointer>::insertRowProps(PropertiesPointer pProps #endif } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::insertTableProps(PropertiesPointer pProps) +template <typename T> +void TableManager<T>::insertTableProps(TablePropertyMapPtr pProps) { #ifdef DEBUG_WRITERFILTER if (mpTableLogger != nullptr) @@ -1002,8 +1000,8 @@ void TableManager<T, PropertiesPointer>::insertTableProps(PropertiesPointer pPro #endif } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::resolveCurrentTable() +template <typename T> +void TableManager<T>::resolveCurrentTable() { #ifdef DEBUG_WRITERFILTER if (mpTableLogger != nullptr) @@ -1014,8 +1012,7 @@ void TableManager<T, PropertiesPointer>::resolveCurrentTable() { try { - typename TableData<T, PropertiesPointer>::Pointer_t - pTableData = mTableDataStack.top(); + typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); unsigned int nRows = pTableData->getRowCount(); @@ -1023,7 +1020,7 @@ void TableManager<T, PropertiesPointer>::resolveCurrentTable() for (unsigned int nRow = 0; nRow < nRows; ++nRow) { - typename RowData<T, PropertiesPointer>::Pointer_t pRowData = pTableData->getRow(nRow); + typename RowData<T, TablePropertyMapPtr>::Pointer_t pRowData = pTableData->getRow(nRow); unsigned int nCells = pRowData->getCellCount(); @@ -1031,9 +1028,7 @@ void TableManager<T, PropertiesPointer>::resolveCurrentTable() for (unsigned int nCell = 0; nCell < nCells; ++nCell) { - mpTableDataHandler->startCell - (pRowData->getCellStart(nCell), - pRowData->getCellProperties(nCell)); + mpTableDataHandler->startCell(pRowData->getCellStart(nCell), pRowData->getCellProperties(nCell)); mpTableDataHandler->endCell(pRowData->getCellEnd(nCell)); } @@ -1057,30 +1052,29 @@ void TableManager<T, PropertiesPointer>::resolveCurrentTable() #endif } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::endOfCellAction() +template <typename T> +void TableManager<T>::endOfCellAction() { } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::endOfRowAction() +template <typename T> +void TableManager<T>::endOfRowAction() { } -template <typename T, typename PropertiesPointer> -bool TableManager<T, PropertiesPointer>::isIgnore() const +template <typename T> +bool TableManager<T>::isIgnore() const { return isRowEnd(); } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::clearData() +template <typename T> +void TableManager<T>::clearData() { } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::openCell -(const T & rHandle, PropertiesPointer pProps) +template <typename T> +void TableManager<T>::openCell(const T & rHandle, TablePropertyMapPtr pProps) { #ifdef DEBUG_WRITERFILTER mpTableLogger->startElement("tablemanager.openCell"); @@ -1090,16 +1084,14 @@ void TableManager<T, PropertiesPointer>::openCell if (mTableDataStack.size() > 0) { - typename TableData<T, PropertiesPointer>::Pointer_t - pTableData = mTableDataStack.top(); + typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); pTableData->addCell(rHandle, pProps); } } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::closeCell -(const T & rHandle) +template <typename T> +void TableManager<T>::closeCell(const T & rHandle) { #ifdef DEBUG_WRITERFILTER mpTableLogger->startElement("tablemanager.closeCell"); @@ -1109,15 +1101,14 @@ void TableManager<T, PropertiesPointer>::closeCell if (mTableDataStack.size() > 0) { - typename TableData<T, PropertiesPointer>::Pointer_t - pTableData = mTableDataStack.top(); + typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); pTableData->endCell(rHandle); } } -template <typename T, typename PropertiesPointer> -void TableManager<T, PropertiesPointer>::ensureOpenCell(PropertiesPointer pProps) +template <typename T> +void TableManager<T>::ensureOpenCell(TablePropertyMapPtr pProps) { #ifdef DEBUG_WRITERFILTER mpTableLogger->startElement("tablemanager.ensureOpenCell"); @@ -1125,8 +1116,7 @@ void TableManager<T, PropertiesPointer>::ensureOpenCell(PropertiesPointer pProp if (mTableDataStack.size() > 0) { - typename TableData<T, PropertiesPointer>::Pointer_t - pTableData = mTableDataStack.top(); + typename TableData<T, TablePropertyMapPtr>::Pointer_t pTableData = mTableDataStack.top(); if (pTableData.get() != nullptr) { @@ -1143,6 +1133,8 @@ void TableManager<T, PropertiesPointer>::ensureOpenCell(PropertiesPointer pProp } +} + #endif // INCLUDED_WRITERFILTER_INC_RESOURCEMODEL_TABLEMANAGER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TablePropertiesHandler.hxx b/writerfilter/source/dmapper/TablePropertiesHandler.hxx index 467e9f1..c0b95d4 100644 --- a/writerfilter/source/dmapper/TablePropertiesHandler.hxx +++ b/writerfilter/source/dmapper/TablePropertiesHandler.hxx @@ -35,7 +35,7 @@ namespace dmapper { class DomainMapper; typedef ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > Handle_t; -typedef TableManager<Handle_t , TablePropertyMapPtr > DomainMapperTableManager_Base_t; +typedef TableManager<Handle_t> DomainMapperTableManager_Base_t; class TablePropertiesHandler { commit 64507885bc44aa835728fc37f4d3c5919a47d600 Author: Miklos Vajna <[email protected]> Date: Sat Nov 29 13:23:38 2014 +0100 Unused writerfilter::TagLogger::propertySet Change-Id: If0dd607823cad5dbc2da2df93ed0847a34791b58 diff --git a/unusedcode.easy b/unusedcode.easy index 6c9ec97..cb99ad9 100644 --- a/unusedcode.easy +++ b/unusedcode.easy @@ -192,4 +192,3 @@ sfx2::SvBaseLink::SvBaseLink(rtl::OUString const&, unsigned short, sfx2::SvLinkS std::_Rb_tree<rtl::OUString, std::pair<rtl::OUString const, (anonymous namespace)::TemplateId>, std::_Select1st<std::pair<rtl::OUString const, (anonymous namespace)::TemplateId> >, std::less<rtl::OUString>, std::allocator<std::pair<rtl::OUString const, (anonymous namespace)::TemplateId> > >::_Rb_tree(std::_Rb_tree<rtl::OUString, std::pair<rtl::OUString const, (anonymous namespace)::TemplateId>, std::_Select1st<std::pair<rtl::OUString const, (anonymous namespace)::TemplateId> >, std::less<rtl::OUString>, std::allocator<std::pair<rtl::OUString const, (anonymous namespace)::TemplateId> > >&&) std::__cxx1998::vector<rtl::Reference<oox::xls::(anonymous namespace)::WorkerThread>, std::allocator<rtl::Reference<oox::xls::(anonymous namespace)::WorkerThread> > >::reserve(unsigned long) vcl::MapChar(vcl::_TrueTypeFont*, unsigned short, bool) -writerfilter::TagLogger::propertySet(boost::shared_ptr<writerfilter::Reference<writerfilter::Properties> >, boost::shared_ptr<writerfilter::IdToString>) diff --git a/writerfilter/inc/resourcemodel/TagLogger.hxx b/writerfilter/inc/resourcemodel/TagLogger.hxx index d693e98..b5e5d67 100644 --- a/writerfilter/inc/resourcemodel/TagLogger.hxx +++ b/writerfilter/inc/resourcemodel/TagLogger.hxx @@ -74,9 +74,6 @@ namespace writerfilter void chars(const std::string & chars); void chars(const OUString & chars); void endElement(); - - void propertySet(writerfilter::Reference<Properties>::Pointer_t props, - IdToString::Pointer_t pIdToString); #endif }; } diff --git a/writerfilter/source/resourcemodel/TagLogger.cxx b/writerfilter/source/resourcemodel/TagLogger.cxx index 8338483..7551871 100644 --- a/writerfilter/source/resourcemodel/TagLogger.cxx +++ b/writerfilter/source/resourcemodel/TagLogger.cxx @@ -301,17 +301,6 @@ namespace writerfilter m_pLogger->endElement(); } - - void TagLogger::propertySet(writerfilter::Reference<Properties>::Pointer_t props, - IdToString::Pointer_t pIdToString) - { - startElement( "propertySet" ); - - PropertySetDumpHandler handler( this, pIdToString ); - handler.resolve( props ); - - endElement( ); - } #endif } commit ccfd64827aa557813efdcdfbbb93f3172d3a2493 Author: Miklos Vajna <[email protected]> Date: Sat Nov 29 13:19:19 2014 +0100 writerfilter: only dmapper needs TableManager.hxx Change-Id: I3354f82a3dd0a598b5405ab32c5d1b0d370829c3 diff --git a/writerfilter/CppunitTest_writerfilter_misc.mk b/writerfilter/CppunitTest_writerfilter_misc.mk index 3f4fd80..f563c7a 100644 --- a/writerfilter/CppunitTest_writerfilter_misc.mk +++ b/writerfilter/CppunitTest_writerfilter_misc.mk @@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_set_include,writerfilter_misc,\ $$(INCLUDE) \ -I$(SRCDIR)/writerfilter/inc \ -I$(SRCDIR)/writerfilter/source \ + -I$(SRCDIR)/writerfilter/source/dmapper \ )) $(eval $(call gb_CppunitTest_use_external,writerfilter_misc,boost_headers)) diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx index f1fe804..bd71674 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx @@ -19,7 +19,7 @@ #ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPERTABLEHANDLER_HXX #define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPERTABLEHANDLER_HXX -#include <resourcemodel/TableManager.hxx> +#include <TableManager.hxx> #include <PropertyMap.hxx> #include <comphelper/sequenceasvector.hxx> diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.hxx b/writerfilter/source/dmapper/DomainMapperTableManager.hxx index 65aecc7..599c432 100644 --- a/writerfilter/source/dmapper/DomainMapperTableManager.hxx +++ b/writerfilter/source/dmapper/DomainMapperTableManager.hxx @@ -22,7 +22,7 @@ #include "TablePropertiesHandler.hxx" #include "TablePositionHandler.hxx" -#include <resourcemodel/TableManager.hxx> +#include <TableManager.hxx> #include "PropertyMap.hxx" #include "StyleSheetTable.hxx" #include <com/sun/star/text/XTextRange.hpp> diff --git a/writerfilter/inc/resourcemodel/TableManager.hxx b/writerfilter/source/dmapper/TableManager.hxx similarity index 99% rename from writerfilter/inc/resourcemodel/TableManager.hxx rename to writerfilter/source/dmapper/TableManager.hxx index c13303c..6bac58d3 100644 --- a/writerfilter/inc/resourcemodel/TableManager.hxx +++ b/writerfilter/source/dmapper/TableManager.hxx @@ -17,8 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_WRITERFILTER_INC_RESOURCEMODEL_TABLEMANAGER_HXX -#define INCLUDED_WRITERFILTER_INC_RESOURCEMODEL_TABLEMANAGER_HXX +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TABLEMANAGER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TABLEMANAGER_HXX #include <resourcemodel/TableData.hxx> @@ -28,8 +28,8 @@ #include <boost/shared_ptr.hpp> #include <stack> -#include "util.hxx" -#include "TagLogger.hxx" +#include <resourcemodel/util.hxx> +#include <resourcemodel/TagLogger.hxx> #include <rtl/strbuf.hxx> diff --git a/writerfilter/source/dmapper/TablePropertiesHandler.hxx b/writerfilter/source/dmapper/TablePropertiesHandler.hxx index ed41c64..467e9f1 100644 --- a/writerfilter/source/dmapper/TablePropertiesHandler.hxx +++ b/writerfilter/source/dmapper/TablePropertiesHandler.hxx @@ -22,7 +22,7 @@ #include "PropertyMap.hxx" -#include <resourcemodel/TableManager.hxx> +#include <TableManager.hxx> #include <resourcemodel/WW8ResourceModel.hxx> #include <boost/shared_ptr.hpp> commit db92adda5b4f7bd7ca1c3bbb87802752c6867d71 Author: Miklos Vajna <[email protected]> Date: Sat Nov 29 13:18:35 2014 +0100 writerfilter: turn RTFOverwrite into a C++11 scoped enumeration Change-Id: Ic49033c85f77be8ba415078ae5e3518ef0faae75 diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index ae15b15..8793529 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -60,7 +60,7 @@ static Id lcl_getParagraphBorder(sal_uInt32 nIndex) } static void lcl_putNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId, RTFValue::Pointer_t pValue, - RTFOverwrite eOverwrite = OVERWRITE_YES, bool bAttribute = true) + RTFOverwrite eOverwrite = RTFOverwrite::YES, bool bAttribute = true) { RTFValue::Pointer_t pParent = rSprms.find(nParent, /*bFirst=*/true, /*bForWrite=*/true); if (!pParent.get()) @@ -80,7 +80,7 @@ static void lcl_putNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId, RTFValu rAttributes.set(nId, pValue, eOverwrite); } -static void lcl_putNestedSprm(RTFSprms& rSprms, Id nParent, Id nId, RTFValue::Pointer_t pValue, RTFOverwrite eOverwrite = OVERWRITE_NO_APPEND) +static void lcl_putNestedSprm(RTFSprms& rSprms, Id nParent, Id nId, RTFValue::Pointer_t pValue, RTFOverwrite eOverwrite = RTFOverwrite::NO_APPEND) { lcl_putNestedAttribute(rSprms, nParent, nId, pValue, eOverwrite, false); } @@ -2493,7 +2493,7 @@ void RTFDocumentImpl::restoreTableRowProperties() void RTFDocumentImpl::resetTableRowProperties() { m_aStates.top().aTableRowSprms = m_aDefaultState.aTableRowSprms; - m_aStates.top().aTableRowSprms.set(NS_ooxml::LN_CT_TblGridBase_gridCol, RTFValue::Pointer_t(new RTFValue(-1)), OVERWRITE_NO_APPEND); + m_aStates.top().aTableRowSprms.set(NS_ooxml::LN_CT_TblGridBase_gridCol, RTFValue::Pointer_t(new RTFValue(-1)), RTFOverwrite::NO_APPEND); m_aStates.top().aTableRowAttributes = m_aDefaultState.aTableRowAttributes; if (DESTINATION_NESTEDTABLEPROPERTIES == m_aStates.top().nDestinationState) m_nNestedCurrentCellX = 0; @@ -3748,7 +3748,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) aRunPropsSprms.set(NS_ooxml::LN_EG_RPrBase_rFonts, RTFValue::Pointer_t(new RTFValue(aFontAttributes))); m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_Lvl_rPr, RTFValue::Pointer_t(new RTFValue(RTFSprms(), aRunPropsSprms)), - OVERWRITE_NO_APPEND); + RTFOverwrite::NO_APPEND); } else { @@ -4193,7 +4193,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) rCurrentCellX = nParam; RTFValue::Pointer_t pXValue(new RTFValue(nCellX)); - m_aStates.top().aTableRowSprms.set(NS_ooxml::LN_CT_TblGridBase_gridCol, pXValue, OVERWRITE_NO_APPEND); + m_aStates.top().aTableRowSprms.set(NS_ooxml::LN_CT_TblGridBase_gridCol, pXValue, RTFOverwrite::NO_APPEND); if (DESTINATION_NESTEDTABLEPROPERTIES == m_aStates.top().nDestinationState) { m_nNestedCells++; @@ -4273,53 +4273,47 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) break; case RTF_PAPERH: // fall through: set the default + current value lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_h, pIntValue, OVERWRITE_YES); + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_h, pIntValue, RTFOverwrite::YES); case RTF_PGHSXN: lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_h, pIntValue, OVERWRITE_YES); + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_h, pIntValue, RTFOverwrite::YES); break; case RTF_PAPERW: // fall through: set the default + current value lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_w, pIntValue, OVERWRITE_YES); + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_w, pIntValue, RTFOverwrite::YES); case RTF_PGWSXN: lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_w, pIntValue, OVERWRITE_YES); + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_w, pIntValue, RTFOverwrite::YES); break; case RTF_MARGL: // fall through: set the default + current value lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_left, pIntValue, OVERWRITE_YES); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_left, pIntValue, RTFOverwrite::YES); case RTF_MARGLSXN: lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_left, pIntValue, OVERWRITE_YES); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_left, pIntValue, RTFOverwrite::YES); break; case RTF_MARGR: // fall through: set the default + current value lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_right, pIntValue, OVERWRITE_YES); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_right, pIntValue, RTFOverwrite::YES); case RTF_MARGRSXN: lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_right, pIntValue, OVERWRITE_YES); + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_right, pIntValue, RTFOverwrite::YES); break; case RTF_MARGT: // fall through: set the default + current value - lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_top, pIntValue, OVERWRITE_YES); + lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_top, pIntValue, RTFOverwrite::YES); case RTF_MARGTSXN: - lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_top, pIntValue, OVERWRITE_YES); + lcl_putNestedAttribute(m_aStates.top().aSectionSprms, NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_top, pIntValue, RTFOverwrite::YES); break; case RTF_MARGB: // fall through: set the default + current value - lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_bottom, pIntValue, OVERWRITE_YES); + lcl_putNestedAttribute(m_aDefaultState.aSectionSprms, NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_bottom, pIntValue, RTFOverwrite::YES); case RTF_MARGBSXN: - lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_bottom, pIntValue, OVERWRITE_YES); + lcl_putNestedAttribute(m_aStates.top().aSectionSprms, NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_bottom, pIntValue, RTFOverwrite::YES); break; case RTF_HEADERY: - lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_header, pIntValue, OVERWRITE_YES); + lcl_putNestedAttribute(m_aStates.top().aSectionSprms, NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_header, pIntValue, RTFOverwrite::YES); break; case RTF_FOOTERY: - lcl_putNestedAttribute(m_aStates.top().aSectionSprms, - NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_footer, pIntValue, OVERWRITE_YES); + lcl_putNestedAttribute(m_aStates.top().aSectionSprms, NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_footer, pIntValue, RTFOverwrite::YES); break; case RTF_DEFTAB: m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_defaultTabStop, pIntValue); @@ -4483,12 +4477,10 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) m_aStates.top().aPicture.eWMetafile = nParam; break; case RTF_SB: - lcl_putNestedAttribute(m_aStates.top().aParagraphSprms, - NS_ooxml::LN_CT_PPrBase_spacing, NS_ooxml::LN_CT_Spacing_before, pIntValue, OVERWRITE_YES); + lcl_putNestedAttribute(m_aStates.top().aParagraphSprms, NS_ooxml::LN_CT_PPrBase_spacing, NS_ooxml::LN_CT_Spacing_before, pIntValue, RTFOverwrite::YES); break; case RTF_SA: - lcl_putNestedAttribute(m_aStates.top().aParagraphSprms, - NS_ooxml::LN_CT_PPrBase_spacing, NS_ooxml::LN_CT_Spacing_after, pIntValue, OVERWRITE_YES); + lcl_putNestedAttribute(m_aStates.top().aParagraphSprms, NS_ooxml::LN_CT_PPrBase_spacing, NS_ooxml::LN_CT_Spacing_after, pIntValue, RTFOverwrite::YES); break; case RTF_DPX: m_aStates.top().aDrawingObject.nLeft = convertTwipToMm100(nParam); @@ -4704,7 +4696,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) // It turns out \li should reset the \fi inherited from the stylesheet. // So set the direct formatting to zero, if we don't have such direct formatting yet. lcl_putNestedAttribute(m_aStates.top().aParagraphSprms, NS_ooxml::LN_CT_PPrBase_ind, NS_ooxml::LN_CT_Ind_firstLine, RTFValue::Pointer_t(new RTFValue(0)), - OVERWRITE_NO_IGNORE, /*bAttribute=*/true); + RTFOverwrite::NO_IGNORE, /*bAttribute=*/true); } break; case RTF_RI: @@ -4892,12 +4884,10 @@ int RTFDocumentImpl::dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam } break; case RTF_SBAUTO: - lcl_putNestedAttribute(m_aStates.top().aParagraphSprms, - NS_ooxml::LN_CT_PPrBase_spacing, NS_ooxml::LN_CT_Spacing_beforeAutospacing, pBoolValue, OVERWRITE_YES); + lcl_putNestedAttribute(m_aStates.top().aParagraphSprms, NS_ooxml::LN_CT_PPrBase_spacing, NS_ooxml::LN_CT_Spacing_beforeAutospacing, pBoolValue, RTFOverwrite::YES); break; case RTF_SAAUTO: - lcl_putNestedAttribute(m_aStates.top().aParagraphSprms, - NS_ooxml::LN_CT_PPrBase_spacing, NS_ooxml::LN_CT_Spacing_afterAutospacing, pBoolValue, OVERWRITE_YES); + lcl_putNestedAttribute(m_aStates.top().aParagraphSprms, NS_ooxml::LN_CT_PPrBase_spacing, NS_ooxml::LN_CT_Spacing_afterAutospacing, pBoolValue, RTFOverwrite::YES); break; default: { @@ -5072,7 +5062,7 @@ int RTFDocumentImpl::popState() break; case DESTINATION_LISTENTRY: for (RTFSprms::Iterator_t i = aState.aListLevelEntries.begin(); i != aState.aListLevelEntries.end(); ++i) - aState.aTableSprms.set(i->first, i->second, OVERWRITE_NO_APPEND); + aState.aTableSprms.set(i->first, i->second, RTFOverwrite::NO_APPEND); break; case DESTINATION_FIELDINSTRUCTION: { @@ -5811,7 +5801,7 @@ int RTFDocumentImpl::popState() case DESTINATION_LISTENTRY: { RTFValue::Pointer_t pValue(new RTFValue(aState.aTableAttributes, aState.aTableSprms)); - m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_abstractNum, pValue, OVERWRITE_NO_APPEND); + m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_abstractNum, pValue, RTFOverwrite::NO_APPEND); } break; case DESTINATION_PARAGRAPHNUMBERING: @@ -5855,12 +5845,12 @@ int RTFDocumentImpl::popState() RTFSprms aAbstractSprms; aAbstractAttributes.set(NS_ooxml::LN_CT_AbstractNum_abstractNumId, pIdValue); RTFValue::Pointer_t pLevelValue(new RTFValue(aLevelAttributes, aLevelSprms)); - aAbstractSprms.set(NS_ooxml::LN_CT_AbstractNum_lvl, pLevelValue, OVERWRITE_NO_APPEND); + aAbstractSprms.set(NS_ooxml::LN_CT_AbstractNum_lvl, pLevelValue, RTFOverwrite::NO_APPEND); RTFSprms aListTableSprms; RTFValue::Pointer_t pAbstractValue(new RTFValue(aAbstractAttributes, aAbstractSprms)); // It's important that Numbering_abstractNum and Numbering_num never overwrites previous values. - aListTableSprms.set(NS_ooxml::LN_CT_Numbering_abstractNum, pAbstractValue, OVERWRITE_NO_APPEND); + aListTableSprms.set(NS_ooxml::LN_CT_Numbering_abstractNum, pAbstractValue, RTFOverwrite::NO_APPEND); // Numbering RTFSprms aNumberingAttributes; @@ -5868,7 +5858,7 @@ int RTFDocumentImpl::popState() aNumberingAttributes.set(NS_ooxml::LN_CT_AbstractNum_nsid, pIdValue); aNumberingSprms.set(NS_ooxml::LN_CT_Num_abstractNumId, pIdValue); RTFValue::Pointer_t pNumberingValue(new RTFValue(aNumberingAttributes, aNumberingSprms)); - aListTableSprms.set(NS_ooxml::LN_CT_Numbering_num, pNumberingValue, OVERWRITE_NO_APPEND); + aListTableSprms.set(NS_ooxml::LN_CT_Numbering_num, pNumberingValue, RTFOverwrite::NO_APPEND); // Table RTFSprms aListTableAttributes; @@ -5911,7 +5901,7 @@ int RTFDocumentImpl::popState() RTFValue::Pointer_t pValue(new RTFValue(aState.aTableAttributes, aState.aTableSprms)); if (m_aStates.top().nDestinationState != DESTINATION_LFOLEVEL) - m_aStates.top().aListLevelEntries.set(NS_ooxml::LN_CT_AbstractNum_lvl, pValue, OVERWRITE_NO_APPEND); + m_aStates.top().aListLevelEntries.set(NS_ooxml::LN_CT_AbstractNum_lvl, pValue, RTFOverwrite::NO_APPEND); else m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_NumLvl_lvl, pValue); } @@ -5923,7 +5913,7 @@ int RTFDocumentImpl::popState() aState.aTableAttributes.set(NS_ooxml::LN_CT_NumLvl_ilvl, pInnerValue); RTFValue::Pointer_t pValue(new RTFValue(aState.aTableAttributes, aState.aTableSprms)); - m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_Num_lvlOverride, pValue, OVERWRITE_NO_APPEND); + m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_Num_lvlOverride, pValue, RTFOverwrite::NO_APPEND); } break; // list override table @@ -5938,9 +5928,8 @@ int RTFDocumentImpl::popState() } else { - RTFValue::Pointer_t pValue(new RTFValue( - aState.aTableAttributes, aState.aTableSprms)); - m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_num, pValue, OVERWRITE_NO_APPEND); + RTFValue::Pointer_t pValue(new RTFValue(aState.aTableAttributes, aState.aTableSprms)); + m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_num, pValue, RTFOverwrite::NO_APPEND); } } break; @@ -6003,7 +5992,7 @@ int RTFDocumentImpl::popState() // Dummy value, real picture is already sent to dmapper. aSprms.set(NS_ooxml::LN_CT_NumPicBullet_pict, RTFValue::Pointer_t(new RTFValue(0))); RTFValue::Pointer_t pValue(new RTFValue(aAttributes, aSprms)); - m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_numPicBullet, pValue, OVERWRITE_NO_APPEND); + m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_numPicBullet, pValue, RTFOverwrite::NO_APPEND); } } break; diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx index a123a3a..8c9f0ef 100644 --- a/writerfilter/source/rtftok/rtfsdrimport.cxx +++ b/writerfilter/source/rtftok/rtfsdrimport.cxx @@ -738,7 +738,7 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose, ShapeOrPict const shap RTFSprms aPathAttributes; aPathAttributes.set(NS_ooxml::LN_CT_Point2D_x, RTFValue::Pointer_t(new RTFValue(*oX))); aPathAttributes.set(NS_ooxml::LN_CT_Point2D_y, RTFValue::Pointer_t(new RTFValue(*oY))); - aPolygonSprms.set(NS_ooxml::LN_CT_WrapPath_lineTo, RTFValue::Pointer_t(new RTFValue(aPathAttributes)), OVERWRITE_NO_APPEND); + aPolygonSprms.set(NS_ooxml::LN_CT_WrapPath_lineTo, RTFValue::Pointer_t(new RTFValue(aPathAttributes)), RTFOverwrite::NO_APPEND); } } while (nCharIndex >= 0); diff --git a/writerfilter/source/rtftok/rtfsprm.cxx b/writerfilter/source/rtftok/rtfsprm.cxx index 02e29cf..dbd84d9 100644 --- a/writerfilter/source/rtftok/rtfsprm.cxx +++ b/writerfilter/source/rtftok/rtfsprm.cxx @@ -102,12 +102,12 @@ void RTFSprms::set(Id nKeyword, RTFValue::Pointer_t pValue, RTFOverwrite eOverwr { ensureCopyBeforeWrite(); bool bFound = false; - if (eOverwrite == OVERWRITE_YES || eOverwrite == OVERWRITE_NO_IGNORE) + if (eOverwrite == RTFOverwrite::YES || eOverwrite == RTFOverwrite::NO_IGNORE) { for (RTFSprms::Iterator_t i = m_pSprms->begin(); i != m_pSprms->end(); ++i) if (i->first == nKeyword) { - if (eOverwrite == OVERWRITE_YES) + if (eOverwrite == RTFOverwrite::YES) { i->second = pValue; return; @@ -119,7 +119,7 @@ void RTFSprms::set(Id nKeyword, RTFValue::Pointer_t pValue, RTFOverwrite eOverwr } } } - if (eOverwrite == OVERWRITE_NO_APPEND || !bFound) + if (eOverwrite == RTFOverwrite::NO_APPEND || !bFound) m_pSprms->push_back(std::make_pair(nKeyword, pValue)); } diff --git a/writerfilter/source/rtftok/rtfsprm.hxx b/writerfilter/source/rtftok/rtfsprm.hxx index 818eb87..1be31de 100644 --- a/writerfilter/source/rtftok/rtfsprm.hxx +++ b/writerfilter/source/rtftok/rtfsprm.hxx @@ -45,11 +45,11 @@ inline void intrusive_ptr_release(RTFSprmsImpl* p) delete p; } -enum RTFOverwrite +enum class RTFOverwrite { - OVERWRITE_YES, ///< Yes, if an existing key is found, overwrite it. - OVERWRITE_NO_APPEND, ///< No, always append the value to the end of the list. - OVERWRITE_NO_IGNORE ///< No, if the key is already in the list, then ignore, otherwise append. + YES, ///< Yes, if an existing key is found, overwrite it. + NO_APPEND, ///< No, always append the value to the end of the list. + NO_IGNORE ///< No, if the key is already in the list, then ignore, otherwise append. }; /// A list of RTFSprm with a copy constructor that performs a deep copy. @@ -65,7 +65,7 @@ public: RTFSprms& operator=(const RTFSprms& rOther); RTFValue::Pointer_t find(Id nKeyword, bool bFirst = true, bool bForWrite = false); /// Does the same as ->push_back(), except that it can overwrite or ignore existing entries. - void set(Id nKeyword, RTFValue::Pointer_t pValue, RTFOverwrite eOverwrite = OVERWRITE_YES); + void set(Id nKeyword, RTFValue::Pointer_t pValue, RTFOverwrite eOverwrite = RTFOverwrite::YES); bool erase(Id nKeyword); /// Removes elements which are already in the reference set. /// Also insert default values to override attributes of style commit fa15d039e3a553da8500c17190d27169a9477cf2 Author: Miklos Vajna <[email protected]> Date: Sat Nov 29 11:43:10 2014 +0100 fdo#72031 RTF import: bogus call to getBestTextEncodingFromLocale() There were two problems here. First, commit bbe3627eece0c3486e7ea11f2f13377aaa3a8fed (rtftok: stop sending sprm:CRgFtc{0,1,2} tokens, 2014-03-05) broke the use-case when the font encoding is 0, but it's present. Before that commit, we parsed the font encoding instantly; after that commit we parse it once we have a font name. If we do that, then we have to have an idea if we have a font encoding. Given that 0 is a valid encoding, use -1 for the "have no encoding" case instead. Second, commit 7839633fb356285652ed96f4bf3f85bcd5b561a4 (fdo#85889 handle pc, pca and mac rtf keywords in writerfilter, 2014-11-24) abused m_nCurrentEncoding, which is meant to be used within the font table only. The problem with this is that this way only the first font will get the encoding, while the spec says it should be used in every context where there is no other explicit encoding. Fix this by setting the default encoding for those 3 control words instead -- and consider the default encoding in getEncoding(). Change-Id: Ia1d71f8ce70f2a53a3770b4840e21362d082e71f diff --git a/sw/qa/extras/rtfimport/data/fdo72031.rtf b/sw/qa/extras/rtfimport/data/fdo72031.rtf new file mode 100644 index 0000000..ee589da --- /dev/null +++ b/sw/qa/extras/rtfimport/data/fdo72031.rtf @@ -0,0 +1 @@ +{\rtf1\ansi\ansicpg1250\deff0\deflang1038{\fonttbl{\f0\fnil\fcharset2 Symbol;}{\f1\fnil\fcharset238 MS Shell Dlg 2;}}\viewkind4\uc1\pard\f0\fs23\'c5\f1\fs17\par} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 7dc67c3..0e916d3 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -66,7 +66,7 @@ public: virtual void preTest(const char* filename) SAL_OVERRIDE { m_aSavedSettings = Application::GetSettings(); - if (OString(filename) == "fdo48023.rtf") + if (OString(filename) == "fdo48023.rtf" || OString(filename) == "fdo72031.rtf") { AllSettings aSettings(m_aSavedSettings); aSettings.SetLanguageTag(LanguageTag("ru")); @@ -82,7 +82,7 @@ public: virtual void postTest(const char* filename) SAL_OVERRIDE { - if (OString(filename) == "fdo48023.rtf" || OString(filename) == "fdo44211.rtf") + if (OString(filename) == "fdo48023.rtf" || OString(filename) == "fdo72031.rtf" || OString(filename) == "fdo44211.rtf") Application::SetSettings(m_aSavedSettings); } @@ -2206,6 +2206,11 @@ DECLARE_RTFIMPORT_TEST(testFdo85889mac, "fdo85889-mac.rtf") CPPUNIT_ASSERT_EQUAL(aExpected, xTextRange->getString()); } +DECLARE_RTFIMPORT_TEST(testFdo72031, "fdo72031.rtf") +{ + OUString aExpected("\xc3\x85", 2, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL(aExpected, getRun(getParagraph(1), 1)->getString()); +} CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 0e5150b..ae15b15 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -255,7 +255,7 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x m_bObject(false), m_aFontTableEntries(), m_nCurrentFontIndex(0), - m_nCurrentEncoding(0), + m_nCurrentEncoding(-1), m_nDefaultFontIndex(-1), m_aStyleTableEntries(), m_nCurrentStyleIndex(0), @@ -641,8 +641,14 @@ rtl_TextEncoding RTFDocumentImpl::getEncoding(int nFontIndex) { std::map<int, rtl_TextEncoding>::iterator it = m_aFontEncodings.find(nFontIndex); if (it != m_aFontEncodings.end()) + // We have a font encoding associated to this font. return it->second; - return msfilter::util::getBestTextEncodingFromLocale(Application::GetSettings().GetLanguageTag().getLocale()); + else if (m_aDefaultState.nCurrentEncoding != rtl_getTextEncodingFromWindowsCharset(0)) + // We have a default encoding. + return m_aDefaultState.nCurrentEncoding; + else + // Guess based on locale. + return msfilter::util::getBestTextEncodingFromLocale(Application::GetSettings().GetLanguageTag().getLocale()); } else return m_pSuperstream->getEncoding(nFontIndex); @@ -1163,10 +1169,10 @@ void RTFDocumentImpl::text(OUString& rString) case DESTINATION_FONTENTRY: { m_aFontNames[m_nCurrentFontIndex] = aName; - if (m_nCurrentEncoding > 0) + if (m_nCurrentEncoding >= 0) { m_aFontEncodings[m_nCurrentFontIndex] = m_nCurrentEncoding; - m_nCurrentEncoding = 0; + m_nCurrentEncoding = -1; } m_aStates.top().aTableAttributes.set(NS_ooxml::LN_CT_Font_name, RTFValue::Pointer_t(new RTFValue(aName))); @@ -2907,16 +2913,16 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) m_aStates.top().nCurrentEncoding = RTL_TEXTENCODING_MS_1252; break; case RTF_MAC: - m_nCurrentEncoding = RTL_TEXTENCODING_APPLE_ROMAN; - m_aStates.top().nCurrentEncoding = m_nCurrentEncoding; + m_aDefaultState.nCurrentEncoding = RTL_TEXTENCODING_APPLE_ROMAN; + m_aStates.top().nCurrentEncoding = m_aDefaultState.nCurrentEncoding; break; case RTF_PC: - m_nCurrentEncoding = RTL_TEXTENCODING_IBM_437; - m_aStates.top().nCurrentEncoding = m_nCurrentEncoding; + m_aDefaultState.nCurrentEncoding = RTL_TEXTENCODING_IBM_437; + m_aStates.top().nCurrentEncoding = m_aDefaultState.nCurrentEncoding; break; case RTF_PCA: - m_nCurrentEncoding = RTL_TEXTENCODING_IBM_850; - m_aStates.top().nCurrentEncoding = m_nCurrentEncoding; + m_aDefaultState.nCurrentEncoding = RTL_TEXTENCODING_IBM_850; + m_aStates.top().nCurrentEncoding = m_aDefaultState.nCurrentEncoding; break; case RTF_PLAIN: { _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
