From 3668787249068ddb09cd0c7a8868f2645a2df346 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sat, 29 Sep 2018 17:19:17 -0400 Subject: Add -c and -s to psf2png --- bin/man/psf2png.1 | 17 ++++++++++++++++- bin/psf2png.c | 33 ++++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 10 deletions(-) (limited to 'bin') diff --git a/bin/man/psf2png.1 b/bin/man/psf2png.1 index 3450dce8..bbabd484 100644 --- a/bin/man/psf2png.1 +++ b/bin/man/psf2png.1 @@ -8,6 +8,8 @@ . .Sh SYNOPSIS .Nm +.Op Fl c Ar cols +.Op Fl s Ar str .Op Ar file . .Sh DESCRIPTION @@ -17,7 +19,20 @@ renders the PSF2 font or standard input to PNG on standard output. -The glyphs are arranged in 32 columns. +. +.Pp +The arguments are as follows: +.Bl -tag -width Ds +.It Fl c Ar cols +Arrange glyphs in +.Ar cols +columns. +The default number of columns is 32. +.It Fl s Ar str +Render glyphs for string +.Ar str +rather than all glyphs. +.El . .Sh SEE ALSO .Xr pngo 1 , diff --git a/bin/psf2png.c b/bin/psf2png.c index 6106fd89..eee4e1a9 100644 --- a/bin/psf2png.c +++ b/bin/psf2png.c @@ -21,10 +21,9 @@ #include #include #include +#include #include -static const uint32_t GlyphCols = 32; - static uint32_t crc; static void pngWrite(const void *ptr, size_t size) { fwrite(ptr, size, 1, stdout); @@ -42,8 +41,22 @@ static void pngChunk(const char *type, uint32_t size) { } int main(int argc, char *argv[]) { + uint32_t cols = 32; + const char *str = NULL; + + int opt; + while (0 < (opt = getopt(argc, argv, "c:s:"))) { + switch (opt) { + break; case 'c': cols = strtoul(optarg, NULL, 0); + break; case 's': str = optarg; + break; default: return EX_USAGE; + } + } + if (!cols && str) cols = strlen(str); + if (!cols) return EX_USAGE; + const char *path = NULL; - if (argc > 1) path = argv[1]; + if (optind < argc) path = argv[optind]; FILE *file = path ? fopen(path, "r") : stdin; if (!file) err(EX_NOINPUT, "%s", path); @@ -76,8 +89,9 @@ int main(int argc, char *argv[]) { pngWrite("\x89PNG\r\n\x1A\n", 8); - uint32_t width = header.glyph.width * GlyphCols; - uint32_t rows = (header.glyph.len + GlyphCols - 1) / GlyphCols; + uint32_t count = (str ? strlen(str) : header.glyph.len); + uint32_t width = header.glyph.width * cols; + uint32_t rows = (count + cols - 1) / cols; uint32_t height = header.glyph.height * rows; pngChunk("IHDR", 13); @@ -89,12 +103,13 @@ int main(int argc, char *argv[]) { uint8_t data[height][1 + width]; memset(data, 0, sizeof(data)); - for (uint32_t i = 0; i < header.glyph.len; ++i) { - uint32_t row = header.glyph.height * (i / GlyphCols); - uint32_t col = 1 + header.glyph.width * (i % GlyphCols); + for (uint32_t i = 0; i < count; ++i) { + uint32_t row = header.glyph.height * (i / cols); + uint32_t col = 1 + header.glyph.width * (i % cols); + uint32_t g = (str ? str[i] : i); for (uint32_t y = 0; y < header.glyph.height; ++y) { for (uint32_t x = 0; x < header.glyph.width; ++x) { - uint8_t bit = glyphs[i][y][x / 8] >> (7 - x % 8) & 1; + uint8_t bit = glyphs[g][y][x / 8] >> (7 - x % 8) & 1; data[row + y][col + x] = -bit; } } -- cgit 1.4.1 815052411d699e34dd&follow=1'>Try successive getaddrinfo resultsJune McEnroe 2018-09-15Render README from chatte.7June McEnroe 2018-09-14Factor out uiPrompt to call on nick changeJune McEnroe 2018-09-14Run test binaries with set -e and semicolonsJune McEnroe BSD make behaves oddly when trying to replace with &. 2018-09-14Fail target when any test binary failsJune McEnroe 2018-09-14Run tests in default targetJune McEnroe 2018-09-14Add termEvent testsJune McEnroe 2018-09-14Check width of entire next word including codesJune McEnroe This results in a tiny bit of premature wrapping for color codes, but that isn't a problem. 2018-09-14Remove word handling from formatParseJune McEnroe 2018-09-14Apply consecutive formatting codes at onceJune McEnroe Fixes the failing splits test. 2018-09-14Add tests for formatParseJune McEnroe With one currently failing so you know they're worth it. 2018-09-13Preview with nick in input windowJune McEnroe 2018-09-13Never send PRIVMSG to TagStatus or TagVerboseJune McEnroe 2018-09-13Move color selection to format.cJune McEnroe 2018-09-13Fix len for format->split at end of stringJune McEnroe 2018-09-13Avoid uninitialized x in uiReadJune McEnroe 2018-09-13Add IRCDefault to colors enumJune McEnroe 2018-09-13Return a format->split even at the end of the stringJune McEnroe 2018-09-13Fix weird tab-complete after commaJune McEnroe I have no idea why I did this. 2018-09-13Rewrite UI againJune McEnroe The persistent topic is gone and the status line is now at the top. The status formatting still needs to be reworked. I also want to try showing the nick in the input window so it really looks like your next message. 2018-09-12Add note about C-oJune McEnroe Why are there so few well usable ctrl key bindings? 2018-09-12Use formatParse split to position input cursorJune McEnroe 2018-09-12Factor out IRC formatting parsingJune McEnroe 2018-09-11Add /help equivalent to /manJune McEnroe 2018-09-11Don't render every PM as a pingJune McEnroe 2018-09-11Add urlOpenMatchJune McEnroe 2018-09-10Depend on man.sh for chroot.tar targetJune McEnroe 2018-09-10Set LESSSECURE=1 in man.shJune McEnroe Ridiculous. 2018-09-10Add /man commandJune McEnroe 2018-09-10Install man page in chrootJune McEnroe 2018-09-10Install man pageJune McEnroe 2018-09-10Split keys into subsections and document colorsJune McEnroe 2018-09-10Add "blank" lines to chatte.1June McEnroe 2018-09-10Document key bindings in chatte.1June McEnroe 2018-09-08Document slash commands in chatte.1June McEnroe