Fixed crashes with WM_GETDLGCODE translation.
[wine/testsucceed.git] / graphics / psdrv / text.c
bloba8207b76448b26ab7b7cda33f2b5d3a2bcf0b2b8
1 /*
2 * PostScript driver text functions
4 * Copyright 1998 Huw D M Davies
6 */
7 #include <string.h>
8 #include "windows.h"
9 #include "psdrv.h"
10 #include "debug.h"
11 #include "print.h"
13 /***********************************************************************
14 * PSDRV_ExtTextOut
16 BOOL32 PSDRV_ExtTextOut( DC *dc, INT32 x, INT32 y, UINT32 flags,
17 const RECT32 *lprect, LPCSTR str, UINT32 count,
18 const INT32 *lpDx )
20 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
21 char *strbuf;
22 SIZE32 sz;
24 TRACE(psdrv, "(x=%d, y=%d, flags=0x%08x, str='%s', count=%d)\n", x, y,
25 flags, str, count);
27 strbuf = (char *)HeapAlloc( PSDRV_Heap, 0, count + 1);
28 if(!strbuf) {
29 WARN(psdrv, "HeapAlloc failed\n");
30 return FALSE;
33 if(dc->w.textAlign & TA_UPDATECP) {
34 x = dc->w.CursPosX;
35 y = dc->w.CursPosY;
38 x = XLPTODP(dc, x);
39 y = YLPTODP(dc, y);
41 GetTextExtentPoint32A(dc->hSelf, str, count, &sz);
42 sz.cx = XLSTODS(dc, sz.cx);
43 sz.cy = YLSTODS(dc, sz.cy);
45 switch(dc->w.textAlign & (TA_LEFT | TA_CENTER | TA_RIGHT) ) {
46 case TA_LEFT:
47 if(dc->w.textAlign & TA_UPDATECP)
48 dc->w.CursPosX = XDPTOLP(dc, x + sz.cx);
49 break;
51 case TA_CENTER:
52 x -= sz.cx/2;
53 break;
55 case TA_RIGHT:
56 x -= sz.cx;
57 if(dc->w.textAlign & TA_UPDATECP)
58 dc->w.CursPosX = XDPTOLP(dc, x);
59 break;
62 switch(dc->w.textAlign & (TA_TOP | TA_BASELINE | TA_BOTTOM) ) {
63 case TA_TOP:
64 y += physDev->font.tm.tmAscent;
65 break;
67 case TA_BASELINE:
68 break;
70 case TA_BOTTOM:
71 y -= physDev->font.tm.tmDescent;
72 break;
75 memcpy(strbuf, str, count);
76 *(strbuf + count) = '\0';
78 PSDRV_SetFont(dc);
80 PSDRV_WriteMoveTo(dc, x, y);
81 PSDRV_WriteShow(dc, strbuf, strlen(strbuf));
83 HeapFree(PSDRV_Heap, 0, strbuf);
84 return TRUE;