- Main Page
- Modules
- Data Structures
- Files

# hpgsfont.h

    00001 /***********************************************************************
    00002  *                                                                     *
    00003  * $Id: hpgsfont.h 489 2009-02-11 14:10:30Z softadm $
    00004  *                                                                     *
    00005  * hpgs - HPGl Script, a hpgl/2 interpreter, which uses a Postscript   *
    00006  *        API for rendering a scene and thus renders to a variety of   *
    00007  *        devices and fileformats.                                     *
    00008  *                                                                     *
    00009  * (C) 2004-2009 ev-i Informationstechnologie GmbH  http://www.ev-i.at *
    00010  *                                                                     *
    00011  * Author: Wolfgang Glas                                               *
    00012  *                                                                     *
    00013  *  hpgs is free software; you can redistribute it and/or              *
    00014  * modify it under the terms of the GNU Lesser General Public          *
    00015  * License as published by the Free Software Foundation; either        *
    00016  * version 2.1 of the License, or (at your option) any later version.  *
    00017  *                                                                     *
    00018  * hpgs is distributed in the hope that it will be useful,             *
    00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of      *
    00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   *
    00021  * Lesser General Public License for more details.                     *
    00022  *                                                                     *
    00023  * You should have received a copy of the GNU Lesser General Public    *
    00024  * License along with this library; if not, write to the               *
    00025  * Free Software  Foundation, Inc., 59 Temple Place, Suite 330,        *
    00026  * Boston, MA  02111-1307  USA                                         *
    00027  *                                                                     *
    00028  ***********************************************************************
    00029  *                                                                     *
    00030  * Private header file for ttf font support.                           *
    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 // The max. number of ttf tables to store.
    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; /* Table name */
    00065   uint32_t checksum; /* for table */
    00066   uint32_t offset;      /* to start of table in input file */
    00067   uint32_t length;   /* length of table */
    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   //int64_t  created;
    00078   //int64_t  modified;
    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; // 0x00020000 for version 2.0
    00158   int32_t italicAngle; // Italic angle in counter-clockwise degrees from the vertical. Zero for upright text, negative for text that leans to the right (forward).
    00159   int16_t  underlinePosition; // This is the suggested distance of the top of the underline from the baseline (negative values indicate below baseline).
    00160   int16_t underlineThickness; // Suggested values for the underline thickness.
    00161   uint32_t isFixedPitch; // Set to 0 if the font is proportionally spaced, non-zero if the font is not proportionally spaced (i.e. monospaced).
    00162   uint32_t minMemType42; // Minimum memory usage when an OpenType font is downloaded.
    00163   uint32_t maxMemType42; // Maximum memory usage when an OpenType font is downloaded.
    00164   uint32_t minMemType1; // Minimum memory usage when an OpenType font is downloaded as a Type 1 font.
    00165   uint32_t maxMemType1; // Maximum memory usage when an OpenType font is downloaded as a Type 1 font.
    00166   uint16_t numberOfGlyphs; // Number of glyphs (this should be the same as numGlyphs in 'maxp' table).
    00167
    00168   const char **names; // pointer to the glyph names.
    00169   const char *name_data; // the buffer holding the actual 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; //  HPGS_FONT_GLYPH_POINT_*
    00180 };
    00181
    00182 struct hpgs_font_glyph_ref_st
    00183 {
    00184   hpgs_matrix matrix; // transformation matrix
    00185   uint16_t    gid;    // the references glyph id.
    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   // the file header.
    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