2 * X11 graphics driver text functions
4 * Copyright 1993,1994 Alexandre Julliard
14 /*#include "callback.h"*/
20 #define SWAP_INT(a,b) { int t = a; a = b; b = t; }
21 #define IROUND(x) (int)((x)>0? (x)+0.5 : (x) - 0.5)
23 /***********************************************************************
27 X11DRV_ExtTextOut( DC
*dc
, INT32 x
, INT32 y
, UINT32 flags
,
28 const RECT32
*lprect
, LPCSTR str
, UINT32 count
,
32 int dir
, ascent
, descent
, i
;
37 char dfBreakChar
, lfUnderline
, lfStrikeOut
;
39 if (!DC_SetupGCForText( dc
)) return TRUE
;
41 pfo
= XFONT_GetFontObject( dc
->u
.x
.font
);
44 dfBreakChar
= (char)pfo
->fi
->df
.dfBreakChar
;
45 lfUnderline
= (pfo
->fo_flags
& FO_SYNTH_UNDERLINE
) ? 1 : 0;
46 lfStrikeOut
= (pfo
->fo_flags
& FO_SYNTH_STRIKEOUT
) ? 1 : 0;
48 TRACE(text
,"hdc=%04x df=%04x %d,%d %s, %d flags=%d\n",
49 dc
->hSelf
, (UINT16
)(dc
->u
.x
.font
), x
, y
,
50 debugstr_an (str
, count
), count
, flags
);
52 /* some strings sent here end in a newline for whatever reason. I have no
53 clue what the right treatment should be in general, but ignoring
54 terminating newlines seems ok. MW, April 1998. */
55 if (count
> 0 && str
[count
- 1] == '\n') count
--;
57 if (lprect
!= NULL
) TRACE(text
, "\trect=(%d,%d - %d,%d)\n",
58 lprect
->left
, lprect
->top
,
59 lprect
->right
, lprect
->bottom
);
60 /* Setup coordinates */
62 if (dc
->w
.textAlign
& TA_UPDATECP
)
68 if (flags
& (ETO_OPAQUE
| ETO_CLIPPED
)) /* there's a rectangle */
70 if (!lprect
) /* not always */
73 if (flags
& ETO_CLIPPED
) /* Can't clip with no rectangle */
75 if (!X11DRV_GetTextExtentPoint( dc
, str
, count
, &sz
))
77 rect
.left
= XLPTODP( dc
, x
);
78 rect
.right
= XLPTODP( dc
, x
+sz
.cx
);
79 rect
.top
= YLPTODP( dc
, y
);
80 rect
.bottom
= YLPTODP( dc
, y
+sz
.cy
);
84 rect
.left
= XLPTODP( dc
, lprect
->left
);
85 rect
.right
= XLPTODP( dc
, lprect
->right
);
86 rect
.top
= YLPTODP( dc
, lprect
->top
);
87 rect
.bottom
= YLPTODP( dc
, lprect
->bottom
);
89 if (rect
.right
< rect
.left
) SWAP_INT( rect
.left
, rect
.right
);
90 if (rect
.bottom
< rect
.top
) SWAP_INT( rect
.top
, rect
.bottom
);
96 TRACE(text
,"\treal coord: x=%i, y=%i, rect=(%d,%d - %d,%d)\n",
97 x
, y
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
99 /* Draw the rectangle */
101 if (flags
& ETO_OPAQUE
)
103 TSXSetForeground( display
, dc
->u
.x
.gc
, dc
->w
.backgroundPixel
);
104 TSXFillRectangle( display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
105 dc
->w
.DCOrgX
+ rect
.left
, dc
->w
.DCOrgY
+ rect
.top
,
106 rect
.right
-rect
.left
, rect
.bottom
-rect
.top
);
108 if (!count
) return TRUE
; /* Nothing more to do */
110 /* Compute text starting position */
112 if (lpDx
) /* have explicit character cell x offsets in logical coordinates */
114 int extra
= dc
->wndExtX
/ 2;
115 for (i
= info
.width
= 0; i
< count
; i
++) info
.width
+= lpDx
[i
];
116 info
.width
= (info
.width
* dc
->vportExtX
+ extra
) / dc
->wndExtX
;
120 TSXTextExtents( font
, str
, count
, &dir
, &ascent
, &descent
, &info
);
121 info
.width
+= count
*dc
->w
.charExtra
+ dc
->w
.breakExtra
*dc
->w
.breakCount
;
124 switch( dc
->w
.textAlign
& (TA_LEFT
| TA_RIGHT
| TA_CENTER
) )
127 if (dc
->w
.textAlign
& TA_UPDATECP
)
128 dc
->w
.CursPosX
= XDPTOLP( dc
, x
+ info
.width
);
132 if (dc
->w
.textAlign
& TA_UPDATECP
) dc
->w
.CursPosX
= XDPTOLP( dc
, x
);
139 switch( dc
->w
.textAlign
& (TA_TOP
| TA_BOTTOM
| TA_BASELINE
) )
151 /* Set the clip region */
153 if (flags
& ETO_CLIPPED
)
155 hRgnClip
= dc
->w
.hClipRgn
;
156 CLIPPING_IntersectClipRect( dc
, rect
.left
, rect
.top
, rect
.right
,
157 rect
.bottom
, CLIP_INTERSECT
|CLIP_KEEPRGN
);
160 /* Draw the text background if necessary */
162 if (dc
->w
.backgroundMode
!= TRANSPARENT
)
164 /* If rectangle is opaque and clipped, do nothing */
165 if (!(flags
& ETO_CLIPPED
) || !(flags
& ETO_OPAQUE
))
167 /* Only draw if rectangle is not opaque or if some */
168 /* text is outside the rectangle */
169 if (!(flags
& ETO_OPAQUE
) ||
171 (x
+ info
.width
>= rect
.right
) ||
172 (y
-font
->ascent
< rect
.top
) ||
173 (y
+font
->descent
>= rect
.bottom
))
175 TSXSetForeground( display
, dc
->u
.x
.gc
, dc
->w
.backgroundPixel
);
176 TSXFillRectangle( display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
178 dc
->w
.DCOrgY
+ y
- font
->ascent
,
180 font
->ascent
+ font
->descent
);
185 /* Draw the text (count > 0 verified) */
187 TSXSetForeground( display
, dc
->u
.x
.gc
, dc
->w
.textPixel
);
188 if (!dc
->w
.charExtra
&& !dc
->w
.breakExtra
&& !lpDx
)
190 if (!pfo
->lf
.lfOrientation
) /* angled baseline? */
192 TSXDrawString( display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
193 dc
->w
.DCOrgX
+ x
, dc
->w
.DCOrgY
+ y
, str
, count
);
197 /* have to render character by character. */
200 /* tenths of degrees to radians */
201 double theta
= M_PI
*pfo
->lf
.lfOrientation
/1800.;
202 /* components of pointsize matrix */
203 double xc
= pfo
->fi
->lfd_decipoints
*cos(theta
)/10.;
204 double yc
= pfo
->fi
->lfd_decipoints
*sin(theta
)/10.;
206 for(i
=0; i
<count
; i
++) {
207 int char_metric_offset
= (unsigned char) str
[i
]
208 - font
->min_char_or_byte2
;
209 int x_i
= IROUND((double) (dc
->w
.DCOrgX
+ x
) + offset
*xc
/1000. );
210 int y_i
= IROUND((double) (dc
->w
.DCOrgY
+ y
) - offset
*yc
/1000. );
212 TSXDrawString( display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
213 x_i
, y_i
, &str
[i
], 1);
214 offset
+= (double) (font
->per_char
?
215 font
->per_char
[char_metric_offset
].attributes
:
216 font
->min_bounds
.attributes
);
220 else /* Now the fun begins... */
222 XTextItem
*items
, *pitem
;
225 /* allocate max items */
227 pitem
= items
= HEAP_xalloc( GetProcessHeap(), 0,
228 count
* sizeof(XTextItem
) );
230 if( lpDx
) /* explicit character widths */
232 int extra
= dc
->wndExtX
/ 2;
236 /* initialize text item with accumulated delta */
238 pitem
->chars
= (char *)str
+ i
;
239 pitem
->delta
= delta
;
244 /* add characters to the same XTextItem until new delta
245 * becomes non-zero */
249 delta
+= (lpDx
[i
] * dc
->vportExtX
+ extra
) / dc
->wndExtX
250 - TSXTextWidth( font
, str
+ i
, 1);
252 } while ((++i
< count
) && !delta
);
256 else /* charExtra or breakExtra */
260 pitem
->chars
= (char *)str
+ i
;
261 pitem
->delta
= delta
;
268 delta
+= dc
->w
.charExtra
;
269 if (str
[i
] == (char)dfBreakChar
) delta
+= dc
->w
.breakExtra
;
271 } while ((++i
< count
) && !delta
);
276 TSXDrawText( display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
277 dc
->w
.DCOrgX
+ x
, dc
->w
.DCOrgY
+ y
, items
, pitem
- items
);
278 HeapFree( GetProcessHeap(), 0, items
);
281 /* Draw underline and strike-out if needed */
285 long linePos
, lineWidth
;
287 if (!TSXGetFontProperty( font
, XA_UNDERLINE_POSITION
, &linePos
))
288 linePos
= font
->descent
-1;
289 if (!TSXGetFontProperty( font
, XA_UNDERLINE_THICKNESS
, &lineWidth
))
291 else if (lineWidth
== 1) lineWidth
= 0;
292 TSXSetLineAttributes( display
, dc
->u
.x
.gc
, lineWidth
,
293 LineSolid
, CapRound
, JoinBevel
);
294 TSXDrawLine( display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
295 dc
->w
.DCOrgX
+ x
, dc
->w
.DCOrgY
+ y
+ linePos
,
296 dc
->w
.DCOrgX
+ x
+ info
.width
, dc
->w
.DCOrgY
+ y
+ linePos
);
300 long lineAscent
, lineDescent
;
301 if (!TSXGetFontProperty( font
, XA_STRIKEOUT_ASCENT
, &lineAscent
))
302 lineAscent
= font
->ascent
/ 2;
303 if (!TSXGetFontProperty( font
, XA_STRIKEOUT_DESCENT
, &lineDescent
))
304 lineDescent
= -lineAscent
* 2 / 3;
305 TSXSetLineAttributes( display
, dc
->u
.x
.gc
, lineAscent
+ lineDescent
,
306 LineSolid
, CapRound
, JoinBevel
);
307 TSXDrawLine( display
, dc
->u
.x
.drawable
, dc
->u
.x
.gc
,
308 dc
->w
.DCOrgX
+ x
, dc
->w
.DCOrgY
+ y
- lineAscent
,
309 dc
->w
.DCOrgX
+ x
+ info
.width
, dc
->w
.DCOrgY
+ y
- lineAscent
);
312 if (flags
& ETO_CLIPPED
)
314 SelectClipRgn32( dc
->hSelf
, hRgnClip
);
315 DeleteObject32( hRgnClip
);