Initial commit
[profile/ivi/fontpackages.git] / private / process-fc-query
1 #!/bin/sh
2 # Process fc query output to collect font file data
3
4 # font file to examine
5 font_file="$1"
6 # Where to save fc-query data
7 fc_file="$2"
8
9 # FIXME: only extracts info about the first typeface in a TTC file for now
10 parse_localized_fc_query() {
11   field="$1"
12   file="$2"
13   fieldstring=$(awk -F ':' -v field="$field" \
14                     '$1 == "\t"field { print $2 ; exit }' "$file" \
15                | sed 's="(s)="=g' | sed 's=" *"=|=g'| sed 's= *" *==g')"|"
16   default=$(echo $fieldstring | awk -F "|" '{ print $1 }')
17   if $(grep -q "^"$'\t'$field"lang:" "$file") ; then
18     langstring=$(awk -F ':' -v field="$field" \
19                 '$1 == "\t"field"lang" { print $2 ; exit }' "$file" \
20                 | sed 's="(s)="=g' | sed 's=" *"=|=g'| sed 's= *" *==g')"|"
21     # Try to find the English label
22     while [ "$langstring" != "" -a \
23             "$(echo $langstring | cut -d '|' -f 1)" != "en" ] ; do
24       fieldstring=$(echo "$fieldstring" | sed 's+\([^|]*\)|\(.*\)+\2+g')
25       langstring=$(echo "$langstring" | sed 's+\([^|]*\)|\(.*\)+\2+g')
26     done
27     # We could hide problems by reporting the first label regardless of its
28     # language. But this is an audit script — we do not hide problems
29     echo "$fieldstring" |  awk -F "|" '{ print $1 }'
30   else
31     echo $(echo $fieldstring | cut -d '|' -f 1)
32   fi
33 }
34
35 if $(FC_DEBUG=256 fc-query "$font_file" 2> /dev/null > "$fc_file") ; then
36   family=$(parse_localized_fc_query family "$fc_file")
37   style=$(parse_localized_fc_query style "$fc_file")
38   format=$(parse_localized_fc_query fontformat "$fc_file")
39 else
40   touch "$fc_file"
41 fi
42
43
44 echo "$family|$style|$format"