From ec1d430daf529802729aa1ab622ad1a2d7c53cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haoran=20S=2E=20Diao=20=28=E5=88=81=E6=B5=A9=E7=84=B6=29?= <0@hairydiode.xyz> Date: Fri, 30 Jun 2023 02:55:40 -0700 Subject: Added ability to display entire strings of text --- README | 8 +++++++- fontd | 3 ++- textd | 13 +++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100755 textd diff --git a/README b/README index 656d38b..3b6e755 100644 --- a/README +++ b/README @@ -32,4 +32,10 @@ examples are in INPUT and INPUT2 ------------------------------------=[fontd]=----------------------------------- Font Display: prints font in braille characters, useful for limited environments such - as the linux console(although you would need braille support first) + as the linux console(although you would need braille support first), + takes as first argument a decimal codepoint (bdf format) and the 2nd a + directory with bdf fonts from which to find the character +------------------------------------=[textd]=----------------------------------- +Text Display: + Takes utf-8 input from stdin and displays it vertically with fonts + specified by the first argument diff --git a/fontd b/fontd index 3ca9ae3..d6754d0 100755 --- a/fontd +++ b/fontd @@ -2,6 +2,7 @@ #USAGE # fontd CHAR DIR # display CHAR if found in any bdf fonts in DIR/ +# NOTE: CHAR must be in decimal encoding point format of bdf #gets font size, it can take multiple fonts as input so only get the first one #and assume they're all the same size @@ -10,7 +11,7 @@ size=$(cat $2/*bdf | grep -m 1 PIXEL_SIZE | awk '{print $2}') #get bdf bitmap info from bdf #fflag ensures only one result even with multiple bdfs, cflag finds the char, #bflag labels just the bitmap part -bdf=$(cat $2/*bdf | awk "NR==1{fflag=0}/STARTCHAR $1$/{if(fflag==0){cflag=1;fflag=1}}/BITMAP/{if (cflag==1){bflag=1};next}/ENDCHAR/{cflag=0;bflag=0}bflag") +bdf=$(cat $2/*bdf | awk "NR==1{fflag=0}/ENCODING $1$/{if(fflag==0){cflag=1;fflag=1}}/BITMAP/{if (cflag==1){bflag=1};next}/ENDCHAR/{cflag=0;bflag=0}bflag") #convert to binary, cols depends on size bin=$(echo $bdf | xxd -r -ps | xxd -b -c $(($size/8))|\ diff --git a/textd b/textd new file mode 100755 index 0000000..57394a0 --- /dev/null +++ b/textd @@ -0,0 +1,13 @@ +#!/bin/bash +#usage: +# textd DIR +# reads from stdin, and displays all text vertically using fonts +# in DIR +# assumes unicode utf-8 input +codes=$(iconv -f utf8 -t utf32be | xxd -u -p -c 4) +#convert to decimal +dec=$(echo -n "ibase=16;$codes" | bc) +dec=($dec) +for decimal_code in "${dec[@]}"; do + ./fontd "$decimal_code" "$1" +done -- cgit v1.1