Skip to content

Commit

Permalink
CGContextDrawLinearGradient() now works in CGContextVML.
Browse files Browse the repository at this point in the history
  • Loading branch information
nciagra authored and Ross Boucher committed May 6, 2009
1 parent ae8fd0c commit 854d1c0
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion AppKit/CoreGraphics/CGContextVML.j
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ function CGContextDrawPath(aContext, aMode)

vml.push("\">");

if (fill)
if (gState.gradient)
vml.push(gState.gradient)

else if (fill)
vml.push("<cg_vml_:fill color=\"", gState.fillStyle, "\" opacity=\"", opacity, "\" />");

if (stroke)
Expand Down Expand Up @@ -260,3 +263,33 @@ function CGContextDrawPath(aContext, aMode)
aContext.DOMElement.insertAdjacentHTML("BeforeEnd", vml.join(""));
}

function to_string(aColor)
{
return "rgb(" + ROUND(aColor.components[0] * 255) + ", " + ROUND(aColor.components[1] * 255) + ", " + ROUND(255 * aColor.components[2]) + ")";
}

function CGContextDrawLinearGradient(aContext, aGradient, aStartPoint, anEndPoint, options)
{
if (!aContext || !aGradient)
return;

var colors = aGradient.colors,
count = colors.length,

vml = ["<cg_vml_:fill type=\"gradient\" "];

vml.push("colors=\"");
console.log(aGradient.locations);
for (var i = 0; i < count; i++)
vml.push((aGradient.locations[i]*100).toFixed(0)+"% "+to_string(colors[i])+(i<count-1 ? "," : ""));

vml.push("\" />");

aContext.gState.gradient = vml.join("");
console.log(vml.join(""));

// if (aContext.buffer != nil)
// aContext.buffer += vml.join("");
// else
// aContext.DOMElement.innerHTML = vml.join("");
}

0 comments on commit 854d1c0

Please sign in to comment.