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/primitive2d/groupprimitive2d.hxx>
23 #include <drawinglayer/geometry/viewinformation2d.hxx>
24 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
25 #include <basegfx/polygon/b2dpolygontools.hxx>
26 #include <svtools/borderhelper.hxx>
30 double snapToDiscreteUnit(
32 double fMinimalDiscreteUnit
)
36 fValue
= std::max(fValue
, fMinimalDiscreteUnit
);
42 class StyleVectorCombination
45 struct OffsetAndHalfWidthAndColor
51 OffsetAndHalfWidthAndColor(double offset
, double halfWidth
, Color color
) :
53 mfHalfWidth(halfWidth
),
58 double mfRefModeOffset
;
59 basegfx::B2DVector maB2DVector
;
61 std::vector
< OffsetAndHalfWidthAndColor
> maOffsets
;
64 StyleVectorCombination(
65 const svx::frame::Style
& rStyle
,
66 const basegfx::B2DVector
& rB2DVector
,
69 const Color
* pForceColor
,
70 double fMinimalDiscreteUnit
)
71 : mfRefModeOffset(0.0),
72 maB2DVector(rB2DVector
),
78 svx::frame::RefMode
aRefMode(rStyle
.GetRefMode());
79 Color
aPrim(rStyle
.GetColorPrim());
80 Color
aSecn(rStyle
.GetColorSecn());
81 const bool bSecnUsed(0.0 != rStyle
.Secn());
83 // Get the single segment line widths. This is the point where the
84 // minimal discrete unit will be used if given (fMinimalDiscreteUnit). If
85 // not given it's 0.0 and thus will have no influence.
86 double fPrim(snapToDiscreteUnit(rStyle
.Prim(), fMinimalDiscreteUnit
));
87 const double fDist(snapToDiscreteUnit(rStyle
.Dist(), fMinimalDiscreteUnit
));
88 double fSecn(snapToDiscreteUnit(rStyle
.Secn(), fMinimalDiscreteUnit
));
90 // Of course also do not use svx::frame::Style::GetWidth() for obvious
92 const double fStyleWidth(fPrim
+ fDist
+ fSecn
);
98 case svx::frame::RefMode::Begin
: aRefMode
= svx::frame::RefMode::End
; break;
99 case svx::frame::RefMode::End
: aRefMode
= svx::frame::RefMode::Begin
; break;
105 std::swap(aPrim
, aSecn
);
106 std::swap(fPrim
, fSecn
);
110 if (svx::frame::RefMode::Centered
!= aRefMode
)
112 const double fHalfWidth(fStyleWidth
* 0.5);
114 if (svx::frame::RefMode::Begin
== aRefMode
)
116 // move aligned below vector
117 mfRefModeOffset
= fHalfWidth
;
119 else if (svx::frame::RefMode::End
== aRefMode
)
121 // move aligned above vector
122 mfRefModeOffset
= -fHalfWidth
;
128 // both or all three lines used
129 const bool bPrimTransparent(rStyle
.GetColorPrim().IsFullyTransparent());
130 const bool bDistTransparent(!rStyle
.UseGapColor() || rStyle
.GetColorGap().IsFullyTransparent());
131 const bool bSecnTransparent(aSecn
.IsFullyTransparent());
133 if(!bPrimTransparent
|| !bDistTransparent
|| !bSecnTransparent
)
135 const double a(mfRefModeOffset
- (fStyleWidth
* 0.5));
136 const double b(a
+ fPrim
);
137 const double c(b
+ fDist
);
138 const double d(c
+ fSecn
);
141 OffsetAndHalfWidthAndColor(
144 nullptr != pForceColor
? *pForceColor
: aPrim
));
147 OffsetAndHalfWidthAndColor(
151 ? (nullptr != pForceColor
? *pForceColor
: rStyle
.GetColorGap())
155 OffsetAndHalfWidthAndColor(
158 nullptr != pForceColor
? *pForceColor
: aSecn
));
163 // one line used, push two values, from outer to inner
164 if(!rStyle
.GetColorPrim().IsFullyTransparent())
167 OffsetAndHalfWidthAndColor(
170 nullptr != pForceColor
? *pForceColor
: aPrim
));
175 double getRefModeOffset() const { return mfRefModeOffset
; }
176 const basegfx::B2DVector
& getB2DVector() const { return maB2DVector
; }
177 double getAngle() const { return mfAngle
; }
178 bool empty() const { return maOffsets
.empty(); }
179 size_t size() const { return maOffsets
.size(); }
181 void getColorAndOffsetAndHalfWidth(size_t nIndex
, Color
& rColor
, double& rfOffset
, double& rfHalfWidth
) const
183 if(nIndex
>= maOffsets
.size())
185 const OffsetAndHalfWidthAndColor
& rCandidate(maOffsets
[nIndex
]);
186 rfOffset
= rCandidate
.mfOffset
;
187 rfHalfWidth
= rCandidate
.mfHalfWidth
;
188 rColor
= rCandidate
.maColor
;
192 class StyleVectorTable
195 std::vector
< StyleVectorCombination
> maEntries
;
203 const svx::frame::Style
& rStyle
,
204 const basegfx::B2DVector
& rMyVector
,
205 const basegfx::B2DVector
& rOtherVector
,
207 double fMinimalDiscreteUnit
)
209 if(!rStyle
.IsUsed() || basegfx::areParallel(rMyVector
, rOtherVector
))
212 // create angle between both. angle() needs vectors pointing away from the same point,
213 // so take the mirrored one. Add M_PI to get from -pi..+pi to [0..M_PI_2] for sorting
214 const double fAngle(basegfx::B2DVector(-rMyVector
.getX(), -rMyVector
.getY()).angle(rOtherVector
) + M_PI
);
215 maEntries
.emplace_back(
221 fMinimalDiscreteUnit
);
226 // sort inverse from highest to lowest
230 [](const StyleVectorCombination
& a
, const StyleVectorCombination
& b
)
231 { return a
.getAngle() > b
.getAngle(); });
234 bool empty() const { return maEntries
.empty(); }
235 const std::vector
< StyleVectorCombination
>& getEntries() const{ return maEntries
; }
245 CutSet() : mfOLML(0.0), mfORML(0.0), mfOLMR(0.0), mfORMR(0.0)
249 bool operator<( const CutSet
& rOther
) const
251 const double fA(mfOLML
+ mfORML
+ mfOLMR
+ mfORMR
);
252 const double fB(rOther
.mfOLML
+ rOther
.mfORML
+ rOther
.mfOLMR
+ rOther
.mfORMR
);
257 double getSum() const { return mfOLML
+ mfORML
+ mfOLMR
+ mfORMR
; }
262 const basegfx::B2DPoint
& rLeft
,
263 const basegfx::B2DPoint
& rRight
,
264 const basegfx::B2DVector
& rX
,
265 const basegfx::B2DPoint
& rOtherLeft
,
266 const basegfx::B2DPoint
& rOtherRight
,
267 const basegfx::B2DVector
& rOtherX
)
269 basegfx::utils::findCut(
277 basegfx::utils::findCut(
285 basegfx::utils::findCut(
293 basegfx::utils::findCut(
307 ExtendSet() : mfExtLeft(0.0), mfExtRight(0.0) {}
311 std::vector
<ExtendSet
>& rExtendSet
, // target Left/Right values to fill
312 const basegfx::B2DPoint
& rOrigin
, // own vector start
313 const StyleVectorCombination
& rCombination
, // own vector and offsets for lines
314 const basegfx::B2DVector
& rPerpendX
, // normalized perpendicular to own vector
315 const std::vector
< StyleVectorCombination
>& rStyleVector
) // other vectors emerging in this point
317 if(!(!rCombination
.empty() && !rStyleVector
.empty() && rCombination
.size() == rExtendSet
.size()))
320 const size_t nOffsetA(rCombination
.size());
324 Color aMyColor
; double fMyOffset(0.0); double fMyHalfWidth(0.0);
325 rCombination
.getColorAndOffsetAndHalfWidth(0, aMyColor
, fMyOffset
, fMyHalfWidth
);
327 if(!aMyColor
.IsFullyTransparent())
329 const basegfx::B2DPoint
aLeft(rOrigin
+ (rPerpendX
* (fMyOffset
- fMyHalfWidth
)));
330 const basegfx::B2DPoint
aRight(rOrigin
+ (rPerpendX
* (fMyOffset
+ fMyHalfWidth
)));
331 std::vector
< CutSet
> aCutSets
;
333 for(const auto& rStyleCandidate
: rStyleVector
)
335 const basegfx::B2DVector
aOtherPerpend(basegfx::getNormalizedPerpendicular(rStyleCandidate
.getB2DVector()));
336 const size_t nOffsetB(rStyleCandidate
.size());
338 for(size_t other(0); other
< nOffsetB
; other
++)
340 Color aOtherColor
; double fOtherOffset(0.0); double fOtherHalfWidth(0.0);
341 rStyleCandidate
.getColorAndOffsetAndHalfWidth(other
, aOtherColor
, fOtherOffset
, fOtherHalfWidth
);
343 if(!aOtherColor
.IsFullyTransparent())
345 const basegfx::B2DPoint
aOtherLeft(rOrigin
+ (aOtherPerpend
* (fOtherOffset
- fOtherHalfWidth
)));
346 const basegfx::B2DPoint
aOtherRight(rOrigin
+ (aOtherPerpend
* (fOtherOffset
+ fOtherHalfWidth
)));
349 getCutSet(aNewCutSet
, aLeft
, aRight
, rCombination
.getB2DVector(), aOtherLeft
, aOtherRight
, rStyleCandidate
.getB2DVector());
350 aCutSets
.push_back(aNewCutSet
);
355 if(!aCutSets
.empty())
357 CutSet
aCutSet(aCutSets
[0]);
358 const size_t nNumCutSets(aCutSets
.size());
362 double fCutSet(aCutSet
.getSum());
364 for(size_t a(1); a
< nNumCutSets
; a
++)
366 const CutSet
& rCandidate(aCutSets
[a
]);
367 const double fCandidate(rCandidate
.getSum());
369 if(basegfx::fTools::equalZero(fCandidate
- fCutSet
))
371 // both have equal center point, use medium cut
372 const double fNewOLML(std::max(std::min(rCandidate
.mfOLML
, rCandidate
.mfORML
), std::min(aCutSet
.mfOLML
, aCutSet
.mfORML
)));
373 const double fNewORML(std::min(std::max(rCandidate
.mfOLML
, rCandidate
.mfORML
), std::max(aCutSet
.mfOLML
, aCutSet
.mfORML
)));
374 const double fNewOLMR(std::max(std::min(rCandidate
.mfOLMR
, rCandidate
.mfORMR
), std::min(aCutSet
.mfOLMR
, aCutSet
.mfORMR
)));
375 const double fNewORMR(std::min(std::max(rCandidate
.mfOLMR
, rCandidate
.mfORMR
), std::max(aCutSet
.mfOLMR
, aCutSet
.mfORMR
)));
376 aCutSet
.mfOLML
= fNewOLML
;
377 aCutSet
.mfORML
= fNewORML
;
378 aCutSet
.mfOLMR
= fNewOLMR
;
379 aCutSet
.mfORMR
= fNewORMR
;
380 fCutSet
= aCutSet
.getSum();
382 else if(fCandidate
< fCutSet
)
385 fCutSet
= fCandidate
;
386 aCutSet
= rCandidate
;
391 ExtendSet
& rExt(rExtendSet
[0]);
393 rExt
.mfExtLeft
= std::min(aCutSet
.mfOLML
, aCutSet
.mfORML
);
394 rExt
.mfExtRight
= std::min(aCutSet
.mfOLMR
, aCutSet
.mfORMR
);
400 size_t nVisEdgeUp(0);
401 size_t nVisEdgeDn(0);
403 for(size_t my(0); my
< nOffsetA
; my
++)
405 Color aMyColor
; double fMyOffset(0.0); double fMyHalfWidth(0.0);
406 rCombination
.getColorAndOffsetAndHalfWidth(my
, aMyColor
, fMyOffset
, fMyHalfWidth
);
408 if(!aMyColor
.IsFullyTransparent())
410 const basegfx::B2DPoint
aLeft(rOrigin
+ (rPerpendX
* (fMyOffset
- fMyHalfWidth
)));
411 const basegfx::B2DPoint
aRight(rOrigin
+ (rPerpendX
* (fMyOffset
+ fMyHalfWidth
)));
412 const bool bUpper(my
<= (nOffsetA
>> 1));
413 const StyleVectorCombination
& rStyleCandidate(bUpper
? rStyleVector
.front() : rStyleVector
.back());
414 const basegfx::B2DVector
aOtherPerpend(basegfx::getNormalizedPerpendicular(rStyleCandidate
.getB2DVector()));
415 const size_t nOffsetB(rStyleCandidate
.size());
416 std::vector
< CutSet
> aCutSets
;
418 for(size_t other(0); other
< nOffsetB
; other
++)
420 Color aOtherColor
; double fOtherOffset(0.0); double fOtherHalfWidth(0.0);
421 rStyleCandidate
.getColorAndOffsetAndHalfWidth(other
, aOtherColor
, fOtherOffset
, fOtherHalfWidth
);
423 if(!aOtherColor
.IsFullyTransparent())
425 const basegfx::B2DPoint
aOtherLeft(rOrigin
+ (aOtherPerpend
* (fOtherOffset
- fOtherHalfWidth
)));
426 const basegfx::B2DPoint
aOtherRight(rOrigin
+ (aOtherPerpend
* (fOtherOffset
+ fOtherHalfWidth
)));
428 getCutSet(aCutSet
, aLeft
, aRight
, rCombination
.getB2DVector(), aOtherLeft
, aOtherRight
, rStyleCandidate
.getB2DVector());
429 aCutSets
.push_back(aCutSet
);
433 if(!aCutSets
.empty())
435 // sort: min to start, max to end
436 std::sort(aCutSets
.begin(), aCutSets
.end());
437 const bool bOtherUpper(rStyleCandidate
.getAngle() > M_PI
);
439 // check if we need min or max
440 // bUpper bOtherUpper MinMax
445 const bool bMax(bUpper
== bOtherUpper
);
446 size_t nBaseIndex(0);
447 const size_t nNumCutSets(aCutSets
.size());
452 nBaseIndex
= nNumCutSets
- 1 - (bUpper
? nVisEdgeUp
: nVisEdgeDn
);
457 nBaseIndex
= bUpper
? nVisEdgeUp
: nVisEdgeDn
;
460 const size_t nSecuredIndex(std::clamp(nBaseIndex
, size_t(0), size_t(nNumCutSets
- 1)));
461 const CutSet
& rCutSet(aCutSets
[nSecuredIndex
]);
462 ExtendSet
& rExt(rExtendSet
[my
]);
464 rExt
.mfExtLeft
= std::min(rCutSet
.mfOLML
, rCutSet
.mfORML
);
465 rExt
.mfExtRight
= std::min(rCutSet
.mfOLMR
, rCutSet
.mfORMR
);
482 * Helper method to create the correct drawinglayer::primitive2d::BorderLinePrimitive2D
483 * for the given data, especially the correct drawinglayer::primitive2d::BorderLine entries
484 * including the correctly solved/created LineStartEnd extends
486 * rTarget : Here the evtl. created BorderLinePrimitive2D will be appended
487 * rOrigin : StartPoint of the Borderline
488 * rX : Vector of the Borderline
489 * rBorder : svx::frame::Style of the of the Borderline
490 * rStartStyleVectorTable : All other Borderlines which have to be taken into account because
491 * they have the same StartPoint as the current Borderline. These will be used to calculate
492 * the correct LineStartEnd extends tor the BorderLinePrimitive2D. The definition should be
493 * built up using svx::frame::StyleVectorTable and StyleVectorTable::add and includes:
494 * rStyle : the svx::frame::Style of one other BorderLine
495 * rMyVector : the Vector of the *new* to-be-defined BorderLine, identical to rX
496 * rOtherVector: the Vector of one other BorderLine (may be, but does not need to be normalized),
497 * always *pointing away* from the common StartPoint rOrigin
498 * bMirrored : define if rStyle of one other BorderLine shall be mirrored (e.g. bottom-right edges)
499 * With multiple BorderLines the definitions have to be CounterClockWise. This will be
500 * ensured by StyleVectorTable sorting the entries, but knowing this may allow more efficient
502 * rEndStyleVectorTable: All other BorderLines that have the same EndPoint. There are differences to
503 * the Start definitions:
504 * - do not forget to consequently use -rX for rMyVector
505 * - definitions have to be ClockWise for the EndBorderLines, will be ensured by sorting
507 * If you take all this into account, you will get correctly extended BorderLinePrimitive2D
508 * representations for the new to be defined BorderLine. That extensions will overlap nicely
509 * with the corresponding BorderLines and take all multiple line definitions in the ::Style into
511 * The internal solver is *not limited* to ::Style(s) with three parts (Left/Gap/Right), this is
512 * just due to svx::frame::Style's definitions. A new solver based on this one can be created
513 * anytime using more mulötiple borders based on the more flexible
514 * std::vector< drawinglayer::primitive2d::BorderLine > if needed.
516 void CreateBorderPrimitives(
517 drawinglayer::primitive2d::Primitive2DContainer
& rTarget
, /// target for created primitives
518 const basegfx::B2DPoint
& rOrigin
, /// start point of borderline
519 const basegfx::B2DVector
& rX
, /// X-Axis of borderline with length
520 const svx::frame::Style
& rBorder
, /// Style of borderline
521 const StyleVectorTable
& rStartStyleVectorTable
, /// Styles and vectors (pointing away) at borderline start, ccw
522 const StyleVectorTable
& rEndStyleVectorTable
, /// Styles and vectors (pointing away) at borderline end, cw
523 const Color
* pForceColor
, /// If specified, overrides frame border color.
524 double fMinimalDiscreteUnit
) /// minimal discrete unit to use for svx::frame::Style width values
526 // get offset color pairs for style, one per visible line
527 const StyleVectorCombination
aCombination(
533 fMinimalDiscreteUnit
);
535 if(aCombination
.empty())
538 const basegfx::B2DVector
aPerpendX(basegfx::getNormalizedPerpendicular(rX
));
539 const bool bHasStartStyles(!rStartStyleVectorTable
.empty());
540 const bool bHasEndStyles(!rEndStyleVectorTable
.empty());
541 const size_t nOffsets(aCombination
.size());
542 std::vector
<ExtendSet
> aExtendSetStart(nOffsets
);
543 std::vector
<ExtendSet
> aExtendSetEnd(nOffsets
);
547 // create extends for line starts, use given point/vector and offsets
548 getExtends(aExtendSetStart
, rOrigin
, aCombination
, aPerpendX
, rStartStyleVectorTable
.getEntries());
553 // Create extends for line ends, create inverse point/vector and inverse offsets.
554 const StyleVectorCombination
aMirroredCombination(
560 fMinimalDiscreteUnit
);
562 getExtends(aExtendSetEnd
, rOrigin
+ rX
, aMirroredCombination
, -aPerpendX
, rEndStyleVectorTable
.getEntries());
564 // also need to inverse the result to apply to the correct lines
565 std::reverse(aExtendSetEnd
.begin(), aExtendSetEnd
.end());
568 std::vector
< drawinglayer::primitive2d::BorderLine
> aBorderlines
;
569 const double fNegLength(-rX
.getLength());
571 for(size_t a(0); a
< nOffsets
; a
++)
574 double fMyOffset(0.0);
575 double fMyHalfWidth(0.0);
576 aCombination
.getColorAndOffsetAndHalfWidth(a
, aMyColor
, fMyOffset
, fMyHalfWidth
);
577 const ExtendSet
& rExtStart(aExtendSetStart
[a
]);
578 const ExtendSet
& rExtEnd(aExtendSetEnd
[a
]);
580 if(aMyColor
.IsFullyTransparent())
582 aBorderlines
.push_back(
583 drawinglayer::primitive2d::BorderLine(
584 fMyHalfWidth
* 2.0));
588 aBorderlines
.push_back(
589 drawinglayer::primitive2d::BorderLine(
590 drawinglayer::attribute::LineAttribute(
591 aMyColor
.getBColor(),
593 fNegLength
* rExtStart
.mfExtLeft
,
594 fNegLength
* rExtStart
.mfExtRight
,
595 fNegLength
* rExtEnd
.mfExtRight
,
596 fNegLength
* rExtEnd
.mfExtLeft
));
600 static const double fPatScFact(10.0); // 10.0 multiply, see old code
601 std::vector
<double> aDashing(svtools::GetLineDashing(rBorder
.Type(), rBorder
.PatternScale() * fPatScFact
));
602 drawinglayer::attribute::StrokeAttribute
aStrokeAttribute(std::move(aDashing
));
603 const basegfx::B2DPoint
aStart(rOrigin
+ (aPerpendX
* aCombination
.getRefModeOffset()));
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 Primitive2DReference
SdrFrameBorderPrimitive2D::create2DDecomposition(
767 const geometry::ViewInformation2D
& /*aViewInformation*/) const
769 if(getFrameBorders().empty())
774 Primitive2DContainer aRetval
;
776 // Check and use the minimal non-zero BorderWidth for decompose
777 // if that is set and wanted
778 const double fMinimalDiscreteUnit(doForceToSingleDiscreteUnit()
779 ? mfMinimalNonZeroBorderWidthUsedForDecompose
782 // decompose all buffered SdrFrameBorderData entries and try to merge them
783 // to reduce existing number of BorderLinePrimitive2D(s)
784 for(const auto& rCandidate
: getFrameBorders())
786 // get decomposition on one SdrFrameBorderData entry
787 Primitive2DContainer aPartial
;
788 rCandidate
.create2DDecomposition(
790 fMinimalDiscreteUnit
);
792 for(const auto& aCandidatePartial
: aPartial
)
796 // no local data yet, just add as 1st entry, done
797 aRetval
.append(aCandidatePartial
);
801 bool bDidMerge(false);
803 for(auto& aCandidateRetval
: aRetval
)
805 // try to merge by appending new data to existing data
806 const drawinglayer::primitive2d::Primitive2DReference
aMergeRetvalPartial(
807 drawinglayer::primitive2d::tryMergeBorderLinePrimitive2D(
808 static_cast<BorderLinePrimitive2D
*>(aCandidateRetval
.get()),
809 static_cast<BorderLinePrimitive2D
*>(aCandidatePartial
.get())));
811 if(aMergeRetvalPartial
.is())
813 // could append, replace existing data with merged data, done
814 aCandidateRetval
= aMergeRetvalPartial
;
819 // try to merge by appending existing data to new data
820 const drawinglayer::primitive2d::Primitive2DReference
aMergePartialRetval(
821 drawinglayer::primitive2d::tryMergeBorderLinePrimitive2D(
822 static_cast<BorderLinePrimitive2D
*>(aCandidatePartial
.get()),
823 static_cast<BorderLinePrimitive2D
*>(aCandidateRetval
.get())));
825 if(aMergePartialRetval
.is())
827 // could append, replace existing data with merged data, done
828 aCandidateRetval
= aMergePartialRetval
;
836 // no merge after checking all existing data, append as new segment
837 aRetval
.append(aCandidatePartial
);
843 return new GroupPrimitive2D(std::move(aRetval
));
846 SdrFrameBorderPrimitive2D::SdrFrameBorderPrimitive2D(
847 SdrFrameBorderDataVector
&& rFrameBorders
,
848 bool bForceToSingleDiscreteUnit
)
849 : maFrameBorders(std::move(rFrameBorders
)),
850 mfMinimalNonZeroBorderWidth(0.0),
851 mfMinimalNonZeroBorderWidthUsedForDecompose(0.0),
852 mbForceToSingleDiscreteUnit(bForceToSingleDiscreteUnit
)
854 if(!getFrameBorders().empty() && doForceToSingleDiscreteUnit())
856 // detect used minimal non-zero partial border width
857 for(const auto& rCandidate
: getFrameBorders())
859 mfMinimalNonZeroBorderWidth
= getMinimalNonZeroValue(
860 mfMinimalNonZeroBorderWidth
,
861 rCandidate
.getMinimalNonZeroBorderWidth());
866 bool SdrFrameBorderPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
868 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
870 const SdrFrameBorderPrimitive2D
& rCompare
= static_cast<const SdrFrameBorderPrimitive2D
&>(rPrimitive
);
872 return getFrameBorders() == rCompare
.getFrameBorders()
873 && doForceToSingleDiscreteUnit() == rCompare
.doForceToSingleDiscreteUnit();
879 void SdrFrameBorderPrimitive2D::get2DDecomposition(
880 Primitive2DDecompositionVisitor
& rVisitor
,
881 const geometry::ViewInformation2D
& rViewInformation
) const
883 if(doForceToSingleDiscreteUnit())
885 // Get the current DiscreteUnit, look at X and Y and use the maximum
886 const basegfx::B2DVector
aDiscreteVector(rViewInformation
.getInverseObjectToViewTransformation() * basegfx::B2DVector(1.0, 1.0));
887 double fDiscreteUnit(std::min(fabs(aDiscreteVector
.getX()), fabs(aDiscreteVector
.getY())));
889 if(fDiscreteUnit
<= mfMinimalNonZeroBorderWidth
)
891 // no need to use it, reset
895 if(fDiscreteUnit
!= mfMinimalNonZeroBorderWidthUsedForDecompose
)
897 // conditions of last local decomposition have changed, delete
899 if(getBuffered2DDecomposition())
901 const_cast< SdrFrameBorderPrimitive2D
* >(this)->setBuffered2DDecomposition(nullptr);
904 // remember new conditions
905 const_cast< SdrFrameBorderPrimitive2D
* >(this)->mfMinimalNonZeroBorderWidthUsedForDecompose
= fDiscreteUnit
;
909 // call parent. This will call back ::create2DDecomposition above
910 // where mfMinimalNonZeroBorderWidthUsedForDecompose will be used
911 // when doForceToSingleDiscreteUnit() is true
912 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor
, rViewInformation
);
916 sal_uInt32
SdrFrameBorderPrimitive2D::getPrimitive2DID() const
918 return PRIMITIVE2D_ID_SDRFRAMEBORDERTPRIMITIVE2D
;
921 } // end of namespace
923 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */