⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nsample.c

📁 unix vnc 协议源码. VNC是一款远程控制工具软件.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $XConsortium: nsample.c,v 1.3 93/10/28 15:27:12 gildea Exp $ *//*Copyright 1989-1991, Bitstream Inc., Cambridge, MA.You are hereby granted permission under all Bitstream propriety rights touse, copy, modify, sublicense, sell, and redistribute the Bitstream Speedosoftware and the Bitstream Charter outline font for any purpose and withoutrestrictions; provided, that this notice is left intact on all copies of suchsoftware or font and that Bitstream's trademark is acknowledged as shown belowon all unmodified copies of such font.BITSTREAM CHARTER is a registered trademark of Bitstream Inc.BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDINGWITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR APARTICULAR PURPOSE.  BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECTDAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHERINCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTEDWITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.*//*************************** N S A M P L E . C ******************************* *                                                                           * *                 SPEEDO CHARACTER GENERATOR TEST MODULE                    * *                                                                           * * This is an illustration of what external resources are required to        * * load a Speedo outline and use the Speedo character generator to generate  * * bitmaps or scaled outlines according to the desired specification.        *                                                    * *                                                                           * * This program loads a Speedo outline, defines a set of character           * * generation specifications, generates bitmap (or outline) data for each    * * character in the font and prints them on the standard output.             * *                                                                           * * If the font buffer is too small to hold the entire font, the first        * * part of the font is loaded. Character data is then loaded dynamically     * * as required.                                                              * *                                                                           * ****************************************************************************/#include <stdio.h>#if PROTOS_AVAIL#include <stddef.h>#include <malloc.h>#include <stdlib.h>void main(int argc,char *argv[]);#elsevoid* malloc();#endif#include "speedo.h"                 /* General definition for make_bmap */#include "keys.h"                  /* Font decryption keys */#define DEBUG  0#if DEBUG#define SHOW(X) printf("X = %d\n", X)#else#define SHOW(X)#endif#define MAX_BITS  256              /* Max line length of generated bitmap *//***** GLOBAL FUNCTIONS *****//***** EXTERNAL FUNCTIONS *****//***** STATIC FUNCTIONS *****/#if PROTOS_AVAILfix31 read_4b(ufix8 FONTFAR *ptr);fix15 read_2b(ufix8 FONTFAR *ptr);#elsefix31 read_4b();fix15 read_2b();#endif/***** STATIC VARIABLES *****/static  char   pathname[100];      /* Name of font file to be output */static  ufix8 FONTFAR *font_buffer;       /* Pointer to allocated Font buffer */static  ufix8 FONTFAR *char_buffer;       /* Pointer to allocate Character buffer */static  buff_t font;               /* Buffer descriptor for font data */#if INCL_LCDstatic  buff_t char_data;          /* Buffer descriptor for character data */#endifstatic  FILE  *fdescr;             /* Speedo outline file descriptor */static  ufix16 char_index;         /* Index of character to be generated */static  ufix16 char_id;            /* Character ID */static  ufix16 minchrsz;              /* minimum character buffer size */static  ufix8  key[] =     {    KEY0,     KEY1,     KEY2,     KEY3,     KEY4,     KEY5,     KEY6,     KEY7,     KEY8    };                             /* Font decryption key */static  fix15  raswid;             /* raster width  */static  fix15  rashgt;             /* raster height */static  fix15  offhor;             /* horizontal offset from left edge of emsquare */static  fix15  offver;             /* vertical offset from baseline */static  fix15  set_width;          /* character set width */static  fix15  y_cur;              /* Current y value being generated and printed */static  char   line_of_bits[2 * MAX_BITS + 1]; /* Buffer for row of generated bits */#if INCL_MULTIDEV#if INCL_BLACK || INCL_SCREEN || INCL_2Dbitmap_t bfuncs = { sp_open_bitmap, sp_set_bitmap_bits, sp_close_bitmap };#endif#if INCL_OUTLINEoutline_t ofuncs = { sp_open_outline, sp_start_new_char, sp_start_contour, sp_curve_to,                     sp_line_to, sp_close_contour, sp_close_outline };#endif#endifufix8   temp[16];             /* temp buffer for first 16 bytes of font */FUNCTION void main(argc,argv)int argc;char *argv[];{ufix16     bytes_read;           /* Number of bytes read from font file */specs_t specs;                /* Bundle of character generation specs  */int     first_char_index;     /* Index of first character in font */int     no_layout_chars;        /* number of characters in layout */ufix32  i;ufix32  minbufsz;             /* minimum font buffer size to allocate */ufix16 cust_no;ufix8  FONTFAR *byte_ptr;#if REENTRANT_ALLOCSPEEDO_GLOBALS* sp_global_ptr;#endifif (argc != 2)     {    fprintf(stderr,"Usage: nsample {fontfile}\n\n");     exit (1);    }sprintf(pathname, argv[1]);/* Load Speedo outline file */fdescr = fopen (pathname, "rb");if (fdescr == NULL)    {    printf("****** Cannot open file %s\n", pathname);    return;                      }/* get minimum font buffer size - read first 16 bytes to get the minimum   size field from the header, then allocate buffer dynamically  */bytes_read = fread(temp, sizeof(ufix8), 16, fdescr);if (bytes_read != 16)	{	printf("****** Error on reading %s: %x\n", pathname, bytes_read);	fclose(fdescr);	return;	}#if INCL_LCDminbufsz = (ufix32)read_4b(temp+FH_FBFSZ);#elseminbufsz = (ufix32)read_4b(temp+FH_FNTSZ);if (minbufsz >= 0x10000)	{	printf("****** Cannot process fonts greater than 64K - use dynamic character loading configuration option\n");	fclose(fdescr);	return;	}#endif#if (defined(M_I86SM) || defined(M_I86MM))font_buffer = (ufix8 FONTFAR *)_fmalloc((ufix16)minbufsz);#elsefont_buffer = (ufix8 *)malloc((ufix16)minbufsz);#endif      if (font_buffer == NULL)	{	printf("****** Unable to allocate memory for font buffer\n");    fclose(fdescr);	return;	}#if DEBUGprintf("Loading font file %s\n", pathname);#endiffseek(fdescr, (ufix32)0, 0);#if (defined(M_I86SM) || (defined(M_I86MM)))byte_ptr = font_buffer;for (i=0; i< minbufsz; i++){    int ch;    ch = getc(fdescr);    if (ch == EOF)       {printf ("Premature EOF in reading font buffer, %ld bytes read\n",i);        exit(2);}    *byte_ptr=(ufix8)ch;    byte_ptr++;    }bytes_read = i;#elsebytes_read = fread((ufix8 *)font_buffer, sizeof(ufix8), (ufix16)minbufsz, fdescr);if (bytes_read == 0)    {    printf("****** Error on reading %s: %x\n", pathname, bytes_read);    fclose(fdescr);         return;    }#endif#if INCL_LCD/* now allocate minimum character buffer */minchrsz = read_2b(font_buffer+FH_CBFSZ);#if (defined(M_I86SM) || (defined(M_I86MM)))char_buffer = (ufix8 FONTFAR *)_fmalloc(minchrsz);#elsechar_buffer = (ufix8*)malloc(minchrsz);#endifif (char_buffer == NULL)	{	printf("****** Unable to allocate memory for character buffer\n");    fclose(fdescr);     	return;	}#endif#if DYNAMIC_ALLOC || REENTRANT_ALLOC	sp_global_ptr = (SPEEDO_GLOBALS *)malloc(sizeof(SPEEDO_GLOBALS));	memset(sp_global_ptr,(ufix8)0,sizeof(SPEEDO_GLOBALS));#endif/* Initialization */#if REENTRANT_ALLOCsp_reset(sp_global_ptr);                   /* Reset Speedo character generator */#elsesp_reset();                   /* Reset Speedo character generator */#endiffont.org = font_buffer;font.no_bytes = bytes_read;#if REENTRANT_ALLOCif ((cust_no=sp_get_cust_no(sp_global_ptr,font)) != CUS0 && /* NOT STANDARD ENCRYPTION */#elseif ((cust_no=sp_get_cust_no(font)) != CUS0 && /* NOT STANDARD ENCRYPTION */#endif				cust_no != 0)	{#if REENTRANT_ALLOC	printf("Unable to use fonts for customer number %d\n",				sp_get_cust_no(sp_global_ptr(font)));#else	printf("Unable to use fonts for customer number %d\n",				sp_get_cust_no(font));#endif    fclose(fdescr);	return;   	}#if INCL_KEYS#if REENTRANT_ALLOCsp_set_key(sp_global_ptr,key);              /* Set decryption key */#elsesp_set_key(key);              /* Set decryption key */#endif#endif#if INCL_MULTIDEV#if INCL_BLACK || INCL_SCREEN || INCL_2D#if REENTRANT_ALLOCsp_set_bitmap_device(sp_global_ptr,&bfuncs,sizeof(bfuncs));              /* Set decryption key */#elsesp_set_bitmap_device(&bfuncs,sizeof(bfuncs));              /* Set decryption key */#endif#endif#if INCL_OUTLINE#if REENTRANT_ALLOCsp_set_outline_device(sp_global_ptr,&ofuncs,sizeof(ofuncs));              /* Set decryption key */#elsesp_set_outline_device(&ofuncs,sizeof(ofuncs));              /* Set decryption key */#endif#endif#endiffirst_char_index = read_2b(font_buffer + FH_FCHRF);no_layout_chars = read_2b(font_buffer + FH_NCHRL);/* Set specifications for character to be generated */specs.pfont = &font;          /* Pointer to Speedo outline structure */specs.xxmult = 25L << 16;     /* Coeff of X to calculate X pixels */specs.xymult = 0L << 16;      /* Coeff of Y to calculate X pixels */specs.xoffset = 0L << 16;     /* Position of X origin */specs.yxmult = 0L << 16;      /* Coeff of X to calculate Y pixels */specs.yymult = 25L << 16;     /* Coeff of Y to calculate Y pixels */specs.yoffset = 0L << 16;     /* Position of Y origin */specs.flags = 0;         /* Mode flags */specs.out_info = NULL;   #if REENTRANT_ALLOCif (!sp_set_specs(sp_global_ptr,&specs))    /* Set character generation specifications */#elseif (!sp_set_specs(&specs))    /* Set character generation specifications */#endif    {    printf("****** Cannot set requested specs\n");    }else    {    for (i = 0; i < no_layout_chars; i++)   /* For each character in font */        {        char_index = i + first_char_index;#if REENTRANT_ALLOC        char_id = sp_get_char_id(sp_global_ptr,char_index);#else        char_id = sp_get_char_id(char_index);#endif		if (char_id != 0)			{#if REENTRANT_ALLOC	        if (!sp_make_char(sp_global_ptr,char_index))#else	        if (!sp_make_char(char_index))#endif	            {    	        printf("****** Cannot generate character %d\n", char_index);        	    }			}        }    }fclose(fdescr);     }#if INCL_LCD#if REENTRANT_ALLOCFUNCTION buff_t *sp_load_char_data(sp_global_ptr, file_offset, no_bytes, cb_offset)SPEEDO_GLOBALS *sp_global_ptr;#elseFUNCTION buff_t *sp_load_char_data(file_offset, no_bytes, cb_offset)#endiffix31    file_offset;  /* Offset in bytes from the start of the font file */fix15    no_bytes;     /* Number of bytes to be loaded */fix15    cb_offset;    /* Offset in bytes from start of char buffer *//* * Called by Speedo character generator to request that character * data be loaded from the font file into a character data buffer. * The character buffer offset is zero for all characters except elements * of compound characters. If a single buffer is allocated for character * data, cb_offset ensures that sub-character data is loaded after the * top-level compound character. * Returns a pointer to a buffer descriptor. */{int     bytes_read;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -