summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-05-19 12:57:59 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-05-19 12:57:59 (GMT)
commit8f56293a6faf629fa90092d966ad634247c76389 (patch)
tree5db13901c256ec3f40b154b0af58944cef02c52c
parentbfa63c7740a0f5a2251012014fd7f2b67d3389b9 (diff)
parent2ff5fda0fe162179358a1fdd26adefa380b72286 (diff)
downloadtk-8f56293a6faf629fa90092d966ad634247c76389.zip
tk-8f56293a6faf629fa90092d966ad634247c76389.tar.gz
tk-8f56293a6faf629fa90092d966ad634247c76389.tar.bz2
merge core-8-6-branch
-rw-r--r--generic/tkCanvPs.c2
-rw-r--r--generic/tkFont.c43
-rw-r--r--generic/tkFont.h6
-rw-r--r--macosx/tkMacOSXFont.c2
-rw-r--r--unix/tkUnixFont.c16
-rw-r--r--unix/tkUnixRFont.c23
-rw-r--r--win/tkWinDialog.c2
-rw-r--r--win/tkWinFont.c6
8 files changed, 54 insertions, 46 deletions
diff --git a/generic/tkCanvPs.c b/generic/tkCanvPs.c
index c6470dd..2bfdcc5 100644
--- a/generic/tkCanvPs.c
+++ b/generic/tkCanvPs.c
@@ -825,7 +825,7 @@ Tk_PostscriptFont(
fontname = Tcl_DStringValue(&ds);
Tcl_AppendPrintfToObj(GetPostscriptBuffer(interp),
"/%s findfont %d scalefont%s setfont\n",
- fontname, TkFontGetPoints(psInfoPtr->tkwin, points),
+ fontname, (int)(TkFontGetPoints(psInfoPtr->tkwin, points) + 0.5),
strncasecmp(fontname, "Symbol", 7) ? " ISOEncode" : "");
Tcl_CreateHashEntry(&psInfoPtr->fontTable, Tcl_DStringValue(&ds), &i);
Tcl_DStringFree(&ds);
diff --git a/generic/tkFont.c b/generic/tkFont.c
index a00c627..dde722b 100644
--- a/generic/tkFont.c
+++ b/generic/tkFont.c
@@ -1228,7 +1228,7 @@ Tk_AllocFontFromObj(
descent = fontPtr->fm.descent;
fontPtr->underlinePos = descent / 2;
- fontPtr->underlineHeight = TkFontGetPixels(tkwin, fontPtr->fa.size) / 10;
+ fontPtr->underlineHeight = (int) (TkFontGetPixels(tkwin, fontPtr->fa.size) / 10 + 0.5);
if (fontPtr->underlineHeight == 0) {
fontPtr->underlineHeight = 1;
}
@@ -1795,7 +1795,7 @@ Tk_PostscriptFontName(
}
}
- return fontPtr->fa.size;
+ return (int)(fontPtr->fa.size + 0.5);
}
/*
@@ -3404,7 +3404,7 @@ ConfigAttributesObj(
if (Tcl_GetIntFromObj(interp, valuePtr, &n) != TCL_OK) {
return TCL_ERROR;
}
- faPtr->size = n;
+ faPtr->size = (double)n;
break;
case FONT_WEIGHT:
n = TkFindStateNumObj(interp, optionPtr, weightMap, valuePtr);
@@ -3495,7 +3495,11 @@ GetAttributeInfoObj(
break;
case FONT_SIZE:
- valuePtr = Tcl_NewIntObj(faPtr->size);
+ if (faPtr->size >= 0.0) {
+ valuePtr = Tcl_NewIntObj((int)(faPtr->size + 0.5));
+ } else {
+ valuePtr = Tcl_NewIntObj(-(int)(-faPtr->size + 0.5));
+ }
break;
case FONT_WEIGHT:
@@ -3644,7 +3648,7 @@ ParseFontNameObj(
if (Tcl_GetIntFromObj(interp, objv[1], &n) != TCL_OK) {
return TCL_ERROR;
}
- faPtr->size = n;
+ faPtr->size = (double)n;
}
i = 2;
@@ -3888,7 +3892,7 @@ TkFontParseXLFD(
* historical compatibility.
*/
- faPtr->size = 12;
+ faPtr->size = 12.0;
if (FieldSpecified(field[XLFD_POINT_SIZE])) {
if (field[XLFD_POINT_SIZE][0] == '[') {
@@ -3902,10 +3906,10 @@ TkFontParseXLFD(
* the purpose of, so I ignore them.
*/
- faPtr->size = atoi(field[XLFD_POINT_SIZE] + 1);
+ faPtr->size = atof(field[XLFD_POINT_SIZE] + 1);
} else if (Tcl_GetInt(NULL, field[XLFD_POINT_SIZE],
- &faPtr->size) == TCL_OK) {
- faPtr->size /= 10;
+ &i) == TCL_OK) {
+ faPtr->size = i/10.0;
} else {
return TCL_ERROR;
}
@@ -3927,9 +3931,10 @@ TkFontParseXLFD(
* ignore them.
*/
- faPtr->size = atoi(field[XLFD_PIXEL_SIZE] + 1);
+ faPtr->size = atof(field[XLFD_PIXEL_SIZE] + 1);
} else if (Tcl_GetInt(NULL, field[XLFD_PIXEL_SIZE],
- &faPtr->size) != TCL_OK) {
+ &i) != TCL_OK) {
+ faPtr->size = (double)i;
return TCL_ERROR;
}
}
@@ -4005,21 +4010,21 @@ FieldSpecified(
*---------------------------------------------------------------------------
*/
-int
+double
TkFontGetPixels(
Tk_Window tkwin, /* For point->pixel conversion factor. */
- int size) /* Font size. */
+ double size) /* Font size. */
{
double d;
- if (size < 0) {
+ if (size <= 0.0) {
return -size;
}
d = size * 25.4 / 72.0;
d *= WidthOfScreen(Tk_Screen(tkwin));
d /= WidthMMOfScreen(Tk_Screen(tkwin));
- return (int) (d + 0.5);
+ return d;
}
/*
@@ -4039,21 +4044,21 @@ TkFontGetPixels(
*---------------------------------------------------------------------------
*/
-int
+double
TkFontGetPoints(
Tk_Window tkwin, /* For pixel->point conversion factor. */
- int size) /* Font size. */
+ double size) /* Font size. */
{
double d;
- if (size >= 0) {
+ if (size >= 0.0) {
return size;
}
d = -size * 72.0 / 25.4;
d *= WidthMMOfScreen(Tk_Screen(tkwin));
d /= WidthOfScreen(Tk_Screen(tkwin));
- return (int) (d + 0.5);
+ return d;
}
/*
diff --git a/generic/tkFont.h b/generic/tkFont.h
index b8de885..de479bf 100644
--- a/generic/tkFont.h
+++ b/generic/tkFont.h
@@ -23,7 +23,7 @@
struct TkFontAttributes {
Tk_Uid family; /* Font family, or NULL to represent plaform-
* specific default system font. */
- int size; /* Pointsize of font, 0 for default size, or
+ double size; /* Pointsize of font, 0.0 for default size, or
* negative number meaning pixel size. */
int weight; /* Weight flag; see below for def'n. */
int slant; /* Slant flag; see below for def'n. */
@@ -198,8 +198,8 @@ MODULE_SCOPE int TkFontParseXLFD(const char *string,
TkFontAttributes *faPtr, TkXLFDAttributes *xaPtr);
MODULE_SCOPE const char *const * TkFontGetAliasList(const char *faceName);
MODULE_SCOPE const char *const *const * TkFontGetFallbacks(void);
-MODULE_SCOPE int TkFontGetPixels(Tk_Window tkwin, int size);
-MODULE_SCOPE int TkFontGetPoints(Tk_Window tkwin, int size);
+MODULE_SCOPE double TkFontGetPixels(Tk_Window tkwin, double size);
+MODULE_SCOPE double TkFontGetPoints(Tk_Window tkwin, double size);
MODULE_SCOPE const char *const * TkFontGetGlobalClass(void);
MODULE_SCOPE const char *const * TkFontGetSymbolClass(void);
MODULE_SCOPE int TkCreateNamedFont(Tcl_Interp *interp, Tk_Window tkwin,
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c
index b5ae1a3..fd4c19a 100644
--- a/macosx/tkMacOSXFont.c
+++ b/macosx/tkMacOSXFont.c
@@ -515,7 +515,7 @@ TkpGetFontFromAttributes(
/* Set of attributes to match. */
{
MacFont *fontPtr;
- int points = TkFontGetPoints(tkwin, faPtr->size);
+ int points = (int)(TkFontGetPoints(tkwin, faPtr->size) + 0.5);
NSFontTraitMask traits = GetNSFontTraitsFromTkFontAttributes(faPtr);
NSInteger weight = (faPtr->weight == TK_FW_BOLD ? 9 : 5);
NSFont *nsFont;
diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c
index e5aceb1..6f37c15 100644
--- a/unix/tkUnixFont.c
+++ b/unix/tkUnixFont.c
@@ -1535,7 +1535,7 @@ CreateClosestFont(
continue;
}
IdentifySymbolEncodings(&got);
- scalable = (got.fa.size == 0);
+ scalable = (got.fa.size == 0.0);
score = RankAttributes(&want, &got);
if (score < bestScore[scalable]) {
bestIdx[scalable] = nameIdx;
@@ -1642,7 +1642,7 @@ InitFont(
fmPtr->fixed = fixed;
fontPtr->display = display;
- fontPtr->pixelSize = TkFontGetPixels(tkwin, fa.fa.size);
+ fontPtr->pixelSize = (int)(TkFontGetPixels(tkwin, fa.fa.size) + 0.5);
fontPtr->xa = fa.xa;
fontPtr->numSubFonts = 1;
@@ -2452,7 +2452,7 @@ CanUseFallback(
want.xa = fontPtr->xa;
want.fa.family = Tk_GetUid(faceName);
- want.fa.size = -fontPtr->pixelSize;
+ want.fa.size = (double)-fontPtr->pixelSize;
hateFoundry = NULL;
hateCharset = NULL;
@@ -2535,7 +2535,7 @@ CanUseFallback(
* D. Rank each name and pick the best match.
*/
- scalable = (got.fa.size == 0);
+ scalable = (got.fa.size == 0.0);
score = RankAttributes(&want, &got);
if (score < bestScore[scalable]) {
bestIdx[scalable] = nameIdx;
@@ -2664,7 +2664,7 @@ RankAttributes(
penalty += 1000;
}
- if (gotPtr->fa.size == 0) {
+ if (gotPtr->fa.size == 0.0) {
/*
* A scalable font is almost always acceptable, but the corresponding
* bitmapped font would be better.
@@ -2678,14 +2678,14 @@ RankAttributes(
* It's worse to be too large than to be too small.
*/
- diff = (-gotPtr->fa.size - -wantPtr->fa.size);
+ diff = (int) (150 * (-gotPtr->fa.size - -wantPtr->fa.size));
if (diff > 0) {
penalty += 600;
} else if (diff < 0) {
penalty += 150;
diff = -diff;
}
- penalty += 150 * diff;
+ penalty += diff;
}
if (gotPtr->xa.charset != wantPtr->xa.charset) {
size_t i;
@@ -2772,7 +2772,7 @@ GetScreenFont(
}
*str = '\0';
sprintf(buf, "%.200s-%d-*-*-*-*-*%s", nameList[bestIdx[1]],
- -wantPtr->fa.size, rest);
+ (int)(-wantPtr->fa.size+0.5), rest);
*str = '-';
fontStructPtr = XLoadQueryFont(display, buf);
bestScore[1] = INT_MAX;
diff --git a/unix/tkUnixRFont.c b/unix/tkUnixRFont.c
index 36c4540..9c1116d 100644
--- a/unix/tkUnixRFont.c
+++ b/unix/tkUnixRFont.c
@@ -170,18 +170,21 @@ GetTkFontAttributes(
{
const char *family = "Unknown";
const char *const *familyPtr = &family;
- int weight, slant, size, pxsize;
- double ptsize;
+ int weight, slant, pxsize;
+ double size, ptsize;
(void) XftPatternGetString(ftFont->pattern, XFT_FAMILY, 0, familyPtr);
if (XftPatternGetDouble(ftFont->pattern, XFT_SIZE, 0,
&ptsize) == XftResultMatch) {
- size = (int) ptsize;
+ size = ptsize;
+ } else if (XftPatternGetDouble(ftFont->pattern, XFT_PIXEL_SIZE, 0,
+ &ptsize) == XftResultMatch) {
+ size = -ptsize;
} else if (XftPatternGetInteger(ftFont->pattern, XFT_PIXEL_SIZE, 0,
&pxsize) == XftResultMatch) {
- size = -pxsize;
+ size = (double)-pxsize;
} else {
- size = 12;
+ size = 12.0;
}
if (XftPatternGetInteger(ftFont->pattern, XFT_WEIGHT, 0,
&weight) != XftResultMatch) {
@@ -194,7 +197,7 @@ GetTkFontAttributes(
#if DEBUG_FONTSEL
printf("family %s size %d weight %d slant %d\n",
- family, size, weight, slant);
+ family, (int)size, weight, slant);
#endif /* DEBUG_FONTSEL */
faPtr->family = Tk_GetUid(family);
@@ -441,10 +444,10 @@ TkpGetFontFromAttributes(
if (faPtr->family) {
XftPatternAddString(pattern, XFT_FAMILY, faPtr->family);
}
- if (faPtr->size > 0) {
- XftPatternAddDouble(pattern, XFT_SIZE, (double)faPtr->size);
- } else if (faPtr->size < 0) {
- XftPatternAddInteger(pattern, XFT_PIXEL_SIZE, -faPtr->size);
+ if (faPtr->size > 0.0) {
+ XftPatternAddDouble(pattern, XFT_SIZE, faPtr->size);
+ } else if (faPtr->size < 0.0) {
+ XftPatternAddDouble(pattern, XFT_PIXEL_SIZE, -faPtr->size);
} else {
XftPatternAddDouble(pattern, XFT_SIZE, 12.0);
}
diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c
index f9a7cfd..5be6776 100644
--- a/win/tkWinDialog.c
+++ b/win/tkWinDialog.c
@@ -3487,7 +3487,7 @@ FontchooserShowCmd(
LF_FACESIZE-1);
Tcl_DStringFree(&ds);
lf.lfFaceName[LF_FACESIZE-1] = 0;
- lf.lfHeight = -MulDiv(TkFontGetPoints(tkwin, fontPtr->fa.size),
+ lf.lfHeight = -MulDiv((int)(TkFontGetPoints(tkwin, fontPtr->fa.size) + 0.5),
GetDeviceCaps(hdc, LOGPIXELSY), 72);
if (fontPtr->fa.weight == TK_FW_BOLD) {
lf.lfWeight = FW_BOLD;
diff --git a/win/tkWinFont.c b/win/tkWinFont.c
index c01dc3f..aa0697c 100644
--- a/win/tkWinFont.c
+++ b/win/tkWinFont.c
@@ -562,7 +562,7 @@ TkpGetFontFromAttributes(
ReleaseDC(hwnd, hdc);
hFont = GetScreenFont(faPtr, faceName,
- TkFontGetPixels(tkwin, faPtr->size), 0.0);
+ (int)(TkFontGetPixels(tkwin, faPtr->size) + 0.5), 0.0);
if (tkFontPtr == NULL) {
fontPtr = ckalloc(sizeof(WinFont));
} else {
@@ -763,7 +763,7 @@ TkpGetFontAttrsForChar(
ReleaseDC(fontPtr->hwnd, hdc);
faPtr->family = familyPtr->faceName;
faPtr->size = TkFontGetPoints(tkwin,
- tm.tmInternalLeading - tm.tmHeight);
+ (double)(tm.tmInternalLeading - tm.tmHeight));
faPtr->weight = (tm.tmWeight > FW_MEDIUM) ? TK_FW_BOLD : TK_FW_NORMAL;
faPtr->slant = tm.tmItalic ? TK_FS_ITALIC : TK_FS_ROMAN;
faPtr->underline = (tm.tmUnderlined != 0);
@@ -1600,7 +1600,7 @@ InitFont(
faPtr->family = Tk_GetUid(Tcl_DStringValue(&faceString));
faPtr->size =
- TkFontGetPoints(tkwin, -(fontPtr->pixelSize));
+ TkFontGetPoints(tkwin, (double)-(fontPtr->pixelSize));
faPtr->weight =
(tm.tmWeight > FW_MEDIUM) ? TK_FW_BOLD : TK_FW_NORMAL;
faPtr->slant = (tm.tmItalic != 0) ? TK_FS_ITALIC : TK_FS_ROMAN;