dinput: Fix printing NULL strings.
[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, HANDLE gdiFont )
40 {
41     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
42     LOGFONTW lf;
43     BOOL subst = FALSE;
44     char FaceName[LF_FACESIZE];
45
46     if (!GetObjectW( hfont, sizeof(lf), &lf )) return HGDI_ERROR;
47
48     TRACE("FaceName = %s Height = %d Italic = %d Weight = %d\n",
49           debugstr_w(lf.lfFaceName), lf.lfHeight, lf.lfItalic,
50           lf.lfWeight);
51
52     WideCharToMultiByte(CP_ACP, 0, lf.lfFaceName, -1,
53                         FaceName, sizeof(FaceName), NULL, NULL);
54
55     if(FaceName[0] == '\0') {
56         switch(lf.lfPitchAndFamily & 0xf0) {
57         case FF_DONTCARE:
58             break;
59         case FF_ROMAN:
60         case FF_SCRIPT:
61             strcpy(FaceName, "Times");
62             break;
63         case FF_SWISS:
64             strcpy(FaceName, "Helvetica");
65             break;
66         case FF_MODERN:
67             strcpy(FaceName, "Courier");
68             break;
69         case FF_DECORATIVE:
70             strcpy(FaceName, "Symbol");
71             break;
72         }
73     }
74
75     if(FaceName[0] == '\0') {
76         switch(lf.lfPitchAndFamily & 0x0f) {
77         case VARIABLE_PITCH:
78             strcpy(FaceName, "Times");
79             break;
80         default:
81             strcpy(FaceName, "Courier");
82             break;
83         }
84     }
85
86     if (physDev->pi->FontSubTableSize != 0)
87     {
88         DWORD i;
89
90         for (i = 0; i < physDev->pi->FontSubTableSize; ++i)
91         {
92             if (!strcasecmp (FaceName,
93                     physDev->pi->FontSubTable[i].pValueName))
94             {
95                 TRACE ("substituting facename '%s' for '%s'\n",
96                         (LPSTR) physDev->pi->FontSubTable[i].pData, FaceName);
97                 if (strlen ((LPSTR) physDev->pi->FontSubTable[i].pData) <
98                         LF_FACESIZE)
99                 {
100                     strcpy (FaceName,
101                             (LPSTR) physDev->pi->FontSubTable[i].pData);
102                     subst = TRUE;
103                 }
104                 else
105                     WARN ("Facename '%s' is too long; ignoring substitution\n",
106                             (LPSTR) physDev->pi->FontSubTable[i].pData);
107                 break;
108             }
109         }
110     }
111
112     physDev->font.escapement = lf.lfEscapement;
113     physDev->font.set = FALSE;
114
115     if(gdiFont && !subst) {
116         if(PSDRV_SelectDownloadFont(dev))
117             return 0; /* use gdi font */
118     }
119
120     PSDRV_SelectBuiltinFont(dev, hfont, &lf, FaceName);
121     return (HFONT)1; /* use device font */
122 }
123
124 /***********************************************************************
125  *           PSDRV_SetFont
126  */
127 BOOL PSDRV_SetFont( PHYSDEV dev )
128 {
129     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
130
131     PSDRV_WriteSetColor(dev, &physDev->font.color);
132     if(physDev->font.set) return TRUE;
133
134     switch(physDev->font.fontloc) {
135     case Builtin:
136         PSDRV_WriteSetBuiltinFont(dev);
137         break;
138     case Download:
139         PSDRV_WriteSetDownloadFont(dev);
140         break;
141     default:
142         ERR("fontloc = %d\n", physDev->font.fontloc);
143         assert(1);
144         break;
145     }
146     physDev->font.set = TRUE;
147     return TRUE;
148 }