~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/winex11.drv/text.c

Version: ~ [ wine-1.5.30 ] ~ [ wine-1.5.29 ] ~ [ wine-1.5.28 ] ~ [ wine-1.5.27 ] ~ [ wine-1.5.26 ] ~ [ wine-1.5.25 ] ~ [ wine-1.5.24 ] ~ [ wine-1.5.23 ] ~ [ wine-1.5.22 ] ~ [ wine-1.5.21 ] ~ [ wine-1.5.20 ] ~ [ wine-1.5.19 ] ~ [ wine-1.5.18 ] ~ [ wine-1.5.17 ] ~ [ wine-1.5.16 ] ~ [ wine-1.5.15 ] ~ [ wine-1.5.14 ] ~ [ wine-1.5.13 ] ~ [ wine-1.5.12 ] ~ [ wine-1.5.11 ] ~ [ wine-1.5.10 ] ~ [ wine-1.5.9 ] ~ [ wine-1.5.8 ] ~ [ wine-1.5.7 ] ~ [ wine-1.4.1 ] ~ [ wine-1.5.6 ] ~ [ wine-1.5.5 ] ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * X11 graphics driver text functions
  3  *
  4  * Copyright 1993,1994 Alexandre Julliard
  5  *
  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.
 10  *
 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.
 15  *
 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #include "config.h"
 22 
 23 #include <stdarg.h>
 24 #include <stdlib.h>
 25 #include <math.h>
 26 
 27 #include "windef.h"
 28 #include "winbase.h"
 29 #include "x11font.h"
 30 #include "wine/debug.h"
 31 
 32 WINE_DEFAULT_DEBUG_CHANNEL(text);
 33 
 34 #define IROUND(x) (int)((x)>0? (x)+0.5 : (x) - 0.5)
 35 
 36 
 37 /***********************************************************************
 38  *           X11DRV_ExtTextOut
 39  */
 40 BOOL CDECL
 41 X11DRV_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flags,
 42                    const RECT *lprect, LPCWSTR wstr, UINT count,
 43                    const INT *lpDx )
 44 {
 45     unsigned int i;
 46     fontObject*         pfo;
 47     XFontStruct*        font;
 48     BOOL                rotated = FALSE;
 49     XChar2b             *str2b = NULL;
 50     BOOL                dibUpdateFlag = FALSE;
 51     BOOL                result = TRUE;
 52     HRGN                saved_region = 0;
 53 
 54     if(physDev->has_gdi_font)
 55         return X11DRV_XRender_ExtTextOut(physDev, x, y, flags, lprect, wstr, count, lpDx);
 56 
 57     if (!X11DRV_SetupGCForText( physDev )) return TRUE;
 58 
 59     pfo = XFONT_GetFontObject( physDev->font );
 60     font = pfo->fs;
 61 
 62     if (pfo->lf.lfEscapement && pfo->lpX11Trans)
 63         rotated = TRUE;
 64 
 65     TRACE("hdc=%p df=%04x %d,%d rc %s %s, %d  flags=%d lpDx=%p\n",
 66           physDev->hdc, (UINT16)physDev->font, x, y, wine_dbgstr_rect(lprect),
 67           debugstr_wn (wstr, count), count, flags, lpDx);
 68 
 69       /* Draw the rectangle */
 70 
 71     if (flags & ETO_OPAQUE)
 72     {
 73         X11DRV_LockDIBSection( physDev, DIB_Status_GdiMod );
 74         dibUpdateFlag = TRUE;
 75         wine_tsx11_lock();
 76         XSetForeground( gdi_display, physDev->gc, physDev->backgroundPixel );
 77         XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
 78                         physDev->dc_rect.left + lprect->left, physDev->dc_rect.top + lprect->top,
 79                         lprect->right - lprect->left, lprect->bottom - lprect->top );
 80         wine_tsx11_unlock();
 81     }
 82     if (!count) goto END;  /* Nothing more to do */
 83 
 84 
 85       /* Set the clip region */
 86 
 87     if (flags & ETO_CLIPPED)
 88     {
 89         HRGN clip_region;
 90 
 91         clip_region = CreateRectRgnIndirect( lprect );
 92         /* make a copy of the current device region */
 93         saved_region = CreateRectRgn( 0, 0, 0, 0 );
 94         CombineRgn( saved_region, physDev->region, 0, RGN_COPY );
 95         X11DRV_SetDeviceClipping( physDev, saved_region, clip_region );
 96         DeleteObject( clip_region );
 97     }
 98 
 99       /* Draw the text background if necessary */
