winecoreaudio: GetNextPacketSize returns 0 when no data is available yet.
[wine] / dlls / wineps.drv / font.c
1 /*
2  *      PostScript driver font functions
3  *
4  *      Copyright 1998  Huw D M Davies
5  *
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.
10  *
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.
15  *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 #include <stdarg.h>
21 #include <string.h>
22 #include <assert.h>
23 #include <stdlib.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winnls.h"
29 #include "winspool.h"
30
31 #include "psdrv.h"
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
35
36 /***********************************************************************
37  *           SelectFont   (WINEPS.@)
38  */
39 HFONT PSDRV_SelectFont( PHYSDEV dev, HFONT hfont )
40 {
41     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
42     PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSelectFont );
43     HFONT ret;
44     LOGFONTW lf;
45     BOOL subst = FALSE;
46     char FaceName[LF_FACESIZE];
47
48     if (!GetObjectW( hfont, sizeof(lf), &lf )) return 0;
49
50     TRACE("FaceName = %s Height = %d Italic = %d Weight = %d\n",
51           debugstr_w(lf.lfFaceName), lf.lfHeight, lf.lfItalic,
52           lf.lfWeight);
53
54     WideCharToMultiByte(CP_ACP, 0, lf.lfFaceName, -1,
55                         FaceName, sizeof(FaceName), NULL, NULL);
56
57     if(FaceName[0] == '\0') {
58         switch(lf.lfPitchAndFamily & 0xf0) {
59         case FF_DONTCARE:
60             break;
61         case FF_ROMAN:
62         case FF_SCRIPT:
63             strcpy(FaceName, "Times");
64             break;
65         case FF_SWISS:
66             strcpy(FaceName, "Helvetica");
67             break;
68         case FF_MODERN:
69             strcpy(FaceName, "Courier");
70             break;
71         case FF_DECORATIVE:
72             strcpy(FaceName, "Symbol");
73             break;
74         }
75     }
76
77     if(FaceName[0] == '\0') {
78         switch(lf.lfPitchAndFamily & 0x0f) {
79         case VARIABLE_PITCH:
80             strcpy(FaceName, "Times");
81             break;
82         default:
83             strcpy(FaceName, "Courier");
84             break;
85         }
86     }
87
88     if (physDev->pi->FontSubTableSize != 0)
89     {
90         DWORD i;
91
92         for (i = 0; i < physDev->pi->FontSubTableSize; ++i)
93         {
94             if (!strcasecmp (FaceName,
95                     physDev->pi->FontSubTable[i].pValueName))
96             {
97                 TRACE ("substituting facename '%s' for '%s'\n",
98                         (LPSTR) physDev->pi->FontSubTable[i].pData, FaceName);
99                 if (strlen ((LPSTR) physDev->pi->FontSubTable[i].pData) <
100                         LF_FACESIZE)
101                 {
102                     strcpy (FaceName,
103                             (LPSTR) physDev->pi->FontSubTable[i].pData);
104                     subst = TRUE;
105                 }
106                 else
107                     WARN ("Facename '%s' is too long; ignoring substitution\n",
108                             (LPSTR) physDev->pi->FontSubTable[i].pData);
109                 break;
110             }
111         }
112     }
113
114     physDev->font.escapement = lf.lfEscapement;
115     physDev->font.set = FALSE;
116
117     if (!subst && ((ret = next->funcs->pSelectFont( next, hfont ))))
118     {
119         PSDRV_SelectDownloadFont(dev);
120         return ret;
121     }
122
123     PSDRV_SelectBuiltinFont(dev, hfont, &lf, FaceName);
124     next->funcs->pSelectFont( next, 0 );  /* tell next driver that we selected a device font */
125     return hfont;
126 }
127
128 /***********************************************************************
129  *           PSDRV_SetFont
130  */
131 BOOL PSDRV_SetFont( PHYSDEV dev )
132 {
133     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
134
135     PSDRV_WriteSetColor(dev, &physDev->font.color);
136     if(physDev->font.set) return TRUE;
137
138     switch(physDev->font.fontloc) {
139     case Builtin:
140         PSDRV_WriteSetBuiltinFont(dev);
141         break;
142     case Download:
143         PSDRV_WriteSetDownloadFont(dev);
144         break;
145     default:
146         ERR("fontloc = %d\n", physDev->font.fontloc);
147         assert(1);
148         break;
149     }
150     physDev->font.set = TRUE;
151     return TRUE;
152 }