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,
51 XChar2b *str2b = NULL;
52 BOOL dibUpdateFlag = FALSE;
54 HRGN saved_region = 0;
56 if(physDev->has_gdi_font)
57 return X11DRV_XRender_ExtTextOut(physDev, x, y, flags, lprect, wstr, count, lpDx);
59 if (!X11DRV_SetupGCForText( physDev )) return TRUE;
61 pfo = XFONT_GetFontObject( physDev->font );
64 if (pfo->lf.lfEscapement && pfo->lpX11Trans)
67 TRACE("hdc=%p df=%04x %d,%d %s, %d flags=%d lpDx=%p\n",
68 physDev->hdc, (UINT16)(physDev->font), x, y,
69 debugstr_wn (wstr, count), count, flags, lpDx);
71 if (lprect != NULL) TRACE("\trect=(%ld,%ld - %ld,%ld)\n",
72 lprect->left, lprect->top,
73 lprect->right, lprect->bottom );
75 /* Draw the rectangle */
77 if (flags & ETO_OPAQUE)
79 X11DRV_LockDIBSection( physDev, DIB_Status_GdiMod, FALSE );
82 XSetForeground( gdi_display, physDev->gc, physDev->backgroundPixel );
83 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
84 physDev->org.x + lprect->left, physDev->org.y + lprect->top,
85 lprect->right - lprect->left, lprect->bottom - lprect->top );
88 if (!count) goto END; /* Nothing more to do */
91 /* Set the clip region */
93 if (flags & ETO_CLIPPED)
97 clip_region = CreateRectRgnIndirect( lprect );
98 /* make a copy of the current device region */
99 saved_region = CreateRectRgn( 0, 0, 0, 0 );
100 CombineRgn( saved_region, physDev->region, 0, RGN_COPY );
101 X11DRV_SetDeviceClipping( physDev, saved_region, clip_region );
102 DeleteObject( clip_region );
105 /* Draw the text background if necessary */
109 X11DRV_LockDIBSection( physDev, DIB_Status_GdiMod, FALSE );
110 dibUpdateFlag = TRUE;
114 /* Draw the text (count > 0 verified) */
115 if (!(str2b = X11DRV_cptable[pfo->fi->cptable].punicode_to_char2b( pfo, wstr, count )))
119 XSetForeground( gdi_display, physDev->gc, physDev->textPixel );
125 X11DRV_cptable[pfo->fi->cptable].pDrawString(
126 pfo, gdi_display, physDev->drawable, physDev->gc,
127 physDev->org.x + x, physDev->org.y + y, str2b, count );
131 XTextItem16 *items, *pitem;
133 pitem = items = HeapAlloc( GetProcessHeap(), 0,
134 count * sizeof(XTextItem16) );
135 if(items == NULL) goto FAIL;
137 for(i = 0; i < count; i++)
139 pitem->chars = str2b + i;
140 pitem->delta = lpDx[i];
146 X11DRV_cptable[pfo->fi->cptable].pDrawText( pfo, gdi_display,
147 physDev->drawable, physDev->gc,
148 physDev->org.x + x, physDev->org.y + y, items, pitem - items );
149 HeapFree( GetProcessHeap(), 0, items );
154 /* have to render character by character. */
158 for (i=0; i<count; i++)
160 int char_metric_offset = str2b[i].byte2 + (str2b[i].byte1 << 8)
161 - font->min_char_or_byte2;
162 int x_i = IROUND((double) (physDev->org.x + x) + offset *
163 pfo->lpX11Trans->a / pfo->lpX11Trans->pixelsize );
164 int y_i = IROUND((double) (physDev->org.y + y) - offset *
165 pfo->lpX11Trans->b / pfo->lpX11Trans->pixelsize );
167 X11DRV_cptable[pfo->fi->cptable].pDrawString(
168 pfo, gdi_display, physDev->drawable, physDev->gc,
169 x_i, y_i, &str2b[i], 1);
176 offset += (double) (font->per_char ?
177 font->per_char[char_metric_offset].attributes:
178 font->min_bounds.attributes)
179 * pfo->lpX11Trans->pixelsize / 1000.0;
183 HeapFree( GetProcessHeap(), 0, str2b );
185 if (flags & ETO_CLIPPED)
187 /* restore the device region */
188 X11DRV_SetDeviceClipping( physDev, saved_region, 0 );
189 DeleteObject( saved_region );
194 HeapFree( GetProcessHeap(), 0, str2b );
198 if (dibUpdateFlag) X11DRV_UnlockDIBSection( physDev, TRUE );
203 /***********************************************************************
204 * X11DRV_GetTextExtentPoint
206 BOOL X11DRV_GetTextExtentPoint( X11DRV_PDEVICE *physDev, LPCWSTR str, INT count,
209 fontObject* pfo = XFONT_GetFontObject( physDev->font );
211 TRACE("%s %d\n", debugstr_wn(str,count), count);
213 XChar2b *p = X11DRV_cptable[pfo->fi->cptable].punicode_to_char2b( pfo, str, count );
214 if (!p) return FALSE;
215 if( !pfo->lpX11Trans ) {
216 int dir, ascent, descent;
218 X11DRV_cptable[pfo->fi->cptable].pTextExtents( pfo, p,
219 count, &dir, &ascent, &descent, &info_width );
221 size->cx = info_width;
222 size->cy = pfo->fs->ascent + pfo->fs->descent;
225 float x = 0.0, y = 0.0;
226 /* FIXME: Deal with *_char_or_byte2 != 0 situations */
227 for(i = 0; i < count; i++) {
228 x += pfo->fs->per_char ?
229 pfo->fs->per_char[p[i].byte2 - pfo->fs->min_char_or_byte2].attributes :
230 pfo->fs->min_bounds.attributes;
232 y = pfo->lpX11Trans->RAW_ASCENT + pfo->lpX11Trans->RAW_DESCENT;
233 TRACE("x = %f y = %f\n", x, y);
234 size->cx = x * pfo->lpX11Trans->pixelsize / 1000.0;
235 size->cy = y * pfo->lpX11Trans->pixelsize / 1000.0;
237 size->cx *= pfo->rescale;
238 size->cy *= pfo->rescale;
239 HeapFree( GetProcessHeap(), 0, p );