Added stroke fonts.

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@25 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
cjp 2002-05-18 21:42:00 +00:00
parent 7ac8537d0f
commit 0c84f4f27e
11 changed files with 6715 additions and 12 deletions

5
.gitattributes vendored
View File

@ -34,6 +34,8 @@ freeglut/freeglut/freeglut-1.3/freeglut_menu.c svn_keywords=Author+Date+Id+Revis
freeglut/freeglut/freeglut-1.3/freeglut_misc.c svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/freeglut-1.3/freeglut_overlay.c svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/freeglut-1.3/freeglut_state.c svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/freeglut-1.3/freeglut_stroke_mono_roman.c svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/freeglut-1.3/freeglut_stroke_roman.c svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/freeglut-1.3/freeglut_structure.c svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/freeglut-1.3/freeglut_teapot.c svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/freeglut-1.3/freeglut_videoresize.c svn_keywords=Author+Date+Id+Revision
@ -50,6 +52,9 @@ freeglut/freeglut/genfonts/Roman.src svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/genfonts/Roman_M.src svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/genfonts/genfonts.c svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/genfonts/genstroke.c svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/genfonts/lex.l svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/genfonts/to_stroke.y svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/genfonts/wfont.h svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/include/GL/Makefile.am svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/include/GL/freeglut.h svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/include/GL/freeglut_internal.h svn_keywords=Author+Date+Id+Revision

View File

@ -13,6 +13,8 @@ libfreeglut_1_3_la_SOURCES = freeglut_callbacks.c \
freeglut_display.c \
freeglut_font.c \
freeglut_font_data.c \
freeglut_stroke_roman.c \
freeglut_stroke_mono_roman.c \
freeglut_gamemode.c \
freeglut_geometry.c \
freeglut_init.c \

View File

@ -53,6 +53,8 @@ extern SFG_Font fgFontHelvetica12;
extern SFG_Font fgFontHelvetica18;
extern SFG_Font fgFontTimesRoman10;
extern SFG_Font fgFontTimesRoman24;
extern SFG_StrokeFont fgStrokeRoman;
extern SFG_StrokeFont fgStrokeMonoRoman;
/*
* This is for GLUT binary compatibility, as suggested by Steve Baker
@ -97,6 +99,26 @@ static SFG_Font* fghFontByID( void* font )
return 0;
}
/*
* Matches a font ID with a SFG_StrokeFont structure pointer.
* This was changed to match the GLUT header style.
*/
static SFG_StrokeFont* fghStrokeByID( void* font )
{
/*
* Try matching the font ID and the font data structure
*/
if( font == GLUT_STROKE_ROMAN ) return( &fgStrokeRoman );
if( font == GLUT_STROKE_MONO_ROMAN ) return( &fgStrokeMonoRoman );
/*
* This probably is the library user's fault
*/
fgError( "stroke font 0x%08x not found", font );
return 0;
}
/* -- INTERFACE FUNCTIONS -------------------------------------------------- */
@ -115,7 +137,7 @@ void FGAPIENTRY glutBitmapCharacter( void* fontID, int character )
/*
* Make sure the character we want to output is valid
*/
freeglut_return_if_fail( character > 0 && character < 256 );
freeglut_return_if_fail( character >= 0 && character < font->Quantity );
/*
* Then find the character we want to draw
@ -174,7 +196,7 @@ int FGAPIENTRY glutBitmapWidth( void* fontID, int character )
/*
* Make sure the character we want to output is valid
*/
freeglut_return_val_if_fail( character > 0 && character < 256, 0 );
freeglut_return_val_if_fail( character > 0 && character < font->Quantity, 0 );
/*
* Scan the font looking for the specified character
@ -187,10 +209,34 @@ int FGAPIENTRY glutBitmapWidth( void* fontID, int character )
*/
void FGAPIENTRY glutStrokeCharacter( void* fontID, int character )
{
const SFG_StrokeChar *schar;
const SFG_StrokeStrip *strip;
int i, j;
/*
* Stroke fonts are not supported yet, use a bitmap font instead
* First of all we'll need a font to use
*/
glutBitmapCharacter( GLUT_BITMAP_8_BY_13, character );
SFG_StrokeFont* font = fghStrokeByID( fontID );
/*
* Make sure the character we want to output is valid
*/
freeglut_return_if_fail( character >= 0 && character < font->Quantity );
schar = font->Characters[character];
strip = schar->Strips;
for (i = 0; i < schar->Number; i++, strip++)
{
glBegin(GL_LINE_STRIP);
for(j = 0; j < strip->Number; j++)
{
glVertex2f(strip->Vertices[j].X, strip->Vertices[j].Y);
}
glEnd();
}
glTranslatef(schar->Right, 0.0, 0.0);
}
/*
@ -199,9 +245,16 @@ void FGAPIENTRY glutStrokeCharacter( void* fontID, int character )
int FGAPIENTRY glutStrokeWidth( void* fontID, int character )
{
/*
* Stroke fonts are not supported yet, use a bitmap font instead
* First of all we'll need a font to use
*/
return( glutBitmapWidth( GLUT_BITMAP_8_BY_13, character ) );
SFG_StrokeFont* font = fghStrokeByID( fontID );
/*
* Make sure the character we want to output is valid
*/
freeglut_return_if_fail( character >= 0 && character < font->Quantity );
return (font->Characters[character]->Right);
}
/*
@ -261,13 +314,17 @@ int FGAPIENTRY glutBitmapHeight( void* fontID )
/*
* Returns the height of a stroke font
*/
int FGAPIENTRY glutStrokeHeight( void* font )
GLfloat FGAPIENTRY glutStrokeHeight( void* fontID )
{
/*
* Stroke fonts are currently not implemented.
* Using GLUT_BITMAP_8_BY_13 bitmap font instead
* See which font are we queried about
*/
return( glutBitmapHeight( GLUT_BITMAP_8_BY_13 ) );
SFG_StrokeFont* font = fghStrokeByID( fontID );
/*
* Return the character set's height
*/
return( font->Height );
}
/*** END OF FILE ***/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@
# Mono-spaced version of Roman Simplex font.
FONTNAME Roman
FONTNAME MonoRoman
TOP 119.0476
BOTTOM -33.3333
NUM_CH 128

View File

@ -0,0 +1,143 @@
%{
/* $XConsortium: lex.l,v 5.9 95/01/05 19:18:40 kaleb Exp $ */
/* $XFree86: xc/fonts/PEX/lex.l,v 3.9 1996/10/17 15:10:45 dawes Exp $ */
/*****************************************************************
Copyright (c) 1989,1990, 1991 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
Copyright (c) 1989,1990, 1991 by Sun Microsystems, Inc.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Sun Microsystems,
and the X Consortium, not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission.
SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
int string(char *, int), res_words(char *);
%}
%%
\'[^']*\' |
\"[^"]*\" return string(yytext, yyleng);
#.* ;
[ ,;\t\n\r]* /* natural dilimters */ ;
[a-zA-Z][a-zA-Z0-9_.]* {
int token;
if ( (token = res_words(yytext)) )
return token;
return string(yytext, yyleng);
}
[+-]?[0-9]+\.?[0-9]*[eE][+-]?[0-9]+ |
[+-]?[0-9]+\.[0-9]* |
\.[0-9]+ {
yylval.dval = atof((char *)yytext);
return REAL;
}
[+-]?[0-9]+#[0-9]+ {
return INTEGER;
}
[+-]?[0-9]+ {
yylval.ival = atoi((char *)yytext);
return INTEGER;
}
[()] ;
%%
int res_words(char *str)
{
static struct res_strct {
char *word;
int token;
} res_table[] = {
{"BOTTOM", BOTTOM},
{"CENTER", CENTER},
{"PROPERTIES", PROPERTIES},
{"CLOSE", CLOSE},
{"FONTNAME", FONTNAME},
{"INDEX", INDEX},
{"MAGIC", MAGIC},
{"OPEN", OPEN},
{"RIGHT", RIGHT},
{"STROKE", STROKE},
{"TOP", TOP},
{"VERTICES", VERTICES},
{"BEARING", BEARING},
{"L_SPACE", L_SPACE},
{"WIDTH", WIDTH},
{"R_SPACE", R_SPACE},
{"NUM_CH", NUM_CH},
{0, 0}
};
{
register struct res_strct *reserved;
reserved = res_table;
do
if (!strcmp(str, reserved->word))
break;
while ((++reserved)->word != 0);
return reserved->token;
}
}
int string(char *str, int n)
{
if (*str == '\"' || *str == '\'')
{
str++;
n -= 2; /* one for EOL, one for end quote */
}
if ((yylval.cval = (char *)malloc(n + 1)) != NULL)
{
strncpy(yylval.cval, str, n);
yylval.cval[n] = '\0';
return STRING;
}
else
return 0;
}

