0 Replies Latest reply on Feb 7, 2013 5:11 AM by thinkink_es

# Compound Path - determine  winding rules

I have a compound path, and i need to parse all points, for export to CANVAS HTML , for this I wrote this script:

But the problem is how to detect the holes. I find information, and i think that i need the fill rule or clockwise fill, but in the reference doesn't exist.

Somebody can help me. Thanks

Nonzero winding fill rule

Uses mathematical equations to determine if a point is outside or inside a shape. Illustrator uses the nonzero winding rule as the default rule.

Even-odd fill rule

Uses mathematical equations to determine if a point is outside or inside a shape. This rule is the more predictable rule because every other region within an even‑odd compound path is a hole, regardless of path direction. Some applications, such as Adobe Photoshop, use the even‑odd rule by default, so compound paths imported from these applications will use the even‑odd rule.

http://www.fireworkszone.com/tuts/476/fill_rules.pdf

/*bool*/ Polygon.prototype.collideShapes = function(/*Polygon*/ _poly)

//--------------------------------------------------------------------

// Ret. TRUE if the shapes intersect

// slow method

{

try {

this.intersectPath(_poly);

app.activeDocument.undo();

return(true);

}

catch(ex)

{

return(false);

}

}

var selection = app.activeDocument.selection;

var a= selection[0]

var b= selection[1]

function inArray(agulla, paller){

var length = paller.length;

for(var i = 0; i < length; i++) {

if(paller[i] == agulla) return true;

}

return false;

}

var item  = app.activeDocument.selection;

var items = item[0].releaseCompoundPath();

var restantes = items;

var groups={}

var i = items.length;

//          while( i-- )

for (var i=0;i< items.length;i++)

{

a = items[i];

try{

\$.writeln( items[i].LocalDisplaySetting          )

}catch(e){\$.writeln( e)}

for (var s=0;s< restantes.length;s++){

var b = restantes[s]

if(a!=b){

if(inArray(b, restantes)== true){

try{

if(a.collideShapes(b)){

if(typeof groups[i]== "undefined"){

groups[i]=[]

groups[i].push(i)

}

groups[i].push(s)

restantes[i]= "void";

items[i]= "void";

restantes[s]= "void";

items[s]= "void";

}

}

catch(e){}

}

}

}

}

app.activeDocument.undo();

for (var t=0;t< restantes.length;t++){

if(restantes[t]!= "void")

\$.writeln ( "_" + t +",");

}

for(var g  in groups){

var group = groups[g]

\$.writeln ("var compoundPath = new CompoundPath( _" + group.join(", _") +").fillColor = 'red';");

}