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

borderline: Adapted BorderLinePrimitive2D and usages

Big changes to BorderLinePrimitive2D and BorderLine, freeing
it from one/three entries, going to a free definition using
gaps with width but without color. Adapted usages and creation,
not yet tested much

Change-Id: Ic1255a790401901c3166d200205bc23322b37185
üst 0d2b5305
......@@ -25,6 +25,7 @@ $(eval $(call gb_CppunitTest_use_libraries,drawinglayer_border, \
test \
tl \
unotest \
svt \
))
$(eval $(call gb_CppunitTest_use_externals,drawinglayer_border,\
......
......@@ -25,6 +25,7 @@
#include <vcl/vclptr.hxx>
#include <vcl/virdev.hxx>
#include <editeng/borderline.hxx>
#include <svtools/borderhelper.hxx>
using namespace com::sun::star;
......@@ -49,7 +50,7 @@ void DrawinglayerBorderTest::testDoubleDecompositionSolid()
// 1.47 pixels is 0.03cm at 130% zoom and 96 DPI.
basegfx::B2DPoint aStart(0, 20);
basegfx::B2DPoint aEnd(100, 20);
double fLeftWidth = 1.47;
double const fLeftWidth = 1.47;
double const fDistance = 1.47;
double const fRightWidth = 1.47;
double const fExtendLeftStart = 0;
......@@ -58,30 +59,39 @@ void DrawinglayerBorderTest::testDoubleDecompositionSolid()
double const fExtendRightEnd = 0;
basegfx::BColor aColorRight;
basegfx::BColor aColorLeft;
basegfx::BColor aColorGap;
bool const bHasGapColor = false;
SvxBorderLineStyle const nStyle = SvxBorderLineStyle::DOUBLE;
const std::vector<double> aDashing(svtools::GetLineDashing(SvxBorderLineStyle::DOUBLE, 10.0));
const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(aDashing);
std::vector< drawinglayer::primitive2d::BorderLine > aBorderlines;
aBorderlines.push_back(
drawinglayer::primitive2d::BorderLine(
drawinglayer::attribute::LineAttribute(
aColorLeft,
fLeftWidth),
fExtendLeftStart,
fExtendLeftStart,
fExtendLeftEnd,
fExtendLeftEnd));
aBorderlines.push_back(
drawinglayer::primitive2d::BorderLine(fDistance));
aBorderlines.push_back(
drawinglayer::primitive2d::BorderLine(
drawinglayer::attribute::LineAttribute(
aColorRight,
fRightWidth),
fExtendRightStart,
fExtendRightStart,
fExtendRightEnd,
fExtendRightEnd));
rtl::Reference<drawinglayer::primitive2d::BorderLinePrimitive2D> aBorder(
new drawinglayer::primitive2d::BorderLinePrimitive2D(
aStart,
aEnd,
drawinglayer::primitive2d::BorderLine(
fLeftWidth,
aColorLeft,
drawinglayer::primitive2d::BorderLineExtend(
fExtendLeftStart,
fExtendLeftEnd)),
drawinglayer::primitive2d::BorderLine(
fDistance,
aColorGap),
drawinglayer::primitive2d::BorderLine(
fRightWidth,
aColorRight,
drawinglayer::primitive2d::BorderLineExtend(
fExtendRightStart,
fExtendRightEnd)),
bHasGapColor,
nStyle));
aBorderlines,
aStrokeAttribute));
// Decompose it into polygons.
drawinglayer::geometry::ViewInformation2D aView;
......@@ -126,33 +136,42 @@ void DrawinglayerBorderTest::testDoublePixelProcessing()
double const fExtendRightEnd = 0;
basegfx::BColor aColorRight;
basegfx::BColor aColorLeft;
basegfx::BColor aColorGap;
bool const bHasGapColor = false;
SvxBorderLineStyle const nStyle = SvxBorderLineStyle::DOUBLE;
rtl::Reference<drawinglayer::primitive2d::BorderLinePrimitive2D> xBorder(
const std::vector<double> aDashing(svtools::GetLineDashing(SvxBorderLineStyle::DOUBLE, 10.0));
const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(aDashing);
std::vector< drawinglayer::primitive2d::BorderLine > aBorderlines;
aBorderlines.push_back(
drawinglayer::primitive2d::BorderLine(
drawinglayer::attribute::LineAttribute(
aColorLeft,
fLeftWidth),
fExtendLeftStart,
fExtendLeftStart,
fExtendLeftEnd,
fExtendLeftEnd));
aBorderlines.push_back(
drawinglayer::primitive2d::BorderLine(fDistance));
aBorderlines.push_back(
drawinglayer::primitive2d::BorderLine(
drawinglayer::attribute::LineAttribute(
aColorRight,
fRightWidth),
fExtendRightStart,
fExtendRightStart,
fExtendRightEnd,
fExtendRightEnd));
rtl::Reference<drawinglayer::primitive2d::BorderLinePrimitive2D> aBorder(
new drawinglayer::primitive2d::BorderLinePrimitive2D(
aStart,
aEnd,
drawinglayer::primitive2d::BorderLine(
fLeftWidth,
aColorLeft,
drawinglayer::primitive2d::BorderLineExtend(
fExtendLeftStart,
fExtendLeftEnd)),
drawinglayer::primitive2d::BorderLine(
fDistance,
aColorGap),
drawinglayer::primitive2d::BorderLine(
fRightWidth,
aColorRight,
drawinglayer::primitive2d::BorderLineExtend(
fExtendRightStart,
fExtendRightEnd)),
bHasGapColor,
nStyle));
aBorderlines,
aStrokeAttribute));
drawinglayer::primitive2d::Primitive2DContainer aPrimitives;
aPrimitives.push_back(drawinglayer::primitive2d::Primitive2DReference(xBorder.get()));
aPrimitives.push_back(drawinglayer::primitive2d::Primitive2DReference(aBorder.get()));
// Process the primitives.
pProcessor->process(aPrimitives);
......
......@@ -26,6 +26,8 @@
#include <basegfx/color/bcolor.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <drawinglayer/attribute/lineattribute.hxx>
#include <drawinglayer/attribute/strokeattribute.hxx>
enum class SvxBorderLineStyle : sal_Int16;
......@@ -33,70 +35,53 @@ namespace drawinglayer
{
namespace primitive2d
{
/** BorderLineExtend class
*/
class DRAWINGLAYER_DLLPUBLIC BorderLineExtend
{
private:
std::vector<double> mfExtends;
public:
BorderLineExtend();
BorderLineExtend(
double fStart,
double fEnd);
BorderLineExtend(
double fStartLeft,
double fStartRight,
double fEndLeft,
double fEndRight);
~BorderLineExtend();
bool equalStart() const;
bool equalEnd() const;
double getStartLeft() const;
double getStartRight() const;
double getEndLeft() const;
double getEndRight() const;
double getStartAverage() const;
double getEndAverage() const;
/// compare operator
bool operator==(const BorderLineExtend& rBorderLineExtend) const;
};
/** BorderLine class
Helper class holding the style definition for a single part of a full NorderLine definition.
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
*/
class DRAWINGLAYER_DLLPUBLIC BorderLine
{
private:
// line width
double mfWidth;
// line color
basegfx::BColor maRGBColor;
// line attribute containing Width, Color and others
drawinglayer::attribute::LineAttribute maLineAttribute;
// line extends
BorderLineExtend maBorderLineExtend;
double mfStartLeft;
double mfStartRight;
double mfEndLeft;
double mfEndRight;
// if this is a gap, this is set to true
bool mbIsGap;
public:
// Constructor for visible BorderLine segments
BorderLine(
double fWidth,
const basegfx::BColor& rRGBColor,
const BorderLineExtend& rBorderLineExtend);
BorderLine(
double fWidth,
const basegfx::BColor& rRGBColor);
const drawinglayer::attribute::LineAttribute& rLineAttribute,
double fStartLeft = 0.0,
double fStartRight = 0.0,
double fEndLeft = 0.0,
double fEndRight = 0.0);
// Constructor for gap BorderLine segments
BorderLine(double fWidth);
~BorderLine();
double getWidth() const { return mfWidth; }
const basegfx::BColor& getRGBColor() const { return maRGBColor; }
const BorderLineExtend& getBorderLineExtend() const { return maBorderLineExtend; }
const drawinglayer::attribute::LineAttribute& getLineAttribute() const { return maLineAttribute; }
double getStartLeft() const { return mfStartLeft; }
double getStartRight() const { return mfStartRight; }
double getEndLeft() const { return mfEndLeft; }
double getEndRight() const { return mfEndRight; }
bool isGap() const { return mbIsGap; }
/// helper to get adapted width (maximum)
double getAdaptedWidth(double fMinWidth) const;
/// helper to get average values Start/End
double getStartAverage() const { return 0.5 * (mfStartLeft + mfStartRight); }
double getEndAverage() const { return 0.5 * (mfEndLeft + mfEndRight); }
/// compare operator
bool operator==(const BorderLine& rBorderLine) const;
......@@ -117,50 +102,39 @@ namespace drawinglayer
basegfx::B2DPoint maStart;
basegfx::B2DPoint maEnd;
/// the single BorderLine style definition(s), one or three allowed (see constructors)
/// the single BorderLine style definition(s), one or three mostly used
std::vector< BorderLine > maBorderLines;
bool mbHasGapColor;
/// common style definitions
SvxBorderLineStyle mnStyle;
double mfPatternScale;
const drawinglayer::attribute::StrokeAttribute maStrokeAttribute;
// for view dependent decomposition in the case with distance (gap),
// remember the last used concrete mfDistance, see get2DDecomposition
// for view dependent decomposition in the case with existing gaps,
// remember the smallest allowed concrete gap distance, see get2DDecomposition
// implementation
double mfDiscreteGapDistance;
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
double getFullWidth() const;
public:
/// simplified constructor for BorderLine with single edge
BorderLinePrimitive2D(
const basegfx::B2DPoint& rStart,
const basegfx::B2DPoint& rEnd,
const BorderLine& rBorderLine,
SvxBorderLineStyle nStyle,
double fPatternScale = 1.0);
/// constructor for full-fledged BorderLine with two edges and gap
BorderLinePrimitive2D(
const basegfx::B2DPoint& rStart,
const basegfx::B2DPoint& rEnd,
const BorderLine& rLeft,
const BorderLine& rGap,
const BorderLine& rRight,
bool bHasGapColor,
SvxBorderLineStyle nStyle,
double fPatternScale = 1.0);
const std::vector< BorderLine >& rBorderLines,
const drawinglayer::attribute::StrokeAttribute& rStrokeAttribute);
/// data read access
const basegfx::B2DPoint& getStart() const { return maStart; }
const basegfx::B2DPoint& getEnd() const { return maEnd; }
const std::vector< BorderLine >& getBorderLines() const { return maBorderLines; }
bool hasGapColor() const { return mbHasGapColor; }
SvxBorderLineStyle getStyle() const { return mnStyle; }
double getPatternScale() const { return mfPatternScale; }
const drawinglayer::attribute::StrokeAttribute& getStrokeAttribute() const { return maStrokeAttribute; }
/// helper to decide if AntiAliasing should be used
bool isHorizontalOrVertical(const geometry::ViewInformation2D& rViewInformation) const;
......
This diff is collapsed.
......@@ -85,7 +85,7 @@ typedef std::vector< Cell > CellVec;
size_t Cell::GetCellIndex(const Array& rArray) const
{
if(-1 == maCellIndex)
if(static_cast<size_t>(-1) == maCellIndex)
{
rArray.AddCellIndices();
}
......@@ -102,7 +102,7 @@ basegfx::B2DHomMatrix Cell::CreateCoordinateSystem(const Array& rArray) const
const size_t nCellIndex(GetCellIndex(rArray));
if(-1 != nCellIndex)
if(static_cast<size_t>(-1) != nCellIndex)
{
const basegfx::B2DRange aRange(rArray.GetCellRange(nCellIndex));
......@@ -976,7 +976,7 @@ void HelperCreateHorizontalEntry(
CreateBorderPrimitives(
rSequence,
bUpper ? rOrigin : rOrigin + rY,
bUpper ? rOrigin : basegfx::B2DPoint(rOrigin + rY),
rX,
rStyle,
aStart,
......@@ -1021,7 +1021,7 @@ void HelperCreateVerticalEntry(
CreateBorderPrimitives(
rSequence,
bLeft ? rOrigin : rOrigin + rX,
bLeft ? rOrigin : basegfx::B2DPoint(rOrigin + rX),
rY,
rStyle,
aStart,
......@@ -1038,7 +1038,7 @@ void HelperCreateEntry(const Array& rArray, const Style& rStyle, drawinglayer::p
{
const size_t nCellIndex(pCell->GetCellIndex(rArray));
if(-1 != nCellIndex)
if(static_cast<size_t>(-1) != nCellIndex)
{
size_t col(nCellIndex % rArray.GetColCount());
size_t row(nCellIndex / rArray.GetColCount());
......
......@@ -111,7 +111,6 @@ using namespace ::editeng;
using namespace ::com::sun::star;
using ::drawinglayer::primitive2d::BorderLinePrimitive2D;
using ::drawinglayer::primitive2d::BorderLine;
using ::drawinglayer::primitive2d::BorderLineExtend;
using std::pair;
using std::make_pair;
......@@ -519,56 +518,37 @@ lcl_MergeBorderLines(
basegfx::B2DPoint const& rStart,
basegfx::B2DPoint const& rEnd)
{
const BorderLine& rLineLeft = rLine.getBorderLines()[0];
const BorderLine& rOtherLeft(rOther.getBorderLines()[0]);
if (1 == rLine.getBorderLines().size())
{
return new BorderLinePrimitive2D(
rStart,
rEnd,
BorderLine(
rLineLeft.getWidth(),
rLineLeft.getRGBColor(),
BorderLineExtend(
rLineLeft.getBorderLineExtend().getStartLeft(),
rLineLeft.getBorderLineExtend().getStartRight(),
rOtherLeft.getBorderLineExtend().getEndLeft(),
rOtherLeft.getBorderLineExtend().getEndRight())),
rLine.getStyle());
}
else
const std::vector< BorderLine >& rLineLeft(rLine.getBorderLines());
const std::vector< BorderLine >& rOtherLeft(rOther.getBorderLines());
const size_t aSize(std::min(rLineLeft.size(), rOtherLeft.size()));
std::vector< BorderLine > aNew;
for(size_t a(0); a < aSize; a++)
{
const BorderLine& rLineGap(rLine.getBorderLines()[1]);
// const BorderLine& rOtherGap(rOther.getBorderLines()[1]);
const BorderLine& rLineRight(rLine.getBorderLines()[2]);
const BorderLine& rOtherRight(rOther.getBorderLines()[2]);
return new BorderLinePrimitive2D(
rStart,
rEnd,
BorderLine(
rLineLeft.getWidth(),
rLineLeft.getRGBColor(),
BorderLineExtend(
rLineLeft.getBorderLineExtend().getStartLeft(),
rLineLeft.getBorderLineExtend().getStartRight(),
rOtherLeft.getBorderLineExtend().getEndLeft(),
rOtherLeft.getBorderLineExtend().getEndRight())),
BorderLine(
rLineGap.getWidth(),
rLineGap.getRGBColor()),
BorderLine(
rLineRight.getWidth(),
rLineRight.getRGBColor(),
BorderLineExtend(
rLineRight.getBorderLineExtend().getStartLeft(),
rLineRight.getBorderLineExtend().getStartRight(),
rOtherRight.getBorderLineExtend().getEndLeft(),
rOtherRight.getBorderLineExtend().getEndRight())),
rLine.hasGapColor(),
rLine.getStyle());
const BorderLine& la(rLineLeft[a]);
const BorderLine& lb(rOtherLeft[a]);
if(la.isGap() || lb.isGap())
{
aNew.push_back(la);
}
else
{
aNew.push_back(
BorderLine(
la.getLineAttribute(),
la.getStartLeft(),
la.getStartRight(),
lb.getEndLeft(),
lb.getEndRight()));
}
}
return new BorderLinePrimitive2D(
rStart,
rEnd,
aNew,
rLine.getStrokeAttribute());
}
/**
......@@ -601,36 +581,24 @@ lcl_TryMergeBorderLine(BorderLinePrimitive2D const& rThis,
double otherWidth = rOther.getEnd().getX() - rOther.getStart().getX();
// check for same orientation, same line width, same style and matching colors
bool bSameStuff(false);
const BorderLine& rThisLeft(rThis.getBorderLines()[0]);
const BorderLine& rOtherLeft(rOther.getBorderLines()[0]);
bool bSameStuff(
((thisHeight > thisWidth) == (otherHeight > otherWidth))
&& rThis.getStrokeAttribute() == rOther.getStrokeAttribute());
if (1 == rThis.getBorderLines().size())
{
bSameStuff = ((thisHeight > thisWidth) == (otherHeight > otherWidth))
&& (rtl::math::approxEqual(rThisLeft.getWidth(), rOtherLeft.getWidth()))
&& (rThis.getStyle() == rOther.getStyle())
&& (rThisLeft.getRGBColor() == rOtherLeft.getRGBColor());
}
else
if(bSameStuff)
{
const BorderLine& rThisGap(rThis.getBorderLines()[1]);
const BorderLine& rOtherGap(rOther.getBorderLines()[1]);
const BorderLine& rThisRight(rThis.getBorderLines()[2]);
const BorderLine& rOtherRight(rOther.getBorderLines()[2]);
const std::vector< BorderLine >& rLineLeft(rThis.getBorderLines());
const std::vector< BorderLine >& rOtherLeft(rOther.getBorderLines());
const size_t aSize(std::min(rLineLeft.size(), rOtherLeft.size()));
bSameStuff = ((thisHeight > thisWidth) == (otherHeight > otherWidth))
&& (rtl::math::approxEqual(rThisLeft.getWidth(), rOtherLeft.getWidth()))
&& (rtl::math::approxEqual(rThisGap.getWidth(), rOtherGap.getWidth()))
&& (rtl::math::approxEqual(rThisRight.getWidth(), rOtherRight.getWidth()))
&& (rThis.getStyle() == rOther.getStyle())
&& (rThisLeft.getRGBColor() == rOtherLeft.getRGBColor())
&& (rThisRight.getRGBColor() == rOtherRight.getRGBColor())
&& (rThis.hasGapColor() == rOther.hasGapColor())
&& (!rThis.hasGapColor() ||
(rThisGap.getRGBColor() == rOtherGap.getRGBColor()));
}
for(size_t a(0); bSameStuff && a < aSize; a++)
{
const BorderLine& la(rLineLeft[a]);
const BorderLine& lb(rOtherLeft[a]);
bSameStuff = la == lb;
}
}
if (bSameStuff)
{
......@@ -4894,45 +4862,44 @@ static void lcl_MakeBorderLine(SwRect const& rRect,
double const nRightWidth = rBorder.GetInWidth();
Color const aLeftColor = rBorder.GetColorOut(isLeftOrTopBorder);
Color const aRightColor = rBorder.GetColorIn(isLeftOrTopBorder);
const std::vector<double> aDashing(svtools::GetLineDashing(rBorder.GetBorderLineStyle(), 10.0));
const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(aDashing);
std::vector< drawinglayer::primitive2d::BorderLine > aBorderlines;
rtl::Reference<BorderLinePrimitive2D> xLine;
if (basegfx::fTools::equalZero(nRightWidth))
{
xLine = new BorderLinePrimitive2D(
aStart,
aEnd,
BorderLine(
nLeftWidth,
aBorderlines.push_back(
drawinglayer::primitive2d::BorderLine(
drawinglayer::attribute::LineAttribute(
aLeftColor.getBColor(),
BorderLineExtend(
nExtentLeftStart,
nExtentLeftEnd)),
rBorder.GetBorderLineStyle());
}
else
{
xLine = new BorderLinePrimitive2D(
nLeftWidth),
nExtentLeftStart,
nExtentLeftStart,
nExtentLeftEnd,
nExtentLeftEnd));
if (!basegfx::fTools::equalZero(nRightWidth))
{
drawinglayer::primitive2d::BorderLine(
drawinglayer::attribute::LineAttribute(
rBorder.GetColorGap().getBColor(),
rBorder.GetDistance()));
aBorderlines.push_back(
drawinglayer::primitive2d::BorderLine(
drawinglayer::attribute::LineAttribute(
aRightColor.getBColor(),
nRightWidth),
nExtentRightStart,
nExtentRightStart,
nExtentRightEnd,
nExtentRightEnd));
}
rtl::Reference<BorderLinePrimitive2D> xLine(
new BorderLinePrimitive2D(
aStart,
aEnd,
BorderLine(
nLeftWidth,
aLeftColor.getBColor(),
BorderLineExtend(
nExtentLeftStart,
nExtentLeftEnd)),
BorderLine(
rBorder.GetDistance(),
rBorder.GetColorGap().getBColor()),
BorderLine(
nRightWidth,
aRightColor.getBColor(),
BorderLineExtend(
nExtentRightStart,
nExtentRightEnd)),
rBorder.HasGapColor(),
rBorder.GetBorderLineStyle());
}
aBorderlines,
aStrokeAttribute));
properties.pBLines->AddBorderLine(xLine.get(), properties);
}
......
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