Release 961023
[wine] / objects / text.c
1 /*
2  * text functions
3  *
4  * Copyright 1993, 1994 Alexandre Julliard
5  *
6  */
7
8 #include <stdlib.h>
9 #include <X11/Xatom.h>
10 #include "windows.h"
11 #include "dc.h"
12 #include "gdi.h"
13 #include "callback.h"
14 #include "metafile.h"
15 #include "string32.h"
16 #include "stddebug.h"
17 /* #define DEBUG_TEXT */
18 #include "debug.h"
19 #include "xmalloc.h"
20
21 #define TAB     9
22 #define LF     10
23 #define CR     13
24 #define SPACE  32
25 #define PREFIX 38
26
27 #define SWAP_INT(a,b)  { int t = a; a = b; b = t; }
28
29 static int tabstop = 8;
30 static int tabwidth;
31 static int spacewidth;
32 static int prefix_offset;
33
34 extern int CLIPPING_IntersectClipRect( DC * dc, short left, short top,
35                                          short right, short bottom, UINT16 flags);
36
37 static const char *TEXT_NextLine( HDC16 hdc, const char *str, int *count,
38                                   char *dest, int *len, int width, WORD format)
39 {
40     /* Return next line of text from a string.
41      * 
42      * hdc - handle to DC.
43      * str - string to parse into lines.
44      * count - length of str.
45      * dest - destination in which to return line.
46      * len - length of resultant line in dest in chars.
47      * width - maximum width of line in pixels.
48      * format - format type passed to DrawText.
49      *
50      * Returns pointer to next char in str after end of the line
51      * or NULL if end of str reached.
52      */
53
54     int i = 0, j = 0, k;
55     int plen = 0;
56     int numspaces;
57     SIZE16 size;
58     int lasttab = 0;
59     int wb_i = 0, wb_j = 0, wb_count = 0;
60
61     while (*count)
62     {
63         switch (str[i])
64         {
65         case CR:
66         case LF:
67             if (!(format & DT_SINGLELINE))
68             {
69                 if (str[i] == CR && str[i+1] == LF)
70                     i++;
71                 i++;
72                 *len = j;
73                 (*count)--;
74                 return (&str[i]);
75             }
76             dest[j++] = str[i++];
77             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
78                 (format & DT_WORDBREAK))
79             {
80                 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
81                     return NULL;
82                 plen += size.cx;
83             }
84             break;
85             
86         case PREFIX:
87             if (!(format & DT_NOPREFIX))
88             {
89                 prefix_offset = j;
90                 i++;
91             }
92             else
93             {
94                 dest[j++] = str[i++];
95                 if (!(format & DT_NOCLIP) || (format & DT_WORDBREAK))
96                 {
97                     if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
98                         return NULL;
99                     plen += size.cx;
100                 }
101             }
102             break;
103             
104         case TAB:
105             if (format & DT_EXPANDTABS)
106             {
107                 wb_i = ++i;
108                 wb_j = j;
109                 wb_count = *count;
110
111                 if (!GetTextExtentPoint16(hdc, &dest[lasttab], j - lasttab,
112                                                                  &size))
113                     return NULL;
114
115                 numspaces = (tabwidth - size.cx) / spacewidth;
116                 for (k = 0; k < numspaces; k++)
117                     dest[j++] = SPACE;
118                 plen += tabwidth - size.cx;
119                 lasttab = wb_j + numspaces;
120             }
121             else
122             {
123                 dest[j++] = str[i++];
124                 if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
125                     (format & DT_WORDBREAK))
126                 {
127                     if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
128                         return NULL;
129                     plen += size.cx;
130                 }
131             }
132             break;
133
134         case SPACE:
135             dest[j++] = str[i++];
136             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
137                 (format & DT_WORDBREAK))
138             {
139                 wb_i = i;
140                 wb_j = j - 1;
141                 wb_count = *count;
142                 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
143                     return NULL;
144                 plen += size.cx;
145             }
146             break;
147
148         default:
149             dest[j++] = str[i++];
150             if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) ||
151                 (format & DT_WORDBREAK))
152             {
153                 if (!GetTextExtentPoint16(hdc, &dest[j-1], 1, &size))
154                     return NULL;
155                 plen += size.cx;
156             }
157         }
158
159         (*count)--;
160         if (!(format & DT_NOCLIP) || (format & DT_WORDBREAK))
161         {
162             if (plen > width)
163             {
164                 if (format & DT_WORDBREAK)
165                 {
166                     if (wb_j)
167                     {
168                         *len = wb_j;
169                         *count = wb_count - 1;
170                         return (&str[wb_i]);
171                     }
172                 }
173                 else
174                 {
175                     *len = j;
176                     return (&str[i]);
177                 }
178             }
179         }
180     }
181     
182     *len = j;
183     return NULL;
184 }
185
186
187 /***********************************************************************
188  *           DrawText16    (USER.85)
189  */
190 INT16 DrawText16( HDC16 hdc, LPCSTR str, INT16 i_count,
191                   LPRECT16 rect, UINT16 flags )
192 {
193     SIZE16 size;
194     const char *strPtr;
195     static char line[1024];
196     int len, lh, count=i_count;
197     int prefix_x = 0;
198     int prefix_end = 0;
199     TEXTMETRIC16 tm;
200     int x = rect->left, y = rect->top;
201     int width = rect->right - rect->left;
202     int max_width = 0;
203
204     dprintf_text(stddeb,"DrawText: '%s', %d , [(%d,%d),(%d,%d)]\n", str,
205                  count, rect->left, rect->top, rect->right, rect->bottom);
206     
207     if (count == -1) count = strlen(str);
208     strPtr = str;
209
210     GetTextMetrics16(hdc, &tm);
211     if (flags & DT_EXTERNALLEADING)
212         lh = tm.tmHeight + tm.tmExternalLeading;
213     else
214         lh = tm.tmHeight;
215
216     if (flags & DT_TABSTOP)
217         tabstop = flags >> 8;
218
219     if (flags & DT_EXPANDTABS)
220     {
221         GetTextExtentPoint16(hdc, " ", 1, &size);
222         spacewidth = size.cx;
223         GetTextExtentPoint16(hdc, "o", 1, &size);
224         tabwidth = size.cx * tabstop;
225     }
226
227     if (flags & DT_CALCRECT) flags |= DT_NOCLIP;
228
229     do
230     {
231         prefix_offset = -1;
232         strPtr = TEXT_NextLine(hdc, strPtr, &count, line, &len, width, flags);
233
234         if (prefix_offset != -1)
235         {
236             GetTextExtentPoint16(hdc, line, prefix_offset, &size);
237             prefix_x = size.cx;
238             GetTextExtentPoint16(hdc, line, prefix_offset + 1, &size);
239             prefix_end = size.cx - 1;
240         }
241
242         if (!GetTextExtentPoint16(hdc, line, len, &size)) return 0;
243         if (flags & DT_CENTER) x = (rect->left + rect->right -
244                                     size.cx) / 2;
245         else if (flags & DT_RIGHT) x = rect->right - size.cx;
246
247         if (flags & DT_SINGLELINE)
248         {
249             if (flags & DT_VCENTER) y = rect->top + 
250                 (rect->bottom - rect->top) / 2 - size.cy / 2;
251             else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
252         }
253         if (!(flags & DT_CALCRECT))
254         {
255             if (!ExtTextOut16(hdc, x, y, (flags & DT_NOCLIP) ? 0 : ETO_CLIPPED,
256                               rect, line, len, NULL )) return 0;
257             if (prefix_offset != -1)
258             {
259                 HPEN16 hpen = CreatePen( PS_SOLID, 1, GetTextColor(hdc) );
260                 HPEN16 oldPen = SelectObject( hdc, hpen );
261                 MoveTo(hdc, x + prefix_x, y + tm.tmAscent + 1 );
262                 LineTo(hdc, x + prefix_end, y + tm.tmAscent + 1 );
263                 SelectObject( hdc, oldPen );
264                 DeleteObject( hpen );
265             }
266         }
267         else if (size.cx > max_width)
268             max_width = size.cx;
269
270         y += lh;
271         if (strPtr)
272         {
273             if (!(flags & DT_NOCLIP))
274             {
275                 if (y > rect->bottom - lh)
276                     break;
277             }
278         }
279     }
280     while (strPtr);
281     if (flags & DT_CALCRECT)
282     {
283         rect->right = rect->left + max_width;
284         rect->bottom = y;
285     }
286     return 1;
287 }
288
289
290 /***********************************************************************
291  *           DrawText32A    (USER32.163)
292  */
293 INT32 DrawText32A( HDC32 hdc, LPCSTR str, INT32 count,
294                    LPRECT32 rect, UINT32 flags )
295 {
296     RECT16 rect16;
297     INT16 ret;
298
299     if (!rect)
300         return DrawText16( (HDC16)hdc, str, (INT16)count, NULL, (UINT16)flags);
301     CONV_RECT32TO16( rect, &rect16 );
302     ret = DrawText16( (HDC16)hdc, str, (INT16)count, &rect16, (UINT16)flags );
303     CONV_RECT16TO32( &rect16, rect );
304     return ret;
305 }
306
307
308 /***********************************************************************
309  *           DrawText32W    (USER32.166)
310  */
311 INT32 DrawText32W( HDC32 hdc, LPCWSTR str, INT32 count,
312                    LPRECT32 rect, UINT32 flags )
313 {
314     char *p = STRING32_DupUniToAnsi( str );
315     INT32 ret = DrawText32A( hdc, p, count, rect, flags );
316     free(p);
317     return ret;
318 }
319
320
321 /***********************************************************************
322  *           ExtTextOut16    (GDI.351)
323  */
324 BOOL16 ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
325                      const RECT16 *lprect, LPCSTR str, UINT16 count,
326                      const INT16 *lpDx )
327 {
328     HRGN32      hRgnClip = 0;
329     int         dir, ascent, descent, i;
330     XCharStruct info;
331     XFontStruct *font;
332     RECT16      rect;
333
334     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
335     if (!dc) 
336     {
337         dc = (DC *)GDI_GetObjPtr( hdc, METAFILE_DC_MAGIC );
338         if (!dc) return FALSE;
339         MF_ExtTextOut( dc, x, y, flags, lprect, str, count, lpDx );
340         return TRUE;
341     }
342
343     if (!DC_SetupGCForText( dc )) return TRUE;
344     font = dc->u.x.font.fstruct;
345
346     dprintf_text(stddeb,"ExtTextOut: hdc=%04x %d,%d '%*.*s', %d  flags=%d\n",
347             hdc, x, y, count, count, str, count, flags);
348     if (lprect != NULL) dprintf_text(stddeb, "\trect=(%d,%d- %d,%d)\n",
349                                      lprect->left, lprect->top,
350                                      lprect->right, lprect->bottom );
351
352       /* Setup coordinates */
353
354     if (dc->w.textAlign & TA_UPDATECP)
355     {
356         x = dc->w.CursPosX;
357         y = dc->w.CursPosY;
358     }
359
360     if (flags & (ETO_OPAQUE | ETO_CLIPPED))  /* there's a rectangle */
361     {
362         if (!lprect)  /* not always */
363         {
364             SIZE16 sz;
365             if (flags & ETO_CLIPPED)  /* Can't clip with no rectangle */
366               return FALSE;
367             if (!GetTextExtentPoint16( hdc, str, count, &sz ))
368               return FALSE;
369             rect.left   = XLPTODP( dc, x );
370             rect.right  = XLPTODP( dc, x+sz.cx );
371             rect.top    = YLPTODP( dc, y );
372             rect.bottom = YLPTODP( dc, y+sz.cy );
373         }
374         else
375         {
376             rect.left   = XLPTODP( dc, lprect->left );
377             rect.right  = XLPTODP( dc, lprect->right );
378             rect.top    = YLPTODP( dc, lprect->top );
379             rect.bottom = YLPTODP( dc, lprect->bottom );
380         }
381         if (rect.right < rect.left) SWAP_INT( rect.left, rect.right );
382         if (rect.bottom < rect.top) SWAP_INT( rect.top, rect.bottom );
383     }
384
385     x = XLPTODP( dc, x );
386     y = YLPTODP( dc, y );
387
388     dprintf_text(stddeb,"\treal coord: x=%i, y=%i, rect=(%d,%d-%d,%d)\n",
389                           x, y, rect.left, rect.top, rect.right, rect.bottom);
390
391       /* Draw the rectangle */
392
393     if (flags & ETO_OPAQUE)
394     {
395         XSetForeground( display, dc->u.x.gc, dc->w.backgroundPixel );
396         XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
397                         dc->w.DCOrgX + rect.left, dc->w.DCOrgY + rect.top,
398                         rect.right-rect.left, rect.bottom-rect.top );
399     }
400     if (!count) return TRUE;  /* Nothing more to do */
401
402       /* Compute text starting position */
403
404     XTextExtents( font, str, count, &dir, &ascent, &descent, &info );
405
406     if (lpDx) /* have explicit character cell x offsets */
407     {
408         /* sum lpDx array and add the width of last character */
409
410         info.width = XTextWidth( font, str + count - 1, 1) + dc->w.charExtra;
411         if (str[count-1] == (char)dc->u.x.font.metrics.tmBreakChar)
412             info.width += dc->w.breakExtra;
413
414         for (i = 0; i < count; i++) info.width += lpDx[i];
415     }
416     else
417        info.width += count*dc->w.charExtra + dc->w.breakExtra*dc->w.breakCount;
418
419     switch( dc->w.textAlign & (TA_LEFT | TA_RIGHT | TA_CENTER) )
420     {
421       case TA_LEFT:
422           if (dc->w.textAlign & TA_UPDATECP)
423               dc->w.CursPosX = XDPTOLP( dc, x + info.width );
424           break;
425       case TA_RIGHT:
426           x -= info.width;
427           if (dc->w.textAlign & TA_UPDATECP) dc->w.CursPosX = XDPTOLP( dc, x );
428           break;
429       case TA_CENTER:
430           x -= info.width / 2;
431           break;
432     }
433
434     switch( dc->w.textAlign & (TA_TOP | TA_BOTTOM | TA_BASELINE) )
435     {
436       case TA_TOP:
437           y += font->ascent;
438           break;
439       case TA_BOTTOM:
440           y -= font->descent;
441           break;
442       case TA_BASELINE:
443           break;
444     }
445
446       /* Set the clip region */
447
448     if (flags & ETO_CLIPPED)
449     {
450        if (dc->w.flags & DC_MEMORY)
451        {
452           hRgnClip = dc->w.hClipRgn;
453           CLIPPING_IntersectClipRect(dc, rect.left, rect.top, rect.right, rect.bottom,
454                                          CLIP_INTERSECT | CLIP_KEEPRGN);
455        }
456        else
457        { 
458           SaveVisRgn( hdc );
459           IntersectVisRect( hdc, rect.left, rect.top, rect.right, rect.bottom );
460        }
461     }
462
463       /* Draw the text background if necessary */
464
465     if (dc->w.backgroundMode != TRANSPARENT)
466     {
467           /* If rectangle is opaque and clipped, do nothing */
468         if (!(flags & ETO_CLIPPED) || !(flags & ETO_OPAQUE))
469         {
470               /* Only draw if rectangle is not opaque or if some */
471               /* text is outside the rectangle */
472             if (!(flags & ETO_OPAQUE) ||
473                 (x < rect.left) ||
474                 (x + info.width >= rect.right) ||
475                 (y-font->ascent < rect.top) ||
476                 (y+font->descent >= rect.bottom))
477             {
478                 XSetForeground( display, dc->u.x.gc, dc->w.backgroundPixel );
479                 XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
480                                 dc->w.DCOrgX + x,
481                                 dc->w.DCOrgY + y - font->ascent,
482                                 info.width,
483                                 font->ascent + font->descent );
484             }
485         }
486     }
487     
488     /* Draw the text (count > 0 verified) */
489
490     XSetForeground( display, dc->u.x.gc, dc->w.textPixel );
491     if (!dc->w.charExtra && !dc->w.breakExtra && !lpDx)
492     {
493         XDrawString( display, dc->u.x.drawable, dc->u.x.gc, 
494                      dc->w.DCOrgX + x, dc->w.DCOrgY + y, str, count );
495     }
496     else  /* Now the fun begins... */
497     {
498         XTextItem *items, *pitem;
499         int delta;
500
501         /* allocate max items */
502
503         pitem = items = xmalloc( count * sizeof(XTextItem) );
504         delta = i = 0;
505         while (i < count)
506         {
507             /* initialize text item with accumulated delta */
508
509             pitem->chars  = (char *)str + i;
510             pitem->delta  = delta; 
511             pitem->nchars = 0;
512             pitem->font   = None;
513             delta = 0;
514
515             /* stuff characters into the same XTextItem until new delta 
516              * becomes  non-zero */
517
518             do
519             {
520                 if (lpDx) delta += lpDx[i] - XTextWidth( font, str + i, 1);
521                 else
522                 {
523                     delta += dc->w.charExtra;
524                     if (str[i] == (char)dc->u.x.font.metrics.tmBreakChar)
525                         delta += dc->w.breakExtra;
526                 }
527                 pitem->nchars++;
528             } 
529             while ((++i < count) && !delta);
530             pitem++;
531         }
532
533         XDrawText( display, dc->u.x.drawable, dc->u.x.gc,
534                    dc->w.DCOrgX + x, dc->w.DCOrgY + y, items, pitem - items );
535         free( items );
536     }
537
538       /* Draw underline and strike-out if needed */
539
540     if (dc->u.x.font.metrics.tmUnderlined)
541     {
542         long linePos, lineWidth;       
543         if (!XGetFontProperty( font, XA_UNDERLINE_POSITION, &linePos ))
544             linePos = font->descent-1;
545         if (!XGetFontProperty( font, XA_UNDERLINE_THICKNESS, &lineWidth ))
546             lineWidth = 0;
547         else if (lineWidth == 1) lineWidth = 0;
548         XSetLineAttributes( display, dc->u.x.gc, lineWidth,
549                             LineSolid, CapRound, JoinBevel ); 
550         XDrawLine( display, dc->u.x.drawable, dc->u.x.gc,
551                    dc->w.DCOrgX + x, dc->w.DCOrgY + y + linePos,
552                    dc->w.DCOrgX + x + info.width, dc->w.DCOrgY + y + linePos );
553     }
554     if (dc->u.x.font.metrics.tmStruckOut)
555     {
556         long lineAscent, lineDescent;
557         if (!XGetFontProperty( font, XA_STRIKEOUT_ASCENT, &lineAscent ))
558             lineAscent = font->ascent / 3;
559         if (!XGetFontProperty( font, XA_STRIKEOUT_DESCENT, &lineDescent ))
560             lineDescent = -lineAscent;
561         XSetLineAttributes( display, dc->u.x.gc, lineAscent + lineDescent,
562                             LineSolid, CapRound, JoinBevel ); 
563         XDrawLine( display, dc->u.x.drawable, dc->u.x.gc,
564                    dc->w.DCOrgX + x, dc->w.DCOrgY + y - lineAscent,
565                    dc->w.DCOrgX + x + info.width, dc->w.DCOrgY + y - lineAscent );
566     }
567
568     if (flags & ETO_CLIPPED) 
569     {
570         if( dc->w.flags & DC_MEMORY )
571              SelectClipRgn( hdc, hRgnClip );
572         else RestoreVisRgn( hdc );
573     }
574     return TRUE;
575 }
576
577
578 /***********************************************************************
579  *           ExtTextOut32A    (GDI32.98)
580  */
581 BOOL32 ExtTextOut32A( HDC32 hdc, INT32 x, INT32 y, UINT32 flags,
582                       const RECT32 *lprect, LPCSTR str, UINT32 count,
583                       const INT32 *lpDx )
584 {
585     RECT16 rect16;
586
587     if (lpDx) fprintf( stderr, "ExtTextOut32A: lpDx not implemented\n" );
588     if (!lprect)
589         return ExtTextOut16( (HDC16)hdc, (INT16)x, (INT16)y, (UINT16)flags,
590                              NULL, str, (UINT16)count, NULL );
591     CONV_RECT32TO16( lprect, &rect16 );
592     return ExtTextOut16( (HDC16)hdc, (INT16)x, (INT16)y, (UINT16)flags,
593                          &rect16, str, (UINT16)count, NULL );
594 }
595
596
597 /***********************************************************************
598  *           ExtTextOut32W    (GDI32.99)
599  */
600 BOOL32 ExtTextOut32W( HDC32 hdc, INT32 x, INT32 y, UINT32 flags,
601                       const RECT32 *lprect, LPCWSTR str, UINT32 count,
602                       const INT32 *lpDx )
603 {
604     char *p = STRING32_DupUniToAnsi( str );
605     INT32 ret = ExtTextOut32A( hdc, x, y, flags, lprect, p, count, lpDx );
606     free(p);
607     return ret;
608 }
609
610
611 /***********************************************************************
612  *           TextOut16    (GDI.33)
613  */
614 BOOL16 TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
615 {
616     return ExtTextOut16( hdc, x, y, 0, NULL, str, count, NULL );
617 }
618
619
620 /***********************************************************************
621  *           TextOut32A    (GDI32.355)
622  */
623 BOOL32 TextOut32A( HDC32 hdc, INT32 x, INT32 y, LPCSTR str, INT32 count )
624 {
625     return ExtTextOut32A( hdc, x, y, 0, NULL, str, count, NULL );
626 }
627
628
629 /***********************************************************************
630  *           TextOut32W    (GDI32.356)
631  */
632 BOOL32 TextOut32W( HDC32 hdc, INT32 x, INT32 y, LPCWSTR str, INT32 count )
633 {
634     return ExtTextOut32W( hdc, x, y, 0, NULL, str, count, NULL );
635 }
636
637
638 /***********************************************************************
639  *           GrayString   (USER.185)
640  */
641 BOOL GrayString(HDC16 hdc, HBRUSH16 hbr, GRAYSTRINGPROC16 gsprc, LPARAM lParam, 
642                 INT cch, INT x, INT y, INT cx, INT cy)
643 {
644     BOOL ret;
645     COLORREF current_color;
646
647     if (!cch) cch = lstrlen16( (LPCSTR)PTR_SEG_TO_LIN(lParam) );
648     if (gsprc) return gsprc( hdc, lParam, cch );
649     current_color = GetTextColor( hdc );
650     SetTextColor( hdc, GetSysColor(COLOR_GRAYTEXT) );
651     ret = TextOut16( hdc, x, y, (LPCSTR)PTR_SEG_TO_LIN(lParam), cch );
652     SetTextColor( hdc, current_color );
653     return ret;
654 }
655
656
657 /***********************************************************************
658  *           TEXT_TabbedTextOut
659  *
660  * Helper function for TabbedTextOut() and GetTabbedTextExtent().
661  * Note: this doesn't work too well for text-alignment modes other
662  *       than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-)
663  */
664 LONG TEXT_TabbedTextOut( HDC16 hdc, int x, int y, LPSTR lpstr, int count, 
665                          int cTabStops, LPINT16 lpTabPos, int nTabOrg,
666                          BOOL fDisplayText)
667 {
668     WORD defWidth;
669     DWORD extent = 0;
670     int i, tabPos = x;
671     int start = x;
672
673     if (cTabStops == 1)
674     {
675         defWidth = *lpTabPos;
676         cTabStops = 0;
677     }
678     else
679     {
680         TEXTMETRIC16 tm;
681         GetTextMetrics16( hdc, &tm );
682         defWidth = 8 * tm.tmAveCharWidth;
683     }
684     
685     while (count > 0)
686     {
687         for (i = 0; i < count; i++)
688             if (lpstr[i] == '\t') break;
689         extent = GetTextExtent( hdc, lpstr, i );
690         while ((cTabStops > 0) && (nTabOrg + *lpTabPos <= x + LOWORD(extent)))
691         {
692             lpTabPos++;
693             cTabStops--;
694         }
695         if (i == count)
696             tabPos = x + LOWORD(extent);
697         else if (cTabStops > 0)
698             tabPos = nTabOrg + *lpTabPos;
699         else
700             tabPos = nTabOrg + ((x + LOWORD(extent) - nTabOrg) / defWidth + 1) * defWidth;
701         if (fDisplayText)
702         {
703             RECT16 r;
704             SetRect16( &r, x, y, tabPos, y+HIWORD(extent) );
705             ExtTextOut16( hdc, x, y,
706                           GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0,
707                           &r, lpstr, i, NULL );
708         }
709         x = tabPos;
710         count -= i+1;
711         lpstr += i+1;
712     }
713     return MAKELONG(tabPos - start, HIWORD(extent));
714 }
715
716
717 /***********************************************************************
718  *           TabbedTextOut    (USER.196)
719  */
720 LONG TabbedTextOut( HDC16 hdc, short x, short y, LPSTR lpstr, short count, 
721                     short cTabStops, LPINT16 lpTabPos, short nTabOrg )
722 {
723     dprintf_text( stddeb, "TabbedTextOut: %04x %d,%d '%*.*s' %d\n",
724                   hdc, x, y, count, count, lpstr, count );
725     return TEXT_TabbedTextOut( hdc, x, y, lpstr, count, cTabStops,
726                                lpTabPos, nTabOrg, TRUE );
727 }
728
729
730 /***********************************************************************
731  *           GetTabbedTextExtent    (USER.197)
732  */
733 DWORD GetTabbedTextExtent( HDC16 hdc, LPSTR lpstr, int count, 
734                           int cTabStops, LPINT16 lpTabPos )
735 {
736     dprintf_text( stddeb, "GetTabbedTextExtent: %04x '%*.*s' %d\n",
737                   hdc, count, count, lpstr, count );
738     return TEXT_TabbedTextOut( hdc, 0, 0, lpstr, count, cTabStops,
739                                lpTabPos, 0, FALSE );
740 }