2 * PostScript driver text functions
4 * Copyright 1998 Huw D M Davies
9 #include "debugtools.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 /***********************************************************************
20 BOOL PSDRV_ExtTextOut( DC *dc, INT x, INT y, UINT flags,
21 const RECT *lprect, LPCWSTR str, UINT count,
24 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
26 BOOL bClipped = FALSE;
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 */
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);
45 PSDRV_WriteRectangle(dc, rect.left, rect.top, rect.right - rect.left,
46 rect.bottom - rect.top);
48 if (flags & ETO_OPAQUE)
52 PSDRV_WriteSetColor(dc, &physDev->bkColor);
54 PSDRV_WriteGRestore(dc);
57 if (flags & ETO_CLIPPED)
63 bResult = PSDRV_Text(dc, x, y, str, count, !(bClipped && bOpaque), lpDx);
64 PSDRV_WriteGRestore(dc);
68 bResult = PSDRV_Text(dc, x, y, str, count, TRUE, lpDx);
74 /***********************************************************************
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;
84 strbuf = HeapAlloc( PSDRV_Heap, 0, (count + 1) * sizeof(WCHAR));
86 WARN("HeapAlloc failed\n");
90 if(dc->textAlign & TA_UPDATECP) {
95 x = INTERNAL_XWPTODP(dc, x, y);
96 y = INTERNAL_YWPTODP(dc, x, y);
98 GetTextExtentPoint32W(dc->hSelf, str, count, &sz);
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++)
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) ) {
114 if(dc->textAlign & TA_UPDATECP) {
115 dc->CursPosX = INTERNAL_XDPTOWP(dc, x + sz.cx, y);
125 if(dc->textAlign & TA_UPDATECP) {
126 dc->CursPosX = INTERNAL_XDPTOWP(dc, x, y);
131 switch(dc->textAlign & (TA_TOP | TA_BASELINE | TA_BOTTOM) ) {
133 y += physDev->font.tm.tmAscent;
140 y -= physDev->font.tm.tmDescent;
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);
156 PSDRV_WriteGRestore(dc);
159 PSDRV_WriteMoveTo(dc, x, y);
162 PSDRV_WriteShow(dc, strbuf, lstrlenW(strbuf));
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;
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);
215 PSDRV_WriteRectangle(dc, x, y + (INT)pos, size.cx, (INT)thick);
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);
240 PSDRV_WriteRectangle(dc, x, y + (INT)pos, size.cx, (INT)thick);
244 if (escapement != 0) /* rotated text */
245 PSDRV_WriteGRestore(dc); /* restore the graphics state */
249 HeapFree(PSDRV_Heap, 0, strbuf);