please dont rip this site
////////////////////////////////////////////////////////////
// softfont.cpp

#ifdef __WATCOMC__
#include <mem.h>
#else
#include <memory.h>
#endif
#include <stdlib.h>

#include "rasterop.h"
#include "softfont.h"
#include "util.h"


#define SWAB(w)		((w) = (((w)&0x00FF)<<8) | ((w)>>8)&0x00FF)


static void font_deletechars( FONTNODE *pf );


static FONTLIST fontlist;


FONTNODE *font_find( int id )
{
	for( FONTNODE *pf = fontlist; pf; pf = pf->next )
		if( pf->id == id )
			return pf;
	return NULL;
}

FONTNODE *font_new( int id, char *pdata, int cdata )
{
	FONTNODE *pf = font_find( id );
	if( pf )
	{
		font_deletechars( pf );
	}
	else
	{
		pf = new FONTNODE;
		if( !pf )
			return NULL;
		pf->next = fontlist;
		pf->id = id;
		memset( pf->cd, 0, sizeof(pf->cd) );
		fontlist = pf;
	}
	if( cdata >= sizeof(FONTDESC) )
	{
		memcpy( &pf->fd, pdata, sizeof(FONTDESC) );
	}
	else
	{
		memcpy( &pf->fd, pdata, cdata );
		memset( (char *)&pf->fd + cdata, 0, sizeof(FONTDESC) - cdata );
	}
	SWAB( pf->fd.fdsize );
	SWAB( pf->fd.baseline );
	SWAB( pf->fd.cellwidth );
	SWAB( pf->fd.cellheight );
	SWAB( pf->fd.symbolset );
	SWAB( pf->fd.pitch );
	SWAB( pf->fd.height );
	SWAB( pf->fd.xheight );
	SWAB( pf->fd.textheight );
	SWAB( pf->fd.textwidth );
	SWAB( pf->fd.firstcode );
	SWAB( pf->fd.lastcode );
	SWAB( pf->fd.capheight );
	swap( unsigned char, pf->fd.fontno[0], pf->fd.fontno[3] );
	swap( unsigned char, pf->fd.fontno[1], pf->fd.fontno[2] );
	SWAB( pf->fd.copyrightlen );

	return pf;
}

CHARDESC *font_newchar( int id, int charcode, char *pdata, int cdata )
{
	FONTNODE *pf = font_find( id );

	if( pf && charcode >= 0 && charcode <= 255 && cdata >= sizeof(CHARDESC) )
	{
		unsigned short w, h;

		swab( pdata + 10, (char *)&w, sizeof(unsigned short) );
		swab( pdata + 12, (char *)&h, sizeof(unsigned short) );
		if( pf->cd[charcode] )
		{
			free( pf->cd[charcode] );
			pf->cd[charcode] = NULL;
		}
		int n = sizeof(CHARDESC) + (w+7)/8 * h;
		pf->cd[charcode] = (CHARDESC *)new unsigned char[n];
		if( pf->cd[charcode] )
		{
			if( cdata >= n )
			{
				memcpy( pf->cd[charcode], pdata, n );
			}
			else
			{
				memcpy( pf->cd[charcode], pdata, cdata );
				memset( (char *)pf->cd[charcode] + cdata, 0, n - cdata );
			}
			SWAB( pf->cd[charcode]->leftoffset );
			SWAB( pf->cd[charcode]->topoffset );
			SWAB( pf->cd[charcode]->width );
			SWAB( pf->cd[charcode]->height );
			SWAB( pf->cd[charcode]->deltax );
		}
		return pf->cd[charcode];
	}
	return NULL;
}

int font_drawchar( unsigned char bits[3300][300], int x, int y, FONTNODE *pf, int charcode )
{
	if( pf && charcode >= 0 && charcode <= 255 && pf->cd[charcode] )
	{
		bit_blt( bits, x + pf->cd[charcode]->leftoffset, y - pf->cd[charcode]->topoffset,
				 (unsigned char *)(pf->cd[charcode] + 1), pf->cd[charcode]->width, pf->cd[charcode]->height );
		return pf->cd[charcode]->deltax;
	}
	return 0;
}

//////////////////////////////////////////////////////////////

void font_deletechars( FONTNODE *pf )
{
	for( int i=0; i<256; i++ )
	{
		if( pf->cd[i] )
		{
			free( pf->cd[i] );
			pf->cd[i] = NULL;
		}
	}
}

file: /Techref/language/pcl/pickle/softfont_cpp.htm, 27KB, , updated: 2001/4/5 14:54, local time: 2024/11/24 22:35,
TOP NEW HELP FIND: 
18.227.0.57:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://ecomorder.com/techref/language/pcl/pickle/softfont_cpp.htm"> Colorized Source Code</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to ecomorder.com!

 
Quick, Easy and CHEAP! RCL-1 RS232 Level Converter in a DB9 backshell
Ashley Roll has put together a really nice little unit here. Leave off the MAX232 and keep these handy for the few times you need true RS232!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .