font.c 3.66 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1
/*
Alexandre Julliard's avatar
Alexandre Julliard committed
2
 *	PostScript driver font functions
Alexandre Julliard's avatar
Alexandre Julliard committed
3 4 5
 *
 *	Copyright 1998  Huw D M Davies
 *
6 7 8 9 10 11 12 13 14 15 16 17
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
Alexandre Julliard's avatar
Alexandre Julliard committed
19
 */
20
#include <stdarg.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
21
#include <string.h>
22 23
#include <assert.h>
#include <stdlib.h>
24

25
#include "windef.h"
26 27
#include "winbase.h"
#include "wingdi.h"
28
#include "winspool.h"
29

Alexandre Julliard's avatar
Alexandre Julliard committed
30
#include "psdrv.h"
31
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
32

33
WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
Alexandre Julliard's avatar
Alexandre Julliard committed
34 35

/***********************************************************************
36
 *           SelectFont   (WINEPS.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
37
 */
38
HFONT PSDRV_SelectFont( PSDRV_PDEVICE *physDev, HFONT hfont, HANDLE gdiFont )
Alexandre Julliard's avatar
Alexandre Julliard committed
39
{
40
    LOGFONTW lf;
41
    BOOL subst = FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
42 43
    char FaceName[LF_FACESIZE];

44
    if (!GetObjectW( hfont, sizeof(lf), &lf )) return HGDI_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
45

46
    TRACE("FaceName = %s Height = %ld Italic = %d Weight = %ld\n",
47 48
	  debugstr_w(lf.lfFaceName), lf.lfHeight, lf.lfItalic,
	  lf.lfWeight);
Alexandre Julliard's avatar
Alexandre Julliard committed
49

50
    WideCharToMultiByte(CP_ACP, 0, lf.lfFaceName, -1,
51
			FaceName, sizeof(FaceName), NULL, NULL);
52

Alexandre Julliard's avatar
Alexandre Julliard committed
53
    if(FaceName[0] == '\0') {
54
        switch(lf.lfPitchAndFamily & 0xf0) {
Alexandre Julliard's avatar
Alexandre Julliard committed
55 56 57 58
	case FF_DONTCARE:
	    break;
	case FF_ROMAN:
	case FF_SCRIPT:
Alexandre Julliard's avatar
Alexandre Julliard committed
59
	    strcpy(FaceName, "Times");
Alexandre Julliard's avatar
Alexandre Julliard committed
60 61
	    break;
	case FF_SWISS:
Alexandre Julliard's avatar
Alexandre Julliard committed
62
	    strcpy(FaceName, "Helvetica");
Alexandre Julliard's avatar
Alexandre Julliard committed
63 64
	    break;
	case FF_MODERN:
Alexandre Julliard's avatar
Alexandre Julliard committed
65
	    strcpy(FaceName, "Courier");
Alexandre Julliard's avatar
Alexandre Julliard committed
66 67
	    break;
	case FF_DECORATIVE:
Alexandre Julliard's avatar
Alexandre Julliard committed
68
	    strcpy(FaceName, "Symbol");
Alexandre Julliard's avatar
Alexandre Julliard committed
69 70 71 72 73
	    break;
	}
    }

    if(FaceName[0] == '\0') {
74
        switch(lf.lfPitchAndFamily & 0x0f) {
Alexandre Julliard's avatar
Alexandre Julliard committed
75
	case VARIABLE_PITCH:
Alexandre Julliard's avatar
Alexandre Julliard committed
76
	    strcpy(FaceName, "Times");
Alexandre Julliard's avatar
Alexandre Julliard committed
77 78
	    break;
	default:
Alexandre Julliard's avatar
Alexandre Julliard committed
79
	    strcpy(FaceName, "Courier");
Alexandre Julliard's avatar
Alexandre Julliard committed
80 81 82 83
	    break;
	}
    }

84 85 86 87 88 89 90 91 92 93 94 95 96
    if (physDev->pi->FontSubTableSize != 0)
    {
	DWORD i;

	for (i = 0; i < physDev->pi->FontSubTableSize; ++i)
	{
	    if (!strcasecmp (FaceName,
		    physDev->pi->FontSubTable[i].pValueName))
	    {
		TRACE ("substituting facename '%s' for '%s'\n",
			(LPSTR) physDev->pi->FontSubTable[i].pData, FaceName);
		if (strlen ((LPSTR) physDev->pi->FontSubTable[i].pData) <
			LF_FACESIZE)
97
		{
98 99
		    strcpy (FaceName,
			    (LPSTR) physDev->pi->FontSubTable[i].pData);
100 101
		    subst = TRUE;
		}
102 103 104 105 106 107 108 109
		else
		    WARN ("Facename '%s' is too long; ignoring substitution\n",
			    (LPSTR) physDev->pi->FontSubTable[i].pData);
		break;
	    }
	}
    }

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

Alexandre Julliard's avatar
Alexandre Julliard committed
122 123 124
/***********************************************************************
 *           PSDRV_SetFont
 */
125
BOOL PSDRV_SetFont( PSDRV_PDEVICE *physDev )
Alexandre Julliard's avatar
Alexandre Julliard committed
126
{
127
    PSDRV_WriteSetColor(physDev, &physDev->font.color);
Alexandre Julliard's avatar
Alexandre Julliard committed
128 129
    if(physDev->font.set) return TRUE;

130 131 132 133 134 135 136 137 138 139 140 141
    switch(physDev->font.fontloc) {
    case Builtin:
        PSDRV_WriteSetBuiltinFont(physDev);
	break;
    case Download:
        PSDRV_WriteSetDownloadFont(physDev);
	break;
    default:
        ERR("fontloc = %d\n", physDev->font.fontloc);
        assert(1);
	break;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
142 143 144
    physDev->font.set = TRUE;
    return TRUE;
}