aboutsummaryrefslogtreecommitdiff
path: root/font_lib/tools/make_font_lua.sh
blob: 4559341d724ebb0bad6da5ff0b32d2c8e33a7314 (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
#!/bin/bash

scriptname=$0
identify="identify"

font_name=default

for f in textures/font_${font_name}_????.png
do
    if [[ $f =~ textures/font_${font_name}_([0-9a-fA-F]{4}).png ]]
    then
        code=$((16#${BASH_REMATCH[1]}))
        size=$(identify $f | cut -d " " -f 3)
        w=$(echo $size | cut -d "x" -f 1)
        h=$(echo $size | cut -d "x" -f 2)  

        if [ -z "$font_height" ]
        then
        	font_height=$h
        else
        	if [ $font_height -ne $h ]
        	then
        		echo "Error : $f as height of $h pixels, previous textures have a height of $font_height pixels. All textures should have the same height."
        	fi
        fi

        if [ -z "$font_widths" ]
        then
      	    font_widths="[$code]=$w"
      	else
      	    font_widths="$font_widths, [$code]=$w"
      	fi
    fi
done

echo "--[[

$luafile generated by $scriptname $(LANG=en_US date)

--]]

font_lib.register_font(
	'$font_name',
	$font_height,
	{ $font_widths }
);
" > font_$font_name.lua