MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / nsvg__createGradient

Function nsvg__createGradient

rEFIt_UEFI/libeg/nanosvg.cpp:810–907  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

808static void nsvg__getLocalBounds(float* bounds, NSVGshape *shape); //, float* xform);
809
810static NSVGgradient* nsvg__createGradient(NSVGparser* p, NSVGshape* shape, NSVGgradientLink* link, char* paintType)
811{
812 // NSVGattrib* attr = nsvg__getAttr(p);
813 NSVGgradientData* data = NULL;
814 NSVGgradientData* ref = NULL;
815 NSVGgradientStop* stops = NULL;
816 NSVGgradient* grad;
817 float ox, oy, sw, sh, sl;
818 int nstops = 0;
819
820 if (!link) {
821 *paintType = NSVG_PAINT_NONE;
822 return NULL;
823 }
824 data = nsvg__findGradientData(p, link->id);
825 if (data == NULL) return NULL;
826 // DumpFloat2("gradient data xform:", data->xform, 6);
827 stops = data->stops;
828 nstops = data->nstops;
829 ref = nsvg__findGradientData(p, data->ref);
830 while (ref != NULL) {
831 if (stops == NULL && ref->stops != NULL) { //take stops only once at first occuerence
832 stops = ref->stops;
833 nstops = ref->nstops;
834 }
835 //left referenced, right is current,
836 // matrix are reversed
837 nsvg__xformPremultiply(data->xform, ref->xform);
838 ref = nsvg__findGradientData(p, ref->ref); //recursive refs?
839 }
840 if (stops == NULL) return NULL;
841 // DumpFloat2("gradient final xform:", data->xform, 6);
842 grad = (NSVGgradient*)AllocateZeroPool(sizeof(NSVGgradient) + sizeof(NSVGgradientStop)*(nstops-1));
843 if (grad == NULL) return NULL;
844 // The shape width and height.
845 if (data->units == NSVG_OBJECT_SPACE) {
846 float localBounds[4];
847 nsvg__getLocalBounds(localBounds, shape); //, inv); //before any transform
848
849 ox = localBounds[0];
850 oy = localBounds[1];
851 sw = localBounds[2] - localBounds[0];
852 sh = localBounds[3] - localBounds[1];
853 } else {
854 ox = nsvg__actualOrigX(p);
855 oy = nsvg__actualOrigY(p);
856 sw = nsvg__actualWidth(p);
857 sh = nsvg__actualHeight(p);
858 }
859
860 float gradForm[6]; //coordinates
861 nsvg__xformIdentity(gradForm);
862 // sl = sqrtf(sw*sw + sh*sh) * 0.70710678118655f; // == 1. / sqrtf(2.0f);
863 sl = nsvg__vmag(sw, sh) * 0.70710678118655f;
864 if (data->type == NSVG_PAINT_LINEAR_GRADIENT) {
865 float x1, y1, x2, y2, dx, dy;
866
867 x1 = nsvg__convertToPixelsForGradient(p, data->units, &data->direction.linear.x1, ox, sw);

Callers 1

nsvg__assignGradientsFunction · 0.85

Calls 14

nsvg__findGradientDataFunction · 0.85
nsvg__xformPremultiplyFunction · 0.85
nsvg__getLocalBoundsFunction · 0.85
nsvg__actualOrigXFunction · 0.85
nsvg__actualOrigYFunction · 0.85
nsvg__actualWidthFunction · 0.85
nsvg__actualHeightFunction · 0.85
nsvg__xformIdentityFunction · 0.85
nsvg__vmagFunction · 0.85
nsvg__xformMultiplyFunction · 0.85
nsvg__xformInverseFunction · 0.85

Tested by

no test coverage detected