svggradientprimitive2d.cxx (2b45cf47) svggradientprimitive2d.cxx (025b0597)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 342 unchanged lines hidden (view full) ---

351 }
352 else
353 {
354 rTargetColor.push_back(
355 new SvgLinearAtomPrimitive2D(
356 rFrom.getColor(), rFrom.getOffset() + nOffset,
357 rTo.getColor(), rTo.getOffset() + nOffset));
358
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 342 unchanged lines hidden (view full) ---

351 }
352 else
353 {
354 rTargetColor.push_back(
355 new SvgLinearAtomPrimitive2D(
356 rFrom.getColor(), rFrom.getOffset() + nOffset,
357 rTo.getColor(), rTo.getOffset() + nOffset));
358
359 const double fTransFrom(1.0 - rFrom.getOpacity());
360 const double fTransTo(1.0 - rTo.getOpacity());
359 if(!getFullyOpaque())
360 {
361 const double fTransFrom(1.0 - rFrom.getOpacity());
362 const double fTransTo(1.0 - rTo.getOpacity());
363 const basegfx::BColor aColorFrom(fTransFrom, fTransFrom, fTransFrom);
364 const basegfx::BColor aColorTo(fTransTo, fTransTo, fTransTo);
361
365
362 rTargetOpacity.push_back(
363 new SvgLinearAtomPrimitive2D(
364 basegfx::BColor(fTransFrom, fTransFrom, fTransFrom), rFrom.getOffset() + nOffset,
365 basegfx::BColor(fTransTo,fTransTo, fTransTo), rTo.getOffset() + nOffset));
366 rTargetOpacity.push_back(
367 new SvgLinearAtomPrimitive2D(
368 aColorFrom, rFrom.getOffset() + nOffset,
369 aColorTo, rTo.getOffset() + nOffset));
370 }
366 }
367 }
368
369 Primitive2DSequence SvgLinearGradientPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
370 {
371 Primitive2DSequence xRetval;
372
373 if(!getPreconditionsChecked())

--- 158 unchanged lines hidden (view full) ---

532 const basegfx::B2DPoint& rEnd,
533 SpreadMethod aSpreadMethod)
534 : BufferedDecompositionPrimitive2D(),
535 SvgGradientHelper(rPolyPolygon, rGradientEntries, rStart, aSpreadMethod),
536 maEnd(rEnd)
537 {
538 }
539
371 }
372 }
373
374 Primitive2DSequence SvgLinearGradientPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
375 {
376 Primitive2DSequence xRetval;
377
378 if(!getPreconditionsChecked())

--- 158 unchanged lines hidden (view full) ---

537 const basegfx::B2DPoint& rEnd,
538 SpreadMethod aSpreadMethod)
539 : BufferedDecompositionPrimitive2D(),
540 SvgGradientHelper(rPolyPolygon, rGradientEntries, rStart, aSpreadMethod),
541 maEnd(rEnd)
542 {
543 }
544
545 SvgLinearGradientPrimitive2D::~SvgLinearGradientPrimitive2D()
546 {
547 }
548
540 bool SvgLinearGradientPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
541 {
542 const SvgGradientHelper* pSvgGradientHelper = dynamic_cast< const SvgGradientHelper* >(&rPrimitive);
543
544 if(pSvgGradientHelper && SvgGradientHelper::operator==(*pSvgGradientHelper))
545 {
546 const SvgLinearGradientPrimitive2D& rCompare = static_cast< const SvgLinearGradientPrimitive2D& >(rPrimitive);
547

--- 67 unchanged lines hidden (view full) ---

615 else
616 {
617 rTargetColor.push_back(
618 new SvgRadialAtomPrimitive2D(
619 rFrom.getColor(), fScaleFrom,
620 rTo.getColor(), fScaleTo));
621 }
622
549 bool SvgLinearGradientPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
550 {
551 const SvgGradientHelper* pSvgGradientHelper = dynamic_cast< const SvgGradientHelper* >(&rPrimitive);
552
553 if(pSvgGradientHelper && SvgGradientHelper::operator==(*pSvgGradientHelper))
554 {
555 const SvgLinearGradientPrimitive2D& rCompare = static_cast< const SvgLinearGradientPrimitive2D& >(rPrimitive);
556

--- 67 unchanged lines hidden (view full) ---

624 else
625 {
626 rTargetColor.push_back(
627 new SvgRadialAtomPrimitive2D(
628 rFrom.getColor(), fScaleFrom,
629 rTo.getColor(), fScaleTo));
630 }
631
623 const double fTransFrom(1.0 - rFrom.getOpacity());
624 const double fTransTo(1.0 - rTo.getOpacity());
625 const basegfx::BColor aColorFrom(fTransFrom, fTransFrom, fTransFrom);
626 const basegfx::BColor aColorTo(fTransTo, fTransTo, fTransTo);
627
628 if(isFocalSet())
632 if(!getFullyOpaque())
629 {
633 {
630 const basegfx::B2DVector aTranslateFrom(maFocalVector * (maFocalLength - fScaleFrom));
631 const basegfx::B2DVector aTranslateTo(maFocalVector * (maFocalLength - fScaleTo));
634 const double fTransFrom(1.0 - rFrom.getOpacity());
635 const double fTransTo(1.0 - rTo.getOpacity());
636 const basegfx::BColor aColorFrom(fTransFrom, fTransFrom, fTransFrom);
637 const basegfx::BColor aColorTo(fTransTo, fTransTo, fTransTo);
638
639 if(isFocalSet())
640 {
641 const basegfx::B2DVector aTranslateFrom(maFocalVector * (maFocalLength - fScaleFrom));
642 const basegfx::B2DVector aTranslateTo(maFocalVector * (maFocalLength - fScaleTo));
632
643
633 rTargetOpacity.push_back(
634 new SvgRadialAtomPrimitive2D(
635 aColorFrom, fScaleFrom, aTranslateFrom,
636 aColorTo, fScaleTo, aTranslateTo));
644 rTargetOpacity.push_back(
645 new SvgRadialAtomPrimitive2D(
646 aColorFrom, fScaleFrom, aTranslateFrom,
647 aColorTo, fScaleTo, aTranslateTo));
648 }
649 else
650 {
651 rTargetOpacity.push_back(
652 new SvgRadialAtomPrimitive2D(
653 aColorFrom, fScaleFrom,
654 aColorTo, fScaleTo));
655 }
637 }
656 }
638 else
639 {
640 rTargetOpacity.push_back(
641 new SvgRadialAtomPrimitive2D(
642 aColorFrom, fScaleFrom,
643 aColorTo, fScaleTo));
644 }
645 }
646 }
647
648 const SvgGradientEntryVector& SvgRadialGradientPrimitive2D::getMirroredGradientEntries() const
649 {
650 if(maMirroredGradientEntries.empty() && !getGradientEntries().empty())
651 {
652 const_cast< SvgRadialGradientPrimitive2D* >(this)->createMirroredGradientEntries();

--- 138 unchanged lines hidden (view full) ---

791 SvgGradientHelper(rPolyPolygon, rGradientEntries, rStart, aSpreadMethod),
792 mfRadius(fRadius),
793 maFocal(rStart),
794 maFocalVector(0.0, 0.0),
795 maFocalLength(0.0),
796 maMirroredGradientEntries(),
797 mbFocalSet(false)
798 {
657 }
658 }
659
660 const SvgGradientEntryVector& SvgRadialGradientPrimitive2D::getMirroredGradientEntries() const
661 {
662 if(maMirroredGradientEntries.empty() && !getGradientEntries().empty())
663 {
664 const_cast< SvgRadialGradientPrimitive2D* >(this)->createMirroredGradientEntries();

--- 138 unchanged lines hidden (view full) ---

803 SvgGradientHelper(rPolyPolygon, rGradientEntries, rStart, aSpreadMethod),
804 mfRadius(fRadius),
805 maFocal(rStart),
806 maFocalVector(0.0, 0.0),
807 maFocalLength(0.0),
808 maMirroredGradientEntries(),
809 mbFocalSet(false)
810 {
799 if(pFocal)
811 if(pFocal && !pFocal->equal(getStart()))
800 {
801 maFocal = *pFocal;
802 maFocalVector = maFocal - getStart();
803 mbFocalSet = true;
804 }
805 }
806
812 {
813 maFocal = *pFocal;
814 maFocalVector = maFocal - getStart();
815 mbFocalSet = true;
816 }
817 }
818
819 SvgRadialGradientPrimitive2D::~SvgRadialGradientPrimitive2D()
820 {
821 }
822
807 bool SvgRadialGradientPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
808 {
809 const SvgGradientHelper* pSvgGradientHelper = dynamic_cast< const SvgGradientHelper* >(&rPrimitive);
810
811 if(pSvgGradientHelper && SvgGradientHelper::operator==(*pSvgGradientHelper))
812 {
813 const SvgRadialGradientPrimitive2D& rCompare = static_cast< const SvgRadialGradientPrimitive2D& >(rPrimitive);
814

--- 43 unchanged lines hidden (view full) ---

858 if(!basegfx::fTools::equalZero(fDelta))
859 {
860 // use one discrete unit for overlap (one pixel)
861 const double fDiscreteUnit(getDiscreteUnit());
862
863 // use color distance and discrete lengths to calculate step count
864 const sal_uInt32 nSteps(calculateStepsForSvgGradient(getColorA(), getColorB(), fDelta, fDiscreteUnit));
865
823 bool SvgRadialGradientPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
824 {
825 const SvgGradientHelper* pSvgGradientHelper = dynamic_cast< const SvgGradientHelper* >(&rPrimitive);
826
827 if(pSvgGradientHelper && SvgGradientHelper::operator==(*pSvgGradientHelper))
828 {
829 const SvgRadialGradientPrimitive2D& rCompare = static_cast< const SvgRadialGradientPrimitive2D& >(rPrimitive);
830

--- 43 unchanged lines hidden (view full) ---

874 if(!basegfx::fTools::equalZero(fDelta))
875 {
876 // use one discrete unit for overlap (one pixel)
877 const double fDiscreteUnit(getDiscreteUnit());
878
879 // use color distance and discrete lengths to calculate step count
880 const sal_uInt32 nSteps(calculateStepsForSvgGradient(getColorA(), getColorB(), fDelta, fDiscreteUnit));
881
866 // prepare loop and polygon (with overlap for linear gradients)
867 double fStart(0.0);
868 double fStep(fDelta / nSteps);
882 // prepare polygon in needed width at start position (with discrete overlap)
869 const basegfx::B2DPolygon aPolygon(
870 basegfx::tools::createPolygonFromRect(
871 basegfx::B2DRange(
872 getOffsetA() - fDiscreteUnit,
873 0.0,
883 const basegfx::B2DPolygon aPolygon(
884 basegfx::tools::createPolygonFromRect(
885 basegfx::B2DRange(
886 getOffsetA() - fDiscreteUnit,
887 0.0,
874 getOffsetA() + fStep + fDiscreteUnit,
888 getOffsetA() + (fDelta / nSteps) + fDiscreteUnit,
875 1.0)));
876
889 1.0)));
890
877 // loop and create primitives
891 // prepare loop (inside to outside, [0.0 .. 1.0[)
892 double fUnitScale(0.0);
893 const double fUnitStep(1.0 / nSteps);
894
895 // prepare result set (known size)
878 xRetval.realloc(nSteps);
879
896 xRetval.realloc(nSteps);
897
880 for(sal_uInt32 a(0); a < nSteps; a++, fStart += fStep)
898 for(sal_uInt32 a(0); a < nSteps; a++, fUnitScale += fUnitStep)
881 {
882 basegfx::B2DPolygon aNew(aPolygon);
883
899 {
900 basegfx::B2DPolygon aNew(aPolygon);
901
884 aNew.transform(basegfx::tools::createTranslateB2DHomMatrix(fStart, 0.0));
902 aNew.transform(basegfx::tools::createTranslateB2DHomMatrix(fDelta * fUnitScale, 0.0));
885 xRetval[a] = new PolyPolygonColorPrimitive2D(
886 basegfx::B2DPolyPolygon(aNew),
903 xRetval[a] = new PolyPolygonColorPrimitive2D(
904 basegfx::B2DPolyPolygon(aNew),
887 basegfx::interpolate(getColorA(), getColorB(), fStart/fDelta));
905 basegfx::interpolate(getColorA(), getColorB(), fUnitScale));
888 }
889 }
890
891 return xRetval;
892 }
893
894 SvgLinearAtomPrimitive2D::SvgLinearAtomPrimitive2D(
895 const basegfx::BColor& aColorA, double fOffsetA,

--- 47 unchanged lines hidden (view full) ---

943 if(!basegfx::fTools::equalZero(fDeltaScale))
944 {
945 // use one discrete unit for overlap (one pixel)
946 const double fDiscreteUnit(getDiscreteUnit());
947
948 // use color distance and discrete lengths to calculate step count
949 const sal_uInt32 nSteps(calculateStepsForSvgGradient(getColorA(), getColorB(), fDeltaScale, fDiscreteUnit));
950
906 }
907 }
908
909 return xRetval;
910 }
911
912 SvgLinearAtomPrimitive2D::SvgLinearAtomPrimitive2D(
913 const basegfx::BColor& aColorA, double fOffsetA,

--- 47 unchanged lines hidden (view full) ---

961 if(!basegfx::fTools::equalZero(fDeltaScale))
962 {
963 // use one discrete unit for overlap (one pixel)
964 const double fDiscreteUnit(getDiscreteUnit());
965
966 // use color distance and discrete lengths to calculate step count
967 const sal_uInt32 nSteps(calculateStepsForSvgGradient(getColorA(), getColorB(), fDeltaScale, fDiscreteUnit));
968
951 // prepare loop (outside to inside, full polygons, no polypolygons with holes)
952 double fEndScale(getScaleB());
953 double fStepScale(fDeltaScale / nSteps);
969 // prepare loop ([0.0 .. 1.0[, full polygons, no polypolygons with holes)
970 double fUnitScale(0.0);
971 const double fUnitStep(1.0 / nSteps);
954
972
955 // loop and create primitives
973 // prepare result set (known size)
956 xRetval.realloc(nSteps);
957
974 xRetval.realloc(nSteps);
975
958 for(sal_uInt32 a(0); a < nSteps; a++, fEndScale -= fStepScale)
976 for(sal_uInt32 a(0); a < nSteps; a++, fUnitScale += fUnitStep)
959 {
977 {
960 const double fUnitScale(fEndScale/fDeltaScale);
961 basegfx::B2DHomMatrix aTransform;
978 basegfx::B2DHomMatrix aTransform;
979 const double fEndScale(getScaleB() - (fDeltaScale * fUnitScale));
962
963 if(isTranslateSet())
964 {
965 const basegfx::B2DVector aTranslate(
966 basegfx::interpolate(
980
981 if(isTranslateSet())
982 {
983 const basegfx::B2DVector aTranslate(
984 basegfx::interpolate(
967 getTranslateA(),
968 getTranslateB(),
985 getTranslateB(),
986 getTranslateA(),
969 fUnitScale));
970
971 aTransform = basegfx::tools::createScaleTranslateB2DHomMatrix(
972 fEndScale,
973 fEndScale,
974 aTranslate.getX(),
975 aTranslate.getY());
976 }

--- 4 unchanged lines hidden (view full) ---

981 fEndScale);
982 }
983
984 basegfx::B2DPolygon aNew(basegfx::tools::createPolygonFromUnitCircle());
985
986 aNew.transform(aTransform);
987 xRetval[a] = new PolyPolygonColorPrimitive2D(
988 basegfx::B2DPolyPolygon(aNew),
987 fUnitScale));
988
989 aTransform = basegfx::tools::createScaleTranslateB2DHomMatrix(
990 fEndScale,
991 fEndScale,
992 aTranslate.getX(),
993 aTranslate.getY());
994 }

--- 4 unchanged lines hidden (view full) ---

999 fEndScale);
1000 }
1001
1002 basegfx::B2DPolygon aNew(basegfx::tools::createPolygonFromUnitCircle());
1003
1004 aNew.transform(aTransform);
1005 xRetval[a] = new PolyPolygonColorPrimitive2D(
1006 basegfx::B2DPolyPolygon(aNew),
989 basegfx::interpolate(getColorA(), getColorB(), fUnitScale));
1007 basegfx::interpolate(getColorB(), getColorA(), fUnitScale));
990 }
991 }
992
993 return xRetval;
994 }
995
996 SvgRadialAtomPrimitive2D::SvgRadialAtomPrimitive2D(
997 const basegfx::BColor& aColorA, double fScaleA, const basegfx::B2DVector& rTranslateA,

--- 96 unchanged lines hidden ---
1008 }
1009 }
1010
1011 return xRetval;
1012 }
1013
1014 SvgRadialAtomPrimitive2D::SvgRadialAtomPrimitive2D(
1015 const basegfx::BColor& aColorA, double fScaleA, const basegfx::B2DVector& rTranslateA,

--- 96 unchanged lines hidden ---