summaryrefslogtreecommitdiff
path: root/include/bzr.h
blob: 8faba70f3d6cf7bc71b9d55dfaff29998abaf02a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
# bzr.h: manipulate Bezier-format font files.  See ../bzr/README
#        for the precise definition of the file format.
#
# Copyright (C) 1992, 2011 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
*/



#ifndef BZR_H
#define BZR_H

#include <kpathsea/types.h>

#include "bounding-box.h"
#include "font.h"
#include "spline.h"


/* At most one output (and one input) file can be open at a time;
   calling either of these routines twice, with no intervening call to
   close the file, results in a fatal error.  */
extern boolean bzr_open_output_file (string filename);
extern boolean bzr_open_input_file (string filename);

/* If no output (or input) file is open, a fatal error results.  */
extern void bzr_close_output_file (void);
extern void bzr_close_input_file (void);

/* Fontwide information at the beginning of the file.  */
typedef struct
{
  string comment;
  real design_size;
} bzr_preamble_type;

/* The comment usually identifies the creator of the file, but it need
   not be anything in particular.  */
#define BZR_COMMENT(p) ((p).comment)

/* The design size is given in points (72.27pt=1in).  */
#define BZR_DESIGN_SIZE(p) ((p).design_size)


/* You should write the preamble before writing anything els.  */
extern void bzr_put_preamble (bzr_preamble_type);

/* You should be positioned at the beginning of the file (e.g., have
   just opened it) before calling this.  Furthermore, you should call
   this routine before calling any of the other input routines. 
   (Because this is what reads the design size of the font, and other
   values in the file are scaled by that.)  */
extern bzr_preamble_type bzr_get_preamble (void);

/* Character information.  */

typedef struct
{
  charcode_type code;
  real set_width;
  real_bounding_box_type bb;
  spline_list_array_type shape;
} bzr_char_type;


/* The character code is always in the range 0 to 255.  You can use the
   `CHARCODE' macro to access it.  */

/* The set width is given in points.  You can use the `CHAR_SET_WIDTH'
   macro to access it.  */

/* The character bounding box is not guaranteed to be the tightest
   possible, but it should be close.  The values are in points.  The
   CHAR_HEIGHT, CHAR_DEPTH, CHAR_SET_WIDTH, CHAR_BB, and related macros
   in `font.h' all work.  */

/* The shape is given as a list of lists of lines and cubic splines.
   Each element of the outer list represents a closed path.  The values
   are in points.  */
#define BZR_SHAPE(c) ((c).shape)


/* This routine writes the given character.  */
extern void bzr_put_char (bzr_char_type);

/* This routine returns the next character in the file.  If the postamble
   is next, it returns NULL.  Each spline in the `shape' element is
   guaranteed to have degree `LINEAR' or `CUBIC' (see `spline.h').  */
extern bzr_char_type *bzr_get_next_char (void);

/* This routine returns the character with the given CODE, or NULL.
   Each spline in the `shape' element is guaranteed to have degree
   `LINEAR' or `CUBIC' (see `spline.h').  */
extern bzr_char_type *bzr_get_char (one_byte code);

/* More fontwide information, this at the end of the file.  */

typedef struct
{
  real_bounding_box_type font_bb;
  one_byte nchars;
} bzr_postamble_type;

/* The font bounding box is guaranteed to be the tightest possible,
   given the character bounding box.  The values are in points.  */
#define BZR_FONT_BB(p) ((p).font_bb)

/* The total number of characters (possibly zero) in the font.  */
#define BZR_NCHARS(p) ((p).nchars)


/* The postamble must be written last; the library itself determines the
   font bounding box, based on the character bounding boxes, so you do
   not supply it as an argument.  */
extern void bzr_put_postamble (void);

/* And this reads the postamble back.  You should be positioned at the
   postamble (e.g., `bzr_get_char' should have just returned NULL) before
   calling this.  */
extern bzr_postamble_type bzr_get_postamble (void);

#endif /* not BZR_H */