[Libreoffice-commits] core.git: sw/inc sw/qa sw/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed Aug 8 13:53:18 UTC 2018
sw/inc/tblafmt.hxx | 6 ++++
sw/qa/extras/htmlimport/data/reqif-table.xhtml | 33 +++++++++++++++++++++++++
sw/qa/extras/htmlimport/htmlimport.cxx | 15 +++++++++++
sw/source/core/doc/tblafmt.cxx | 10 +++++++
sw/source/core/docnode/ndtbl.cxx | 5 ---
sw/source/filter/html/htmltab.cxx | 31 +++++++++++++++++++++++
sw/source/filter/html/swhtml.cxx | 5 +++
sw/source/filter/html/swhtml.hxx | 5 +++
8 files changed, 105 insertions(+), 5 deletions(-)
New commits:
commit 63c91b9cb3f73b66a915875721b0efd65b8aebac
Author: Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Wed Aug 8 14:15:23 2018 +0200
Commit: Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Wed Aug 8 15:52:54 2018 +0200
sw HTML import: apply default table autoformat on cells in reqif mode
The reqif xhtml subset doesn't allow formatting of cells, which means
that the tables created with the UI and imported tables look different,
e.g. the later ones have no borders.
Fix this inconsistency by applying the default table autoformat during
import (in reqif mode). The import result looks better this way, and the
export will ignore it anyway.
Change-Id: I310770594e7a00e62f23d9df8cb16c2b95e1e44a
Reviewed-on: https://gerrit.libreoffice.org/58741
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Jenkins
diff --git a/sw/inc/tblafmt.hxx b/sw/inc/tblafmt.hxx
index c12db612b11f..f1bc805fee84 100644
--- a/sw/inc/tblafmt.hxx
+++ b/sw/inc/tblafmt.hxx
@@ -333,6 +333,12 @@ public:
OUString GetTableTemplateCellSubName(const SwBoxAutoFormat& rBoxFormat) const;
/// Returns a vector of indexes in aBoxAutoFormat array. Returned indexes points to cells which are mapped to a table-template.
static const std::vector<sal_Int32>& GetTableTemplateMap();
+
+ /**
+ * Calculates the relevant position in the table autoformat for a given
+ * cell in a given table.
+ */
+ static sal_uInt8 CountPos(sal_uInt32 nCol, sal_uInt32 nCols, sal_uInt32 nRow, sal_uInt32 nRows);
};
class SW_DLLPUBLIC SwTableAutoFormatTable
diff --git a/sw/qa/extras/htmlimport/data/reqif-table.xhtml b/sw/qa/extras/htmlimport/data/reqif-table.xhtml
new file mode 100644
index 000000000000..242201de817d
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/reqif-table.xhtml
@@ -0,0 +1,33 @@
+<reqif-xhtml:div><reqif-xhtml:p>Before.</reqif-xhtml:p>
+<reqif-xhtml:table width="100%" cellpadding="4" cellspacing="0">
+ <reqif-xhtml:col width="128*"/>
+
+ <reqif-xhtml:col width="128*"/>
+
+ <reqif-xhtml:tr valign="top">
+ <reqif-xhtml:td><reqif-xhtml:p align="left" style="text-decoration: none">
+ <reqif-xhtml:br/>
+
+ </reqif-xhtml:p>
+ </reqif-xhtml:td>
+ <reqif-xhtml:td><reqif-xhtml:p align="left" style="text-decoration: none">
+ <reqif-xhtml:br/>
+
+ </reqif-xhtml:p>
+ </reqif-xhtml:td>
+ </reqif-xhtml:tr>
+ <reqif-xhtml:tr valign="top">
+ <reqif-xhtml:td><reqif-xhtml:p align="left" style="text-decoration: none">
+ <reqif-xhtml:br/>
+
+ </reqif-xhtml:p>
+ </reqif-xhtml:td>
+ <reqif-xhtml:td><reqif-xhtml:p align="left" style="text-decoration: none">
+ <reqif-xhtml:br/>
+
+ </reqif-xhtml:p>
+ </reqif-xhtml:td>
+ </reqif-xhtml:tr>
+</reqif-xhtml:table>
+<reqif-xhtml:p>After.</reqif-xhtml:p>
+</reqif-xhtml:div>
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index fecd3c53b5b6..ad404d7e4f3a 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -321,6 +321,21 @@ DECLARE_HTMLIMPORT_TEST(testReqIfBr, "reqif-br.xhtml")
CPPUNIT_ASSERT(getParagraph(1)->getString().startsWith("aaa\nbbb"));
}
+DECLARE_HTMLIMPORT_TEST(testReqIfTable, "reqif-table.xhtml")
+{
+ // Load a table with xhtmlns=reqif-xhtml filter param.
+ uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
+ uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xTables->getCount());
+ uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
+ uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
+ auto aBorder = getProperty<table::BorderLine2>(xCell, "TopBorder");
+ // This was 0, tables had no borders, even if the default autoformat has
+ // borders and the markup allows no custom borders.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(18), aBorder.LineWidth);
+}
+
DECLARE_HTMLIMPORT_TEST(testImageSize, "image-size.html")
{
awt::Size aSize = getShape(1)->getSize();
diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index 5d30ed5e1809..4cca119a6729 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -1138,6 +1138,16 @@ const std::vector<sal_Int32>& SwTableAutoFormat::GetTableTemplateMap()
return *pTableTemplateMap;
}
+sal_uInt8 SwTableAutoFormat::CountPos(sal_uInt32 nCol, sal_uInt32 nCols, sal_uInt32 nRow,
+ sal_uInt32 nRows)
+{
+ sal_uInt8 nRet = static_cast<sal_uInt8>(
+ !nRow ? 0 : ((nRow + 1 == nRows) ? 12 : (4 * (1 + ((nRow - 1) & 1)))));
+ nRet = nRet
+ + static_cast<sal_uInt8>(!nCol ? 0 : (nCol + 1 == nCols ? 3 : (1 + ((nCol - 1) & 1))));
+ return nRet;
+}
+
struct SwTableAutoFormatTable::Impl
{
std::vector<std::unique_ptr<SwTableAutoFormat>> m_AutoFormats;
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 15a04fd1c8d6..7d05eb88177b 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -492,10 +492,7 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTableOpts,
SwTableBoxFormat *pBoxF;
if( pTAFormat )
{
- sal_uInt8 nId = static_cast<sal_uInt8>(!n ? 0 : (( n+1 == nRows )
- ? 12 : (4 * (1 + ((n-1) & 1 )))));
- nId = nId + static_cast<sal_uInt8>( !i ? 0 :
- ( i+1 == nCols ? 3 : (1 + ((i-1) & 1))));
+ sal_uInt8 nId = SwTableAutoFormat::CountPos(i, nCols, n, nRows);
pBoxF = ::lcl_CreateAFormatBoxFormat( *this, aBoxFormatArr, *pTAFormat,
nCols, nId );
diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx
index 69df8477af5a..916db2f2aad0 100644
--- a/sw/source/filter/html/htmltab.cxx
+++ b/sw/source/filter/html/htmltab.cxx
@@ -64,6 +64,8 @@
#include <numrule.hxx>
#include <txtftn.hxx>
#include <itabenum.hxx>
+#include <tblafmt.hxx>
+#include <SwStyleNameMapper.hxx>
#define NETSCAPE_DFLT_BORDER 1
#define NETSCAPE_DFLT_CELLSPACING 2
@@ -1054,6 +1056,16 @@ void SwHTMLParser::DeregisterHTMLTable(HTMLTable* pOld)
m_aTables.erase(std::remove(m_aTables.begin(), m_aTables.end(), pOld));
}
+SwDoc* SwHTMLParser::GetDoc() const
+{
+ return m_xDoc.get();
+}
+
+bool SwHTMLParser::IsReqIF() const
+{
+ return m_bReqIF;
+}
+
HTMLTable::~HTMLTable()
{
m_pParser->DeregisterHTMLTable(this);
@@ -1455,6 +1467,25 @@ void HTMLTable::FixFrameFormat( SwTableBox *pBox,
pFrameFormat->ResetFormatAttr( RES_VERT_ORIENT );
pFrameFormat->ResetFormatAttr( RES_BOXATR_FORMAT );
}
+
+ if (m_pParser->IsReqIF())
+ {
+ // ReqIF case, cells would have no formatting. Apply the default
+ // table autoformat on them, so imported and UI-created tables look
+ // the same.
+ SwTableAutoFormatTable& rTable = m_pParser->GetDoc()->GetTableStyles();
+ SwTableAutoFormat* pTableFormat = rTable.FindAutoFormat(
+ SwStyleNameMapper::GetUIName(RES_POOLTABSTYLE_DEFAULT, OUString()));
+ if (pTableFormat)
+ {
+ sal_uInt8 nPos = SwTableAutoFormat::CountPos(nCol, m_nCols, nRow, m_nRows);
+ pTableFormat->UpdateToSet(nPos,
+ const_cast<SfxItemSet&>(static_cast<SfxItemSet const&>(
+ pFrameFormat->GetAttrSet())),
+ SwTableAutoFormat::UPDATE_BOX,
+ pFrameFormat->GetDoc()->GetNumberFormatter());
+ }
+ }
}
else
{
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index 991251d62adb..c3130d840b52 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -5576,8 +5576,11 @@ void SwHTMLParser::SetupFilterOptions()
const OUString aXhtmlNsKey("xhtmlns=");
if (aFilterOptions.startsWith(aXhtmlNsKey))
{
- SetNamespace(aFilterOptions.copy(aXhtmlNsKey.getLength()));
+ OUString aNamespace = aFilterOptions.copy(aXhtmlNsKey.getLength());
+ SetNamespace(aNamespace);
m_bXHTML = true;
+ if (aNamespace == "reqif-xhtml")
+ m_bReqIF = true;
}
}
diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx
index b3560065c326..e1244ba24839 100644
--- a/sw/source/filter/html/swhtml.hxx
+++ b/sw/source/filter/html/swhtml.hxx
@@ -463,6 +463,7 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient
SfxViewFrame* m_pTempViewFrame;
bool m_bXHTML = false;
+ bool m_bReqIF = false;
/**
* Non-owning pointers to already inserted OLE nodes, matching opened
@@ -921,6 +922,10 @@ public:
void DeregisterHTMLTable(HTMLTable* pOld);
+ SwDoc* GetDoc() const;
+
+ bool IsReqIF() const;
+
/// Strips query and fragment from a URL path if base URL is a file:// one.
static OUString StripQueryFromPath(const OUString& rBase, const OUString& rPath);
};
More information about the Libreoffice-commits
mailing list