| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <test/unoapixml_test.hxx> |
| 11 |
|
| 12 |
#include <com/sun/star/awt/Point.hpp> |
| 13 |
#include <com/sun/star/awt/Size.hpp> |
| 14 |
#include <com/sun/star/beans/XPropertySet.hpp> |
| 15 |
#include <com/sun/star/drawing/XDrawPageSupplier.hpp> |
| 16 |
#include <com/sun/star/container/XNamed.hpp> |
| 17 |
#include <com/sun/star/text/RelOrientation.hpp> |
| 18 |
#include <com/sun/star/text/VertOrientation.hpp> |
| 19 |
#include <com/sun/star/text/XTextViewCursorSupplier.hpp> |
| 20 |
#include <com/sun/star/view/XViewCursor.hpp> |
| 21 |
#include <com/sun/star/drawing/PointSequenceSequence.hpp> |
| 22 |
#include <com/sun/star/qa/XDumper.hpp> |
| 23 |
|
| 24 |
#include <basegfx/polygon/b2dpolypolygontools.hxx> |
| 25 |
#include <officecfg/Office/Common.hxx> |
| 26 |
|
| 27 |
using namespace ::com::sun::star; |
| 28 |
|
| 29 |
namespace |
| 30 |
{ |
| 31 |
/// Tests for sw/source/writerfilter/dmapper/GraphicImport.cxx. |
| 32 |
class Test : public UnoApiXmlTest |
| 33 |
{ |
| 34 |
public: |
| 35 |
Test() |
| 36 |
: UnoApiXmlTest(u"/sw/qa/writerfilter/dmapper/data/"_ustr) |
| 37 |
{ |
| 38 |
} |
| 39 |
}; |
| 40 |
|
| 41 |
CPPUNIT_TEST_FIXTURE(Test, testTdf143455SmartArtPosition) |
| 42 |
{ |
| 43 |
loadFromFile(u"tdf143455_SmartArtPosition.docx"); |
| 44 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 45 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 46 |
uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 47 |
// Without fix in place the group, which represents the SmartArt, was placed at the initializing |
| 48 |
// position 0|0. |
| 49 |
sal_Int32 nHoriPosition = 0; |
| 50 |
xShape->getPropertyValue(u"HoriOrientPosition"_ustr) >>= nHoriPosition; |
| 51 |
// The test would have failed with Expected: 2858, Actual: 0 |
| 52 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2858), nHoriPosition); |
| 53 |
sal_Int32 nVertPosition = 0; |
| 54 |
xShape->getPropertyValue(u"VertOrientPosition"_ustr) >>= nVertPosition; |
| 55 |
// The test would have failed with Expected: 1588, Actual: 0 |
| 56 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1588), nVertPosition); |
| 57 |
} |
| 58 |
|
| 59 |
CPPUNIT_TEST_FIXTURE(Test, testTdf143208wrapTight) |
| 60 |
{ |
| 61 |
loadFromFile(u"tdf143208_wrapTight.docx"); |
| 62 |
// The document has a shape with indentation and contour wrap "wrapTight". Error was, that |
| 63 |
// the corresponding shape property 'ContourOutside=true' was not set. |
| 64 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 65 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 66 |
uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 67 |
bool bContourOutside = false; |
| 68 |
xShape->getPropertyValue(u"ContourOutside"_ustr) >>= bContourOutside; |
| 69 |
CPPUNIT_ASSERT(bContourOutside); |
| 70 |
} |
| 71 |
|
| 72 |
CPPUNIT_TEST_FIXTURE(Test, testTdf142305StrokeGlowMargin) |
| 73 |
{ |
| 74 |
loadFromFile(u"tdf142305StrokeGlowMargin.docx"); |
| 75 |
// The document has an arc with fat stroke and glow. Its bounding rectangle differs much |
| 76 |
// from the snap rectangle. Error was, that the margins were not set in a way, that the shape |
| 77 |
// would render similar to Word. |
| 78 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 79 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 80 |
uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 81 |
sal_Int32 nTopMargin = 0; |
| 82 |
xShape->getPropertyValue(u"TopMargin"_ustr) >>= nTopMargin; |
| 83 |
// Without fix in place top margin was 0, so that the text comes near to the shape. |
| 84 |
// The test would have failed with Expected: 838, Actual: 0 |
| 85 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(838), nTopMargin); |
| 86 |
sal_Int32 nBottomMargin = 0; |
| 87 |
// Without fix in place bottom margin was >0, so that the text was far from to the shape. |
| 88 |
// The test would have failed with Expected: 0, Actual: 637 |
| 89 |
xShape->getPropertyValue(u"BottomMargin"_ustr) >>= nBottomMargin; |
| 90 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nBottomMargin); |
| 91 |
} |
| 92 |
|
| 93 |
CPPUNIT_TEST_FIXTURE(Test, testTdf142305SquareWrapMargin) |
| 94 |
{ |
| 95 |
loadFromFile(u"tdf142305SquareWrapMargin.docx"); |
| 96 |
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); |
| 97 |
uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier( |
| 98 |
xModel->getCurrentController(), uno::UNO_QUERY_THROW); |
| 99 |
uno::Reference<text::XTextViewCursor> xViewCursor(xTextViewCursorSupplier->getViewCursor()); |
| 100 |
xViewCursor->gotoStart(/*bExpand=*/false); |
| 101 |
uno::Reference<view::XViewCursor> xCursor(xViewCursor, uno::UNO_QUERY); |
| 102 |
xCursor->goDown(/*nCount=*/10, /*bExpand=*/false); |
| 103 |
xViewCursor->goRight(/*nCount=*/1, /*bExpand=*/true); |
| 104 |
OUString sText = xViewCursor->getString(); |
| 105 |
// Without fix in place, wrap was tight to the bounding box and not around the full shape as in |
| 106 |
// Word. That results in different text at start of line, here "u" instead of expected "m". |
| 107 |
CPPUNIT_ASSERT(sText.startsWith("m")); |
| 108 |
} |
| 109 |
|
| 110 |
CPPUNIT_TEST_FIXTURE(Test, testTdf142304GroupPosition) |
| 111 |
{ |
| 112 |
loadFromFile(u"tdf142304GroupPosition.docx"); |
| 113 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 114 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 115 |
uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 116 |
sal_Int32 nVertPosition = 0; |
| 117 |
xShape->getPropertyValue(u"VertOrientPosition"_ustr) >>= nVertPosition; |
| 118 |
// Without fix in place the group was shifted left and down |
| 119 |
// The test would have failed with Expected: 2178, Actual: 2521 |
| 120 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2178), nVertPosition); |
| 121 |
sal_Int32 nHoriPosition = 0; |
| 122 |
// The test would have failed with Expected: 4304, Actual: 3874 |
| 123 |
xShape->getPropertyValue(u"HoriOrientPosition"_ustr) >>= nHoriPosition; |
| 124 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4304), nHoriPosition); |
| 125 |
} |
| 126 |
|
| 127 |
CPPUNIT_TEST_FIXTURE(Test, testTdf141540ChildRotation) |
| 128 |
{ |
| 129 |
loadFromFile(u"tdf141540ChildRotation.docx"); |
| 130 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 131 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 132 |
uno::Reference<container::XIndexAccess> xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY_THROW); |
| 133 |
uno::Reference<beans::XPropertySet> xRotatedShape(xGroup->getByIndex(1), uno::UNO_QUERY); |
| 134 |
sal_Int32 nShearAngle = 9000; // initialize with invalid value |
| 135 |
xRotatedShape->getPropertyValue(u"ShearAngle"_ustr) >>= nShearAngle; |
| 136 |
// Without fix in place, this test would have failed with: |
| 137 |
// - Expected: 0 |
| 138 |
// - Actual : 2494 |
| 139 |
// i.e. the rotated rectangle in the group was sheared, although the group itself is not rotated |
| 140 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nShearAngle); |
| 141 |
} |
| 142 |
|
| 143 |
CPPUNIT_TEST_FIXTURE(Test, testTdf141540GroupRotation) |
| 144 |
{ |
| 145 |
loadFromFile(u"tdf141540GroupRotation.docx"); |
| 146 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 147 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 148 |
uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 149 |
sal_Int32 nShearAngle = 9000; // init with invalid value |
| 150 |
xShape->getPropertyValue(u"ShearAngle"_ustr) >>= nShearAngle; |
| 151 |
// Without fix in place, this test would have failed with: |
| 152 |
// - Expected: 0 |
| 153 |
// - Actual : -3190 |
| 154 |
// i.e. the group has got a shearing although MSO does not know shearing at all. |
| 155 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nShearAngle); |
| 156 |
} |
| 157 |
|
| 158 |
CPPUNIT_TEST_FIXTURE(Test, testTdf141540GroupLinePosSize) |
| 159 |
{ |
| 160 |
loadFromFile(u"tdf141540GroupLinePosSize.docx"); |
| 161 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 162 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 163 |
|
| 164 |
// Test line |
| 165 |
uno::Reference<drawing::XShape> xLineShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 166 |
awt::Point aPosition = xLineShape->getPosition(); |
| 167 |
awt::Size aSize = xLineShape->getSize(); |
| 168 |
// Without fix in place, you had got Position = (19|6498), Size = 5001 x 2 |
| 169 |
// i.e. the line was nearly horizontal instead of vertical |
| 170 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5022), aPosition.X); |
| 171 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2965), aPosition.Y); |
| 172 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aSize.Width); |
| 173 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(7071), aSize.Height); |
| 174 |
|
| 175 |
// Test group |
| 176 |
uno::Reference<drawing::XShape> xGroupShape(xDrawPage->getByIndex(1), uno::UNO_QUERY); |
| 177 |
aPosition = xGroupShape->getPosition(); |
| 178 |
aSize = xGroupShape->getSize(); |
| 179 |
// Without fix in place, you had got Position = (11511|3480), Size = 4022 x 4022 |
| 180 |
// i.e. the group was erroneously downscaled to unrotated size |
| 181 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(10679), aPosition.X); |
| 182 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2648), aPosition.Y); |
| 183 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5687), aSize.Width); |
| 184 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5687), aSize.Height); |
| 185 |
} |
| 186 |
|
| 187 |
CPPUNIT_TEST_FIXTURE(Test, testGroupShapeRotation) |
| 188 |
{ |
| 189 |
loadFromFile(u"group-shape-rotation.docx"); |
| 190 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 191 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 192 |
uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 193 |
sal_Int32 nVertPosition = 0; |
| 194 |
xShape->getPropertyValue(u"VertOrientPosition"_ustr) >>= nVertPosition; |
| 195 |
// Without the accompanying fix in place, this test would have failed with: |
| 196 |
// - Expected: 1221 |
| 197 |
// - Actual : -2048 |
| 198 |
// i.e. the group shape had a so low vertical position that the line shape did not point into |
| 199 |
// it. |
| 200 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1221), nVertPosition); |
| 201 |
} |
| 202 |
|
| 203 |
CPPUNIT_TEST_FIXTURE(Test, testDrawShapeInlineEffect) |
| 204 |
{ |
| 205 |
loadFromFile(u"draw-shape-inline-effect.docx"); |
| 206 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 207 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 208 |
uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 209 |
sal_Int32 nBottomMargin = 0; |
| 210 |
xShape->getPropertyValue(u"BottomMargin"_ustr) >>= nBottomMargin; |
| 211 |
// 273 in mm100 is 98425 EMUs from the file. |
| 212 |
// Without the accompanying fix in place, this test would have failed with: |
| 213 |
// - Expected: 273 |
| 214 |
// - Actual : 0 |
| 215 |
// i.e. the layout result had less pages than expected (compared to Word). |
| 216 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(273), nBottomMargin); |
| 217 |
} |
| 218 |
|
| 219 |
CPPUNIT_TEST_FIXTURE(Test, testInlineAnchoredZOrder) |
| 220 |
{ |
| 221 |
// Load a document which has two shapes: an inline one and an anchored one. The inline has no |
| 222 |
// explicit ZOrder, the anchored one has, and it's set to a value so it's visible. |
| 223 |
loadFromFile(u"inline-anchored-zorder.docx"); |
| 224 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 225 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 226 |
uno::Reference<container::XNamed> xOval(xDrawPage->getByIndex(1), uno::UNO_QUERY); |
| 227 |
// Without the accompanying fix in place, this test would have failed with: |
| 228 |
// - Expected: Oval 2 |
| 229 |
// - Actual : |
| 230 |
// i.e. the rectangle (with no name) was on top of the oval one, not the other way around. |
| 231 |
CPPUNIT_ASSERT_EQUAL(u"Oval 2"_ustr, xOval->getName()); |
| 232 |
} |
| 233 |
|
| 234 |
CPPUNIT_TEST_FIXTURE(Test, testInlineInShapeAnchoredZOrder) |
| 235 |
{ |
| 236 |
// This document has a textbox shape and then an inline shape inside that. |
| 237 |
// The ZOrder of the inline shape is larger than the hosting textbox, so the image is visible. |
| 238 |
loadFromFile(u"inline-inshape-anchored-zorder.docx"); |
| 239 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 240 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 241 |
uno::Reference<container::XNamed> xOval(xDrawPage->getByIndex(1), uno::UNO_QUERY); |
| 242 |
// Without the accompanying fix in place, this test would have failed with: |
| 243 |
// - Expected: Picture 1 |
| 244 |
// - Actual : Text Box 2 |
| 245 |
// i.e. the image was behind the textbox that was hosting it. |
| 246 |
CPPUNIT_ASSERT_EQUAL(u"Picture 1"_ustr, xOval->getName()); |
| 247 |
} |
| 248 |
|
| 249 |
CPPUNIT_TEST_FIXTURE(Test, testRelfromhInsidemargin) |
| 250 |
{ |
| 251 |
loadFromFile(u"relfromh-insidemargin.docx"); |
| 252 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 253 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 254 |
uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 255 |
sal_Int16 nRelation = 0; |
| 256 |
xShape->getPropertyValue(u"HoriOrientRelation"_ustr) >>= nRelation; |
| 257 |
// Without the accompanying fix in place, this test would have failed with: |
| 258 |
// - Expected: 7 (PAGE_FRAME) |
| 259 |
// - Actual : 0 (FRAME) |
| 260 |
// i.e. the horizontal position was relative to the paragraph area, not to the entire page. |
| 261 |
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, nRelation); |
| 262 |
bool bPageToggle = false; |
| 263 |
xShape->getPropertyValue(u"PageToggle"_ustr) >>= bPageToggle; |
| 264 |
CPPUNIT_ASSERT(bPageToggle); |
| 265 |
} |
| 266 |
|
| 267 |
CPPUNIT_TEST_FIXTURE(Test, testWrapPolyCrop) |
| 268 |
{ |
| 269 |
loadFromFile(u"wrap-poly-crop.docx"); |
| 270 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 271 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 272 |
uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 273 |
drawing::PointSequenceSequence aContour; |
| 274 |
xShape->getPropertyValue(u"ContourPolyPolygon"_ustr) >>= aContour; |
| 275 |
auto aPolyPolygon = basegfx::utils::UnoPointSequenceSequenceToB2DPolyPolygon(aContour); |
| 276 |
CPPUNIT_ASSERT_EQUAL(sal_uInt32(1), aPolyPolygon.count()); |
| 277 |
auto aPolygon = aPolyPolygon.getB2DPolygon(0); |
| 278 |
CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), aPolygon.count()); |
| 279 |
|
| 280 |
// Ideally this would be 2352, because the graphic size in mm100, using the graphic's DPI is |
| 281 |
// 10582, the lower 33% of the graphic is cropped, and the wrap polygon covers the middle third |
| 282 |
// of the area vertically. Which means 10582*2/3 = 7054.67 is the cropped height, and the top of |
| 283 |
// the middle third is 2351.55. |
| 284 |
// Then there is a 15 twips shift from the origo, so it's 2351.55 + 26.46 = 2378.01 in mm100. |
| 285 |
// |
| 286 |
// Without the accompanying fix in place, this test would have failed with: |
| 287 |
// - Expected: 2369 |
| 288 |
// - Actual : 3542 |
| 289 |
// i.e. the wrap polygon covered a larger-than-correct area, which end the end means 3 lines |
| 290 |
// were wrapping around the image, not only 2 as Word does it. |
| 291 |
CPPUNIT_ASSERT_EQUAL(2369., aPolygon.getB2DPoint(0).getY()); |
| 292 |
} |
| 293 |
|
| 294 |
CPPUNIT_TEST_FIXTURE(Test, testTextboxTextline) |
| 295 |
{ |
| 296 |
// Load a document with a shape with a textbox. |
| 297 |
// The shape's vertical relation is <wp:positionV relativeFrom="line">. |
| 298 |
loadFromFile(u"textbox-textline.docx"); |
| 299 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 300 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 301 |
uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 302 |
sal_Int16 nActualRelation{}; |
| 303 |
CPPUNIT_ASSERT(xShape->getPropertyValue(u"VertOrientRelation"_ustr) >>= nActualRelation); |
| 304 |
sal_Int32 nActualPosition{}; |
| 305 |
CPPUNIT_ASSERT(xShape->getPropertyValue(u"VertOrientPosition"_ustr) >>= nActualPosition); |
| 306 |
|
| 307 |
sal_Int16 nExpectedRelation = text::RelOrientation::TEXT_LINE; |
| 308 |
CPPUNIT_ASSERT_EQUAL(nExpectedRelation, nActualRelation); |
| 309 |
sal_Int32 nExpectedPosition = -2; |
| 310 |
CPPUNIT_ASSERT_EQUAL(nExpectedPosition, nActualPosition); |
| 311 |
} |
| 312 |
|
| 313 |
CPPUNIT_TEST_FIXTURE(Test, testTextboxTextlineTop) |
| 314 |
{ |
| 315 |
loadFromFile(u"textbox-textline-top.docx"); |
| 316 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 317 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 318 |
uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 319 |
sal_Int16 nActualRelation{}; |
| 320 |
CPPUNIT_ASSERT(xShape->getPropertyValue(u"VertOrientRelation"_ustr) >>= nActualRelation); |
| 321 |
sal_Int16 nExpectedRelation = text::RelOrientation::TEXT_LINE; |
| 322 |
// Without the accompanying fix in place, this test would have failed with: |
| 323 |
// - Expected: 9 (TEXT_LINE) |
| 324 |
// - Actual : 0 (FRAME) |
| 325 |
// i.e. the anchor point for the positioning was wrong, resulting in overlapping textboxes. |
| 326 |
CPPUNIT_ASSERT_EQUAL(nExpectedRelation, nActualRelation); |
| 327 |
|
| 328 |
sal_Int16 nActualOrient{}; |
| 329 |
CPPUNIT_ASSERT(xShape->getPropertyValue(u"VertOrient"_ustr) >>= nActualOrient); |
| 330 |
sal_Int16 nExpectedOrient = text::VertOrientation::BOTTOM; |
| 331 |
CPPUNIT_ASSERT_EQUAL(nExpectedOrient, nActualOrient); |
| 332 |
} |
| 333 |
|
| 334 |
CPPUNIT_TEST_FIXTURE(Test, testLayoutInCellWrapnoneColumn) |
| 335 |
{ |
| 336 |
// Given a file with a table, then a shape anchored inside the cell: |
| 337 |
loadFromFile(u"layout-in-cell-wrapnone-column.docx"); |
| 338 |
|
| 339 |
// Then make sure the shape can leave the cell: |
| 340 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 341 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 342 |
uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY); |
| 343 |
uno::Reference<container::XNamed> xNamedShape(xShape, uno::UNO_QUERY); |
| 344 |
CPPUNIT_ASSERT_EQUAL(u"Text Box 1"_ustr, xNamedShape->getName()); |
| 345 |
bool bFollowingTextFlow = true; |
| 346 |
// Without the accompanying fix in place, this test would have failed, the shape was not allowed |
| 347 |
// to leave the cell, leading to incorrect layout. |
| 348 |
CPPUNIT_ASSERT(xShape->getPropertyValue(u"IsFollowingTextFlow"_ustr) >>= bFollowingTextFlow); |
| 349 |
CPPUNIT_ASSERT(bFollowingTextFlow); |
| 350 |
|
| 351 |
// dump the layout |
| 352 |
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); |
| 353 |
uno::Reference<qa::XDumper> xDumper(xModel->getCurrentController(), uno::UNO_QUERY); |
| 354 |
const OString aDump = xDumper->dump(u"layout"_ustr).toUtf8(); |
| 355 |
auto pCharBuffer = reinterpret_cast<const xmlChar*>(aDump.getStr()); |
| 356 |
xmlDocUniquePtr pXmlDoc(xmlParseDoc(pCharBuffer)); |
| 357 |
|
| 358 |
// The entire blue, wrapthrough shape should be above the table that it is layoutInCell'd to. |
| 359 |
const sal_Int32 nShapeBottom |
| 360 |
= getXPath(pXmlDoc, "//tab/row/cell[2]/txt[1]/anchored/SwAnchoredDrawObject/bounds", |
| 361 |
"bottom") |
| 362 |
.toInt32(); |
| 363 |
sal_Int32 nTableTop = getXPath(pXmlDoc, "//tab/row/infos/bounds", "top").toInt32(); |
| 364 |
// The entire table must be below the rectangle |
| 365 |
CPPUNIT_ASSERT(nTableTop > nShapeBottom); |
| 366 |
} |
| 367 |
|
| 368 |
CPPUNIT_TEST_FIXTURE(Test, testLayoutInCellOfHraphics) |
| 369 |
{ |
| 370 |
// Given a file with a table, then a shape anchored inside the cell: |
| 371 |
loadFromFile(u"layout-in-cell-2.docx"); |
| 372 |
|
| 373 |
// Then make sure the cell obeys the layoutInCell: |
| 374 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 375 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 376 |
uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY); |
| 377 |
bool bFollowingTextFlow = false; |
| 378 |
CPPUNIT_ASSERT(xShape->getPropertyValue(u"IsFollowingTextFlow"_ustr) >>= bFollowingTextFlow); |
| 379 |
CPPUNIT_ASSERT(bFollowingTextFlow); |
| 380 |
} |
| 381 |
|
| 382 |
CPPUNIT_TEST_FIXTURE(Test, testTdf149840SmartArtBackground) |
| 383 |
{ |
| 384 |
// Make sure SmartArt is loaded as group shape |
| 385 |
bool bUseGroup = officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get(); |
| 386 |
if (!bUseGroup) |
| 387 |
{ |
| 388 |
std::shared_ptr<comphelper::ConfigurationChanges> pChange( |
| 389 |
comphelper::ConfigurationChanges::create()); |
| 390 |
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true, pChange); |
| 391 |
pChange->commit(); |
| 392 |
} |
| 393 |
|
| 394 |
loadFromFile(u"tdf149840_SmartArtBackground.docx"); |
| 395 |
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
| 396 |
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); |
| 397 |
uno::Reference<container::XIndexAccess> xGroup(xDrawPage->getByIndex(0), uno::UNO_QUERY); |
| 398 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), xGroup->getCount()); |
| 399 |
|
| 400 |
// The first shape in the group, which represents the SmartArt, corresponds to the background of |
| 401 |
// the diagram. Without fix in place it has width and height zero, which does not only result in |
| 402 |
// not visible background but in wrong sizes of the diagram shapes too. |
| 403 |
uno::Reference<drawing::XShape> xBackgroundShape(xGroup->getByIndex(0), uno::UNO_QUERY); |
| 404 |
awt::Size aBackgroundSize = xBackgroundShape->getSize(); |
| 405 |
// Tolerances are for rounding inaccuracies. |
| 406 |
// The test would have failed with Expected: 9560x5036, Actual: 2x2 |
| 407 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<sal_Int32>(9560), aBackgroundSize.Width, 1); |
| 408 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<sal_Int32>(5036), aBackgroundSize.Height, 1); |
| 409 |
|
| 410 |
uno::Reference<drawing::XShape> xShapeOne(xGroup->getByIndex(1), uno::UNO_QUERY); |
| 411 |
awt::Size aShapeOneSize = xShapeOne->getSize(); |
| 412 |
// The test would have failed with Expected: 3282x3709, Actual: 3972x3709 |
| 413 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<sal_Int32>(3282), aShapeOneSize.Width, 1); |
| 414 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<sal_Int32>(3709), aShapeOneSize.Height, 1); |
| 415 |
|
| 416 |
uno::Reference<drawing::XShape> xShapeTwo(xGroup->getByIndex(2), uno::UNO_QUERY); |
| 417 |
awt::Size aShapeTwoSize = xShapeTwo->getSize(); |
| 418 |
// The test would have failed with Expected: 2404x5226, Actual: 2910x5226 |
| 419 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<sal_Int32>(2404), aShapeTwoSize.Width, 1); |
| 420 |
CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<sal_Int32>(5226), aShapeTwoSize.Height, 1); |
| 421 |
|
| 422 |
if (!bUseGroup) |
| 423 |
{ |
| 424 |
std::shared_ptr<comphelper::ConfigurationChanges> pChange( |
| 425 |
comphelper::ConfigurationChanges::create()); |
| 426 |
officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false, pChange); |
| 427 |
pChange->commit(); |
| 428 |
} |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |