summaryrefslogtreecommitdiff
path: root/scripts/newbitmaps/strings/build_font
blob: 50f483b14647df1c671a486a299903c9d11808f6 (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
#!/bin/sh
# Copyright (c) 2012 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.

# Generates font source images.

SCRIPT="$(readlink -f "$0")"
SCRIPT_DIR="$(dirname "$SCRIPT")"
GLYPHS='* 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ{}-_'
COLOR="#888888"
FONT="Droid Sans Bold"

die() {
  echo "ERROR: $*" >&2
  exit 1
}

main() {
  [ "$#" = "1" ] || die "Usage: $0 output_dir"
  local output="$1"
  mkdir -p "$output"

  local i=1
  local c=''
  echo "Generating glyph text source..."
  while true; do
    c="$(echo "$GLYPHS" | cut -b $i)"
    [ -z "$c" ] && break
    ord="0x$(echo "$c" | od -t x1 -A none | awk '{print $1}')"
    echo "$c" >"$output/idx$(printf "%03d" $ord)_$(printf "%x" $ord).txt"
    i=$((i + 1))
  done

  echo "Converting glyph images..."
  "$SCRIPT_DIR/text_to_png"  --margin=0 --font="$FONT" --color="$COLOR" \
    "$output/*.txt"
}

set -e
main "$@"