home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
dev
/
cmanual-3.0.lha
/
CManual
/
Graphics
/
IncludeFonts
/
PrintFont.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-12
|
20KB
|
588 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
/* ------------------------------- ------------------ */
/* */
/* Book: ACM Graphics Amiga C Club */
/* Chapter: Include Fonts Tulevagen 22 */
/* File: PrintFont.c 181 41 LIDINGO */
/* Author: Anders Bjerin SWEDEN */
/* Date: 92-05-01 */
/* Version: 1.10 */
/* */
/* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
/* */
/* Registered members may use this program freely in their */
/* own commercial/noncommercial programs/articles. */
/* */
/***********************************************************/
/****************************************************************/
/* */
/* PrintFont loads a specified diskfont and prints the complete */
/* definition of it in 'C'. This printout can be included and */
/* compiled with your own programs, and you will then be able */
/* to use the font without having to bother about loading it. */
/* Perfect for smaller utilities and games! */
/* */
/* If you wite a large program that is using a lot of different */
/* fonts it is best to load these fonts as normal, and not */
/* include all of them with help of this utility. The advantage */
/* with normal diskfonts is that several programs can use the */
/* same fonts, and thus a lot of memory is saved. If the font */
/* is included together with the program code, no other program */
/* can use that font. However, for small utilities and games it */
/* is better to include the font rather than messing around */
/* with external files that may not exist. */
/* */
/* Many thanks to Michael Loughman who told me about his */
/* excellent idea to make a program that converts fonts into */
/* normal 'C' code. (What should we include next?) */
/* */
/* */
/* I N S T R U C T I O N S */
/* ----------------------- */
/* */
/* PrintFont converts disk fonts to 'C' code. The font may be */
/* of any size, proportional or non-proportional, and in any */
/* style. PrintFont does not handle coloured fonts, although */
/* this will soon be changed. If the font is non-proportional */
/* (fixed size), PrintFont will write two arrays, one for the */
/* font data (graphics) and one which contains information */
/* about where each character is in the font data, and how wide */
/* each bit definition of the character is. After these two */
/* arrays a complete pre-initialized TextFont structure is */
/* written. */
/* */
/* If the font is proportional (variable size), PrintFont will */
/* add two more arrays. The first array contains the width of */
/* the box in which each character is printed, while the second */
/* array contains the kerning data for each character. (The */
/* kerning value is the number of pixels each character is */
/* moved from the left left side of the box.) */
/* */
/* You need to tell PrintFont three things. First you must of */
/* course tell it which font yu want to convert. Secondly which */
/* size of the font you want. (PrintFont will try to load the */
/* font which best matches your requirements.) Finally you need */
/* to tell it what name the arrays and structure should have. */
/* (The name will be added to all arrays and the structure. For */
/* example, if you set the name to "Nice", the font data array */
/* will then be called "NiceData" and the structure "NiceFont" */
/* and so on...) */
/* */
/* This is how you call PrintFont: (without quotations) */
/* */
/* PrintFont > "file.c" "font" "size" "name" */
/* */
/* "file.c": The name of the file where all 'C' code will be */
/* stored. Note the "arrow" in front of the name, it */
/* tells DOS that all output should be stored in the */
/* file "file.c". */
/* */
/* "font": The name of the font you want to convert. */
/* */
/* "size": The size (number of points) of the font you want */
/* to convert. */
/* */
/* "name": The name of the structure and arrays. */
/* */
/* For example. To convert the font "Times" of the size 18 */
/* points to 'C' code, do like this: (The 'C' code will be */
/* stored in file "FontFile.c", and the TextFont structure */
/* will be called "NewsletterFont".) */
/* */
/* PrintFont > FontFile.c Times 18 Newsletter */
/* */
/* */
/* Once the font has been converted you can immediately start */
/* to use it. To change the RastPort's font to your new */
/* "NewsletterFont", simply call the function SetFont(). */
/* */
/* Synopsis: error = SetFont( rast_port, font ); */
/* */
/* error: (long) If SetFond could not change the RastPort's */
/* font it returns a non zero value. If it could */
/* change font successfully it returns 0. */
/* */
/* rast_port: (struct RastPort *) Pointer to the RastPort which */
/* should use the new font. */
/* */
/* font: (struct TextFont *) Pointer to the font you have */
/* converted (or opened as usual). */
/* */
/* error = SetFont( &my_rast_port, &NewsletterFont ) */
/* if( error ) */
/* printf( "Could not change font!\n" ); */
/* */
/****************************************************************/
#include <intuition/intuition.h>
struct Intuition *IntuitionBase = NULL; /* Running under Intuition. */
struct GfxBase *GfxBase = NULL; /* Move() and Text(). */
struct Library *DiskfontBase = NULL; /* OpenDiskFont() etc. */
/* The new font's attributes: */
struct TextAttr font_attr;
/* Pointer to our new font: */
struct TextFont *font = NULL;
/* Declare a pointer to a Window structure: */
struct Window *m