Image image;
} Font;
+typedef struct sRange
+{
+ unsigned first;
+ unsigned last;
+} Range;
+
typedef int bool;
void usage(void);
int convert_numeric_option(char, int);
-void convert_code_point_range(char, unsigned *, unsigned *);
+void convert_code_point_range(char, Range *);
unsigned str_to_code_point(const char *, char **);
void convert_size(char, unsigned *, unsigned *);
unsigned round_to_pot(unsigned);
void *alloc_image_data(size_t, size_t);
-int init_font(Font *, FT_Face, unsigned, unsigned, bool);
+int init_font(Font *, FT_Face, const Range *, unsigned, bool);
+int init_glyphs(Font *, FT_Face, const Range *, bool);
int render_grid(Font *, unsigned, unsigned, unsigned, bool);
int render_packed(Font *, unsigned, unsigned);
int save_defs(const char *, const Font *);
int main(int argc, char **argv)
{
char *fn;
- unsigned begin = 0;
- unsigned end = 255;
+ Range *ranges = NULL;
+ unsigned n_ranges = 0;
unsigned size = 10;
unsigned cpl = 0;
unsigned cellw = 0;
switch(i)
{
case 'r':
- convert_code_point_range('r', &begin, &end);
+ ranges = (Range *)realloc(ranges, (++n_ranges)*sizeof(Range));
+ convert_code_point_range('r', &ranges[n_ranges-1]);
break;
case 's':
size = convert_numeric_option('s', 1);
}
font.size = size;
- err = init_font(&font, face, begin, end, autohinter);
+ err = init_font(&font, face, ranges, n_ranges, autohinter);
if(err)
return 1;
return value;
}
-void convert_code_point_range(char opt, unsigned *begin, unsigned *end)
+void convert_code_point_range(char opt, Range *range)
{
int value;
char *ptr;
if(!strcmp(optarg, "all"))
{
- *begin = 0;
- *end = 0x10FFFF;
+ range->first = 0;
+ range->last = 0x10FFFF;
return;
}
value = str_to_code_point(optarg, &ptr);
if(value>0 && *ptr==',')
{
- *begin = value;
+ range->first = value;
value = str_to_code_point(ptr+1, &ptr);
if(value>0 && !*ptr)
{
- *end = value;
+ range->last = value;
return;
}
}
return ptr;
}
-int init_font(Font *font, FT_Face face, unsigned first, unsigned last, bool autohinter)
+int init_font(Font *font, FT_Face face, const Range *ranges, unsigned n_ranges, bool autohinter)
{
unsigned i, j;
unsigned size = 0;
font->n_glyphs = 0;
font->glyphs = NULL;
- for(i=first; i<=last; ++i)
+ for(i=0; i<n_ranges; ++i)
+ if(init_glyphs(font, face, &ranges[i], autohinter))
+ return -1;
+
+ if(verbose>=1)
+ printf("Loaded %u glyphs\n", font->n_glyphs);
+
+ font->n_kerning = 0;
+ font->kerning = NULL;
+ for(i=0; i<font->n_glyphs; ++i) for(j=0; j<font->n_glyphs; ++j)
+ if(j!=i)
+ {
+ FT_Vector kerning;
+ FT_Get_Kerning(face, font->glyphs[i].index, font->glyphs[j].index, FT_KERNING_DEFAULT, &kerning);
+
+ /* FreeType documentation says that vertical kerning is practically
+ never used, so we ignore it. */
+ if(kerning.x)
+ {
+ Kerning *kern;
+
+ if(font->n_kerning>=size)
+ {
+ size += 16;
+ font->kerning = (Kerning *)realloc(font->kerning, size*sizeof(Kerning));
+ }
+
+ kern = &font->kerning[font->n_kerning++];
+ kern->left_code = font->glyphs[i].code;
+ kern->right_code = font->glyphs[j].code;
+ kern->distance = kerning.x/64;
+ }
+ }
+
+ if(verbose>=1)
+ printf("Loaded %d kerning pairs\n", font->n_kerning);
+
+ return 0;
+}
+
+int init_glyphs(Font *font, FT_Face face, const Range *range, bool autohinter)
+{
+ unsigned i, j;
+ unsigned size = font->n_glyphs;
+
+ for(i=range->first; i<=range->last; ++i)
{
unsigned n;
FT_Bitmap *bmp = &face->glyph->bitmap;
}
}
- if(verbose>=1)
- printf("Loaded %u glyphs\n", font->n_glyphs);
-
- size = 0;
- font->n_kerning = 0;
- font->kerning = NULL;
- for(i=0; i<font->n_glyphs; ++i) for(j=0; j<font->n_glyphs; ++j)
- if(j!=i)
- {
- FT_Vector kerning;
- FT_Get_Kerning(face, font->glyphs[i].index, font->glyphs[j].index, FT_KERNING_DEFAULT, &kerning);
-
- /* FreeType documentation says that vertical kerning is practically
- never used, so we ignore it. */
- if(kerning.x)
- {
- Kerning *kern;
-
- if(font->n_kerning>=size)
- {
- size += 16;
- font->kerning = (Kerning *)realloc(font->kerning, size*sizeof(Kerning));
- }
-
- kern = &font->kerning[font->n_kerning++];
- kern->left_code = font->glyphs[i].code;
- kern->right_code = font->glyphs[j].code;
- kern->distance = kerning.x/64;
- }
- }
-
- if(verbose>=1)
- printf("Loaded %d kerning pairs\n", font->n_kerning);
-
return 0;
}