Fixed error handling in DGA_IDirectDraw2Impl_GetCaps().
[wine] / graphics / metafiledrv / text.c
1 /*
2  * metafile driver text functions
3  *
4  * Copyright 1993, 1994 Alexandre Julliard
5  *
6  */
7
8 #include "windef.h"
9 #include "metafiledrv.h"
10 #include "debug.h"
11 #include "heap.h"
12
13 DEFAULT_DEBUG_CHANNEL(metafile)
14
15
16 /******************************************************************
17  *         MFDRV_MetaExtTextOut
18  */
19 static BOOL MFDRV_MetaExtTextOut(DC*dc, short x, short y, UINT16 flags,
20                                  const RECT16 *rect, LPCSTR str, short count,
21                                  const INT16 *lpDx)
22 {
23     BOOL ret;
24     DWORD len;
25     METARECORD *mr;
26     
27     if((!flags && rect) || (flags && !rect))
28         WARN(metafile, "Inconsistent flags and rect\n");
29     len = sizeof(METARECORD) + (((count + 1) >> 1) * 2) + 2 * sizeof(short)
30             + sizeof(UINT16);
31     if(rect)
32         len += sizeof(RECT16);
33     if (lpDx)
34      len+=count*sizeof(INT16);
35     if (!(mr = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, len)))
36         return FALSE;
37
38     mr->rdSize = len / 2;
39     mr->rdFunction = META_EXTTEXTOUT;
40     *(mr->rdParm) = y;
41     *(mr->rdParm + 1) = x;
42     *(mr->rdParm + 2) = count;
43     *(mr->rdParm + 3) = flags;
44     if (rect) memcpy(mr->rdParm + 4, rect, sizeof(RECT16));
45     memcpy(mr->rdParm + (rect ? 8 : 4), str, count);
46     if (lpDx)
47      memcpy(mr->rdParm + (rect ? 8 : 4) + ((count + 1) >> 1),lpDx,
48       count*sizeof(INT16));
49     ret = MFDRV_WriteRecord( dc, mr, mr->rdSize * 2);
50     HeapFree( SystemHeap, 0, mr);
51     return ret;
52 }
53
54
55
56 /***********************************************************************
57  *           MFDRV_ExtTextOut
58  */
59 BOOL
60 MFDRV_ExtTextOut( DC *dc, INT x, INT y, UINT flags,
61                   const RECT *lprect, LPCSTR str, UINT count,
62                   const INT *lpDx )
63 {
64     RECT16      rect16;
65     LPINT16     lpdx16 = NULL;
66     BOOL        ret;
67     int         i;
68
69     if(lpDx)
70         lpdx16 = HeapAlloc( SystemHeap, 0, sizeof(INT16)*count );
71     if (lprect) CONV_RECT32TO16(lprect,&rect16);
72     if (lpdx16)
73         for (i=count;i--;)
74             lpdx16[i]=lpDx[i];
75     ret = MFDRV_MetaExtTextOut(dc,x,y,flags,lprect?&rect16:NULL,str,count,
76                                lpdx16);
77     if (lpdx16) HeapFree( SystemHeap, 0, lpdx16 );
78     return ret;
79 }
80
81
82