Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正关于线型设置的 bug #13

Merged
merged 2 commits into from
Apr 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 94 additions & 70 deletions src/egegapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,56 +616,70 @@ getcolor(PIMAGE pimg) {
return 0xFFFFFFFF;
}

// ���������ε�λģʽת��Ϊ style ����
// ���� ExtCreatePen ��
// ����ֵΪ�õ�������Ԫ������
static int upattern2array(unsigned short upattern, DWORD style[]) {
int n, segments = 0, segmentLength = 1;
int state = !!(upattern & 1);
for (n = 1; n < 16; n++) {
int currentBit = !!(upattern & (1<<n));
if (state == currentBit) {
segmentLength += 1;
} else {
state = currentBit;
style[segments] = segmentLength;
segments += 1;
segmentLength = 1;
}
}
style[segments] = segmentLength;
segments += 1;

// �� upattern �� 0 ��ͷ��Ϊż����
if (!(upattern & 1) && segments % 2 == 0) {
DWORD p0 = style[0];
for (int i = 0; i < segments - 1; ++i) {
style[i] = style[i + 1];
}
style[segments - 1] = p0;
}

return segments;
}

void
setcolor(color_t color, PIMAGE pimg) {
PIMAGE img = CONVERT_IMAGE(pimg);

if (img && img->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);

LOGBRUSH lbr;
lbr.lbColor = bgrcolor;
lbr.lbStyle = BS_SOLID;
lbr.lbHatch = 0;

// ������Щ�����Ի����ȷ����ʾЧ��
int ls = linestyle|PS_GEOMETRIC|PS_ENDCAP_ROUND|PS_JOIN_ROUND;

SetTextColor(img->m_hDC, color);
if (lPen.lopnStyle == PS_USERSTYLE) {
HPEN hpen;
if (linestyle == USERBIT_LINE) {
DWORD style[20] = {0};
LOGBRUSH lbr;
unsigned short upattern = img->m_linestyle.upattern;
int n, bn = 0, len = 1, st = 0;
lbr.lbColor = lPen.lopnColor;
lbr.lbStyle = BS_SOLID;
lbr.lbHatch = 0;
st = upattern & 1;
for (n = 1; n < 16; n++) {
if (upattern & (1<<n)) {
if (st == 0) {
st = 1;
style[bn++] = len;
len = 1;
} else {
len++;
}
} else {
if (st == 0) {
len++;
} else {
st = 0;
style[bn++] = len;
len = 1;
}
}
}
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;
}
Expand Down Expand Up @@ -1375,47 +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 n, bn = 0, len = 1, st = 0;
lbr.lbColor = lpen.lopnColor;
lbr.lbStyle = BS_SOLID;
lbr.lbHatch = 0;
st = upattern & 1;
for (n = 1; n < 16; n++) {
if (upattern & (1<<n)) {
if (st == 0) {
st = 1;
style[bn++] = len;
len = 1;
} else {
len++;
}
} else {
if (st == 0) {
len++;
} else {
st = 0;
style[bn++] = len;
len = 1;
}
}
}
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));
Expand All @@ -1426,8 +1425,33 @@ setlinestyle(int linestyle, unsigned short upattern, int thickness, PIMAGE pimg)
void
setlinewidth(float width, PIMAGE pimg) {
PIMAGE img = CONVERT_IMAGE_CONST(pimg);
img->m_linestyle.thickness = (int)width;
img->m_linewidth = width;

if (img && img->m_hDC) {
int thickness = (int)width;
int linestyle = img->m_linestyle.linestyle;
img->m_linestyle.thickness = thickness;
img->m_linewidth = width;

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};
int bn = upattern2array(img->m_linestyle.upattern, style);
hpen = ExtCreatePen(ls, thickness, &lbr, bn, style);
} else {
hpen = ExtCreatePen(ls, thickness, &lbr, 0, NULL);
}
if (hpen) {
DeleteObject(SelectObject(img->m_hDC, hpen));
}
}
CONVERT_IMAGE_END;
}

Expand Down