d3d10/effect: Add support for 'imul' instruction.
[wine.git] / dlls / user32 / text.c
blob788ed10269c3115505b6fff162c8cfd24e208564
1 /*
2 * USER text functions
4 * Copyright 1993, 1994 Alexandre Julliard
5 * Copyright 2002 Bill Medland
7 * Contains
8 * 1. DrawText functions
9 * 2. GrayString functions
10 * 3. TabbedText functions
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include <stdarg.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <assert.h>
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "winnls.h"
36 #include "controls.h"
37 #include "usp10.h"
38 #include "user_private.h"
39 #include "wine/debug.h"
40 #include "wine/heap.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(text);
44 /*********************************************************************
46 * DrawText functions
48 * Design issues
49 * How many buffers to use
50 * While processing in DrawText there are potentially three different forms
51 * of the text that need to be held. How are they best held?
52 * 1. The original text is needed, of course, to see what to display.
53 * 2. The text that will be returned to the user if the DT_MODIFYSTRING is
54 * in effect.
55 * 3. The buffered text that is about to be displayed e.g. the current line.
56 * Typically this will exclude the ampersands used for prefixing etc.
58 * Complications.
59 * a. If the buffered text to be displayed includes the ampersands then
60 * we will need special measurement and draw functions that will ignore
61 * the ampersands (e.g. by copying to a buffer without the prefix and
62 * then using the normal forms). This may involve less space but may
63 * require more processing. e.g. since a line containing tabs may
64 * contain several underlined characters either we need to carry around
65 * a list of prefix locations or we may need to locate them several
66 * times.
67 * b. If we actually directly modify the "original text" as we go then we
68 * will need some special "caching" to handle the fact that when we
69 * ellipsify the text the ellipsis may modify the next line of text,
70 * which we have not yet processed. (e.g. ellipsification of a W at the
71 * end of a line will overwrite the W, the \n and the first character of
72 * the next line, and a \0 will overwrite the second. Try it!!)
74 * Option 1. Three separate storages. (To be implemented)
75 * If DT_MODIFYSTRING is in effect then allocate an extra buffer to hold
76 * the edited string in some form, either as the string itself or as some
77 * sort of "edit list" to be applied just before returning.
78 * Use a buffer that holds the ellipsified current line sans ampersands
79 * and accept the need occasionally to recalculate the prefixes (if
80 * DT_EXPANDTABS and not DT_NOPREFIX and not DT_HIDEPREFIX)
83 #define TAB 9
84 #define LF 10
85 #define CR 13
86 #define SPACE 32
87 #define PREFIX 38
88 #define ALPHA_PREFIX 30 /* Win16: Alphabet prefix */
89 #define KANA_PREFIX 31 /* Win16: Katakana prefix */
91 #define FORWARD_SLASH '/'
92 #define BACK_SLASH '\\'
94 static const WCHAR ELLIPSISW[] = L"...";
96 typedef struct tag_ellipsis_data
98 int before;
99 int len;
100 int under;
101 int after;
102 } ellipsis_data;
104 /*********************************************************************
105 * TEXT_Ellipsify (static)
107 * Add an ellipsis to the end of the given string whilst ensuring it fits.
109 * If the ellipsis alone doesn't fit then it will be returned anyway.
111 * See Also TEXT_PathEllipsify
113 * Arguments
114 * hdc [in] The handle to the DC that defines the font.
115 * str [in/out] The string that needs to be modified.
116 * max_str [in] The dimension of str (number of WCHAR).
117 * len_str [in/out] The number of characters in str
118 * width [in] The maximum width permitted (in logical coordinates)
119 * size [out] The dimensions of the text
120 * modstr [out] The modified form of the string, to be returned to the
121 * calling program. It is assumed that the caller has
122 * made sufficient space available so we don't need to
123 * know the size of the space. This pointer may be NULL if
124 * the modified string is not required.
125 * len_before [out] The number of characters before the ellipsis.
126 * len_ellip [out] The number of characters in the ellipsis.
128 * See for example Microsoft article Q249678.
130 * For now we will simply use three dots rather than worrying about whether
131 * the font contains an explicit ellipsis character.
133 static void TEXT_Ellipsify (HDC hdc, WCHAR *str, unsigned int max_len,
134 unsigned int *len_str, int width, SIZE *size,
135 WCHAR *modstr,
136 int *len_before, int *len_ellip)
138 unsigned int len_ellipsis;
139 unsigned int lo, mid, hi;
141 len_ellipsis = lstrlenW (ELLIPSISW);
142 if (len_ellipsis > max_len) len_ellipsis = max_len;
143 if (*len_str > max_len - len_ellipsis)
144 *len_str = max_len - len_ellipsis;
146 /* First do a quick binary search to get an upper bound for *len_str. */
147 if (*len_str > 0 &&
148 GetTextExtentExPointW(hdc, str, *len_str, width, NULL, NULL, size) &&
149 size->cx > width)
151 for (lo = 0, hi = *len_str; lo < hi; )
153 mid = (lo + hi) / 2;
154 if (!GetTextExtentExPointW(hdc, str, mid, width, NULL, NULL, size))
155 break;
156 if (size->cx > width)
157 hi = mid;
158 else
159 lo = mid + 1;
161 *len_str = hi;
163 /* Now this should take only a couple iterations at most. */
164 for ( ; ; )
166 memcpy(str + *len_str, ELLIPSISW, len_ellipsis*sizeof(WCHAR));
168 if (!GetTextExtentExPointW (hdc, str, *len_str + len_ellipsis, width,
169 NULL, NULL, size)) break;
171 if (!*len_str || size->cx <= width) break;
173 (*len_str)--;
175 *len_ellip = len_ellipsis;
176 *len_before = *len_str;
177 *len_str += len_ellipsis;
179 if (modstr)
181 memcpy (modstr, str, *len_str * sizeof(WCHAR));
182 modstr[*len_str] = '\0';
186 /*********************************************************************
187 * TEXT_PathEllipsify (static)
189 * Add an ellipsis to the provided string in order to make it fit within
190 * the width. The ellipsis is added as specified for the DT_PATH_ELLIPSIS
191 * flag.
193 * See Also TEXT_Ellipsify
195 * Arguments
196 * hdc [in] The handle to the DC that defines the font.
197 * str [in/out] The string that needs to be modified
198 * max_str [in] The dimension of str (number of WCHAR).
199 * len_str [in/out] The number of characters in str
200 * width [in] The maximum width permitted (in logical coordinates)
201 * size [out] The dimensions of the text
202 * modstr [out] The modified form of the string, to be returned to the
203 * calling program. It is assumed that the caller has
204 * made sufficient space available so we don't need to
205 * know the size of the space. This pointer may be NULL if
206 * the modified string is not required.
207 * pellip [out] The ellipsification results
209 * For now we will simply use three dots rather than worrying about whether
210 * the font contains an explicit ellipsis character.
212 * The following applies, I think to Win95. We will need to extend it for
213 * Win98 which can have both path and end ellipsis at the same time (e.g.
214 * C:\MyLongFileName.Txt becomes ...\MyLongFileN...)
216 * The resulting string consists of as much as possible of the following:
217 * 1. The ellipsis itself
218 * 2. The last \ or / of the string (if any)
219 * 3. Everything after the last \ or / of the string (if any) or the whole
220 * string if there is no / or \. I believe that under Win95 this would
221 * include everything even though some might be clipped off the end whereas
222 * under Win98 that might be ellipsified too.
223 * Yet to be investigated is whether this would include wordbreaking if the
224 * filename is more than 1 word and splitting if DT_EDITCONTROL was in
225 * effect. (If DT_EDITCONTROL is in effect then on occasions text will be
226 * broken within words).
227 * 4. All the stuff before the / or \, which is placed before the ellipsis.
229 static void TEXT_PathEllipsify (HDC hdc, WCHAR *str, unsigned int max_len,
230 unsigned int *len_str, int width, SIZE *size,
231 WCHAR *modstr, ellipsis_data *pellip)
233 int len_ellipsis;
234 int len_trailing;
235 int len_under;
236 WCHAR *lastBkSlash, *lastFwdSlash, *lastSlash;
238 len_ellipsis = lstrlenW (ELLIPSISW);
239 if (!max_len) return;
240 if (len_ellipsis >= max_len) len_ellipsis = max_len - 1;
241 if (*len_str + len_ellipsis >= max_len)
242 *len_str = max_len - len_ellipsis-1;
243 /* Hopefully this will never happen, otherwise it would probably lose
244 * the wrong character
246 str[*len_str] = '\0'; /* to simplify things */
248 lastBkSlash = wcsrchr (str, BACK_SLASH);
249 lastFwdSlash = wcsrchr (str, FORWARD_SLASH);
250 lastSlash = lastBkSlash > lastFwdSlash ? lastBkSlash : lastFwdSlash;
251 if (!lastSlash) lastSlash = str;
252 len_trailing = *len_str - (lastSlash - str);
254 /* overlap-safe movement to the right */
255 memmove (lastSlash+len_ellipsis, lastSlash, len_trailing * sizeof(WCHAR));
256 memcpy (lastSlash, ELLIPSISW, len_ellipsis*sizeof(WCHAR));
257 len_trailing += len_ellipsis;
258 /* From this point on lastSlash actually points to the ellipsis in front
259 * of the last slash and len_trailing includes the ellipsis
262 len_under = 0;
263 for ( ; ; )
265 if (!GetTextExtentExPointW (hdc, str, *len_str + len_ellipsis, width,
266 NULL, NULL, size)) break;
268 if (lastSlash == str || size->cx <= width) break;
270 /* overlap-safe movement to the left */
271 memmove (lastSlash-1, lastSlash, len_trailing * sizeof(WCHAR));
272 lastSlash--;
273 len_under++;
275 assert (*len_str);
276 (*len_str)--;
278 pellip->before = lastSlash-str;
279 pellip->len = len_ellipsis;
280 pellip->under = len_under;
281 pellip->after = len_trailing - len_ellipsis;
282 *len_str += len_ellipsis;
284 if (modstr)
286 memcpy(modstr, str, *len_str * sizeof(WCHAR));
287 modstr[*len_str] = '\0';
291 /*********************************************************************
292 * TEXT_WordBreak (static)
294 * Perform wordbreak processing on the given string
296 * Assumes that DT_WORDBREAK has been specified and not all the characters
297 * fit. Note that this function should even be called when the first character
298 * that doesn't fit is known to be a space or tab, so that it can swallow them.
300 * Note that the Windows processing has some strange properties.
301 * 1. If the text is left-justified and there is room for some of the spaces
302 * that follow the last word on the line then those that fit are included on
303 * the line.
304 * 2. If the text is centered or right-justified and there is room for some of
305 * the spaces that follow the last word on the line then all but one of those
306 * that fit are included on the line.
307 * 3. (Reasonable behaviour) If the word breaking causes a space to be the first
308 * character of a new line it will be skipped.
310 * Arguments
311 * hdc [in] The handle to the DC that defines the font.
312 * str [in/out] The string that needs to be broken.
313 * max_str [in] The dimension of str (number of WCHAR).
314 * len_str [in/out] The number of characters in str
315 * width [in] The maximum width permitted
316 * format [in] The format flags in effect
317 * chars_fit [in] The maximum number of characters of str that are already
318 * known to fit; chars_fit+1 is known not to fit.
319 * chars_used [out] The number of characters of str that have been "used" and
320 * do not need to be included in later text. For example this will
321 * include any spaces that have been discarded from the start of
322 * the next line.
323 * size [out] The size of the returned text in logical coordinates
325 * Pedantic assumption - Assumes that the text length is monotonically
326 * increasing with number of characters (i.e. no weird kernings)
328 * Algorithm
330 * Work back from the last character that did fit to either a space or the last
331 * character of a word, whichever is met first.
332 * If there was one or the first character didn't fit then
333 * If the text is centered or right justified and that one character was a
334 * space then break the line before that character
335 * Otherwise break the line after that character
336 * and if the next character is a space then discard it.
337 * Suppose there was none (and the first character did fit).
338 * If Break Within Word is permitted
339 * break the word after the last character that fits (there must be
340 * at least one; none is caught earlier).
341 * Otherwise
342 * discard any trailing space.
343 * include the whole word; it may be ellipsified later
345 * Break Within Word is permitted under a set of circumstances that are not
346 * totally clear yet. Currently our best guess is:
347 * If DT_EDITCONTROL is in effect and neither DT_WORD_ELLIPSIS nor
348 * DT_PATH_ELLIPSIS is
351 static void TEXT_WordBreak (HDC hdc, WCHAR *str, unsigned int max_str,
352 unsigned int *len_str,
353 int width, int format, unsigned int chars_fit,
354 unsigned int *chars_used, SIZE *size)
356 WCHAR *p;
357 BOOL word_fits;
358 SCRIPT_LOGATTR *sla;
359 SCRIPT_ANALYSIS sa;
360 int i;
362 assert (format & DT_WORDBREAK);
363 assert (chars_fit < *len_str);
365 sla = heap_alloc(sizeof(SCRIPT_LOGATTR) * *len_str);
367 memset(&sa, 0, sizeof(SCRIPT_ANALYSIS));
368 sa.eScript = SCRIPT_UNDEFINED;
370 ScriptBreak(str, *len_str, &sa, sla);
372 /* Work back from the last character that did fit to either a space or the
373 * last character of a word, whichever is met first.
375 p = str + chars_fit; /* The character that doesn't fit */
376 i = chars_fit;
377 word_fits = TRUE;
378 if (!chars_fit)
379 word_fits = FALSE;
380 else if (sla[i].fSoftBreak) /* chars_fit < *len_str so this is valid */
382 /* the word just fitted */
383 p--;
385 else
387 while (i > 0 && !sla[(--i)+1].fSoftBreak) p--;
388 p--;
389 word_fits = (i != 0 || sla[i+1].fSoftBreak );
392 /* If there was one. */
393 if (word_fits)
395 BOOL next_is_space;
396 /* break the line before/after that character */
397 if (!(format & (DT_RIGHT | DT_CENTER)) || *p != SPACE)
398 p++;
399 next_is_space = (p - str) < *len_str && *p == SPACE;
400 *len_str = p - str;
401 /* and if the next character is a space then discard it. */
402 *chars_used = *len_str;
403 if (next_is_space)
404 (*chars_used)++;
406 /* Suppose there was none. */
407 else
409 if ((format & (DT_EDITCONTROL | DT_WORD_ELLIPSIS | DT_PATH_ELLIPSIS)) ==
410 DT_EDITCONTROL)
412 /* break the word after the last character that fits (there must be
413 * at least one). */
414 if (!chars_fit)
415 ++chars_fit;
416 *len_str = chars_fit;
417 *chars_used = chars_fit;
419 /* FIXME - possible error. Since the next character is now removed
420 * this could make the text longer so that it no longer fits, and
421 * so we need a loop to test and shrink.
424 /* Otherwise */
425 else
427 /* discard any trailing space. */
428 const WCHAR *e = str + *len_str;
429 p = str + chars_fit;
430 while (p < e && *p != SPACE)
431 p++;
432 *chars_used = p - str;
433 if (p < e) /* i.e. loop failed because *p == SPACE */
434 (*chars_used)++;
436 /* include the whole word; it may be ellipsified later */
437 *len_str = p - str;
438 /* Possible optimisation; if DT_WORD_ELLIPSIS only use chars_fit+1
439 * so that it will be too long
443 /* Remeasure the string */
444 GetTextExtentExPointW (hdc, str, *len_str, 0, NULL, NULL, size);
445 heap_free(sla);
448 /*********************************************************************
449 * TEXT_SkipChars
451 * Skip over the given number of characters, bearing in mind prefix
452 * substitution and the fact that a character may take more than one
453 * WCHAR (Unicode surrogates are two words long) (and there may have been
454 * a trailing &)
456 * Parameters
457 * new_count [out] The updated count
458 * new_str [out] The updated pointer
459 * start_count [in] The count of remaining characters corresponding to the
460 * start of the string
461 * start_str [in] The starting point of the string
462 * max [in] The number of characters actually in this segment of the
463 * string (the & counts)
464 * n [in] The number of characters to skip (if prefix then
465 * &c counts as one)
466 * prefix [in] Apply prefix substitution
468 * Return Values
469 * none
471 * Remarks
472 * There must be at least n characters in the string
473 * We need max because the "line" may have ended with a & followed by a tab
474 * or newline etc. which we don't want to swallow
477 static void TEXT_SkipChars (int *new_count, const WCHAR **new_str,
478 int start_count, const WCHAR *start_str,
479 int max, int n, int prefix)
481 /* This is specific to wide characters, MSDN doesn't say anything much
482 * about Unicode surrogates yet and it isn't clear if _wcsinc will
483 * correctly handle them so we'll just do this the easy way for now
486 if (prefix)
488 const WCHAR *str_on_entry = start_str;
489 assert (max >= n);
490 max -= n;
491 while (n--)
493 if ((*start_str == PREFIX || *start_str == ALPHA_PREFIX) && max--)
494 start_str++;
495 start_str++;
497 start_count -= (start_str - str_on_entry);
499 else
501 start_str += n;
502 start_count -= n;
504 *new_str = start_str;
505 *new_count = start_count;
508 /*********************************************************************
509 * TEXT_Reprefix
511 * Reanalyse the text to find the prefixed character. This is called when
512 * wordbreaking or ellipsification has shortened the string such that the
513 * previously noted prefixed character is no longer visible.
515 * Parameters
516 * str [in] The original string segment (including all characters)
517 * ns [in] The number of characters in str (including prefixes)
518 * pe [in] The ellipsification data
520 * Return Values
521 * The prefix offset within the new string segment (the one that contains the
522 * ellipses and does not contain the prefix characters) (-1 if none)
525 static int TEXT_Reprefix (const WCHAR *str, unsigned int ns,
526 const ellipsis_data *pe)
528 int result = -1;
529 unsigned int i;
530 unsigned int n = pe->before + pe->under + pe->after;
531 assert (n <= ns);
532 for (i = 0; i < n; i++, str++)
534 if (i == pe->before)
536 /* Reached the path ellipsis; jump over it */
537 if (ns < pe->under) break;
538 str += pe->under;
539 ns -= pe->under;
540 i += pe->under;
541 if (!pe->after) break; /* Nothing after the path ellipsis */
543 if (!ns) break;
544 ns--;
545 if (*str == PREFIX || *str == ALPHA_PREFIX)
547 str++;
548 if (!ns) break;
549 if (*str != PREFIX)
550 result = (i < pe->before || pe->under == 0) ? i : i - pe->under + pe->len;
551 /* pe->len may be non-zero while pe_under is zero */
552 ns--;
555 return result;
558 /*********************************************************************
559 * Returns true if and only if the remainder of the line is a single
560 * newline representation or nothing
563 static BOOL remainder_is_none_or_newline (int num_chars, const WCHAR *str)
565 if (!num_chars) return TRUE;
566 if (*str != LF && *str != CR) return FALSE;
567 if (!--num_chars) return TRUE;
568 if (*str == *(str+1)) return FALSE;
569 str++;
570 if (*str != CR && *str != LF) return FALSE;
571 if (--num_chars) return FALSE;
572 return TRUE;
575 /*********************************************************************
576 * Return next line of text from a string.
578 * hdc - handle to DC.
579 * str - string to parse into lines.
580 * count - length of str.
581 * dest - destination in which to return line.
582 * len - dest buffer size in chars on input, copied length into dest on output.
583 * width - maximum width of line in pixels.
584 * format - format type passed to DrawText.
585 * retsize - returned size of the line in pixels.
586 * last_line - TRUE if is the last line that will be processed
587 * p_retstr - If DT_MODIFYSTRING this points to a cursor in the buffer in which
588 * the return string is built.
589 * tabwidth - The width of a tab in logical coordinates
590 * pprefix_offset - Here is where we return the offset within dest of the first
591 * prefixed (underlined) character. -1 is returned if there
592 * are none. Note that there may be more; the calling code
593 * will need to use TEXT_Reprefix to find any later ones.
594 * pellip - Here is where we return the information about any ellipsification
595 * that was carried out. Note that if tabs are being expanded then
596 * this data will correspond to the last text segment actually
597 * returned in dest; by definition there would not have been any
598 * ellipsification in earlier text segments of the line.
600 * Returns pointer to next char in str after end of the line
601 * or NULL if end of str reached.
603 static const WCHAR *TEXT_NextLineW( HDC hdc, const WCHAR *str, int *count,
604 WCHAR *dest, int *len, int width, DWORD format,
605 SIZE *retsize, int last_line, WCHAR *modstr,
606 int tabwidth, int *pprefix_offset,
607 ellipsis_data *pellip)
609 int i = 0, j = 0;
610 int plen = 0;
611 SIZE size;
612 int maxl = *len;
613 int seg_i, seg_count, seg_j;
614 int max_seg_width;
615 int num_fit;
616 BOOL word_broken, line_fits, ellipsified;
617 unsigned int j_in_seg;
618 *pprefix_offset = -1;
620 /* For each text segment in the line */
622 retsize->cy = 0;
623 while (*count)
626 /* Skip any leading tabs */
628 if (str[i] == TAB && (format & DT_EXPANDTABS))
630 plen = ((plen/tabwidth)+1)*tabwidth;
631 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
632 while (*count && str[i] == TAB)
634 plen += tabwidth;
635 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
640 /* Now copy as far as the next tab or cr/lf or eos */
642 seg_i = i;
643 seg_count = *count;
644 seg_j = j;
646 while (*count &&
647 (str[i] != TAB || !(format & DT_EXPANDTABS)) &&
648 ((str[i] != CR && str[i] != LF) || (format & DT_SINGLELINE)))
650 if ((format & DT_NOPREFIX) || *count <= 1)
652 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
653 continue;
656 if (str[i] == PREFIX || str[i] == ALPHA_PREFIX) {
657 (*count)--, i++; /* Throw away the prefix itself */
658 if (str[i] == PREFIX)
660 /* Swallow it before we see it again */
661 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
663 else if (*pprefix_offset == -1 || *pprefix_offset >= seg_j)
665 *pprefix_offset = j;
667 /* else the previous prefix was in an earlier segment of the
668 * line; we will leave it to the drawing code to catch this
669 * one.
672 else if (str[i] == KANA_PREFIX)
674 /* Throw away katakana access keys */
675 (*count)--, i++; /* skip the prefix */
676 (*count)--; i++; /* skip the letter */
678 else
680 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
685 /* Measure the whole text segment and possibly WordBreak and
686 * ellipsify it
689 j_in_seg = j - seg_j;
690 max_seg_width = width - plen;
691 GetTextExtentExPointW (hdc, dest + seg_j, j_in_seg, max_seg_width, &num_fit, NULL, &size);
693 /* The Microsoft handling of various combinations of formats is weird.
694 * The following may very easily be incorrect if several formats are
695 * combined, and may differ between versions (to say nothing of the
696 * several bugs in the Microsoft versions).
698 word_broken = FALSE;
699 line_fits = (num_fit >= j_in_seg);
700 if (!line_fits && (format & DT_WORDBREAK))
702 const WCHAR *s;
703 unsigned int chars_used;
704 TEXT_WordBreak (hdc, dest+seg_j, maxl-seg_j, &j_in_seg,
705 max_seg_width, format, num_fit, &chars_used, &size);
706 line_fits = (size.cx <= max_seg_width);
707 /* and correct the counts */
708 TEXT_SkipChars (count, &s, seg_count, str+seg_i, i-seg_i,
709 chars_used, !(format & DT_NOPREFIX));
710 i = s - str;
711 word_broken = TRUE;
713 pellip->before = j_in_seg;
714 pellip->under = 0;
715 pellip->after = 0;
716 pellip->len = 0;
717 ellipsified = FALSE;
718 if (!line_fits && (format & DT_PATH_ELLIPSIS))
720 TEXT_PathEllipsify (hdc, dest + seg_j, maxl-seg_j, &j_in_seg,
721 max_seg_width, &size, modstr, pellip);
722 line_fits = (size.cx <= max_seg_width);
723 ellipsified = TRUE;
725 /* NB we may end up ellipsifying a word-broken or path_ellipsified
726 * string */
727 if ((!line_fits && (format & DT_WORD_ELLIPSIS)) ||
728 ((format & DT_END_ELLIPSIS) &&
729 ((last_line && *count) ||
730 (remainder_is_none_or_newline (*count, &str[i]) && !line_fits))))
732 int before, len_ellipsis;
733 TEXT_Ellipsify (hdc, dest + seg_j, maxl-seg_j, &j_in_seg,
734 max_seg_width, &size, modstr, &before, &len_ellipsis);
735 if (before > pellip->before)
737 /* We must have done a path ellipsis too */
738 pellip->after = before - pellip->before - pellip->len;
739 /* Leave the len as the length of the first ellipsis */
741 else
743 /* If we are here after a path ellipsification it must be
744 * because even the ellipsis itself didn't fit.
746 assert (pellip->under == 0 && pellip->after == 0);
747 pellip->before = before;
748 pellip->len = len_ellipsis;
749 /* pellip->after remains as zero as does
750 * pellip->under
753 ellipsified = 1;
755 /* As an optimisation if we have ellipsified and we are expanding
756 * tabs and we haven't reached the end of the line we can skip to it
757 * now rather than going around the loop again.
759 if ((format & DT_EXPANDTABS) && ellipsified)
761 if (format & DT_SINGLELINE)
762 *count = 0;
763 else
765 while ((*count) && str[i] != CR && str[i] != LF)
767 (*count)--, i++;
772 j = seg_j + j_in_seg;
773 if (*pprefix_offset >= seg_j + pellip->before)
775 *pprefix_offset = TEXT_Reprefix (str + seg_i, i - seg_i, pellip);
776 if (*pprefix_offset != -1)
777 *pprefix_offset += seg_j;
780 plen += size.cx;
781 if (size.cy > retsize->cy)
782 retsize->cy = size.cy;
784 if (word_broken)
785 break;
786 else if (!*count)
787 break;
788 else if (str[i] == CR || str[i] == LF)
790 (*count)--, i++;
791 if (*count && (str[i] == CR || str[i] == LF) && str[i] != str[i-1])
793 (*count)--, i++;
795 break;
797 /* else it was a Tab and we go around again */
800 retsize->cx = plen;
801 *len = j;
802 if (*count)
803 return (&str[i]);
804 else
805 return NULL;
809 /***********************************************************************
810 * TEXT_DrawUnderscore
812 * Draw the underline under the prefixed character
814 * Parameters
815 * hdc [in] The handle of the DC for drawing
816 * x [in] The x location of the line segment (logical coordinates)
817 * y [in] The y location of where the underscore should appear
818 * (logical coordinates)
819 * str [in] The text of the line segment
820 * offset [in] The offset of the underscored character within str
821 * rect [in] Clipping rectangle (if not NULL)
824 static void TEXT_DrawUnderscore (HDC hdc, int x, int y, const WCHAR *str, int offset, const RECT *rect)
826 int prefix_x;
827 int prefix_end;
828 SIZE size;
829 HPEN hpen;
830 HPEN oldPen;
832 GetTextExtentPointW (hdc, str, offset, &size);
833 prefix_x = x + size.cx;
834 GetTextExtentPointW (hdc, str, offset+1, &size);
835 prefix_end = x + size.cx - 1;
836 /* The above method may eventually be slightly wrong due to kerning etc. */
838 /* Check for clipping */
839 if (rect){
840 if (prefix_x > rect->right || prefix_end < rect->left || y < rect->top || y > rect->bottom)
841 return; /* Completely outside */
842 /* Partially outside */
843 if (prefix_x < rect->left ) prefix_x = rect->left;
844 if (prefix_end > rect->right) prefix_end = rect->right;
847 hpen = CreatePen (PS_SOLID, 1, GetTextColor (hdc));
848 oldPen = SelectObject (hdc, hpen);
849 MoveToEx (hdc, prefix_x, y, NULL);
850 LineTo (hdc, prefix_end, y);
851 SelectObject (hdc, oldPen);
852 DeleteObject (hpen);
855 /***********************************************************************
856 * DrawTextExW (USER32.@)
858 * The documentation on the extra space required for DT_MODIFYSTRING at MSDN
859 * is not quite complete, especially with regard to \0. We will assume that
860 * the returned string could have a length of up to i_count+3 and also have
861 * a trailing \0 (which would be 4 more than a not-null-terminated string but
862 * 3 more than a null-terminated string). If this is not so then increase
863 * the allowance in DrawTextExA.
865 #define MAX_BUFFER 1024
866 INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count,
867 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
869 SIZE size;
870 const WCHAR *strPtr;
871 WCHAR *retstr;
872 size_t size_retstr;
873 WCHAR line[MAX_BUFFER];
874 int len, lh, count=i_count;
875 TEXTMETRICW tm;
876 int lmargin = 0, rmargin = 0;
877 int x, y, width;
878 int max_width = 0;
879 int last_line;
880 int tabwidth /* to keep gcc happy */ = 0;
881 int prefix_offset;
882 ellipsis_data ellip;
883 BOOL invert_y=FALSE;
884 int ret = 0;
886 TRACE("%s, %d, [%s] %08x\n", debugstr_wn (str, count), count,
887 wine_dbgstr_rect(rect), flags);
889 if (dtp) TRACE("Params: iTabLength=%d, iLeftMargin=%d, iRightMargin=%d\n",
890 dtp->iTabLength, dtp->iLeftMargin, dtp->iRightMargin);
892 if (!str) return 0;
894 strPtr = str;
896 if (flags & DT_SINGLELINE)
897 flags &= ~DT_WORDBREAK;
899 if (!GetTextMetricsW(hdc, &tm))
900 return 0;
902 x = rect->left;
903 y = rect->top;
904 width = rect->right - rect->left;
906 if (flags & DT_EXTERNALLEADING)
907 lh = tm.tmHeight + tm.tmExternalLeading;
908 else
909 lh = tm.tmHeight;
911 if (str[0] && count == 0)
912 return lh;
914 if (dtp && dtp->cbSize != sizeof(DRAWTEXTPARAMS))
915 return 0;
917 if (count == -1)
919 count = lstrlenW(str);
920 if (count == 0)
922 if( flags & DT_CALCRECT)
924 rect->right = rect->left;
925 if( flags & DT_SINGLELINE)
926 rect->bottom = rect->top + lh;
927 else
928 rect->bottom = rect->top;
930 return lh;
934 if (GetGraphicsMode(hdc) == GM_COMPATIBLE)
936 SIZE window_ext, viewport_ext;
937 GetWindowExtEx(hdc, &window_ext);
938 GetViewportExtEx(hdc, &viewport_ext);
939 if ((window_ext.cy > 0) != (viewport_ext.cy > 0))
940 invert_y = TRUE;
943 if (dtp)
945 lmargin = dtp->iLeftMargin;
946 rmargin = dtp->iRightMargin;
947 width -= lmargin + rmargin;
948 if (!(flags & (DT_CENTER | DT_RIGHT)))
949 x += lmargin;
950 dtp->uiLengthDrawn = 0; /* This param RECEIVES number of chars processed */
953 if (flags & DT_EXPANDTABS)
955 int tabstop = ((flags & DT_TABSTOP) && dtp && dtp->iTabLength) ? dtp->iTabLength : 8;
956 tabwidth = tm.tmAveCharWidth * tabstop;
959 if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
961 if (flags & DT_MODIFYSTRING)
963 size_retstr = (count + 4) * sizeof (WCHAR);
964 retstr = heap_alloc(size_retstr);
965 if (!retstr) return 0;
966 memcpy (retstr, str, size_retstr);
968 else
970 size_retstr = 0;
971 retstr = NULL;
976 len = ARRAY_SIZE(line);
977 if (invert_y)
978 last_line = !(flags & DT_NOCLIP) && y - ((flags & DT_EDITCONTROL) ? 2*lh-1 : lh) < rect->bottom;
979 else
980 last_line = !(flags & DT_NOCLIP) && y + ((flags & DT_EDITCONTROL) ? 2*lh-1 : lh) > rect->bottom;
981 strPtr = TEXT_NextLineW(hdc, strPtr, &count, line, &len, width, flags, &size, last_line, retstr, tabwidth, &prefix_offset, &ellip);
983 if (flags & DT_CENTER)
984 x = (rect->left + lmargin + rect->right - rmargin - size.cx) / 2;
985 else if (flags & DT_RIGHT)
986 x = rect->right - size.cx - rmargin;
988 if (flags & DT_SINGLELINE)
990 if (flags & DT_VCENTER) y = rect->top +
991 (rect->bottom - rect->top) / 2 - size.cy / 2;
992 else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
995 if (!(flags & DT_CALCRECT))
997 const WCHAR *str = line;
998 int xseg = x;
999 while (len)
1001 int len_seg;
1002 SIZE size;
1003 if ((flags & DT_EXPANDTABS))
1005 const WCHAR *p;
1006 p = str; while (p < str+len && *p != TAB) p++;
1007 len_seg = p - str;
1008 if (len_seg != len && !GetTextExtentPointW(hdc, str, len_seg, &size)) goto done;
1010 else
1011 len_seg = len;
1013 if (!ExtTextOutW( hdc, xseg, y,
1014 ((flags & DT_NOCLIP) ? 0 : ETO_CLIPPED) |
1015 ((flags & DT_RTLREADING) ? ETO_RTLREADING : 0),
1016 rect, str, len_seg, NULL ))
1017 goto done;
1018 if (prefix_offset != -1 && prefix_offset < len_seg)
1020 TEXT_DrawUnderscore (hdc, xseg, y + tm.tmAscent + 1, str, prefix_offset, (flags & DT_NOCLIP) ? NULL : rect);
1022 len -= len_seg;
1023 str += len_seg;
1024 if (len)
1026 assert ((flags & DT_EXPANDTABS) && *str == TAB);
1027 len--; str++;
1028 xseg += ((size.cx/tabwidth)+1)*tabwidth;
1029 if (prefix_offset != -1)
1031 if (prefix_offset < len_seg)
1033 /* We have just drawn an underscore; we ought to
1034 * figure out where the next one is. I am going
1035 * to leave it for now until I have a better model
1036 * for the line, which will make reprefixing easier.
1037 * This is where ellip would be used.
1039 prefix_offset = -1;
1041 else
1042 prefix_offset -= len_seg;
1047 else if (size.cx > max_width)
1048 max_width = size.cx;
1050 if (invert_y)
1051 y -= lh;
1052 else
1053 y += lh;
1054 if (dtp)
1055 dtp->uiLengthDrawn += len;
1057 while (strPtr && !last_line);
1059 if (flags & DT_CALCRECT)
1061 rect->right = rect->left + max_width;
1062 rect->bottom = y;
1063 if (dtp)
1064 rect->right += lmargin + rmargin;
1067 if (retstr) memcpy(str, retstr, size_retstr);
1069 ret = y - rect->top;
1070 if (ret == 0) ret = 1;
1071 done:
1072 heap_free(retstr);
1073 return ret;
1076 /***********************************************************************
1077 * DrawTextExA (USER32.@)
1079 * If DT_MODIFYSTRING is specified then there must be room for up to
1080 * 4 extra characters. We take great care about just how much modified
1081 * string we return.
1083 INT WINAPI DrawTextExA( HDC hdc, LPSTR str, INT count,
1084 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
1086 WCHAR *wstr;
1087 WCHAR *p;
1088 INT ret = 0;
1089 int i;
1090 DWORD wcount;
1091 DWORD wmax;
1092 DWORD amax;
1093 UINT cp;
1094 TEXTMETRICA tm;
1096 if (!GetTextMetricsA(hdc, &tm))
1098 SetLastError(ERROR_INVALID_HANDLE);
1099 return 0;
1102 if (!count) return 0;
1103 if (!str && count > 0) return 0;
1104 if( !str || ((count == -1) && !(count = strlen(str))))
1106 int lh;
1108 if (dtp && dtp->cbSize != sizeof(DRAWTEXTPARAMS))
1109 return 0;
1112 if (flags & DT_EXTERNALLEADING)
1113 lh = tm.tmHeight + tm.tmExternalLeading;
1114 else
1115 lh = tm.tmHeight;
1117 if( flags & DT_CALCRECT)
1119 rect->right = rect->left;
1120 if( flags & DT_SINGLELINE)
1121 rect->bottom = rect->top + lh;
1122 else
1123 rect->bottom = rect->top;
1125 return lh;
1127 cp = GdiGetCodePage( hdc );
1128 wcount = MultiByteToWideChar( cp, 0, str, count, NULL, 0 );
1129 wmax = wcount;
1130 amax = count;
1131 if (flags & DT_MODIFYSTRING)
1133 wmax += 4;
1134 amax += 4;
1136 wstr = heap_alloc(wmax * sizeof(WCHAR));
1137 if (wstr)
1139 MultiByteToWideChar( cp, 0, str, count, wstr, wcount );
1140 if (flags & DT_MODIFYSTRING)
1141 for (i=4, p=wstr+wcount; i--; p++) *p=0xFFFE;
1142 /* Initialise the extra characters so that we can see which ones
1143 * change. U+FFFE is guaranteed to be not a unicode character and
1144 * so will not be generated by DrawTextEx itself.
1146 ret = DrawTextExW( hdc, wstr, wcount, rect, flags, dtp );
1147 if (flags & DT_MODIFYSTRING)
1149 /* Unfortunately the returned string may contain multiple \0s
1150 * and so we need to measure it ourselves.
1152 for (i=4, p=wstr+wcount; i-- && *p != 0xFFFE; p++) wcount++;
1153 WideCharToMultiByte( cp, 0, wstr, wcount, str, amax, NULL, NULL );
1155 heap_free(wstr);
1157 return ret;
1160 /***********************************************************************
1161 * DrawTextW (USER32.@)
1163 INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags )
1165 DRAWTEXTPARAMS dtp;
1167 memset (&dtp, 0, sizeof(dtp));
1168 dtp.cbSize = sizeof(dtp);
1169 if (flags & DT_TABSTOP)
1171 dtp.iTabLength = (flags >> 8) & 0xff;
1172 flags &= 0xffff00ff;
1174 return DrawTextExW(hdc, (LPWSTR)str, count, rect, flags, &dtp);
1177 /***********************************************************************
1178 * DrawTextA (USER32.@)
1180 INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count, LPRECT rect, UINT flags )
1182 DRAWTEXTPARAMS dtp;
1184 memset (&dtp, 0, sizeof(dtp));
1185 dtp.cbSize = sizeof(dtp);
1186 if (flags & DT_TABSTOP)
1188 dtp.iTabLength = (flags >> 8) & 0xff;
1189 flags &= 0xffff00ff;
1191 return DrawTextExA( hdc, (LPSTR)str, count, rect, flags, &dtp );
1194 /***********************************************************************
1196 * GrayString functions
1199 /* callback for ANSI gray string proc */
1200 static BOOL CALLBACK gray_string_callbackA( HDC hdc, LPARAM param, INT len )
1202 return TextOutA( hdc, 0, 0, (LPCSTR)param, len );
1205 /* callback for Unicode gray string proc */
1206 static BOOL CALLBACK gray_string_callbackW( HDC hdc, LPARAM param, INT len )
1208 return TextOutW( hdc, 0, 0, (LPCWSTR)param, len );
1211 /***********************************************************************
1212 * TEXT_GrayString
1214 static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb, GRAYSTRINGPROC fn, LPARAM lp, INT len,
1215 INT x, INT y, INT cx, INT cy )
1217 HBITMAP hbm, hbmsave;
1218 HBRUSH hbsave;
1219 HFONT hfsave;
1220 HDC memdc;
1221 int slen = len;
1222 BOOL retval;
1223 COLORREF fg, bg;
1225 if(!hdc) return FALSE;
1226 if (!(memdc = CreateCompatibleDC(hdc))) return FALSE;
1228 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1229 hbmsave = SelectObject(memdc, hbm);
1230 hbsave = SelectObject( memdc, GetStockObject(BLACK_BRUSH) );
1231 PatBlt( memdc, 0, 0, cx, cy, PATCOPY );
1232 SelectObject( memdc, hbsave );
1233 SetTextColor(memdc, RGB(255, 255, 255));
1234 SetBkColor(memdc, RGB(0, 0, 0));
1235 hfsave = SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1237 retval = fn(memdc, lp, slen);
1238 SelectObject(memdc, hfsave);
1241 * Windows doc says that the bitmap isn't grayed when len == -1 and
1242 * the callback function returns FALSE. However, testing this on
1243 * win95 showed otherwise...
1245 #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
1246 if(retval || len != -1)
1247 #endif
1249 hbsave = SelectObject(memdc, SYSCOLOR_Get55AABrush());
1250 PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
1251 SelectObject(memdc, hbsave);
1254 if(hb) hbsave = SelectObject(hdc, hb);
1255 fg = SetTextColor(hdc, RGB(0, 0, 0));
1256 bg = SetBkColor(hdc, RGB(255, 255, 255));
1257 BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746);
1258 SetTextColor(hdc, fg);
1259 SetBkColor(hdc, bg);
1260 if(hb) SelectObject(hdc, hbsave);
1262 SelectObject(memdc, hbmsave);
1263 DeleteObject(hbm);
1264 DeleteDC(memdc);
1265 return retval;
1269 /***********************************************************************
1270 * GrayStringA (USER32.@)
1272 BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
1273 LPARAM lParam, INT cch, INT x, INT y,
1274 INT cx, INT cy )
1276 if (!cch) cch = strlen( (LPCSTR)lParam );
1277 if ((cx == 0 || cy == 0) && cch != -1)
1279 SIZE s;
1280 GetTextExtentPoint32A( hdc, (LPCSTR)lParam, cch, &s );
1281 if (cx == 0) cx = s.cx;
1282 if (cy == 0) cy = s.cy;
1284 if (!gsprc) gsprc = gray_string_callbackA;
1285 return TEXT_GrayString( hdc, hbr, gsprc, lParam, cch, x, y, cx, cy );
1289 /***********************************************************************
1290 * GrayStringW (USER32.@)
1292 BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
1293 LPARAM lParam, INT cch, INT x, INT y,
1294 INT cx, INT cy )
1296 if (!cch) cch = lstrlenW( (LPCWSTR)lParam );
1297 if ((cx == 0 || cy == 0) && cch != -1)
1299 SIZE s;
1300 GetTextExtentPoint32W( hdc, (LPCWSTR)lParam, cch, &s );
1301 if (cx == 0) cx = s.cx;
1302 if (cy == 0) cy = s.cy;
1304 if (!gsprc) gsprc = gray_string_callbackW;
1305 return TEXT_GrayString( hdc, hbr, gsprc, lParam, cch, x, y, cx, cy );
1309 /***********************************************************************
1310 * TEXT_TabbedTextOut
1312 * Helper function for TabbedTextOut() and GetTabbedTextExtent().
1313 * Note: this doesn't work too well for text-alignment modes other
1314 * than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
1316 static LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCWSTR lpstr,
1317 INT count, INT cTabStops, const INT *lpTabPos, INT nTabOrg,
1318 BOOL fDisplayText )
1320 INT defWidth;
1321 SIZE extent;
1322 int i, j;
1323 int start = x;
1324 TEXTMETRICW tm;
1326 if (!lpstr || count == 0) return 0;
1328 if (!lpTabPos)
1329 cTabStops=0;
1331 GetTextMetricsW( hdc, &tm );
1333 if (cTabStops == 1)
1335 defWidth = *lpTabPos;
1336 cTabStops = 0;
1338 else
1340 defWidth = 8 * tm.tmAveCharWidth;
1343 while (count > 0)
1345 RECT r;
1346 INT x0;
1347 x0 = x;
1348 r.left = x0;
1349 /* chop the string into substrings of 0 or more <tabs>
1350 * possibly followed by 1 or more normal characters */
1351 for (i = 0; i < count; i++)
1352 if (lpstr[i] != '\t') break;
1353 for (j = i; j < count; j++)
1354 if (lpstr[j] == '\t') break;
1355 /* get the extent of the normal character part */
1356 GetTextExtentPointW( hdc, lpstr + i, j - i , &extent );
1357 /* and if there is a <tab>, calculate its position */
1358 if( i) {
1359 /* get x coordinate for the drawing of this string */
1360 for (; cTabStops >= i; lpTabPos++, cTabStops--)
1362 if( nTabOrg + abs( *lpTabPos) > x) {
1363 if( lpTabPos[ i - 1] >= 0) {
1364 /* a left aligned tab */
1365 x0 = nTabOrg + lpTabPos[i-1];
1366 x = x0 + extent.cx;
1367 break;
1369 else
1371 /* if tab pos is negative then text is right-aligned
1372 * to tab stop meaning that the string extends to the
1373 * left, so we must subtract the width of the string */
1374 if (nTabOrg - lpTabPos[ i - 1] - extent.cx > x)
1376 x = nTabOrg - lpTabPos[ i - 1];
1377 x0 = x - extent.cx;
1378 break;
1383 /* if we have run out of tab stops and we have a valid default tab
1384 * stop width then round x up to that width */
1385 if ((cTabStops < i) && (defWidth > 0)) {
1386 x0 = nTabOrg + ((x - nTabOrg) / defWidth + i) * defWidth;
1387 x = x0 + extent.cx;
1388 } else if ((cTabStops < i) && (defWidth < 0)) {
1389 x = nTabOrg + ((x - nTabOrg + extent.cx) / -defWidth + i)
1390 * -defWidth;
1391 x0 = x - extent.cx;
1393 } else
1394 x += extent.cx;
1396 if (!extent.cy) extent.cy = tm.tmHeight;
1398 if (fDisplayText)
1400 r.top = y;
1401 r.right = x;
1402 r.bottom = y + extent.cy;
1403 ExtTextOutW( hdc, x0, y, GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
1404 &r, lpstr + i, j - i, NULL );
1406 count -= j;
1407 lpstr += j;
1410 return MAKELONG(x - start, extent.cy);
1414 /***********************************************************************
1415 * TabbedTextOutA (USER32.@)
1417 * See TabbedTextOutW.
1419 LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr, INT count,
1420 INT cTabStops, const INT *lpTabPos, INT nTabOrg )
1422 LONG ret;
1423 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpstr, count, NULL, 0 );
1424 LPWSTR strW = heap_alloc( len * sizeof(WCHAR) );
1425 if (!strW) return 0;
1426 MultiByteToWideChar( CP_ACP, 0, lpstr, count, strW, len );
1427 ret = TabbedTextOutW( hdc, x, y, strW, len, cTabStops, lpTabPos, nTabOrg );
1428 heap_free( strW );
1429 return ret;
1433 /***********************************************************************
1434 * TabbedTextOutW (USER32.@)
1436 * Draws tabbed text aligned using the specified tab stops.
1438 * PARAMS
1439 * hdc [I] Handle to device context to draw to.
1440 * x [I] X co-ordinate to start drawing the text at in logical units.
1441 * y [I] Y co-ordinate to start drawing the text at in logical units.
1442 * str [I] Pointer to the characters to draw.
1443 * count [I] Number of WCHARs pointed to by str.
1444 * cTabStops [I] Number of tab stops pointed to by lpTabPos.
1445 * lpTabPos [I] Tab stops in logical units. Should be sorted in ascending order.
1446 * nTabOrg [I] Starting position to expand tabs from in logical units.
1448 * RETURNS
1449 * The dimensions of the string drawn. The height is in the high-order word
1450 * and the width is in the low-order word.
1452 * NOTES
1453 * The tabs stops can be negative, in which case the text is right aligned to
1454 * that tab stop and, despite what MSDN says, this is supported on
1455 * Windows XP SP2.
1457 * BUGS
1458 * MSDN says that the TA_UPDATECP from GetTextAlign causes this function to
1459 * ignore the x and y co-ordinates, but this is unimplemented at the moment.
1461 LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str, INT count,
1462 INT cTabStops, const INT *lpTabPos, INT nTabOrg )
1464 TRACE("%p %d,%d %s %d\n", hdc, x, y, debugstr_wn(str,count), count );
1465 return TEXT_TabbedTextOut( hdc, x, y, str, count, cTabStops, lpTabPos, nTabOrg, TRUE );
1469 /***********************************************************************
1470 * GetTabbedTextExtentA (USER32.@)
1472 DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count,
1473 INT cTabStops, const INT *lpTabPos )
1475 LONG ret;
1476 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpstr, count, NULL, 0 );
1477 LPWSTR strW = heap_alloc( len * sizeof(WCHAR) );
1478 if (!strW) return 0;
1479 MultiByteToWideChar( CP_ACP, 0, lpstr, count, strW, len );
1480 ret = GetTabbedTextExtentW( hdc, strW, len, cTabStops, lpTabPos );
1481 heap_free( strW );
1482 return ret;
1486 /***********************************************************************
1487 * GetTabbedTextExtentW (USER32.@)
1489 DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count,
1490 INT cTabStops, const INT *lpTabPos )
1492 TRACE("%p %s %d\n", hdc, debugstr_wn(lpstr,count), count );
1493 return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops, lpTabPos, 0, FALSE );