1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/* -*- 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 <swmodeltestbase.hxx>
#include <vcl/gdimtf.hxx>
#include <comphelper/classids.hxx>
#include <tools/globname.hxx>
#include <svtools/embedhlp.hxx>
#include <wrtsh.hxx>
#include <fmtanchr.hxx>
static char const DATA_DIRECTORY[] = "/sw/qa/core/layout/data/";
/// Covers sw/source/core/layout/ fixes.
class SwCoreLayoutTest : public SwModelTestBase
{
};
CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testTableFlyOverlap)
{
// Load a document that has an image anchored in the header.
// It also has a table which has the wrap around the image.
load(DATA_DIRECTORY, "table-fly-overlap.docx");
SwTwips nFlyTop = parseDump("//header/txt/anchored/fly/infos/bounds", "top").toInt32();
SwTwips nFlyHeight = parseDump("//header/txt/anchored/fly/infos/bounds", "height").toInt32();
SwTwips nFlyBottom = nFlyTop + nFlyHeight;
SwTwips nTableFrameTop = parseDump("//tab/infos/bounds", "top").toInt32();
SwTwips nTablePrintTop = parseDump("//tab/infos/prtBounds", "top").toInt32();
SwTwips nTableTop = nTableFrameTop + nTablePrintTop;
// Without the accompanying fix in place, this test would have failed with:
// - Expected greater or equal than: 3579
// - Actual : 2210
// i.e. the table's top border overlapped with the image, even if the image's wrap mode was set
// to parallel.
CPPUNIT_ASSERT_GREATEREQUAL(nFlyBottom, nTableTop);
}
CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testTdf128195)
{
// Load a document that has two paragraphs in the header.
// The second paragraph should have its bottom spacing applied.
load(DATA_DIRECTORY, "tdf128195.docx");
sal_Int32 nTxtHeight = parseDump("//header/txt[2]/infos/bounds", "height").toInt32();
sal_Int32 nTxtBottom = parseDump("//header/txt[2]/infos/bounds", "bottom").toInt32();
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2269), nTxtHeight);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3529), nTxtBottom);
}
CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testBorderCollapseCompat)
{
// Load a document with a border conflict: top cell has a dotted bottom border, bottom cell has
// a solid upper border.
load(DATA_DIRECTORY, "border-collapse-compat.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
SwDocShell* pShell = pTextDoc->GetDocShell();
std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
MetafileXmlDump aDumper;
xmlDocPtr pXmlDoc = dumpAndParse(aDumper, *xMetaFile);
// Make sure the solid border has priority.
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 1
// - Actual : 48
// i.e. there was no single cell border with width=20, rather there were 48 border parts
// (forming a dotted border), all with width=40.
assertXPath(pXmlDoc, "//polyline[@style='solid']", "width", "20");
}
CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testGutterMargin)
{
// Create a document, remember the old left edge of the page print area (the rectangle that is
// inside margins).
loadURL("private:factory/swriter", nullptr);
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
uno::Reference<beans::XPropertySet> xStandard(getStyles("PageStyles")->getByName("Standard"),
uno::UNO_QUERY);
SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
SwFrame* pPage = pLayout->GetLower();
long nOldLeft = pPage->getFramePrintArea().Left();
// Set the gutter margin to 2cm.
sal_Int32 nGutterMm100 = 2000;
xStandard->setPropertyValue("GutterMargin", uno::makeAny(nGutterMm100));
// Verify that the new left edge is larger.
long nNewLeft = pPage->getFramePrintArea().Left();
long nGutterTwips = convertMm100ToTwip(nGutterMm100);
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 1134
// - Actual : 0
// i.e. the gutter was not added to the left margin.
CPPUNIT_ASSERT_EQUAL(nGutterTwips, nNewLeft - nOldLeft);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|