text.c 4.35 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4 5
/*
 * metafile driver text functions
 *
 * Copyright 1993, 1994 Alexandre Julliard
 *
6 7 8 9 10 11 12 13 14 15 16 17
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
Alexandre Julliard's avatar
Alexandre Julliard committed
19 20
 */

21
#include <stdarg.h>
22 23
#include <string.h>

24
#include "windef.h"
25
#include "winbase.h"
26
#include "wine/wingdi16.h"
27
#include "mfdrv/metafiledrv.h"
28
#include "wine/debug.h"
29

30
WINE_DEFAULT_DEBUG_CHANNEL(metafile);
31

32 33 34 35

/******************************************************************
 *         MFDRV_MetaExtTextOut
 */
36
static BOOL MFDRV_MetaExtTextOut( PHYSDEV dev, short x, short y, UINT16 flags,
37 38 39 40 41 42
				 const RECT16 *rect, LPCSTR str, short count,
				 const INT16 *lpDx)
{
    BOOL ret;
    DWORD len;
    METARECORD *mr;
43
    BOOL isrect = flags & (ETO_CLIPPED | ETO_OPAQUE);
44

45 46
    len = sizeof(METARECORD) + (((count + 1) >> 1) * 2) + 2 * sizeof(short)
	    + sizeof(UINT16);
47
    if (isrect)
48 49 50
        len += sizeof(RECT16);
    if (lpDx)
     len+=count*sizeof(INT16);
51
    if (!(mr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len)))
52 53 54 55 56 57 58 59
	return FALSE;

    mr->rdSize = len / 2;
    mr->rdFunction = META_EXTTEXTOUT;
    *(mr->rdParm) = y;
    *(mr->rdParm + 1) = x;
    *(mr->rdParm + 2) = count;
    *(mr->rdParm + 3) = flags;
60 61
    if (isrect) memcpy(mr->rdParm + 4, rect, sizeof(RECT16));
    memcpy(mr->rdParm + (isrect ? 8 : 4), str, count);
62
    if (lpDx)
63
     memcpy(mr->rdParm + (isrect ? 8 : 4) + ((count + 1) >> 1),lpDx,
64
      count*sizeof(INT16));
65
    ret = MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
66
    HeapFree( GetProcessHeap(), 0, mr);
67 68 69
    return ret;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
70 71 72 73 74


/***********************************************************************
 *           MFDRV_ExtTextOut
 */
75 76
BOOL MFDRV_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags,
                       const RECT *lprect, LPCWSTR str, UINT count, const INT *lpDx )
Alexandre Julliard's avatar
Alexandre Julliard committed
77 78
{
    RECT16	rect16;
79
    LPINT16	lpdx16 = NULL;
80
    BOOL	ret;
81
    unsigned int i, j;
82
    LPSTR       ascii;
83
    DWORD len;
84
    CHARSETINFO csi;
85
    int charset = GetTextCharset( dev->hdc );
86 87
    UINT cp = CP_ACP;

88
    if(TranslateCharsetInfo(ULongToPtr(charset), &csi, TCI_SRCCHARSET))
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        cp = csi.ciACP;
    else {
        switch(charset) {
	case OEM_CHARSET:
	    cp = GetOEMCP();
	    break;
	case DEFAULT_CHARSET:
	    cp = GetACP();
	    break;

	case VISCII_CHARSET:
	case TCVN_CHARSET:
	case KOI8_CHARSET:
	case ISO3_CHARSET:
	case ISO4_CHARSET:
	case ISO10_CHARSET:
	case CELTIC_CHARSET:
	  /* FIXME: These have no place here, but because x11drv
	     enumerates fonts with these (made up) charsets some apps
	     might use them and then the FIXME below would become
	     annoying.  Now we could pick the intended codepage for
	     each of these, but since it's broken anyway we'll just
	     use CP_ACP and hope it'll go away...
	  */
	    cp = CP_ACP;
	    break;


	default:
	    FIXME("Can't find codepage for charset %d\n", charset);
	    break;
	}
    }


    TRACE("cp == %d\n", cp);
125 126 127
    len = WideCharToMultiByte(cp, 0, str, count, NULL, 0, NULL, NULL);
    ascii = HeapAlloc(GetProcessHeap(), 0, len);
    WideCharToMultiByte(cp, 0, str, count, ascii, len, NULL, NULL);
128 129
    TRACE("mapped %s -> %s\n", debugstr_wn(str, count), debugstr_an(ascii, len));

Alexandre Julliard's avatar
Alexandre Julliard committed
130

131 132 133 134 135 136 137
    if (lprect)
    {
        rect16.left   = lprect->left;
        rect16.top    = lprect->top;
        rect16.right  = lprect->right;
        rect16.bottom = lprect->bottom;
    }
138 139 140 141 142 143 144 145 146 147 148

    if(lpDx) {
        lpdx16 = HeapAlloc( GetProcessHeap(), 0, sizeof(INT16)*len );
	for(i = j = 0; i < len; )
	    if(IsDBCSLeadByteEx(cp, ascii[i])) {
	        lpdx16[i++] = lpDx[j++];
		lpdx16[i++] = 0;
	    } else
	        lpdx16[i++] = lpDx[j++];
    }

149
    ret = MFDRV_MetaExtTextOut(dev,x,y,flags,lprect?&rect16:NULL,ascii,len,lpdx16);
150
    HeapFree( GetProcessHeap(), 0, ascii );
151
    HeapFree( GetProcessHeap(), 0, lpdx16 );
Alexandre Julliard's avatar
Alexandre Julliard committed
152 153
    return ret;
}