Skip to content

Commit

Permalink
fontconvert: fractional point support for fine-grained font size control
Browse files Browse the repository at this point in the history
  • Loading branch information
wydrych committed Oct 18, 2023
1 parent 126007f commit 2765c9b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions fontconvert/fontconvert.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void enbit(uint8_t value) {
}

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

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

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

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

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

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

0 comments on commit 2765c9b

Please sign in to comment.