fdopen: don't rewind the file after creating the FILE* handle. Added
[wine] / dlls / gdi / win16drv / text.c
1 /*
2  * win16 driver text functions
3  *
4  * Copyright 1996 John Harvey
5  *           1998 Huw Davies
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdlib.h>
23 #include "win16drv/win16drv.h"
24 #include "gdi.h"
25 #include "wine/debug.h"
26 #include "winbase.h"
27 #include "winnls.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(win16drv);
30
31 /***********************************************************************
32  *           WIN16DRV_ExtTextOut
33  */
34 BOOL WIN16DRV_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags,
35                            const RECT *lprect, LPCWSTR wstr, UINT count,
36                            const INT *lpDx )
37 {
38     WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
39     DC *dc = physDev->dc;
40     BOOL bRet = 1;
41     RECT16       clipRect;
42     RECT16       opaqueRect;
43     RECT16      *lpOpaqueRect = NULL;
44     WORD wOptions = 0;
45     DWORD len;
46     POINT pt;
47     INT16 width;
48     char *str;
49     DWORD dwRet;
50
51     if (count == 0)
52         return FALSE;
53
54     TRACE("%p %d %d %x %p %s %p\n",
55           dc->hSelf, x, y, flags, lprect, debugstr_wn(wstr, count), lpDx);
56
57     len = WideCharToMultiByte( CP_ACP, 0, wstr, count, NULL, 0, NULL, NULL );
58     str = HeapAlloc( GetProcessHeap(), 0, len );
59     WideCharToMultiByte( CP_ACP, 0, wstr, count, str, len, NULL, NULL );
60
61     clipRect.left = 0;
62     clipRect.top = 0;
63
64     clipRect.right = physDev->DevCaps.horzRes;
65     clipRect.bottom = physDev->DevCaps.vertRes;
66     if (lprect) {
67         opaqueRect.left = lprect->left;
68         opaqueRect.top = lprect->top;
69         opaqueRect.right = lprect->right;
70         opaqueRect.bottom = lprect->bottom;
71         lpOpaqueRect = &opaqueRect;
72     }
73
74     TRACE("textalign = %d\n", dc->textAlign);
75
76     if (dc->textAlign & TA_UPDATECP) {
77         x = dc->CursPosX;
78         y = dc->CursPosY;
79     }
80
81     pt.x = x;
82     pt.y = y;
83     LPtoDP( physDev->hdc, &pt, 1 );
84     x = pt.x;
85     y = pt.y;
86
87     dwRet = PRTDRV_ExtTextOut(physDev->segptrPDEVICE, 0, 0,
88                               NULL, str, -len,  physDev->FontInfo,
89                               win16drv_SegPtr_DrawMode,
90                               win16drv_SegPtr_TextXForm,
91                               NULL, NULL, 0);
92
93     width = LOWORD(dwRet);
94
95     switch( dc->textAlign & (TA_LEFT | TA_RIGHT | TA_CENTER) ) {
96     case TA_LEFT:
97         if (dc->textAlign & TA_UPDATECP)
98         {
99             pt.x = x + width;
100             pt.y = y;
101             DPtoLP( physDev->hdc, &pt, 1 );
102             dc->CursPosX = pt.x;
103         }
104         break;
105     case TA_RIGHT:
106         x -= width;
107         if (dc->textAlign & TA_UPDATECP)
108         {
109             pt.x = x;
110             pt.y = y;
111             DPtoLP( physDev->hdc, &pt, 1 );
112             dc->CursPosX = pt.x;
113         }
114         break;
115     case TA_CENTER:
116         x -= width / 2;
117         break;
118     }
119
120     switch( dc->textAlign & (TA_TOP | TA_BOTTOM | TA_BASELINE) ) {
121     case TA_TOP:
122         break;
123     case TA_BOTTOM:
124         y -= physDev->FontInfo->dfPixHeight;
125         break;
126     case TA_BASELINE:
127         y -= physDev->FontInfo->dfAscent;
128         break;
129     }
130
131     dwRet = PRTDRV_ExtTextOut(physDev->segptrPDEVICE,
132                               x, y, &clipRect, str, (WORD)len,
133                               physDev->FontInfo, win16drv_SegPtr_DrawMode,
134                               win16drv_SegPtr_TextXForm, NULL, lpOpaqueRect,
135                               wOptions);
136
137     HeapFree( GetProcessHeap(), 0, str );
138     return bRet;
139 }