View File

@ -0,0 +1,659 @@
%{
/* $XConsortium: to_wfont.y /main/9 1996/06/11 07:38:48 kaleb $ */
/* $XFree86: xc/fonts/PEX/to_wfont.y,v 3.6.2.1 1998/12/22 11:23:04 hohndel Exp $ */
/*****************************************************************
Copyright (c) 1989,1990, 1991 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
Copyright (c) 1989,1990, 1991 by Sun Microsystems, Inc.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Sun Microsystems,
and the X Consortium, not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission.
SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#define YYMAXDEPTH 10000
#define YY_NO_UNPUT
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#ifndef L_SET
#define L_SET SEEK_SET
#endif
#include "wfont.h"
typedef struct {
float std_left, /* NCGA standard left spacing */
std_wide, /* character width */
std_rght; /* Right spacing */
} Standard;
char fname[80];
Dispatch *Table; /* dispatch table */
Standard *sp_table; /* NCGA font spacings */
Path *strokes; /* strokes of each character */
Property *property; /* property list */
struct {
int path, point, props;
} count, expect;
Path_subpath *current_path;
Font_header head; /* font header */
int tableindex; /* which character */
int yyerrno; /* error number */
int yylex(void);
void yyerror(char *);
void set_num_ch(int);
void init_properties(int);
void check_num_props(void);
void add_property(char *, char *);
void check_num_ch(void);
void wf_header(char *, float, float);
void glyph_header(int, float, float, int);
void std_space(float, float, float);
void init_path(int, int);
void add_point(float, float);
void fini(void);
void freeall(void);
void check_nstroke(void);
void check_npts(void);
%}
%union {
int nil; /* void is reserved */
int ival;
float dval;
char *cval;
}
%start font
%token <dval> REAL
%token <ival> INTEGER
%token <cval> STRING
%token <nil> BOTTOM
%token <nil> CENTER
%token <nil> CLOSE
%token <nil> FONTNAME
%token <nil> PROPERTIES
%token <nil> NUM_CH
%token <nil> INDEX
%token <nil> L_SPACE
%token <nil> MAGIC
%token <nil> OPEN
%token <nil> RIGHT
%token <nil> R_SPACE
%token <nil> STROKE
%token <nil> TOP
%token <nil> VERTICES
%token <nil> BEARING
%token <nil> WIDTH
%type <cval> fontname
%type <dval> top bottom center right
%type <ival> nstroke nvertice n_pts index num_ch
%type <ival> closeflag
%type <ival> counter
%type <dval> sp_left wide sp_right
%%
font : fontheader num_ch fontprops fontbody spacing { fini(); }|
fontheader fontbody { fini(); };
fontheader : fontname top bottom
{ wf_header($1, $2, $3); };
fontname : FONTNAME STRING
{ $$ = $2; };
top : TOP REAL { $$ = $2;};
bottom : BOTTOM REAL { $$ = $2;};
num_ch: NUM_CH INTEGER { set_num_ch($2);};
fontprops : /* empty */ | properties;
properties : PROPERTIES INTEGER { init_properties ($2); } property_list
{ check_num_props (); }
property_list : /* empty */ | single_property property_list
single_property : STRING STRING { add_property($1, $2); };
fontbody : /* empty */
| glyph fontbody;
glyph : glyph_header strokes
{ check_nstroke(); };
glyph_header : index { tableindex = $1; } sym_headinfo;
sym_headinfo : nstroke center right nvertice
{ glyph_header($1, $2, $3, $4); };
index : INDEX INTEGER { check_num_ch(); $$ = $2; };
nstroke : STROKE INTEGER { $$ = $2; expect.path = $2; };
nvertice: {$$ = 0;} | VERTICES INTEGER { $$ = $2; } ;
center : CENTER REAL{ $$ = $2; };
right : RIGHT REAL{ $$ = $2; };
strokes : /* empty */ | path strokes;
path : closeflag n_pts { init_path($1, $2); } points
{ check_npts(); }
points : /* empty */ | coord points;
closeflag : CLOSE { $$ = $1 == CLOSE; } | OPEN { $$ = $1 == CLOSE; } ;
n_pts : INTEGER { $$ = $1; };
coord : REAL REAL { add_point($1, $2); };
spacing : /* empty */
| item spacing;
item : counter {tableindex = $1;} sp_left wide sp_right
{ std_space($3, $4, $5); };
counter : BEARING INTEGER {$$ = $2;};
sp_left: L_SPACE REAL {$$ = $2;};
wide : WIDTH REAL {$$ = $2;};
sp_right: R_SPACE REAL {$$ = $2;};
%%
#define BYE(err) yyerrno = (err), yyerror(NULL)
#define ERR_BASE 1000
#define OPEN_ERROR 1001
#define WRITE_ERROR 1002
#define WRONG_NAME 1003
#define NO_MEMORY 1004
#define EXCEED_PATH 1005
#define EXCEED_POINT 1006
#define PATH_MISMATCH 1007
#define POINT_MISMATCH 1008
#define PROP_MISMATCH 1009
#define EXCEED_PROPS 1010
#include "lex.c"
char *prog;
int main(int argc, char **argv)
{
/* Usage : genstroke [-o outfile] [infile] */
char *s;
fname[0] = 0;
tableindex = 0;
head.num_ch = -1;
prog = *argv;
while (--argc > 0 && *++argv != NULL)
{
s = *argv;
if (*s++ == '-')
{
switch (*s)
{
case 'o':
if (*++argv != NULL)
{
--argc;
(void) strcpy(fname, *argv);
}
break;
default: /* ignore other options */
;
}
}
else
{
int fd;
/* standard input redirection */
fd = open(*argv, O_RDONLY);
if (fd > 0)
{
if (close(fileno(stdin)) < 0)
{
perror(prog);
return (1);
}
if (dup(fd) < 0)
{
perror(prog);
return (1);
}
close(fd);
}
}
}
return (yyparse());
}
/* set number of characters */
void set_num_ch(int num_ch)
{
yyerrno = 0;
head.num_ch = num_ch;
if (num_ch > 0)
{
Table = (Dispatch *) malloc(num_ch * sizeof(Dispatch));
sp_table = (Standard *) malloc(num_ch * sizeof(Standard));
strokes = (Path *) malloc(num_ch * sizeof(Path));
}
for (tableindex = 0; tableindex < num_ch; tableindex++)
{
Table[tableindex].center = 0.0;
Table[tableindex].right = 0.0;
Table[tableindex].offset = 0;
sp_table[tableindex].std_left = 0.0;
sp_table[tableindex].std_wide = 0.0;
sp_table[tableindex].std_rght = 0.0;
strokes[tableindex].n_subpaths = 0;
strokes[tableindex].n_vertices = 0;
strokes[tableindex].subpaths = NULL;
}
}
/* initialize the property info in the header */
void init_properties(int num_props)
{
if (num_props > 0)
{
head.properties = malloc(num_props * sizeof(Property));
head.num_props = expect.props = num_props;
}
else
{
head.properties = NULL;
head.num_props = expect.props = 0;
}
count.props = -1;
property = head.properties; /* initialize the list pointer */
}
void check_num_props(void)
{
count.props++;
if (count.props != expect.props)
BYE (PROP_MISMATCH);
}
/* add individual property info into the buffer */
void add_property(char *name, char *value)
{
/* check if the property exceeds allocated space */
if (++count.props >= head.num_props)
BYE(EXCEED_PROPS);
/* copy the strings into the buffer */
(void) strcpy(property->propname, name);
(void) strcpy(property->propvalue, value);
/* increment the property pointer */
property++;
}
void check_num_ch(void)
{
if (head.num_ch == -1)
set_num_ch(128);
}
void yyerror(char *str)
{
# define ERR_SIZE (sizeof(err_string) / sizeof(char *))
static char *err_string[] = {
"Cannot open file",
"Write fails",
"Illegal font name",
"Memory allocation failure",
"Specified number of strokes exceeded",
"Specified number of points exceeded",
"Number of strokes do not match",
"Number of points do not match",
"Number of properties do not match",
"Specified number of properties exceeded",
0};
if (str == NULL)
{
yyerrno -= ERR_BASE;
if (yyerrno > 0 && yyerrno < ERR_SIZE)
str = err_string[yyerrno-1];
else
str = "Syntax error";
}
fprintf(stderr, "%s.\n", str);
freeall();
(void) unlink(fname);
exit(1);
}
/* create wfont header */
void wf_header(char *name, float top, float bottom)
{
if (name == NULL)
BYE(WRONG_NAME);
head.top = top;
head.bottom = bottom;
head.magic = WFONT_MAGIC_PEX;
(void) strcpy(head.name, name);
free(name);
}
/* create header for each glyph */
void glyph_header(int npath, float center, float right, int npts)
{
{
register Path *strk = strokes + tableindex;
if (npath > 0) /* Don't allocate space unless the character
has strokes associated with it. */
{
strk->subpaths = malloc(npath * sizeof(Path_subpath));
if (strk->subpaths == NULL)
BYE(NO_MEMORY);
strk->type = PATH_2DF;
strk->n_subpaths = npath;
strk->n_vertices = npts;
}
else /* Just initialize the entry */
{
strk->subpaths = NULL;
strk->type = PATH_2DF;
strk->n_subpaths = 0;
strk->n_vertices = 0;
}
}
{
register Dispatch *tbl = Table + tableindex;
tbl->offset = 0;
tbl->center = center;
tbl->right = right;
}
count.path = -1; /* initialize path counter, not to
* exceed n_subpath */
}
/* create standard spacing info for each glyph */
void std_space(float l_bear, float wide, float r_bear)
{
register Standard *tbl = sp_table + tableindex;
tbl->std_left = l_bear;
tbl->std_wide = wide;
tbl->std_rght = r_bear;
}
/* initialize each sub_path */
void init_path(int close, int n)
{
register Path_subpath *path;
if (++count.path >= strokes[tableindex].n_subpaths)
BYE(EXCEED_PATH);
path = current_path = strokes[tableindex].subpaths + count.path;
path->n_pts = n;
path->closed = close;
if (n > 0)
path->pts.pt2df = malloc(n * sizeof(Path_point2df));
if (path->pts.pt2df == NULL)
BYE(NO_MEMORY);
expect.point = path->n_pts;
count.point = -1; /* initialize point counter, not to
* exceed n_pts */
}
/* accumulating points for each sub_path */
void add_point(float x, float y)
{
register Path_subpath *path;
register Path_point2df *pt_ptr;
path = current_path;
if (++count.point >= path->n_pts)
BYE(EXCEED_POINT);
pt_ptr = path->pts.pt2df + count.point;
pt_ptr->x = x;
pt_ptr->y = y;
}
/* Path_type + n_subpaths + n_vertices */
#define STROKE_HEAD (sizeof(Path_type) + sizeof(int) + sizeof(int))
/* write out file, close everything, free everything */
void fini(void)
{
/* pointers used to walk the arrays */
register Path_subpath *spath;
register Dispatch *tbl_ptr;
register Path *strptr;
FILE *fp;
int npath;
register int i, j, k;
Standard *sp_ptr;
Path_point2df *pt;
if (fname[0] == 0) /* default output file name */
{
(void) strcpy(fname, head.name);
(void) strcat(fname, ".c");
}
if ((fp = fopen(fname, "w")) == NULL)
BYE(OPEN_ERROR);
fprintf(fp, "\n/* This file has been automatically generated by the genstroke utility. */\n");
fprintf(fp, "\n#include \"../include/GL/freeglut_internal.h\"\n");
# define BY_BYE(err) fclose(fp), BYE(err)
/* adjust the characters for spacing, note max char width */
head.max_width = 0.0;
for (i = 0, tbl_ptr = Table, strptr = strokes, sp_ptr = sp_table;
i < head.num_ch; i++, tbl_ptr++, strptr++, sp_ptr++)
{
tbl_ptr->center += sp_ptr->std_left;
tbl_ptr->right += sp_ptr->std_left + sp_ptr->std_rght;
if (tbl_ptr->right > head.max_width)
head.max_width = tbl_ptr->right;
npath = strptr->n_subpaths;
if (npath > 0 || tbl_ptr->center != 0.0 ||
tbl_ptr->right != 0.0)
{
for (j = 0, spath = strptr->subpaths;
j < npath; j++, spath++)
{
for(k=0, pt = spath->pts.pt2df;
k<spath->n_pts; k++, pt++)
{
pt->x += sp_ptr->std_left;
}
}
}
}
/* write the stroke table */
for (i = 0, tbl_ptr = Table, strptr = strokes;
i < head.num_ch; i++, tbl_ptr++, strptr++)
{
npath = strptr->n_subpaths;
if (npath > 0 || tbl_ptr->center != 0.0 ||
tbl_ptr->right != 0.0)
{
fprintf(fp, "\n/* char: 0x%x */\n", i);
for (j = 0, spath = strptr->subpaths;
j < npath; j++, spath++)
{
fprintf(fp, "\nstatic const SFG_StrokeVertex ch%ust%u[] =\n{\n", i, j);
for(k = 0; k < spath->n_pts; k++)
{
fprintf(fp, " {%g,%g}%s\n",
spath->pts.pt2df[k].x,
spath->pts.pt2df[k].y,
k+1 < spath->n_pts ? "," : "");
}
fprintf(fp, "};\n");
}
fprintf(fp, "\nstatic const SFG_StrokeStrip ch%ust[] =\n{\n", i);
for (j = 0, spath = strptr->subpaths;
j < npath; j++, spath++)
{
fprintf(fp, " {%u,ch%ust%u}%s\n",
spath->n_pts, i, j,
j+1 < npath ? "," : "");
}
fprintf(fp, "};\n");
fprintf(fp, "\nstatic const SFG_StrokeChar ch%u = {%g,%u,ch%ust};\n",
i, tbl_ptr->right, npath, i);
}
}
fprintf(fp, "\nstatic const SFG_StrokeChar *chars[] =\n{\n");
for (i = 0, tbl_ptr = Table, strptr = strokes;
i < head.num_ch; )
{
for (j = 0; j < 8 && i < head.num_ch;
j++, i++, tbl_ptr++, strptr++)
{
fprintf(fp, " ");
npath = strptr->n_subpaths;
if (npath > 0 || tbl_ptr->center != 0.0 ||
tbl_ptr->right != 0.0)
fprintf(fp, "&ch%u", i);
else
fprintf(fp, "0");
if (i+1 < head.num_ch)
fprintf(fp, ",");
}
fprintf(fp, "\n");
}
fprintf(fp, "};\n");
fprintf(fp, "\nconst SFG_StrokeFont fgStroke%s = {\"%s\",%d,%g,chars};\n",
head.name, head.name, head.num_ch, head.top - head.bottom);
(void) fclose(fp);
freeall();
# undef BY_BYE
}
void freeall(void)
{
register Path *path;
register Path_subpath *spath;
register int i, j, n;
path = strokes;
for (i = 0; i < head.num_ch; i++, path++)
{
n = path->n_subpaths;
if (n <= 0)
continue;
spath = path->subpaths;
for (j = 0; j < n; j++, spath++)
if (spath->pts.pt2df != NULL)
free((char *) spath->pts.pt2df);
if (path->subpaths != NULL)
free((char *) path->subpaths);
}
if (Table)
free(Table);
if (sp_table)
free(sp_table);
if (strokes)
free(strokes);
if (head.properties != NULL)
free((char *) head.properties);
}
void check_nstroke(void)
{
count.path++;
if (expect.path != count.path)
BYE(PATH_MISMATCH);
}
void check_npts(void)
{
count.point++;
if (expect.point != count.point)
BYE(POINT_MISMATCH);
}

