home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
gnu
/
gs-2.6.1.4-src.lha
/
src
/
amiga
/
gs-2.6.1.4
/
gdevwddb.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-27
|
17KB
|
615 lines
/* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises. All rights reserved.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
copies. */
/* gdevwddb.c */
/*
* Microsoft Windows 3.n driver for Ghostscript,
* using device-dependent bitmap.
* Original version by Russell Lang and Maurice Castro with help from
* Programming Windows, 2nd Ed., Charles Petzold, Microsoft Press;
* created from gdevbgi.c and gnuplot/term/win.trm 5th June 1992.
* Extensively modified by L. Peter Deutsch, Aladdin Enterprises.
*/
#include "gdevmswn.h"
/* Make sure we cast to the correct structure type. */
typedef struct gx_device_win_ddb_s gx_device_win_ddb;
#undef wdev
#define wdev ((gx_device_win_ddb *)dev)
/* Forward references */
private void near win_addtool(P2(gx_device_win_ddb *, int));
private void near win_maketools(P2(gx_device_win_ddb *, HDC));
private void near win_destroytools(P1(gx_device_win_ddb *));
/* Device procedures */
/* See gxdevice.h for the definitions of the procedures. */
private dev_proc_open_device(win_ddb_open);
private dev_proc_close_device(win_ddb_close);
private dev_proc_map_rgb_color(win_ddb_map_rgb_color);
private dev_proc_fill_rectangle(win_ddb_fill_rectangle);
private dev_proc_tile_rectangle(win_ddb_tile_rectangle);
private dev_proc_copy_mono(win_ddb_copy_mono);
private dev_proc_copy_color(win_ddb_copy_color);
private dev_proc_draw_line(win_ddb_draw_line);
/* Windows-specific procedures */
private win_proc_copy_to_clipboard(win_ddb_copy_to_clipboard);
private win_proc_repaint(win_ddb_repaint);
private win_proc_alloc_bitmap(win_ddb_alloc_bitmap);
private win_proc_free_bitmap(win_ddb_free_bitmap);
/* The device descriptor */
struct gx_device_win_ddb_s {
gx_device_common;
gx_device_win_common;
/* Handles */
HBITMAP FAR hbitmap;
HDC FAR hdcbit;
HPEN hpen, *hpens;
uint hpensize;
HBRUSH hbrush, *hbrushs;
uint hbrushsize;
#define select_brush(color)\
if (wdev->hbrush != wdev->hbrushs[color])\
{ wdev->hbrush = wdev->hbrushs[color];\
SelectObject(wdev->hdcbit,wdev->hbrush);\
}
HPALETTE hpalette;
LPLOGPALETTE lpalette;
/* A staging bitmap for copy_mono. */
/* We want one big enough to handle the standard 16x16 halftone; */
/* this is also big enough for ordinary-size characters. */
#define bmWidthBytes 4 /* must be even */
#define bmWidthBits (bmWidthBytes * 8)
#define bmHeight 32
HBITMAP FAR hbmmono;
HDC FAR hdcmono;
gx_bitmap_id bm_id;
};
private gx_device_procs win_ddb_procs = {
win_ddb_open,
gx_default_get_initial_matrix,
win_sync_output,
win_output_page,
win_ddb_close,
win_ddb_map_rgb_color,
win_map_color_rgb,
win_ddb_fill_rectangle,
win_ddb_tile_rectangle,
win_ddb_copy_mono,
win_ddb_copy_color,
win_ddb_draw_line,
gx_default_get_bits,
gx_default_get_props,
win_put_props,
gx_default_map_cmyk_color,
win_get_xfont_procs
};
gx_device_win_ddb gs_mswin_device = {
sizeof(gx_device_win_ddb),
&win_ddb_procs,
"mswin",
INITIAL_WIDTH, INITIAL_HEIGHT, /* win_open() fills these in later */
INITIAL_RESOLUTION, INITIAL_RESOLUTION, /* win_open() fills these in later */
no_margins,
dci_black_and_white,
0, /* not open yet */
2, /* nColors */
win_ddb_copy_to_clipboard,
win_ddb_repaint,
win_ddb_alloc_bitmap,
win_ddb_free_bitmap
};
/* Open the win_ddb driver */
private int
win_ddb_open(gx_device *dev)
{ int code = win_open(dev);
HDC hdc;
if ( code < 0 ) return code;
/* Create the backing bitmap. */
code = win_ddb_alloc_bitmap((gx_device_win *)dev, dev);
if ( code < 0 ) return code;
/* Create the bitmap and DC for copy_mono. */
hdc = GetDC(wdev->hwndimg);
wdev->hbmmono = CreateBitmap(bmWidthBits, bmHeight, 1, 1, NULL);
wdev->hdcmono = CreateCompatibleDC(hdc);
if ( wdev->hbmmono == NULL || wdev->hdcmono == NULL )
{ win_ddb_free_bitmap((gx_device_win *)dev);
ReleaseDC(wdev->hwndimg, hdc);
return win_nomemory();
}
SetMapMode(wdev->hdcmono, GetMapMode(hdc));
SelectObject(wdev->hdcmono, wdev->hbmmono);
wdev->bm_id = gx_no_bitmap_id;
ReleaseDC(wdev->hwndimg, hdc);
/* create palette and tools for bitmap */
if ((wdev->lpalette = win_makepalette((gx_device_win *)dev))
== (LPLOGPALETTE)NULL)
return win_nomemory();
wdev->hpalette = CreatePalette(wdev->lpalette);
(void) SelectPalette(wdev->hdcbit,wdev->hpalette,NULL);
RealizePalette(wdev->hdcbit);
win_maketools(wdev,wdev->hdcbit);
wdev->hdctext = wdev->hdcbit; /* draw text here */
return 0;
}
/* Close the win_ddb driver */
private int
win_ddb_close(gx_device *dev)
{
/* Free resources */
win_destroytools(wdev);
DeleteDC(wdev->hdcmono);
win_ddb_free_bitmap((gx_device_win *)dev);
DeleteObject(wdev->hpalette);
DeleteObject(wdev->hbmmono);
gs_free((char *)(wdev->lpalette), 1, sizeof(LOGPALETTE) +
(1<<(wdev->color_info.depth)) * sizeof(PALETTEENTRY),
"win_ddb_close");
return win_close(dev);
}
/* Map a r-g-b color to the colors available under Windows */
private gx_color_index
win_ddb_map_rgb_color(gx_device *dev, gx_color_value r, gx_color_value g,
gx_color_value b)
{ int i = wdev->nColors;
gx_color_index color = win_map_rgb_color(dev, r, g, b);
LPLOGPALETTE lipal = wdev->limgpalette;
LPLOGPALETTE lpal = wdev->lpalette;
if ( color != i ) return color;
/* We just added a color to the window palette. */
/* Add it to the bitmap palette as well. */
DeleteObject(wdev->hpalette);
lpal->palPalEntry[i].peFlags = NULL;
lpal->palPalEntry[i].peRed = lipal->palPalEntry[i].peRed;
lpal->palPalEntry[i].peGreen = lipal->palPalEntry[i].peGreen;
lpal->palPalEntry[i].peBlue = lipal->palPalEntry[i].peBlue;
lpal->palNumEntries = i+1;
wdev->hpalette = CreatePalette(lpal);
(void) SelectPalette(wdev->hdcbit,wdev->hpalette,NULL);
RealizePalette(wdev->hdcbit);
win_addtool(wdev, i);
return color;
}
/* Macro for filling a rectangle with a color. */
/* Note that it starts with a declaration. */
#define fill_rect(x, y, w, h, color)\
RECT rect;\
rect.left = x, rect.top = y;\
rect.right = x + w, rect.bottom = y + h;\
FillRect(wdev->hdcbit, &rect, wdev->hbrushs[(int)color])
/* Fill a rectangle. */
private int
win_ddb_fill_rectangle(gx_device *dev, int x, int y, int w, int h,
gx_color_index color)
{
fit_fill(dev, x, y, w, h);
/* Use PatBlt for filling. Special-case black. */
if ( color == 0 )
PatBlt(wdev->hdcbit, x, y, w, h, rop_write_0s);
else
{ select_brush((int)color);
PatBlt(wdev->hdcbit, x, y, w, h, rop_write_pattern);
}
win_update((gx_device_win *)dev);
return 0;
}
/* Tile a rectangle. If neither color is transparent, */
/* pre-clear the rectangle to color0 and just tile with color1. */
/* This is faster because of how win_copy_mono is implemented. */
/* Note that this also does the right thing for colored tiles. */
private int
win_ddb_tile_rectangle(gx_device *dev, const gx_bitmap *tile,
int x, int y, int w, int h, gx_color_index czero, gx_color_index cone,
int px, int py)
{ fit_fill(dev, x, y, w, h);
if ( czero != gx_no_color_index && cone != gx_no_color_index )
{ fill_rect(x, y, w, h, czero);
czero = gx_no_color_index;
}
if ( tile->raster == bmWidthBytes && tile->size.y <= bmHeight &&
(px | py) == 0 && cone != gx_no_color_index
)
{ /* We can do this much more efficiently */
/* by using the internal algorithms of copy_mono */
/* and gx_default_tile_rectangle. */
int width = tile->size.x;
int height = tile->size.y;
int rwidth = tile->rep_width;
int irx = ((rwidth & (rwidth - 1)) == 0 ? /* power of 2 */