Skip to content

Commit ad6ce26

Browse files
committed
butterbur/GraphicalElement/Path; tesselation: Support for inner contours
- Currently only taken into account for fill
1 parent 5f08c66 commit ad6ce26

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

butterbur/src/GraphicalElement.ec

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,17 +371,28 @@ public:
371371
public class Path : Shape
372372
{
373373
Array<Pointf> nodes { };
374+
Array<Array<Pointf>> innerNodes { };
374375
bool closed, needTesselation;
375376

376377
shpType = path;
377378

379+
~Path()
380+
{
381+
innerNodes.Free();
382+
}
383+
378384
// FIXME: eC improvements: Clarify and fix usage of private members in base class...
379385
public:
380386
property Container<Pointf> nodes
381387
{
382388
set { nodes.copySrc = value; }
383389
get { return nodes; }
384390
}
391+
property Container<Container<Pointf>> innerNodes
392+
{
393+
set { innerNodes.copySrc = (Array<Array<Pointf>>)value; }
394+
get { return (Container<Container<Pointf>>)innerNodes; }
395+
}
385396

386397
property bool closed
387398
{

butterbur/src/tesselation/shapesTesselation.ec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct TesselatedShape
5656
bool closed = false, noJoin = false, needTesselation = false;
5757
bool partialSector = false, fullSector = false;
5858
uint count = 0;
59+
Array<Array<Pointf>> inner = null;
5960

6061
switch(shp.shpType)
6162
{
@@ -75,6 +76,7 @@ struct TesselatedShape
7576
nodes = array.array;
7677
count = array.count;
7778
closed = path.closed && count >= 3;
79+
inner = (Array<Array<Pointf>>)path.innerNodes;
7880
needTesselation = closed && path.needTesselation;
7981
break;
8082
}
@@ -496,7 +498,7 @@ struct TesselatedShape
496498
for(i = 0; i < fillCount; i++)
497499
tPoints[i] = points[ixFill[i]];
498500

499-
tesselatePolygon(tPoints, &output, &prims);
501+
tesselatePolygonEx(tPoints, inner, &output, &prims);
500502

501503
added = output.count - tPoints.count;
502504
if(added > 0)

butterbur/src/tesselation/tesselation.ec

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ static void CALLBACK tessPrimCombine(GLdouble coords[3], Pointf *d[4],
166166

167167
void tesselatePolygon(Array<Pointf> area, Array<Pointf> * outputPtr, Array<TessPrim> * primitivesPtr)
168168
{
169-
int i, d;
169+
tesselatePolygonEx(area, null, outputPtr, primitivesPtr);
170+
}
171+
172+
void tesselatePolygonEx(Array<Pointf> area, Array<Array<Pointf>> inner, Array<Pointf> * outputPtr, Array<TessPrim> * primitivesPtr)
173+
{
174+
int i, j, d;
170175
Pointf * destPoints;
171176
int totalCount = area.count;
172177
int start = 0;
@@ -176,6 +181,10 @@ void tesselatePolygon(Array<Pointf> area, Array<Pointf> * outputPtr, Array<TessP
176181

177182
static TessPrimData tesselatorData;
178183

184+
if(inner)
185+
for(j = 0; j < inner.count; j++)
186+
totalCount += inner[j].count;
187+
179188
tessMutex.Wait();
180189

181190
output.size = totalCount;
@@ -197,6 +206,21 @@ void tesselatePolygon(Array<Pointf> area, Array<Pointf> * outputPtr, Array<TessP
197206
destPoints[d] = area[i];
198207
vertices[d] = { area[i].x, area[i].y };
199208
}
209+
210+
if(inner)
211+
{
212+
for(j = 0; j < inner.count; j++)
213+
{
214+
Array<Pointf> contour = inner[j];
215+
n = contour.count;
216+
217+
for(i = n-1; i >= 0; i--, d++)
218+
{
219+
destPoints[d] = contour[i];
220+
vertices[d] = { contour[i].x, contour[i].y };
221+
}
222+
}
223+
}
200224
}
201225

202226
if(!butterburTesselator)
@@ -221,11 +245,29 @@ void tesselatePolygon(Array<Pointf> area, Array<Pointf> * outputPtr, Array<TessP
221245
{
222246
gluTessBeginContour(butterburTesselator);
223247
d = start;
248+
start += n;
249+
224250
for(i = 0; i < n; i++, d++)
225251
gluTessVertex(butterburTesselator, (double *)&vertices[d], &destPoints[d]);
226252
gluTessEndContour(butterburTesselator);
253+
254+
if(inner)
255+
{
256+
for(j = 0; j < inner.count; j++)
257+
{
258+
Array<Pointf> contour = inner[j];
259+
n = contour.count;
260+
start += n;
261+
262+
gluTessBeginContour(butterburTesselator);
263+
for(i = 0; i < n; i++, d++)
264+
gluTessVertex(butterburTesselator, (double *)&vertices[d], &destPoints[d]);
265+
gluTessEndContour(butterburTesselator);
266+
}
267+
}
227268
}
228-
start += n;
269+
else
270+
start += n;
229271
}
230272

231273
gluTessEndPolygon(butterburTesselator);

0 commit comments

Comments
 (0)