143f32c10Smrg/* 243f32c10SmrgCopyright (c) 2002-2003 by Juliusz Chroboczek 343f32c10Smrg 443f32c10SmrgPermission is hereby granted, free of charge, to any person obtaining a copy 543f32c10Smrgof this software and associated documentation files (the "Software"), to deal 643f32c10Smrgin the Software without restriction, including without limitation the rights 743f32c10Smrgto use, copy, modify, merge, publish, distribute, sublicense, and/or sell 843f32c10Smrgcopies of the Software, and to permit persons to whom the Software is 943f32c10Smrgfurnished to do so, subject to the following conditions: 1043f32c10Smrg 1143f32c10SmrgThe above copyright notice and this permission notice shall be included in 1243f32c10Smrgall copies or substantial portions of the Software. 1343f32c10Smrg 1443f32c10SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1543f32c10SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1643f32c10SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1743f32c10SmrgAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1843f32c10SmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 1943f32c10SmrgOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 2043f32c10SmrgTHE SOFTWARE. 2143f32c10Smrg*/ 2243f32c10Smrg/* $XFree86: xc/programs/fonttosfnt/fonttosfnt.h,v 1.4 2003/10/24 20:38:11 tsi Exp $ */ 2343f32c10Smrg 2443f32c10Smrg#ifndef _FONTTOSFNT_H_ 2543f32c10Smrg#define _FONTTOSFNT_H_ 1 2643f32c10Smrg 2743f32c10Smrg#ifdef HAVE_CONFIG_H 2843f32c10Smrg#include "config.h" 2943f32c10Smrg#endif 3043f32c10Smrg 3143f32c10Smrg#include <stdarg.h> 32c813b494Smrg#include <math.h> 3343f32c10Smrg#include <ft2build.h> 3443f32c10Smrg#include FT_FREETYPE_H 3543f32c10Smrg 3643f32c10Smrg#define ROUND(x) ((double)(int)((x) + 0.5)) 3743f32c10Smrg 3843f32c10Smrgextern int verbose_flag; 3943f32c10Smrgextern int glyph_flag; 4043f32c10Smrgextern int metrics_flag; 4143f32c10Smrgextern int crop_flag; 4243f32c10Smrgextern int bit_aligned_flag; 4343f32c10Smrgextern int reencode_flag; 4443f32c10Smrg 4543f32c10Smrg#define FONT_SEGMENT_SIZE 128 4643f32c10Smrg#define FONT_CODES 0x10000 4743f32c10Smrg 4843f32c10Smrg#define FACE_BOLD 1 4943f32c10Smrg#define FACE_ITALIC 2 5043f32c10Smrg#define FACE_SYMBOL 4 5143f32c10Smrg 5243f32c10Smrg#define STRIKE_BITMAP(s, i) \ 5343f32c10Smrg ((s)->bitmaps[(i)/FONT_SEGMENT_SIZE] ? \ 5443f32c10Smrg (s)->bitmaps[(i)/FONT_SEGMENT_SIZE][(i)%FONT_SEGMENT_SIZE] : \ 5543f32c10Smrg NULL) 5643f32c10Smrg 5743f32c10Smrg#define SAME_METRICS(b1, b2) \ 5843f32c10Smrg ((b1)->advanceWidth == (b2)->advanceWidth && \ 5943f32c10Smrg (b1)->horiBearingX == (b2)->horiBearingX && \ 6043f32c10Smrg (b1)->horiBearingY == (b2)->horiBearingY && \ 6143f32c10Smrg (b1)->width == (b2)->width && \ 6243f32c10Smrg (b1)->height == (b2)->height) 6343f32c10Smrg 6443f32c10Smrg/* bit at (x, y) of raster r with stride s */ 6543f32c10Smrg#define BITREF(r, s, x, y) \ 6643f32c10Smrg (((r)[(y) * (s) + (x) / 8] & (1 << (7 - (x) % 8))) != 0) 6743f32c10Smrg 6843f32c10Smrg#define ONE_HALF (1 << 15) 6943f32c10Smrg#define TWO_SIXTEENTH (1 << 16) 7043f32c10Smrg 7143f32c10Smrg#define UNITS_PER_EM 2048 7243f32c10Smrg 73c813b494Smrg#define UNDEF 0x80000000 7443f32c10Smrg 7543f32c10Smrg/* Convert a fixed-point value into FUnits */ 7643f32c10Smrg#define FONT_UNITS(x) \ 77c813b494Smrg round(((double)(x)) / TWO_SIXTEENTH * UNITS_PER_EM) 7843f32c10Smrg#define FONT_UNITS_FLOOR(x) \ 79c813b494Smrg floor(((double)(x)) / TWO_SIXTEENTH * UNITS_PER_EM) 8043f32c10Smrg#define FONT_UNITS_CEIL(x) \ 81c813b494Smrg ceil(((double)(x)) / TWO_SIXTEENTH * UNITS_PER_EM) 8243f32c10Smrg 8343f32c10Smrgtypedef struct _FontNameEntry { 8443f32c10Smrg int nid; /* name id */ 8543f32c10Smrg int size; /* bytes in value */ 8643f32c10Smrg char *value; 8743f32c10Smrg} FontNameEntryRec, *FontNameEntryPtr; 8843f32c10Smrg 89c813b494Smrgtypedef struct _Metrics { 90c813b494Smrg int height; 91c813b494Smrg int size; 92c813b494Smrg int maxX; 93c813b494Smrg int minX; 94c813b494Smrg int maxY; 95c813b494Smrg int minY; 96c813b494Smrg int xHeight; 97c813b494Smrg int capHeight; 98c813b494Smrg int maxAwidth; 99c813b494Smrg int awidth; 100c813b494Smrg int ascent; 101c813b494Smrg int descent; 102c813b494Smrg int underlinePosition; 103c813b494Smrg int underlineThickness; 104c813b494Smrg} MetricsRec, *MetricsPtr; 105c813b494Smrg 10643f32c10Smrgtypedef struct _Font { 10743f32c10Smrg int numNames; 10843f32c10Smrg struct _FontNameEntry *names; 10943f32c10Smrg int flags; 11043f32c10Smrg int weight; /* as in the OS/2 table */ 11143f32c10Smrg int width; /* as in the OS/2 table */ 11243f32c10Smrg int italicAngle; /* degrees c-clockwise from the vertical */ 113c813b494Smrg MetricsRec pxMetrics; 114c813b494Smrg MetricsRec metrics; 11543f32c10Smrg unsigned foundry; 11643f32c10Smrg struct _Strike *strikes; 11743f32c10Smrg} FontRec, *FontPtr; 11843f32c10Smrg 11943f32c10Smrgtypedef struct _Strike { 12043f32c10Smrg int sizeX; 12143f32c10Smrg int sizeY; 12243f32c10Smrg struct _Bitmap ***bitmaps; 12343f32c10Smrg struct _Strike *next; 12443f32c10Smrg int numSbits; 12543f32c10Smrg int bitmapSizeTableLocation; 12643f32c10Smrg int indexSubTableLocation; 12743f32c10Smrg struct _IndexSubTable *indexSubTables; 12843f32c10Smrg} StrikeRec, *StrikePtr; 12943f32c10Smrg 13043f32c10Smrgtypedef struct _Bitmap { 13143f32c10Smrg int index; 13243f32c10Smrg int advanceWidth; 13343f32c10Smrg int horiBearingX; 13443f32c10Smrg int horiBearingY; 13543f32c10Smrg int width; 13643f32c10Smrg int height; 13743f32c10Smrg int stride; 13843f32c10Smrg char *raster; 13943f32c10Smrg int location; 14043f32c10Smrg} BitmapRec, *BitmapPtr; 14143f32c10Smrg 14243f32c10Smrgtypedef struct _IndexSubTable { 14343f32c10Smrg int location; 14443f32c10Smrg int firstGlyphIndex; 14543f32c10Smrg int lastGlyphIndex; 14643f32c10Smrg int constantMetrics; 14743f32c10Smrg int lastLocation; 14843f32c10Smrg struct _IndexSubTable *next; 14943f32c10Smrg} IndexSubTableRec, *IndexSubTablePtr; 15043f32c10Smrg 15143f32c10Smrgtypedef struct _Cmap { 15243f32c10Smrg int startCode; 15343f32c10Smrg int endCode; 15443f32c10Smrg int index; 15543f32c10Smrg struct _Cmap *next; 15643f32c10Smrg int maxindex; /* only in the head segment*/ 15743f32c10Smrg int *inverse; 15843f32c10Smrg} CmapRec, *CmapPtr; 15943f32c10Smrg 16043f32c10SmrgFontPtr makeFont(void); 16143f32c10SmrgStrikePtr makeStrike(FontPtr, int, int); 16243f32c10SmrgBitmapPtr makeBitmap(StrikePtr, int, 16343f32c10Smrg int, int, int, int, int, int, 164fbfaf8f3Smrg const unsigned char*, int); 16543f32c10SmrgIndexSubTablePtr makeIndexSubTables(StrikePtr, CmapPtr); 16643f32c10Smrgint fontIndex(FontPtr, int); 16743f32c10SmrgCmapPtr makeCmap(FontPtr); 16843f32c10Smrgint findCode(CmapPtr, int); 16943f32c10SmrgBitmapPtr strikeBitmapIndex(StrikePtr, CmapPtr, int); 170c813b494Smrgint strikeMaxWidth(StrikePtr); 17143f32c10Smrgint glyphMetrics(FontPtr, int, int*, int*, int*, int*, int*); 172c813b494Smrgvoid fontMetrics(FontPtr); 17343f32c10Smrgint maxIndex(CmapPtr); 17443f32c10Smrg 17543f32c10Smrgint readFile(char *filename, FontPtr); 17643f32c10Smrgint writeFile(char *filename, FontPtr); 17743f32c10Smrg 17843f32c10Smrg/* util.c */ 17943f32c10Smrg 18043f32c10Smrg#define PROP_ATOM 1 18143f32c10Smrg#define PROP_INTEGER 2 18243f32c10Smrg#define PROP_CARDINAL 3 18343f32c10Smrg 1846ef05171Smrgchar *sprintf_alloc(const char *f, ...); 1856ef05171Smrgchar *vsprintf_alloc(const char *f, va_list args); 1866ef05171Smrgchar *makeUTF16(const char *); 18743f32c10Smrgint macTime(int *, unsigned *); 18843f32c10Smrgunsigned faceFoundry(FT_Face); 18943f32c10Smrgchar *faceEncoding(FT_Face); 19043f32c10Smrgint faceFlags(FT_Face); 191c813b494Smrgint faceIntProp(FT_Face, const char *); 192d2f28e1bSmrgchar *faceStringProp(FT_Face, const char *); 19343f32c10Smrgint faceWeight(FT_Face); 19443f32c10Smrgint faceWidth(FT_Face); 19543f32c10Smrgint faceItalicAngle(FT_Face); 19643f32c10Smrgint degreesToFraction(int, int*, int*); 19743f32c10Smrg 198fbfaf8f3Smrgstatic inline unsigned int 199fbfaf8f3SmrgmakeName(const char *s) 200fbfaf8f3Smrg{ 201fbfaf8f3Smrg return s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]; 202fbfaf8f3Smrg} 203fbfaf8f3Smrg 20443f32c10Smrg#endif /* _FONTTOSFNT_H_ */ 205