Kaydet (Commit) 8f43c78e authored tarafından Armin Le Grand's avatar Armin Le Grand Kaydeden (comit) Caolán McNamara

Resolves: #i120230# Adapt hatch processing for a more pleasant visualisation

Adapt hatch processing to keep a view-dependent minimal distance for a more
pleasant visualisation

(cherry picked from commit 6a036e7a)

Conflicts:
	drawinglayer/inc/drawinglayer/attribute/fillhatchattribute.hxx
	drawinglayer/inc/drawinglayer/primitive2d/fillhatchprimitive2d.hxx
	drawinglayer/inc/drawinglayer/primitive2d/primitivetools2d.hxx
	drawinglayer/source/attribute/fillhatchattribute.cxx

Change-Id: I15cd784ef7d3e47a20308f16d370c24ef46d2f22
üst e1ffd555
......@@ -35,6 +35,7 @@ namespace drawinglayer
double mfDistance;
double mfAngle;
basegfx::BColor maColor;
sal_uInt32 mnMinimalDiscreteDistance;
// bitfield
unsigned mbFillBackground : 1;
......@@ -44,11 +45,13 @@ namespace drawinglayer
double fDistance,
double fAngle,
const basegfx::BColor& rColor,
sal_uInt32 nMinimalDiscreteDistance,
bool bFillBackground)
: meStyle(eStyle),
mfDistance(fDistance),
mfAngle(fAngle),
maColor(rColor),
mnMinimalDiscreteDistance(nMinimalDiscreteDistance),
mbFillBackground(bFillBackground)
{
}
......@@ -58,6 +61,7 @@ namespace drawinglayer
mfDistance(0.0),
mfAngle(0.0),
maColor(basegfx::BColor()),
mnMinimalDiscreteDistance(3), // same as VCL
mbFillBackground(false)
{
}
......@@ -67,6 +71,7 @@ namespace drawinglayer
double getDistance() const { return mfDistance; }
double getAngle() const { return mfAngle; }
const basegfx::BColor& getColor() const { return maColor; }
sal_uInt32 getMinimalDiscreteDistance() const { return mnMinimalDiscreteDistance; }
bool isFillBackground() const { return mbFillBackground; }
bool operator==(const ImpFillHatchAttribute& rCandidate) const
......@@ -75,7 +80,8 @@ namespace drawinglayer
&& getDistance() == rCandidate.getDistance()
&& getAngle() == rCandidate.getAngle()
&& getColor() == rCandidate.getColor()
&& isFillBackground() == rCandidate.isFillBackground());
&& getMinimalDiscreteDistance() == rCandidate.getMinimalDiscreteDistance()
&& isFillBackground() == rCandidate.isFillBackground());
}
};
......@@ -90,9 +96,11 @@ namespace drawinglayer
double fDistance,
double fAngle,
const basegfx::BColor& rColor,
sal_uInt32 nMinimalDiscreteDistance,
bool bFillBackground)
: mpFillHatchAttribute(ImpFillHatchAttribute(
eStyle, fDistance, fAngle, rColor, bFillBackground))
eStyle, fDistance, fAngle, rColor,
nMinimalDiscreteDistance, bFillBackground))
{
}
......@@ -147,6 +155,11 @@ namespace drawinglayer
return mpFillHatchAttribute->getColor();
}
sal_uInt32 FillHatchAttribute::getMinimalDiscreteDistance() const
{
return mpFillHatchAttribute->getMinimalDiscreteDistance();
}
bool FillHatchAttribute::isFillBackground() const
{
return mpFillHatchAttribute->isFillBackground();
......
......@@ -25,6 +25,7 @@
#include <basegfx/tools/canvastools.hxx>
#include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
#include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
#include <drawinglayer/geometry/viewinformation2d.hxx>
//////////////////////////////////////////////////////////////////////////////
......@@ -39,12 +40,26 @@ namespace drawinglayer
Primitive2DSequence FillHatchPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
{
Primitive2DSequence aRetval;
if(!getFillHatch().isDefault())
{
// create hatch
const basegfx::BColor aHatchColor(getFillHatch().getColor());
const double fAngle(getFillHatch().getAngle());
::std::vector< basegfx::B2DHomMatrix > aMatrices;
double fDistance(getFillHatch().getDistance());
const bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
// #i120230# evtl. adapt distance
if(bAdaptDistance)
{
const double fDiscreteDistance(getFillHatch().getDistance() / getDiscreteUnit());
if(fDiscreteDistance < (double)getFillHatch().getMinimalDiscreteDistance())
{
fDistance = (double)getFillHatch().getMinimalDiscreteDistance() * getDiscreteUnit();
}
}
// get hatch transformations
switch(getFillHatch().getStyle())
......@@ -52,7 +67,7 @@ namespace drawinglayer
case attribute::HATCHSTYLE_TRIPLE:
{
// rotated 45 degrees
texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle - F_PI4);
texture::GeoTexSvxHatch aHatch(getObjectRange(), fDistance, fAngle - F_PI4);
aHatch.appendTransformations(aMatrices);
// fall-through by purpose
......@@ -60,7 +75,7 @@ namespace drawinglayer
case attribute::HATCHSTYLE_DOUBLE:
{
// rotated 90 degrees
texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle - F_PI2);
texture::GeoTexSvxHatch aHatch(getObjectRange(), fDistance, fAngle - F_PI2);
aHatch.appendTransformations(aMatrices);
// fall-through by purpose
......@@ -68,7 +83,7 @@ namespace drawinglayer
case attribute::HATCHSTYLE_SINGLE:
{
// angle as given
texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle);
texture::GeoTexSvxHatch aHatch(getObjectRange(), fDistance, fAngle);
aHatch.appendTransformations(aMatrices);
}
}
......@@ -113,7 +128,7 @@ namespace drawinglayer
const basegfx::B2DRange& rObjectRange,
const basegfx::BColor& rBColor,
const attribute::FillHatchAttribute& rFillHatch)
: BufferedDecompositionPrimitive2D(),
: DiscreteMetricDependentPrimitive2D(),
maObjectRange(rObjectRange),
maFillHatch(rFillHatch),
maBColor(rBColor)
......@@ -122,7 +137,7 @@ namespace drawinglayer
bool FillHatchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
{
if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
{
const FillHatchPrimitive2D& rCompare = (FillHatchPrimitive2D&)rPrimitive;
......@@ -140,6 +155,23 @@ namespace drawinglayer
return getObjectRange();
}
Primitive2DSequence FillHatchPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
{
::osl::MutexGuard aGuard( m_aMutex );
bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
if(bAdaptDistance)
{
// behave view-dependent
return DiscreteMetricDependentPrimitive2D::get2DDecomposition(rViewInformation);
}
else
{
// behave view-independent
return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation);
}
}
// provide unique ID
ImplPrimitrive2DIDBlock(FillHatchPrimitive2D, PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D)
......
......@@ -958,6 +958,7 @@ namespace
(double)rHatch.GetDistance(),
(double)rHatch.GetAngle() * F_PI1800,
rHatch.GetColor().getBColor(),
3, // same default as VCL, a minimum of three discrete units (pixels) offset
false);
}
......
......@@ -43,7 +43,7 @@ namespace drawinglayer
if(!getBuffered2DDecomposition().hasElements())
{
// remember new valid DiscreteUnit
const_cast< DiscreteMetricDependentPrimitive2D* >(this)->mfDiscreteUnit = fDiscreteUnit;
const_cast< DiscreteMetricDependentPrimitive2D* >(this)->updateDiscreteUnit(fDiscreteUnit);
}
// call base implementation
......
......@@ -69,6 +69,7 @@ namespace drawinglayer
double fDistance,
double fAngle,
const basegfx::BColor& rColor,
sal_uInt32 nMinimalDiscreteDistance,
bool bFillBackground);
FillHatchAttribute();
FillHatchAttribute(const FillHatchAttribute& rCandidate);
......@@ -86,6 +87,19 @@ namespace drawinglayer
double getDistance() const;
double getAngle() const;
const basegfx::BColor& getColor() const;
// #i120230# If a minimal discrete distance is wanted (VCL used 3,
// this is the default for the global instance, too), set this
// unequal to zero. Zero means not to use it. If set bigger zero
// (should be at least two, one leads to a full plane filled with
// lines when Distance in discrete views is smaller than one) this
// will be used when the discrete value is less than the given one.
// This is used to 'emulate' old VCL behaviour which makes hatches
// look better by not making distances as small as needed, but
// keeping them on a minimal discrete value for more appealing
// visualisation.
sal_uInt32 getMinimalDiscreteDistance() const;
bool isFillBackground() const;
};
} // end of namespace attribute
......
......@@ -23,6 +23,7 @@
#include <drawinglayer/drawinglayerdllapi.h>
#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
#include <drawinglayer/primitive2d/primitivetools2d.hxx>
#include <drawinglayer/attribute/fillhatchattribute.hxx>
#include <basegfx/color/bcolor.hxx>
......@@ -40,9 +41,14 @@ namespace drawinglayer
If the background is to be filled, a flag in FillHatchAttribute is set and
the BColor defines the background color.
#i120230# This primitive is now evtl. metric dependent due to the value
MinimalDiscreteDistance in the FillHatchAttribute if the value is not zero.
This is used for a more appealing, VCL-like visualisation by not letting the
distances get too small between lines.
The decomposition will deliver the hatch lines.
*/
class DRAWINGLAYER_DLLPUBLIC FillHatchPrimitive2D : public BufferedDecompositionPrimitive2D
class DRAWINGLAYER_DLLPUBLIC FillHatchPrimitive2D : public DiscreteMetricDependentPrimitive2D
{
private:
/// the geometric definition
......@@ -76,6 +82,9 @@ namespace drawinglayer
/// get range
virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const;
/// get local decomposition. Overloaded since this decomposition is view-dependent
virtual Primitive2DSequence get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
/// provide unique ID
DeclPrimitrive2DIDBlock()
};
......
......@@ -47,6 +47,13 @@ namespace drawinglayer
*/
double mfDiscreteUnit;
protected:
/// helper to update discrete unit
void updateDiscreteUnit(double fNew)
{
mfDiscreteUnit = fNew;
}
public:
/// constructor
DiscreteMetricDependentPrimitive2D()
......
......@@ -128,6 +128,7 @@ namespace sdr
125.0, // 1.25 mm
45.0 * F_PI180, // 45 degree diagonal
Color(COL_BLACK).getBColor(), // black color
3, // same default as VCL, a minimum of three discrete units (pixels) offset
false); // no filling
const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D(
......
......@@ -230,6 +230,7 @@ namespace drawinglayer
getDiscreteHatchDistance() * getDiscreteUnit(),
getHatchRotation() - getRotation(),
getHatchColor(),
3, // same default as VCL, a minimum of three discrete units (pixels) offset
false);
const Primitive2DReference aPrimitive(
new PolyPolygonHatchPrimitive2D(
......
......@@ -453,6 +453,7 @@ namespace drawinglayer
(double)rHatch.GetDistance(),
(double)rHatch.GetAngle() * F_PI1800,
aColorB.getBColor(),
3, // same default as VCL, a minimum of three discrete units (pixels) offset
((const XFillBackgroundItem&)(rSet.Get(XATTR_FILLBACKGROUND))).GetValue());
break;
......
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