2 * X11 graphics driver text functions
4 * Copyright 1993,1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(text);
35 #define SWAP_INT(a,b) { int t = a; a = b; b = t; }
36 #define IROUND(x) (int)((x)>0? (x)+0.5 : (x) - 0.5)
39 /***********************************************************************
43 X11DRV_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flags,
44 const RECT *lprect, LPCWSTR wstr, UINT count,
52 XChar2b *str2b = NULL;
53 BOOL dibUpdateFlag = FALSE;
55 HRGN saved_region = 0;
57 if(physDev->has_gdi_font)
58 return X11DRV_XRender_ExtTextOut(physDev, x, y, flags, lprect, wstr, count, lpDx);
60 if (!X11DRV_SetupGCForText( physDev )) return TRUE;
62 pfo = XFONT_GetFontObject( physDev->font );
65 if (pfo->lf.lfEscapement && pfo->lpX11Trans)
68 TRACE("hdc=%p df=%04x %d,%d %s, %d flags=%d lpDx=%p\n",
69 physDev->hdc, (UINT16)(physDev->font), x, y,
70 debugstr_wn (wstr, count), count, flags, lpDx);
72 if (lprect != NULL) TRACE("\trect=(%ld,%ld - %ld,%ld)\n",
73 lprect->left, lprect->top,
74 lprect->right, lprect->bottom );
76 /* Draw the rectangle */
78 if (flags & ETO_OPAQUE)
80 X11DRV_LockDIBSection( physDev, DIB_Status_GdiMod, FALSE );
83 XSetForeground( gdi_display, physDev->gc, physDev->backgroundPixel );
84 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
85 physDev->org.x + rect.left, physDev->org.y + rect.top,
86 rect.right-rect.left, rect.bottom-rect.top );
89 if (!count) goto END; /* Nothing more to do */
92 /* Set the clip region */
94 if (flags & ETO_CLIPPED)
98 clip_region = CreateRectRgnIndirect( lprect );
99 /* make a copy of the current device region */
100 saved_region = CreateRectRgn( 0, 0, 0, 0 );
101 CombineRgn( saved_region, physDev->region, 0, RGN_COPY );
102 X11DRV_SetDeviceClipping( physDev, saved_region, clip_region );
103 DeleteObject( clip_region );
106 /* Draw the text background if necessary */
110 X11DRV_LockDIBSection( physDev, DIB_Status_GdiMod, FALSE );
111 dibUpdateFlag = TRUE;
115 /* Draw the text (count > 0 verified) */
116 if (!(str2b = X11DRV_cptable[pfo->fi->cptable].punicode_to_char2b( pfo, wstr, count )))
120 XSetForeground( gdi_display, physDev->gc, physDev->textPixel );
126 X11DRV_cptable[pfo->fi->cptable].pDrawString(
127 pfo, gdi_display, physDev->drawable, physDev->gc,
128 physDev->org.x + x, physDev->org.y + y, str2b, count );
132 XTextItem16 *items, *pitem;
134 pitem = items = HeapAlloc( GetProcessHeap(), 0,
135 count * sizeof(XTextItem16) );
136 if(items == NULL) goto FAIL;
138 for(i = 0; i < count; i++)
140 pitem->chars = str2b + i;
141 pitem->delta = lpDx[i];
147 X11DRV_cptable[pfo->fi->cptable].pDrawText( pfo, gdi_display,
148 physDev->drawable, physDev->gc,
149 physDev->org.x + x, physDev->org.y + y, items, pitem - items );
150 HeapFree( GetProcessHeap(), 0, items );
155 /* have to render character by character. */
159 for (i=0; i<count; i++)
161 int char_metric_offset = str2b[i].byte2 + (str2b[i].byte1 << 8)
162 - font->min_char_or_byte2;
163 int x_i = IROUND((double) (physDev->org.x + x) + offset *
164 pfo->lpX11Trans->a / pfo->lpX11Trans->pixelsize );
165 int y_i = IROUND((double) (physDev->org.y + y) - offset *
166 pfo->lpX11Trans->b / pfo->lpX11Trans->pixelsize );
168 X11DRV_cptable[pfo->fi->cptable].pDrawString(
169 pfo, gdi_display, physDev->drawable, physDev->gc,
170 x_i, y_i, &str2b[i], 1);
177 offset += (double) (font->per_char ?
178 font->per_char[char_metric_offset].attributes:
179 font->min_bounds.attributes)
180 * pfo->lpX11Trans->pixelsize / 1000.0;
184 HeapFree( GetProcessHeap(), 0, str2b );
186 if (flags & ETO_CLIPPED)
188 /* restore the device region */
189 X11DRV_SetDeviceClipping( physDev, saved_region, 0 );
190 DeleteObject( saved_region );
195 HeapFree( GetProcessHeap(), 0, str2b );
199 if (dibUpdateFlag) X11DRV_UnlockDIBSection( physDev, TRUE );
204 /***********************************************************************
205 * X11DRV_GetTextExtentPoint
207 BOOL X11DRV_GetTextExtentPoint( X11DRV_PDEVICE *physDev, LPCWSTR str, INT count,
210 fontObject* pfo = XFONT_GetFontObject( physDev->font );
212 TRACE("%s %d\n", debugstr_wn(str,count), count);
214 XChar2b *p = X11DRV_cptable[pfo->fi->cptable].punicode_to_char2b( pfo, str, count );
215 if (!p) return FALSE;
216 if( !pfo->lpX11Trans ) {
217 int dir, ascent, descent;
219 X11DRV_cptable[pfo->fi->cptable].pTextExtents( pfo, p,
220 count, &dir, &ascent, &descent, &info_width );
222 size->cx = info_width;
223 size->cy = pfo->fs->ascent + pfo->fs->descent;
226 float x = 0.0, y = 0.0;
227 /* FIXME: Deal with *_char_or_byte2 != 0 situations */
228 for(i = 0; i < count; i++) {
229 x += pfo->fs->per_char ?
230 pfo->fs->per_char[p[i].byte2 - pfo->fs->min_char_or_byte2].attributes :
231 pfo->fs->min_bounds.attributes;
233 y = pfo->lpX11Trans->RAW_ASCENT + pfo->lpX11Trans->RAW_DESCENT;
234 TRACE("x = %f y = %f\n", x, y);
235 size->cx = x * pfo->lpX11Trans->pixelsize / 1000.0;
236 size->cy = y * pfo->lpX11Trans->pixelsize / 1000.0;
238 size->cx *= pfo->rescale;
239 size->cy *= pfo->rescale;
240 HeapFree( GetProcessHeap(), 0, p );