blob: 54f35551fc77d3e5d0f9fb8b20ba489fcaba1839 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#!/bin/bash -e
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Render a text file into a bitmap. Files named '*.txt' are small font, those
# named '*.TXT' are large font.
#
# Options:
#
# --rtl Render right-to-left languages
# --font=FONTNAME Use specified font (instead of Helvetica)
#
font="Droid Sans"
rtl=""
point=15
while true ; do
case "$1" in
--rtl)
rtl="--rtl"
shift
;;
--font=*)
font="${1##*=}"
shift
;;
--point=*)
point="${1##*=}"
shift
;;
*)
break
;;
esac
done
# Image parameters
# - New pango-view has --pixel to assign font size in pixel, but that is not
# supported by old (ex, 1.24.5 in chroot) so we must assign --dpi 72 for
# pointsize.
bg="#ffffff"
small_color="#000000"
small_font="$font"
small_pointsize="$point"
large_color="#585858"
large_font="$font"
large_pointsize=40
_x86_scale="-scale 59%x78%"
_x86_opts="-colors 256 -compress none -alpha off"
for txtfile in $*; do
# pango-view does not support assigning output format options for bitmap, so
# we first create the images in PNG format and then convert into BMP by
# ImageMagick.
pngfile="${txtfile%.*}".png
bmpfile="${txtfile%.*}".bmp
case "$txtfile" in
*.txt)
pango-view -q $rtl --no-auto-dir \
--background "$bg" --foreground "$small_color" \
--font "$small_font $small_pointsize" --dpi 72 \
--margin=3 --align=center \
--output "$pngfile" \
"$txtfile"
convert ${_x86_scale} ${_x86_opts} "$pngfile" BMP3:"$bmpfile"
rm -f "$pngfile"
echo "wrote $bmpfile"
;;
*.TXT)
pango-view -q $rtl --no-auto-dir \
--background "$bg" --foreground "$large_color" \
--font "$large_font $large_pointsize" --dpi 72 \
--margin=10 --align=center \
--output "$pngfile" \
"$txtfile"
convert ${_x86_scale} ${_x86_opts} " $pngfile" BMP3:"$bmpfile"
rm -f "$pngfile"
echo "wrote $bmpfile"
;;
*)
echo "Ignoring $txtfile. Filename should end with .txt or .TXT"
;;
esac
done
|