/
PostScriptWraps.psw
58 lines (52 loc) · 1.86 KB
/
PostScriptWraps.psw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* PostScript Wrap Functions */
/*
Draw Rounded Rectangle function. Additional information:
1. https://nacho4d-nacho4d.blogspot.com/2011/05/bezier-paths-rounded-corners-rectangles.html
2. http://spencermortensen.com/articles/bezier-circle/
3. https://stackoverflow.com/a/27863181
C++/Qt5 equivalent method:
```
void drawRoundedRect(QPainter &painter, const QColor &color, const QRect &rect, int rad) {
int left = rect.left(), right = rect.right(), top = rect.top(), bottom = rect.bottom();
float offset = rad * (1 - 0.551915024494);
QPainterPath p;
p.moveTo(left + rad, top);
p.lineTo(right - rad, top);
p.cubicTo(right - offset, top, right, top + offset, right, top + rad);
p.lineTo(right, bottom - rad);
p.cubicTo(right, bottom - offset, right - offset, bottom, right - rad, bottom);
p.lineTo(left + rad, bottom);
p.cubicTo(left + offset, bottom, left, bottom - offset, left, bottom - rad);
p.lineTo(left, top + rad);
p.cubicTo(left, top + offset, left + offset, top, left + rad, top);
p.closeSubpath();
painter.fillPath(p, color);
}
```
*/
defineps PSWdrawRectRounded(float r, g, b, left, right, top, bottom, rad)
/off 1 0.551915024494 sub rad mul def
r g b setrgbcolor
1.0 setalpha
left rad add top moveto
right rad sub top lineto
right off sub top right top off add right top rad add curveto
right bottom rad sub lineto
right bottom off sub right off sub bottom right rad sub bottom curveto
left rad add bottom lineto
left off add bottom left bottom off sub left bottom rad sub curveto
left top rad add lineto
left top off add left off add top left rad add top curveto
fill
endps
defineps PSWfade(float r, g, b, a, width, height)
r g b setrgbcolor
a setalpha
0 0 width height Sover compositerect
endps
defineps PSWdrawText(float r, g, b, x, y; char *text)
r g b setrgbcolor
1.0 setalpha
x y moveto
(text) show
endps