summarylogtreecommitdiffstats
path: root/build
blob: 4bb263c5cb353dbe19d8da03ceedd17933e8a443 (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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# Ilya Kuzmin; Russia, Saint-Petersbugr, 2019. ©
# Generate DejaVu font descriptions to enable it in groff.

output=font

function register_font
{
    local base_name="$1"; shift;
    local font_name="$1"; shift;

    echo $font_name

    local internalname=`awk '/^internalname/{print $2;}' $font_name`


    if ! grep "\b$internalname\t" "$output/devpdf/download" &>/dev/null; then
        echo -e "\t$internalname\t../$base_name.pfa" >> $output/devpdf/download
    else
        echo "Font with name '$internalname' already present in '$output/devpdf/download'"
    fi

    if ! grep "\b$internalname\t" $output/devps/download &>/dev/null; then
       echo -e "\t$internalname\t../$base_name.pfa" >> $output/devps/download
    else
        echo "Font with name '$internalname' already present in '$output/devps/download'"
    fi
}

ttf=$(find /usr/share/fonts/TTF/ -name "DejaVu*")
if  [ -z "$ttf" ]; then
    echo "Make sure ttf-dejavu is installed"
    exit -1
fi

if ! type fontforge >/dev/null; then
    echo "Make sure 'fontforge' is installed"
    exit -1;
fi

textmap=(/usr/share/groff/*/font/devpdf/map/textmap)
if ! type afmtodit >/dev/null || ! [ -e "$textmap" ]; then
    echo "Make sure 'groff' is installed"
    exit -1;
fi

if ! [ -d "$output" ]; then
    mkdir $output
    mkdir $output/devps
    mkdir $output/devpdf
fi

for name in $ttf; do
    base_name=$(basename $name .ttf)
    if ! fontforge 2>/dev/null -lang=ff -c "Open(\"$name\");Generate(\"$output/$base_name.pfa\");"; then
        echo "Can't generate post-scipt font and afm description for $base_name"
        echo -1
    fi

    if [[ "$base_name" =~ -BoldOblique$ ]]; then
        font_name=${base_name/-BoldOblique/BI}
    elif [[ "$base_name" =~ -ExtraLight$ ]]; then
        font_name=${base_name/-ExtraLight/II}
    elif [[ "$base_name" =~ -BoldItalic$ ]]; then
        font_name=${base_name/-BoldItalic/BI}
    elif [[ "$base_name" =~ -Bold$ ]]; then
        font_name=${base_name/-Bold/B}
    elif [[ "$base_name" =~ -Oblique$ ]]; then
        font_name=${base_name/-Oblique/I}
    elif [[ "$base_name" =~ -Italic$ ]]; then
        font_name=${base_name/-Italic/I}
    elif [[ "$base_name" =~ - ]]; then
        echo "Can't gues font name  from '$base_name'"
        exit -1;
    else
        font_name=${base_name}R
    fi

    if [[ "$font_name" =~ DejaVuSansMono ]]; then
        font_name=${font_name/DejaVuSansMono/DeVuSaMo}
    elif [[ "$font_name" =~ DejaVuSansCondensed ]]; then
        font_name=${font_name/DejaVuSansCondensed/DeVuSaCo}
    elif [[ "$font_name" =~ DejaVuSerifCondensed ]]; then
        font_name=${font_name/DejaVuSerifCondensed/DeVuSeCo}
    elif [[ "$font_name" =~ DejaVuSans ]]; then
        font_name=${font_name/DejaVuSans/DeVuSa}
    elif [[ "$font_name" =~ DejaVuSerif ]]; then
        font_name=${font_name/DejaVuSerif/DeVuSe}
    elif [[ "$font_name" =~ DejaVuMathTeXGyre ]]; then
        font_name=${font_name/DejaVuMathTeXGyre/DeVuTex}
    fi


    if ! afmtodit $output/$base_name.afm $textmap $font_name 2>/dev/null; then
        echo "Can't generate groff font description '$font_name' for '$base_name'"
        echo -1
    fi

    register_font $base_name $font_name

    cp $font_name $output/devps/
    cp $font_name $output/devpdf/

    if [[ "$font_name" == "DeVuSaMoR" ]]; then
        for dev in devps devpdf; do
            echo "Link $font_name -> $dev/DeVuSeMo, $dev/DeVuSaMo" 
            cd $output/$dev;
            ln -s DeVuSaMoR DeVuSaMo
            ln -s DeVuSaMoR DeVuSeMo
            cd - >/dev/null;
        done
    fi

    rm $output/$base_name.afm $font_name
done