/*
* ttfinline.c
* Copyright (C) 2002-2007, Ciprian Niculescu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* BUGS
*
* .the output file is fseek(3)-ed
* .if a charmap has been specified specified (through its index or encoding)
* only the glyphs needed for that charmap are inlined. Any charset
* indication is considered only if a charmap has been specified. One charmap
* is inlined even if none has been specified. Charset indications should be
* considered always. Charmap 0 should be inlined if no charmap has been
* specified. This is a long and boring comment.
* .there have been a bug in computing the `glyph_big_width', which consisted
* in not adding the `x_shift'. Bug was corrected, but the side effects
* (especially in fitting and outlining) were not checked.
*/
/*
* TODO
*
* .charmap selection
* .remake point size setting for height
* .add fitting shift to the output glyph advance (think it's done already)
*
* .non quantized fitting for GRAYMAP process
*
* .compression?
*
* .remove comments
*/
/*
* NOTES
*
* .the 4xX fitting works actually only for 4x4
*/
#include <config.h>
#if defined HAVE_FEATURES_H
# include <features.h>
#endif /* HAVE_FEATURES_H */
#include <ctype.h>
#if defined HAVE_ENDIAN_H
# include <endian.h>
#endif /* HAVE_ENDIAN_H */
#include <errno.h>
#include <fcntl.h>
#include <float.h>
#include <ft2build.h>
#include <getopt.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <inter.h>
#include FT_FREETYPE_H
#define __ENABLE_SPECIAL_4xx_SCALER__ 0
#define __IGNORE_NEGATIVE_LINE_GAP__ 1
#define __IGNORE_POSITIVE_DESCENT__ 1
#define __USE_MASK4S__ 1
#if defined HAVE_ENDIAN_H
# if __BYTE_ORDER == __BIG_ENDIAN
# define WORDS_BIGENDIAN 1
# endif /* __BYTE_ORDER == __BIG_ENDIAN */
#endif /* HAVE_ENDIAN_H */
#if !defined WORDS_BIGENDIAN
# define WORDS_BIGENDIAN 0
#endif /* !WORDS_BIGENDIAN */
#define Apple_Unicode 0x00000000
#define Apple_Unicode__v_1_1_ 0x00000001
#define Apple_Unicode__ISO_10646_1_1993_ \
0x00000002
#define Apple_Unicode__v_2_0_ 0x00000003
#define Apple_Roman 0x00010000
#define ISO_Ascii 0x00020000
#define ISO_7_bit 0x00020001
#define ISO_10646 0x00020002
#define UNSPECIFIED_ENCODING 0xffffffff
#define DEFAULT_POINT_SIZE 1024
#define LOAD_FLAGS FT_LOAD_DEFAULT
#undef LOAD_FLAGS
#define LOAD_FLAGS \
(FT_LOAD_MONOCHROME | FT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING)
#define BITMAP_PROCESS 0
#define GRAYMAP_PROCESS 1
#define GRAYMAP4_PROCESS 2
#if SIZEOF_VOID_P == SIZEOF_LONG
# define integral_q unsigned long
#else
# define integral_q unsigned
#endif /* SIZEOF_VOID_P == SIZEOF_LONG */
#define SHIFT_T_1(t) t##1
#define SHIFT_T_2(t) t##2
#define SHIFT_T_3(t) t##3
#define SHIFT_T_5(t) t##5
#define SHIFT_T_6(t) t##6
#define SHIFT_T_7(t) t##7
#define BF(b, c) ((b) << 002 | (c) >> 036)
#define FB(b, c) ((b) << 006 | (c) >> 032)
#define ag(b, c) ((b) << 001 | (c) >> 007)
#define bf(b, c) ((b) << 002 | (c) >> 006)
#define ce(b, c) ((b) << 003 | (c) >> 005)
#define dd(b, c) ((b) << 004 | (c) >> 004)
#define ec(b, c) ((b) << 005 | (c) >> 003)
#define fb(b, c) ((b) << 006 | (c) >> 002)
#define ga(b, c) ((b) << 007 | (c) >> 001)
#define this(e) (e)
#define class(e) (e)
#define false(e) 0
#define t_1_0_(m) triangle_1_0_((m))
#define t_1_1_(m) triangle_1_1_((m))
#define t_3_0_(m) triangle_3_0_((m))
#define t_3_1_(m) triangle_3_1_((m))
#define t_5_0_(m) triangle_5_0_((m))
#define t_5_1_(m) triangle_5_1_((m))
#define t_6_0_(m) triangle_6_0_((m))
#define t_6_1_(m) triangle_6_1_((m))
#define t_7_0_(m) triangle_7_0_((m))
#define t_7_1_(m) triangle_7_1_((m))
#define t_8_0_(m) triangle_8_0_((m))
#define t_8_1_(m) triangle_8_1_((m))
#define triangle_1_0_(m) ((m) + 0400 * 0x0)
#define triangle_1_1_(m) ((m) + 0400 * 0x1)
#define triangle_3_0_(m) ((m) + 0400 * 0x2)
#define triangle_3_1_(m) ((m) + 0400 * 0x3)
#define triangle_5_0_(m) ((m) + 0400 * 0x4)
#define triangle_5_1_(m) ((m) + 0400 * 0x5)
#define triangle_6_0_(m) ((m) + 0400 * 0x6)
#define triangle_6_1_(m) ((m) + 0400 * 0x7)
#define triangle_7_0_(m) ((m) + 0400 * 0x8)
#define triangle_7_1_(m) ((m) + 0400 * 0x9)
#define triangle_8_0_(m) ((m) + 0400 * 0xa)
#define triangle_8_1_(m) ((m) + 0400 * 0xb)
#define DEPRESS_G0________ARGS_0 \
FILE *, int, unsigned, struct process_type *, struct slide_type *, \
unsigned, unsigned, unsigned, unsigned, unsigned, unsigned, \
unsigned char *, int *
#define DEPRESS_G0________ARGS_1 \
FILE *output, int left, unsigned glyph_index, \
struct process_type *process_data, struct slide_type *slide_data, \
unsigned glyph_width, unsigned glyph_height, unsigned glyph_width_1, \
unsigned glyph_height_1, unsigned shift, unsigned glyph_size, \
unsigned char *header, int *status
#define DEPRESS_G0________ARGS_2 \
output, left, glyph_index, process_data, slide_data, glyph_width, \
glyph_height, glyph_width_1, glyph_height_1, shift, glyph_size, header, \
status
#define PROCESS_G0________ARGS_0 \
int *, int *, int *, int *, int *, int, int, unsigned *, unsigned *, \
unsigned *, unsigned, unsigned *, struct process_type *, \
struct slide_type *
#define PROCESS_G0________ARGS_1 \
int *c_advance, int *c_x_max, int *c_x_min, int *c_y_max, int *c_y_min, \
int left, int right, unsigned *c_glyph_height, unsigned *c_glyph_size, \
unsigned *c_glyph_width, unsigned glyph_index, unsigned *shift, \
struct process_type *process_data, struct slide_type *slide_data
#define PROCESS_G0________ARGS_2 \
c_advance, c_x_max, c_x_min, c_y_max, c_y_min, left, right, \
c_glyph_height, c_glyph_size, c_glyph_width, glyph_index, shift, \
process_data, slide_data
#define PROCESS_G1________ARGS_0 \
unsigned char *, unsigned, unsigned *, unsigned, unsigned, \
int, int, unsigned, unsigned *, struct process_type *, \
struct slide_type *
#define PROCESS_G1________ARGS_1 \
unsigned char *graymap, unsigned scale, unsigned *width_in_out, \
unsigned height, unsigned stride, int left, int right, unsigned index, \
unsigned *shift, struct process_type *process_data, \
struct slide_type *slide_data
#define PROCESS_G1________ARGS_2 \
graymap, scale, width_in_out, height, stride, left, right, index, shift, \
process_data, slide_data
#define PROCESS_G2________ARGS_0 \
unsigned char *, int, unsigned, unsigned, unsigned, unsigned, unsigned *, \
unsigned char *, struct slide_type *slide_data
#define PROCESS_G2________ARGS_1 \
unsigned char *graymap, int shift, unsigned scale, unsigned width, \
unsigned height, unsigned stride, unsigned *line, unsigned char *output, \
struct slide_type *slide_data
#define PROCESS_G2________ARGS_2 \
graymap, shift, scale, width, height, stride, line, output, slide_data
#define PROCESS_G2___4____ARGS_0 \
PROCESS_G2________ARGS_0, void (*) (PROCESS_S2___1____ARGS_0)
#define PROCESS_G2___4____ARGS_1 \
PROCESS_G2________ARGS_1, \
void (*process_slIce_2_4_tz