summaryrefslogtreecommitdiff
path: root/fonttosfnt.h
blob: 6ad30fbf7bdc39e61f48d68cd30282b56c19f9bd (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
Copyright (c) 2002-2003 by Juliusz Chroboczek

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
AUTHORS OR COPYRIGHT HOLDERS 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.
*/
/* $XFree86: xc/programs/fonttosfnt/fonttosfnt.h,v 1.4 2003/10/24 20:38:11 tsi Exp $ */

#ifndef _FONTTOSFNT_H_
#define _FONTTOSFNT_H_ 1

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdarg.h>
#include <math.h>
#include <ft2build.h>
#include FT_FREETYPE_H

#define ROUND(x) ((double)(int)((x) + 0.5))

extern int verbose_flag;
extern int glyph_flag;
extern int metrics_flag;
extern int crop_flag;
extern int bit_aligned_flag;
extern int reencode_flag;

#define FONT_SEGMENT_SIZE 128
#define FONT_CODES 0x10000

#define FACE_BOLD 1
#define FACE_ITALIC 2
#define FACE_SYMBOL 4

#define STRIKE_BITMAP(s, i) \
  ((s)->bitmaps[(i)/FONT_SEGMENT_SIZE] ? \
   (s)->bitmaps[(i)/FONT_SEGMENT_SIZE][(i)%FONT_SEGMENT_SIZE] : \
   NULL)

#define SAME_METRICS(b1, b2) \
    ((b1)->advanceWidth == (b2)->advanceWidth && \
     (b1)->horiBearingX == (b2)->horiBearingX && \
     (b1)->horiBearingY == (b2)->horiBearingY && \
     (b1)->width == (b2)->width && \
     (b1)->height == (b2)->height)

/* bit at (x, y) of raster r with stride s */
#define BITREF(r, s, x, y) \
  (((r)[(y) * (s) + (x) / 8] & (1 << (7 - (x) % 8))) != 0)

#define ONE_HALF (1 << 15)
#define TWO_SIXTEENTH (1 << 16)

#define UNITS_PER_EM 2048

#define UNDEF 0x80000000

/* Convert a fixed-point value into FUnits */
#define FONT_UNITS(x) \
  round(((double)(x)) / TWO_SIXTEENTH * UNITS_PER_EM)
#define FONT_UNITS_FLOOR(x) \
  floor(((double)(x)) / TWO_SIXTEENTH * UNITS_PER_EM)
#define FONT_UNITS_CEIL(x) \
  ceil(((double)(x)) / TWO_SIXTEENTH * UNITS_PER_EM)

typedef struct _FontNameEntry {
    int nid;                    /* name id */
    int size;                   /* bytes in value */
    char *value;
} FontNameEntryRec, *FontNameEntryPtr;

typedef struct _Metrics {
    int height;
    int maxX;
    int minX;
    int maxY;
    int minY;
    int xHeight;
    int capHeight;
    int maxAwidth;
    int awidth;
    int ascent;
    int descent;
    int underlinePosition;
    int underlineThickness;
} MetricsRec, *MetricsPtr;

typedef struct _Font {
    int numNames;
    struct _FontNameEntry *names;
    int flags;
    int weight;                 /* as in the OS/2 table */
    int width;                  /* as in the OS/2 table */
    int italicAngle;            /* degrees c-clockwise from the vertical */
    MetricsRec pxMetrics;
    MetricsRec metrics;
    unsigned foundry;
    struct _Strike *strikes;
} FontRec, *FontPtr;

typedef struct _Strike {
    int sizeX;
    int sizeY;
    struct _Bitmap ***bitmaps;
    struct _Strike *next;
    int numSbits;
    int bitmapSizeTableLocation;
    int indexSubTableLocation;
    struct _IndexSubTable *indexSubTables;
} StrikeRec, *StrikePtr;

typedef struct _Bitmap {
    int index;
    int advanceWidth;
    int horiBearingX;
    int horiBearingY;
    int width;
    int height;
    int stride;
    char *raster;
    int location;
} BitmapRec, *BitmapPtr;

typedef struct _IndexSubTable {
    int location;
    int firstGlyphIndex;
    int lastGlyphIndex;
    int constantMetrics;
    int lastLocation;
    struct _IndexSubTable *next;
} IndexSubTableRec, *IndexSubTablePtr;

typedef struct _Cmap {
    int startCode;
    int endCode;
    int index;
    struct _Cmap *next;
    int maxindex;               /* only in the head segment*/
    int *inverse;
} CmapRec, *CmapPtr;

FontPtr makeFont(void);
StrikePtr makeStrike(FontPtr, int, int);
BitmapPtr makeBitmap(StrikePtr, int,
                     int, int, int, int, int, int,
                     unsigned char*, int);
IndexSubTablePtr makeIndexSubTables(StrikePtr, CmapPtr);
int fontIndex(FontPtr, int);
CmapPtr makeCmap(FontPtr);
int findIndex(CmapPtr, int);
int findCode(CmapPtr, int);
BitmapPtr strikeBitmapIndex(StrikePtr, CmapPtr, int);
int strikeMaxWidth(StrikePtr);
int glyphMetrics(FontPtr, int, int*, int*, int*, int*, int*);
void fontMetrics(FontPtr);
int maxIndex(CmapPtr);

int readFile(char *filename, FontPtr);
int writeFile(char *filename, FontPtr);

/* util.c */

#define PROP_ATOM 1
#define PROP_INTEGER 2
#define PROP_CARDINAL 3

char *sprintf_alloc(const char *f, ...);
char *vsprintf_alloc(const char *f, va_list args);
char *makeUTF16(const char *);
unsigned makeName(const char*);
int macTime(int *, unsigned *);
unsigned faceFoundry(FT_Face);
char *faceEncoding(FT_Face);
int faceFlags(FT_Face);
int faceIntProp(FT_Face, const char *);
int faceWeight(FT_Face);
int faceWidth(FT_Face);
int faceItalicAngle(FT_Face);
int degreesToFraction(int, int*, int*);

#endif /* _FONTTOSFNT_H_ */