From: Mikko Rasa Date: Fri, 4 May 2018 21:07:23 +0000 (+0300) Subject: Add an option to control distance field border zone X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a815ebe3941e2157639365806e9186e49ee944b5;p=ttf2png.git Add an option to control distance field border zone --- diff --git a/Readme b/Readme index 7695e61..c4fc9d0 100644 --- a/Readme +++ b/Readme @@ -80,6 +80,10 @@ Command-line options stored without alpha and with large/positive values indicating the inside of glyphs; the -t and -i options are ignored. + -b + Set the border zone width for distance field. The default is the square + root of the font size. + -d File name to write glyph definitions. See the section below for details. diff --git a/ttf2png.c b/ttf2png.c index 1c17c6b..0a66de2 100644 --- a/ttf2png.c +++ b/ttf2png.c @@ -78,8 +78,8 @@ void sort_and_compact_ranges(Range *, unsigned *); int range_cmp(const void *, const void *); unsigned round_to_pot(unsigned); void *alloc_image_data(size_t, size_t); -int init_font(Font *, FT_Face, const Range *, unsigned, bool, unsigned); -int init_glyphs(Font *, FT_Face, const Range *, bool, unsigned); +int init_font(Font *, FT_Face, const Range *, unsigned, bool, unsigned, unsigned); +int init_glyphs(Font *, FT_Face, const Range *, bool, unsigned, unsigned); int copy_bitmap(const FT_Bitmap *, Image *); unsigned sqrti(unsigned); unsigned find_distance_to_edge(const Image *, int, int, unsigned); @@ -109,6 +109,7 @@ int main(int argc, char **argv) unsigned padding = 1; bool npot = 0; unsigned distfield = 0; + unsigned border = 0; FT_Library freetype; FT_Face face; @@ -127,7 +128,7 @@ int main(int argc, char **argv) return 1; } - while((i = getopt(argc, argv, "r:s:l:c:o:atvh?ed:pim:n:gf:")) != -1) + while((i = getopt(argc, argv, "r:s:l:c:o:atvh?ed:pim:n:gf:b:")) != -1) { switch(i) { @@ -184,6 +185,9 @@ int main(int argc, char **argv) case 'f': distfield = convert_numeric_option('f', 1); break; + case 'b': + border = convert_numeric_option('b', 1); + break; } } if(!strcmp(out_fn, "-")) @@ -222,7 +226,11 @@ int main(int argc, char **argv) font.size = size; if(distfield) + { + if(!border) + border = sqrti(font.size); size *= distfield; + } err = FT_Set_Pixel_Sizes(face, 0, size); if(err) @@ -241,7 +249,7 @@ int main(int argc, char **argv) else sort_and_compact_ranges(ranges, &n_ranges); - err = init_font(&font, face, ranges, n_ranges, autohinter, distfield); + err = init_font(&font, face, ranges, n_ranges, autohinter, distfield, border); if(err) return 1; @@ -508,7 +516,7 @@ void *alloc_image_data(size_t a, size_t b) return ptr; } -int init_font(Font *font, FT_Face face, const Range *ranges, unsigned n_ranges, bool autohinter, unsigned distfield) +int init_font(Font *font, FT_Face face, const Range *ranges, unsigned n_ranges, bool autohinter, unsigned distfield, unsigned border) { unsigned i, j; unsigned size = 0; @@ -526,7 +534,7 @@ int init_font(Font *font, FT_Face face, const Range *ranges, unsigned n_ranges, font->n_glyphs = 0; font->glyphs = NULL; for(i=0; i=1) @@ -565,7 +573,7 @@ int init_font(Font *font, FT_Face face, const Range *ranges, unsigned n_ranges, return 0; } -int init_glyphs(Font *font, FT_Face face, const Range *range, bool autohinter, unsigned distfield) +int init_glyphs(Font *font, FT_Face face, const Range *range, bool autohinter, unsigned distfield, unsigned border) { unsigned i, j; unsigned size = font->n_glyphs; @@ -632,11 +640,9 @@ int init_glyphs(Font *font, FT_Face face, const Range *range, bool autohinter, u start from the bottom. */ if(distfield) { - unsigned margin = 3; - - glyph->offset_x -= margin; - glyph->offset_y -= margin; - create_distance_field(bmp, &glyph->image, distfield, margin); + glyph->offset_x -= border; + glyph->offset_y -= border; + create_distance_field(bmp, &glyph->image, distfield, border); } else {