681 {
686
687 bool doStitchFunctions = (
state.fType == SkShaderBase::GradientType::kLinear ||
688 state.fType == SkShaderBase::GradientType::kRadial ||
689 state.fType == SkShaderBase::GradientType::kConical) &&
692
693 int32_t shadingType = 1;
695
696
697
698
699 if (doStitchFunctions) {
701 shadingType = (
state.fType == SkShaderBase::GradientType::kLinear) ? 2 : 3;
702
704 extend->reserve(2);
705 extend->appendBool(true);
706 extend->appendBool(true);
707 pdfShader->insertObject("Extend", std::move(extend));
708
709 std::unique_ptr<SkPDFArray> coords;
710 if (
state.fType == SkShaderBase::GradientType::kConical) {
716
719 r1,
722 r2);
723 }
else if (
state.fType == SkShaderBase::GradientType::kRadial) {
727 0,
731 } else {
738 }
739
740 pdfShader->insertObject("Coords", std::move(coords));
741 } else {
742
743
744 transformPoints[0] =
info.fPoint[0];
745 transformPoints[1] =
info.fPoint[1];
746 switch (
state.fType) {
747 case SkShaderBase::GradientType::kLinear:
748 break;
749 case SkShaderBase::GradientType::kRadial:
750 transformPoints[1] = transformPoints[0];
751 transformPoints[1].
fX +=
info.fRadius[0];
752 break;
753 case SkShaderBase::GradientType::kConical: {
754 transformPoints[1] = transformPoints[0];
756 break;
757 }
758 case SkShaderBase::GradientType::kSweep:
759 transformPoints[1] = transformPoints[0];
761 break;
763 default:
765 }
766
767
768
769
770
773
775
776
777
778
779
780
784 &finalMatrix, &perspectiveInverseOnly)) {
786 }
787 }
788
793 }
795
797
798 if (
state.fType == SkShaderBase::GradientType::kConical) {
800 if (!mapperMatrix.
invert(&inverseMapperMatrix)) {
802 }
806 }
807 switch (
state.fType) {
808 case SkShaderBase::GradientType::kLinear:
809 linearCode(infoCopy, perspectiveInverseOnly, &functionCode);
810 break;
811 case SkShaderBase::GradientType::kRadial:
812 radialCode(infoCopy, perspectiveInverseOnly, &functionCode);
813 break;
814 case SkShaderBase::GradientType::kConical:
816 break;
817 case SkShaderBase::GradientType::kSweep:
818 sweepCode(infoCopy, perspectiveInverseOnly, &functionCode);
819 break;
820 default:
822 }
823 pdfShader->insertObject(
825
827 std::unique_ptr<SkPDFArray> rangeObject =
SkPDFMakeArray(0, 1, 0, 1, 0, 1);
828 pdfShader->insertRef("Function",
830 std::move(rangeObject), doc));
831 }
832
833 pdfShader->insertInt("ShadingType", shadingType);
834 pdfShader->insertName("ColorSpace", "DeviceRGB");
835
837 pdfFunctionShader.insertInt("PatternType", 2);
839 pdfFunctionShader.insertObject("Shading", std::move(pdfShader));
840 return doc->
emit(pdfFunctionShader);
841}
static void radialCode(const SkShaderBase::GradientInfo &info, const SkMatrix &perspectiveRemover, SkDynamicMemoryWStream *function)
static std::unique_ptr< SkPDFDict > gradientStitchCode(const SkShaderBase::GradientInfo &info)
static void sweepCode(const SkShaderBase::GradientInfo &info, const SkMatrix &perspectiveRemover, SkDynamicMemoryWStream *function)
static void linearCode(const SkShaderBase::GradientInfo &info, const SkMatrix &perspectiveRemover, SkDynamicMemoryWStream *function)
static bool split_perspective(const SkMatrix in, SkMatrix *affine, SkMatrix *perspectiveInverse)
static void twoPointConicalCode(const SkShaderBase::GradientInfo &info, const SkMatrix &perspectiveRemover, SkDynamicMemoryWStream *function)
static SkPDFIndirectReference make_ps_function(std::unique_ptr< SkStreamAsset > psCode, std::unique_ptr< SkPDFArray > domain, std::unique_ptr< SkPDFObject > range, SkPDFDocument *doc)
static void unit_to_points_matrix(const SkPoint pts[2], SkMatrix *matrix)
static void FixUpRadius(const SkPoint &p1, SkScalar &r1, const SkPoint &p2, SkScalar &r2)
std::unique_ptr< SkStreamAsset > detachAsStream()
SkScalar mapRadius(SkScalar radius) const
void mapPoints(SkPoint dst[], const SkPoint src[], int count) const
bool invert(SkMatrix *inverse) const
SkMatrix & preConcat(const SkMatrix &other)
SkPDFIndirectReference emit(const SkPDFObject &, SkPDFIndirectReference)
std::unique_ptr< SkPDFArray > MatrixToArray(const SkMatrix &matrix)
bool InverseTransformBBox(const SkMatrix &matrix, SkRect *bbox)
constexpr float y() const
constexpr float x() const
constexpr float left() const
constexpr float top() const
constexpr float right() const
void set(const SkIRect &src)
constexpr float bottom() const