summaryrefslogtreecommitdiffstats
path: root/win/tkWinGDI.c
diff options
context:
space:
mode:
Diffstat (limited to 'win/tkWinGDI.c')
-rw-r--r--win/tkWinGDI.c334
1 files changed, 183 insertions, 151 deletions
diff --git a/win/tkWinGDI.c b/win/tkWinGDI.c
index bcc7796..6290979 100644
--- a/win/tkWinGDI.c
+++ b/win/tkWinGDI.c
@@ -57,7 +57,7 @@ static int GdiGetColor(Tcl_Obj *nameObj, COLORREF *color);
*/
static int GdiMakeLogFont(Tcl_Interp *interp, const char *str,
LOGFONTW *lf, HDC hDC);
-static int GdiMakePen(Tcl_Interp *interp, int width,
+static int GdiMakePen(Tcl_Interp *interp, double dwidth,
int dashstyle, const char *dashstyledata,
int capstyle, int joinstyle,
int stipplestyle, const char *stippledata,
@@ -144,7 +144,7 @@ static const struct gdi_command {
static int GdiArc(
TCL_UNUSED(void *),
Tcl_Interp *interp,
- int argc,
+ int objc,
Tcl_Obj *const *objv)
{
static const char usage_message[] =
@@ -153,12 +153,12 @@ static int GdiArc(
"-fill color -outline color "
"-width dimension -dash dashrule "
"-outlinestipple ignored -stipple ignored\n" ;
- int x1, y1, x2, y2;
+ double x1, y1, x2, y2;
int xr0, yr0, xr1, yr1;
HDC hDC;
double extent = 0.0, start = 0.0;
DrawFunc drawfunc;
- int width = 0;
+ double width = 0.0;
HPEN hPen;
COLORREF linecolor = 0, fillcolor = BS_NULL;
int dolinecolor = 0, dofillcolor = 0;
@@ -171,23 +171,23 @@ static int GdiArc(
drawfunc = Pie;
/* Verrrrrry simple for now.... */
- if (argc < 6) {
+ if (objc < 6) {
Tcl_AppendResult(interp, usage_message, (char *)NULL);
return TCL_ERROR;
}
hDC = printDC;
- if ((Tcl_GetIntFromObj(interp, objv[2], &x1) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[3], &y1) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[4], &x2) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[5], &y2) != TCL_OK)) {
+ if ((Tcl_GetDoubleFromObj(interp, objv[2], &x1) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[3], &y1) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[4], &x2) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[5], &y2) != TCL_OK)) {
return TCL_ERROR;
}
- argc -= 6;
+ objc -= 6;
objv += 6;
- while (argc >= 2) {
+ while (objc >= 2) {
if (strcmp(Tcl_GetString(objv[0]), "-extent") == 0) {
extent = atof(Tcl_GetString(objv[1]));
} else if (strcmp(Tcl_GetString(objv[0]), "-start") == 0) {
@@ -214,7 +214,7 @@ static int GdiArc(
} else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
/* ignored */
} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
- if (Tcl_GetIntFromObj(interp, objv[1], &width)) {
+ if (Tcl_GetDoubleFromObj(interp, objv[1], &width)) {
return TCL_ERROR;
}
} else if (strcmp(Tcl_GetString(objv[0]), "-dash") == 0) {
@@ -227,7 +227,7 @@ static int GdiArc(
Tcl_AppendResult(interp, usage_message, (char *)NULL);
return TCL_ERROR;
}
- argc -= 2;
+ objc -= 2;
objv += 2;
}
xr0 = xr1 = (x1 + x2) / 2;
@@ -368,7 +368,7 @@ static int GdiImage(
static int GdiPhoto(
TCL_UNUSED(void *),
Tcl_Interp *interp,
- int argc,
+ int objc,
Tcl_Obj *const *objv)
{
static const char usage_message[] =
@@ -392,7 +392,7 @@ static int GdiPhoto(
*/
/* HDC is required. */
- if (argc < 2) {
+ if (objc < 2) {
Tcl_AppendResult(interp, usage_message, (char *)NULL);
return TCL_ERROR;
}
@@ -412,13 +412,13 @@ static int GdiPhoto(
}
/* Parse the command line arguments. */
- for (j = 2; j < argc; j++) {
+ for (j = 2; j < objc; j++) {
if (strcmp(Tcl_GetString(objv[j]), "-destination") == 0) {
double x, y, w, h;
int count = 0;
char dummy;
- if (j < argc) {
+ if (j < objc) {
count = sscanf(Tcl_GetString(objv[++j]), "%lf%lf%lf%lf%c",
&x, &y, &w, &h, &dummy);
}
@@ -563,7 +563,7 @@ static int Bezierize(
POINT* polypoints,
int npoly,
int nStep,
- POINT* bpointptr)
+ POINT** bpointptr)
{
/* First, translate my points into a list of doubles. */
double *inPointList, *outPointList;
@@ -606,7 +606,7 @@ static int Bezierize(
bpoints[n].y = (long)outPointList[2*n + 1];
}
ckfree(outPointList);
- *bpointptr = *bpoints;
+ *bpointptr = bpoints;
return nbpoints;
}
@@ -626,7 +626,7 @@ static int Bezierize(
static int GdiLine(
TCL_UNUSED(void *),
Tcl_Interp *interp,
- int argc,
+ int objc,
Tcl_Obj *const *objv)
{
static const char usage_message[] =
@@ -646,7 +646,7 @@ static int GdiLine(
LOGBRUSH lbrush;
HBRUSH hBrush = NULL;
- int width = 0;
+ double width = 0.0;
COLORREF linecolor = 0;
int dolinecolor = 0;
int dosmooth = 0;
@@ -657,36 +657,41 @@ static int GdiLine(
int dodash = 0;
const char *dashdata = 0;
+ double p1x, p1y, p2x, p2y;
arrowshape[0] = 8;
arrowshape[1] = 10;
arrowshape[2] = 3;
/* Verrrrrry simple for now.... */
- if (argc < 6) {
+ if (objc < 6) {
Tcl_AppendResult(interp, usage_message, (char *)NULL);
return TCL_ERROR;
}
hDC = printDC;
- polypoints = (POINT *)attemptckalloc((argc - 1) * sizeof(POINT));
+ polypoints = (POINT *)attemptckalloc((objc - 1) * sizeof(POINT));
if (polypoints == 0) {
Tcl_AppendResult(interp, "Out of memory in GdiLine", (char *)NULL);
return TCL_ERROR;
}
- if ((Tcl_GetIntFromObj(interp, objv[2], (int *)&polypoints[0].x) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[3], (int *)&polypoints[0].y) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[4], (int *)&polypoints[1].x) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[5], (int *)&polypoints[1].y) != TCL_OK)
+ if ((Tcl_GetDoubleFromObj(interp, objv[2], &p1x) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[3], &p1y) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[4], &p2x) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[5], &p2y) != TCL_OK)
) {
return TCL_ERROR;
}
- argc -= 6;
+ polypoints[0].x = floor(p1x+0.5);
+ polypoints[0].y = floor(p1y+0.5);
+ polypoints[1].x = floor(p2x+0.5);
+ polypoints[1].y = floor(p2y+0.5);
+ objc -= 6;
objv += 6;
npoly = 2;
- while (argc >= 2) {
+ while (objc >= 2) {
/* Check for a number. */
x = strtoul(Tcl_GetString(objv[0]), &strend, 0);
if (strend > Tcl_GetString(objv[0])) {
@@ -697,7 +702,7 @@ static int GdiLine(
polypoints[npoly].x = x;
polypoints[npoly].y = y;
npoly++;
- argc -= 2;
+ objc -= 2;
objv += 2;
} else {
/* Only one number... Assume a usage error. */
@@ -717,7 +722,7 @@ static int GdiLine(
doarrow = 1;
}
objv += 2;
- argc -= 2;
+ objc -= 2;
} else if (strcmp(Tcl_GetString(*objv), "-arrowshape") == 0) {
/* List of 3 numbers--set arrowshape array. */
int a1, a2, a3;
@@ -732,19 +737,19 @@ static int GdiLine(
/* Else the argument was bad. */
objv += 2;
- argc -= 2;
+ objc -= 2;
} else if (strcmp(Tcl_GetString(*objv), "-capstyle") == 0) {
objv += 2;
- argc -= 2;
+ objc -= 2;
} else if (strcmp(Tcl_GetString(*objv), "-fill") == 0) {
if (GdiGetColor(objv[1], &linecolor)) {
dolinecolor = 1;
}
objv += 2;
- argc -= 2;
+ objc -= 2;
} else if (strcmp(Tcl_GetString(*objv), "-joinstyle") == 0) {
objv += 2;
- argc -= 2;
+ objc -= 2;
} else if (strcmp(Tcl_GetString(*objv), "-smooth") == 0) {
/* Argument is true/false or 1/0 or bezier. */
if (Tcl_GetString(objv[1])) {
@@ -759,35 +764,35 @@ static int GdiLine(
break;
}
objv += 2;
- argc -= 2;
+ objc -= 2;
}
} else if (strcmp(Tcl_GetString(*objv), "-splinesteps") == 0) {
if (Tcl_GetIntFromObj(interp, objv[1], &nStep) != TCL_OK) {
return TCL_ERROR;
}
objv += 2;
- argc -= 2;
+ objc -= 2;
} else if (strcmp(Tcl_GetString(*objv), "-dash") == 0) {
if (Tcl_GetString(objv[1])) {
dodash = 1;
dashdata = Tcl_GetString(objv[1]);
}
objv += 2;
- argc -= 2;
+ objc -= 2;
} else if (strcmp(Tcl_GetString(*objv), "-dashoffset") == 0) {
objv += 2;
- argc -= 2;
+ objc -= 2;
} else if (strcmp(Tcl_GetString(*objv), "-stipple") == 0) {
objv += 2;
- argc -= 2;
+ objc -= 2;
} else if (strcmp(Tcl_GetString(*objv), "-width") == 0) {
- if (Tcl_GetIntFromObj(interp, objv[1], &width) != TCL_OK) {
+ if (Tcl_GetDoubleFromObj(interp, objv[1], &width) != TCL_OK) {
return TCL_ERROR;
}
objv += 2;
- argc -= 2;
+ objc -= 2;
} else { /* It's an unknown argument!. */
- argc--;
+ objc--;
objv++;
}
/* Check for arguments
@@ -806,15 +811,15 @@ static int GdiLine(
if (dosmooth) { /* Use PolyBezier. */
int nbpoints;
- POINT *bpoints = 0;
+ POINT *bpoints = NULL;
- nbpoints = Bezierize(polypoints,npoly,nStep,bpoints);
+ nbpoints = Bezierize(polypoints,npoly,nStep,&bpoints);
if (nbpoints > 0) {
Polyline(hDC, bpoints, nbpoints);
} else {
Polyline(hDC, polypoints, npoly); /* Out of memory? Just draw a regular line. */
}
- if (bpoints != 0) {
+ if (bpoints) {
ckfree(bpoints);
}
} else {
@@ -927,16 +932,16 @@ static int GdiLine(
static int GdiOval(
TCL_UNUSED(void *),
Tcl_Interp *interp,
- int argc,
+ int objc,
Tcl_Obj *const *objv)
{
static const char usage_message[] =
"::tk::print::_gdi oval hdc x1 y1 x2 y2 -fill color -outline color "
"-stipple bitmap -width linewid";
- int x1, y1, x2, y2;
+ double x1, y1, x2, y2;
HDC hDC;
HPEN hPen;
- int width = 0;
+ double width = 0.0;
COLORREF linecolor = 0, fillcolor = 0;
int dolinecolor = 0, dofillcolor = 0;
HBRUSH hBrush = NULL;
@@ -947,33 +952,33 @@ static int GdiOval(
const char *dashdata = 0;
/* Verrrrrry simple for now.... */
- if (argc < 6) {
+ if (objc < 6) {
Tcl_AppendResult(interp, usage_message, (char *)NULL);
return TCL_ERROR;
}
hDC = printDC;
- if ((Tcl_GetIntFromObj(interp, objv[2], &x1) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[3], &y1) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[4], &x2) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[5], &y2) != TCL_OK)) {
+ if ((Tcl_GetDoubleFromObj(interp, objv[2], &x1) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[3], &y1) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[4], &x2) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[5], &y2) != TCL_OK)) {
return TCL_ERROR;
}
if (x1 > x2) {
- int x3 = x1;
+ double x3 = x1;
x1 = x2;
x2 = x3;
}
if (y1 > y2) {
- int y3 = y1;
+ double y3 = y1;
y1 = y2;
y2 = y3;
}
- argc -= 6;
+ objc -= 6;
objv += 6;
- while (argc > 0) {
+ while (objc > 0) {
/* Now handle any other arguments that occur. */
if (strcmp(Tcl_GetString(objv[0]), "-fill") == 0) {
if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &fillcolor)) {
@@ -987,7 +992,7 @@ static int GdiOval(
/* Not actually implemented */
} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
if (Tcl_GetString(objv[1])) {
- if (Tcl_GetIntFromObj(interp, objv[1], &width) != TCL_OK) {
+ if (Tcl_GetDoubleFromObj(interp, objv[1], &width) != TCL_OK) {
return TCL_ERROR;
}
}
@@ -998,7 +1003,7 @@ static int GdiOval(
}
}
objv += 2;
- argc -= 2;
+ objc -= 2;
}
if (dofillcolor) {
@@ -1016,7 +1021,7 @@ static int GdiOval(
* earlier documentation, canvas rectangle does not. Thus, add 1 to right
* and lower bounds to get appropriate behavior.
*/
- Ellipse(hDC, x1, y1, x2+1, y2+1);
+ Ellipse(hDC, floor(x1+0.5), floor(y1+0.5), floor(x2+1.5), floor(y2+1.5));
if (width || dolinecolor) {
GdiFreePen(interp, hDC, hPen);
@@ -1046,7 +1051,7 @@ static int GdiOval(
static int GdiPolygon(
TCL_UNUSED(void *),
Tcl_Interp *interp,
- int argc,
+ int objc,
Tcl_Obj *const *objv)
{
static const char usage_message[] =
@@ -1062,7 +1067,7 @@ static int GdiPolygon(
int x, y;
HDC hDC;
HPEN hPen;
- int width = 0;
+ double width = 0.0;
COLORREF linecolor = 0, fillcolor = BS_NULL;
int dolinecolor = 0, dofillcolor = 0;
LOGBRUSH lbrush;
@@ -1071,32 +1076,37 @@ static int GdiPolygon(
int dodash = 0;
const char *dashdata = 0;
+ double p1x, p1y, p2x, p2y;
/* Verrrrrry simple for now.... */
- if (argc < 6) {
+ if (objc < 6) {
Tcl_AppendResult(interp, usage_message, (char *)NULL);
return TCL_ERROR;
}
hDC = printDC;
- polypoints = (POINT *)attemptckalloc((argc - 1) * sizeof(POINT));
+ polypoints = (POINT *)attemptckalloc((objc - 1) * sizeof(POINT));
if (polypoints == 0) {
/* TODO: unreachable */
Tcl_AppendResult(interp, "Out of memory in GdiLine", (char *)NULL);
return TCL_ERROR;
}
- if ((Tcl_GetIntFromObj(interp, objv[2], (int *)&polypoints[0].x) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[3], (int *)&polypoints[0].y) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[4], (int *)&polypoints[1].x) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[5], (int *)&polypoints[1].y) != TCL_OK)) {
+ if ((Tcl_GetDoubleFromObj(interp, objv[2], &p1x) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[3], &p1y) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[4], &p2x) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[5], &p2y) != TCL_OK)) {
return TCL_ERROR;
}
- argc -= 6;
+ polypoints[0].x = floor(p1x + 0.5);
+ polypoints[0].y = floor(p1y + 0.5);
+ polypoints[1].x = floor(p2x + 0.5);
+ polypoints[1].y = floor(p2y + 0.5);
+ objc -= 6;
objv += 6;
npoly = 2;
- while (argc >= 2) {
+ while (objc >= 2) {
/* Check for a number */
x = strtoul(Tcl_GetString(objv[0]), &strend, 0);
if (strend > Tcl_GetString(objv[0])) {
@@ -1107,7 +1117,7 @@ static int GdiPolygon(
polypoints[npoly].x = x;
polypoints[npoly].y = y;
npoly++;
- argc -= 2;
+ objc -= 2;
objv += 2;
} else {
/* Only one number... Assume a usage error. */
@@ -1151,7 +1161,7 @@ static int GdiPolygon(
/* Not supported */
} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
if (Tcl_GetString(objv[1])) {
- if (Tcl_GetIntFromObj(interp, objv[1], &width) != TCL_OK) {
+ if (Tcl_GetDoubleFromObj(interp, objv[1], &width) != TCL_OK) {
return TCL_ERROR;
}
}
@@ -1161,7 +1171,7 @@ static int GdiPolygon(
dashdata = Tcl_GetString(objv[1]);
}
}
- argc -= 2;
+ objc -= 2;
objv += 2;
}
}
@@ -1179,14 +1189,15 @@ static int GdiPolygon(
if (dosmooth) {
int nbpoints;
- POINT *bpoints = 0;
- nbpoints = Bezierize(polypoints,npoly,nStep,bpoints);
+ POINT *bpoints = NULL;
+
+ nbpoints = Bezierize(polypoints, npoly, nStep, &bpoints);
if (nbpoints > 0) {
Polygon(hDC, bpoints, nbpoints);
} else {
Polygon(hDC, polypoints, npoly);
}
- if (bpoints != 0) {
+ if (bpoints) {
ckfree(bpoints);
}
} else {
@@ -1222,7 +1233,7 @@ static int GdiPolygon(
static int GdiRectangle(
TCL_UNUSED(void *),
Tcl_Interp *interp,
- int argc,
+ int objc,
Tcl_Obj *const *objv)
{
static const char usage_message[] =
@@ -1230,10 +1241,10 @@ static int GdiRectangle(
"-fill color -outline color "
"-stipple bitmap -width linewid";
- int x1, y1, x2, y2;
+ double x1, y1, x2, y2;
HDC hDC;
HPEN hPen;
- int width = 0;
+ double width = 0.0;
COLORREF linecolor = 0, fillcolor = BS_NULL;
int dolinecolor = 0, dofillcolor = 0;
LOGBRUSH lbrush;
@@ -1244,34 +1255,34 @@ static int GdiRectangle(
const char *dashdata = 0;
/* Verrrrrry simple for now.... */
- if (argc < 6) {
+ if (objc < 6) {
Tcl_AppendResult(interp, usage_message, (char *)NULL);
return TCL_ERROR;
}
hDC = printDC;
- if ((Tcl_GetIntFromObj(interp, objv[2], &x1) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[3], &y1) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[4], &x2) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[5], &y2) != TCL_OK)) {
+ if ((Tcl_GetDoubleFromObj(interp, objv[2], &x1) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[3], &y1) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[4], &x2) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[5], &y2) != TCL_OK)) {
return TCL_ERROR;
}
if (x1 > x2) {
- int x3 = x1;
+ double x3 = x1;
x1 = x2;
x2 = x3;
}
if (y1 > y2) {
- int y3 = y1;
+ double y3 = y1;
y1 = y2;
y2 = y3;
}
- argc -= 6;
+ objc -= 6;
objv += 6;
/* Now handle any other arguments that occur. */
- while (argc > 1) {
+ while (objc > 1) {
if (strcmp(Tcl_GetString(objv[0]), "-fill") == 0) {
if (Tcl_GetString(objv[1]) && GdiGetColor(objv[1], &fillcolor)) {
dofillcolor = 1;
@@ -1284,7 +1295,7 @@ static int GdiRectangle(
/* Not supported; ignored */
} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
if (Tcl_GetString(objv[1])) {
- if (Tcl_GetIntFromObj(interp, objv[1], &width) != TCL_OK) {
+ if (Tcl_GetDoubleFromObj(interp, objv[1], &width) != TCL_OK) {
return TCL_ERROR;
}
}
@@ -1295,7 +1306,7 @@ static int GdiRectangle(
}
}
- argc -= 2;
+ objc -= 2;
objv += 2;
}
@@ -1320,7 +1331,7 @@ static int GdiRectangle(
* earlier documentation, canvas rectangle does not. Thus, add 1 to
* right and lower bounds to get appropriate behavior.
*/
- Rectangle(hDC, x1, y1, x2+1, y2+1);
+ Rectangle(hDC, floor(x1+0.5), floor(y1+0.5), floor(x2+1.5), floor(y2+1.5));
if (width || dolinecolor) {
GdiFreePen(interp, hDC, hPen);
@@ -1352,7 +1363,7 @@ static int GdiRectangle(
static int GdiCharWidths(
TCL_UNUSED(void *),
Tcl_Interp *interp,
- int argc,
+ int objc,
Tcl_Obj *const *objv)
{
static const char usage_message[] =
@@ -1374,19 +1385,19 @@ static int GdiCharWidths(
int widths[256];
int retval;
- if (argc < 2) {
+ if (objc < 2) {
Tcl_AppendResult(interp, usage_message, (char *)NULL);
return TCL_ERROR;
}
hDC = printDC;
- argc -= 2;
+ objc -= 2;
objv += 2;
- while (argc > 0) {
+ while (objc > 0) {
if (strcmp(Tcl_GetString(objv[0]), "-font") == 0) {
- argc--;
+ objc--;
objv++;
if (GdiMakeLogFont(interp, Tcl_GetString(objv[0]), &lf, hDC)) {
if ((hfont = CreateFontIndirectW(&lf)) != NULL) {
@@ -1397,13 +1408,13 @@ static int GdiCharWidths(
/* Else leave the font alone!. */
} else if (strcmp(Tcl_GetString(objv[0]), "-array") == 0) {
objv++;
- argc--;
- if (argc > 0) {
+ objc--;
+ if (objc > 0) {
aryvarname = Tcl_GetString(objv[0]);
}
}
objv++;
- argc--;
+ objc--;
}
/* Now, get the widths using the correct function for font type. */
@@ -1467,7 +1478,7 @@ static int GdiCharWidths(
int GdiText(
TCL_UNUSED(void *),
Tcl_Interp *interp,
- int argc,
+ int objc,
Tcl_Obj *const *objv)
{
static const char usage_message[] =
@@ -1478,7 +1489,7 @@ int GdiText(
"-single -backfill";
HDC hDC;
- int x, y;
+ double x, y;
const char *string = 0;
RECT sizerect;
UINT format_flags = DT_EXPANDTABS|DT_NOPREFIX; /* Like the canvas. */
@@ -1496,7 +1507,7 @@ int GdiText(
WCHAR *wstring;
Tcl_DString tds;
- if (argc < 4) {
+ if (objc < 4) {
Tcl_AppendResult(interp, usage_message, (char *)NULL);
return TCL_ERROR;
}
@@ -1505,27 +1516,27 @@ int GdiText(
hDC = printDC;
- if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)) {
+ if ((Tcl_GetDoubleFromObj(interp, objv[2], &x) != TCL_OK)
+ || (Tcl_GetDoubleFromObj(interp, objv[3], &y) != TCL_OK)) {
return TCL_ERROR;
}
- argc -= 4;
+ objc -= 4;
objv += 4;
- sizerect.left = sizerect.right = x;
- sizerect.top = sizerect.bottom = y;
+ sizerect.left = sizerect.right = floor(x+0.5);
+ sizerect.top = sizerect.bottom = floor(y+0.5);
- while (argc > 0) {
+ while (objc > 0) {
if (strcmp(Tcl_GetString(objv[0]), "-anchor") == 0) {
- argc--;
+ objc--;
objv++;
- if (argc > 0) {
+ if (objc > 0) {
Tk_GetAnchor(interp, Tcl_GetString(objv[0]), &anchor);
}
} else if (strcmp(Tcl_GetString(objv[0]), "-justify") == 0) {
- argc--;
+ objc--;
objv++;
- if (argc > 0) {
+ if (objc > 0) {
if (strcmp(Tcl_GetString(objv[0]), "left") == 0) {
format_flags |= DT_LEFT;
} else if (strcmp(Tcl_GetString(objv[0]), "center") == 0) {
@@ -1535,13 +1546,13 @@ int GdiText(
}
}
} else if (strcmp(Tcl_GetString(objv[0]), "-text") == 0) {
- argc--;
+ objc--;
objv++;
- if (argc > 0) {
+ if (objc > 0) {
string = Tcl_GetString(objv[0]);
}
} else if (strcmp(Tcl_GetString(objv[0]), "-font") == 0) {
- argc--;
+ objc--;
objv++;
if (GdiMakeLogFont(interp, Tcl_GetString(objv[0]), &lf, hDC)) {
if ((hfont = CreateFontIndirectW(&lf)) != NULL) {
@@ -1551,20 +1562,20 @@ int GdiText(
}
/* Else leave the font alone! */
} else if (strcmp(Tcl_GetString(objv[0]), "-stipple") == 0) {
- argc--;
+ objc--;
objv++;
/* Not implemented yet. */
} else if (strcmp(Tcl_GetString(objv[0]), "-fill") == 0) {
- argc--;
+ objc--;
objv++;
/* Get text color. */
if (GdiGetColor(objv[0], &textcolor)) {
dotextcolor = 1;
}
} else if (strcmp(Tcl_GetString(objv[0]), "-width") == 0) {
- argc--;
+ objc--;
objv++;
- if (argc > 0) {
+ if (objc > 0) {
int value;
if (Tcl_GetIntFromObj(interp, objv[0], &value) != TCL_OK) {
return TCL_ERROR;
@@ -1579,7 +1590,7 @@ int GdiText(
dobgmode = 1;
}
- argc--;
+ objc--;
objv++;
}
@@ -1822,7 +1833,7 @@ static const char *GdiModeToName(
static int GdiMap(
TCL_UNUSED(void *),
Tcl_Interp *interp,
- int argc,
+ int objc,
Tcl_Obj *const *objv)
{
static const char usage_message[] =
@@ -1846,7 +1857,7 @@ static int GdiMap(
int use_mode = 0;
/* Required parameter: HDC for printer. */
- if (argc < 2) {
+ if (objc < 2) {
Tcl_AppendResult(interp, usage_message, (char *)NULL);
return TCL_ERROR;
}
@@ -1860,14 +1871,14 @@ static int GdiMap(
}
/* Parse remaining arguments. */
- for (argno = 2; argno < argc; argno++) {
+ for (argno = 2; argno < objc; argno++) {
if (strcmp(Tcl_GetString(objv[argno]), "-default") == 0) {
vextent.cx = vextent.cy = wextent.cx = wextent.cy = 1;
vorigin.x = vorigin.y = worigin.x = worigin.y = 0;
mapmode = MM_TEXT;
use_default = 1;
} else if (strcmp(Tcl_GetString(objv[argno]), "-mode") == 0) {
- if (argno + 1 >= argc) {
+ if (argno + 1 >= objc) {
need_usage = 1;
} else {
mapmode = GdiNameToMode(Tcl_GetString(objv[argno + 1]));
@@ -1875,7 +1886,7 @@ static int GdiMap(
argno++;
}
} else if (strcmp(Tcl_GetString(objv[argno]), "-offset") == 0) {
- if (argno + 1 >= argc) {
+ if (argno + 1 >= objc) {
need_usage = 1;
} else {
/* It would be nice if this parsed units as well.... */
@@ -1888,7 +1899,7 @@ static int GdiMap(
argno++;
}
} else if (strcmp(Tcl_GetString(objv[argno]), "-logical") == 0) {
- if (argno + 1 >= argc) {
+ if (argno + 1 >= objc) {
need_usage = 1;
} else {
int count;
@@ -1910,7 +1921,7 @@ static int GdiMap(
}
}
} else if (strcmp(Tcl_GetString(objv[argno]), "-physical") == 0) {
- if (argno + 1 >= argc) {
+ if (argno + 1 >= objc) {
need_usage = 1;
} else {
int count;
@@ -2005,7 +2016,7 @@ static int GdiMap(
static int GdiCopyBits(
TCL_UNUSED(void *),
Tcl_Interp *interp,
- int argc,
+ int objc,
Tcl_Obj *const *objv)
{
/* Goal: get the Tk_Window from the top-level
@@ -2067,7 +2078,7 @@ static int GdiCopyBits(
* Parse the arguments.
*/
/* HDC is required. */
- if (argc < 2) {
+ if (objc < 2) {
Tcl_AppendResult(interp, usage_message, (char *)NULL);
return TCL_ERROR;
}
@@ -2085,7 +2096,7 @@ static int GdiCopyBits(
}
/* Loop through the remaining arguments. */
- for (k=2; k<argc; k++) {
+ for (k=2; k<objc; k++) {
if (strcmp(Tcl_GetString(objv[k]), "-window") == 0) {
if (Tcl_GetString(objv[k+1]) && Tcl_GetString(objv[k+1])[0] == '.') {
do_window = 1;
@@ -2653,7 +2664,7 @@ static int GdiMakeLogFont(
static int GdiMakePen(
Tcl_Interp *interp,
- int width,
+ double dwidth,
int dashstyle,
const char *dashstyledata,
TCL_UNUSED(int), /* Ignored for now. */
@@ -2678,7 +2689,7 @@ static int GdiMakePen(
* after first failure) may suffice for working around this. The
* ExtCreatePen is not supported at all under Win32.
*/
-
+ int width = floor(dwidth + 0.5);
HPEN hPen;
LOGBRUSH lBrush;
DWORD pStyle = PS_SOLID; /* -dash should override*/
@@ -3634,6 +3645,24 @@ static int PrintSelectPrinter(
} else {
localDevmode = NULL;
}
+ } else {
+ unsigned int errorcode = CommDlgExtendedError();
+
+ /*
+ * The user cancelled, or there was an error
+ * The code on the Tcl side checks if the variable
+ * ::tk::print::printer_name is defined to determine
+ * that a valid selection was made.
+ * So we better unset this here, unconditionally.
+ */
+ Tcl_UnsetVar(interp, "::tk::print::printer_name", 0);
+ if (errorcode != 0) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf("print failed: error %04x",
+ errorcode));
+ Tcl_SetErrorCode(interp, "TK", "PRINT", "DIALOG", (char*)NULL);
+ return TCL_ERROR;
+ }
+ return TCL_OK;
}
if (pd.hDevMode != NULL) {
@@ -3641,27 +3670,30 @@ static int PrintSelectPrinter(
}
/*
- * Store print properties and link variables so they can be accessed from
+ * Store print properties in variables so they can be accessed from
* script level.
*/
if (localPrinterName != NULL) {
- char* varlink1 = (char*)ckalloc(100 * sizeof(char));
- char** varlink2 = (char**)ckalloc(sizeof(char*));
- *varlink2 = varlink1;
- WideCharToMultiByte(CP_UTF8, 0, localPrinterName, -1, varlink1, 0, NULL, NULL);
-
- Tcl_LinkVar(interp, "::tk::print::printer_name", varlink2,
- TCL_LINK_STRING | TCL_LINK_READ_ONLY);
- Tcl_LinkVar(interp, "::tk::print::copies", &copies,
- TCL_LINK_INT | TCL_LINK_READ_ONLY);
- Tcl_LinkVar(interp, "::tk::print::dpi_x", &dpi_x,
- TCL_LINK_INT | TCL_LINK_READ_ONLY);
- Tcl_LinkVar(interp, "::tk::print::dpi_y", &dpi_y,
- TCL_LINK_INT | TCL_LINK_READ_ONLY);
- Tcl_LinkVar(interp, "::tk::print::paper_width", &paper_width,
- TCL_LINK_INT | TCL_LINK_READ_ONLY);
- Tcl_LinkVar(interp, "::tk::print::paper_height", &paper_height,
- TCL_LINK_INT | TCL_LINK_READ_ONLY);
+ char *prname;
+ int size_needed = WideCharToMultiByte(CP_UTF8, 0, localPrinterName,
+ -1, NULL, 0, NULL, NULL);
+
+ prname = (char*)ckalloc(size_needed);
+ WideCharToMultiByte(CP_UTF8, 0, localPrinterName, -1, prname,
+ size_needed, NULL, NULL);
+ Tcl_SetVar2Ex(interp, "::tk::print::printer_name", NULL,
+ Tcl_NewStringObj(prname, size_needed - 1), 0);
+ Tcl_SetVar2Ex(interp, "::tk::print::copies", NULL,
+ Tcl_NewIntObj(copies), 0);
+ Tcl_SetVar2Ex(interp, "::tk::print::dpi_x", NULL,
+ Tcl_NewIntObj(dpi_x), 0);
+ Tcl_SetVar2Ex(interp, "::tk::print::dpi_y", NULL,
+ Tcl_NewIntObj(dpi_y), 0);
+ Tcl_SetVar2Ex(interp, "::tk::print::paper_width", NULL,
+ Tcl_NewIntObj(paper_width), 0);
+ Tcl_SetVar2Ex(interp, "::tk::print::paper_height", NULL,
+ Tcl_NewIntObj(paper_height), 0);
+ ckfree(prname);
}
return TCL_OK;