Change the ARTS_Init() error message from an ERR() to a WARN() since
[wine/multimedia.git] / dlls / wineps / text.c
blob5beb3436846a7b4ca41a25278af627f8649af018
1 /*
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
20 #include <string.h>
21 #include <stdarg.h>
22 #include <stdlib.h>
23 #include <math.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "psdrv.h"
29 #include "winspool.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
34 static BOOL PSDRV_Text(PSDRV_PDEVICE *physDev, INT x, INT y, UINT flags,
35 LPCWSTR str, UINT count,
36 BOOL bDrawBackground, const INT *lpDx);
38 /***********************************************************************
39 * PSDRV_ExtTextOut
41 BOOL PSDRV_ExtTextOut( PSDRV_PDEVICE *physDev, INT x, INT y, UINT flags,
42 const RECT *lprect, LPCWSTR str, UINT count,
43 const INT *lpDx, INT breakExtra )
45 BOOL bResult = TRUE;
46 BOOL bClipped = FALSE;
47 BOOL bOpaque = FALSE;
48 RECT rect;
50 TRACE("(x=%d, y=%d, flags=0x%08x, str=%s, count=%d, lpDx=%p)\n", x, y,
51 flags, debugstr_wn(str, count), count, lpDx);
53 /* write font if not already written */
54 PSDRV_SetFont(physDev);
56 PSDRV_SetClip(physDev);
58 /* set clipping and/or draw background */
59 if ((flags & (ETO_CLIPPED | ETO_OPAQUE)) && (lprect != NULL))
61 rect = *lprect;
62 LPtoDP( physDev->hdc, (POINT *)&rect, 2 );
63 PSDRV_WriteGSave(physDev);
64 PSDRV_WriteRectangle(physDev, rect.left, rect.top, rect.right - rect.left,
65 rect.bottom - rect.top);
67 if (flags & ETO_OPAQUE)
69 bOpaque = TRUE;
70 PSDRV_WriteGSave(physDev);
71 PSDRV_WriteSetColor(physDev, &physDev->bkColor);
72 PSDRV_WriteFill(physDev);
73 PSDRV_WriteGRestore(physDev);
76 if (flags & ETO_CLIPPED)
78 bClipped = TRUE;
79 PSDRV_WriteClip(physDev);
82 bResult = PSDRV_Text(physDev, x, y, flags, str, count, !(bClipped && bOpaque), lpDx);
83 PSDRV_WriteGRestore(physDev);
85 else
87 bResult = PSDRV_Text(physDev, x, y, flags, str, count, TRUE, lpDx);
90 PSDRV_ResetClip(physDev);
91 return bResult;
94 /***********************************************************************
95 * PSDRV_Text
97 static BOOL PSDRV_Text(PSDRV_PDEVICE *physDev, INT x, INT y, UINT flags, LPCWSTR str,
98 UINT count, BOOL bDrawBackground, const INT *lpDx)
100 SIZE sz;
101 TEXTMETRICW tm;
102 POINT pt;
103 INT ascent, descent;
104 WORD *glyphs = NULL;
105 UINT align = GetTextAlign( physDev->hdc );
106 INT char_extra;
107 INT *deltas = NULL;
108 double cosEsc, sinEsc;
109 LOGFONTW lf;
111 if (!count)
112 return TRUE;
114 GetObjectW(GetCurrentObject(physDev->hdc, OBJ_FONT), sizeof(lf), &lf);
115 if(lf.lfEscapement != 0) {
116 cosEsc = cos(lf.lfEscapement * M_PI / 1800);
117 sinEsc = sin(lf.lfEscapement * M_PI / 1800);
118 } else {
119 cosEsc = 1;
120 sinEsc = 0;
123 if(physDev->font.fontloc == Download) {
124 if(flags & ETO_GLYPH_INDEX)
125 glyphs = (LPWORD)str;
126 else {
127 glyphs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WORD));
128 GetGlyphIndicesW(physDev->hdc, str, count, glyphs, 0);
132 pt.x = x;
133 pt.y = y;
134 if(align & TA_UPDATECP) GetCurrentPositionEx( physDev->hdc, &pt );
135 LPtoDP(physDev->hdc, &pt, 1);
136 x = pt.x;
137 y = pt.y;
139 if(physDev->font.fontloc == Download)
140 GetTextExtentPointI(physDev->hdc, glyphs, count, &sz);
141 else
142 GetTextExtentPoint32W(physDev->hdc, str, count, &sz);
144 if((char_extra = GetTextCharacterExtra(physDev->hdc)) != 0) {
145 INT i;
146 SIZE tmpsz;
148 deltas = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT));
149 for(i = 0; i < count; i++) {
150 if(lpDx)
151 deltas[i] = lpDx[i] + char_extra;
152 else {
153 if(physDev->font.fontloc == Download)
154 GetTextExtentPointI(physDev->hdc, glyphs + i, 1, &tmpsz);
155 else
156 GetTextExtentPoint32W(physDev->hdc, str + i, 1, &tmpsz);
157 deltas[i] = tmpsz.cx;
160 } else if(lpDx)
161 deltas = (INT*)lpDx;
163 if(deltas) {
164 SIZE tmpsz;
165 INT i;
166 /* Get the width of the last char and add on all the offsets */
167 if(physDev->font.fontloc == Download)
168 GetTextExtentPointI(physDev->hdc, glyphs + count - 1, 1, &tmpsz);
169 else
170 GetTextExtentPoint32W(physDev->hdc, str + count - 1, 1, &tmpsz);
171 for(i = 0; i < count-1; i++)
172 tmpsz.cx += deltas[i];
173 sz.cx = tmpsz.cx; /* sz.cy remains untouched */
176 sz.cx = PSDRV_XWStoDS(physDev, sz.cx);
177 sz.cy = PSDRV_YWStoDS(physDev, sz.cy);
179 GetTextMetricsW(physDev->hdc, &tm);
180 ascent = abs(PSDRV_YWStoDS(physDev, tm.tmAscent));
181 descent = abs(PSDRV_YWStoDS(physDev, tm.tmDescent));
183 TRACE("textAlign = %x\n", align);
184 switch(align & (TA_LEFT | TA_CENTER | TA_RIGHT) ) {
185 case TA_LEFT:
186 if(align & TA_UPDATECP)
188 POINT pt;
189 pt.x = x + sz.cx * cosEsc;
190 pt.y = y - sz.cx * sinEsc;
191 DPtoLP( physDev->hdc, &pt, 1 );
192 MoveToEx( physDev->hdc, pt.x, pt.y, NULL );
194 break;
196 case TA_CENTER:
197 x -= sz.cx * cosEsc / 2;
198 y += sz.cx * sinEsc / 2;
199 break;
201 case TA_RIGHT:
202 x -= sz.cx * cosEsc;
203 y += sz.cx * sinEsc;
204 if(align & TA_UPDATECP)
206 POINT pt;
207 pt.x = x;
208 pt.y = y;
209 DPtoLP( physDev->hdc, &pt, 1 );
210 MoveToEx( physDev->hdc, pt.x, pt.y, NULL );
212 break;
215 switch(align & (TA_TOP | TA_BASELINE | TA_BOTTOM) ) {
216 case TA_TOP:
217 y += ascent * cosEsc;
218 x += ascent * sinEsc;
219 break;
221 case TA_BASELINE:
222 break;
224 case TA_BOTTOM:
225 y -= descent * cosEsc;
226 x -= descent * sinEsc;
227 break;
230 if ((GetBkMode( physDev->hdc ) != TRANSPARENT) && bDrawBackground)
232 PSDRV_WriteGSave(physDev);
233 PSDRV_WriteNewPath(physDev);
234 PSDRV_WriteRectangle(physDev, x, y - ascent, sz.cx,
235 ascent + descent);
236 PSDRV_WriteSetColor(physDev, &physDev->bkColor);
237 PSDRV_WriteFill(physDev);
238 PSDRV_WriteGRestore(physDev);
241 PSDRV_WriteMoveTo(physDev, x, y);
243 if(!deltas) {
244 if(physDev->font.fontloc == Download)
245 PSDRV_WriteDownloadGlyphShow(physDev, glyphs, count);
246 else
247 PSDRV_WriteBuiltinGlyphShow(physDev, str, count);
249 else {
250 INT i;
251 float dx = 0.0, dy = 0.0;
252 float cos_theta = cos(physDev->font.escapement * M_PI / 1800.0);
253 float sin_theta = sin(physDev->font.escapement * M_PI / 1800.0);
254 for(i = 0; i < count-1; i++) {
255 TRACE("lpDx[%d] = %d\n", i, deltas[i]);
256 if(physDev->font.fontloc == Download)
257 PSDRV_WriteDownloadGlyphShow(physDev, glyphs + i, 1);
258 else
259 PSDRV_WriteBuiltinGlyphShow(physDev, str + i, 1);
260 dx += deltas[i] * cos_theta;
261 dy -= deltas[i] * sin_theta;
262 PSDRV_WriteMoveTo(physDev, x + PSDRV_XWStoDS(physDev, dx),
263 y + PSDRV_YWStoDS(physDev, dy));
265 if(physDev->font.fontloc == Download)
266 PSDRV_WriteDownloadGlyphShow(physDev, glyphs + i, 1);
267 else
268 PSDRV_WriteBuiltinGlyphShow(physDev, str + i, 1);
269 if(deltas != lpDx)
270 HeapFree(GetProcessHeap(), 0, deltas);
274 * Underline and strikeout attributes.
276 if ((tm.tmUnderlined) || (tm.tmStruckOut)) {
278 /* Get the thickness and the position for the underline attribute */
279 /* We'll use the same thickness for the strikeout attribute */
281 INT escapement = physDev->font.escapement;
283 /* Do the underline */
285 if (tm.tmUnderlined) {
286 PSDRV_WriteNewPath(physDev); /* will be closed by WriteRectangle */
287 if (escapement != 0) /* rotated text */
289 PSDRV_WriteGSave(physDev); /* save the graphics state */
290 PSDRV_WriteMoveTo(physDev, x, y); /* move to the start */
292 /* temporarily rotate the coord system */
293 PSDRV_WriteRotate(physDev, -escapement/10);
295 /* draw the underline relative to the starting point */
296 PSDRV_WriteRRectangle(physDev, 0, -physDev->font.underlinePosition,
297 sz.cx, physDev->font.underlineThickness);
299 else
300 PSDRV_WriteRectangle(physDev, x, y - physDev->font.underlinePosition,
301 sz.cx, physDev->font.underlineThickness);
303 PSDRV_WriteFill(physDev);
305 if (escapement != 0) /* rotated text */
306 PSDRV_WriteGRestore(physDev); /* restore the graphics state */
309 /* Do the strikeout */
311 if (tm.tmStruckOut) {
312 PSDRV_WriteNewPath(physDev); /* will be closed by WriteRectangle */
313 if (escapement != 0) /* rotated text */
315 PSDRV_WriteGSave(physDev); /* save the graphics state */
316 PSDRV_WriteMoveTo(physDev, x, y); /* move to the start */
318 /* temporarily rotate the coord system */
319 PSDRV_WriteRotate(physDev, -escapement/10);
321 /* draw the line relative to the starting point */
322 PSDRV_WriteRRectangle(physDev, 0, -physDev->font.strikeoutPosition,
323 sz.cx, physDev->font.strikeoutThickness);
325 else
326 PSDRV_WriteRectangle(physDev, x, y - physDev->font.strikeoutPosition,
327 sz.cx, physDev->font.strikeoutThickness);
329 PSDRV_WriteFill(physDev);
331 if (escapement != 0) /* rotated text */
332 PSDRV_WriteGRestore(physDev); /* restore the graphics state */
336 if(glyphs && glyphs != str) HeapFree(GetProcessHeap(), 0, glyphs);
337 return TRUE;