push decde5eed3d79f9d889b4d757f73e86ce6ff9241
[wine/hacks.git] / dlls / wineps.drv / font.c
blob9e0ae3942563c524459dd25e9c3963dd9af7d421
1 /*
2 * PostScript driver font 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
21 #include <string.h>
22 #include <assert.h>
23 #include <stdlib.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winspool.h"
30 #include "psdrv.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
35 /***********************************************************************
36 * SelectFont (WINEPS.@)
38 HFONT PSDRV_SelectFont( PSDRV_PDEVICE *physDev, HFONT hfont, HANDLE gdiFont )
40 LOGFONTW lf;
41 BOOL subst = FALSE;
42 char FaceName[LF_FACESIZE];
44 if (!GetObjectW( hfont, sizeof(lf), &lf )) return HGDI_ERROR;
46 TRACE("FaceName = %s Height = %d Italic = %d Weight = %d\n",
47 debugstr_w(lf.lfFaceName), lf.lfHeight, lf.lfItalic,
48 lf.lfWeight);
50 WideCharToMultiByte(CP_ACP, 0, lf.lfFaceName, -1,
51 FaceName, sizeof(FaceName), NULL, NULL);
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;
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;
84 if (physDev->pi->FontSubTableSize != 0)
86 DWORD i;
88 for (i = 0; i < physDev->pi->FontSubTableSize; ++i)
90 if (!strcasecmp (FaceName,
91 physDev->pi->FontSubTable[i].pValueName))
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)
98 strcpy (FaceName,
99 (LPSTR) physDev->pi->FontSubTable[i].pData);
100 subst = TRUE;
102 else
103 WARN ("Facename '%s' is too long; ignoring substitution\n",
104 (LPSTR) physDev->pi->FontSubTable[i].pData);
105 break;
110 physDev->font.escapement = lf.lfEscapement;
111 physDev->font.set = FALSE;
113 if(gdiFont && !subst) {
114 if(PSDRV_SelectDownloadFont(physDev))
115 return 0; /* use gdi font */
118 PSDRV_SelectBuiltinFont(physDev, hfont, &lf, FaceName);
119 return (HFONT)1; /* use device font */
122 /***********************************************************************
123 * PSDRV_SetFont
125 BOOL PSDRV_SetFont( PSDRV_PDEVICE *physDev )
127 PSDRV_WriteSetColor(physDev, &physDev->font.color);
128 if(physDev->font.set) return TRUE;
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;
142 physDev->font.set = TRUE;
143 return TRUE;