summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpatthoyts <patthoyts@users.sourceforge.net>2007-11-17 21:28:05 (GMT)
committerpatthoyts <patthoyts@users.sourceforge.net>2007-11-17 21:28:05 (GMT)
commit6cb937528ddf86aca32fbae1af99b6b4ab59653d (patch)
treeaba921a5e65aceda64cb68ca883d80d542fae88b
parent47bb49fb410bdc4333931805c2c3df2192d604c3 (diff)
downloadtk-6cb937528ddf86aca32fbae1af99b6b4ab59653d.zip
tk-6cb937528ddf86aca32fbae1af99b6b4ab59653d.tar.gz
tk-6cb937528ddf86aca32fbae1af99b6b4ab59653d.tar.bz2
Only check for -displayof if there are sufficient arguments. This permits checking strings like -d.
-rw-r--r--generic/tkFont.c12
-rw-r--r--tests/font.test15
2 files changed, 19 insertions, 8 deletions
diff --git a/generic/tkFont.c b/generic/tkFont.c
index 64c487b..d80227a 100644
--- a/generic/tkFont.c
+++ b/generic/tkFont.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkFont.c,v 1.40 2007/10/21 14:50:19 das Exp $
+ * RCS: @(#) $Id: tkFont.c,v 1.41 2007/11/17 21:28:05 patthoyts Exp $
*/
#include "tkInt.h"
@@ -718,12 +718,14 @@ Tk_FontObjCmd(
case FONT_MEASURE: {
char *string;
Tk_Font tkfont;
- int length, skip;
+ int length = 0, skip = 0;
Tcl_Obj *resultPtr;
- skip = TkGetDisplayOf(interp, objc - 3, objv + 3, &tkwin);
- if (skip < 0) {
- return TCL_ERROR;
+ if (objc > 4) {
+ skip = TkGetDisplayOf(interp, objc - 3, objv + 3, &tkwin);
+ if (skip < 0) {
+ return TCL_ERROR;
+ }
}
if (objc - skip != 4) {
Tcl_WrongNumArgs(interp, 2, objv, "font ?-displayof window? text");
diff --git a/tests/font.test b/tests/font.test
index 3dce0f7..4627396 100644
--- a/tests/font.test
+++ b/tests/font.test
@@ -6,7 +6,7 @@
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
-# RCS: @(#) $Id: font.test,v 1.15 2007/04/24 15:54:30 hobbs Exp $
+# RCS: @(#) $Id: font.test,v 1.16 2007/11/17 21:28:05 patthoyts Exp $
package require tcltest 2.1
eval tcltest::configure $argv
@@ -309,8 +309,8 @@ test font-8.4 {font command: families} {
test font-9.1 {font command: measure: arguments} {
# (skip < 0)
- list [catch {font measure xyz -displayof} msg] $msg
-} {1 {value for "-displayof" missing}}
+ list [catch {expr {[font measure xyz -displayof]>0}} msg] $msg
+} {0 1}
test font-9.2 {font command: measure: arguments} {
# (objc - skip != 4)
list [catch {font measure} msg] $msg
@@ -327,6 +327,15 @@ test font-9.5 {font command: measure} {
# Tk_TextWidth()
expr [font measure $fixed "abcdefg"]==[font measure $fixed "a"]*7
} {1}
+test font-9.6 {font command: measure -d} {
+ list [catch {expr {[font measure $fixed -d] > 0}} msg] $msg
+} {0 1}
+test font-9.7 {font command: measure -d with -displayof} {
+ list [catch {expr {[font measure $fixed -displayof . -d] > 0}} msg] $msg
+} {0 1}
+test font-9.8 {font command: measure: arguments} {
+ list [catch {font measure $fixed -displayof .} msg] $msg
+} {1 {wrong # args: should be "font measure font ?-displayof window? text"}}
test font-10.1 {font command: metrics: arguments} {
list [catch {font metrics xyz -displayof} msg] $msg