Fixed callback parameters (bogus hWave); added acm conversion for
[wine.git] / dlls / wineps / text.c
blobc2365601da41aff6dcf49acf9c92176674dbbada
1 /*
2 * PostScript driver text functions
4 * Copyright 1998 Huw D M Davies
6 */
7 #include <string.h>
8 #include "psdrv.h"
9 #include "debugtools.h"
10 #include "winspool.h"
12 DEFAULT_DEBUG_CHANNEL(psdrv);
14 static BOOL PSDRV_Text(DC *dc, INT x, INT y, LPCWSTR str, UINT count,
15 BOOL bDrawBackground, const INT *lpDx);
17 /***********************************************************************
18 * PSDRV_ExtTextOut
20 BOOL PSDRV_ExtTextOut( DC *dc, INT x, INT y, UINT flags,
21 const RECT *lprect, LPCWSTR str, UINT count,
22 const INT *lpDx )
24 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
25 BOOL bResult = TRUE;
26 BOOL bClipped = FALSE;
27 BOOL bOpaque = FALSE;
28 RECT rect;
30 TRACE("(x=%d, y=%d, flags=0x%08x, str=%s, count=%d, lpDx=%p)\n", x, y,
31 flags, debugstr_wn(str, count), count, lpDx);
33 /* write font if not already written */
34 PSDRV_SetFont(dc);
36 /* set clipping and/or draw background */
37 if ((flags & (ETO_CLIPPED | ETO_OPAQUE)) && (lprect != NULL))
39 rect.left = INTERNAL_XWPTODP(dc, lprect->left, lprect->top);
40 rect.right = INTERNAL_XWPTODP(dc, lprect->right, lprect->bottom);
41 rect.top = INTERNAL_YWPTODP(dc, lprect->left, lprect->top);
42 rect.bottom = INTERNAL_YWPTODP(dc, lprect->right, lprect->bottom);
44 PSDRV_WriteGSave(dc);
45 PSDRV_WriteRectangle(dc, rect.left, rect.top, rect.right - rect.left,
46 rect.bottom - rect.top);
48 if (flags & ETO_OPAQUE)
50 bOpaque = TRUE;
51 PSDRV_WriteGSave(dc);
52 PSDRV_WriteSetColor(dc, &physDev->bkColor);
53 PSDRV_WriteFill(dc);
54 PSDRV_WriteGRestore(dc);
57 if (flags & ETO_CLIPPED)
59 bClipped = TRUE;
60 PSDRV_WriteClip(dc);
63 bResult = PSDRV_Text(dc, x, y, str, count, !(bClipped && bOpaque), lpDx);
64 PSDRV_WriteGRestore(dc);
66 else
68 bResult = PSDRV_Text(dc, x, y, str, count, TRUE, lpDx);
71 return bResult;
74 /***********************************************************************
75 * PSDRV_Text
77 static BOOL PSDRV_Text(DC *dc, INT x, INT y, LPCWSTR str, UINT count,
78 BOOL bDrawBackground, const INT *lpDx)
80 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
81 LPWSTR strbuf;
82 SIZE sz;
84 strbuf = HeapAlloc( PSDRV_Heap, 0, (count + 1) * sizeof(WCHAR));
85 if(!strbuf) {
86 WARN("HeapAlloc failed\n");
87 return FALSE;
90 if(dc->textAlign & TA_UPDATECP) {
91 x = dc->CursPosX;
92 y = dc->CursPosY;
95 x = INTERNAL_XWPTODP(dc, x, y);
96 y = INTERNAL_YWPTODP(dc, x, y);
98 GetTextExtentPoint32W(dc->hSelf, str, count, &sz);
99 if(lpDx) {
100 SIZE tmpsz;
101 INT i;
102 /* Get the width of the last char and add on all the offsets */
103 GetTextExtentPoint32W(dc->hSelf, str + count - 1, 1, &tmpsz);
104 for(i = 0; i < count-1; i++)
105 tmpsz.cx += lpDx[i];
106 sz.cx = tmpsz.cx; /* sz.cy remains untouched */
109 sz.cx = INTERNAL_XWSTODS(dc, sz.cx);
110 sz.cy = INTERNAL_YWSTODS(dc, sz.cy);
111 TRACE("textAlign = %x\n", dc->textAlign);
112 switch(dc->textAlign & (TA_LEFT | TA_CENTER | TA_RIGHT) ) {
113 case TA_LEFT:
114 if(dc->textAlign & TA_UPDATECP) {
115 dc->CursPosX = INTERNAL_XDPTOWP(dc, x + sz.cx, y);
117 break;
119 case TA_CENTER:
120 x -= sz.cx/2;
121 break;
123 case TA_RIGHT:
124 x -= sz.cx;
125 if(dc->textAlign & TA_UPDATECP) {
126 dc->CursPosX = INTERNAL_XDPTOWP(dc, x, y);
128 break;
131 switch(dc->textAlign & (TA_TOP | TA_BASELINE | TA_BOTTOM) ) {
132 case TA_TOP:
133 y += physDev->font.tm.tmAscent;
134 break;
136 case TA_BASELINE:
137 break;
139 case TA_BOTTOM:
140 y -= physDev->font.tm.tmDescent;
141 break;
144 memcpy(strbuf, str, count * sizeof(WCHAR));
145 *(strbuf + count) = '\0';
147 if ((dc->backgroundMode != TRANSPARENT) && (bDrawBackground != FALSE))
149 PSDRV_WriteGSave(dc);
150 PSDRV_WriteNewPath(dc);
151 PSDRV_WriteRectangle(dc, x, y - physDev->font.tm.tmAscent, sz.cx,
152 physDev->font.tm.tmAscent +
153 physDev->font.tm.tmDescent);
154 PSDRV_WriteSetColor(dc, &physDev->bkColor);
155 PSDRV_WriteFill(dc);
156 PSDRV_WriteGRestore(dc);
159 PSDRV_WriteMoveTo(dc, x, y);
161 if(!lpDx)
162 PSDRV_WriteShow(dc, strbuf, lstrlenW(strbuf));
163 else {
164 INT i;
165 float dx = 0.0, dy = 0.0;
166 float cos_theta = cos(physDev->font.escapement * M_PI / 1800.0);
167 float sin_theta = sin(physDev->font.escapement * M_PI / 1800.0);
168 for(i = 0; i < count-1; i++) {
169 TRACE("lpDx[%d] = %d\n", i, lpDx[i]);
170 PSDRV_WriteShow(dc, &strbuf[i], 1);
171 dx += lpDx[i] * cos_theta;
172 dy -= lpDx[i] * sin_theta;
173 PSDRV_WriteMoveTo(dc, x + INTERNAL_XWSTODS(dc, dx),
174 y + INTERNAL_YWSTODS(dc, dy));
176 PSDRV_WriteShow(dc, &strbuf[i], 1);
180 * Underline and strikeout attributes.
182 if ((physDev->font.tm.tmUnderlined) || (physDev->font.tm.tmStruckOut)) {
184 /* Get the thickness and the position for the underline attribute */
185 /* We'll use the same thickness for the strikeout attribute */
187 float thick = physDev->font.afm->UnderlineThickness * physDev->font.scale;
188 float pos = -physDev->font.afm->UnderlinePosition * physDev->font.scale;
189 SIZE size;
190 INT escapement = physDev->font.escapement;
192 TRACE("Position = %f Thickness %f Escapement %d\n",
193 pos, thick, escapement);
195 /* Get the width of the text */
197 PSDRV_GetTextExtentPoint(dc, strbuf, lstrlenW(strbuf), &size);
198 size.cx = INTERNAL_XWSTODS(dc, size.cx);
200 /* Do the underline */
202 if (physDev->font.tm.tmUnderlined) {
203 if (escapement != 0) /* rotated text */
205 PSDRV_WriteGSave(dc); /* save the graphics state */
206 PSDRV_WriteMoveTo(dc, x, y); /* move to the start */
208 /* temporarily rotate the coord system */
209 PSDRV_WriteRotate(dc, -escapement/10);
211 /* draw the underline relative to the starting point */
212 PSDRV_WriteRRectangle(dc, 0, (INT)pos, size.cx, (INT)thick);
214 else
215 PSDRV_WriteRectangle(dc, x, y + (INT)pos, size.cx, (INT)thick);
217 PSDRV_WriteFill(dc);
219 if (escapement != 0) /* rotated text */
220 PSDRV_WriteGRestore(dc); /* restore the graphics state */
223 /* Do the strikeout */
225 if (physDev->font.tm.tmStruckOut) {
226 pos = -physDev->font.tm.tmAscent / 2;
228 if (escapement != 0) /* rotated text */
230 PSDRV_WriteGSave(dc); /* save the graphics state */
231 PSDRV_WriteMoveTo(dc, x, y); /* move to the start */
233 /* temporarily rotate the coord system */
234 PSDRV_WriteRotate(dc, -escapement/10);
236 /* draw the underline relative to the starting point */
237 PSDRV_WriteRRectangle(dc, 0, (INT)pos, size.cx, (INT)thick);
239 else
240 PSDRV_WriteRectangle(dc, x, y + (INT)pos, size.cx, (INT)thick);
242 PSDRV_WriteFill(dc);
244 if (escapement != 0) /* rotated text */
245 PSDRV_WriteGRestore(dc); /* restore the graphics state */
249 HeapFree(PSDRV_Heap, 0, strbuf);
250 return TRUE;