Skip to content

Commit 2765c9b

Browse files
committed
fontconvert: fractional point support for fine-grained font size control
1 parent 126007f commit 2765c9b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

fontconvert/fontconvert.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void enbit(uint8_t value) {
5151
}
5252

5353
int main(int argc, char *argv[]) {
54-
int i, j, err, size, first = ' ', last = '~', bitmapOffset = 0, x, y, byte;
54+
int i, j, err, size, fpt, first = ' ', last = '~', bitmapOffset = 0, x, y, byte;
5555
char *fontName, c, *ptr;
5656
FT_Library library;
5757
FT_Face face;
@@ -65,6 +65,7 @@ int main(int argc, char *argv[]) {
6565
// fontconvert [filename] [size]
6666
// fontconvert [filename] [size] [last char]
6767
// fontconvert [filename] [size] [first char] [last char]
68+
// Fractional points (1/64 pt) are used if size ends with 'f'
6869
// Unless overridden, default first and last chars are
6970
// ' ' (space) and '~', respectively
7071

@@ -74,6 +75,7 @@ int main(int argc, char *argv[]) {
7475
}
7576

7677
size = atoi(argv[2]);
78+
fpt = argv[2][strlen(argv[2]) - 1] == 'f';
7779

7880
if (argc == 4) {
7981
last = atoi(argv[3]);
@@ -109,7 +111,7 @@ int main(int argc, char *argv[]) {
109111
ptr = &fontName[strlen(fontName)]; // If none, append
110112
// Insert font size and 7/8 bit. fontName was alloc'd w/extra
111113
// space to allow this, we're not sprintfing into Forbidden Zone.
112-
sprintf(ptr, "%dpt%db", size, (last > 127) ? 8 : 7);
114+
sprintf(ptr, "%d%spt%db", size, fpt ? "f" : "", (last > 127) ? 8 : 7);
113115
// Space and punctuation chars in name replaced w/ underscores.
114116
for (i = 0; (c = fontName[i]); i++) {
115117
if (isspace(c) || ispunct(c))
@@ -137,7 +139,7 @@ int main(int argc, char *argv[]) {
137139
}
138140

139141
// << 6 because '26dot6' fixed-point format
140-
FT_Set_Char_Size(face, size << 6, 0, DPI, 0);
142+
FT_Set_Char_Size(face, fpt ? size : size << 6, 0, DPI, 0);
141143

142144
// Currently all symbols from 'first' to 'last' are processed.
143145
// Fonts may contain WAY more glyphs than that, but this code

0 commit comments

Comments
 (0)