Kaydet (Commit) 31339211 authored tarafından Armin Le Grand's avatar Armin Le Grand

Reorganize FrameBorderPrimitive creation (II)

Step5: Move the view-dependent decomposition from
BorderLinePrimitive2D to SdrFrameBorderPrimitive2D.

It is now possible to use discrete sizes before the
line and edge matching is done what will look much
better. When it was done at BorderLinePrimitive2D
and the matching was already done, that match was
'displaced' with the adapted forced scale to discrete
units.

The space and size used when zooming out for a single
discrete unit (pixel) can heavily vary - it just covers
a much larger logical area than the 'real' line/poly
would do. All this needs to be handled (also for bound
ranges) and can only be in a good way using primitives.

Adapted to no longer do view-dependent changes in
BorderLinePrimitive2D. Adapted to do these now at
SdrFrameBorderPrimitive2D. Currently used to force
the existing border partial lines (up to three) to
not get taller than one logical unit.

Adapted to no longer switch off AntiAliased rendering
in VclPixelProcessor2D for processBorderLinePrimitive2D,
this is problematic with various renderers on various
systems (e.g. vcl still falls back to render multiple
one-pixel-lines when taller than 3.5 pixels which looks
horrible combined with other parts like filled polygons)

All this needs fine balancing on
- all systems
- all renderers
- all apps (which all have their own table implementation)
- all render targets (pixel/PDF/print/slideshow/...)

Done as thorough as possible, but may need additional
finetuning. May also be a motivation to move away from
vcl and implement these urgetly needed system-dependent
primitive renderers...

Adapted UnitTest testDoublePixelProcessing with the needed
comments.

