From 52d662f304a58ad44ece8efd6f5489cc3a04d942 Mon Sep 17 00:00:00 2001 From: chirsz-ever Date: Sun, 12 Apr 2020 22:15:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20`setlinewidth`=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E7=9A=84=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正 `setlinewidth` 为立即更新 增加了辅助函数 `upattern2array` --- src/egegapi.cpp | 103 +++++++++++++++++++++++++++--------------------- 1 file changed, 59 insertions(+), 44 deletions(-) diff --git a/src/egegapi.cpp b/src/egegapi.cpp index 92075c17..0d6e95f1 100644 --- a/src/egegapi.cpp +++ b/src/egegapi.cpp @@ -616,6 +616,34 @@ getcolor(PIMAGE pimg) { return 0xFFFFFFFF; } +// ελģʽתΪ style +// ExtCreatePen +// õԪ +static int upattern2array(unsigned short upattern, DWORD style[]) { + int n, bn = 0, len = 1; + int st = upattern & 1; + for (n = 1; n < 16; n++) { + if (upattern & (1<m_linestyle.upattern; - int n, bn = 0, len = 1, st = 0; + int bn; lbr.lbColor = lPen.lopnColor; lbr.lbStyle = BS_SOLID; lbr.lbHatch = 0; - st = upattern & 1; - for (n = 1; n < 16; n++) { - if (upattern & (1<m_linestyle.thickness, &lbr, bn, style); } else { hpen = CreatePenIndirect(&lPen); @@ -1389,30 +1398,11 @@ setlinestyle(int linestyle, unsigned short upattern, int thickness, PIMAGE pimg) if (linestyle == PS_USERSTYLE) { DWORD style[20] = {0}; LOGBRUSH lbr; - int n, bn = 0, len = 1, st = 0; + int bn; lbr.lbColor = lpen.lopnColor; lbr.lbStyle = BS_SOLID; lbr.lbHatch = 0; - st = upattern & 1; - for (n = 1; n < 16; n++) { - if (upattern & (1<m_linestyle.thickness = (int)width; - img->m_linewidth = width; + + if (img && img->m_hDC) { + HPEN hpen; + int linestyle = img->m_linestyle.linestyle; + img->m_linestyle.thickness = (int)width; + img->m_linewidth = width; + + if (linestyle == PS_USERSTYLE) { + DWORD style[20] = {0}; + LOGBRUSH lbr; + int bn; + lbr.lbColor = img->m_color; + lbr.lbStyle = BS_SOLID; + lbr.lbHatch = 0; + bn = upattern2array(img->m_linestyle.upattern, style); + hpen = ExtCreatePen(PS_GEOMETRIC, (int)width, &lbr, bn, style); + } else { + LOGPEN lpen = {0}; + lpen.lopnColor = img->m_color; + lpen.lopnWidth.x = (LONG)width; + lpen.lopnStyle = linestyle; + hpen = CreatePenIndirect(&lpen); + } + if (hpen) { + DeleteObject(SelectObject(img->m_hDC, hpen)); + } + } CONVERT_IMAGE_END; } From 5091f9b3875c528c6f3cce2a3c62134f089dd088 Mon Sep 17 00:00:00 2001 From: chirsz-ever Date: Mon, 13 Apr 2020 01:00:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=20`setlinestyle?= =?UTF-8?q?`=20=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 设置 PS_USERSTYLE 得到正确间隔 改进了 upattern 转换算法 在 `setcolor`、`setlinestyle`、`setlinewidth` 中正确地 地使用 `ExtCreatePen` --- src/egegapi.cpp | 139 ++++++++++++++++++++++++++---------------------- 1 file changed, 74 insertions(+), 65 deletions(-) diff --git a/src/egegapi.cpp b/src/egegapi.cpp index 0d6e95f1..62dca6fe 100644 --- a/src/egegapi.cpp +++ b/src/egegapi.cpp @@ -617,31 +617,35 @@ getcolor(PIMAGE pimg) { } // ελģʽתΪ style -// ExtCreatePen -// õԪ +// ExtCreatePen С +// ֵΪõԪ static int upattern2array(unsigned short upattern, DWORD style[]) { - int n, bn = 0, len = 1; - int st = upattern & 1; + int n, segments = 0, segmentLength = 1; + int state = !!(upattern & 1); for (n = 1; n < 16; n++) { - if (upattern & (1<m_hDC) { - LOGPEN lPen; - HPEN hpen; - img->m_color = color; - color = RGBTOBGR(color); - lPen.lopnColor = color; - lPen.lopnStyle = img->m_linestyle.linestyle; - lPen.lopnWidth.x = img->m_linestyle.thickness; + int linestyle = img->m_linestyle.linestyle; + + COLORREF bgrcolor = RGBTOBGR(color); - SetTextColor(img->m_hDC, color); - if (lPen.lopnStyle == PS_USERSTYLE) { + LOGBRUSH lbr; + lbr.lbColor = bgrcolor; + lbr.lbStyle = BS_SOLID; + lbr.lbHatch = 0; + + // ЩԻȷʾЧ + int ls = linestyle|PS_GEOMETRIC|PS_ENDCAP_ROUND|PS_JOIN_ROUND; + + HPEN hpen; + if (linestyle == USERBIT_LINE) { DWORD style[20] = {0}; - LOGBRUSH lbr; unsigned short upattern = img->m_linestyle.upattern; - int bn; - lbr.lbColor = lPen.lopnColor; - lbr.lbStyle = BS_SOLID; - lbr.lbHatch = 0; - bn = upattern2array(upattern, style); - hpen = ExtCreatePen(PS_GEOMETRIC, img->m_linestyle.thickness, &lbr, bn, style); + int bn = upattern2array(upattern, style); + hpen = ExtCreatePen(ls, img->m_linestyle.thickness, &lbr, bn, style); } else { - hpen = CreatePenIndirect(&lPen); + hpen = ExtCreatePen(ls, img->m_linestyle.thickness, &lbr, 0, NULL); } if (hpen) { DeleteObject(SelectObject(img->m_hDC, hpen)); } + + SetTextColor(img->m_hDC, bgrcolor); } CONVERT_IMAGE_END; } @@ -1384,28 +1389,32 @@ getlinestyle(int *plinestyle, unsigned short *pupattern, int *pthickness, PIMAGE void setlinestyle(int linestyle, unsigned short upattern, int thickness, PIMAGE pimg) { PIMAGE img = CONVERT_IMAGE_CONST(pimg); - LOGPEN lpen = {0}; - lpen.lopnColor = RGBTOBGR(getcolor(pimg)); + + if (!(img && img->m_hDC)) { + CONVERT_IMAGE_END; + return; + } + img->m_linestyle.thickness = thickness; img->m_linewidth = (float)thickness; img->m_linestyle.linestyle = linestyle; img->m_linestyle.upattern = upattern; - lpen.lopnWidth.x = thickness; - lpen.lopnStyle = linestyle; + LOGBRUSH lbr; + lbr.lbColor = RGBTOBGR(img->m_color); + lbr.lbStyle = BS_SOLID; + lbr.lbHatch = 0; + + // ЩԻȷʾЧ + int ls = linestyle|PS_GEOMETRIC|PS_ENDCAP_ROUND|PS_JOIN_ROUND; HPEN hpen; - if (linestyle == PS_USERSTYLE) { + if (linestyle == USERBIT_LINE) { DWORD style[20] = {0}; - LOGBRUSH lbr; - int bn; - lbr.lbColor = lpen.lopnColor; - lbr.lbStyle = BS_SOLID; - lbr.lbHatch = 0; - bn = upattern2array(upattern, style); - hpen = ExtCreatePen(PS_GEOMETRIC, thickness, &lbr, bn, style); + int bn = upattern2array(upattern, style); + hpen = ExtCreatePen(ls, thickness, &lbr, bn, style); } else { - hpen = CreatePenIndirect(&lpen); + hpen = ExtCreatePen(ls, thickness, &lbr, 0, NULL); } if (hpen) { DeleteObject(SelectObject(img->m_hDC, hpen)); @@ -1418,26 +1427,26 @@ setlinewidth(float width, PIMAGE pimg) { PIMAGE img = CONVERT_IMAGE_CONST(pimg); if (img && img->m_hDC) { - HPEN hpen; + int thickness = (int)width; int linestyle = img->m_linestyle.linestyle; - img->m_linestyle.thickness = (int)width; + img->m_linestyle.thickness = thickness; img->m_linewidth = width; - if (linestyle == PS_USERSTYLE) { + LOGBRUSH lbr; + lbr.lbColor = RGBTOBGR(img->m_color); + lbr.lbStyle = BS_SOLID; + lbr.lbHatch = 0; + + // ЩԻȷʾЧ + int ls = linestyle|PS_GEOMETRIC|PS_ENDCAP_ROUND|PS_JOIN_ROUND; + + HPEN hpen; + if (linestyle == USERBIT_LINE) { DWORD style[20] = {0}; - LOGBRUSH lbr; - int bn; - lbr.lbColor = img->m_color; - lbr.lbStyle = BS_SOLID; - lbr.lbHatch = 0; - bn = upattern2array(img->m_linestyle.upattern, style); - hpen = ExtCreatePen(PS_GEOMETRIC, (int)width, &lbr, bn, style); + int bn = upattern2array(img->m_linestyle.upattern, style); + hpen = ExtCreatePen(ls, thickness, &lbr, bn, style); } else { - LOGPEN lpen = {0}; - lpen.lopnColor = img->m_color; - lpen.lopnWidth.x = (LONG)width; - lpen.lopnStyle = linestyle; - hpen = CreatePenIndirect(&lpen); + hpen = ExtCreatePen(ls, thickness, &lbr, 0, NULL); } if (hpen) { DeleteObject(SelectObject(img->m_hDC, hpen));