tdf#124987 sw: Fixed off-by-one error in draw obj anchor clipping rect
Since tdf#91260, Writer clips drawing objects to pages by checking
whether their anchors are contained by a bounding rectangle. The code
that calculated this rectangle had an off-by-one error causing the
clipping rectangle to always be exactly 1 twip shorter and narrower than
the actual page frame rectangle. As a result, anything with an anchor
position on the right or bottom edge of the screen would fail to render
- including any objects anchored to an RTL page.
Regression from commit 689cead9e0
Author: Michael Stahl <mstahl@redhat.com>
Date: Tue Dec 6 22:59:40 2016 +0100
tdf#91260 svx, sw: don't paint off-page part of drawing object
Change-Id: Ife6c817f0689ca2b31d22df31f740c30ab548c8c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205114
Reviewed-by: Jonathan Clark <jonathan@libreoffice.org>
Tested-by: Jenkins
This commit is contained in:
@@ -161,6 +161,7 @@ namespace vcl::unotools
|
||||
tools::Rectangle VCL_DLLPUBLIC rectangleFromB2IRectangle( const basegfx::B2IRange& );
|
||||
basegfx::B2IPoint VCL_DLLPUBLIC b2IPointFromPoint(const Point&);
|
||||
basegfx::B2IRectangle VCL_DLLPUBLIC b2IRectangleFromRectangle(const tools::Rectangle&);
|
||||
basegfx::B2IRectangle VCL_DLLPUBLIC b2IRectangleFromClosedRectangle(const tools::Rectangle&);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,11 @@ void SwViewShellImp::PaintLayer( const SdrLayerID _nLayerID,
|
||||
}
|
||||
|
||||
pOutDev->Push( vcl::PushFlags::LINECOLOR );
|
||||
basegfx::B2IRectangle const pageFrame = vcl::unotools::b2IRectangleFromRectangle(rPageFrame.getFrameArea().SVRect());
|
||||
|
||||
// tdf#124987: Writer considers frame rectangles closed ranges, and may position anchors
|
||||
// at the edges of the rectangle. Convert this to B2IRectangle as a closed range, not open.
|
||||
basegfx::B2IRectangle const pageFrame
|
||||
= vcl::unotools::b2IRectangleFromClosedRectangle(rPageFrame.getFrameArea().SVRect());
|
||||
GetPageView()->DrawLayer(_nLayerID, pOutDev, pRedirector, aPaintRect.SVRect(), &pageFrame);
|
||||
pOutDev->Pop();
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ $(eval $(call gb_CppunitTest_set_include,vcl_text,\
|
||||
|
||||
$(eval $(call gb_CppunitTest_add_exception_objects,vcl_text, \
|
||||
vcl/qa/cppunit/canvasbitmaptest \
|
||||
vcl/qa/cppunit/canvastoolstest \
|
||||
vcl/qa/cppunit/complextext \
|
||||
vcl/qa/cppunit/justificationdata \
|
||||
vcl/qa/cppunit/text \
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/* -*- 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 <test/bootstrapfixture.hxx>
|
||||
#include <vcl/canvastools.hxx>
|
||||
|
||||
using namespace ::com::sun::star;
|
||||
using namespace vcl::unotools;
|
||||
|
||||
namespace
|
||||
{
|
||||
class CanvasToolsTest : public CppUnit::TestFixture
|
||||
{
|
||||
public:
|
||||
void testB2IRectangleFromClosedRectangle();
|
||||
|
||||
CPPUNIT_TEST_SUITE(CanvasToolsTest);
|
||||
CPPUNIT_TEST(testB2IRectangleFromClosedRectangle);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
|
||||
void CanvasToolsTest::testB2IRectangleFromClosedRectangle()
|
||||
{
|
||||
// tdf#124987: Characterization test for a use that was causing an off-by-one
|
||||
// error when clipping draw objects to the page containing the anchor
|
||||
|
||||
tools::Rectangle aRect{ /*nLeft*/ 100, /*nTop*/ 100, /*nRight*/ 200, /*nBottom*/ 300 };
|
||||
|
||||
// With the original code, the simulated RTL anchor would be considered off-screen
|
||||
auto aBadPageFrame = b2IRectangleFromRectangle(aRect);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(200), aBadPageFrame.getMaxX());
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(300), aBadPageFrame.getMaxY());
|
||||
|
||||
// With the new code, the simulated RTL anchor would be considered on-screen
|
||||
auto aPageFrame = b2IRectangleFromClosedRectangle(aRect);
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(201), aPageFrame.getMaxX());
|
||||
CPPUNIT_ASSERT_EQUAL(sal_Int32(301), aPageFrame.getMaxY());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(CanvasToolsTest);
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -338,6 +338,19 @@ namespace vcl::unotools
|
||||
rRect.IsHeightEmpty() ? rRect.Top() : rRect.Bottom() );
|
||||
}
|
||||
|
||||
basegfx::B2IRectangle b2IRectangleFromClosedRectangle(tools::Rectangle const& rRect)
|
||||
{
|
||||
// although B2IRange internally has separate height/width emptiness, it doesn't
|
||||
// expose any API to let us set them separately, so just do the best we can.
|
||||
if (rRect.IsWidthEmpty() && rRect.IsHeightEmpty())
|
||||
{
|
||||
return basegfx::B2IRange(basegfx::B2ITuple(rRect.Left(), rRect.Top()));
|
||||
}
|
||||
|
||||
return basegfx::B2IRange(rRect.Left(), rRect.Top(), rRect.Left() + rRect.GetWidth(),
|
||||
rRect.Top() + rRect.GetHeight());
|
||||
}
|
||||
|
||||
basegfx::B2DSize b2DSizeFromSize(const Size& rSize)
|
||||
{
|
||||
return basegfx::B2DSize(rSize.Width(), rSize.Height());
|
||||
|
||||
Reference in New Issue
Block a user