Change-Id: Ie88bb76c2474b6ab3764d45a9cd1669264492acd
Reviewed-on: https://gerrit.libreoffice.org/62344
Tested-by: Jenkins
Reviewed-by: 's avatarArmin Le Grand <Armin.Le.Grand@cib.de>
üst 8dec85a3
......@@ -189,7 +189,7 @@ void DrawinglayerBorderTest::testDoublePixelProcessing()
{
auto pMPLAction = static_cast<MetaPolyLineAction*>(pAction);
if (0 == pMPLAction->GetLineInfo().GetWidth() && LineStyle::Solid == pMPLAction->GetLineInfo().GetStyle())
if (0 != pMPLAction->GetLineInfo().GetWidth() && LineStyle::Solid == pMPLAction->GetLineInfo().GetStyle())
{
nPolyLineActionCount++;
}
......@@ -198,7 +198,16 @@ void DrawinglayerBorderTest::testDoublePixelProcessing()
// Check if all eight (2x four) simple lines with width == 0 and
// solid were created
const sal_uInt32 nExpectedNumPolyLineActions = 8;
//
// This has changed: Now, just the needed 'real' lines get created
// which have a width of 1. This are two lines. The former multiple
// lines were a combination of view-dependent force to a single-pixel
// line width (0 == lineWidth -> hairline) and vcl rendering this
// using a (insane) combination of single non-AAed lines. All the
// system-dependent part of the BorderLine stuff is now done in
// SdrFrameBorderPrimitive2D and svx.
// Adapted this test - still useful, breaking it may be a hint :-)
const sal_uInt32 nExpectedNumPolyLineActions = 2;
CPPUNIT_ASSERT_EQUAL(nExpectedNumPolyLineActions, nPolyLineActionCount);
}
......
......@@ -76,18 +76,6 @@ namespace drawinglayer
&& isGap() == rBorderLine.isGap();
}
double BorderLine::getAdaptedWidth(double fMinWidth) const
{
if(isGap())
{
return std::max(getLineAttribute().getWidth(), fMinWidth);
}
else
{
return getLineAttribute().getWidth();
}
}
// helper to add a centered, maybe stroked line primitive to rContainer
static void addPolygonStrokePrimitive2D(
Primitive2DContainer& rContainer,
......@@ -124,7 +112,7 @@ namespace drawinglayer
for(const auto& candidate : maBorderLines)
{
fRetval += candidate.getAdaptedWidth(mfSmallestAllowedDiscreteGapDistance);
fRetval += candidate.getLineAttribute().getWidth();
}
return fRetval;
......@@ -143,7 +131,7 @@ namespace drawinglayer
for(const auto& candidate : maBorderLines)
{
const double fWidth(candidate.getAdaptedWidth(mfSmallestAllowedDiscreteGapDistance));
const double fWidth(candidate.getLineAttribute().getWidth());
if(!candidate.isGap())
{
......@@ -289,8 +277,7 @@ namespace drawinglayer
maStart(rStart),
maEnd(rEnd),
maBorderLines(rBorderLines),
maStrokeAttribute(rStrokeAttribute),
mfSmallestAllowedDiscreteGapDistance(0.0)
maStrokeAttribute(rStrokeAttribute)
{
}
......@@ -320,71 +307,6 @@ namespace drawinglayer
return false;
}
bool BorderLinePrimitive2D::getSmallestGap(double& rfSmallestGap) const
{
bool bGapFound(false);
for(const auto& candidate : maBorderLines)
{
if(candidate.isGap())
{
if(bGapFound)
{
rfSmallestGap = std::min(rfSmallestGap, candidate.getLineAttribute().getWidth());
}
else
{
bGapFound = true;
rfSmallestGap = candidate.getLineAttribute().getWidth();
}
}
}
return bGapFound;
}
void BorderLinePrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const
{
::osl::MutexGuard aGuard(m_aMutex);
if (!getStart().equal(getEnd()) && getBorderLines().size() > 1)
{
// Line with potential gap. In this case, we want to be view-dependent.
// get the smallest gap
double fSmallestGap(0.0);
if(getSmallestGap(fSmallestGap))
{
// Get the current DiscreteUnit, look at X and Y and use the maximum
const basegfx::B2DVector aDiscreteVector(rViewInformation.getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 1.0));
const double fDiscreteUnit(std::min(fabs(aDiscreteVector.getX()), fabs(aDiscreteVector.getY())));
// When discrete unit is bigger than distance (distance is less than one pixel),
// force distance to one pixel. Or expressed different, do not let the distance
// get smaller than one pixel. This is done for screen rendering and compatibility.
// This can also be done using DiscreteMetricDependentPrimitive2D as base class
// for this class, but specialization is better here for later buffering (only
// do this when 'double line with gap')
const double fNewDiscreteDistance(std::max(fDiscreteUnit, fSmallestGap));
if (!rtl::math::approxEqual(fNewDiscreteDistance, mfSmallestAllowedDiscreteGapDistance))
{
if (!getBuffered2DDecomposition().empty())
{
// conditions of last local decomposition have changed, delete
const_cast< BorderLinePrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DContainer());
}
// remember value for usage in create2DDecomposition
const_cast< BorderLinePrimitive2D* >(this)->mfSmallestAllowedDiscreteGapDistance = fNewDiscreteDistance;
}
}
}
// call base implementation
BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor, rViewInformation);
}
// provide unique ID
ImplPrimitive2DIDBlock(BorderLinePrimitive2D, PRIMITIVE2D_ID_BORDERLINEPRIMITIVE2D)
......
......@@ -879,17 +879,36 @@ namespace drawinglayer
void VclPixelProcessor2D::processBorderLinePrimitive2D(const drawinglayer::primitive2d::BorderLinePrimitive2D& rBorder)
{
// process recursively, but switch off AntiAliasing for
// Process recursively, but switch off AntiAliasing for
// horizontal/vertical lines (*not* diagonal lines).
// Checked using AntialiasingFlags::PixelSnapHairline instead,
// but with AntiAliasing on the display really is too 'ghosty' when
// using fine stroking. Correct, but 'ghosty'.
if (rBorder.isHorizontalOrVertical(getViewInformation2D()))
// It has shown that there are quite some problems here:
// - vcl OutDev renderer methods stuill use fallbacks to paint
// multiple single lines between discrete sizes of < 3.5 what
// looks bad and does not matzch
// - mix of filled Polygons and Lines is bad when AA switched off
// - Alignment of AA with non-AA may be bad in diverse different
// renderers
//
// Due to these reasons I change the strategy: Always draw AAed, but
// allow fallback to test/check and if needed. The normal case
// where BorderLines will be system-depenently snapped to have at
// least a single discrete width per partial line (there may be up to
// three) works well nowadays due to most renderers moving the AA stuff
// by 0.5 pixels (discrete units) to match well with the non-AAed parts.
//
// Env-Switch for steering this, default is off.
// Enable by setting at all (and to something)
static const char* pSwitchOffAntiAliasingForHorVerBorderlines(getenv("SAL_SWITCH_OFF_ANTIALIASING_FOR_HOR_VER_BORTDERLINES"));
static bool bSwitchOffAntiAliasingForHorVerBorderlines(nullptr != pSwitchOffAntiAliasingForHorVerBorderlines);
if (bSwitchOffAntiAliasingForHorVerBorderlines && rBorder.isHorizontalOrVertical(getViewInformation2D()))
{
AntialiasingFlags nAntiAliasing = mpOutputDevice->GetAntialiasing();
mpOutputDevice->SetAntialiasing(nAntiAliasing & ~AntialiasingFlags::EnableB2dDraw);
process(rBorder);
mpOutputDevice->SetAntialiasing(nAntiAliasing);
}
......
......@@ -38,7 +38,9 @@ namespace drawinglayer
/** BorderLine class
Helper class holding the style definition for a single part of a full BorderLine definition.
Line extends are for start/end and for Left/Right, seen in vector direction. If
Left != Right that means the line has a diagonal start/end
Left != Right that means the line has a diagonal start/end.
Think about it similar to a trapezoid, but not aligned to X-Axis and using the
perpendicular vector to the given one in a right-handed coordinate system.
*/
class DRAWINGLAYER_DLLPUBLIC BorderLine
{
......@@ -76,9 +78,6 @@ namespace drawinglayer
double getEndRight() const { return mfEndRight; }
bool isGap() const { return mbIsGap; }
/// helper to get adapted width (maximum)
double getAdaptedWidth(double fMinWidth) const;
/// compare operator
bool operator==(const BorderLine& rBorderLine) const;
};
......@@ -111,18 +110,10 @@ namespace drawinglayer
/// common style definitions
const drawinglayer::attribute::StrokeAttribute maStrokeAttribute;
// for view dependent decomposition in the case with existing gaps,
// remember the smallest allowed concrete gap distance, see get2DDecomposition
// implementation
double mfSmallestAllowedDiscreteGapDistance;
/// create local decomposition
virtual void create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& rViewInformation) const override;
/// helper to find smallest defined gap in maBorderLines
bool getSmallestGap(double& rfSmallestGap) const;
/// helper to get the full width taking mfSmallestAllowedDiscreteGapDistance into account
/// helper to get the full width from maBorderLines
double getFullWidth() const;
public:
......@@ -145,9 +136,6 @@ namespace drawinglayer
/// compare operator
virtual bool operator==(const BasePrimitive2D& rPrimitive) const override;
/// Override standard getDecomposition to be view-dependent here
virtual void get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const override;
/// provide unique ID
DeclPrimitive2DIDBlock()
};
......
......@@ -72,7 +72,11 @@ namespace drawinglayer
const basegfx::B2DVector& rNormalizedPerpendicular,
bool bStyleMirrored);
void create2DDecomposition(Primitive2DContainer& rContainer) const;
void create2DDecomposition(
Primitive2DContainer& rContainer,
double fMinDiscreteUnit) const;
double getMinimalNonZeroBorderWidth() const;
};
typedef std::vector<SdrFrameBorderData> SdrFrameBorderDataVector;
......@@ -88,7 +92,10 @@ namespace drawinglayer
{
private:
std::shared_ptr<SdrFrameBorderDataVector> maFrameBorders;
double mfMinimalNonZeroBorderWidth;
double mfMinimalNonZeroBorderWidthUsedForDecompose;
bool mbMergeResult;
bool mbForceToSingleDiscreteUnit;
protected:
// local decomposition.
......@@ -99,14 +106,21 @@ namespace drawinglayer
public:
SdrFrameBorderPrimitive2D(
std::shared_ptr<SdrFrameBorderDataVector>& rFrameBorders,
bool bMergeResult);
bool bMergeResult,
bool bForceToSingleDiscreteUnit);
// compare operator
virtual bool operator==(const BasePrimitive2D& rPrimitive) const override;
// override to get view-dependent
virtual void get2DDecomposition(
Primitive2DDecompositionVisitor& rVisitor,
const geometry::ViewInformation2D& rViewInformation) const override;
// data access
const SdrFrameBorderDataVector& getFrameBorders() const { return *maFrameBorders.get(); }
bool getMergeResult() const { return mbMergeResult; }
const std::shared_ptr<SdrFrameBorderDataVector>& getFrameBorders() const { return maFrameBorders; }
bool doMergeResult() const { return mbMergeResult; }
bool doForceToSingleDiscreteUnit() const { return mbForceToSingleDiscreteUnit; }
// provide unique ID
DeclPrimitive2DIDBlock()
......
......@@ -1233,7 +1233,8 @@ drawinglayer::primitive2d::Primitive2DContainer Array::CreateB2DPrimitiveRange(
drawinglayer::primitive2d::Primitive2DReference(
new drawinglayer::primitive2d::SdrFrameBorderPrimitive2D(
aData,
true)));
true, // try to merge results to have less primitivbes
true))); // force visualization to minimal one discrete unit (pixel)
}
return aSequence;
......
......@@ -2567,7 +2567,8 @@ void SwTabFramePainter::PaintLines(OutputDevice& rDev, const SwRect& rRect) cons
drawinglayer::primitive2d::Primitive2DReference(
new drawinglayer::primitive2d::SdrFrameBorderPrimitive2D(
aData,
true)));
true, // try to merge results to have less primitivbes
true))); // force visualization to minimal one discrete unit (pixel)
// paint
mrTabFrame.ProcessPrimitives(aSequence);
}
......@@ -4630,7 +4631,8 @@ namespace drawinglayer
drawinglayer::primitive2d::Primitive2DReference(
new drawinglayer::primitive2d::SdrFrameBorderPrimitive2D(
aData,
true)));
true, // try to merge results to have less primitivbes
true))); // force visualization to minimal one discrete unit (pixel)
}
}
......
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