View File

@ -0,0 +1,164 @@
/* $XConsortium: wfont.h,v 5.2 94/04/17 20:10:09 rws Exp $ */
/*****************************************************************
Copyright (c) 1989,1990, 1991 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
Copyright (c) 1989,1990, 1991 by Sun Microsystems, Inc.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Sun Microsystems,
and the X Consortium, not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission.
SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#ifndef WFONT_INCLUDED
#define WFONT_INCLUDED
#define WFONT_MAGIC 0x813
#define WFONT_MAGIC_PLUS 0x715
#define WFONT_MAGIC_PEX 0x70686e74
#define START_PROPS 0x100
#define START_DISPATCH(_num_props) (START_PROPS + 160 * _num_props)
#define START_PATH(_num_ch_, _num_props) (START_DISPATCH(_num_props) + sizeof(Dispatch) * _num_ch_)
#define NUM_DISPATCH 128
typedef struct {
unsigned short x;
unsigned short y;
} Path_point2dpx;
typedef struct {
float x;
float y;
} Path_point2df;
typedef struct {
int x;
int y;
int z;
} Path_point3di;
typedef struct {
float x;
float y;
float z;
} Path_point3df;
typedef struct {
float x;
float y;
float z;
float w;
} Path_point4df;
typedef union {
Path_point2dpx *pt2dpx;
Path_point2df *pt2df;
Path_point3di *pt3di;
Path_point3df *pt3df;
Path_point4df *pt4df;
} Path_pt_ptr;
typedef enum {
PATH_2DF,
PATH_2DPX,
PATH_3DF,
PATH_3DI,
PATH_4DF
} Path_type;
typedef struct {
int n_pts; /* number of points in the subpath */
Path_pt_ptr pts; /* pointer to them */
int closed; /* true if the subpath is closed */
int dcmp_flag; /* flag for pgon dcmp, pgon type
and dcmped triangle type */
} Path_subpath;
typedef struct {
Path_type type; /* type of vertices in this path */
int n_subpaths; /* number of subpaths */
int n_vertices; /* total number of vertices */
Path_subpath *subpaths; /* array of subpaths */
} Path;
typedef Path *Path_handle;
typedef struct {
char propname[80]; /* font property name */
char propvalue[80]; /* font property value */
}Property;
typedef struct {
int magic; /* magic number */
char name[80]; /* name of this font */
float top, /* extreme values */
bottom,
max_width;
int num_ch; /* no. of fonts in the set */
int num_props; /* no. of font properties */
Property *properties; /* array of properties */
} Font_header;
typedef struct {
float center, /* center of the character */
right; /* right edge */
long offset; /* offset in the file of the character
* description*/
} Dispatch;
typedef struct {
float center,
right;
Path strokes;
} Ch_font;
typedef struct {
char name[80];
float top,
bottom,
max_width;
int num_ch; /* # characters in the font*/
Ch_font **ch_data;
} Phg_font;
#endif /*WFONT_INCLUDED*/

