color.c 2.92 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4 5
/*
 *	PostScript colour functions
 *
 *	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 21
 */

#include "psdrv.h"
22
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
23

24
WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
25

Alexandre Julliard's avatar
Alexandre Julliard committed
26 27 28 29 30

/**********************************************************************
 *	     PSDRV_CopyColor
 *
 * Copies col2 into col1. Return FALSE on error.
31
 */
32
BOOL PSDRV_CopyColor(PSCOLOR *col1, PSCOLOR *col2)
Alexandre Julliard's avatar
Alexandre Julliard committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46
{

    switch(col2->type) {
    case PSCOLOR_GRAY:
        col1->value.gray.i = col2->value.gray.i;
	break;

    case PSCOLOR_RGB:
        col1->value.rgb.r = col2->value.rgb.r;
	col1->value.rgb.g = col2->value.rgb.g;
	col1->value.rgb.b = col2->value.rgb.b;
	break;

    default:
47
        ERR("Unknown colour type %d\n", col1->type);
Alexandre Julliard's avatar
Alexandre Julliard committed
48 49 50 51 52 53 54 55 56 57 58 59
	return FALSE;
    }

    col1->type = col2->type;
    return TRUE;
}


/**********************************************************************
 *	     PSDRV_CreateColor
 *
 * Creates a PostScript colour from a COLORREF.
60
 * Result is grey scale if ColorDevice field of ppd is CD_False else an
Alexandre Julliard's avatar
Alexandre Julliard committed
61 62 63 64 65 66 67 68
 * rgb colour is produced.
 */
void PSDRV_CreateColor( PSDRV_PDEVICE *physDev, PSCOLOR *pscolor,
		     COLORREF wincolor )
{
    int ctype = wincolor >> 24;
    float r, g, b;

69
    if(ctype != 0 && ctype != 2)
70
        FIXME("Colour is %08x\n", wincolor);
Alexandre Julliard's avatar
Alexandre Julliard committed
71 72 73 74 75

    r = (wincolor & 0xff) / 256.0;
    g = ((wincolor >> 8) & 0xff) / 256.0;
    b = ((wincolor >> 16) & 0xff) / 256.0;

76
    if(physDev->pi->ppd->ColorDevice != CD_False) {
Alexandre Julliard's avatar
Alexandre Julliard committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
        pscolor->type = PSCOLOR_RGB;
	pscolor->value.rgb.r = r;
	pscolor->value.rgb.g = g;
	pscolor->value.rgb.b = b;
    } else {
        pscolor->type = PSCOLOR_GRAY;
	/* FIXME configurable */
	pscolor->value.gray.i = r * 0.3 + g * 0.59 + b * 0.11;
    }
    return;
}


/***********************************************************************
 *           PSDRV_SetBkColor
 */
93
COLORREF CDECL PSDRV_SetBkColor( PSDRV_PDEVICE *physDev, COLORREF color )
Alexandre Julliard's avatar
Alexandre Julliard committed
94 95
{
    PSDRV_CreateColor(physDev, &physDev->bkColor, color);
96
    return color;
Alexandre Julliard's avatar
Alexandre Julliard committed
97 98 99 100 101 102
}


/***********************************************************************
 *           PSDRV_SetTextColor
 */
103
COLORREF CDECL PSDRV_SetTextColor( PSDRV_PDEVICE *physDev, COLORREF color )
Alexandre Julliard's avatar
Alexandre Julliard committed
104 105 106
{
    PSDRV_CreateColor(physDev, &physDev->font.color, color);
    physDev->font.set = FALSE;
107
    return color;
Alexandre Julliard's avatar
Alexandre Julliard committed
108
}