* Copyright (c) 1991 The Regents of the University of California.
* This code is derived from software contributed to the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory and to the University
* of California at Berkeley by Jef Poskanzer.
* %sccs.include.redist.c%
* @(#)raster_text.c 7.2 (Berkeley) %G%
* from: $Header: raster_text.c,v 1.15 92/06/17 08:14:45 torek Exp $
* Text routines for raster library.
#include <sparc/rcons/raster.h>
#define NEW(size) malloc(size, M_DEVBUF, M_NOWAIT)
#include <sparc/rcons/raster.h>
#define NEW(size) malloc(size)
/* Draws text. Returns 0 on success, -1 on failure. */
raster_text( r
, x
, y
, rop
, rf
, text
)
register struct raster
* r
;
return raster_textn( r
, x
, y
, rop
, rf
, text
, strlen( text
) );
/* Draws n characters of text. Returns 0 on success, -1 on failure. */
raster_textn( r
, x
, y
, rop
, rf
, text
, n
)
register struct raster
* r
;
/* Check whether we can avoid clipping. */
if ( rf
->flags
& RASFONT_FIXEDWIDTH
&&
rf
->flags
& RASFONT_NOVERTICALMOVEMENT
)
/* This font is well-behaved, we can compute the extent cheaply. */
if ( x
+ c
->homex
< 0 || y
+ c
->homey
< 0 ||
x
+ c
->homex
+ n
* c
->nextx
> r
->width
||
y
+ c
->homey
+ charrast
->height
> r
->height
)
/* Got to step through the string to compute the extent. */
for ( i
= 0, x1
= x
, y1
= y
;
++i
, x1
+= c
->nextx
, y1
+= c
->nexty
)
c
= &(rf
->chars
[text
[i
]]);
if ( charrast
!= (struct raster
*) 0 )
if ( x1
+ c
->homex
< 0 || y1
+ c
->homey
< 0 ||
x1
+ c
->homex
+ charrast
->width
> r
->width
||
y1
+ c
->homey
+ charrast
->height
> r
->height
)
/* Now display the text. */
for ( i
= 0, x1
= x
, y1
= y
;
++i
, x1
+= c
->nextx
, y1
+= c
->nexty
)
if ( charrast
!= (struct raster
*) 0 )
/* Initialize color font cache if necessary. */
if ( rf
->cache
== (struct raster_fontcache
*) -1 )
rf
->cache
= (struct raster_fontcache
*)
NEW( sizeof(struct raster_fontcache
) );
if ( rf
->cache
!= (struct raster_fontcache
*) 0 )
for ( c
= 0; c
< 256; ++c
)
rf
->cache
->cr
[c
] = (struct raster
*) 0;
if ( rf
->cache
!= (struct raster_fontcache
*) 0 )
color
= RAS_GETCOLOR( rop
);
/* Is this character cached yet? */
if ( cr
!= (struct raster
*) 0 )
/* Yes, but is it the right color? */
if ( rf
->cache
->color
[ch
] == color
)
/* Yes - switch rasters. */
cr
, 0, 0, charrast
->width
,
charrast
->height
, rop
, charrast
, 0, 0 ) == 0 )
rf
->cache
->color
[ch
] = color
;
/* It's not cached, so cache it. */
charrast
->width
, charrast
->height
, 8 );
if ( cr
!= (struct raster
*) 0 )
cr
, 0, 0, charrast
->width
, charrast
->height
,
rop
, charrast
, 0, 0 ) == 0 )
rf
->cache
->color
[ch
] = color
;
charrast
= rf
->cache
->cr
[ch
] = cr
;
#endif /*COLORFONT_CACHE*/
r
, thisx
, thisy
, charrast
->width
, charrast
->height
,
rop
, charrast
, phase
, 0 ) < 0 )
r
, thisx
, thisy
, charrast
->width
, charrast
->height
,
rop
, charrast
, phase
, 0 ) < 0 )
/* Allocates a raster. Returns (struct raster*) 0 on failure. */
raster_alloc( width
, height
, depth
)
int width
, height
, depth
;
if ( width
<= 0 || height
<= 0 || ( depth
!= 1 && depth
!= 8 ) )
return (struct raster
*) 0;
linelongs
= ( ( width
* depth
+ 31 ) >> 5 );
NEW( sizeof(struct raster
) + height
* linelongs
* sizeof(u_long
));
if ( r
== (struct raster
*) 0 )
return (struct raster
*) 0;
r
->linelongs
= linelongs
;
r
->pixels
= (u_long
*) (r
+ 1);