View File

@ -447,7 +447,7 @@ FGAPI int FGAPIENTRY glutStrokeWidth( void* font, int character );
FGAPI int FGAPIENTRY glutBitmapLength( void* font, const char* string );
FGAPI int FGAPIENTRY glutStrokeLength( void* font, const char* string );
FGAPI int FGAPIENTRY glutBitmapHeight( void* font );
FGAPI int FGAPIENTRY glutStrokeHeight( void* font );
FGAPI GLfloat FGAPIENTRY glutStrokeHeight( void* font );
FGAPI void FGAPIENTRY glutBitmapString( void* font, const char *string );
FGAPI void FGAPIENTRY glutStrokeString( void* font, const char *string );

View File

@ -443,6 +443,39 @@ struct tagSFG_Font
const GLubyte** Characters; /* The characters mapping */
};
/*
* The stroke font structures
*/
typedef struct tagSFG_StrokeVertex SFG_StrokeVertex;
struct tagSFG_StrokeVertex
{
GLfloat X, Y;
};
typedef struct tagSFG_StrokeStrip SFG_StrokeStrip;
struct tagSFG_StrokeStrip
{
int Number;
const SFG_StrokeVertex* Vertices;
};
typedef struct tagSFG_StrokeChar SFG_StrokeChar;
struct tagSFG_StrokeChar
{
GLfloat Right;
int Number;
const SFG_StrokeStrip* Strips;
};
typedef struct tagSFG_StrokeFont SFG_StrokeFont;
struct tagSFG_StrokeFont
{
char* Name; /* The source font name */
int Quantity; /* Number of chars in font */
GLfloat Height; /* Height of the characters */
const SFG_StrokeChar** Characters; /* The characters mapping */
};
/* -- GLOBAL VARIABLES EXPORTS --------------------------------------------- */