JLChen
2021-08-02 38f4fb064df09f344fc3237409c76a9fba2a8a9e
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
#!/bin/bash
 
##
## Copyright (c) 2010-2019 Belledonne Communications SARL.
##
## This file is part of linphone-iphone 
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##
 
# Created by Gautier Pelloux-Prayer on 2014/10/07.
# This script can be used to replace default font with a custom one in every xib
# Please note that it changes only .xib files and not hardcoded fonts in .m/.h files.
# It creates a backup file with .backup_font extension.
 
if [ $# != 0 ]; then
    echo "Usage: $0"
    echo "To avoid reentering input, you can preset values, for intance:"
    echo 'repository=. newfont_family="Movistar Text" newregular_font=MovistarText newbold_font=MovistarText-Bold newitalic_font=MovistarText-Italic' $0
    exit 0
fi
 
# quit on first error
set -e
 
#################################### Input values #########################
# read $2 from stdin if it is not already set. Works also for multiple reads, but
# only check that the first read variable is not set
function readv {
    prompt=$1
    shift
    if [ -z "${!1}" ]; then
        echo "$prompt"
        read "$@" #cannot use read -p because unknown on MacOS
    else
        echo "$1 already set ($1=${!1}). Skipping $@"
    fi
 
    for arg in "$@"; do
        echo "$arg=${!arg}"
    done
}
echo $repository
readv '# Your git repository where we must apply changes like $HOME/code/linphone-iphone' repository
readv '# The font family name like "Helvetica"' newfont_family
readv '# The normal font like "Helvetica"' newregular_font
readv '# The bold font like "Helvetica-Bold"' newbold_font
readv '# The italic font like "Helvetica-Italic"' newitalic_font
readv '# RGB values for new text color like "255 255 255" for white' newred newgreen newblue
newred=$(echo $newred / 255.0 | bc -l)
newgreen=$(echo $newgreen / 255.0 | bc -l)
newblue=$(echo $newblue / 255.0 | bc -l)
################################################################################
 
# This is default Linphone text color ("gray")
oldred="\"0.35"
oldgreen="\"0.39"
oldblue="\"0.43"
 
if [ ! -d "$repository" ]; then
    echo "Invalid repository '$repository': it does not exist"
    exit 1
elif [ ! -d "$repository/Classes/" ]; then
    echo "Invalid repository '$repository': expected subfolder Classses/ does not exist"
    exit 2
fi
 
 
cd $repository/Classes
 
fonts=( "system:$newregular_font"
"boldSystem:$newbold_font"
"italicSystem:$newitalic_font" )
 
 
for font in "${fonts[@]}"; do
    system_font=${font%:*}
    new_font=${font#*:}
    echo "$system_font -> $new_font"
 
    find . -name '*.xib' -exec \
        sed -E -i.font_backup \
            -e "s|<fontDescription key=\"fontDescription\" type=\"$system_font\"|<fontDescription key=\"fontDescription\" name=\"$new_font\" family=\"$newfont_family>\"|g"  \
            -e "s|<color key=\"(.*)Color\".*$oldred.*$oldgreen.*$oldblue.*|<color key=\"\\1Color\" red=\"$newred\" green=\"$newgreen\" blue=\"$newblue\" alpha=\"1\" colorSpace=\"deviceRGB\"/>|g" {} \;
done
 
echo "**********************
Done. Created .backup_font files. If you are OK with the change, you can remove them with:
find $repository -name '*.font_backup' -exec rm {} \;
If you are NOT ok with change, you can put them back.
**********************"