diff options
author | ferrieux <ferrieux@users.sourceforge.net> | 2008-11-27 23:47:09 (GMT) |
---|---|---|
committer | ferrieux <ferrieux@users.sourceforge.net> | 2008-11-27 23:47:09 (GMT) |
commit | 01a618069d775fcdce058d2fc203f55073e95435 (patch) | |
tree | c9fc8e9cb71b8cf58580375c8cbc29a24be76984 | |
parent | 713876e1f5bca010fe3fa12da61c8fdf67cd5665 (diff) | |
download | tk-01a618069d775fcdce058d2fc203f55073e95435.zip tk-01a618069d775fcdce058d2fc203f55073e95435.tar.gz tk-01a618069d775fcdce058d2fc203f55073e95435.tar.bz2 |
Millimeter patch. Fixes [1813597,2218964] by eliminating the functional redundancy and unnecessary loss of precision of the {pixel,mm}ObjType tandem.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | generic/tkCanvUtil.c | 9 | ||||
-rw-r--r-- | generic/tkInt.h | 7 | ||||
-rw-r--r-- | generic/tkObj.c | 95 | ||||
-rw-r--r-- | generic/tkText.c | 8 |
5 files changed, 109 insertions, 17 deletions
@@ -1,3 +1,10 @@ +2008-11-28 Alexandre Ferrieux <ferrieux@users.sourceforge.net> + + * generic/tkCanvUtil.c Millimeter patch. Fixes [1813597,2218964] + * generic/tkInt.h by eliminating the functional redundancy + * generic/tkObj.c and unnecessary loss of precision of the + * generic/tkText.c {pixel,mm}ObjType tandem. + 2008-11-27 Jan Nijtmans <nijtmans@users.sf.net> * generic/tkCanvLine.c: Replace Tcl_SetResult(interp, NULL, ....) diff --git a/generic/tkCanvUtil.c b/generic/tkCanvUtil.c index 31e3af6..85a6c1f 100644 --- a/generic/tkCanvUtil.c +++ b/generic/tkCanvUtil.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvUtil.c,v 1.23 2008/11/09 21:53:39 nijtmans Exp $ + * RCS: @(#) $Id: tkCanvUtil.c,v 1.24 2008/11/27 23:47:09 ferrieux Exp $ */ #include "tkInt.h" @@ -261,12 +261,7 @@ Tk_CanvasGetCoordFromObj( * form may be used here). */ double *doublePtr) /* Place to store converted coordinate. */ { - if (Tk_GetMMFromObj(Canvas(canvas)->interp, Canvas(canvas)->tkwin, obj, - doublePtr) != TCL_OK) { - return TCL_ERROR; - } - *doublePtr *= Canvas(canvas)->pixelsPerMM; - return TCL_OK; + return Tk_GetDoublePixelsFromObj(Canvas(canvas)->interp, Canvas(canvas)->tkwin, obj, doublePtr); } /* diff --git a/generic/tkInt.h b/generic/tkInt.h index 2b4705c..3ab1d77 100644 --- a/generic/tkInt.h +++ b/generic/tkInt.h @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: $Id: tkInt.h,v 1.95 2008/11/23 21:58:24 patthoyts Exp $ + * RCS: $Id: tkInt.h,v 1.96 2008/11/27 23:47:09 ferrieux Exp $ */ #ifndef _TKINT @@ -1141,6 +1141,11 @@ MODULE_SCOPE int Tk_WinfoObjCmd(ClientData clientData, MODULE_SCOPE int Tk_WmObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); +MODULE_SCOPE int Tk_GetDoublePixelsFromObj(Tcl_Interp *interp, + Tk_Window tkwin, + Tcl_Obj *objPtr, + double *doublePtr); + MODULE_SCOPE void TkEventInit(void); MODULE_SCOPE void TkRegisterObjTypes(void); MODULE_SCOPE int TkCreateMenuCmd(Tcl_Interp *interp); diff --git a/generic/tkObj.c b/generic/tkObj.c index 41cc589..c8bc746 100644 --- a/generic/tkObj.c +++ b/generic/tkObj.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkObj.c,v 1.22 2008/10/15 06:41:06 nijtmans Exp $ + * RCS: @(#) $Id: tkObj.c,v 1.23 2008/11/27 23:47:09 ferrieux Exp $ */ #include "tkInt.h" @@ -125,7 +125,7 @@ static const Tcl_ObjType windowObjType = { /* *---------------------------------------------------------------------- * - * Tk_GetPixelsFromObj -- + * GetPixelsFromObjEx -- * * Attempt to return a pixel value from the Tcl object "objPtr". If the * object is not already a pixel value, an attempt will be made to @@ -143,12 +143,14 @@ static const Tcl_ObjType windowObjType = { *---------------------------------------------------------------------- */ +static int -Tk_GetPixelsFromObj( +GetPixelsFromObjEx( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ Tk_Window tkwin, Tcl_Obj *objPtr, /* The object from which to get pixels. */ - int *intPtr) /* Place to store resulting pixels. */ + int *intPtr, + double *dblPtr) /* Places to store resulting pixels. */ { int result; double d; @@ -166,6 +168,9 @@ Tk_GetPixelsFromObj( if (SIMPLE_PIXELREP(objPtr)) { *intPtr = GET_SIMPLEPIXEL(objPtr); + if (dblPtr) { + *dblPtr=(double)(*intPtr); + } } else { pixelPtr = GET_COMPLEXPIXEL(objPtr); if (pixelPtr->tkwin != tkwin) { @@ -180,6 +185,9 @@ Tk_GetPixelsFromObj( pixelPtr->returnValue = (int) (d + 0.5); } pixelPtr->tkwin = tkwin; + if (dblPtr) { + *dblPtr=(double)d; + } } *intPtr = pixelPtr->returnValue; } @@ -189,6 +197,85 @@ Tk_GetPixelsFromObj( /* *---------------------------------------------------------------------- * + * Tk_GetPixelsFromObj -- + * + * Attempt to return a pixel value from the Tcl object "objPtr". If the + * object is not already a pixel value, an attempt will be made to + * convert it to one. + * + * Results: + * The return value is a standard Tcl object result. If an error occurs + * during conversion, an error message is left in the interpreter's + * result unless "interp" is NULL. + * + * Side effects: + * If the object is not already a pixel, the conversion will free any old + * internal representation. + * + *---------------------------------------------------------------------- + */ + +int +Tk_GetPixelsFromObj( + Tcl_Interp *interp, /* Used for error reporting if not NULL. */ + Tk_Window tkwin, + Tcl_Obj *objPtr, /* The object from which to get pixels. */ + int *intPtr) /* Place to store resulting pixels. */ +{ + return GetPixelsFromObjEx(interp,tkwin,objPtr,intPtr,NULL); +} + +/* + *---------------------------------------------------------------------- + * + * Tk_GetDoublePixelsFromObj -- + * + * Attempt to return a double pixel value from the Tcl object + * "objPtr". If the object is not already a pixel value, an attempt will + * be made to convert it to one, the internal unit being pixels. + * + * Results: + * The return value is a standard Tcl object result. If an error occurs + * during conversion, an error message is left in the interpreter's + * result unless "interp" is NULL. + * + * Side effects: + * If the object is not already a pixel, the conversion will free any old + * internal representation. + * + *---------------------------------------------------------------------- + */ + +int +Tk_GetDoublePixelsFromObj( + Tcl_Interp *interp, /* Used for error reporting if not NULL. */ + Tk_Window tkwin, + Tcl_Obj *objPtr, /* The object from which to get pixels. */ + double *doublePtr) /* Place to store resulting pixels. */ +{ + double d; + int result,val; + + result=GetPixelsFromObjEx(interp, tkwin, objPtr, &val, &d); + if (result != TCL_OK) { + return result; + } + if (!SIMPLE_PIXELREP(objPtr)) { + PixelRep *pixelPtr; + pixelPtr = GET_COMPLEXPIXEL(objPtr); + if (pixelPtr->units >= 0) { + /* internally "shimmer" to pixel units */ + pixelPtr->units=-1; + pixelPtr->value=d; + } + } + *doublePtr = d; + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * * FreePixelInternalRep -- * * Deallocate the storage associated with a pixel object's internal diff --git a/generic/tkText.c b/generic/tkText.c index 59a855f..c2cc914 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -13,7 +13,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkText.c,v 1.84 2008/11/08 18:44:40 dkf Exp $ + * RCS: @(#) $Id: tkText.c,v 1.85 2008/11/27 23:47:09 ferrieux Exp $ */ #include "default.h" @@ -4323,12 +4323,10 @@ TkTextGetTabs( } prevStop = lastStop; - if (Tk_GetMMFromObj(interp, textPtr->tkwin, objv[i], - &lastStop) != TCL_OK) { + if (Tk_GetDoublePixelsFromObj (interp, textPtr->tkwin, objv[i], + &lastStop) != TCL_OK) { goto error; } - lastStop *= WidthOfScreen(Tk_Screen(textPtr->tkwin)); - lastStop /= WidthMMOfScreen(Tk_Screen(textPtr->tkwin)); if (i > 0 && (tabPtr->location <= (tabPtr-1)->location)) { /* |