gdiplus: Make pen width depend on world transform.
This commit is contained in:
parent
4c424b3c16
commit
b7053b74ba
|
@ -99,10 +99,21 @@ static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
|
||||||
HPEN gdipen;
|
HPEN gdipen;
|
||||||
REAL width;
|
REAL width;
|
||||||
INT save_state = SaveDC(graphics->hdc);
|
INT save_state = SaveDC(graphics->hdc);
|
||||||
|
GpPointF pt[2];
|
||||||
|
|
||||||
EndPath(graphics->hdc);
|
EndPath(graphics->hdc);
|
||||||
|
|
||||||
width = pen->width * convert_unit(graphics->hdc,
|
/* Get an estimate for the amount the pen width is affected by the world
|
||||||
|
* transform. (This is similar to what some of the wine drivers do.) */
|
||||||
|
pt[0].X = 0.0;
|
||||||
|
pt[0].Y = 0.0;
|
||||||
|
pt[1].X = 1.0;
|
||||||
|
pt[1].Y = 1.0;
|
||||||
|
GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
|
||||||
|
width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
|
||||||
|
(pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
|
||||||
|
|
||||||
|
width *= pen->width * convert_unit(graphics->hdc,
|
||||||
pen->unit == UnitWorld ? graphics->unit : pen->unit);
|
pen->unit == UnitWorld ? graphics->unit : pen->unit);
|
||||||
|
|
||||||
gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb, 0, NULL);
|
gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb, 0, NULL);
|
||||||
|
@ -205,31 +216,35 @@ static void calc_curve_bezier_endp(REAL xend, REAL yend, REAL xadj, REAL yadj,
|
||||||
static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
|
static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
|
||||||
const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
|
const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
|
||||||
{
|
{
|
||||||
HGDIOBJ oldbrush, oldpen;
|
HGDIOBJ oldbrush = NULL, oldpen = NULL;
|
||||||
GpMatrix *matrix = NULL;
|
GpMatrix *matrix = NULL;
|
||||||
HBRUSH brush;
|
HBRUSH brush = NULL;
|
||||||
HPEN pen;
|
HPEN pen = NULL;
|
||||||
PointF ptf[4], *custptf = NULL;
|
PointF ptf[4], *custptf = NULL;
|
||||||
POINT pt[4], *custpt = NULL;
|
POINT pt[4], *custpt = NULL;
|
||||||
BYTE *tp = NULL;
|
BYTE *tp = NULL;
|
||||||
REAL theta, dsmall, dbig, dx, dy = 0.0;
|
REAL theta, dsmall, dbig, dx, dy = 0.0;
|
||||||
INT i, count;
|
INT i, count;
|
||||||
LOGBRUSH lb;
|
LOGBRUSH lb;
|
||||||
|
BOOL customstroke;
|
||||||
|
|
||||||
if((x1 == x2) && (y1 == y2))
|
if((x1 == x2) && (y1 == y2))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
theta = gdiplus_atan2(y2 - y1, x2 - x1);
|
theta = gdiplus_atan2(y2 - y1, x2 - x1);
|
||||||
|
|
||||||
brush = CreateSolidBrush(color);
|
customstroke = (cap == LineCapCustom) && custom && (!custom->fill);
|
||||||
lb.lbStyle = BS_SOLID;
|
if(!customstroke){
|
||||||
lb.lbColor = color;
|
brush = CreateSolidBrush(color);
|
||||||
lb.lbHatch = 0;
|
lb.lbStyle = BS_SOLID;
|
||||||
pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT,
|
lb.lbColor = color;
|
||||||
((cap == LineCapCustom) && custom && (custom->fill)) ? size : 1,
|
lb.lbHatch = 0;
|
||||||
&lb, 0, NULL);
|
pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT |
|
||||||
oldbrush = SelectObject(graphics->hdc, brush);
|
PS_JOIN_MITER, 1, &lb, 0,
|
||||||
oldpen = SelectObject(graphics->hdc, pen);
|
NULL);
|
||||||
|
oldbrush = SelectObject(graphics->hdc, brush);
|
||||||
|
oldpen = SelectObject(graphics->hdc, pen);
|
||||||
|
}
|
||||||
|
|
||||||
switch(cap){
|
switch(cap){
|
||||||
case LineCapFlat:
|
case LineCapFlat:
|
||||||
|
@ -382,10 +397,12 @@ custend:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectObject(graphics->hdc, oldbrush);
|
if(!customstroke){
|
||||||
SelectObject(graphics->hdc, oldpen);
|
SelectObject(graphics->hdc, oldbrush);
|
||||||
DeleteObject(brush);
|
SelectObject(graphics->hdc, oldpen);
|
||||||
DeleteObject(pen);
|
DeleteObject(brush);
|
||||||
|
DeleteObject(pen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Shortens the line by the given percent by changing x2, y2.
|
/* Shortens the line by the given percent by changing x2, y2.
|
||||||
|
|
Loading…
Reference in New Issue