Skip to content

Commit

Permalink
Implemented dashing on OS X.
Browse files Browse the repository at this point in the history
  • Loading branch information
andlabs committed Oct 16, 2015
1 parent 8119a69 commit b4cbf79
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion darwin/draw.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStro
{
CGLineCap cap;
CGLineJoin join;
CGPathRef dashPath;
CGFloat *dashes;
size_t i;
uiDrawPath p2;

if (!path->ended)
Expand Down Expand Up @@ -153,13 +156,29 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStro
}

// create a temporary path identical to the previous one
dashPath = (CGPathRef) path->path;
if (p->NumDashes != 0) {
dashes = (CGFloat *) uiAlloc(p->NumDashes * sizeof (CGFloat), "CGFloat[]");
for (i = 0; i < p->NumDashes; i++)
dashes[i] = p->Dashes[i];
dashPath = CGPathCreateCopyByDashingPath(path->path,
NULL,
p->DashPhase,
dashes,
p->NumDashes);
uiFree(dashes);
}
// the documentation is wrong: this produces a path suitable for calling CGPathCreateCopyByStrokingPath(), not for filling directly
// the cast is safe; we never modify the CGPathRef and always cast it back to a CGPathRef anyway
p2.path = (CGMutablePathRef) CGPathCreateCopyByStrokingPath(path->path,
p2.path = (CGMutablePathRef) CGPathCreateCopyByStrokingPath(dashPath,
NULL,
p->Thickness,
cap,
join,
p->MiterLimit);
if (p->NumDashes != 0)
CGPathRelease(dashPath);

// always draw stroke fills using the winding rule
// otherwise intersecting figures won't draw correctly
p2.fillMode = uiDrawFillModeWinding;
Expand Down
2 changes: 1 addition & 1 deletion windows/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeP
&style);
if (hr != S_OK)
logHRESULT("error creating stroke style in uiDrawStroke()", hr);
if (dashes != NULL)
if (sp->NumDashes != 0)
uiFree(dashes);

cliplayer = applyClip(c);
Expand Down

0 comments on commit b4cbf79

Please sign in to comment.