-
Notifications
You must be signed in to change notification settings - Fork 61
/
getFontWeightStyle.sh
executable file
·85 lines (67 loc) · 1.8 KB
/
getFontWeightStyle.sh
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
#!/bin/sh
SCRIPT_DIR=`echo $0 | sed "s/getFontWeightStyle.sh//"`
getFontInfo() {
OUT=`fontforge -script $SCRIPT_DIR/getFontInfo.pe $1 2> /dev/null`
INFO_WEIGHT=`echo "$OUT" | egrep "^Weight:"`
INFO_FONTNAME=`echo "$OUT" | egrep "^Font name:"`
INFO_FULLNAME=`echo "$OUT" | egrep "^Full name:"`
INFO_ITALICANGLE=`echo "$OUT" | egrep "^Italic angle:"`
}
isWeightStyle () {
STYLE="$1"
R="F"
echo "$INFO_WEIGHT" | grep -i $STYLE > /dev/null
if [ "$?" = "0" ]
then
R="T"
else
echo "$INFO_FULLNAME" | grep -i $STYLE > /dev/null
if [ "$?" = "0" ]
then
R="T"
else
echo "$INFO_FONTNAME" | grep -i $STYLE > /dev/null
if [ "$?" = "0" ]
then
R="T"
fi
fi
fi
#.. if we are testing for italic and the answer is F so far, check the
# italic angle
if [ "$R" = "F" -a "$STYLE" = "italic" ]
then
ANGLE=`echo "$INFO_ITALICANGLE" | awk -F": " '{print $2}'`
if [ "$ANGLE" != "0" ]
then
R="T"
fi
fi
echo $R
}
#.. first, get the info about the font from fontforge.
getFontInfo $1
#.. next, from the fontforge info, find out if the font is bold, italic and/or condensed.
IS_BOLD=`isWeightStyle 'bold'`
IS_ITALIC=`isWeightStyle 'italic'`
IS_CONDENSED=`isWeightStyle 'condensed'`
#.. condensed and narrow are the same (I believe).
if [ "$IS_CONDENSED" = "F" ]
then
IS_CONDENSED=`isWeightStyle 'narrow'`
fi
#.. the name we will refer to in CSS will be without the words "Bold", "Italic", etc.
NEW_NAME=`echo $INFO_FONTNAME | awk -F": " '{print $2}' |
sed 's/Bold//gi;
s/Italic//gi;
s/Narrow//gi;
s/Condensed//gi;
s/Regular//gi;
s/-$//' `
echo
echo "$OUT"
echo "==============="
echo "CSS Name: $NEW_NAME"
echo "IS BOLD: $IS_BOLD"
echo "IS ITALIC: $IS_ITALIC"
echo "IS CONDENSED: $IS_CONDENSED"