Back to index

texmacs  1.0.7.15
sfnt.h
Go to the documentation of this file.
00001 /*  $Header: /home/cvsroot/dvipdfmx/src/sfnt.h,v 1.10 2008/05/08 18:51:59 chofchof Exp $
00002     
00003     This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
00004 
00005     Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata,
00006     the dvipdfmx project team <dvipdfmx@project.ktug.or.kr>
00007     
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012     
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017     
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00021 */
00022 
00023 #ifndef _SFNT_H_
00024 #define _SFNT_H_
00025 
00026 #include "mfileio.h"
00027 #include "numbers.h"
00028 #include "pdfobj.h"
00029 
00030 /* Data Types as described in Apple's TTRefMan */
00031 typedef unsigned char  BYTE;
00032 typedef signed char    CHAR;
00033 typedef unsigned short USHORT;
00034 typedef signed short   SHORT;
00035 typedef unsigned long  ULONG;
00036 typedef signed long    LONG;
00037 typedef unsigned long  Fixed;   /* 16.16-bit signed fixed-point number */
00038 typedef short          FWord;
00039 typedef unsigned short uFWord;
00040 typedef short          F2Dot14; /* 16-bit signed fixed number with the low
00041                                14 bits representing fraction. */
00042 
00043 struct sfnt_table
00044 {
00045   /* table header */
00046   char   tag[4];
00047   ULONG  check_sum;
00048   ULONG  offset;
00049   ULONG  length;
00050   char  *data;   /* table data */
00051 };
00052 
00053 #define SFNT_TABLE_REQUIRED (1 << 0)
00054 
00055 struct sfnt_table_directory
00056 {
00057   ULONG   version;         /* Fixed for Win */
00058   USHORT  num_tables;
00059   USHORT  search_range;
00060   USHORT  entry_selector;
00061   USHORT  range_shift;
00062   USHORT  num_kept_tables; /* number of kept tables */
00063   char   *flags;           /* keep or omit */
00064   struct  sfnt_table *tables;
00065 };
00066 
00067 /* sfnt resource */
00068 #define SFNT_TYPE_TRUETYPE   (1 << 0)
00069 #define SFNT_TYPE_OPENTYPE   (1 << 1)
00070 #define SFNT_TYPE_POSTSCRIPT (1 << 2)
00071 #define SFNT_TYPE_TTC        (1 << 4)
00072 #define SFNT_TYPE_DFONT      (1 << 8)
00073 
00074 typedef struct
00075 {
00076   FILE  *stream;
00077   int    type;
00078   ULONG  offset;
00079   struct sfnt_table_directory *directory;
00080 } sfnt;
00081 
00082 /* Convert sfnt "fixed" type to double */
00083 #define fixed(a) ((double)((a)%0x10000L)/(double)(0x10000L) + \
00084  (a)/0x10000L - (((a)/0x10000L > 0x7fffL) ? 0x10000L : 0))
00085 
00086 /* get_***_*** from numbers.h */
00087 #define sfnt_get_byte(s)   ((BYTE)   get_unsigned_byte((s)->stream))
00088 #define sfnt_get_char(s)   ((CHAR)   get_signed_byte  ((s)->stream))
00089 #define sfnt_get_ushort(s) ((USHORT) get_unsigned_pair((s)->stream))
00090 #define sfnt_get_short(s)  ((SHORT)  get_signed_pair  ((s)->stream))
00091 #define sfnt_get_ulong(s)  ((ULONG)  get_unsigned_quad((s)->stream))
00092 #define sfnt_get_long(s)   ((LONG)   get_signed_quad  ((s)->stream))
00093 
00094 #define sfnt_seek_set(s,o)   seek_absolute((s)->stream, (o))
00095 #define sfnt_read(b,l,s)     fread((b), 1, (l), (s)->stream)
00096 
00097 extern  int  put_big_endian (void *s, LONG q, int n);
00098 
00099 #define sfnt_put_ushort(s,v) put_big_endian((s), v, 2);
00100 #define sfnt_put_short(s,v)  put_big_endian((s), v, 2);
00101 #define sfnt_put_ulong(s,v)  put_big_endian((s), v, 4);
00102 #define sfnt_put_long(s,v)   put_big_endian((s), v, 4);
00103 
00104 extern sfnt *sfnt_open  (FILE *fp);
00105 extern void  sfnt_close (sfnt *sfont);
00106 extern sfnt *dfont_open (FILE *fp, int index);
00107 
00108 /* table directory */
00109 extern int   sfnt_read_table_directory (sfnt *sfont, ULONG offset);
00110 extern ULONG sfnt_find_table_len       (sfnt *sfont, const char *tag);
00111 extern ULONG sfnt_find_table_pos       (sfnt *sfont, const char *tag);
00112 extern ULONG sfnt_locate_table         (sfnt *sfont, const char *tag);
00113 
00114 extern void  sfnt_set_table     (sfnt *sfont,
00115                              const char *tag, void *data, ULONG length);
00116 extern int   sfnt_require_table (sfnt *sfont, const char *tag, int must_exist);
00117 
00118 extern pdf_obj *sfnt_create_FontFile_stream (sfnt *sfont);
00119 
00120 #endif /* _SFNT_H_ */