BRL-CAD
vfont.h
Go to the documentation of this file.
1 /* V F O N T . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file libbu/vfont.h
21  *
22  * Header file for putting fonts up.
23  *
24  */
25 
26 #ifndef LIBBU_VFONT_H
27 #define LIBBU_VFONT_H
28 
29 #include "common.h"
30 
31 #include "bu/file.h"
32 #include "bu/endian.h"
33 #include "bu/str.h"
34 
35 #define SWAB(shrt) if (bu_byteorder() == BU_BIG_ENDIAN) (shrt=(((shrt)>>8) & 0xff) | (((shrt)<<8) & 0xff00))
36 #define SWABV(shrt) (bu_byteorder() == BU_BIG_ENDIAN) ? ((((shrt)>>8) & 0xff) | (((shrt)<<8) & 0xff00)) : (shrt)
37 
38 #define FONTBUFSZ 200
39 #define FONTNAME "times.r.6" /* Default font name. */
40 #define FONTNAMESZ 128
41 
42 #define SIGNBIT (1<<7)
43 #define SIGNMASK ~SIGNBIT
44 #define TWOSCOMP(chr) ((~(chr)&0xff)+1)
45 
46 #ifdef CHARS_UNSIGNED_ONLY
47 # define SignedChar(chr) (((chr)&SIGNBIT) ? -TWOSCOMP(chr) : (chr))
48 #else
49 # define SignedChar(chr) chr
50 #endif
51 
52 /* The structures header and dispatch define the format of a font file. */
53 struct header {
54  short magic;
55  unsigned short size;
56  short maxx;
57  short maxy;
58  short xtend;
59 };
60 
61 struct dispatch {
62  unsigned short addr;
63  short nbytes;
64  char up, down, left, right;
65  short width;
66 };
67 
68 struct vfont_file {
69  FILE *ffdes; /* File pointer for current font. */
70  off_t offset; /* Current offset to character data. */
71  struct header hdr; /* Header for font file. */
72  struct dispatch dir[256]; /* Directory for character font. */
73  int width; /* Current character width. */
74  int height; /* Current character height. */
75 };
76 
77 
78 /**
79  * get_font validates and loads the specified fontname, logging any
80  * error messages via the provided log callback.
81  *
82  * the ffdes field of the returned struct vfont_file indicates whether the
83  * load was successful or not.
84  */
85 struct vfont_file
86 get_font(const char* fontname, void (*vfont_log)(const char *fmt, ...));
87 
88 
89 #endif /* LIBBU_VFONT_H */
90 
91 /*
92  * Local Variables:
93  * mode: C
94  * tab-width: 8
95  * indent-tabs-mode: t
96  * c-file-style: "stroustrup"
97  * End:
98  * ex: shiftwidth=4 tabstop=8
99  */
Definition: vfont.h:53
char right
Definition: vfont.h:64
Definition: vfont.h:61
short width
Definition: vfont.h:65
int width
Definition: vfont.h:73
Header file for the BRL-CAD common definitions.
struct vfont_file get_font(const char *fontname, void(*vfont_log)(const char *fmt,...))
Definition: vfont.c:37
struct header hdr
Definition: vfont.h:71
char left
Definition: vfont.h:64
unsigned short addr
Definition: vfont.h:62
char down
Definition: vfont.h:64
short nbytes
Definition: vfont.h:63
unsigned short size
Definition: vfont.h:55
FILE * ffdes
Definition: vfont.h:69
int height
Definition: vfont.h:74
struct dispatch dir[256]
Definition: vfont.h:72
short maxx
Definition: vfont.h:56
short xtend
Definition: vfont.h:58
off_t offset
Definition: vfont.h:70
short maxy
Definition: vfont.h:57
char up
Definition: vfont.h:64
short magic
Definition: vfont.h:54