From bf328bc606b6193838f501fc306f3ac7c1e81051 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Tue, 21 Jun 2011 13:33:55 +0200 Subject: [PATCH] Start with a more flexible API. --- src/hint.c | 2 +- src/ttfautohint.c | 38 +++++++++++--------- src/ttfautohint.h | 102 ++++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 113 insertions(+), 29 deletions(-) diff --git a/src/hint.c b/src/hint.c index f5708a0..5875248 100644 --- a/src/hint.c +++ b/src/hint.c @@ -50,7 +50,7 @@ main(int argc, exit(EXIT_FAILURE); } - error = TTF_autohint((void*)in, (void*)out, NULL); + error = TTF_autohint("in-file, out-file", in, out); if (error) { fprintf(stderr, "Error code `0x%02x' while autohinting font\n", error); diff --git a/src/ttfautohint.c b/src/ttfautohint.c index 77862fa..3a5d1f4 100644 --- a/src/ttfautohint.c +++ b/src/ttfautohint.c @@ -12,12 +12,9 @@ static FT_Error -TA_font_read(FONT* font, - void* in) +TA_font_file_read(FONT* font, + FILE* in_file) { - /* XXX provide different means to read a font */ - FILE* in_file = (FILE*)in; - fseek(in_file, 0, SEEK_END); font->in_len = ftell(in_file); fseek(in_file, 0, SEEK_SET); @@ -1327,14 +1324,10 @@ Err: static FT_Error -TA_font_write(FONT* font, - void* out) +TA_font_file_write(FONT* font, + FILE* out_file) { - /* XXX provide different means to write a font */ - FILE* out_font = (FILE*)out; - - - if (fwrite(font->out_buf, 1, font->out_len, out_font) != font->out_len) + if (fwrite(font->out_buf, 1, font->out_len, out_file) != font->out_len) return TA_Err_Invalid_Stream_Write; return TA_Err_Ok; @@ -1403,20 +1396,31 @@ TA_font_unload(FONT* font) TA_Error -TTF_autohint(void* in, - void* out, - const char* options) +TTF_autohint(const char* options, + ...) { + va_list ap; + FONT* font; FT_Error error; FT_Long i; + FILE* in_file; + FILE* out_file; + + /* XXX */ + va_start(ap, options); + + in_file = va_arg(ap, FILE*); + out_file = va_arg(ap, FILE*); + + va_end(ap); font = (FONT*)calloc(1, sizeof (FONT)); if (!font) return FT_Err_Out_Of_Memory; - error = TA_font_read(font, in); + error = TA_font_file_read(font, in_file); if (error) goto Err; @@ -1495,7 +1499,7 @@ TTF_autohint(void* in, if (error) goto Err; - error = TA_font_write(font, out); + error = TA_font_file_write(font, out_file); if (error) goto Err; diff --git a/src/ttfautohint.h b/src/ttfautohint.h index ae6b0cf..1096fe8 100644 --- a/src/ttfautohint.h +++ b/src/ttfautohint.h @@ -5,7 +5,7 @@ #ifndef __TTFAUTOHINT_H__ #define __TTFAUTOHINT_H__ -#include +#include /* Error type. */ @@ -25,25 +25,105 @@ typedef int TA_Error; * `prep', `fpgm', `cvt ', and `glyf'), and write a new TrueType font with * new bytecode based on the autohinting of the FreeType library. * - * It expects three arguments: + * It expects a format string `options' and a variable number of arguments, + * depending on the fields in `options'. The fields are comma separated; + * whitespace within the format string is not significant, a trailing comma + * is ignored. Fields are parsed from left to right; if a field occurs + * multiple times, the last field's argument wins. Depending on the field, + * zero or one argument is expected. * - * in A void pointer to the input data. + * Note that fields marked as `not implemented yet' are subject to change. * - * out A void pointer to the output data. + * in-file A pointer of type `FILE*' to the data + * stream of the input font, opened for + * binary reading. * - * options A string giving options to control the conversion. + * in-buffer A pointer of type `const char*' to a + * buffer which contains the input font. + * Needs `in-buffer-len'. Not implemented + * yet. * - * By default, `in' and `out' are cast to `FILE*', opened for binary reading - * and writing, respectively. + * in-buffer-len A value of type `size_t', giving the + * length of the input buffer. Needs + * `in-buffer'. Not implemented yet. * - * Currently, `options' is ignored. + * out-file A pointer of type `FILE*' to the data + * stream of the output font, opened for + * binary writing. * + * out-buffer A pointer of type `char*' to a buffer + * which contains the output font. Needs + * `out-buffer-len'. Not implemented yet. + * + * out-buffer-len A value of type `size_t', giving the + * length of the output buffer. Needs + * `out-buffer'. Not implemented yet. + * + * progress-callback A pointer of type `TA_Progress_Func', + * specifying a callback function for + * progress reports. This function gets + * called after a single glyph has been + * processed. If this field is not set, no + * progress callback function is used. Not + * implemented yet. + * + * hinting-range-min An integer giving the lowest ppem value + * used for autohinting. If this field is + * not set, it defaults to value 8. Not + * implemented yet. + * + * hinting-range-max An integer giving the highest ppem value + * used for autohinting. If this field is + * not set, it defaults to value 1000. Not + * implemented yet. + * + * pre-hinting Apply native TrueType hinting to all + * glyphs before passing them to the + * (internal) autohinter. The used + * resolution is the em-size in font units; + * for most fonts this is 2048ppem. Use this + * if the hints move or scale subglyphs + * independently of the output resolution. + * This field has no argument. Not + * implemented yet. + * + * no-x-height-snapping Disable x-height snapping. This field has + * no argument. Not implemented yet. + * + * x-height-snapping-exceptions A pointer of type `const char*' to a + * null-terminated string which gives a list + * of comma separated ppem values or value + * ranges at which no x-height snapping shall + * be applied. A value range has the form + * `value1-value2', meaning `value1' <= ppem + * <= `value2'. Whitespace is not + * significant; a trailing comma is ignored. + * By default, there are no snapping + * exceptions. Not implemented yet. + * + * ignore-permissions If the font has set bit 1 in the `fsType' + * field of the `OS/2' table, the ttfautohint + * library refuses to process the font since + * a permission to do that is required from + * the font's legal owner. In case you have + * such a permission you might set this + * option to make ttfautohint handle the + * font. This field has no argument. Not + * implemented yet. + * + * latin-fallback Use the `latin' autohinting module as a + * fallback for glyphs not in the `latin' + * range. This field has no argument. By + * default, the `dummy' fallback module is + * used. Not implemented yet. + * + * Obviously, it is necessary to have an input and an output data stream. + * All other options are optional. */ TA_Error -TTF_autohint(void *in, - void *out, - const char* options); +TTF_autohint(const char* options, + ...); #endif /* __TTFAUTOHINT_H__ */ -- 2.11.4.GIT