00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef __HPGS_FONT_H__
00035 #define __HPGS_FONT_H__
00036
00037 #include<hpgsmutex.h>
00038 #include<stdint.h>
00039
00040 HPGS_INTERNAL_API void hpgs_font_init();
00041 HPGS_INTERNAL_API void hpgs_font_cleanup();
00042
00043
00044 #define HPGS_FONT_MAX_TTF_TABLES 32
00045
00046 typedef struct hpgs_font_header_st hpgs_font_header;
00047 typedef struct hpgs_font_dentry_st hpgs_font_dentry;
00048 typedef struct hpgs_font_table_entry_st hpgs_font_table_entry;
00049 typedef struct hpgs_font_head_data_st hpgs_font_head_data;
00050 typedef struct hpgs_font_hhea_data_st hpgs_font_hhea_data;
00051 typedef struct hpgs_font_maxp_data_st hpgs_font_maxp_data;
00052 typedef struct hpgs_font_longHorMetrics_st hpgs_font_longHorMetrics;
00053 typedef struct hpgs_font_cmap_data_st hpgs_font_cmap_data;
00054 typedef struct hpgs_font_cmap_code_range_st hpgs_font_cmap_code_range;
00055 typedef struct hpgs_font_post_data_st hpgs_font_post_data;
00056 typedef struct hpgs_font_glyph_point_st hpgs_font_glyph_point;
00057 typedef struct hpgs_font_glyph_ref_st hpgs_font_glyph_ref;
00058 typedef struct hpgs_font_glyph_data_st hpgs_font_glyph_data;
00059 typedef struct hpgs_font_kern_pair_st hpgs_font_kern_pair;
00060
00061
00062 struct hpgs_font_table_entry_st
00063 {
00064 uint32_t tag;
00065 uint32_t checksum;
00066 uint32_t offset;
00067 uint32_t length;
00068 };
00069
00070 struct hpgs_font_head_data_st {
00071 uint32_t version;
00072 uint32_t fontRevision;
00073 uint32_t checkSumAdjustment;
00074 uint32_t magicNumber;
00075 uint16_t flags;
00076 uint16_t unitsPerEm;
00077
00078
00079 int32_t created_low;
00080 int32_t created_high;
00081 int32_t modified_low;
00082 int32_t modified_high;
00083 int16_t xMin;
00084 int16_t yMin;
00085 int16_t xMax;
00086 int16_t yMax;
00087 uint16_t macStyle;
00088 int16_t lowestRecPPEM;
00089 int16_t fontDirectionHint;
00090 int16_t indexToLocFormat;
00091 int16_t glyphDataFormat;
00092 };
00093
00094 struct hpgs_font_hhea_data_st {
00095 uint32_t version;
00096 int16_t ascent;
00097 int16_t descent;
00098 int16_t lineGap;
00099 uint16_t advanceWidthMax;
00100 int16_t minLeftSideBearing;
00101 int16_t minRightSideBearing;
00102 int16_t xMaxExtent;
00103 int16_t caretSlopeRise;
00104 int16_t caretSlopeRun;
00105 int16_t caretOffset;
00106 int16_t reserved1;
00107 int16_t reserved2;
00108 int16_t reserved3;
00109 int16_t reserved4;
00110 int16_t metricDataFormat;
00111 uint16_t numOfLongHorMetrics;
00112 };
00113
00114 struct hpgs_font_maxp_data_st {
00115 uint32_t version;
00116 uint16_t numGlyphs;
00117 uint16_t maxPoints;
00118 uint16_t maxContours;
00119 uint16_t maxComponentPoints;
00120 uint16_t maxComponentContours;
00121 uint16_t maxZones;
00122 uint16_t maxTwilightPoints;
00123 uint16_t maxStorage;
00124 uint16_t maxFunctionDefs;
00125 uint16_t maxInstructionDefs;
00126 uint16_t maxStackElements;
00127 uint16_t maxSizeOfInstructions;
00128 uint16_t maxComponentElements;
00129 uint16_t maxComponentDepth;
00130 };
00131
00132 struct hpgs_font_longHorMetrics_st
00133 {
00134 uint16_t advanceWidth;
00135 int16_t leftSideBearing;
00136 };
00137
00138 struct hpgs_font_cmap_code_range_st
00139 {
00140 uint16_t startCode;
00141 uint16_t endCode;
00142 uint16_t idDelta;
00143 uint16_t idRangeOffset;
00144 };
00145
00146 struct hpgs_font_cmap_data_st
00147 {
00148 size_t ranges_sz;
00149 hpgs_font_cmap_code_range *ranges;
00150
00151 size_t glyphIndexArray_sz;
00152 uint16_t *glyphIndexArray;
00153 };
00154
00155 struct hpgs_font_post_data_st
00156 {
00157 int32_t version;
00158 int32_t italicAngle;
00159 int16_t underlinePosition;
00160 int16_t underlineThickness;
00161 uint32_t isFixedPitch;
00162 uint32_t minMemType42;
00163 uint32_t maxMemType42;
00164 uint32_t minMemType1;
00165 uint32_t maxMemType1;
00166 uint16_t numberOfGlyphs;
00167
00168 const char **names;
00169 const char *name_data;
00170 };
00171
00172 #define HPGS_FONT_GLYPH_POINT_START 1
00173 #define HPGS_FONT_GLYPH_POINT_ONCURVE 2
00174 #define HPGS_FONT_GLYPH_POINT_CONTROL 3
00175
00176 struct hpgs_font_glyph_point_st
00177 {
00178 hpgs_point p;
00179 int flags;
00180 };
00181
00182 struct hpgs_font_glyph_ref_st
00183 {
00184 hpgs_matrix matrix;
00185 uint16_t gid;
00186 };
00187
00188 struct hpgs_font_glyph_data_st
00189 {
00190 hpgs_bbox bbox;
00191
00192 size_t points_sz;
00193 hpgs_font_glyph_point *points;
00194
00195 size_t refs_sz;
00196 size_t refs_alloc_sz;
00197 hpgs_font_glyph_ref *refs;
00198
00199 size_t begin_kern_pair;
00200 size_t end_kern_pair;
00201 };
00202
00206 struct hpgs_font_kern_pair_st
00207 {
00208 uint16_t left_gid;
00209 uint16_t right_gid;
00211 double value;
00212 };
00213
00214
00221 struct hpgs_font_header_st
00222 {
00223 int32_t version;
00224 uint16_t numtab;
00225 uint16_t searchRange;
00226 uint16_t entrySel;
00227 uint16_t rangeShift;
00229 hpgs_font_table_entry tables[HPGS_FONT_MAX_TTF_TABLES];
00231 int name_table;
00232 int head_table;
00233 int hhea_table;
00234 int maxp_table;
00235 int hmtx_table;
00236 int loca_table;
00237 int cmap_table;
00238 int post_table;
00239 int glyf_table;
00240 int kern_table;
00241 };
00242
00249 struct hpgs_font_st
00250 {
00251 hpgs_istream *is;
00253
00254 hpgs_font_header header;
00255
00256 hpgs_font_head_data head_data;
00257 hpgs_font_hhea_data hhea_data;
00258 hpgs_font_maxp_data maxp_data;
00260 hpgs_font_longHorMetrics *hmtx_data;
00263 uint32_t *loca_data;
00264 size_t loca_data_sz;
00266 hpgs_font_cmap_data cmap_data;
00267 hpgs_font_post_data post_data;
00269 hpgs_font_kern_pair *kern_data;
00270 size_t kern_data_sz;
00272 int *glyph_cache_positions;
00277 size_t n_cached_glyphs;
00278 hpgs_font_glyph_data *glyph_cache;
00280 hpgs_mutex_t mutex;
00281 size_t nref;
00282 };
00283
00288 struct hpgs_font_dentry_st {
00289
00290 char *font_name;
00291 char *filename;
00293 hpgs_font *font;
00294 };
00295
00296 #endif