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);
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)\n", x, y,
31 flags, debugstr_wn(str, count), count);
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 = XLPTODP(dc, lprect->left);
40 rect.right = XLPTODP(dc, lprect->right);
41 rect.top = YLPTODP(dc, lprect->top);
42 rect.bottom = YLPTODP(dc, 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));
64 PSDRV_WriteGRestore(dc);
68 bResult = PSDRV_Text(dc, x, y, str, count, TRUE);
74 /***********************************************************************
77 static BOOL PSDRV_Text(DC *dc, INT x, INT y, LPCWSTR str, UINT count,
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->w.textAlign & TA_UPDATECP) {
98 GetTextExtentPoint32W(dc->hSelf, str, count, &sz);
99 sz.cx = XLSTODS(dc, sz.cx);
100 sz.cy = YLSTODS(dc, sz.cy);
102 switch(dc->w.textAlign & (TA_LEFT | TA_CENTER | TA_RIGHT) ) {
104 if(dc->w.textAlign & TA_UPDATECP)
105 dc->w.CursPosX = XDPTOLP(dc, x + sz.cx);
114 if(dc->w.textAlign & TA_UPDATECP)
115 dc->w.CursPosX = XDPTOLP(dc, x);
119 switch(dc->w.textAlign & (TA_TOP | TA_BASELINE | TA_BOTTOM) ) {
121 y += physDev->font.tm.tmAscent;
128 y -= physDev->font.tm.tmDescent;
132 memcpy(strbuf, str, count * sizeof(WCHAR));
133 *(strbuf + count) = '\0';
135 if ((dc->w.backgroundMode != TRANSPARENT) && (bDrawBackground != FALSE))
137 PSDRV_WriteGSave(dc);
138 PSDRV_WriteNewPath(dc);
139 PSDRV_WriteRectangle(dc, x, y - physDev->font.tm.tmAscent, sz.cx,
140 physDev->font.tm.tmAscent +
141 physDev->font.tm.tmDescent);
142 PSDRV_WriteSetColor(dc, &physDev->bkColor);
144 PSDRV_WriteGRestore(dc);
147 PSDRV_WriteMoveTo(dc, x, y);
148 PSDRV_WriteShow(dc, strbuf, lstrlenW(strbuf));
151 * Underline and strikeout attributes.
153 if ((physDev->font.tm.tmUnderlined) || (physDev->font.tm.tmStruckOut)) {
155 /* Get the thickness and the position for the underline attribute */
156 /* We'll use the same thickness for the strikeout attribute */
158 float thick = physDev->font.afm->UnderlineThickness * physDev->font.scale;
159 float pos = -physDev->font.afm->UnderlinePosition * physDev->font.scale;
161 INT escapement = physDev->font.escapement;
163 TRACE("Position = %f Thickness %f Escapement %d\n",
164 pos, thick, escapement);
166 /* Get the width of the text */
168 PSDRV_GetTextExtentPoint(dc, strbuf, lstrlenW(strbuf), &size);
169 size.cx = XLSTODS(dc, size.cx);
171 /* Do the underline */
173 if (physDev->font.tm.tmUnderlined) {
174 if (escapement != 0) /* rotated text */
176 PSDRV_WriteGSave(dc); /* save the graphics state */
177 PSDRV_WriteMoveTo(dc, x, y); /* move to the start */
179 /* temporarily rotate the coord system */
180 PSDRV_WriteRotate(dc, -escapement/10);
182 /* draw the underline relative to the starting point */
183 PSDRV_WriteRRectangle(dc, 0, (INT)pos, size.cx, (INT)thick);
186 PSDRV_WriteRectangle(dc, x, y + (INT)pos, size.cx, (INT)thick);
190 if (escapement != 0) /* rotated text */
191 PSDRV_WriteGRestore(dc); /* restore the graphics state */
194 /* Do the strikeout */
196 if (physDev->font.tm.tmStruckOut) {
197 pos = -physDev->font.tm.tmAscent / 2;
199 if (escapement != 0) /* rotated text */
201 PSDRV_WriteGSave(dc); /* save the graphics state */
202 PSDRV_WriteMoveTo(dc, x, y); /* move to the start */
204 /* temporarily rotate the coord system */
205 PSDRV_WriteRotate(dc, -escapement/10);
207 /* draw the underline relative to the starting point */
208 PSDRV_WriteRRectangle(dc, 0, (INT)pos, size.cx, (INT)thick);
211 PSDRV_WriteRectangle(dc, x, y + (INT)pos, size.cx, (INT)thick);
215 if (escapement != 0) /* rotated text */
216 PSDRV_WriteGRestore(dc); /* restore the graphics state */
220 HeapFree(PSDRV_Heap, 0, strbuf);