wined3d: Print lastpixel state fixme only once.
[wine/hacks.git] / dlls / gdi32 / mfdrv / text.c
blob8154e391673c929275e2edc3e145435b84fc9745
1 /*
2 * metafile 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <string.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "mfdrv/metafiledrv.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(metafile);
32 /******************************************************************
33 * MFDRV_MetaExtTextOut
35 static BOOL MFDRV_MetaExtTextOut( PHYSDEV dev, short x, short y, UINT16 flags,
36 const RECT16 *rect, LPCSTR str, short count,
37 const INT16 *lpDx)
39 BOOL ret;
40 DWORD len;
41 METARECORD *mr;
42 BOOL isrect = flags & (ETO_CLIPPED | ETO_OPAQUE);
44 len = sizeof(METARECORD) + (((count + 1) >> 1) * 2) + 2 * sizeof(short)
45 + sizeof(UINT16);
46 if (isrect)
47 len += sizeof(RECT16);
48 if (lpDx)
49 len+=count*sizeof(INT16);
50 if (!(mr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len)))
51 return FALSE;
53 mr->rdSize = len / 2;
54 mr->rdFunction = META_EXTTEXTOUT;
55 *(mr->rdParm) = y;
56 *(mr->rdParm + 1) = x;
57 *(mr->rdParm + 2) = count;
58 *(mr->rdParm + 3) = flags;
59 if (isrect) memcpy(mr->rdParm + 4, rect, sizeof(RECT16));
60 memcpy(mr->rdParm + (isrect ? 8 : 4), str, count);
61 if (lpDx)
62 memcpy(mr->rdParm + (isrect ? 8 : 4) + ((count + 1) >> 1),lpDx,
63 count*sizeof(INT16));
64 ret = MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
65 HeapFree( GetProcessHeap(), 0, mr);
66 return ret;
71 /***********************************************************************
72 * MFDRV_ExtTextOut
74 BOOL
75 MFDRV_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags,
76 const RECT *lprect, LPCWSTR str, UINT count,
77 const INT *lpDx )
79 RECT16 rect16;
80 LPINT16 lpdx16 = NULL;
81 BOOL ret;
82 unsigned int i, j;
83 LPSTR ascii;
84 DWORD len;
85 CHARSETINFO csi;
86 METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
87 int charset = GetTextCharset(physDev->hdc);
88 UINT cp = CP_ACP;
90 if(TranslateCharsetInfo((DWORD*)charset, &csi, TCI_SRCCHARSET))
91 cp = csi.ciACP;
92 else {
93 switch(charset) {
94 case OEM_CHARSET:
95 cp = GetOEMCP();
96 break;
97 case DEFAULT_CHARSET:
98 cp = GetACP();
99 break;
101 case VISCII_CHARSET:
102 case TCVN_CHARSET:
103 case KOI8_CHARSET:
104 case ISO3_CHARSET:
105 case ISO4_CHARSET:
106 case ISO10_CHARSET:
107 case CELTIC_CHARSET:
108 /* FIXME: These have no place here, but because x11drv
109 enumerates fonts with these (made up) charsets some apps
110 might use them and then the FIXME below would become
111 annoying. Now we could pick the intended codepage for
112 each of these, but since it's broken anyway we'll just
113 use CP_ACP and hope it'll go away...
115 cp = CP_ACP;
116 break;
119 default:
120 FIXME("Can't find codepage for charset %d\n", charset);
121 break;
126 TRACE("cp == %d\n", cp);
127 len = WideCharToMultiByte(cp, 0, str, count, NULL, 0, NULL, NULL);
128 ascii = HeapAlloc(GetProcessHeap(), 0, len);
129 WideCharToMultiByte(cp, 0, str, count, ascii, len, NULL, NULL);
130 TRACE("mapped %s -> %s\n", debugstr_wn(str, count), debugstr_an(ascii, len));
133 if (lprect)
135 rect16.left = lprect->left;
136 rect16.top = lprect->top;
137 rect16.right = lprect->right;
138 rect16.bottom = lprect->bottom;
141 if(lpDx) {
142 lpdx16 = HeapAlloc( GetProcessHeap(), 0, sizeof(INT16)*len );
143 for(i = j = 0; i < len; )
144 if(IsDBCSLeadByteEx(cp, ascii[i])) {
145 lpdx16[i++] = lpDx[j++];
146 lpdx16[i++] = 0;
147 } else
148 lpdx16[i++] = lpDx[j++];
151 ret = MFDRV_MetaExtTextOut(dev,x,y,flags,lprect?&rect16:NULL,ascii,len,lpdx16);
152 HeapFree( GetProcessHeap(), 0, ascii );
153 HeapFree( GetProcessHeap(), 0, lpdx16 );
154 return ret;