| #!/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 normal text files, |
| # while '*.TXT' files may contain markup. |
| # |
| # Options: |
| # |
| # --lan=LANGUAGE Render language (locale) settings |
| # --font=FONTNAME Use specified font (instead of Droid Sans) |
| # --point=POINT Font size, in points (72dpi) |
| # --margin=MARGIN Set different margin (usually for font bitmaps) |
| # --color=COLOR Override foreground color (in '#ffffff' format) |
| # --markup Render text as pango-view markup file |
| # --align Override align settings |
| # |
| font="Verdana" |
| language="" |
| pointsize=17 |
| margin=3 |
| align="center" |
| bgcolor="#ffffff" |
| color="#000000" |
| params="" |
| |
| while true ; do |
| case "$1" in |
| --lan=* | --language=*) |
| language="--language=${1##*=}" |
| shift |
| ;; |
| --font=*) |
| # Allows empty string = default font. |
| param="${1##*=}" |
| [ -n "$param" ] && font="$param" |
| shift |
| ;; |
| --align=*) |
| align="${1##*=}" |
| shift |
| ;; |
| --color=*) |
| color="${1##*=}" |
| shift |
| ;; |
| --point=*) |
| pointsize="${1##*=}" |
| shift |
| ;; |
| --margin=*) |
| margin="${1##*=}" |
| shift |
| ;; |
| --markup) |
| params="$params --markup" |
| shift |
| ;; |
| *) |
| break |
| ;; |
| esac |
| done |
| |
| # Revise color. pango-view color syntax (in #rrggbb) may cause problem in shell |
| # scripts, so let's also allow 'rrggbb'. |
| color="${color###}" |
| bgcolor="${bgcolor###}" |
| [ -z "$color" ] || color="#$color" |
| [ -z "$bgcolor" ] || bgcolor="#$bgcolor" |
| |
| # 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. |
| |
| for txtfile in $*; do |
| # pango-view does not support assigning output format options for bitmap, so |
| # we must create images in PNG format and then post-process it (ex, convert |
| # into BMP by ImageMagick). |
| pngfile="${txtfile%.*}".png |
| file_opt="" |
| case "$txtfile" in |
| *.txt) |
| file_opt="" |
| ;; |
| *.TXT) |
| file_opt="--markup " |
| ;; |
| *) |
| echo "Ignoring $txtfile. Filename should end with .txt or .TXT" |
| continue |
| ;; |
| esac |
| pango-view -q $language \ |
| --hinting=full \ |
| --background="$bgcolor" --foreground="$color" \ |
| --font="$font $pointsize" --dpi 72 \ |
| --margin=$margin \ |
| --align="$align" \ |
| $params $file_opt \ |
| --output "$pngfile" \ |
| "$txtfile" |
| echo "wrote $pngfile" |
| done |