···
2
+
# Script to preview fonts
5
+
printf '%b\n' "${0##*/} [-F FILE | -S | -t STRING] [OPTIONS]" \
7
+
"\t-F FILE - read from file" \
8
+
"\t-S - read from stdin" \
9
+
"\t-t STRING - use a string" \
11
+
"\t-b SIZE - border size" \
12
+
"\t-c COLORS - set the color of the text and background" \
13
+
"\t-f FONT - which font to preview" \
14
+
"\t-h - display this message" \
15
+
"\t-i - do not generate an inverse image" \
16
+
"\t-o FILE - output file for the generated image" \
17
+
"\t-s SIZE - size of the font" \
18
+
"\ndefault values:" \
19
+
"These values can be set before execution to change default values" \
20
+
"\tPREFON_ACTION=text (file, stdin, or text)" \
21
+
"\tPREFON_BORDER_SIZE=16" \
22
+
"\tPREFON_COLORS=\"000000,ffffff\"" \
23
+
"\tPREFON_FONT=\"monospace\"" \
24
+
"\tPREFON_OUTPUT=\"/tmp/prefon.png\"" \
25
+
"\tPREFON_SIZE=16" \
26
+
"\tPREFON_TEXT=\"The quick brown fox jumps\\\n over the lazy dog}\"" \
27
+
"\tPREFON_INVERSE=vertical (horizontal, vertical, none)"
33
+
w ) prefix=WARNING ;;
35
+
* ) printf '%s\n' "sus!" 1>&2; exit 1 ;;
39
+
printf "${0##*/}: $prefix: %b\n" "$*" 1>&2
43
+
PREFON_ACTION=${PREFON_ACTION:-text}
44
+
PREFON_BORDER_SIZE=${PREFON_BORDER_SIZE:-16}
45
+
PREFON_COLORS=${PREFON_COLORS:-000000,ffffff}
46
+
PREFON_FONT="${PREFON_FONT:-monospace}"
47
+
PREFON_OUTPUT="${PREFON_OUTPUT:-/tmp/prefon.png}"
48
+
PREFON_SIZE=${PREFON_SIZE:-16}
49
+
PREFON_TEXT="${PREFON_TEXT:-The quick brown fox jumps\n over the lazy dog}"
50
+
PREFON_INVERSE=${PREFON_WITHOUT_INVERSE:-vertical}
56
+
- ) shift; continue ;;
57
+
-- ) shift; break ;;
58
+
-* ) flag=${1#-}; shift ;;
59
+
* ) shift; continue ;;
63
+
arg=${flag%${flag#?}}
65
+
F ) PREFON_ACTION="file"; PREFON_FILE=$1; shift ;;
66
+
S ) PREFON_ACTION=stdin; PREFON_FILE=/dev/stdin ;;
67
+
b ) PREFON_BORDER_SIZE=$1; shift ;;
68
+
c ) PREFON_COLORS=$1; shift ;;
69
+
f ) PREFON_FONT=$1; shift ;;
70
+
h ) usage; exit 0 ;;
71
+
i ) PREFON_INVERSE=$1; shift ;;
72
+
o ) PREFON_OUTPUT=$1; shift ;;
73
+
s ) PREFON_SIZE=$1; shift ;;
74
+
t ) PREFON_ACTION=text; PREFON_TEXT=$1; shift ;;
75
+
* ) printf '%s\n' "${0##*/}: -$arg: invalid argument" 1>&2; usage 1>&2; exit 1 ;;
83
+
convert -background "#$2" -bordercolor "#$2" -border "$PREFON_BORDER_SIZE" \
84
+
pango:"<span foreground=\"#$1\" font_desc=\"$PREFON_FONT $PREFON_SIZE\">$4</span>" "$3"
87
+
fgcolor=${PREFON_COLORS%,*}
88
+
bgcolor=${PREFON_COLORS#*,}
90
+
_gen_img "$fgcolor" "$bgcolor" "$PREFON_OUTPUT" "$1" || { info e failed to generate image; exit 1; }
92
+
[ "$PREFON_INVERSE" != "none" ] && {
93
+
inverse="${PREFON_OUTPUT%.*}"
94
+
inverse="${inverse}-inverse.${PREFON_OUTPUT##*.}"
96
+
_gen_img "$bgcolor" "$fgcolor" "$inverse" "$1" || { info e failed to generate image; exit 1; }
98
+
case $PREFON_INVERSE in
99
+
horizontal ) convert "$PREFON_OUTPUT" "$inverse" +append "$PREFON_OUTPUT" \
100
+
|| { info e failed to generate image; exit 1; } ;;
101
+
vertical ) convert "$PREFON_OUTPUT" "$inverse" -append "$PREFON_OUTPUT" \
102
+
|| { info e failed to generate image; exit 1; } ;;
103
+
* ) info e "${PREFON_INVERSE}: is not a valid value for PREFON_INVERSE"; exit 1 ;;
106
+
rm "$inverse" || info w failed to remove temporary file: "${inverse}"
109
+
printf '%s\n' "$PREFON_OUTPUT"
114
+
while IFS= read -r line
116
+
printf '%s\n' "$line"
117
+
done < "$PREFON_FILE"
120
+
input="$(_output_file)"
121
+
generate_image "$input"
124
+
case $PREFON_ACTION in
125
+
file ) [ -e "$PREFON_FILE" ] || { info e "'$PREFON_FILE' does not exist"; exit 1; }
127
+
stdin ) [ -e /dev/stdin ] || { info e "/dev/stdin does not exist"; exit 1; }
129
+
text ) [ "$PREFON_TEXT" ] || { info e "string not provided"; exit 1; }
130
+
generate_image "$PREFON_TEXT" ;;
131
+
* ) info e invalid action: $PREFON_ACTION; exit 1 ;;