diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2010-01-05 08:49:47 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2010-01-05 08:49:47 (GMT) |
commit | aacf8d739e27f7131d0a7322da993ba8158df5e6 (patch) | |
tree | b53ca9c943b91ed43676acd0f73612577ebae655 /unix | |
parent | a580567464cda1d5a6116339acc707e451e7854e (diff) | |
download | tk-aacf8d739e27f7131d0a7322da993ba8158df5e6.zip tk-aacf8d739e27f7131d0a7322da993ba8158df5e6.tar.gz tk-aacf8d739e27f7131d0a7322da993ba8158df5e6.tar.bz2 |
Corrected rounding of coordinates when working with fonts. [Bug 2824916]
Diffstat (limited to 'unix')
-rw-r--r-- | unix/tkUnixFont.c | 42 | ||||
-rw-r--r-- | unix/tkUnixRFont.c | 31 |
2 files changed, 56 insertions, 17 deletions
diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c index ba78339..3b9beae 100644 --- a/unix/tkUnixFont.c +++ b/unix/tkUnixFont.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: tkUnixFont.c,v 1.40 2009/01/28 20:47:49 nijtmans Exp $ + * RCS: @(#) $Id: tkUnixFont.c,v 1.41 2010/01/05 08:49:49 dkf Exp $ */ #include "tkUnixInt.h" @@ -3010,7 +3010,7 @@ GetEncodingAlias( EncodingAlias *aliasPtr; for (aliasPtr = encodingAliases; aliasPtr->aliasPattern != NULL; ) { - if (Tcl_StringMatch((char *) name, aliasPtr->aliasPattern)) { + if (Tcl_StringMatch(name, aliasPtr->aliasPattern)) { return aliasPtr->realName; } aliasPtr++; @@ -3018,6 +3018,28 @@ GetEncodingAlias( return name; } +/* + *--------------------------------------------------------------------------- + * + * TkpDrawAngledChars -- + * + * Draw some characters at an angle. This is awkward here because we have + * no reliable way of drawing any characters at an angle in classic X11; + * we have to draw on a Pixmap which is converted to an XImage (from + * helper function GetImageOfText), rotate the image (hokey code!) onto + * another XImage (from helper function InitDestImage), and then use the + * rotated image as a mask when drawing. This is pretty awful; improved + * versions are welcomed! + * + * Results: + * None. + * + * Side effects: + * Target drawable is updated. + * + *--------------------------------------------------------------------------- + */ + static inline XImage * GetImageOfText( Display *display, /* Display on which to draw. */ @@ -3179,32 +3201,32 @@ TkpDrawAngledChars( for (j=0 ; j<srcHeight ; j++) { switch (quadrant) { case Q0: - dx = floor(i*cosA + j*sinA + 0.5); - dy = floor(j*cosA + (srcWidth - i)*sinA + 0.5); + dx = ROUND16(i*cosA + j*sinA); + dy = ROUND16(j*cosA + (srcWidth - i)*sinA); break; case R1: dx = j; dy = srcWidth - i; break; case Q1: - dx = floor((i - srcWidth)*cosA + j*sinA + 0.5); - dy = floor((srcWidth-i)*sinA + (j-srcHeight)*cosA + 0.5); + dx = ROUND16((i - srcWidth)*cosA + j*sinA); + dy = ROUND16((srcWidth-i)*sinA + (j-srcHeight)*cosA); break; case R2: dx = srcWidth - i; dy = srcHeight - j; break; case Q2: - dx = floor((i-srcWidth)*cosA + (j-srcHeight)*sinA + 0.5); - dy = floor((j - srcHeight)*cosA - i*sinA + 0.5); + dx = ROUND16((i-srcWidth)*cosA + (j-srcHeight)*sinA); + dy = ROUND16((j - srcHeight)*cosA - i*sinA); break; case R3: dx = srcHeight - j; dy = i; break; default: - dx = floor(i*cosA + (j - srcHeight)*sinA + 0.5); - dy = floor(j*cosA - i*sinA + 0.5); + dx = ROUND16(i*cosA + (j - srcHeight)*sinA); + dy = ROUND16(j*cosA - i*sinA); } if (dx < 0 || dy < 0 || dx >= bufWidth || dy >= bufHeight) { diff --git a/unix/tkUnixRFont.c b/unix/tkUnixRFont.c index eef42d5..34f504e 100644 --- a/unix/tkUnixRFont.c +++ b/unix/tkUnixRFont.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: tkUnixRFont.c,v 1.32 2010/01/02 18:40:35 dkf Exp $ + * RCS: @(#) $Id: tkUnixRFont.c,v 1.33 2010/01/05 08:49:50 dkf Exp $ */ #include "tkUnixInt.h" @@ -16,8 +16,6 @@ #include <X11/Xft/Xft.h> #include <ctype.h> -#define ROUND16(x) ((short)((x) + 0.5)) - typedef struct { XftFont *ftFont; XftFont *ft0Font; @@ -827,6 +825,25 @@ Tk_DrawChars( } } +/* + *--------------------------------------------------------------------------- + * + * TkpDrawAngledChars -- + * + * Draw some characters at an angle. This would be simple code, except + * Xft has bugs with cumulative errors in character positioning which are + * caused by trying to perform all calculations internally with integers. + * So we have to do the work ourselves with floating-point math. + * + * Results: + * None. + * + * Side effects: + * Target drawable is updated. + * + *--------------------------------------------------------------------------- + */ + void TkpDrawAngledChars( Display *display, /* Display on which to draw. */ @@ -923,8 +940,8 @@ TkpDrawAngledChars( XftDrawGlyphs(fontPtr->ftDraw, &fontPtr->color, currentFtFont, originX, originY, glyphs, nglyph); } - originX = (int) floor(x + 0.5); - originY = (int) floor(y + 0.5); + originX = ROUND16(x); + originY = ROUND16(y); if (nglyph) { XftGlyphExtents(fontPtr->display, currentFtFont, glyphs, nglyph, &metrics); @@ -993,8 +1010,8 @@ TkpDrawAngledChars( if (ftFont && ft0Font) { specs[nspec].font = ftFont; specs[nspec].glyph = XftCharIndex(fontPtr->display, ftFont, c); - specs[nspec].x = (int) floor(x + 0.5); - specs[nspec].y = (int) floor(y + 0.5); + specs[nspec].x = ROUND16(x); + specs[nspec].y = ROUND16(y); XftGlyphExtents(fontPtr->display, ft0Font, &specs[nspec].glyph, 1, &metrics); x += metrics.xOff*cosA + metrics.yOff*sinA; |