| 1 |
/* |
| 2 |
Copyright (c) 1998-2002 by Juliusz Chroboczek |
| 3 |
Copyright (c) 2003 After X-TT Project, All rights reserved. |
| 4 |
|
| 5 |
Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 |
of this software and associated documentation files (the "Software"), to deal |
| 7 |
in the Software without restriction, including without limitation the rights |
| 8 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
copies of the Software, and to permit persons to whom the Software is |
| 10 |
furnished to do so, subject to the following conditions: |
| 11 |
|
| 12 |
The above copyright notice and this permission notice shall be included in |
| 13 |
all copies or substantial portions of the Software. |
| 14 |
|
| 15 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 |
THE SOFTWARE. |
| 22 |
*/ |
| 23 |
|
| 24 |
/* Number of buckets in the hashtable holding faces */ |
| 25 |
#define NUMFACEBUCKETS 32 |
| 26 |
|
| 27 |
/* Glyphs are held in segments of this size */ |
| 28 |
#define FONTSEGMENTSIZE 16 |
| 29 |
|
| 30 |
/* A structure that holds bitmap order and padding info. */ |
| 31 |
|
| 32 |
typedef struct { |
| 33 |
int bit; /* bit order */ |
| 34 |
int byte; /* byte order */ |
| 35 |
int glyph; /* glyph pad size */ |
| 36 |
int scan; /* machine word size */ |
| 37 |
} FontBitmapFormatRec, *FontBitmapFormatPtr; |
| 38 |
|
| 39 |
struct FTSize_s; |
| 40 |
|
| 41 |
/* At the lowest level, there is face; FTFaces are in one-to-one |
| 42 |
correspondence with TrueType faces. Multiple instance may share |
| 43 |
the same face. */ |
| 44 |
|
| 45 |
typedef struct _FTFace { |
| 46 |
char *filename; |
| 47 |
FT_Face face; |
| 48 |
int bitmap; |
| 49 |
FT_UInt num_hmetrics; |
| 50 |
struct _FTInstance *instances; |
| 51 |
struct _FTInstance *active_instance; |
| 52 |
struct _FTFace *next; /* link to next face in bucket */ |
| 53 |
} FTFaceRec, *FTFacePtr; |
| 54 |
|
| 55 |
/* A transformation matrix with resolution information */ |
| 56 |
typedef struct _FTNormalisedTransformation { |
| 57 |
double scale; |
| 58 |
int nonIdentity; /* if 0, matrix is the identity */ |
| 59 |
FT_Matrix matrix; |
| 60 |
int xres, yres; |
| 61 |
} FTNormalisedTransformationRec, *FTNormalisedTransformationPtr; |
| 62 |
|
| 63 |
#define FT_PROPORTIONAL 0 |
| 64 |
#define FT_MONOSPACED 1 |
| 65 |
#define FT_CHARCELL 2 |
| 66 |
|
| 67 |
#define FT_AVAILABLE_UNKNOWN 0 |
| 68 |
#define FT_AVAILABLE_NO 1 |
| 69 |
#define FT_AVAILABLE_METRICS 2 |
| 70 |
#define FT_AVAILABLE_RASTERISED 3 |
| 71 |
|
| 72 |
#define FT_GET_GLYPH_BOTH 0x01 |
| 73 |
#define FT_GET_GLYPH_METRICS_ONLY 0x02 |
| 74 |
#define FT_GET_DUMMY 0x04 |
| 75 |
#define FT_FORCE_CONSTANT_SPACING 0x08 |
| 76 |
|
| 77 |
#define TTCAP_DOUBLE_STRIKE 0x0001 |
| 78 |
#define TTCAP_DOUBLE_STRIKE_MKBOLD_EDGE_LEFT 0x0002 |
| 79 |
#define TTCAP_DOUBLE_STRIKE_CORRECT_B_BOX_WIDTH 0x0008 |
| 80 |
#define TTCAP_IS_VERY_LAZY 0x0010 |
| 81 |
#define TTCAP_DISABLE_DEFAULT_VERY_LAZY 0x0020 |
| 82 |
#define TTCAP_FORCE_C_LSB_FLAG 0x0100 |
| 83 |
#define TTCAP_FORCE_C_RSB_FLAG 0x0200 |
| 84 |
#define TTCAP_FORCE_C_OUTSIDE 0x0400 |
| 85 |
#define TTCAP_MONO_CENTER 0x0800 |
| 86 |
|
| 87 |
/* TTCap */ |
| 88 |
struct TTCapInfo { |
| 89 |
long flags; |
| 90 |
double autoItalic; |
| 91 |
double scaleWidth; |
| 92 |
double scaleBBoxWidth; |
| 93 |
double scaleBBoxHeight; |
| 94 |
int doubleStrikeShift; |
| 95 |
int adjustBBoxWidthByPixel; |
| 96 |
int adjustLeftSideBearingByPixel; |
| 97 |
int adjustRightSideBearingByPixel; |
| 98 |
double scaleBitmap; |
| 99 |
int forceConstantSpacingBegin; |
| 100 |
int forceConstantSpacingEnd; |
| 101 |
/* We don't compare */ |
| 102 |
int force_c_adjust_width_by_pixel; |
| 103 |
int force_c_adjust_lsb_by_pixel; |
| 104 |
int force_c_adjust_rsb_by_pixel; |
| 105 |
int force_c_representative_metrics_char_code; |
| 106 |
double force_c_scale_b_box_width; |
| 107 |
double force_c_scale_b_box_height; |
| 108 |
double force_c_scale_lsb; |
| 109 |
double force_c_scale_rsb; |
| 110 |
double vl_slant; |
| 111 |
int lsbShiftOfBitmapAutoItalic; |
| 112 |
int rsbShiftOfBitmapAutoItalic; |
| 113 |
}; |
| 114 |
|
| 115 |
/* An instance builds on a face by specifying the transformation |
| 116 |
matrix. Multiple fonts may share the same instance. */ |
| 117 |
|
| 118 |
/* This structure caches bitmap data */ |
| 119 |
typedef struct _FTInstance { |
| 120 |
FTFacePtr face; /* the associated face */ |
| 121 |
FT_Size size; |
| 122 |
FTNormalisedTransformationRec transformation; |
| 123 |
FT_Int32 load_flags; |
| 124 |
FT_ULong strike_index; |
| 125 |
int spacing; /* actual spacing */ |
| 126 |
double pixel_size; /* to calc attributes (actual height) */ |
| 127 |
double pixel_width_unit_x; /* to calc horiz. width (cosine) */ |
| 128 |
double pixel_width_unit_y; /* to calc vert. width (cosine) */ |
| 129 |
xCharInfo *charcellMetrics; /* the header's metrics */ |
| 130 |
int averageWidth; /* the header's metrics */ |
| 131 |
long rawAverageWidth; /* the header's metrics */ |
| 132 |
double advance; /* the header's metrics */ |
| 133 |
xCharInfo *forceConstantMetrics; |
| 134 |
FontBitmapFormatRec bmfmt; |
| 135 |
unsigned nglyphs; |
| 136 |
CharInfoPtr *glyphs; /* glyphs and available are used in parallel */ |
| 137 |
int **available; |
| 138 |
struct TTCapInfo ttcap; |
| 139 |
int refcount; |
| 140 |
struct _FTInstance *next; /* link to next instance */ |
| 141 |
} FTInstanceRec, *FTInstancePtr; |
| 142 |
|
| 143 |
/* A font is an instance with coding information; fonts are in |
| 144 |
one-to-one correspondence with X fonts */ |
| 145 |
typedef struct _FTFont{ |
| 146 |
FTInstancePtr instance; |
| 147 |
FTMappingRec mapping; |
| 148 |
unsigned zero_idx; |
| 149 |
FontInfoPtr info; |
| 150 |
int nranges; |
| 151 |
CharInfoRec dummy_char; |
| 152 |
fsRange *ranges; |
| 153 |
} FTFontRec, *FTFontPtr; |
| 154 |
|
| 155 |
#ifndef NOT_IN_FTFUNCS |
| 156 |
|
| 157 |
/* Prototypes for some local functions */ |
| 158 |
|
| 159 |
static int FreeTypeOpenFace(FTFacePtr *facep, char *FTFileName, char *realFileName, int faceNumber); |
| 160 |
static void FreeTypeFreeFace(FTFacePtr face); |
| 161 |
static int |
| 162 |
FreeTypeOpenInstance(FTInstancePtr *instancep, FTFacePtr face, |
| 163 |
char *FTFileName, FTNormalisedTransformationPtr trans, |
| 164 |
int spacing, FontBitmapFormatPtr bmfmt, |
| 165 |
struct TTCapInfo *tmp_ttcap, FT_Int32 load_flags); |
| 166 |
static void FreeTypeFreeInstance(FTInstancePtr instance); |
| 167 |
static int |
| 168 |
FreeTypeInstanceGetGlyph(unsigned idx, int flags, CharInfoPtr *g, FTInstancePtr instance); |
| 169 |
static int |
| 170 |
FreeTypeInstanceGetGlyphMetrics(unsigned idx, int flags, |
| 171 |
xCharInfo **metrics, FTInstancePtr instance ); |
| 172 |
static int |
| 173 |
FreeTypeRasteriseGlyph(unsigned idx, int flags, CharInfoPtr tgp, |
| 174 |
FTInstancePtr instance, int hasMetrics ); |
| 175 |
static void FreeTypeFreeFont(FTFontPtr font); |
| 176 |
static void FreeTypeFreeXFont(FontPtr pFont, int freeProps); |
| 177 |
static void FreeTypeUnloadXFont(FontPtr pFont); |
| 178 |
static int |
| 179 |
FreeTypeAddProperties(FTFontPtr font, FontScalablePtr vals, FontInfoPtr info, |
| 180 |
char *fontname, int rawAverageWidth, Bool font_properties); |
| 181 |
static int FreeTypeFontGetGlyph(unsigned code, int flags, CharInfoPtr *g, FTFontPtr font); |
| 182 |
static int |
| 183 |
FreeTypeLoadFont(FTFontPtr font, FontInfoPtr info, FTFacePtr face, |
| 184 |
char *FTFileName, FontScalablePtr vals, FontEntryPtr entry, |
| 185 |
FontBitmapFormatPtr bmfmt, FT_Int32 load_flags, |
| 186 |
struct TTCapInfo *tmp_ttcap, char *dynStrTTCapCodeRange, |
| 187 |
int ttcap_spacing ); |
| 188 |
|
| 189 |
#endif /* NOT_IN_FTFUNCS */ |