Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fontconvert: fractional point support for fine-grained font size control #436

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, f, 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]);
f = 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, f ? "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, f ? 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