From 61df977a5c1cf4e9e937aa9833d57182a105dd5f Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Mon, 28 Mar 2011 10:32:15 +0200 Subject: [PATCH] Move header-like stuff to a new header file. --- src/Makefile.am | 3 +- src/ta.h | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ttfautohint.c | 119 +------------------------------------------------ src/ttfautohint.h | 9 +++- 4 files changed, 140 insertions(+), 121 deletions(-) create mode 100644 src/ta.h diff --git a/src/Makefile.am b/src/Makefile.am index 39e6345..dc3037d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,7 +4,8 @@ AM_CPPFLAGS = $(FREETYPE_CPPFLAGS) AM_LDFLAGS = $(FREETYPE_LDFLAGS) noinst_LIBRARIES = libttfautohint.a -libttfautohint_a_SOURCES = ttfautohint.c \ +libttfautohint_a_SOURCES = ta.h \ + ttfautohint.c \ ttfautohint.h noinst_PROGRAMS = hint diff --git a/src/ta.h b/src/ta.h new file mode 100644 index 0000000..6298417 --- /dev/null +++ b/src/ta.h @@ -0,0 +1,130 @@ +/* ta.h */ + +/* written 2011 by Werner Lemberg */ + +#ifndef __TA_H__ +#define __TA_H__ + +#include + +#include +#include FT_FREETYPE_H +#include FT_TRUETYPE_TABLES_H +#include FT_TRUETYPE_TAGS_H + +#include "ttfautohint.h" + + +/* these macros convert 16bit and 32bit numbers into single bytes */ +/* using the byte order needed within SFNT files */ + +#define HIGH(x) (FT_Byte)(((x) & 0xFF00) >> 8) +#define LOW(x) ((x) & 0x00FF) + +#define BYTE1(x) (FT_Byte)(((x) & 0xFF000000UL) >> 24); +#define BYTE2(x) (FT_Byte)(((x) & 0x00FF0000UL) >> 16); +#define BYTE3(x) (FT_Byte)(((x) & 0x0000FF00UL) >> 8); +#define BYTE4(x) ((x) & 0x000000FFUL); + + +/* the length of a dummy `DSIG' table */ +#define DSIG_LEN 8 + +/* an empty slot in the table info array */ +#define MISSING (FT_ULong)~0 + +/* the offset to the loca table format in the `head' table */ +#define LOCA_FORMAT_OFFSET 51 + +/* various offsets within the `maxp' table */ +#define MAXP_MAX_ZONES_OFFSET 14 +#define MAXP_MAX_TWILIGHT_POINTS_OFFSET 16 +#define MAXP_MAX_STORAGE_OFFSET 18 +#define MAXP_MAX_FUNCTION_DEFS_OFFSET 20 +#define MAXP_MAX_INSTRUCTION_DEFS_OFFSET 22 +#define MAXP_MAX_STACK_ELEMENTS_OFFSET 24 +#define MAXP_MAX_INSTRUCTIONS_OFFSET 26 + +#define MAXP_LEN 32 + + +/* flags in composite glyph records */ +#define ARGS_ARE_WORDS 0x0001 +#define ARGS_ARE_XY_VALUES 0x0002 +#define WE_HAVE_A_SCALE 0x0008 +#define MORE_COMPONENTS 0x0020 +#define WE_HAVE_AN_XY_SCALE 0x0040 +#define WE_HAVE_A_2X2 0x0080 +#define WE_HAVE_INSTR 0x0100 + +/* flags in simple glyph records */ +#define X_SHORT_VECTOR 0x02 +#define Y_SHORT_VECTOR 0x04 +#define REPEAT 0x08 +#define SAME_X 0x10 +#define SAME_Y 0x20 + + +/* a single glyph */ +typedef struct GLYPH_ +{ + FT_ULong len; + FT_Byte* buf; +} GLYPH; + +/* a representation of the data in the `glyf' table */ +typedef struct glyf_Data_ +{ + FT_UShort num_glyphs; + GLYPH* glyphs; +} glyf_Data; + +/* an SFNT table */ +typedef struct SFNT_Table_ { + FT_ULong tag; + FT_ULong len; + FT_Byte* buf; /* the table data */ + FT_ULong offset; /* from beginning of file */ + FT_ULong checksum; + void* data; /* used e.g. for `glyf' table data */ + FT_Bool processed; +} SFNT_Table; + +/* we use indices into the SFNT table array to */ +/* represent table info records of the TTF header */ +typedef FT_ULong SFNT_Table_Info; + +/* this structure is used to model a TTF or a subfont within a TTC */ +typedef struct SFNT_ { + FT_Face face; + + SFNT_Table_Info* table_infos; + FT_ULong num_table_infos; + + /* various SFNT table indices */ + FT_ULong glyf_idx; + FT_ULong loca_idx; + FT_ULong head_idx; + FT_ULong maxp_idx; +} SFNT; + +/* our font object */ +typedef struct FONT_ { + FT_Library lib; + + FT_Byte* in_buf; + size_t in_len; + + FT_Byte* out_buf; + size_t out_len; + + SFNT* sfnts; + FT_Long num_sfnts; + + SFNT_Table* tables; + FT_ULong num_tables; +} FONT; + +#endif /* __TA_H__ */ + +/* end of ta.h */ diff --git a/src/ttfautohint.c b/src/ttfautohint.c index 701ded1..a432b63 100644 --- a/src/ttfautohint.c +++ b/src/ttfautohint.c @@ -5,128 +5,11 @@ /* This file needs FreeType 2.4.5 or newer. */ -#include #include #include #include -#include -#include FT_FREETYPE_H -#include FT_TRUETYPE_TABLES_H -#include FT_TRUETYPE_TAGS_H - -#include "ttfautohint.h" - - -/* these macros convert 16bit and 32bit numbers into single bytes */ -/* using the byte order needed within SFNT files */ - -#define HIGH(x) (FT_Byte)(((x) & 0xFF00) >> 8) -#define LOW(x) ((x) & 0x00FF) - -#define BYTE1(x) (FT_Byte)(((x) & 0xFF000000UL) >> 24); -#define BYTE2(x) (FT_Byte)(((x) & 0x00FF0000UL) >> 16); -#define BYTE3(x) (FT_Byte)(((x) & 0x0000FF00UL) >> 8); -#define BYTE4(x) ((x) & 0x000000FFUL); - - -/* the length of a dummy `DSIG' table */ -#define DSIG_LEN 8 - -/* an empty slot in the table info array */ -#define MISSING (FT_ULong)~0 - -/* the offset to the loca table format in the `head' table */ -#define LOCA_FORMAT_OFFSET 51 - -/* various offsets within the `maxp' table */ -#define MAXP_MAX_ZONES_OFFSET 14 -#define MAXP_MAX_TWILIGHT_POINTS_OFFSET 16 -#define MAXP_MAX_STORAGE_OFFSET 18 -#define MAXP_MAX_FUNCTION_DEFS_OFFSET 20 -#define MAXP_MAX_INSTRUCTION_DEFS_OFFSET 22 -#define MAXP_MAX_STACK_ELEMENTS_OFFSET 24 -#define MAXP_MAX_INSTRUCTIONS_OFFSET 26 - -#define MAXP_LEN 32 - - -/* flags in composite glyph records */ -#define ARGS_ARE_WORDS 0x0001 -#define ARGS_ARE_XY_VALUES 0x0002 -#define WE_HAVE_A_SCALE 0x0008 -#define MORE_COMPONENTS 0x0020 -#define WE_HAVE_AN_XY_SCALE 0x0040 -#define WE_HAVE_A_2X2 0x0080 -#define WE_HAVE_INSTR 0x0100 - -/* flags in simple glyph records */ -#define X_SHORT_VECTOR 0x02 -#define Y_SHORT_VECTOR 0x04 -#define REPEAT 0x08 -#define SAME_X 0x10 -#define SAME_Y 0x20 - - -/* a single glyph */ -typedef struct GLYPH_ -{ - FT_ULong len; - FT_Byte* buf; -} GLYPH; - -/* a representation of the data in the `glyf' table */ -typedef struct glyf_Data_ -{ - FT_UShort num_glyphs; - GLYPH* glyphs; -} glyf_Data; - -/* an SFNT table */ -typedef struct SFNT_Table_ { - FT_ULong tag; - FT_ULong len; - FT_Byte* buf; /* the table data */ - FT_ULong offset; /* from beginning of file */ - FT_ULong checksum; - void* data; /* used e.g. for `glyf' table data */ - FT_Bool processed; -} SFNT_Table; - -/* we use indices into the SFNT table array to */ -/* represent table info records of the TTF header */ -typedef FT_ULong SFNT_Table_Info; - -/* this structure is used to model a TTF or a subfont within a TTC */ -typedef struct SFNT_ { - FT_Face face; - - SFNT_Table_Info* table_infos; - FT_ULong num_table_infos; - - /* various SFNT table indices */ - FT_ULong glyf_idx; - FT_ULong loca_idx; - FT_ULong head_idx; - FT_ULong maxp_idx; -} SFNT; - -/* our font object */ -typedef struct FONT_ { - FT_Library lib; - - FT_Byte* in_buf; - size_t in_len; - - FT_Byte* out_buf; - size_t out_len; - - SFNT* sfnts; - FT_Long num_sfnts; - - SFNT_Table* tables; - FT_ULong num_tables; -} FONT; +#include "ta.h" static FT_Error diff --git a/src/ttfautohint.h b/src/ttfautohint.h index 064dc9a..380f3ed 100644 --- a/src/ttfautohint.h +++ b/src/ttfautohint.h @@ -2,15 +2,18 @@ /* written 2011 by Werner Lemberg */ +#ifndef __TTFAUTOHINT_H__ +#define __TTFAUTOHINT_H__ + #include -/* error type */ +/* Error type. */ typedef int TA_Error; -/* errors */ +/* Error values in addition to the FT_Err_XXX constants from FreeType. */ #define TA_Err_Ok 0x00 #define TA_Err_Invalid_Stream_Write 0x5F @@ -31,4 +34,6 @@ TA_Error TTF_autohint(FILE *in, FILE *out); +#endif /* __TTFAUTOHINT_H__ */ + /* end of ttfautohint.h */ -- 2.11.4.GIT