Kaydet (Commit) f8b4d371 authored tarafından Miklos Vajna's avatar Miklos Vajna

drawinglayer: avoid AA for hairline polygons built from hori/vert lines only

For one, it seems this was the intention already since commit
85c70f37 (CWS-TOOLING: integrate CWS
aw063, 2009-03-04): "suppress AntiAliasing for pure horizontal or
vertical lines".

For another, this fixes the TileCacheTests::testTileWireIDHandling()
testcase in online.git, which assumes that the indicators at the corners
of the Writer body frame (paragraph marks hidden / default case) can be
painted multiple times, producing pixel-by-pixel matching results. But
in reality AA breaks that assumption, and we know these indicators are
never diagonal lines.

Change-Id: Ib74f823165799991296b64cee58ec106dbdcedcf
Reviewed-on: https://gerrit.libreoffice.org/72000Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
üst c1bcdf9a
......@@ -416,6 +416,24 @@ namespace basegfx
return aRetval;
bool containsOnlyHorizontalOrVerticalLines(const basegfx::B2DPolygon& rPolygon)
if (rPolygon.count() <= 1)
return false;
for (size_t i = 1; i < rPolygon.count(); ++i)
const basegfx::B2DPoint& rPrevPoint = rPolygon.getB2DPoint(i - 1);
const basegfx::B2DPoint& rPoint = rPolygon.getB2DPoint(i);
if (rPrevPoint.getX() == rPoint.getX() || rPrevPoint.getY() == rPoint.getY())
return false;
return true;
B2DPolyPolygon createSevenSegmentPolyPolygon(sal_Char nNumber, bool bLitSegments)
// config here
......@@ -22,6 +22,7 @@
#include <cppunit/extensions/HelperMacros.h>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/point/b2dpoint.hxx>
namespace basegfx
......@@ -77,12 +78,31 @@ public:
CPPUNIT_ASSERT_EQUAL_MESSAGE("#2 second polygon point wrong", B2DPoint(3, 3),
void testContainsOnlyHorizontalOrVerticalLines()
// First line is horziontal, second is vertical.
B2DPolygon aPoly;
aPoly.append(B2DPoint(0, 1));
aPoly.append(B2DPoint(1, 1));
aPoly.append(B2DPoint(1, 0));
// First line is diagonal, second is vertical.
aPoly.append(B2DPoint(0, 0));
aPoly.append(B2DPoint(1, 1));
aPoly.append(B2DPoint(1, 0));
// Change the following lines only, if you add, remove or rename
// member functions of the current class,
// because these macros are need by auto register mechanism.
}; // class b2dpolygon
......@@ -140,6 +140,16 @@ namespace drawinglayer
if (getOptionsDrawinglayer().IsAntiAliasing() && getOptionsDrawinglayer().IsSnapHorVerLinesToDiscrete())
if (basegfx::utils::containsOnlyHorizontalOrVerticalLines(rLocalPolygon))
// DrawPolyLineDirect() only works in AA mode, but pure horizontal or vertical
// lines are better with AA off.
return false;
// try drawing; if it did not work, use standard fallback
return mpOutputDevice->DrawPolyLineDirect(
......@@ -331,6 +331,7 @@ namespace drawinglayer
basegfx::B2DPolygon aLocalPolygon(rPolygonCandidate.getB2DPolygon());
bool bDisableAA = false;
if(bPixelBased && getOptionsDrawinglayer().IsAntiAliasing() && getOptionsDrawinglayer().IsSnapHorVerLinesToDiscrete())
// #i98289#
......@@ -339,9 +340,18 @@ namespace drawinglayer
// not-AntiAliased such lines look more pleasing to the eye (e.g. 2D chart content). This
// NEEDS to be done in discrete coordinates, so only useful for pixel based rendering.
aLocalPolygon = basegfx::utils::snapPointsOfHorizontalOrVerticalEdges(aLocalPolygon);
// Also disable AA, snap would leave the start/end of lines still anti-aliased when
// their coordinates are provided in logic units.
bDisableAA = basegfx::utils::containsOnlyHorizontalOrVerticalLines(aLocalPolygon);
const AntialiasingFlags nOriginalAA(mpOutputDevice->GetAntialiasing());
if (bDisableAA && (nOriginalAA & AntialiasingFlags::EnableB2dDraw))
mpOutputDevice->SetAntialiasing(nOriginalAA & ~AntialiasingFlags::EnableB2dDraw);
mpOutputDevice->DrawPolyLine(aLocalPolygon, 0.0);
if (bDisableAA && (nOriginalAA & AntialiasingFlags::EnableB2dDraw))
mpOutputDevice->SetAntialiasing(mpOutputDevice->GetAntialiasing() | AntialiasingFlags::EnableB2dDraw);
// direct draw of transformed BitmapEx primitive
......@@ -445,6 +445,9 @@ namespace basegfx
BASEGFX_DLLPUBLIC B2DPolygon snapPointsOfHorizontalOrVerticalEdges(const B2DPolygon& rCandidate);
/// Determines if rPolygon lacks diagonal lines or not.
BASEGFX_DLLPUBLIC bool containsOnlyHorizontalOrVerticalLines(const basegfx::B2DPolygon& rPolygon);
/// get the tangent with which the given point is entered seen from the previous
/// polygon path data. Take into account all stuff like closed state, zero-length edges and others.
BASEGFX_DLLPUBLIC B2DVector getTangentEnteringPoint(const B2DPolygon& rCandidate, sal_uInt32 nIndex);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment