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