[PATCH v2] gdiplus: Scale widened dashes to the pen width.
Zebediah Figura
z.figura12 at gmail.com
Tue Jun 27 17:27:18 CDT 2017
v2: more correct approach
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
dlls/gdiplus/graphicspath.c | 14 ++++++++++----
dlls/gdiplus/tests/graphicspath.c | 27 +++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/dlls/gdiplus/graphicspath.c b/dlls/gdiplus/graphicspath.c
index 5fedd07e4ea..5d82a770f7f 100644
--- a/dlls/gdiplus/graphicspath.c
+++ b/dlls/gdiplus/graphicspath.c
@@ -2063,6 +2063,7 @@ static void widen_dashed_figure(GpPath *path, GpPen *pen, int start, int end,
REAL dash_pos=0.0;
int dash_index=0;
const REAL *dash_pattern;
+ REAL *dash_pattern_scaled;
int dash_count;
GpPointF *tmp_points;
REAL segment_dy;
@@ -2101,6 +2102,12 @@ static void widen_dashed_figure(GpPath *path, GpPen *pen, int start, int end,
break;
}
+ dash_pattern_scaled = heap_alloc(dash_count * sizeof(REAL));
+ if (!dash_pattern_scaled) return;
+
+ for (i = 0; i < dash_count; i++)
+ dash_pattern_scaled[i] = pen->width * dash_pattern[i];
+
tmp_points = heap_alloc_zero((end - start + 2) * sizeof(GpPoint));
if (!tmp_points) return; /* FIXME */
@@ -2149,7 +2156,7 @@ static void widen_dashed_figure(GpPath *path, GpPen *pen, int start, int end,
}
}
- if (dash_pattern[dash_index] - dash_pos > segment_length - segment_pos)
+ if (dash_pattern_scaled[dash_index] - dash_pos > segment_length - segment_pos)
{
/* advance to next segment */
if ((dash_index % 2) == 0)
@@ -2163,7 +2170,7 @@ static void widen_dashed_figure(GpPath *path, GpPen *pen, int start, int end,
else
{
/* advance to next dash in pattern */
- segment_pos += dash_pattern[dash_index] - dash_pos;
+ segment_pos += dash_pattern_scaled[dash_index] - dash_pos;
dash_pos = 0.0;
if (++dash_index == dash_count)
dash_index = 0;
@@ -2175,8 +2182,7 @@ static void widen_dashed_figure(GpPath *path, GpPen *pen, int start, int end,
if (dash_index % 2 == 0 && num_tmp_points != 0)
{
/* last dash overflows last segment */
- tmp_points[num_tmp_points] = path->pathdata.Points[end];
- widen_open_figure(tmp_points, pen, 0, num_tmp_points,
+ widen_open_figure(tmp_points, pen, 0, num_tmp_points-1,
draw_start_cap ? pen->startcap : LineCapFlat, pen->customstart,
closed ? LineCapFlat : pen->endcap, pen->customend, last_point);
}
diff --git a/dlls/gdiplus/tests/graphicspath.c b/dlls/gdiplus/tests/graphicspath.c
index c44ed5e4240..2a94e845c92 100644
--- a/dlls/gdiplus/tests/graphicspath.c
+++ b/dlls/gdiplus/tests/graphicspath.c
@@ -1065,6 +1065,17 @@ static path_test_t widenline_wide_path[] = {
{5.0, 20.0, PathPointTypeLine|PathPointTypeCloseSubpath, 0, 0} /*3*/
};
+static path_test_t widenline_dash_path[] = {
+ {5.0, 0.0, PathPointTypeStart, 0, 0}, /*0*/
+ {35.0, 0.0, PathPointTypeLine, 0, 0}, /*1*/
+ {35.0, 10.0, PathPointTypeLine, 0, 0}, /*2*/
+ {5.0, 10.0, PathPointTypeLine|PathPointTypeCloseSubpath, 0, 0}, /*3*/
+ {45.0, 0.0, PathPointTypeStart, 0, 0}, /*4*/
+ {50.0, 0.0, PathPointTypeLine, 0, 0}, /*5*/
+ {50.0, 10.0, PathPointTypeLine, 0, 0}, /*6*/
+ {45.0, 10.0, PathPointTypeLine|PathPointTypeCloseSubpath, 0, 0}, /*7*/
+ };
+
static void test_widen(void)
{
GpStatus status;
@@ -1139,6 +1150,22 @@ static void test_widen(void)
status = GdipScaleMatrix(m, 1.0, 0.5, MatrixOrderAppend);
expect(Ok, status);
+ /* dashed line */
+ status = GdipResetPath(path);
+ expect(Ok, status);
+ status = GdipAddPathLine(path, 5.0, 5.0, 50.0, 5.0);
+ expect(Ok, status);
+
+ status = GdipSetPenDashStyle(pen, DashStyleDash);
+ expect(Ok, status);
+
+ status = GdipWidenPath(path, pen, m, 1.0);
+ expect(Ok, status);
+ ok_path(path, widenline_dash_path, sizeof(widenline_dash_path)/sizeof(path_test_t), FALSE);
+
+ status = GdipSetPenDashStyle(pen, DashStyleSolid);
+ expect(Ok, status);
+
/* pen width in UnitWorld */
GdipDeletePen(pen);
status = GdipCreatePen1(0xffffffff, 10.0, UnitWorld, &pen);
--
2.13.1
More information about the wine-patches
mailing list