diff --git a/test/drawtests.c b/test/drawtests.c index 990b5de3..b72dfd05 100644 --- a/test/drawtests.c +++ b/test/drawtests.c @@ -17,6 +17,10 @@ static void drawOriginal(uiAreaDrawParams *p) uiDrawBrush brush; uiDrawStrokeParams sp; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; + brush.Type = uiDrawBrushTypeSolid; brush.A = 1; @@ -150,6 +154,10 @@ static void drawArcs(uiAreaDrawParams *p) uiDrawBrush brush; uiDrawStrokeParams sp; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; + path = uiDrawNewPath(uiDrawFillModeWinding); add = (2.0 * M_PI) / 12; @@ -322,6 +330,10 @@ static void drawD2DSimpleApp(uiAreaDrawParams *p) uiDrawStrokeParams sp; int x, y; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; + d2dSolidBrush(&lightSlateGray, d2dLightSlateGray, 1.0); d2dSolidBrush(&cornflowerBlue, d2dCornflowerBlue, 1.0); @@ -390,6 +402,10 @@ static void drawD2DSolidBrush(uiAreaDrawParams *p) uiDrawBrush yellowGreen; uiDrawStrokeParams sp; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; + d2dSolidBrush(&black, d2dBlack, 1.0); d2dSolidBrush(&yellowGreen, d2dYellowGreen, 1.0); @@ -420,6 +436,10 @@ static void drawD2DLinearBrush(uiAreaDrawParams *p) uiDrawMatrix m; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; + // leave some room uiDrawMatrixSetIdentity(&m); uiDrawMatrixTranslate(&m, 25, 25); @@ -467,6 +487,10 @@ static void drawD2DRadialBrush(uiAreaDrawParams *p) uiDrawMatrix m; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; + // leave some room uiDrawMatrixSetIdentity(&m); uiDrawMatrixTranslate(&m, 25, 25); @@ -526,6 +550,10 @@ static void drawD2DPathGeometries(uiAreaDrawParams *p) uiDrawStrokeParams sp; uiDrawBrushGradientStop stops[2]; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; + // TODO this is definitely wrong but the example doesn't have the right brush in it radial.Type = uiDrawBrushTypeRadialGradient; radial.X0 = 75; @@ -694,6 +722,10 @@ static void drawD2DGeometryGroup(uiAreaDrawParams *p) uiDrawStrokeParams sp; uiDrawMatrix m; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; + alternate = uiDrawNewPath(uiDrawFillModeAlternate); uiDrawPathNewFigureWithArc(alternate, 105, 105, @@ -785,6 +817,13 @@ static void drawD2DRotate(uiAreaDrawParams *p) uiDrawStrokeParams transformsp; uiDrawMatrix m; + originalsp.Dashes = NULL; + originalsp.NumDashes = 0; + originalsp.DashPhase = 0; + transformsp.Dashes = NULL; + transformsp.NumDashes = 0; + transformsp.DashPhase = 0; + path = uiDrawNewPath(uiDrawFillModeWinding); uiDrawPathAddRectangle(path, 438.0, 301.5, 498.0 - 438.0, 361.5 - 301.5); uiDrawPathEnd(path); @@ -849,6 +888,13 @@ static void drawD2DScale(uiAreaDrawParams *p) uiDrawStrokeParams transformsp; uiDrawMatrix m; + originalsp.Dashes = NULL; + originalsp.NumDashes = 0; + originalsp.DashPhase = 0; + transformsp.Dashes = NULL; + transformsp.NumDashes = 0; + transformsp.DashPhase = 0; + path = uiDrawNewPath(uiDrawFillModeWinding); uiDrawPathAddRectangle(path, 438.0, 80.5, 498.0 - 438.0, 140.5 - 80.5); uiDrawPathEnd(path); @@ -914,6 +960,13 @@ void drawD2DSkew(uiAreaDrawParams *p) uiDrawStrokeParams transformsp; uiDrawMatrix m; + originalsp.Dashes = NULL; + originalsp.NumDashes = 0; + originalsp.DashPhase = 0; + transformsp.Dashes = NULL; + transformsp.NumDashes = 0; + transformsp.DashPhase = 0; + path = uiDrawNewPath(uiDrawFillModeWinding); uiDrawPathAddRectangle(path, 126.0, 301.5, 186.0 - 126.0, 361.5 - 301.5); uiDrawPathEnd(path); @@ -978,6 +1031,13 @@ static void drawD2DTranslate(uiAreaDrawParams *p) uiDrawStrokeParams transformsp; uiDrawMatrix m; + originalsp.Dashes = NULL; + originalsp.NumDashes = 0; + originalsp.DashPhase = 0; + transformsp.Dashes = NULL; + transformsp.NumDashes = 0; + transformsp.DashPhase = 0; + path = uiDrawNewPath(uiDrawFillModeWinding); uiDrawPathAddRectangle(path, 126.0, 80.5, 186.0 - 126.0, 140.5 - 80.5); uiDrawPathEnd(path); @@ -1021,6 +1081,13 @@ static void drawD2DMultiTransforms(uiAreaDrawParams *p) uiDrawMatrix mtranslate; uiDrawMatrix mrotate; + originalsp.Dashes = NULL; + originalsp.NumDashes = 0; + originalsp.DashPhase = 0; + transformsp.Dashes = NULL; + transformsp.NumDashes = 0; + transformsp.DashPhase = 0; + path = uiDrawNewPath(uiDrawFillModeWinding); uiDrawPathAddRectangle(path, 300.0, 40.0, 360.0 - 300.0, 100.0 - 40.0); uiDrawPathEnd(path); @@ -1100,6 +1167,10 @@ static void drawD2DComplexShape(uiAreaDrawParams *p) uiDrawStrokeParams sp; uiDrawMatrix m; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; + path = uiDrawNewPath(uiDrawFillModeWinding); uiDrawPathNewFigure(path, 0, 0); uiDrawPathLineTo(path, 200, 0); @@ -1195,6 +1266,9 @@ static void drawCSArc(uiAreaDrawParams *p) sp.Cap = uiDrawLineCapFlat; sp.Join = uiDrawLineJoinMiter; sp.MiterLimit = uiDrawDefaultMiterLimit; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; sp.Thickness = 10.0; path = uiDrawNewPath(uiDrawFillModeWinding); @@ -1255,6 +1329,9 @@ static void drawCSArcNegative(uiAreaDrawParams *p) sp.Cap = uiDrawLineCapFlat; sp.Join = uiDrawLineJoinMiter; sp.MiterLimit = uiDrawDefaultMiterLimit; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; sp.Thickness = 10.0; path = uiDrawNewPath(uiDrawFillModeWinding); @@ -1310,6 +1387,9 @@ static void drawCSClip(uiAreaDrawParams *p) sp.Cap = uiDrawLineCapFlat; sp.Join = uiDrawLineJoinMiter; sp.MiterLimit = uiDrawDefaultMiterLimit; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; path = uiDrawNewPath(uiDrawFillModeWinding); @@ -1361,6 +1441,9 @@ static void drawCSCurveRectangle(uiAreaDrawParams *p) sp.Cap = uiDrawLineCapFlat; sp.Join = uiDrawLineJoinMiter; sp.MiterLimit = uiDrawDefaultMiterLimit; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; path = uiDrawNewPath(uiDrawFillModeWinding); @@ -1430,6 +1513,9 @@ static void drawCSCurveTo(uiAreaDrawParams *p) sp.Cap = uiDrawLineCapFlat; sp.Join = uiDrawLineJoinMiter; sp.MiterLimit = uiDrawDefaultMiterLimit; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; path = uiDrawNewPath(uiDrawFillModeWinding); @@ -1452,7 +1538,44 @@ static void drawCSCurveTo(uiAreaDrawParams *p) uiDrawFreePath(path); } -// TODO dash +// dash +static void drawCSDash(uiAreaDrawParams *p) +{ + double dashes[] = { + 50.0, /* ink */ + 10.0, /* skip */ + 10.0, /* ink */ + 10.0 /* skip*/ + }; + int ndash = sizeof (dashes)/sizeof(dashes[0]); + double offset = -50.0; + + uiDrawBrush source; + uiDrawStrokeParams sp; + uiDrawPath *path; + + crsourcergba(&source, 0, 0, 0, 1); + sp.Cap = uiDrawLineCapFlat; + sp.Join = uiDrawLineJoinMiter; + sp.MiterLimit = uiDrawDefaultMiterLimit; + sp.Dashes = dashes; + sp.NumDashes = ndash; + sp.DashPhase = offset; + sp.Thickness = 10.0; + + path = uiDrawNewPath(uiDrawFillModeWinding); + uiDrawPathNewFigure(path, 128.0, 25.6); + uiDrawPathLineTo(path, 230.4, 230.4); + uiDrawPathLineTo(path, 230.4 -102.4, 230.4 + 0.0); + uiDrawPathBezierTo(path, + 51.2, 230.4, + 51.2, 128.0, + 128.0, 128.0); + uiDrawPathEnd(path); + + uiDrawStroke(p->Context, path, &source, &sp); + uiDrawFreePath(path); +} // fill and stroke2 static void drawCSFillAndStroke2(uiAreaDrawParams *p) @@ -1465,6 +1588,9 @@ static void drawCSFillAndStroke2(uiAreaDrawParams *p) sp.Cap = uiDrawLineCapFlat; sp.Join = uiDrawLineJoinMiter; sp.MiterLimit = uiDrawDefaultMiterLimit; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; path = uiDrawNewPath(uiDrawFillModeWinding); @@ -1502,6 +1628,9 @@ static void drawCSFillStyle(uiAreaDrawParams *p) sp.Cap = uiDrawLineCapFlat; sp.Join = uiDrawLineJoinMiter; sp.MiterLimit = uiDrawDefaultMiterLimit; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; sp.Thickness = 6; @@ -1566,6 +1695,9 @@ static void drawCSMultiCaps(uiAreaDrawParams *p) crsourcergba(&source, 0, 0, 0, 1); sp.Join = uiDrawLineJoinMiter; sp.MiterLimit = uiDrawDefaultMiterLimit; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; path = uiDrawNewPath(uiDrawFillModeWinding); @@ -1606,6 +1738,9 @@ static void drawCSRoundRect(uiAreaDrawParams *p) sp.Cap = uiDrawLineCapFlat; sp.Join = uiDrawLineJoinMiter; sp.MiterLimit = uiDrawDefaultMiterLimit; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; path = uiDrawNewPath(uiDrawFillModeWinding); @@ -1655,6 +1790,9 @@ static void drawCSSetLineCap(uiAreaDrawParams *p) sp.Cap = uiDrawLineCapFlat; sp.Join = uiDrawLineJoinMiter; sp.MiterLimit = uiDrawDefaultMiterLimit; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; sp.Thickness = 30.0; @@ -1709,6 +1847,9 @@ static void drawCSSetLineJoin(uiAreaDrawParams *p) sp.Cap = uiDrawLineCapFlat; sp.Join = uiDrawLineJoinMiter; sp.MiterLimit = uiDrawDefaultMiterLimit; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; sp.Thickness = 40.96; path = uiDrawNewPath(uiDrawFillModeWinding); @@ -1814,6 +1955,7 @@ static const struct drawtest tests[] = { { "cairo samples: clip", drawCSClip }, { "cairo samples: curve rectangle", drawCSCurveRectangle }, { "cairo samples: curve to", drawCSCurveTo }, + { "cairo samples: dash", drawCSDash }, { "cairo samples: fill and stroke2", drawCSFillAndStroke2 }, { "cairo samples: fill style", drawCSFillStyle }, { "cairo samples: multi segment caps", drawCSMultiCaps }, diff --git a/test/page7.c b/test/page7.c index ac15bef0..3428b1fa 100644 --- a/test/page7.c +++ b/test/page7.c @@ -34,6 +34,9 @@ static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p) sp.Cap = uiDrawLineCapFlat; sp.Join = uiDrawLineJoinMiter; sp.MiterLimit = uiDrawDefaultMiterLimit; + sp.Dashes = NULL; + sp.NumDashes = 0; + sp.DashPhase = 0; startText = uiEntryText(startAngle); sweepText = uiEntryText(sweep); diff --git a/ui.h b/ui.h index faca117e..82f1e735 100644 --- a/ui.h +++ b/ui.h @@ -288,8 +288,6 @@ struct uiAreaDrawParams { intmax_t VScrollPos; }; -// TODO dotting/dashing - typedef struct uiDrawPath uiDrawPath; typedef struct uiDrawBrush uiDrawBrush; typedef struct uiDrawStrokeParams uiDrawStrokeParams; @@ -381,6 +379,11 @@ struct uiDrawStrokeParams { uiDrawLineJoin Join; double Thickness; double MiterLimit; + double *Dashes; + // TOOD what if this is 1 on Direct2D? + // TODO what if a dash is 0 on Cairo or Quartz? + size_t NumDashes; + double DashPhase; }; _UI_EXTERN uiDrawPath *uiDrawNewPath(uiDrawFillMode fillMode); diff --git a/unix/draw.c b/unix/draw.c index 5cf1e546..e17f33a7 100644 --- a/unix/draw.c +++ b/unix/draw.c @@ -278,6 +278,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStro break; } cairo_set_line_width(c->cr, p->Thickness); + cairo_set_dash(c->cr, p->Dashes, p->NumDashes, p->DashPhase); cairo_stroke(c->cr); cairo_pattern_destroy(pat); }