Fixed error handling in DGA_IDirectDraw2Impl_GetCaps().
[wine] / graphics / psdrv / text.c
1 /*
2  *      PostScript driver text functions
3  *
4  *      Copyright 1998  Huw D M Davies
5  *
6  */
7 #include <string.h>
8 #include "psdrv.h"
9 #include "debug.h"
10 #include "winspool.h"
11
12 DEFAULT_DEBUG_CHANNEL(psdrv)
13
14 /***********************************************************************
15  *           PSDRV_ExtTextOut
16  */
17 BOOL PSDRV_ExtTextOut( DC *dc, INT x, INT y, UINT flags,
18                    const RECT *lprect, LPCSTR str, UINT count,
19                    const INT *lpDx )
20 {
21     PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
22     char *strbuf;
23     SIZE sz;
24
25     TRACE(psdrv, "(x=%d, y=%d, flags=0x%08x, str='%.*s', count=%d)\n", x, y,
26           flags, (int)count, str, count);
27
28     strbuf = (char *)HeapAlloc( PSDRV_Heap, 0, count + 1);
29     if(!strbuf) {
30         WARN(psdrv, "HeapAlloc failed\n");
31         return FALSE;
32     }
33
34     if(dc->w.textAlign & TA_UPDATECP) {
35         x = dc->w.CursPosX;
36         y = dc->w.CursPosY;
37     }
38
39     x = XLPTODP(dc, x);
40     y = YLPTODP(dc, y);
41
42     GetTextExtentPoint32A(dc->hSelf, str, count, &sz);
43     sz.cx = XLSTODS(dc, sz.cx);
44     sz.cy = YLSTODS(dc, sz.cy);
45
46     switch(dc->w.textAlign & (TA_LEFT | TA_CENTER | TA_RIGHT) ) {
47     case TA_LEFT:
48         if(dc->w.textAlign & TA_UPDATECP)
49             dc->w.CursPosX = XDPTOLP(dc, x + sz.cx);
50         break;
51
52     case TA_CENTER:
53         x -= sz.cx/2;
54         break;
55
56     case TA_RIGHT:
57         x -= sz.cx;
58         if(dc->w.textAlign & TA_UPDATECP)
59             dc->w.CursPosX = XDPTOLP(dc, x);
60         break;
61     }
62
63     switch(dc->w.textAlign & (TA_TOP | TA_BASELINE | TA_BOTTOM) ) {
64     case TA_TOP:
65         y += physDev->font.tm.tmAscent;
66         break;
67
68     case TA_BASELINE:
69         break;
70
71     case TA_BOTTOM:
72         y -= physDev->font.tm.tmDescent;
73         break;
74     }
75
76     memcpy(strbuf, str, count);
77     *(strbuf + count) = '\0';
78     
79     PSDRV_SetFont(dc);
80
81     PSDRV_WriteMoveTo(dc, x, y);
82     PSDRV_WriteShow(dc, strbuf, strlen(strbuf));
83
84     HeapFree(PSDRV_Heap, 0, strbuf);
85     return TRUE;
86 }