Last active
October 30, 2020 18:07
-
-
Save lbonanomi/c32a7c6ae982ae4d81f4ac884258e006 to your computer and use it in GitHub Desktop.
Partially automated SVG scrolls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
wd=$(mktemp -d) | |
function gothique { | |
# re-type everything in unicode blackletter font | |
# | |
seed=1D56C | |
for num in $(seq 65 90; seq 97 122) | |
do | |
dseed=$(echo "obase=10; ibase=16; $seed" | bc) | |
letter=$(echo | awk '{ print sprintf("%c", '$num') }') | |
cat $1 | awk '{split($0,chars,"");for(i=1;i<=length($0);i++) {if (chars[i] == "'$letter'") {system("printf \"\\U'$seed'\"")} else {printf chars[i]}}}' > $1.tmp && mv $1.tmp $1 | |
seed=$(echo "obase=16; ibase=10; $((dseed+1))" | bc) | |
done | |
} | |
function initial { | |
# Firt letter of first line a little bigger, and in a colored box | |
# | |
echo $1 > $wd/initialize | |
gothique $wd/initialize | |
printf '<svg height="2000" width="5000">\n<rect x="550" y="150" width="480" height="380" style="fill:rgb(0,100,80);stroke:gold;stroke-width:20;opacity:1.0" />' | |
printf '<text x="600" y="450" fill="rgb(0,0,111)" font-size="23em">'$(cat $wd/initialize)'</text>' | |
echo;echo; | |
rm $wd/initialize | |
} | |
if [[ -z "$1" ]] | |
then | |
echo "$0 reads files, not streams" | |
exit 1 | |
fi | |
# Add SVG headers | |
# | |
printf '<?xml version="1.0" standalone="no"?><svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="5000" height="2250" style="background: white">' | |
# Break-down input into individual lines. First letter of fist line should be made fancier | |
# https://en.wikipedia.org/wiki/Initial | |
# | |
ln=0 | |
cat $1 | while read line | |
do | |
if [[ $ln == "0" ]] | |
then | |
echo $line | cut -c1 --complement > /$wd/$ln | |
initial $(echo $line | cut -c1) | |
else | |
echo "$line" > /$wd/$ln | |
fi | |
gothique /$wd/$ln | |
ln=$(($ln+1)) | |
done | |
# Initial vertical tab. NOTE: Also controls indentation | |
line=490 | |
for part in $(ls $wd) | |
do | |
if [[ $line == 490 ]] | |
then | |
awk '{ print "<text x=\"1000\" y=\"'$line'\" font-size=\"10em\">"$0"</text>"}' $wd/$part | |
else | |
awk '{ print "<text x=\"600\" y=\"'$line'\" font-size=\"10em\">"$0"</text>"}' $wd/$part | |
fi | |
line=$(($line+200)) | |
done | |
printf "</svg>\n" | |
# Source handsome braidwork borders | |
curl https://gist.githubusercontent.com/lbonanomi/89f743923407b2f1443feada0dc80a3c/raw/0148a2c2c908541da9714352f4adde5b6de2c47f/left-braid.svg | |
curl https://gist.githubusercontent.com/lbonanomi/accac40b46ede8049aeca3a69d881730/raw/cb373974b0e04e6408c7ff6f98ca25e6c545c7bb/right-braid.svg | |
printf "</svg>\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment