ntoskrnl.exe: Implement ExAcquireFastMutex and ExReleaseFastMutex.
[wine.git] / dlls / user32 / text.c
blobfd0751e6f6ac0b10fe283e7bd2ce136dfa919f0e
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 "config.h"
28 #include "wine/port.h"
30 #include <stdarg.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <assert.h>
35 #include "windef.h"
36 #include "winbase.h"
37 #include "wingdi.h"
38 #include "wine/unicode.h"
39 #include "winnls.h"
40 #include "controls.h"
41 #include "usp10.h"
42 #include "user_private.h"
43 #include "wine/debug.h"
44 #include "wine/heap.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(text);
48 /*********************************************************************
50 * DrawText functions
52 * Design issues
53 * How many buffers to use
54 * While processing in DrawText there are potentially three different forms
55 * of the text that need to be held. How are they best held?
56 * 1. The original text is needed, of course, to see what to display.
57 * 2. The text that will be returned to the user if the DT_MODIFYSTRING is
58 * in effect.
59 * 3. The buffered text that is about to be displayed e.g. the current line.
60 * Typically this will exclude the ampersands used for prefixing etc.
62 * Complications.
63 * a. If the buffered text to be displayed includes the ampersands then
64 * we will need special measurement and draw functions that will ignore
65 * the ampersands (e.g. by copying to a buffer without the prefix and
66 * then using the normal forms). This may involve less space but may
67 * require more processing. e.g. since a line containing tabs may
68 * contain several underlined characters either we need to carry around
69 * a list of prefix locations or we may need to locate them several
70 * times.
71 * b. If we actually directly modify the "original text" as we go then we
72 * will need some special "caching" to handle the fact that when we
73 * ellipsify the text the ellipsis may modify the next line of text,
74 * which we have not yet processed. (e.g. ellipsification of a W at the
75 * end of a line will overwrite the W, the \n and the first character of
76 * the next line, and a \0 will overwrite the second. Try it!!)
78 * Option 1. Three separate storages. (To be implemented)
79 * If DT_MODIFYSTRING is in effect then allocate an extra buffer to hold
80 * the edited string in some form, either as the string itself or as some
81 * sort of "edit list" to be applied just before returning.
82 * Use a buffer that holds the ellipsified current line sans ampersands
83 * and accept the need occasionally to recalculate the prefixes (if
84 * DT_EXPANDTABS and not DT_NOPREFIX and not DT_HIDEPREFIX)
87 #define TAB 9
88 #define LF 10
89 #define CR 13
90 #define SPACE 32
91 #define PREFIX 38
92 #define ALPHA_PREFIX 30 /* Win16: Alphabet prefix */
93 #define KANA_PREFIX 31 /* Win16: Katakana prefix */
95 #define FORWARD_SLASH '/'
96 #define BACK_SLASH '\\'
98 static const WCHAR ELLIPSISW[] = {'.','.','.', 0};
100 typedef struct tag_ellipsis_data
102 int before;
103 int len;
104 int under;
105 int after;
106 } ellipsis_data;
108 /*********************************************************************
109 * TEXT_Ellipsify (static)
111 * Add an ellipsis to the end of the given string whilst ensuring it fits.
113 * If the ellipsis alone doesn't fit then it will be returned anyway.
115 * See Also TEXT_PathEllipsify
117 * Arguments
118 * hdc [in] The handle to the DC that defines the font.
119 * str [in/out] The string that needs to be modified.
120 * max_str [in] The dimension of str (number of WCHAR).
121 * len_str [in/out] The number of characters in str
122 * width [in] The maximum width permitted (in logical coordinates)
123 * size [out] The dimensions of the text
124 * modstr [out] The modified form of the string, to be returned to the
125 * calling program. It is assumed that the caller has
126 * made sufficient space available so we don't need to
127 * know the size of the space. This pointer may be NULL if
128 * the modified string is not required.
129 * len_before [out] The number of characters before the ellipsis.
130 * len_ellip [out] The number of characters in the ellipsis.
132 * See for example Microsoft article Q249678.
134 * For now we will simply use three dots rather than worrying about whether
135 * the font contains an explicit ellipsis character.
137 static void TEXT_Ellipsify (HDC hdc, WCHAR *str, unsigned int max_len,
138 unsigned int *len_str, int width, SIZE *size,
139 WCHAR *modstr,
140 int *len_before, int *len_ellip)
142 unsigned int len_ellipsis;
143 unsigned int lo, mid, hi;
145 len_ellipsis = strlenW (ELLIPSISW);
146 if (len_ellipsis > max_len) len_ellipsis = max_len;
147 if (*len_str > max_len - len_ellipsis)
148 *len_str = max_len - len_ellipsis;
150 /* First do a quick binary search to get an upper bound for *len_str. */
151 if (*len_str > 0 &&
152 GetTextExtentExPointW(hdc, str, *len_str, width, NULL, NULL, size) &&
153 size->cx > width)
155 for (lo = 0, hi = *len_str; lo < hi; )
157 mid = (lo + hi) / 2;
158 if (!GetTextExtentExPointW(hdc, str, mid, width, NULL, NULL, size))
159 break;
160 if (size->cx > width)
161 hi = mid;
162 else
163 lo = mid + 1;
165 *len_str = hi;
167 /* Now this should take only a couple iterations at most. */
168 for ( ; ; )
170 memcpy(str + *len_str, ELLIPSISW, len_ellipsis*sizeof(WCHAR));
172 if (!GetTextExtentExPointW (hdc, str, *len_str + len_ellipsis, width,
173 NULL, NULL, size)) break;
175 if (!*len_str || size->cx <= width) break;
177 (*len_str)--;
179 *len_ellip = len_ellipsis;
180 *len_before = *len_str;
181 *len_str += len_ellipsis;
183 if (modstr)
185 memcpy (modstr, str, *len_str * sizeof(WCHAR));
186 modstr[*len_str] = '\0';
190 /*********************************************************************
191 * TEXT_PathEllipsify (static)
193 * Add an ellipsis to the provided string in order to make it fit within
194 * the width. The ellipsis is added as specified for the DT_PATH_ELLIPSIS
195 * flag.
197 * See Also TEXT_Ellipsify
199 * Arguments
200 * hdc [in] The handle to the DC that defines the font.
201 * str [in/out] The string that needs to be modified
202 * max_str [in] The dimension of str (number of WCHAR).
203 * len_str [in/out] The number of characters in str
204 * width [in] The maximum width permitted (in logical coordinates)
205 * size [out] The dimensions of the text
206 * modstr [out] The modified form of the string, to be returned to the
207 * calling program. It is assumed that the caller has
208 * made sufficient space available so we don't need to
209 * know the size of the space. This pointer may be NULL if
210 * the modified string is not required.
211 * pellip [out] The ellipsification results
213 * For now we will simply use three dots rather than worrying about whether
214 * the font contains an explicit ellipsis character.
216 * The following applies, I think to Win95. We will need to extend it for
217 * Win98 which can have both path and end ellipsis at the same time (e.g.
218 * C:\MyLongFileName.Txt becomes ...\MyLongFileN...)
220 * The resulting string consists of as much as possible of the following:
221 * 1. The ellipsis itself
222 * 2. The last \ or / of the string (if any)
223 * 3. Everything after the last \ or / of the string (if any) or the whole
224 * string if there is no / or \. I believe that under Win95 this would
225 * include everything even though some might be clipped off the end whereas
226 * under Win98 that might be ellipsified too.
227 * Yet to be investigated is whether this would include wordbreaking if the
228 * filename is more than 1 word and splitting if DT_EDITCONTROL was in
229 * effect. (If DT_EDITCONTROL is in effect then on occasions text will be
230 * broken within words).
231 * 4. All the stuff before the / or \, which is placed before the ellipsis.
233 static void TEXT_PathEllipsify (HDC hdc, WCHAR *str, unsigned int max_len,
234 unsigned int *len_str, int width, SIZE *size,
235 WCHAR *modstr, ellipsis_data *pellip)
237 int len_ellipsis;
238 int len_trailing;
239 int len_under;
240 WCHAR *lastBkSlash, *lastFwdSlash, *lastSlash;
242 len_ellipsis = strlenW (ELLIPSISW);
243 if (!max_len) return;
244 if (len_ellipsis >= max_len) len_ellipsis = max_len - 1;
245 if (*len_str + len_ellipsis >= max_len)
246 *len_str = max_len - len_ellipsis-1;
247 /* Hopefully this will never happen, otherwise it would probably lose
248 * the wrong character
250 str[*len_str] = '\0'; /* to simplify things */
252 lastBkSlash = strrchrW (str, BACK_SLASH);
253 lastFwdSlash = strrchrW (str, FORWARD_SLASH);
254 lastSlash = lastBkSlash > lastFwdSlash ? lastBkSlash : lastFwdSlash;
255 if (!lastSlash) lastSlash = str;
256 len_trailing = *len_str - (lastSlash - str);
258 /* overlap-safe movement to the right */
259 memmove (lastSlash+len_ellipsis, lastSlash, len_trailing * sizeof(WCHAR));
260 memcpy (lastSlash, ELLIPSISW, len_ellipsis*sizeof(WCHAR));
261 len_trailing += len_ellipsis;
262 /* From this point on lastSlash actually points to the ellipsis in front
263 * of the last slash and len_trailing includes the ellipsis
266 len_under = 0;
267 for ( ; ; )
269 if (!GetTextExtentExPointW (hdc, str, *len_str + len_ellipsis, width,
270 NULL, NULL, size)) break;
272 if (lastSlash == str || size->cx <= width) break;
274 /* overlap-safe movement to the left */
275 memmove (lastSlash-1, lastSlash, len_trailing * sizeof(WCHAR));
276 lastSlash--;
277 len_under++;
279 assert (*len_str);
280 (*len_str)--;
282 pellip->before = lastSlash-str;
283 pellip->len = len_ellipsis;
284 pellip->under = len_under;
285 pellip->after = len_trailing - len_ellipsis;
286 *len_str += len_ellipsis;
288 if (modstr)
290 memcpy(modstr, str, *len_str * sizeof(WCHAR));
291 modstr[*len_str] = '\0';
295 /*********************************************************************
296 * TEXT_WordBreak (static)
298 * Perform wordbreak processing on the given string
300 * Assumes that DT_WORDBREAK has been specified and not all the characters
301 * fit. Note that this function should even be called when the first character
302 * that doesn't fit is known to be a space or tab, so that it can swallow them.
304 * Note that the Windows processing has some strange properties.
305 * 1. If the text is left-justified and there is room for some of the spaces
306 * that follow the last word on the line then those that fit are included on
307 * the line.
308 * 2. If the text is centered or right-justified and there is room for some of
309 * the spaces that follow the last word on the line then all but one of those
310 * that fit are included on the line.
311 * 3. (Reasonable behaviour) If the word breaking causes a space to be the first
312 * character of a new line it will be skipped.
314 * Arguments
315 * hdc [in] The handle to the DC that defines the font.
316 * str [in/out] The string that needs to be broken.
317 * max_str [in] The dimension of str (number of WCHAR).
318 * len_str [in/out] The number of characters in str
319 * width [in] The maximum width permitted
320 * format [in] The format flags in effect
321 * chars_fit [in] The maximum number of characters of str that are already
322 * known to fit; chars_fit+1 is known not to fit.
323 * chars_used [out] The number of characters of str that have been "used" and
324 * do not need to be included in later text. For example this will
325 * include any spaces that have been discarded from the start of
326 * the next line.
327 * size [out] The size of the returned text in logical coordinates
329 * Pedantic assumption - Assumes that the text length is monotonically
330 * increasing with number of characters (i.e. no weird kernings)
332 * Algorithm
334 * Work back from the last character that did fit to either a space or the last
335 * character of a word, whichever is met first.
336 * If there was one or the first character didn't fit then
337 * If the text is centered or right justified and that one character was a
338 * space then break the line before that character
339 * Otherwise break the line after that character
340 * and if the next character is a space then discard it.
341 * Suppose there was none (and the first character did fit).
342 * If Break Within Word is permitted
343 * break the word after the last character that fits (there must be
344 * at least one; none is caught earlier).
345 * Otherwise
346 * discard any trailing space.
347 * include the whole word; it may be ellipsified later
349 * Break Within Word is permitted under a set of circumstances that are not
350 * totally clear yet. Currently our best guess is:
351 * If DT_EDITCONTROL is in effect and neither DT_WORD_ELLIPSIS nor
352 * DT_PATH_ELLIPSIS is
355 static void TEXT_WordBreak (HDC hdc, WCHAR *str, unsigned int max_str,
356 unsigned int *len_str,
357 int width, int format, unsigned int chars_fit,
358 unsigned int *chars_used, SIZE *size)
360 WCHAR *p;
361 BOOL word_fits;
362 SCRIPT_LOGATTR *sla;
363 SCRIPT_ANALYSIS sa;
364 int i;
366 assert (format & DT_WORDBREAK);
367 assert (chars_fit < *len_str);
369 sla = heap_alloc(sizeof(SCRIPT_LOGATTR) * *len_str);
371 memset(&sa, 0, sizeof(SCRIPT_ANALYSIS));
372 sa.eScript = SCRIPT_UNDEFINED;
374 ScriptBreak(str, *len_str, &sa, sla);
376 /* Work back from the last character that did fit to either a space or the
377 * last character of a word, whichever is met first.
379 p = str + chars_fit; /* The character that doesn't fit */
380 i = chars_fit;
381 word_fits = TRUE;
382 if (!chars_fit)
383 word_fits = FALSE;
384 else if (sla[i].fSoftBreak) /* chars_fit < *len_str so this is valid */
386 /* the word just fitted */
387 p--;
389 else
391 while (i > 0 && !sla[(--i)+1].fSoftBreak) p--;
392 p--;
393 word_fits = (i != 0 || sla[i+1].fSoftBreak );
396 /* If there was one. */
397 if (word_fits)
399 BOOL next_is_space;
400 /* break the line before/after that character */
401 if (!(format & (DT_RIGHT | DT_CENTER)) || *p != SPACE)
402 p++;
403 next_is_space = (p - str) < *len_str && *p == SPACE;
404 *len_str = p - str;
405 /* and if the next character is a space then discard it. */
406 *chars_used = *len_str;
407 if (next_is_space)
408 (*chars_used)++;
410 /* Suppose there was none. */
411 else
413 if ((format & (DT_EDITCONTROL | DT_WORD_ELLIPSIS | DT_PATH_ELLIPSIS)) ==
414 DT_EDITCONTROL)
416 /* break the word after the last character that fits (there must be
417 * at least one). */
418 if (!chars_fit)
419 ++chars_fit;
420 *len_str = chars_fit;
421 *chars_used = chars_fit;
423 /* FIXME - possible error. Since the next character is now removed
424 * this could make the text longer so that it no longer fits, and
425 * so we need a loop to test and shrink.
428 /* Otherwise */
429 else
431 /* discard any trailing space. */
432 const WCHAR *e = str + *len_str;
433 p = str + chars_fit;
434 while (p < e && *p != SPACE)
435 p++;
436 *chars_used = p - str;
437 if (p < e) /* i.e. loop failed because *p == SPACE */
438 (*chars_used)++;
440 /* include the whole word; it may be ellipsified later */
441 *len_str = p - str;
442 /* Possible optimisation; if DT_WORD_ELLIPSIS only use chars_fit+1
443 * so that it will be too long
447 /* Remeasure the string */
448 GetTextExtentExPointW (hdc, str, *len_str, 0, NULL, NULL, size);
449 heap_free(sla);
452 /*********************************************************************
453 * TEXT_SkipChars
455 * Skip over the given number of characters, bearing in mind prefix
456 * substitution and the fact that a character may take more than one
457 * WCHAR (Unicode surrogates are two words long) (and there may have been
458 * a trailing &)
460 * Parameters
461 * new_count [out] The updated count
462 * new_str [out] The updated pointer
463 * start_count [in] The count of remaining characters corresponding to the
464 * start of the string
465 * start_str [in] The starting point of the string
466 * max [in] The number of characters actually in this segment of the
467 * string (the & counts)
468 * n [in] The number of characters to skip (if prefix then
469 * &c counts as one)
470 * prefix [in] Apply prefix substitution
472 * Return Values
473 * none
475 * Remarks
476 * There must be at least n characters in the string
477 * We need max because the "line" may have ended with a & followed by a tab
478 * or newline etc. which we don't want to swallow
481 static void TEXT_SkipChars (int *new_count, const WCHAR **new_str,
482 int start_count, const WCHAR *start_str,
483 int max, int n, int prefix)
485 /* This is specific to wide characters, MSDN doesn't say anything much
486 * about Unicode surrogates yet and it isn't clear if _wcsinc will
487 * correctly handle them so we'll just do this the easy way for now
490 if (prefix)
492 const WCHAR *str_on_entry = start_str;
493 assert (max >= n);
494 max -= n;
495 while (n--)
497 if ((*start_str == PREFIX || *start_str == ALPHA_PREFIX) && max--)
498 start_str++;
499 start_str++;
501 start_count -= (start_str - str_on_entry);
503 else
505 start_str += n;
506 start_count -= n;
508 *new_str = start_str;
509 *new_count = start_count;
512 /*********************************************************************
513 * TEXT_Reprefix
515 * Reanalyse the text to find the prefixed character. This is called when
516 * wordbreaking or ellipsification has shortened the string such that the
517 * previously noted prefixed character is no longer visible.
519 * Parameters
520 * str [in] The original string segment (including all characters)
521 * ns [in] The number of characters in str (including prefixes)
522 * pe [in] The ellipsification data
524 * Return Values
525 * The prefix offset within the new string segment (the one that contains the
526 * ellipses and does not contain the prefix characters) (-1 if none)
529 static int TEXT_Reprefix (const WCHAR *str, unsigned int ns,
530 const ellipsis_data *pe)
532 int result = -1;
533 unsigned int i;
534 unsigned int n = pe->before + pe->under + pe->after;
535 assert (n <= ns);
536 for (i = 0; i < n; i++, str++)
538 if (i == pe->before)
540 /* Reached the path ellipsis; jump over it */
541 if (ns < pe->under) break;
542 str += pe->under;
543 ns -= pe->under;
544 i += pe->under;
545 if (!pe->after) break; /* Nothing after the path ellipsis */
547 if (!ns) break;
548 ns--;
549 if (*str == PREFIX || *str == ALPHA_PREFIX)
551 str++;
552 if (!ns) break;
553 if (*str != PREFIX)
554 result = (i < pe->before || pe->under == 0) ? i : i - pe->under + pe->len;
555 /* pe->len may be non-zero while pe_under is zero */
556 ns--;
559 return result;
562 /*********************************************************************
563 * Returns true if and only if the remainder of the line is a single
564 * newline representation or nothing
567 static BOOL remainder_is_none_or_newline (int num_chars, const WCHAR *str)
569 if (!num_chars) return TRUE;
570 if (*str != LF && *str != CR) return FALSE;
571 if (!--num_chars) return TRUE;
572 if (*str == *(str+1)) return FALSE;
573 str++;
574 if (*str != CR && *str != LF) return FALSE;
575 if (--num_chars) return FALSE;
576 return TRUE;
579 /*********************************************************************
580 * Return next line of text from a string.
582 * hdc - handle to DC.
583 * str - string to parse into lines.
584 * count - length of str.
585 * dest - destination in which to return line.
586 * len - dest buffer size in chars on input, copied length into dest on output.
587 * width - maximum width of line in pixels.
588 * format - format type passed to DrawText.
589 * retsize - returned size of the line in pixels.
590 * last_line - TRUE if is the last line that will be processed
591 * p_retstr - If DT_MODIFYSTRING this points to a cursor in the buffer in which
592 * the return string is built.
593 * tabwidth - The width of a tab in logical coordinates
594 * pprefix_offset - Here is where we return the offset within dest of the first
595 * prefixed (underlined) character. -1 is returned if there
596 * are none. Note that there may be more; the calling code
597 * will need to use TEXT_Reprefix to find any later ones.
598 * pellip - Here is where we return the information about any ellipsification
599 * that was carried out. Note that if tabs are being expanded then
600 * this data will correspond to the last text segment actually
601 * returned in dest; by definition there would not have been any
602 * ellipsification in earlier text segments of the line.
604 * Returns pointer to next char in str after end of the line
605 * or NULL if end of str reached.
607 static const WCHAR *TEXT_NextLineW( HDC hdc, const WCHAR *str, int *count,
608 WCHAR *dest, int *len, int width, DWORD format,
609 SIZE *retsize, int last_line, WCHAR *modstr,
610 int tabwidth, int *pprefix_offset,
611 ellipsis_data *pellip)
613 int i = 0, j = 0;
614 int plen = 0;
615 SIZE size;
616 int maxl = *len;
617 int seg_i, seg_count, seg_j;
618 int max_seg_width;
619 int num_fit;
620 BOOL word_broken, line_fits, ellipsified;
621 unsigned int j_in_seg;
622 *pprefix_offset = -1;
624 /* For each text segment in the line */
626 retsize->cy = 0;
627 while (*count)
630 /* Skip any leading tabs */
632 if (str[i] == TAB && (format & DT_EXPANDTABS))
634 plen = ((plen/tabwidth)+1)*tabwidth;
635 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
636 while (*count && str[i] == TAB)
638 plen += tabwidth;
639 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
644 /* Now copy as far as the next tab or cr/lf or eos */
646 seg_i = i;
647 seg_count = *count;
648 seg_j = j;
650 while (*count &&
651 (str[i] != TAB || !(format & DT_EXPANDTABS)) &&
652 ((str[i] != CR && str[i] != LF) || (format & DT_SINGLELINE)))
654 if ((format & DT_NOPREFIX) || *count <= 1)
656 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
657 continue;
660 if (str[i] == PREFIX || str[i] == ALPHA_PREFIX) {
661 (*count)--, i++; /* Throw away the prefix itself */
662 if (str[i] == PREFIX)
664 /* Swallow it before we see it again */
665 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
667 else if (*pprefix_offset == -1 || *pprefix_offset >= seg_j)
669 *pprefix_offset = j;
671 /* else the previous prefix was in an earlier segment of the
672 * line; we will leave it to the drawing code to catch this
673 * one.
676 else if (str[i] == KANA_PREFIX)
678 /* Throw away katakana access keys */
679 (*count)--, i++; /* skip the prefix */
680 (*count)--; i++; /* skip the letter */
682 else
684 (*count)--; if (j < maxl) dest[j++] = str[i++]; else i++;
689 /* Measure the whole text segment and possibly WordBreak and
690 * ellipsify it
693 j_in_seg = j - seg_j;
694 max_seg_width = width - plen;
695 GetTextExtentExPointW (hdc, dest + seg_j, j_in_seg, max_seg_width, &num_fit, NULL, &size);
697 /* The Microsoft handling of various combinations of formats is weird.
698 * The following may very easily be incorrect if several formats are
699 * combined, and may differ between versions (to say nothing of the
700 * several bugs in the Microsoft versions).
702 word_broken = FALSE;
703 line_fits = (num_fit >= j_in_seg);
704 if (!line_fits && (format & DT_WORDBREAK))
706 const WCHAR *s;
707 unsigned int chars_used;
708 TEXT_WordBreak (hdc, dest+seg_j, maxl-seg_j, &j_in_seg,
709 max_seg_width, format, num_fit, &chars_used, &size);
710 line_fits = (size.cx <= max_seg_width);
711 /* and correct the counts */
712 TEXT_SkipChars (count, &s, seg_count, str+seg_i, i-seg_i,
713 chars_used, !(format & DT_NOPREFIX));
714 i = s - str;
715 word_broken = TRUE;
717 pellip->before = j_in_seg;
718 pellip->under = 0;
719 pellip->after = 0;
720 pellip->len = 0;
721 ellipsified = FALSE;
722 if (!line_fits && (format & DT_PATH_ELLIPSIS))
724 TEXT_PathEllipsify (hdc, dest + seg_j, maxl-seg_j, &j_in_seg,
725 max_seg_width, &size, modstr, pellip);
726 line_fits = (size.cx <= max_seg_width);
727 ellipsified = TRUE;
729 /* NB we may end up ellipsifying a word-broken or path_ellipsified
730 * string */
731 if ((!line_fits && (format & DT_WORD_ELLIPSIS)) ||
732 ((format & DT_END_ELLIPSIS) &&
733 ((last_line && *count) ||
734 (remainder_is_none_or_newline (*count, &str[i]) && !line_fits))))
736 int before, len_ellipsis;
737 TEXT_Ellipsify (hdc, dest + seg_j, maxl-seg_j, &j_in_seg,
738 max_seg_width, &size, modstr, &before, &len_ellipsis);
739 if (before > pellip->before)
741 /* We must have done a path ellipsis too */
742 pellip->after = before - pellip->before - pellip->len;
743 /* Leave the len as the length of the first ellipsis */
745 else
747 /* If we are here after a path ellipsification it must be
748 * because even the ellipsis itself didn't fit.
750 assert (pellip->under == 0 && pellip->after == 0);
751 pellip->before = before;
752 pellip->len = len_ellipsis;
753 /* pellip->after remains as zero as does
754 * pellip->under
757 ellipsified = 1;
759 /* As an optimisation if we have ellipsified and we are expanding
760 * tabs and we haven't reached the end of the line we can skip to it
761 * now rather than going around the loop again.
763 if ((format & DT_EXPANDTABS) && ellipsified)
765 if (format & DT_SINGLELINE)
766 *count = 0;
767 else
769 while ((*count) && str[i] != CR && str[i] != LF)
771 (*count)--, i++;
776 j = seg_j + j_in_seg;
777 if (*pprefix_offset >= seg_j + pellip->before)
779 *pprefix_offset = TEXT_Reprefix (str + seg_i, i - seg_i, pellip);
780 if (*pprefix_offset != -1)
781 *pprefix_offset += seg_j;
784 plen += size.cx;
785 if (size.cy > retsize->cy)
786 retsize->cy = size.cy;
788 if (word_broken)
789 break;
790 else if (!*count)
791 break;
792 else if (str[i] == CR || str[i] == LF)
794 (*count)--, i++;
795 if (*count && (str[i] == CR || str[i] == LF) && str[i] != str[i-1])
797 (*count)--, i++;
799 break;
801 /* else it was a Tab and we go around again */
804 retsize->cx = plen;
805 *len = j;
806 if (*count)
807 return (&str[i]);
808 else
809 return NULL;
813 /***********************************************************************
814 * TEXT_DrawUnderscore
816 * Draw the underline under the prefixed character
818 * Parameters
819 * hdc [in] The handle of the DC for drawing
820 * x [in] The x location of the line segment (logical coordinates)
821 * y [in] The y location of where the underscore should appear
822 * (logical coordinates)
823 * str [in] The text of the line segment
824 * offset [in] The offset of the underscored character within str
825 * rect [in] Clipping rectangle (if not NULL)
828 static void TEXT_DrawUnderscore (HDC hdc, int x, int y, const WCHAR *str, int offset, const RECT *rect)
830 int prefix_x;
831 int prefix_end;
832 SIZE size;
833 HPEN hpen;
834 HPEN oldPen;
836 GetTextExtentPointW (hdc, str, offset, &size);
837 prefix_x = x + size.cx;
838 GetTextExtentPointW (hdc, str, offset+1, &size);
839 prefix_end = x + size.cx - 1;
840 /* The above method may eventually be slightly wrong due to kerning etc. */
842 /* Check for clipping */
843 if (rect){
844 if (prefix_x > rect->right || prefix_end < rect->left || y < rect->top || y > rect->bottom)
845 return; /* Completely outside */
846 /* Partially outside */
847 if (prefix_x < rect->left ) prefix_x = rect->left;
848 if (prefix_end > rect->right) prefix_end = rect->right;
851 hpen = CreatePen (PS_SOLID, 1, GetTextColor (hdc));
852 oldPen = SelectObject (hdc, hpen);
853 MoveToEx (hdc, prefix_x, y, NULL);
854 LineTo (hdc, prefix_end, y);
855 SelectObject (hdc, oldPen);
856 DeleteObject (hpen);
859 /***********************************************************************
860 * DrawTextExW (USER32.@)
862 * The documentation on the extra space required for DT_MODIFYSTRING at MSDN
863 * is not quite complete, especially with regard to \0. We will assume that
864 * the returned string could have a length of up to i_count+3 and also have
865 * a trailing \0 (which would be 4 more than a not-null-terminated string but
866 * 3 more than a null-terminated string). If this is not so then increase
867 * the allowance in DrawTextExA.
869 #define MAX_BUFFER 1024
870 INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count,
871 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
873 SIZE size;
874 const WCHAR *strPtr;
875 WCHAR *retstr;
876 size_t size_retstr;
877 WCHAR line[MAX_BUFFER];
878 int len, lh, count=i_count;
879 TEXTMETRICW tm;
880 int lmargin = 0, rmargin = 0;
881 int x = rect->left, y = rect->top;
882 int width = rect->right - rect->left;
883 int max_width = 0;
884 int last_line;
885 int tabwidth /* to keep gcc happy */ = 0;
886 int prefix_offset;
887 ellipsis_data ellip;
888 BOOL invert_y=FALSE;
889 int ret = 0;
891 TRACE("%s, %d, [%s] %08x\n", debugstr_wn (str, count), count,
892 wine_dbgstr_rect(rect), flags);
894 if (dtp) TRACE("Params: iTabLength=%d, iLeftMargin=%d, iRightMargin=%d\n",
895 dtp->iTabLength, dtp->iLeftMargin, dtp->iRightMargin);
897 if (!str) return 0;
899 strPtr = str;
901 if (flags & DT_SINGLELINE)
902 flags &= ~DT_WORDBREAK;
904 GetTextMetricsW(hdc, &tm);
905 if (flags & DT_EXTERNALLEADING)
906 lh = tm.tmHeight + tm.tmExternalLeading;
907 else
908 lh = tm.tmHeight;
910 if (str[0] && count == 0)
911 return lh;
913 if (dtp && dtp->cbSize != sizeof(DRAWTEXTPARAMS))
914 return 0;
916 if (count == -1)
918 count = strlenW(str);
919 if (count == 0)
921 if( flags & DT_CALCRECT)
923 rect->right = rect->left;
924 if( flags & DT_SINGLELINE)
925 rect->bottom = rect->top + lh;
926 else
927 rect->bottom = rect->top;
929 return lh;
933 if (GetGraphicsMode(hdc) == GM_COMPATIBLE)
935 SIZE window_ext, viewport_ext;
936 GetWindowExtEx(hdc, &window_ext);
937 GetViewportExtEx(hdc, &viewport_ext);
938 if ((window_ext.cy > 0) != (viewport_ext.cy > 0))
939 invert_y = TRUE;
942 if (dtp)
944 lmargin = dtp->iLeftMargin;
945 rmargin = dtp->iRightMargin;
946 width -= lmargin + rmargin;
947 if (!(flags & (DT_CENTER | DT_RIGHT)))
948 x += lmargin;
949 dtp->uiLengthDrawn = 0; /* This param RECEIVES number of chars processed */
952 if (flags & DT_EXPANDTABS)
954 int tabstop = ((flags & DT_TABSTOP) && dtp && dtp->iTabLength) ? dtp->iTabLength : 8;
955 tabwidth = tm.tmAveCharWidth * tabstop;
958 if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
960 if (flags & DT_MODIFYSTRING)
962 size_retstr = (count + 4) * sizeof (WCHAR);
963 retstr = heap_alloc(size_retstr);
964 if (!retstr) return 0;
965 memcpy (retstr, str, size_retstr);
967 else
969 size_retstr = 0;
970 retstr = NULL;
975 len = ARRAY_SIZE(line);
976 if (invert_y)
977 last_line = !(flags & DT_NOCLIP) && y - ((flags & DT_EDITCONTROL) ? 2*lh-1 : lh) < rect->bottom;
978 else
979 last_line = !(flags & DT_NOCLIP) && y + ((flags & DT_EDITCONTROL) ? 2*lh-1 : lh) > rect->bottom;
980 strPtr = TEXT_NextLineW(hdc, strPtr, &count, line, &len, width, flags, &size, last_line, retstr, tabwidth, &prefix_offset, &ellip);
982 if (flags & DT_CENTER)
983 x = (rect->left + lmargin + rect->right - rmargin - size.cx) / 2;
984 else if (flags & DT_RIGHT)
985 x = rect->right - size.cx - rmargin;
987 if (flags & DT_SINGLELINE)
989 if (flags & DT_VCENTER) y = rect->top +
990 (rect->bottom - rect->top) / 2 - size.cy / 2;
991 else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
994 if (!(flags & DT_CALCRECT))
996 const WCHAR *str = line;
997 int xseg = x;
998 while (len)
1000 int len_seg;
1001 SIZE size;
1002 if ((flags & DT_EXPANDTABS))
1004 const WCHAR *p;
1005 p = str; while (p < str+len && *p != TAB) p++;
1006 len_seg = p - str;
1007 if (len_seg != len && !GetTextExtentPointW(hdc, str, len_seg, &size)) goto done;
1009 else
1010 len_seg = len;
1012 if (!ExtTextOutW( hdc, xseg, y,
1013 ((flags & DT_NOCLIP) ? 0 : ETO_CLIPPED) |
1014 ((flags & DT_RTLREADING) ? ETO_RTLREADING : 0),
1015 rect, str, len_seg, NULL ))
1016 goto done;
1017 if (prefix_offset != -1 && prefix_offset < len_seg)
1019 TEXT_DrawUnderscore (hdc, xseg, y + tm.tmAscent + 1, str, prefix_offset, (flags & DT_NOCLIP) ? NULL : rect);
1021 len -= len_seg;
1022 str += len_seg;
1023 if (len)
1025 assert ((flags & DT_EXPANDTABS) && *str == TAB);
1026 len--; str++;
1027 xseg += ((size.cx/tabwidth)+1)*tabwidth;
1028 if (prefix_offset != -1)
1030 if (prefix_offset < len_seg)
1032 /* We have just drawn an underscore; we ought to
1033 * figure out where the next one is. I am going
1034 * to leave it for now until I have a better model
1035 * for the line, which will make reprefixing easier.
1036 * This is where ellip would be used.
1038 prefix_offset = -1;
1040 else
1041 prefix_offset -= len_seg;
1046 else if (size.cx > max_width)
1047 max_width = size.cx;
1049 if (invert_y)
1050 y -= lh;
1051 else
1052 y += lh;
1053 if (dtp)
1054 dtp->uiLengthDrawn += len;
1056 while (strPtr && !last_line);
1058 if (flags & DT_CALCRECT)
1060 rect->right = rect->left + max_width;
1061 rect->bottom = y;
1062 if (dtp)
1063 rect->right += lmargin + rmargin;
1066 if (retstr) memcpy(str, retstr, size_retstr);
1068 ret = y - rect->top;
1069 if (ret == 0) ret = 1;
1070 done:
1071 heap_free(retstr);
1072 return ret;
1075 /***********************************************************************
1076 * DrawTextExA (USER32.@)
1078 * If DT_MODIFYSTRING is specified then there must be room for up to
1079 * 4 extra characters. We take great care about just how much modified
1080 * string we return.
1082 INT WINAPI DrawTextExA( HDC hdc, LPSTR str, INT count,
1083 LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
1085 WCHAR *wstr;
1086 WCHAR *p;
1087 INT ret = 0;
1088 int i;
1089 DWORD wcount;
1090 DWORD wmax;
1091 DWORD amax;
1092 UINT cp;
1094 if (!count) return 0;
1095 if (!str && count > 0) return 0;
1096 if( !str || ((count == -1) && !(count = strlen(str))))
1098 int lh;
1099 TEXTMETRICA tm;
1101 if (dtp && dtp->cbSize != sizeof(DRAWTEXTPARAMS))
1102 return 0;
1104 GetTextMetricsA(hdc, &tm);
1105 if (flags & DT_EXTERNALLEADING)
1106 lh = tm.tmHeight + tm.tmExternalLeading;
1107 else
1108 lh = tm.tmHeight;
1110 if( flags & DT_CALCRECT)
1112 rect->right = rect->left;
1113 if( flags & DT_SINGLELINE)
1114 rect->bottom = rect->top + lh;
1115 else
1116 rect->bottom = rect->top;
1118 return lh;
1120 cp = GdiGetCodePage( hdc );
1121 wcount = MultiByteToWideChar( cp, 0, str, count, NULL, 0 );
1122 wmax = wcount;
1123 amax = count;
1124 if (flags & DT_MODIFYSTRING)
1126 wmax += 4;
1127 amax += 4;
1129 wstr = heap_alloc(wmax * sizeof(WCHAR));
1130 if (wstr)
1132 MultiByteToWideChar( cp, 0, str, count, wstr, wcount );
1133 if (flags & DT_MODIFYSTRING)
1134 for (i=4, p=wstr+wcount; i--; p++) *p=0xFFFE;
1135 /* Initialise the extra characters so that we can see which ones
1136 * change. U+FFFE is guaranteed to be not a unicode character and
1137 * so will not be generated by DrawTextEx itself.
1139 ret = DrawTextExW( hdc, wstr, wcount, rect, flags, dtp );
1140 if (flags & DT_MODIFYSTRING)
1142 /* Unfortunately the returned string may contain multiple \0s
1143 * and so we need to measure it ourselves.
1145 for (i=4, p=wstr+wcount; i-- && *p != 0xFFFE; p++) wcount++;
1146 WideCharToMultiByte( cp, 0, wstr, wcount, str, amax, NULL, NULL );
1148 heap_free(wstr);
1150 return ret;
1153 /***********************************************************************
1154 * DrawTextW (USER32.@)
1156 INT WINAPI DrawTextW( HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags )
1158 DRAWTEXTPARAMS dtp;
1160 memset (&dtp, 0, sizeof(dtp));
1161 dtp.cbSize = sizeof(dtp);
1162 if (flags & DT_TABSTOP)
1164 dtp.iTabLength = (flags >> 8) & 0xff;
1165 flags &= 0xffff00ff;
1167 return DrawTextExW(hdc, (LPWSTR)str, count, rect, flags, &dtp);
1170 /***********************************************************************
1171 * DrawTextA (USER32.@)
1173 INT WINAPI DrawTextA( HDC hdc, LPCSTR str, INT count, LPRECT rect, UINT flags )
1175 DRAWTEXTPARAMS dtp;
1177 memset (&dtp, 0, sizeof(dtp));
1178 dtp.cbSize = sizeof(dtp);
1179 if (flags & DT_TABSTOP)
1181 dtp.iTabLength = (flags >> 8) & 0xff;
1182 flags &= 0xffff00ff;
1184 return DrawTextExA( hdc, (LPSTR)str, count, rect, flags, &dtp );
1187 /***********************************************************************
1189 * GrayString functions
1192 /* callback for ASCII gray string proc */
1193 static BOOL CALLBACK gray_string_callbackA( HDC hdc, LPARAM param, INT len )
1195 return TextOutA( hdc, 0, 0, (LPCSTR)param, len );
1198 /* callback for Unicode gray string proc */
1199 static BOOL CALLBACK gray_string_callbackW( HDC hdc, LPARAM param, INT len )
1201 return TextOutW( hdc, 0, 0, (LPCWSTR)param, len );
1204 /***********************************************************************
1205 * TEXT_GrayString
1207 static BOOL TEXT_GrayString(HDC hdc, HBRUSH hb, GRAYSTRINGPROC fn, LPARAM lp, INT len,
1208 INT x, INT y, INT cx, INT cy )
1210 HBITMAP hbm, hbmsave;
1211 HBRUSH hbsave;
1212 HFONT hfsave;
1213 HDC memdc;
1214 int slen = len;
1215 BOOL retval;
1216 COLORREF fg, bg;
1218 if(!hdc) return FALSE;
1219 if (!(memdc = CreateCompatibleDC(hdc))) return FALSE;
1221 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1222 hbmsave = SelectObject(memdc, hbm);
1223 hbsave = SelectObject( memdc, GetStockObject(BLACK_BRUSH) );
1224 PatBlt( memdc, 0, 0, cx, cy, PATCOPY );
1225 SelectObject( memdc, hbsave );
1226 SetTextColor(memdc, RGB(255, 255, 255));
1227 SetBkColor(memdc, RGB(0, 0, 0));
1228 hfsave = SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1230 retval = fn(memdc, lp, slen);
1231 SelectObject(memdc, hfsave);
1234 * Windows doc says that the bitmap isn't grayed when len == -1 and
1235 * the callback function returns FALSE. However, testing this on
1236 * win95 showed otherwise...
1238 #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR
1239 if(retval || len != -1)
1240 #endif
1242 hbsave = SelectObject(memdc, SYSCOLOR_Get55AABrush());
1243 PatBlt(memdc, 0, 0, cx, cy, 0x000A0329);
1244 SelectObject(memdc, hbsave);
1247 if(hb) hbsave = SelectObject(hdc, hb);
1248 fg = SetTextColor(hdc, RGB(0, 0, 0));
1249 bg = SetBkColor(hdc, RGB(255, 255, 255));
1250 BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746);
1251 SetTextColor(hdc, fg);
1252 SetBkColor(hdc, bg);
1253 if(hb) SelectObject(hdc, hbsave);
1255 SelectObject(memdc, hbmsave);
1256 DeleteObject(hbm);
1257 DeleteDC(memdc);
1258 return retval;
1262 /***********************************************************************
1263 * GrayStringA (USER32.@)
1265 BOOL WINAPI GrayStringA( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
1266 LPARAM lParam, INT cch, INT x, INT y,
1267 INT cx, INT cy )
1269 if (!cch) cch = strlen( (LPCSTR)lParam );
1270 if ((cx == 0 || cy == 0) && cch != -1)
1272 SIZE s;
1273 GetTextExtentPoint32A( hdc, (LPCSTR)lParam, cch, &s );
1274 if (cx == 0) cx = s.cx;
1275 if (cy == 0) cy = s.cy;
1277 if (!gsprc) gsprc = gray_string_callbackA;
1278 return TEXT_GrayString( hdc, hbr, gsprc, lParam, cch, x, y, cx, cy );
1282 /***********************************************************************
1283 * GrayStringW (USER32.@)
1285 BOOL WINAPI GrayStringW( HDC hdc, HBRUSH hbr, GRAYSTRINGPROC gsprc,
1286 LPARAM lParam, INT cch, INT x, INT y,
1287 INT cx, INT cy )
1289 if (!cch) cch = strlenW( (LPCWSTR)lParam );
1290 if ((cx == 0 || cy == 0) && cch != -1)
1292 SIZE s;
1293 GetTextExtentPoint32W( hdc, (LPCWSTR)lParam, cch, &s );
1294 if (cx == 0) cx = s.cx;
1295 if (cy == 0) cy = s.cy;
1297 if (!gsprc) gsprc = gray_string_callbackW;
1298 return TEXT_GrayString( hdc, hbr, gsprc, lParam, cch, x, y, cx, cy );
1302 /***********************************************************************
1303 * TEXT_TabbedTextOut
1305 * Helper function for TabbedTextOut() and GetTabbedTextExtent().
1306 * Note: this doesn't work too well for text-alignment modes other
1307 * than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
1309 static LONG TEXT_TabbedTextOut( HDC hdc, INT x, INT y, LPCWSTR lpstr,
1310 INT count, INT cTabStops, const INT *lpTabPos, INT nTabOrg,
1311 BOOL fDisplayText )
1313 INT defWidth;
1314 SIZE extent;
1315 int i, j;
1316 int start = x;
1317 TEXTMETRICW tm;
1319 if (!lpstr || count == 0) return 0;
1321 if (!lpTabPos)
1322 cTabStops=0;
1324 GetTextMetricsW( hdc, &tm );
1326 if (cTabStops == 1)
1328 defWidth = *lpTabPos;
1329 cTabStops = 0;
1331 else
1333 defWidth = 8 * tm.tmAveCharWidth;
1336 while (count > 0)
1338 RECT r;
1339 INT x0;
1340 x0 = x;
1341 r.left = x0;
1342 /* chop the string into substrings of 0 or more <tabs>
1343 * possibly followed by 1 or more normal characters */
1344 for (i = 0; i < count; i++)
1345 if (lpstr[i] != '\t') break;
1346 for (j = i; j < count; j++)
1347 if (lpstr[j] == '\t') break;
1348 /* get the extent of the normal character part */
1349 GetTextExtentPointW( hdc, lpstr + i, j - i , &extent );
1350 /* and if there is a <tab>, calculate its position */
1351 if( i) {
1352 /* get x coordinate for the drawing of this string */
1353 for (; cTabStops >= i; lpTabPos++, cTabStops--)
1355 if( nTabOrg + abs( *lpTabPos) > x) {
1356 if( lpTabPos[ i - 1] >= 0) {
1357 /* a left aligned tab */
1358 x0 = nTabOrg + lpTabPos[i-1];
1359 x = x0 + extent.cx;
1360 break;
1362 else
1364 /* if tab pos is negative then text is right-aligned
1365 * to tab stop meaning that the string extends to the
1366 * left, so we must subtract the width of the string */
1367 if (nTabOrg - lpTabPos[ i - 1] - extent.cx > x)
1369 x = nTabOrg - lpTabPos[ i - 1];
1370 x0 = x - extent.cx;
1371 break;
1376 /* if we have run out of tab stops and we have a valid default tab
1377 * stop width then round x up to that width */
1378 if ((cTabStops < i) && (defWidth > 0)) {
1379 x0 = nTabOrg + ((x - nTabOrg) / defWidth + i) * defWidth;
1380 x = x0 + extent.cx;
1381 } else if ((cTabStops < i) && (defWidth < 0)) {
1382 x = nTabOrg + ((x - nTabOrg + extent.cx) / -defWidth + i)
1383 * -defWidth;
1384 x0 = x - extent.cx;
1386 } else
1387 x += extent.cx;
1389 if (!extent.cy) extent.cy = tm.tmHeight;
1391 if (fDisplayText)
1393 r.top = y;
1394 r.right = x;
1395 r.bottom = y + extent.cy;
1396 ExtTextOutW( hdc, x0, y, GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
1397 &r, lpstr + i, j - i, NULL );
1399 count -= j;
1400 lpstr += j;
1403 return MAKELONG(x - start, extent.cy);
1407 /***********************************************************************
1408 * TabbedTextOutA (USER32.@)
1410 * See TabbedTextOutW.
1412 LONG WINAPI TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr, INT count,
1413 INT cTabStops, const INT *lpTabPos, INT nTabOrg )
1415 LONG ret;
1416 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpstr, count, NULL, 0 );
1417 LPWSTR strW = heap_alloc( len * sizeof(WCHAR) );
1418 if (!strW) return 0;
1419 MultiByteToWideChar( CP_ACP, 0, lpstr, count, strW, len );
1420 ret = TabbedTextOutW( hdc, x, y, strW, len, cTabStops, lpTabPos, nTabOrg );
1421 heap_free( strW );
1422 return ret;
1426 /***********************************************************************
1427 * TabbedTextOutW (USER32.@)
1429 * Draws tabbed text aligned using the specified tab stops.
1431 * PARAMS
1432 * hdc [I] Handle to device context to draw to.
1433 * x [I] X co-ordinate to start drawing the text at in logical units.
1434 * y [I] Y co-ordinate to start drawing the text at in logical units.
1435 * str [I] Pointer to the characters to draw.
1436 * count [I] Number of WCHARs pointed to by str.
1437 * cTabStops [I] Number of tab stops pointed to by lpTabPos.
1438 * lpTabPos [I] Tab stops in logical units. Should be sorted in ascending order.
1439 * nTabOrg [I] Starting position to expand tabs from in logical units.
1441 * RETURNS
1442 * The dimensions of the string drawn. The height is in the high-order word
1443 * and the width is in the low-order word.
1445 * NOTES
1446 * The tabs stops can be negative, in which case the text is right aligned to
1447 * that tab stop and, despite what MSDN says, this is supported on
1448 * Windows XP SP2.
1450 * BUGS
1451 * MSDN says that the TA_UPDATECP from GetTextAlign causes this function to
1452 * ignore the x and y co-ordinates, but this is unimplemented at the moment.
1454 LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str, INT count,
1455 INT cTabStops, const INT *lpTabPos, INT nTabOrg )
1457 TRACE("%p %d,%d %s %d\n", hdc, x, y, debugstr_wn(str,count), count );
1458 return TEXT_TabbedTextOut( hdc, x, y, str, count, cTabStops, lpTabPos, nTabOrg, TRUE );
1462 /***********************************************************************
1463 * GetTabbedTextExtentA (USER32.@)
1465 DWORD WINAPI GetTabbedTextExtentA( HDC hdc, LPCSTR lpstr, INT count,
1466 INT cTabStops, const INT *lpTabPos )
1468 LONG ret;
1469 DWORD len = MultiByteToWideChar( CP_ACP, 0, lpstr, count, NULL, 0 );
1470 LPWSTR strW = heap_alloc( len * sizeof(WCHAR) );
1471 if (!strW) return 0;
1472 MultiByteToWideChar( CP_ACP, 0, lpstr, count, strW, len );
1473 ret = GetTabbedTextExtentW( hdc, strW, len, cTabStops, lpTabPos );
1474 heap_free( strW );
1475 return ret;
1479 /***********************************************************************
1480 * GetTabbedTextExtentW (USER32.@)
1482 DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count,
1483 INT cTabStops, const INT *lpTabPos )
1485 TRACE("%p %s %d\n", hdc, debugstr_wn(lpstr,count), count );
1486 return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops, lpTabPos, 0, FALSE );