4 * Copyright 1993 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1993";
9 #include <X11/Intrinsic.h>
10 #include <X11/StringDefs.h>
12 #include <X11/Shell.h>
13 #include <X11/Xatom.h>
26 static int tabstop
= 8;
28 static int spacewidth
;
29 static int prefix_offset
;
32 static char *TEXT_NextLine(HDC hdc
, char *str
, int *count
, char *dest
,
33 int *len
, int width
, WORD format
)
35 /* Return next line of text from a string.
38 * str - string to parse into lines.
39 * count - length of str.
40 * dest - destination in which to return line.
41 * len - length of resultant line in dest in chars.
42 * width - maximum width of line in pixels.
43 * format - format type passed to DrawText.
45 * Returns pointer to next char in str after end of the line
46 * or NULL if end of str reached.
54 int wb_i
= 0, wb_j
= 0, wb_count
;
62 if (!(format
& DT_SINGLELINE
))
65 if (str
[i
] == CR
|| str
[i
] == LF
)
71 if (!(format
& DT_NOCLIP
) || !(format
& DT_NOPREFIX
))
73 if (!GetTextExtentPoint(hdc
, &dest
[j
-1], 1, &size
))
80 if (!(format
& DT_NOPREFIX
))
82 prefix_offset
= j
+ 1;
88 if (!(format
& DT_NOCLIP
))
90 if (!GetTextExtentPoint(hdc
, &dest
[j
-1], 1, &size
))
98 if (format
& DT_EXPANDTABS
)
104 if (!GetTextExtentPoint(hdc
, &dest
[lasttab
], j
- lasttab
,
108 numspaces
= (tabwidth
- size
.cx
) / spacewidth
;
109 for (k
= 0; k
< numspaces
; k
++)
111 plen
+= tabwidth
- size
.cx
;
112 lasttab
= wb_j
+ numspaces
;
116 dest
[j
++] = str
[i
++];
117 if (!(format
& DT_NOCLIP
) || !(format
& DT_NOPREFIX
))
119 if (!GetTextExtentPoint(hdc
, &dest
[j
-1], 1, &size
))
127 dest
[j
++] = str
[i
++];
128 if (!(format
& DT_NOCLIP
) || !(format
& DT_NOPREFIX
))
133 if (!GetTextExtentPoint(hdc
, &dest
[j
-1], 1, &size
))
140 dest
[j
++] = str
[i
++];
141 if (!(format
& DT_NOCLIP
) || !(format
& DT_NOPREFIX
))
143 if (!GetTextExtentPoint(hdc
, &dest
[j
-1], 1, &size
))
150 if (!(format
& DT_NOCLIP
) || (format
& DT_WORDBREAK
))
154 if (format
& DT_WORDBREAK
)
174 /***********************************************************************
177 int DrawText( HDC hdc
, LPSTR str
, int count
, LPRECT rect
, WORD flags
)
181 static char line
[1024];
182 int len
, lh
, prefix_x
, prefix_len
;
184 int x
= rect
->left
, y
= rect
->top
;
185 int width
= rect
->right
- rect
->left
;
187 if (count
== -1) count
= strlen(str
);
190 GetTextMetrics(hdc
, &tm
);
191 if (flags
& DT_EXTERNALLEADING
)
192 lh
= tm
.tmHeight
+ tm
.tmExternalLeading
;
196 if (flags
& DT_TABSTOP
)
197 tabstop
= flags
>> 8;
199 if (flags
& DT_EXPANDTABS
)
201 GetTextExtentPoint(hdc
, " ", 1, &size
);
202 spacewidth
= size
.cx
;
203 GetTextExtentPoint(hdc
, "o", 1, &size
);
204 tabwidth
= size
.cx
* tabstop
;
210 strPtr
= TEXT_NextLine(hdc
, strPtr
, &count
, line
, &len
, width
, flags
);
212 if (prefix_offset
!= -1)
214 GetTextExtentPoint(hdc
, line
, prefix_offset
- 1, &size
);
216 GetTextExtentPoint(hdc
, line
+ prefix_offset
, 1, &size
);
217 prefix_len
= size
.cx
;
220 if (!GetTextExtentPoint(hdc
, line
, len
, &size
)) return 0;
221 if (flags
& DT_CENTER
) x
= (rect
->left
+ rect
->right
-
223 else if (flags
& DT_RIGHT
) x
= rect
->right
- size
.cx
;
225 if (flags
& DT_SINGLELINE
)
227 if (flags
& DT_VCENTER
) y
= (rect
->top
+ rect
->bottom
-
229 else if (flags
& DT_BOTTOM
) y
= rect
->bottom
- size
.cy
;
232 if (!TextOut(hdc
, x
, y
, line
, len
)) return 0;
233 if (prefix_offset
!= -1)
235 MoveTo(hdc
, x
+ prefix_x
, y
+ size
.cy
);
236 LineTo(hdc
, x
+ prefix_x
+ prefix_len
, y
+ size
.cy
);
242 if (!(flags
& DT_NOCLIP
))
244 if (y
> rect
->bottom
- lh
)
255 /***********************************************************************
258 BOOL
TextOut( HDC hdc
, short x
, short y
, LPSTR str
, short count
)
260 int dir
, ascent
, descent
, i
;
264 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
265 if (!dc
) return FALSE
;
266 if (!DC_SetupGCForText( dc
)) return TRUE
;
267 font
= dc
->u
.x
.font
.fstruct
;
269 if (dc
->w
.textAlign
& TA_UPDATECP
)
275 printf( "TextOut: %d,%d '%s'\n", x
, y
, str
);
277 x
= XLPTODP( dc
, x
);
278 y
= YLPTODP( dc
, y
);
280 XTextExtents( font
, str
, count
, &dir
, &ascent
, &descent
, &info
);
281 info
.width
+= count
*dc
->w
.charExtra
+ dc
->w
.breakExtra
*dc
->w
.breakCount
;
283 /* Compute starting position */
285 switch( dc
->w
.textAlign
& (TA_LEFT
| TA_RIGHT
| TA_CENTER
) )
288 if (dc
->w
.textAlign
& TA_UPDATECP
)
289 dc
->w
.CursPosX
= XDPTOLP( dc
, x
+ info
.width
);
293 if (dc
->w
.textAlign
& TA_UPDATECP
) dc
->w
.CursPosX
= XDPTOLP( dc
, x
);
299 switch( dc
->w
.textAlign
& (TA_TOP
| TA_BOTTOM
| TA_BASELINE
) )
313 if (!dc
->w
.charExtra
&& !dc
->w
.breakExtra
)
315 if (dc
->w
.backgroundMode
== TRANSPARENT
)
316 XDrawString( XT_display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
319 XDrawImageString( XT_display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
326 for (i
= 0; i
< count
; i
++, p
++)
328 XCharStruct
* charStr
;
329 unsigned char ch
= *p
;
332 if ((ch
< font
->min_char_or_byte2
)||(ch
> font
->max_char_or_byte2
))
333 ch
= font
->default_char
;
334 if (!font
->per_char
) charStr
= &font
->min_bounds
;
335 else charStr
= font
->per_char
+ ch
- font
->min_char_or_byte2
;
337 extraWidth
= dc
->w
.charExtra
;
338 if (ch
== dc
->u
.x
.font
.metrics
.tmBreakChar
)
339 extraWidth
+= dc
->w
.breakExtra
;
341 if (dc
->w
.backgroundMode
== TRANSPARENT
)
342 XDrawString( XT_display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
346 XDrawImageString( XT_display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
348 XSetForeground( XT_display
, dc
->u
.x
.gc
, dc
->w
.backgroundPixel
);
349 XFillRectangle( XT_display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
350 xchar
+ charStr
->width
, y
- font
->ascent
,
351 extraWidth
, font
->ascent
+ font
->descent
);
352 XSetForeground( XT_display
, dc
->u
.x
.gc
, dc
->w
.textPixel
);
354 xchar
+= charStr
->width
+ extraWidth
;
358 /* Draw underline and strike-out if needed */
360 if (dc
->u
.x
.font
.metrics
.tmUnderlined
)
362 long linePos
, lineWidth
;
363 if (!XGetFontProperty( font
, XA_UNDERLINE_POSITION
, &linePos
))
364 linePos
= font
->descent
-1;
365 if (!XGetFontProperty( font
, XA_UNDERLINE_THICKNESS
, &lineWidth
))
367 else if (lineWidth
== 1) lineWidth
= 0;
368 XSetLineAttributes( XT_display
, dc
->u
.x
.gc
, lineWidth
,
369 LineSolid
, CapRound
, JoinBevel
);
370 XDrawLine( XT_display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
371 x
, y
+ linePos
, x
+ info
.width
, y
+ linePos
);
373 if (dc
->u
.x
.font
.metrics
.tmStruckOut
)
375 long lineAscent
, lineDescent
;
376 if (!XGetFontProperty( font
, XA_STRIKEOUT_ASCENT
, &lineAscent
))
377 lineAscent
= font
->ascent
/ 3;
378 if (!XGetFontProperty( font
, XA_STRIKEOUT_DESCENT
, &lineDescent
))
379 lineDescent
= -lineAscent
;
380 XSetLineAttributes( XT_display
, dc
->u
.x
.gc
, lineAscent
+ lineDescent
,
381 LineSolid
, CapRound
, JoinBevel
);
382 XDrawLine( XT_display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
383 x
, y
- lineAscent
, x
+ info
.width
, y
- lineAscent
);