2 * fbpad_mkfn - generate fbpad fonts from truetype fonts
4 * Copyright (C) 2009-2016 Ali Gholami Rudi <ali at rudi dot ir>
6 * This program is released under the Modified BSD license.
17 #define NGLYPHS (1 << 14)
19 static int rows
, cols
;
21 static int fn_glyphs(int *glyphs
)
25 for (i
= 0; i
< sizeof(chars
) / sizeof(chars
[0]); i
++) {
26 for (j
= chars
[i
][0]; j
<= chars
[i
][1] && n
< NGLYPHS
; j
++) {
27 if (!mkfn_bitmap(NULL
, j
, rows
, cols
))
29 if (!mkfn_bitmap(NULL
, j
, rows
, cols
) && isdw(j
))
30 glyphs
[n
++] = DWCHAR
| j
;
36 static int intcmp(void *v1
, void *v2
)
38 return *(int *) v1
- *(int *) v2
;
42 * This tinyfont header is followed by:
44 * glyphs[n] unicode character codes (int)
45 * bitmaps[n] character bitmaps (char[rows * cols])
48 char sig
[8]; /* tinyfont signature; "tinyfont" */
49 int ver
; /* version; 0 */
50 int n
; /* number of glyphs */
51 int rows
, cols
; /* glyph dimensions */
54 /* generate the output tinyfont font */
55 static void output(int fd
)
57 char *sig
= "tinyfont";
60 char *buf
= malloc(rows
* cols
);
62 memcpy(head
.sig
, sig
, strlen(sig
));
66 head
.n
= fn_glyphs(glyphs
);
67 qsort(glyphs
, head
.n
, sizeof(glyphs
[0]), (void *) intcmp
);
68 write(fd
, &head
, sizeof(head
));
69 write(fd
, glyphs
, sizeof(*glyphs
) * head
.n
);
70 for (i
= 0; i
< head
.n
; i
++) {
71 mkfn_bitmap(buf
, glyphs
[i
], rows
, cols
);
72 write(fd
, buf
, rows
* cols
);
74 fprintf(stderr
, "tinyfont[%5d]: height=%2d width=%2d\n",
80 "usage: mkfn [options] font1.ttf:size ... >font.tf\n"
82 " -h n \t\t set glyph height\n"
83 " -w n \t\t set glyph width\n";
85 int main(int argc
, char *argv
[])
90 for (i
= 1; i
< argc
&& argv
[i
][0] == '-'; i
++) {
91 if (argv
[i
][1] == 'w')
92 wdiff
= argv
[i
][2] ? argv
[i
] + 2 : argv
[++i
];
93 else if (argv
[i
][1] == 'h')
94 hdiff
= argv
[i
][2] ? argv
[i
] + 2 : argv
[++i
];
96 fprintf(stderr
, usage
);
99 for (; i
< argc
; i
++) {
100 char *name
= argv
[i
];
102 if (strchr(name
, ':')) {
103 spec
= strrchr(name
, ':') + 1;
104 strrchr(name
, ':')[0] = '\0';
106 if (mkfn_font(name
, spec
)) {
107 fprintf(stderr
, "mkfn: failed to load <%s>\n", name
);
111 mkfn_dim(&rows
, &cols
);
113 rows
= strchr("-+", hdiff
[0]) ? rows
+ atoi(hdiff
) : atoi(hdiff
);
115 cols
= strchr("-+", wdiff
[0]) ? cols
+ atoi(wdiff
) : atoi(wdiff
);