100 
101     if (!dibUpdateFlag)
102     {
103         X11DRV_LockDIBSection( physDev, DIB_Status_GdiMod );
104         dibUpdateFlag = TRUE;
105     }
106 
107 
108     /* Draw the text (count > 0 verified) */
109     if (!(str2b = X11DRV_cptable[pfo->fi->cptable].punicode_to_char2b( pfo, wstr, count )))
110         goto FAIL;
111 
112     wine_tsx11_lock();
113     XSetForeground( gdi_display, physDev->gc, physDev->textPixel );
114     wine_tsx11_unlock();
115     if(!rotated)
116     {
117         if (!lpDx)
118         {
119             X11DRV_cptable[pfo->fi->cptable].pDrawString(
120                            pfo, gdi_display, physDev->drawable, physDev->gc,
121                            physDev->dc_rect.left + x, physDev->dc_rect.top + y, str2b, count );
122         }
123         else
124         {
125             XTextItem16 *items;
126 
127             items = HeapAlloc( GetProcessHeap(), 0, count * sizeof(XTextItem16) );
128             if(items == NULL) goto FAIL;
129 
130             items[0].chars = str2b;
131             items[0].delta = 0;
132             items[0].nchars = 1;
133             items[0].font = None;
134             for(i = 1; i < count; i++)
135             {
136                 items[i].chars  = str2b + i;
137                 items[i].delta  = (flags & ETO_PDY) ? lpDx[(i - 1) * 2] : lpDx[i - 1];
138                 items[i].delta -= X11DRV_cptable[pfo->fi->cptable].pTextWidth( pfo, str2b + i - 1, 1 );
139                 items[i].nchars = 1;
140                 items[i].font   = None;
141             }
142             X11DRV_cptable[pfo->fi->cptable].pDrawText( pfo, gdi_display,
143                                   physDev->drawable, physDev->gc,
144                                   physDev->dc_rect.left + x, physDev->dc_rect.top + y, items, count );
145             HeapFree( GetProcessHeap(), 0, items );
146         }
147     }
148     else /* rotated */
149     {
150         /* have to render character by character. */
151         double offset = 0.0;
152         UINT i;
153 
154         for (i=0; i<count; i++)
155         {
156             int char_metric_offset = str2b[i].byte2 + (str2b[i].byte1 << 8)
157                 - font->min_char_or_byte2;
158             int x_i = IROUND((double) (physDev->dc_rect.left + x) + offset *
159                              pfo->lpX11Trans->a / pfo->lpX11Trans->pixelsize );
160             int y_i = IROUND((double) (physDev->dc_rect.top + y) - offset *
161                              pfo->lpX11Trans->b / pfo->lpX11Trans->pixelsize );
162 
163             X11DRV_cptable[pfo->fi->cptable].pDrawString(
164                                     pfo, gdi_display, physDev->drawable, physDev->gc,
165                                     x_i, y_i, &str2b[i], 1);
166             if (lpDx)
167             {
168                 offset += (flags & ETO_PDY) ? lpDx[i * 2] : lpDx[i];
169             }
170             else
171             {
172                 offset += (double) (font->per_char ?
173                                     font->per_char[char_metric_offset].attributes:
174                                     font->min_bounds.attributes)
175                     * pfo->lpX11Trans->pixelsize / 1000.0;
176             }
177         }
178     }
179     HeapFree( GetProcessHeap(), 0, str2b );
180 
181     if (flags & ETO_CLIPPED)
182     {
183         /* restore the device region */
184         X11DRV_SetDeviceClipping( physDev, saved_region, 0 );
185         DeleteObject( saved_region );
186     }
187     goto END;
188 
189 FAIL:
190     HeapFree( GetProcessHeap(), 0, str2b );
191     result = FALSE;
192 
193 END:
194     if (dibUpdateFlag) X11DRV_UnlockDIBSection( physDev, TRUE );
195     return result;
196 }
197 
198 
199 /***********************************************************************
200  *           X11DRV_GetTextExtentExPoint
201  */
202 BOOL CDECL X11DRV_GetTextExtentExPoint( X11DRV_PDEVICE *physDev, LPCWSTR str, INT count,
203                                         INT maxExt, LPINT lpnFit, LPINT alpDx, LPSIZE size )
204 {
205     fontObject* pfo = XFONT_GetFontObject( physDev->font );
206 
207     TRACE("%s %d\n", debugstr_wn(str,count), count);
208     if( pfo ) {
209         XChar2b *p = X11DRV_cptable[pfo->fi->cptable].punicode_to_char2b( pfo, str, count );
210         if (!p) return FALSE;
211         if( !pfo->lpX11Trans ) {
212             int dir, ascent, descent;
213             int info_width;
214             X11DRV_cptable[pfo->fi->cptable].pTextExtents( pfo, p,
215                                 count, &dir, &ascent, &descent, &info_width,
216                                 maxExt, lpnFit, alpDx );
217 
218           size->cx = info_width;
219           size->cy = pfo->fs->ascent + pfo->fs->descent;
220         } else {
221             INT i;
222             INT nfit = 0;
223             float x = 0.0, y = 0.0;
224             float scaled_x = 0.0, pixsize = pfo->lpX11Trans->pixelsize;
225             /* FIXME: Deal with *_char_or_byte2 != 0 situations */
226             for(i = 0; i < count; i++) {
227                 x += pfo->fs->per_char ?
228            pfo->fs->per_char[p[i].byte2 - pfo->fs->min_char_or_byte2].attributes :
229            pfo->fs->min_bounds.attributes;
230                 scaled_x = x * pixsize / 1000.0;
231                 if (alpDx)
232                     alpDx[i] = scaled_x;
233                 if (scaled_x <= maxExt)
234                     ++nfit;
235             }
236             y = pfo->lpX11Trans->RAW_ASCENT + pfo->lpX11Trans->RAW_DESCENT;
237             TRACE("x = %f y = %f\n", x, y);
238             size->cx = x * pfo->lpX11Trans->pixelsize / 1000.0;
239             size->cy = y * pfo->lpX11Trans->pixelsize / 1000.0;
240             if (lpnFit)
241                 *lpnFit = nfit;
242         }
243         size->cx *= pfo->rescale;
244         size->cy *= pfo->rescale;
245         HeapFree( GetProcessHeap(), 0, p );
246         return TRUE;
247     }
248     return FALSE;
249 }
250 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.