2 * PostScript driver text functions
4 * Copyright 1998 Huw D M Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
28 static BOOL PSDRV_Text(PSDRV_PDEVICE *physDev, INT x, INT y, LPCWSTR str, UINT count,
29 BOOL bDrawBackground, const INT *lpDx);
31 /***********************************************************************
34 BOOL PSDRV_ExtTextOut( PSDRV_PDEVICE *physDev, INT x, INT y, UINT flags,
35 const RECT *lprect, LPCWSTR str, UINT count,
39 BOOL bClipped = FALSE;
43 TRACE("(x=%d, y=%d, flags=0x%08x, str=%s, count=%d, lpDx=%p)\n", x, y,
44 flags, debugstr_wn(str, count), count, lpDx);
46 /* write font if not already written */
47 PSDRV_SetFont(physDev);
49 /* set clipping and/or draw background */
50 if ((flags & (ETO_CLIPPED | ETO_OPAQUE)) && (lprect != NULL))
53 LPtoDP( physDev->hdc, (POINT *)&rect, 2 );
54 PSDRV_WriteGSave(physDev);
55 PSDRV_WriteRectangle(physDev, rect.left, rect.top, rect.right - rect.left,
56 rect.bottom - rect.top);
58 if (flags & ETO_OPAQUE)
61 PSDRV_WriteGSave(physDev);
62 PSDRV_WriteSetColor(physDev, &physDev->bkColor);
63 PSDRV_WriteFill(physDev);
64 PSDRV_WriteGRestore(physDev);
67 if (flags & ETO_CLIPPED)
70 PSDRV_WriteClip(physDev);
73 bResult = PSDRV_Text(physDev, x, y, str, count, !(bClipped && bOpaque), lpDx);
74 PSDRV_WriteGRestore(physDev);
78 bResult = PSDRV_Text(physDev, x, y, str, count, TRUE, lpDx);
84 /***********************************************************************
87 static BOOL PSDRV_Text(PSDRV_PDEVICE *physDev, INT x, INT y, LPCWSTR str, UINT count,
88 BOOL bDrawBackground, const INT *lpDx)
93 UINT align = GetTextAlign( physDev->hdc );
98 strbuf = HeapAlloc( PSDRV_Heap, 0, (count + 1) * sizeof(WCHAR));
100 WARN("HeapAlloc failed\n");
104 if(align & TA_UPDATECP) {
109 x = INTERNAL_XWPTODP(dc, x, y);
110 y = INTERNAL_YWPTODP(dc, x, y);
112 GetTextExtentPoint32W(physDev->hdc, str, count, &sz);
116 /* Get the width of the last char and add on all the offsets */
117 GetTextExtentPoint32W(physDev->hdc, str + count - 1, 1, &tmpsz);
118 for(i = 0; i < count-1; i++)
120 sz.cx = tmpsz.cx; /* sz.cy remains untouched */
123 sz.cx = INTERNAL_XWSTODS(dc, sz.cx);
124 sz.cy = INTERNAL_YWSTODS(dc, sz.cy);
125 TRACE("textAlign = %x\n", align);
126 switch(align & (TA_LEFT | TA_CENTER | TA_RIGHT) ) {
128 if(align & TA_UPDATECP) {
129 dc->CursPosX = INTERNAL_XDPTOWP(dc, x + sz.cx, y);
139 if(align & TA_UPDATECP) {
140 dc->CursPosX = INTERNAL_XDPTOWP(dc, x, y);
145 switch(align & (TA_TOP | TA_BASELINE | TA_BOTTOM) ) {
147 y += physDev->font.tm.tmAscent;
154 y -= physDev->font.tm.tmDescent;
158 memcpy(strbuf, str, count * sizeof(WCHAR));
159 *(strbuf + count) = '\0';
161 if ((GetBkMode( physDev->hdc ) != TRANSPARENT) && bDrawBackground)
163 PSDRV_WriteGSave(physDev);
164 PSDRV_WriteNewPath(physDev);
165 PSDRV_WriteRectangle(physDev, x, y - physDev->font.tm.tmAscent, sz.cx,
166 physDev->font.tm.tmAscent +
167 physDev->font.tm.tmDescent);
168 PSDRV_WriteSetColor(physDev, &physDev->bkColor);
169 PSDRV_WriteFill(physDev);
170 PSDRV_WriteGRestore(physDev);
173 PSDRV_WriteMoveTo(physDev, x, y);
176 PSDRV_WriteGlyphShow(physDev, strbuf, lstrlenW(strbuf));
179 float dx = 0.0, dy = 0.0;
180 float cos_theta = cos(physDev->font.escapement * M_PI / 1800.0);
181 float sin_theta = sin(physDev->font.escapement * M_PI / 1800.0);
182 for(i = 0; i < count-1; i++) {
183 TRACE("lpDx[%d] = %d\n", i, lpDx[i]);
184 PSDRV_WriteGlyphShow(physDev, &strbuf[i], 1);
185 dx += lpDx[i] * cos_theta;
186 dy -= lpDx[i] * sin_theta;
187 PSDRV_WriteMoveTo(physDev, x + INTERNAL_XWSTODS(dc, dx),
188 y + INTERNAL_YWSTODS(dc, dy));
190 PSDRV_WriteGlyphShow(physDev, &strbuf[i], 1);
194 * Underline and strikeout attributes.
196 if ((physDev->font.tm.tmUnderlined) || (physDev->font.tm.tmStruckOut)) {
198 /* Get the thickness and the position for the underline attribute */
199 /* We'll use the same thickness for the strikeout attribute */
201 float thick = physDev->font.afm->UnderlineThickness * physDev->font.scale;
202 float pos = -physDev->font.afm->UnderlinePosition * physDev->font.scale;
204 INT escapement = physDev->font.escapement;
206 TRACE("Position = %f Thickness %f Escapement %d\n",
207 pos, thick, escapement);
209 /* Get the width of the text */
211 PSDRV_GetTextExtentPoint(physDev, strbuf, lstrlenW(strbuf), &size);
212 size.cx = INTERNAL_XWSTODS(dc, size.cx);
214 /* Do the underline */
216 if (physDev->font.tm.tmUnderlined) {
217 PSDRV_WriteNewPath(physDev); /* will be closed by WriteRectangle */
218 if (escapement != 0) /* rotated text */
220 PSDRV_WriteGSave(physDev); /* save the graphics state */
221 PSDRV_WriteMoveTo(physDev, x, y); /* move to the start */
223 /* temporarily rotate the coord system */
224 PSDRV_WriteRotate(physDev, -escapement/10);
226 /* draw the underline relative to the starting point */
227 PSDRV_WriteRRectangle(physDev, 0, (INT)pos, size.cx, (INT)thick);
230 PSDRV_WriteRectangle(physDev, x, y + (INT)pos, size.cx, (INT)thick);
232 PSDRV_WriteFill(physDev);
234 if (escapement != 0) /* rotated text */
235 PSDRV_WriteGRestore(physDev); /* restore the graphics state */
238 /* Do the strikeout */
240 if (physDev->font.tm.tmStruckOut) {
241 pos = -physDev->font.tm.tmAscent / 2;
242 PSDRV_WriteNewPath(physDev); /* will be closed by WriteRectangle */
243 if (escapement != 0) /* rotated text */
245 PSDRV_WriteGSave(physDev); /* save the graphics state */
246 PSDRV_WriteMoveTo(physDev, x, y); /* move to the start */
248 /* temporarily rotate the coord system */
249 PSDRV_WriteRotate(physDev, -escapement/10);
251 /* draw the underline relative to the starting point */
252 PSDRV_WriteRRectangle(physDev, 0, (INT)pos, size.cx, (INT)thick);
255 PSDRV_WriteRectangle(physDev, x, y + (INT)pos, size.cx, (INT)thick);
257 PSDRV_WriteFill(physDev);
259 if (escapement != 0) /* rotated text */
260 PSDRV_WriteGRestore(physDev); /* restore the graphics state */
264 HeapFree(PSDRV_Heap, 0, strbuf);