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
;
87 strbuf
= HeapAlloc( PSDRV_Heap
, 0, (count
+ 1) * sizeof(WCHAR
));
89 WARN("HeapAlloc failed\n");
93 if(dc
->textAlign
& TA_UPDATECP
) {
98 x
= INTERNAL_XWPTODP(dc
, x
, y
);
99 y
= INTERNAL_YWPTODP(dc
, x
, y
);
101 GetTextExtentPoint32W(dc
->hSelf
, str
, count
, &sz
);
105 /* Get the width of the last char and add on all the offsets */
106 GetTextExtentPoint32W(dc
->hSelf
, str
+ count
- 1, 1, &tmpsz
);
107 for(i
= 0; i
< count
-1; i
++)
109 sz
.cx
= tmpsz
.cx
; /* sz.cy remains untouched */
112 sz
.cx
= INTERNAL_XWSTODS(dc
, sz
.cx
);
113 sz
.cy
= INTERNAL_YWSTODS(dc
, sz
.cy
);
114 TRACE("textAlign = %x\n", dc
->textAlign
);
115 switch(dc
->textAlign
& (TA_LEFT
| TA_CENTER
| TA_RIGHT
) ) {
117 if(dc
->textAlign
& TA_UPDATECP
) {
118 dc
->CursPosX
= INTERNAL_XDPTOWP(dc
, x
+ sz
.cx
, y
);
128 if(dc
->textAlign
& TA_UPDATECP
) {
129 dc
->CursPosX
= INTERNAL_XDPTOWP(dc
, x
, y
);
134 switch(dc
->textAlign
& (TA_TOP
| TA_BASELINE
| TA_BOTTOM
) ) {
136 y
+= physDev
->font
.tm
.tmAscent
;
143 y
-= physDev
->font
.tm
.tmDescent
;
147 memcpy(strbuf
, str
, count
* sizeof(WCHAR
));
148 *(strbuf
+ count
) = '\0';
150 if ((dc
->backgroundMode
!= TRANSPARENT
) && (bDrawBackground
!= FALSE
))
152 PSDRV_WriteGSave(dc
);
153 PSDRV_WriteNewPath(dc
);
154 PSDRV_WriteRectangle(dc
, x
, y
- physDev
->font
.tm
.tmAscent
, sz
.cx
,
155 physDev
->font
.tm
.tmAscent
+
156 physDev
->font
.tm
.tmDescent
);
157 PSDRV_WriteSetColor(dc
, &physDev
->bkColor
);
159 PSDRV_WriteGRestore(dc
);
162 PSDRV_WriteMoveTo(dc
, x
, y
);
165 PSDRV_WriteGlyphShow(dc
, strbuf
, lstrlenW(strbuf
));
168 float dx
= 0.0, dy
= 0.0;
169 float cos_theta
= cos(physDev
->font
.escapement
* M_PI
/ 1800.0);
170 float sin_theta
= sin(physDev
->font
.escapement
* M_PI
/ 1800.0);
171 for(i
= 0; i
< count
-1; i
++) {
172 TRACE("lpDx[%d] = %d\n", i
, lpDx
[i
]);
173 PSDRV_WriteGlyphShow(dc
, &strbuf
[i
], 1);
174 dx
+= lpDx
[i
] * cos_theta
;
175 dy
-= lpDx
[i
] * sin_theta
;
176 PSDRV_WriteMoveTo(dc
, x
+ INTERNAL_XWSTODS(dc
, dx
),
177 y
+ INTERNAL_YWSTODS(dc
, dy
));
179 PSDRV_WriteGlyphShow(dc
, &strbuf
[i
], 1);
183 * Underline and strikeout attributes.
185 if ((physDev
->font
.tm
.tmUnderlined
) || (physDev
->font
.tm
.tmStruckOut
)) {
187 /* Get the thickness and the position for the underline attribute */
188 /* We'll use the same thickness for the strikeout attribute */
190 float thick
= physDev
->font
.afm
->UnderlineThickness
* physDev
->font
.scale
;
191 float pos
= -physDev
->font
.afm
->UnderlinePosition
* physDev
->font
.scale
;
193 INT escapement
= physDev
->font
.escapement
;
195 TRACE("Position = %f Thickness %f Escapement %d\n",
196 pos
, thick
, escapement
);
198 /* Get the width of the text */
200 PSDRV_GetTextExtentPoint(dc
, strbuf
, lstrlenW(strbuf
), &size
);
201 size
.cx
= INTERNAL_XWSTODS(dc
, size
.cx
);
203 /* Do the underline */
205 if (physDev
->font
.tm
.tmUnderlined
) {
206 PSDRV_WriteNewPath(dc
); /* will be closed by WriteRectangle */
207 if (escapement
!= 0) /* rotated text */
209 PSDRV_WriteGSave(dc
); /* save the graphics state */
210 PSDRV_WriteMoveTo(dc
, x
, y
); /* move to the start */
212 /* temporarily rotate the coord system */
213 PSDRV_WriteRotate(dc
, -escapement
/10);
215 /* draw the underline relative to the starting point */
216 PSDRV_WriteRRectangle(dc
, 0, (INT
)pos
, size
.cx
, (INT
)thick
);
219 PSDRV_WriteRectangle(dc
, x
, y
+ (INT
)pos
, size
.cx
, (INT
)thick
);
223 if (escapement
!= 0) /* rotated text */
224 PSDRV_WriteGRestore(dc
); /* restore the graphics state */
227 /* Do the strikeout */
229 if (physDev
->font
.tm
.tmStruckOut
) {
230 pos
= -physDev
->font
.tm
.tmAscent
/ 2;
231 PSDRV_WriteNewPath(dc
); /* will be closed by WriteRectangle */
232 if (escapement
!= 0) /* rotated text */
234 PSDRV_WriteGSave(dc
); /* save the graphics state */
235 PSDRV_WriteMoveTo(dc
, x
, y
); /* move to the start */
237 /* temporarily rotate the coord system */
238 PSDRV_WriteRotate(dc
, -escapement
/10);
240 /* draw the underline relative to the starting point */
241 PSDRV_WriteRRectangle(dc
, 0, (INT
)pos
, size
.cx
, (INT
)thick
);
244 PSDRV_WriteRectangle(dc
, x
, y
+ (INT
)pos
, size
.cx
, (INT
)thick
);
248 if (escapement
!= 0) /* rotated text */
249 PSDRV_WriteGRestore(dc
); /* restore the graphics state */
253 HeapFree(PSDRV_Heap
, 0, strbuf
);