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