fonttosfnt.h revision c813b494
1/*
2Copyright (c) 2002-2003 by Juliusz Chroboczek
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20THE SOFTWARE.
21*/
22/* $XFree86: xc/programs/fonttosfnt/fonttosfnt.h,v 1.4 2003/10/24 20:38:11 tsi Exp $ */
23
24#ifndef _FONTTOSFNT_H_
25#define _FONTTOSFNT_H_ 1
26
27#ifdef HAVE_CONFIG_H
28#include "config.h"
29#endif
30
31#include <stdarg.h>
32#include <math.h>
33#include <ft2build.h>
34#include FT_FREETYPE_H
35
36#define ROUND(x) ((double)(int)((x) + 0.5))
37
38extern int verbose_flag;
39extern int glyph_flag;
40extern int metrics_flag;
41extern int crop_flag;
42extern int bit_aligned_flag;
43extern int reencode_flag;
44
45#define FONT_SEGMENT_SIZE 128
46#define FONT_CODES 0x10000
47
48#define FACE_BOLD 1
49#define FACE_ITALIC 2
50#define FACE_SYMBOL 4
51
52#define STRIKE_BITMAP(s, i) \
53  ((s)->bitmaps[(i)/FONT_SEGMENT_SIZE] ? \
54   (s)->bitmaps[(i)/FONT_SEGMENT_SIZE][(i)%FONT_SEGMENT_SIZE] : \
55   NULL)
56
57#define SAME_METRICS(b1, b2) \
58    ((b1)->advanceWidth == (b2)->advanceWidth && \
59     (b1)->horiBearingX == (b2)->horiBearingX && \
60     (b1)->horiBearingY == (b2)->horiBearingY && \
61     (b1)->width == (b2)->width && \
62     (b1)->height == (b2)->height)
63
64/* bit at (x, y) of raster r with stride s */
65#define BITREF(r, s, x, y) \
66  (((r)[(y) * (s) + (x) / 8] & (1 << (7 - (x) % 8))) != 0)
67
68#define ONE_HALF (1 << 15)
69#define TWO_SIXTEENTH (1 << 16)
70
71#define UNITS_PER_EM 2048
72
73#define UNDEF 0x80000000
74
75/* Convert a fixed-point value into FUnits */
76#define FONT_UNITS(x) \
77  round(((double)(x)) / TWO_SIXTEENTH * UNITS_PER_EM)
78#define FONT_UNITS_FLOOR(x) \
79  floor(((double)(x)) / TWO_SIXTEENTH * UNITS_PER_EM)
80#define FONT_UNITS_CEIL(x) \
81  ceil(((double)(x)) / TWO_SIXTEENTH * UNITS_PER_EM)
82
83typedef struct _FontNameEntry {
84    int nid;                    /* name id */
85    int size;                   /* bytes in value */
86    char *value;
87} FontNameEntryRec, *FontNameEntryPtr;
88
89typedef struct _Metrics {
90    int height;
91    int size;
92    int maxX;
93    int minX;
94    int maxY;
95    int minY;
96    int xHeight;
97    int capHeight;
98    int maxAwidth;
99    int awidth;
100    int ascent;
101    int descent;
102    int underlinePosition;
103    int underlineThickness;
104} MetricsRec, *MetricsPtr;
105
106typedef struct _Font {
107    int numNames;
108    struct _FontNameEntry *names;
109    int flags;
110    int weight;                 /* as in the OS/2 table */
111    int width;                  /* as in the OS/2 table */
112    int italicAngle;            /* degrees c-clockwise from the vertical */
113    MetricsRec pxMetrics;
114    MetricsRec metrics;
115    unsigned foundry;
116    struct _Strike *strikes;
117} FontRec, *FontPtr;
118
119typedef struct _Strike {
120    int sizeX;
121    int sizeY;
122    struct _Bitmap ***bitmaps;
123    struct _Strike *next;
124    int numSbits;
125    int bitmapSizeTableLocation;
126    int indexSubTableLocation;
127    struct _IndexSubTable *indexSubTables;
128} StrikeRec, *StrikePtr;
129
130typedef struct _Bitmap {
131    int index;
132    int advanceWidth;
133    int horiBearingX;
134    int horiBearingY;
135    int width;
136    int height;
137    int stride;
138    char *raster;
139    int location;
140} BitmapRec, *BitmapPtr;
141
142typedef struct _IndexSubTable {
143    int location;
144    int firstGlyphIndex;
145    int lastGlyphIndex;
146    int constantMetrics;
147    int lastLocation;
148    struct _IndexSubTable *next;
149} IndexSubTableRec, *IndexSubTablePtr;
150
151typedef struct _Cmap {
152    int startCode;
153    int endCode;
154    int index;
155    struct _Cmap *next;
156    int maxindex;               /* only in the head segment*/
157    int *inverse;
158} CmapRec, *CmapPtr;
159
160FontPtr makeFont(void);
161StrikePtr makeStrike(FontPtr, int, int);
162BitmapPtr makeBitmap(StrikePtr, int,
163                     int, int, int, int, int, int,
164                     unsigned char*, int);
165IndexSubTablePtr makeIndexSubTables(StrikePtr, CmapPtr);
166int fontIndex(FontPtr, int);
167CmapPtr makeCmap(FontPtr);
168int findIndex(CmapPtr, int);
169int findCode(CmapPtr, int);
170BitmapPtr strikeBitmapIndex(StrikePtr, CmapPtr, int);
171int strikeMaxWidth(StrikePtr);
172int glyphMetrics(FontPtr, int, int*, int*, int*, int*, int*);
173void fontMetrics(FontPtr);
174int maxIndex(CmapPtr);
175
176int readFile(char *filename, FontPtr);
177int writeFile(char *filename, FontPtr);
178
179/* util.c */
180
181#define PROP_ATOM 1
182#define PROP_INTEGER 2
183#define PROP_CARDINAL 3
184
185char *sprintf_alloc(const char *f, ...);
186char *vsprintf_alloc(const char *f, va_list args);
187char *makeUTF16(const char *);
188unsigned makeName(const char*);
189int macTime(int *, unsigned *);
190unsigned faceFoundry(FT_Face);
191char *faceEncoding(FT_Face);
192int faceFlags(FT_Face);
193int faceIntProp(FT_Face, const char *);
194int faceWeight(FT_Face);
195int faceWidth(FT_Face);
196int faceItalicAngle(FT_Face);
197int degreesToFraction(int, int*, int*);
198
199#endif /* _FONTTOSFNT_H_ */
200