Measure the text more reasonably. This handles intercharacter spacing

and should handle any kerning etc. that might happen. Also ensure no
wordbreaking on singleline text.
This commit is contained in:
Bill Medland 2002-02-15 18:21:59 +00:00 committed by Alexandre Julliard
parent 95d8c95f11
commit 0f9013f7e0
1 changed files with 11 additions and 6 deletions

View File

@ -334,21 +334,21 @@ static int TEXT_Reprefix (const WCHAR *str, unsigned int n1, unsigned int n2,
* Returns pointer to next char in str after end of the line * Returns pointer to next char in str after end of the line
* or NULL if end of str reached. * or NULL if end of str reached.
* *
* FIXME:
* GetTextExtentPoint is used to get the width of each character,
* rather than GetCharABCWidth... So the whitespace between
* characters is ignored, and the reported len is too great.
*/ */
static const WCHAR *TEXT_NextLineW( HDC hdc, const WCHAR *str, int *count, static const WCHAR *TEXT_NextLineW( HDC hdc, const WCHAR *str, int *count,
WCHAR *dest, int *len, int width, WORD format) WCHAR *dest, int *len, int width, WORD format)
{ {
int i = 0, j = 0; int i = 0, j = 0;
int plen = 0; int plen = 0;
int seg_plen; /* plen at the beginning of the current text segment */
SIZE size; SIZE size;
int wb_i = 0, wb_j = 0, wb_count = 0; int wb_i = 0, wb_j = 0, wb_count = 0;
int maxl = *len; int maxl = *len;
int normal_char; int normal_char;
int seg_j; /* j at the beginning of the current text segment */
seg_j = j;
seg_plen = plen;
while (*count && j < maxl) while (*count && j < maxl)
{ {
normal_char = 1; normal_char = 1;
@ -394,10 +394,12 @@ static const WCHAR *TEXT_NextLineW( HDC hdc, const WCHAR *str, int *count,
wb_j = j; wb_j = j;
wb_count = *count; wb_count = *count;
plen = ((plen/tabwidth)+1)*tabwidth; plen = ((plen/tabwidth)+1)*tabwidth;
seg_plen = plen;
} }
normal_char = 0; normal_char = 0;
dest[j++] = str[i++]; dest[j++] = str[i++];
seg_j = j;
} }
break; break;
@ -418,9 +420,9 @@ static const WCHAR *TEXT_NextLineW( HDC hdc, const WCHAR *str, int *count,
dest[j++] = str[i++]; dest[j++] = str[i++];
if ((format & DT_WORDBREAK)) if ((format & DT_WORDBREAK))
{ {
if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size)) if (!GetTextExtentPointW(hdc, &dest[seg_j], j-seg_j, &size))
return NULL; return NULL;
plen += size.cx; plen = seg_plen + size.cx;
} }
} }
@ -542,6 +544,9 @@ INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count,
if (count == 0) return 0; if (count == 0) return 0;
strPtr = str; strPtr = str;
if (flags & DT_SINGLELINE)
flags &= ~DT_WORDBREAK;
GetTextMetricsW(hdc, &tm); GetTextMetricsW(hdc, &tm);
if (flags & DT_EXTERNALLEADING) if (flags & DT_EXTERNALLEADING)
lh = tm.tmHeight + tm.tmExternalLeading; lh = tm.tmHeight + tm.tmExternalLeading;