font.c 3.88 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 "winnls.h"
29
#include "winspool.h"
30

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

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

/***********************************************************************
37
 *           SelectFont   (WINEPS.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
38
 */
39
HFONT PSDRV_SelectFont( PHYSDEV dev, HFONT hfont )
Alexandre Julliard's avatar
Alexandre Julliard committed
40
{
41
    PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
42 43
    PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSelectFont );
    HFONT ret;
44
    LOGFONTW lf;
45
    BOOL subst = FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
46 47
    char FaceName[LF_FACESIZE];

48
    if (!GetObjectW( hfont, sizeof(lf), &lf )) return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
49

50
    TRACE("FaceName = %s Height = %d Italic = %d Weight = %d\n",
51 52
	  debugstr_w(lf.lfFaceName), lf.lfHeight, lf.lfItalic,
	  lf.lfWeight);
Alexandre Julliard's avatar
Alexandre Julliard committed
53

54
    WideCharToMultiByte(CP_ACP, 0, lf.lfFaceName, -1,
55
			FaceName, sizeof(FaceName), NULL, NULL);
56

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

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

88 89 90 91 92 93 94 95 96 97 98 99 100
    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)
101
		{
102 103
		    strcpy (FaceName,
			    (LPSTR) physDev->pi->FontSubTable[i].pData);
104 105
		    subst = TRUE;
		}
106 107 108 109 110 111 112 113
		else
		    WARN ("Facename '%s' is too long; ignoring substitution\n",
			    (LPSTR) physDev->pi->FontSubTable[i].pData);
		break;
	    }
	}
    }

114
    physDev->font.escapement = lf.lfEscapement;
115
    physDev->font.set = FALSE;
116

117 118 119 120
    if (!subst && ((ret = next->funcs->pSelectFont( next, hfont ))))
    {
        PSDRV_SelectDownloadFont(dev);
        return ret;
121
    }
122

123
    PSDRV_SelectBuiltinFont(dev, hfont, &lf, FaceName);
124 125
    next->funcs->pSelectFont( next, 0 );  /* tell next driver that we selected a device font */
    return hfont;
126
}
127

Alexandre Julliard's avatar
Alexandre Julliard committed
128 129 130
/***********************************************************************
 *           PSDRV_SetFont
 */
131
BOOL PSDRV_SetFont( PHYSDEV dev )
Alexandre Julliard's avatar
Alexandre Julliard committed
132
{
133 134 135
    PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );

    PSDRV_WriteSetColor(dev, &physDev->font.color);
Alexandre Julliard's avatar
Alexandre Julliard committed
136 137
    if(physDev->font.set) return TRUE;

138 139
    switch(physDev->font.fontloc) {
    case Builtin:
140
        PSDRV_WriteSetBuiltinFont(dev);
141 142
	break;
    case Download:
143
        PSDRV_WriteSetDownloadFont(dev);
144 145 146 147 148 149
	break;
    default:
        ERR("fontloc = %d\n", physDev->font.fontloc);
        assert(1);
	break;
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
150 151 152
    physDev->font.set = TRUE;
    return TRUE;
}