1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/sdr/primitive2d/sdrframeborderprimitive2d.hxx>
21 #include <drawinglayer/primitive2d/borderlineprimitive2d.hxx>
22 #include <drawinglayer/geometry/viewinformation2d.hxx>
23 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
24 #include <basegfx/polygon/b2dpolygontools.hxx>
25 #include <svtools/borderhelper.hxx>
29 double snapToDiscreteUnit(
31 double fMinimalDiscreteUnit
)
35 fValue
= std::max(fValue
, fMinimalDiscreteUnit
);
41 class StyleVectorCombination
44 struct OffsetAndHalfWidthAndColor
50 OffsetAndHalfWidthAndColor(double offset
, double halfWidth
, Color color
) :
52 mfHalfWidth(halfWidth
),
57 double mfRefModeOffset
;
58 basegfx::B2DVector maB2DVector
;
60 std::vector
< OffsetAndHalfWidthAndColor
> maOffsets
;
63 StyleVectorCombination(
64 const svx::frame::Style
& rStyle
,
65 const basegfx::B2DVector
& rB2DVector
,
68 const Color
* pForceColor
,
69 double fMinimalDiscreteUnit
)
70 : mfRefModeOffset(0.0),
71 maB2DVector(rB2DVector
),
77 svx::frame::RefMode
aRefMode(rStyle
.GetRefMode());
78 Color
aPrim(rStyle
.GetColorPrim());
79 Color
aSecn(rStyle
.GetColorSecn());
80 const bool bSecnUsed(0.0 != rStyle
.Secn());
82 // Get the single segment line widths. This is the point where the
83 // minimal discrete unit will be used if given (fMinimalDiscreteUnit). If
84 // not given it's 0.0 and thus will have no influence.
85 double fPrim(snapToDiscreteUnit(rStyle
.Prim(), fMinimalDiscreteUnit
));
86 const double fDist(snapToDiscreteUnit(rStyle
.Dist(), fMinimalDiscreteUnit
));
87 double fSecn(snapToDiscreteUnit(rStyle
.Secn(), fMinimalDiscreteUnit
));
89 // Of course also do not use svx::frame::Style::GetWidth() for obvious
91 const double fStyleWidth(fPrim
+ fDist
+ fSecn
);
97 case svx::frame::RefMode::Begin
: aRefMode
= svx::frame::RefMode::End
; break;
98 case svx::frame::RefMode::End
: aRefMode
= svx::frame::RefMode::Begin
; break;
104 std::swap(aPrim
, aSecn
);
105 std::swap(fPrim
, fSecn
);
109 if (svx::frame::RefMode::Centered
!= aRefMode
)
111 const double fHalfWidth(fStyleWidth
* 0.5);
113 if (svx::frame::RefMode::Begin
== aRefMode
)
115 // move aligned below vector
116 mfRefModeOffset
= fHalfWidth
;
118 else if (svx::frame::RefMode::End
== aRefMode
)
120 // move aligned above vector
121 mfRefModeOffset
= -fHalfWidth
;
127 // both or all three lines used
128 const bool bPrimTransparent(rStyle
.GetColorPrim().IsFullyTransparent());
129 const bool bDistTransparent(!rStyle
.UseGapColor() || rStyle
.GetColorGap().IsFullyTransparent());
130 const bool bSecnTransparent(aSecn
.IsFullyTransparent());
132 if(!bPrimTransparent
|| !bDistTransparent
|| !bSecnTransparent
)
134 const double a(mfRefModeOffset
- (fStyleWidth
* 0.5));
135 const double b(a
+ fPrim
);
136 const double c(b
+ fDist
);
137 const double d(c
+ fSecn
);
140 OffsetAndHalfWidthAndColor(
143 nullptr != pForceColor
? *pForceColor
: aPrim
));
146 OffsetAndHalfWidthAndColor(
150 ? (nullptr != pForceColor
? *pForceColor
: rStyle
.GetColorGap())
154 OffsetAndHalfWidthAndColor(
157 nullptr != pForceColor
? *pForceColor
: aSecn
));
162 // one line used, push two values, from outer to inner
163 if(!rStyle
.GetColorPrim().IsFullyTransparent())
166 OffsetAndHalfWidthAndColor(
169 nullptr != pForceColor
? *pForceColor
: aPrim
));
174 double getRefModeOffset() const { return mfRefModeOffset
; }
175 const basegfx::B2DVector
& getB2DVector() const { return maB2DVector
; }
176 double getAngle() const { return mfAngle
; }
177 bool empty() const { return maOffsets
.empty(); }
178 size_t size() const { return maOffsets
.size(); }
180 void getColorAndOffsetAndHalfWidth(size_t nIndex
, Color
& rColor
, double& rfOffset
, double& rfHalfWidth
) const
182 if(nIndex
>= maOffsets
.size())
184 const OffsetAndHalfWidthAndColor
& rCandidate(maOffsets
[nIndex
]);
185 rfOffset
= rCandidate
.mfOffset
;
186 rfHalfWidth
= rCandidate
.mfHalfWidth
;
187 rColor
= rCandidate
.maColor
;
191 class StyleVectorTable
194 std::vector
< StyleVectorCombination
> maEntries
;
202 const svx::frame::Style
& rStyle
,
203 const basegfx::B2DVector
& rMyVector
,
204 const basegfx::B2DVector
& rOtherVector
,
206 double fMinimalDiscreteUnit
)
208 if(!rStyle
.IsUsed() || basegfx::areParallel(rMyVector
, rOtherVector
))
211 // create angle between both. angle() needs vectors pointing away from the same point,
212 // so take the mirrored one. Add M_PI to get from -pi..+pi to [0..M_PI_2] for sorting
213 const double fAngle(basegfx::B2DVector(-rMyVector
.getX(), -rMyVector
.getY()).angle(rOtherVector
) + M_PI
);
214 maEntries
.emplace_back(
220 fMinimalDiscreteUnit
);
225 // sort inverse from highest to lowest
229 [](const StyleVectorCombination
& a
, const StyleVectorCombination
& b
)
230 { return a
.getAngle() > b
.getAngle(); });
233 bool empty() const { return maEntries
.empty(); }
234 const std::vector
< StyleVectorCombination
>& getEntries() const{ return maEntries
; }
244 CutSet() : mfOLML(0.0), mfORML(0.0), mfOLMR(0.0), mfORMR(0.0)
248 bool operator<( const CutSet
& rOther
) const
250 const double fA(mfOLML
+ mfORML
+ mfOLMR
+ mfORMR
);
251 const double fB(rOther
.mfOLML
+ rOther
.mfORML
+ rOther
.mfOLMR
+ rOther
.mfORMR
);
256 double getSum() const { return mfOLML
+ mfORML
+ mfOLMR
+ mfORMR
; }
261 const basegfx::B2DPoint
& rLeft
,
262 const basegfx::B2DPoint
& rRight
,
263 const basegfx::B2DVector
& rX
,
264 const basegfx::B2DPoint
& rOtherLeft
,
265 const basegfx::B2DPoint
& rOtherRight
,
266 const basegfx::B2DVector
& rOtherX
)
268 basegfx::utils::findCut(
276 basegfx::utils::findCut(
284 basegfx::utils::findCut(
292 basegfx::utils::findCut(
306 ExtendSet() : mfExtLeft(0.0), mfExtRight(0.0) {}
310 std::vector
<ExtendSet
>& rExtendSet
, // target Left/Right values to fill
311 const basegfx::B2DPoint
& rOrigin
, // own vector start
312 const StyleVectorCombination
& rCombination
, // own vector and offsets for lines
313 const basegfx::B2DVector
& rPerpendX
, // normalized perpendicular to own vector
314 const std::vector
< StyleVectorCombination
>& rStyleVector
) // other vectors emerging in this point
316 if(!(!rCombination
.empty() && !rStyleVector
.empty() && rCombination
.size() == rExtendSet
.size()))
319 const size_t nOffsetA(rCombination
.size());
323 Color aMyColor
; double fMyOffset(0.0); double fMyHalfWidth(0.0);
324 rCombination
.getColorAndOffsetAndHalfWidth(0, aMyColor
, fMyOffset
, fMyHalfWidth
);
326 if(!aMyColor
.IsFullyTransparent())
328 const basegfx::B2DPoint
aLeft(rOrigin
+ (rPerpendX
* (fMyOffset
- fMyHalfWidth
)));
329 const basegfx::B2DPoint
aRight(rOrigin
+ (rPerpendX
* (fMyOffset
+ fMyHalfWidth
)));
330 std::vector
< CutSet
> aCutSets
;
332 for(const auto& rStyleCandidate
: rStyleVector
)
334 const basegfx::B2DVector
aOtherPerpend(basegfx::getNormalizedPerpendicular(rStyleCandidate
.getB2DVector()));
335 const size_t nOffsetB(rStyleCandidate
.size());
337 for(size_t other(0); other
< nOffsetB
; other
++)
339 Color aOtherColor
; double fOtherOffset(0.0); double fOtherHalfWidth(0.0);
340 rStyleCandidate
.getColorAndOffsetAndHalfWidth(other
, aOtherColor
, fOtherOffset
, fOtherHalfWidth
);
342 if(!aOtherColor
.IsFullyTransparent())
344 const basegfx::B2DPoint
aOtherLeft(rOrigin
+ (aOtherPerpend
* (fOtherOffset
- fOtherHalfWidth
)));
345 const basegfx::B2DPoint
aOtherRight(rOrigin
+ (aOtherPerpend
* (fOtherOffset
+ fOtherHalfWidth
)));
348 getCutSet(aNewCutSet
, aLeft
, aRight
, rCombination
.getB2DVector(), aOtherLeft
, aOtherRight
, rStyleCandidate
.getB2DVector());
349 aCutSets
.push_back(aNewCutSet
);
354 if(!aCutSets
.empty())
356 CutSet
aCutSet(aCutSets
[0]);
357 const size_t nNumCutSets(aCutSets
.size());
361 double fCutSet(aCutSet
.getSum());
363 for(size_t a(1); a
< nNumCutSets
; a
++)
365 const CutSet
& rCandidate(aCutSets
[a
]);
366 const double fCandidate(rCandidate
.getSum());
368 if(basegfx::fTools::equalZero(fCandidate
- fCutSet
))
370 // both have equal center point, use medium cut
371 const double fNewOLML(std::max(std::min(rCandidate
.mfOLML
, rCandidate
.mfORML
), std::min(aCutSet
.mfOLML
, aCutSet
.mfORML
)));
372 const double fNewORML(std::min(std::max(rCandidate
.mfOLML
, rCandidate
.mfORML
), std::max(aCutSet
.mfOLML
, aCutSet
.mfORML
)));
373 const double fNewOLMR(std::max(std::min(rCandidate
.mfOLMR
, rCandidate
.mfORMR
), std::min(aCutSet
.mfOLMR
, aCutSet
.mfORMR
)));
374 const double fNewORMR(std::min(std::max(rCandidate
.mfOLMR
, rCandidate
.mfORMR
), std::max(aCutSet
.mfOLMR
, aCutSet
.mfORMR
)));
375 aCutSet
.mfOLML
= fNewOLML
;
376 aCutSet
.mfORML
= fNewORML
;
377 aCutSet
.mfOLMR
= fNewOLMR
;
378 aCutSet
.mfORMR
= fNewORMR
;
379 fCutSet
= aCutSet
.getSum();
381 else if(fCandidate
< fCutSet
)
384 fCutSet
= fCandidate
;
385 aCutSet
= rCandidate
;
390 ExtendSet
& rExt(rExtendSet
[0]);
392 rExt
.mfExtLeft
= std::min(aCutSet
.mfOLML
, aCutSet
.mfORML
);
393 rExt
.mfExtRight
= std::min(aCutSet
.mfOLMR
, aCutSet
.mfORMR
);
399 size_t nVisEdgeUp(0);
400 size_t nVisEdgeDn(0);
402 for(size_t my(0); my
< nOffsetA
; my
++)
404 Color aMyColor
; double fMyOffset(0.0); double fMyHalfWidth(0.0);
405 rCombination
.getColorAndOffsetAndHalfWidth(my
, aMyColor
, fMyOffset
, fMyHalfWidth
);
407 if(!aMyColor
.IsFullyTransparent())
409 const basegfx::B2DPoint
aLeft(rOrigin
+ (rPerpendX
* (fMyOffset
- fMyHalfWidth
)));
410 const basegfx::B2DPoint
aRight(rOrigin
+ (rPerpendX
* (fMyOffset
+ fMyHalfWidth
)));
411 const bool bUpper(my
<= (nOffsetA
>> 1));
412 const StyleVectorCombination
& rStyleCandidate(bUpper
? rStyleVector
.front() : rStyleVector
.back());
413 const basegfx::B2DVector
aOtherPerpend(basegfx::getNormalizedPerpendicular(rStyleCandidate
.getB2DVector()));
414 const size_t nOffsetB(rStyleCandidate
.size());
415 std::vector
< CutSet
> aCutSets
;
417 for(size_t other(0); other
< nOffsetB
; other
++)
419 Color aOtherColor
; double fOtherOffset(0.0); double fOtherHalfWidth(0.0);
420 rStyleCandidate
.getColorAndOffsetAndHalfWidth(other
, aOtherColor
, fOtherOffset
, fOtherHalfWidth
);
422 if(!aOtherColor
.IsFullyTransparent())
424 const basegfx::B2DPoint
aOtherLeft(rOrigin
+ (aOtherPerpend
* (fOtherOffset
- fOtherHalfWidth
)));
425 const basegfx::B2DPoint
aOtherRight(rOrigin
+ (aOtherPerpend
* (fOtherOffset
+ fOtherHalfWidth
)));
427 getCutSet(aCutSet
, aLeft
, aRight
, rCombination
.getB2DVector(), aOtherLeft
, aOtherRight
, rStyleCandidate
.getB2DVector());
428 aCutSets
.push_back(aCutSet
);
432 if(!aCutSets
.empty())
434 // sort: min to start, max to end
435 std::sort(aCutSets
.begin(), aCutSets
.end());
436 const bool bOtherUpper(rStyleCandidate
.getAngle() > M_PI
);
438 // check if we need min or max
439 // bUpper bOtherUpper MinMax
444 const bool bMax(bUpper
== bOtherUpper
);
445 size_t nBaseIndex(0);
446 const size_t nNumCutSets(aCutSets
.size());
451 nBaseIndex
= nNumCutSets
- 1 - (bUpper
? nVisEdgeUp
: nVisEdgeDn
);
456 nBaseIndex
= bUpper
? nVisEdgeUp
: nVisEdgeDn
;
459 const size_t nSecuredIndex(std::clamp(nBaseIndex
, size_t(0), size_t(nNumCutSets
- 1)));
460 const CutSet
& rCutSet(aCutSets
[nSecuredIndex
]);
461 ExtendSet
& rExt(rExtendSet
[my
]);
463 rExt
.mfExtLeft
= std::min(rCutSet
.mfOLML
, rCutSet
.mfORML
);
464 rExt
.mfExtRight
= std::min(rCutSet
.mfOLMR
, rCutSet
.mfORMR
);
481 * Helper method to create the correct drawinglayer::primitive2d::BorderLinePrimitive2D
482 * for the given data, especially the correct drawinglayer::primitive2d::BorderLine entries
483 * including the correctly solved/created LineStartEnd extends
485 * rTarget : Here the evtl. created BorderLinePrimitive2D will be appended
486 * rOrigin : StartPoint of the Borderline
487 * rX : Vector of the Borderline
488 * rBorder : svx::frame::Style of the of the Borderline
489 * rStartStyleVectorTable : All other Borderlines which have to be taken into account because
490 * they have the same StartPoint as the current Borderline. These will be used to calculate
491 * the correct LineStartEnd extends tor the BorderLinePrimitive2D. The definition should be
492 * built up using svx::frame::StyleVectorTable and StyleVectorTable::add and includes:
493 * rStyle : the svx::frame::Style of one other BorderLine
494 * rMyVector : the Vector of the *new* to-be-defined BorderLine, identical to rX
495 * rOtherVector: the Vector of one other BorderLine (may be, but does not need to be normalized),
496 * always *pointing away* from the common StartPoint rOrigin
497 * bMirrored : define if rStyle of one other BorderLine shall be mirrored (e.g. bottom-right edges)
498 * With multiple BorderLines the definitions have to be CounterClockWise. This will be
499 * ensured by StyleVectorTable sorting the entries, but knowing this may allow more efficient
501 * rEndStyleVectorTable: All other BorderLines that have the same EndPoint. There are differences to
502 * the Start definitions:
503 * - do not forget to consequently use -rX for rMyVector
504 * - definitions have to be ClockWise for the EndBorderLines, will be ensured by sorting
506 * If you take all this into account, you will get correctly extended BorderLinePrimitive2D
507 * representations for the new to be defined BorderLine. That extensions will overlap nicely
508 * with the corresponding BorderLines and take all multiple line definitions in the ::Style into
510 * The internal solver is *not limited* to ::Style(s) with three parts (Left/Gap/Right), this is
511 * just due to svx::frame::Style's definitions. A new solver based on this one can be created
512 * anytime using more mulötiple borders based on the more flexible
513 * std::vector< drawinglayer::primitive2d::BorderLine > if needed.
515 void CreateBorderPrimitives(
516 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
, /// target for created primitives
517 const basegfx::B2DPoint
& rOrigin
, /// start point of borderline
518 const basegfx::B2DVector
& rX
, /// X-Axis of borderline with length
519 const svx::frame::Style
& rBorder
, /// Style of borderline
520 const StyleVectorTable
& rStartStyleVectorTable
, /// Styles and vectors (pointing away) at borderline start, ccw
521 const StyleVectorTable
& rEndStyleVectorTable
, /// Styles and vectors (pointing away) at borderline end, cw
522 const Color
* pForceColor
, /// If specified, overrides frame border color.
523 double fMinimalDiscreteUnit
) /// minimal discrete unit to use for svx::frame::Style width values
525 // get offset color pairs for style, one per visible line
526 const StyleVectorCombination
aCombination(
532 fMinimalDiscreteUnit
);
534 if(aCombination
.empty())
537 const basegfx::B2DVector
aPerpendX(basegfx::getNormalizedPerpendicular(rX
));
538 const bool bHasStartStyles(!rStartStyleVectorTable
.empty());
539 const bool bHasEndStyles(!rEndStyleVectorTable
.empty());
540 const size_t nOffsets(aCombination
.size());
541 std::vector
<ExtendSet
> aExtendSetStart(nOffsets
);
542 std::vector
<ExtendSet
> aExtendSetEnd(nOffsets
);
546 // create extends for line starts, use given point/vector and offsets
547 getExtends(aExtendSetStart
, rOrigin
, aCombination
, aPerpendX
, rStartStyleVectorTable
.getEntries());
552 // Create extends for line ends, create inverse point/vector and inverse offsets.
553 const StyleVectorCombination
aMirroredCombination(
559 fMinimalDiscreteUnit
);
561 getExtends(aExtendSetEnd
, rOrigin
+ rX
, aMirroredCombination
, -aPerpendX
, rEndStyleVectorTable
.getEntries());
563 // also need to inverse the result to apply to the correct lines
564 std::reverse(aExtendSetEnd
.begin(), aExtendSetEnd
.end());
567 std::vector
< drawinglayer::primitive2d::BorderLine
> aBorderlines
;
568 const double fNegLength(-rX
.getLength());
570 for(size_t a(0); a
< nOffsets
; a
++)
573 double fMyOffset(0.0);
574 double fMyHalfWidth(0.0);
575 aCombination
.getColorAndOffsetAndHalfWidth(a
, aMyColor
, fMyOffset
, fMyHalfWidth
);
576 const ExtendSet
& rExtStart(aExtendSetStart
[a
]);
577 const ExtendSet
& rExtEnd(aExtendSetEnd
[a
]);
579 if(aMyColor
.IsFullyTransparent())
581 aBorderlines
.push_back(
582 drawinglayer::primitive2d::BorderLine(
583 fMyHalfWidth
* 2.0));
587 aBorderlines
.push_back(
588 drawinglayer::primitive2d::BorderLine(
589 drawinglayer::attribute::LineAttribute(
590 aMyColor
.getBColor(),
592 fNegLength
* rExtStart
.mfExtLeft
,
593 fNegLength
* rExtStart
.mfExtRight
,
594 fNegLength
* rExtEnd
.mfExtRight
,
595 fNegLength
* rExtEnd
.mfExtLeft
));
599 static const double fPatScFact(10.0); // 10.0 multiply, see old code
600 std::vector
<double> aDashing(svtools::GetLineDashing(rBorder
.Type(), rBorder
.PatternScale() * fPatScFact
));
601 drawinglayer::attribute::StrokeAttribute
aStrokeAttribute(std::move(aDashing
));
602 const basegfx::B2DPoint
aStart(rOrigin
+ (aPerpendX
* aCombination
.getRefModeOffset()));
605 drawinglayer::primitive2d::Primitive2DReference(
606 new drawinglayer::primitive2d::BorderLinePrimitive2D(
609 std::move(aBorderlines
),
610 std::move(aStrokeAttribute
))));
613 double getMinimalNonZeroValue(double fCurrent
, double fNew
)
619 fCurrent
= std::min(fNew
, fCurrent
);
630 double getMinimalNonZeroBorderWidthFromStyle(double fCurrent
, const svx::frame::Style
& rStyle
)
634 fCurrent
= getMinimalNonZeroValue(fCurrent
, rStyle
.Prim());
635 fCurrent
= getMinimalNonZeroValue(fCurrent
, rStyle
.Dist());
636 fCurrent
= getMinimalNonZeroValue(fCurrent
, rStyle
.Secn());
643 namespace drawinglayer::primitive2d
645 SdrFrameBorderData::SdrConnectStyleData::SdrConnectStyleData(
646 const svx::frame::Style
& rStyle
,
647 const basegfx::B2DVector
& rNormalizedPerpendicular
,
650 maNormalizedPerpendicular(rNormalizedPerpendicular
),
651 mbStyleMirrored(bStyleMirrored
)
655 bool SdrFrameBorderData::SdrConnectStyleData::operator==(const SdrFrameBorderData::SdrConnectStyleData
& rCompare
) const
657 return mbStyleMirrored
== rCompare
.mbStyleMirrored
658 && maStyle
== rCompare
.maStyle
659 && maNormalizedPerpendicular
== rCompare
.maNormalizedPerpendicular
;
662 SdrFrameBorderData::SdrFrameBorderData(
663 const basegfx::B2DPoint
& rOrigin
,
664 const basegfx::B2DVector
& rX
,
665 const svx::frame::Style
& rStyle
,
666 const Color
* pForceColor
)
670 maColor(nullptr != pForceColor
? *pForceColor
: Color()),
671 mbForceColor(nullptr != pForceColor
)
675 void SdrFrameBorderData::addSdrConnectStyleData(
677 const svx::frame::Style
& rStyle
,
678 const basegfx::B2DVector
& rNormalizedPerpendicular
,
685 maStart
.emplace_back(rStyle
, rNormalizedPerpendicular
, bStyleMirrored
);
689 maEnd
.emplace_back(rStyle
, rNormalizedPerpendicular
, bStyleMirrored
);
694 void SdrFrameBorderData::create2DDecomposition(
695 Primitive2DContainer
& rContainer
,
696 double fMinimalDiscreteUnit
) const
698 StyleVectorTable aStartVector
;
699 StyleVectorTable aEndVector
;
700 const basegfx::B2DVector
aAxis(-maX
);
702 for(const auto& rStart
: maStart
)
707 rStart
.getNormalizedPerpendicular(),
708 rStart
.getStyleMirrored(),
709 fMinimalDiscreteUnit
);
712 for(const auto& rEnd
: maEnd
)
717 rEnd
.getNormalizedPerpendicular(),
718 rEnd
.getStyleMirrored(),
719 fMinimalDiscreteUnit
);
725 CreateBorderPrimitives(
732 mbForceColor
? &maColor
: nullptr,
733 fMinimalDiscreteUnit
);
736 double SdrFrameBorderData::getMinimalNonZeroBorderWidth() const
738 double fRetval(getMinimalNonZeroBorderWidthFromStyle(0.0, maStyle
));
740 for(const auto& rStart
: maStart
)
742 fRetval
= getMinimalNonZeroBorderWidthFromStyle(fRetval
, rStart
.getStyle());
745 for(const auto& rEnd
: maEnd
)
747 fRetval
= getMinimalNonZeroBorderWidthFromStyle(fRetval
, rEnd
.getStyle());
754 bool SdrFrameBorderData::operator==(const SdrFrameBorderData
& rCompare
) const
756 return maOrigin
== rCompare
.maOrigin
757 && maX
== rCompare
.maX
758 && maStyle
== rCompare
.maStyle
759 && maColor
== rCompare
.maColor
760 && mbForceColor
== rCompare
.mbForceColor
761 && maStart
== rCompare
.maStart
762 && maEnd
== rCompare
.maEnd
;
766 void SdrFrameBorderPrimitive2D::create2DDecomposition(
767 Primitive2DContainer
& rContainer
,
768 const geometry::ViewInformation2D
& /*aViewInformation*/) const
770 if(getFrameBorders().empty())
775 Primitive2DContainer aRetval
;
777 // Check and use the minimal non-zero BorderWidth for decompose
778 // if that is set and wanted
779 const double fMinimalDiscreteUnit(doForceToSingleDiscreteUnit()
780 ? mfMinimalNonZeroBorderWidthUsedForDecompose
784 // decompose all buffered SdrFrameBorderData entries and try to merge them
785 // to reduce existing number of BorderLinePrimitive2D(s)
786 for(const auto& rCandidate
: getFrameBorders())
788 // get decomposition on one SdrFrameBorderData entry
789 Primitive2DContainer aPartial
;
790 rCandidate
.create2DDecomposition(
792 fMinimalDiscreteUnit
);
794 for(const auto& aCandidatePartial
: aPartial
)
798 // no local data yet, just add as 1st entry, done
799 aRetval
.append(aCandidatePartial
);
803 bool bDidMerge(false);
805 for(auto& aCandidateRetval
: aRetval
)
807 // try to merge by appending new data to existing data
808 const drawinglayer::primitive2d::Primitive2DReference
aMergeRetvalPartial(
809 drawinglayer::primitive2d::tryMergeBorderLinePrimitive2D(
810 static_cast<BorderLinePrimitive2D
*>(aCandidateRetval
.get()),
811 static_cast<BorderLinePrimitive2D
*>(aCandidatePartial
.get())));
813 if(aMergeRetvalPartial
.is())
815 // could append, replace existing data with merged data, done
816 aCandidateRetval
= aMergeRetvalPartial
;
821 // try to merge by appending existing data to new data
822 const drawinglayer::primitive2d::Primitive2DReference
aMergePartialRetval(
823 drawinglayer::primitive2d::tryMergeBorderLinePrimitive2D(
824 static_cast<BorderLinePrimitive2D
*>(aCandidatePartial
.get()),
825 static_cast<BorderLinePrimitive2D
*>(aCandidateRetval
.get())));
827 if(aMergePartialRetval
.is())
829 // could append, replace existing data with merged data, done
830 aCandidateRetval
= aMergePartialRetval
;
838 // no merge after checking all existing data, append as new segment
839 aRetval
.append(aCandidatePartial
);
846 rContainer
.append(std::move(aRetval
));
849 SdrFrameBorderPrimitive2D::SdrFrameBorderPrimitive2D(
850 SdrFrameBorderDataVector
&& rFrameBorders
,
851 bool bForceToSingleDiscreteUnit
)
852 : maFrameBorders(std::move(rFrameBorders
)),
853 mfMinimalNonZeroBorderWidth(0.0),
854 mfMinimalNonZeroBorderWidthUsedForDecompose(0.0),
855 mbForceToSingleDiscreteUnit(bForceToSingleDiscreteUnit
)
857 if(!getFrameBorders().empty() && doForceToSingleDiscreteUnit())
859 // detect used minimal non-zero partial border width
860 for(const auto& rCandidate
: getFrameBorders())
862 mfMinimalNonZeroBorderWidth
= getMinimalNonZeroValue(
863 mfMinimalNonZeroBorderWidth
,
864 rCandidate
.getMinimalNonZeroBorderWidth());
869 bool SdrFrameBorderPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
871 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
873 const SdrFrameBorderPrimitive2D
& rCompare
= static_cast<const SdrFrameBorderPrimitive2D
&>(rPrimitive
);
875 return getFrameBorders() == rCompare
.getFrameBorders()
876 && doForceToSingleDiscreteUnit() == rCompare
.doForceToSingleDiscreteUnit();
882 void SdrFrameBorderPrimitive2D::get2DDecomposition(
883 Primitive2DDecompositionVisitor
& rVisitor
,
884 const geometry::ViewInformation2D
& rViewInformation
) const
886 if(doForceToSingleDiscreteUnit())
888 // Get the current DiscreteUnit, look at X and Y and use the maximum
889 const basegfx::B2DVector
aDiscreteVector(rViewInformation
.getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 1.0));
890 double fDiscreteUnit(std::min(fabs(aDiscreteVector
.getX()), fabs(aDiscreteVector
.getY())));
892 if(fDiscreteUnit
<= mfMinimalNonZeroBorderWidth
)
894 // no need to use it, reset
898 if(fDiscreteUnit
!= mfMinimalNonZeroBorderWidthUsedForDecompose
)
900 // conditions of last local decomposition have changed, delete
902 if(!getBuffered2DDecomposition().empty())
904 const_cast< SdrFrameBorderPrimitive2D
* >(this)->setBuffered2DDecomposition(Primitive2DContainer());
907 // remember new conditions
908 const_cast< SdrFrameBorderPrimitive2D
* >(this)->mfMinimalNonZeroBorderWidthUsedForDecompose
= fDiscreteUnit
;
912 // call parent. This will call back ::create2DDecomposition above
913 // where mfMinimalNonZeroBorderWidthUsedForDecompose will be used
914 // when doForceToSingleDiscreteUnit() is true
915 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor
, rViewInformation
);
919 sal_uInt32
SdrFrameBorderPrimitive2D::getPrimitive2DID() const
921 return PRIMITIVE2D_ID_SDRFRAMEBORDERTPRIMITIVE2D
;
924 } // end of namespace
926 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */