/
fontmanager
executable file
·223 lines (204 loc) · 8.62 KB
/
fontmanager
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash
#Combining fontwizard, pFont and set-xftdpi (Barry Kauler 2009)
#Sigmund Berglund, Nov 2013
export TEXTDOMAIN=fontmanager
export OUTPUT_CHARSET=UTF-8
#================================================================
# FONTMANAGER
#================================================================
#read current dpi setting...
CURRDPI=`grep "^Xft\\.dpi:" /root/.Xresources | tr '\t' ' ' | tr -s ' ' | cut -f 2 -d ' '`
[ ! $CURRDPI ] && CURRDPI=78
CURRINDEX=$(( $CURRDPI / 6 - 9 ))
#read appearance values
if [ -f $HOME/.fonts.conf ];then
export antialiasing=$(grep '<bool>' $HOME/.fonts.conf|head -1|cut -d '>' -f2|cut -d '<' -f1)
export hinting=$(grep '<bool>' $HOME/.fonts.conf|head -2|tail -1|cut -d '>' -f2|cut -d '<' -f1)
export autohint=$(grep '<bool>' $HOME/.fonts.conf|head -3|tail -1|cut -d '>' -f2|cut -d '<' -f1)
export hintstyle=$(grep '<int>' $HOME/.fonts.conf|cut -d '>' -f2|cut -d '<' -f1)
else
export antialiasing=false hinting=false autohint=false hintstyle=0
fi
#what tab should be active
[ "$1" = "install" ] && PAGE_NR=2 || PAGE_NR=0
install (){
case $FONT in
*.ttf|*.otf)
cp "$FONT" /usr/share/fonts/default/TTF/
rm /usr/share/fonts/default/TTF/fonts.dir
rm /usr/share/fonts/default/TTF/fonts.scale
mkfontscale /usr/share/fonts/default/TTF
mkfontdir /usr/share/fonts/default/TTF
;;
*)
Xdialog --title "Font installer" --msgbox "'$(gettext 'No TTF-file to install')" 0 0
;;
esac
}
export -f install
S='
<window title="'$(gettext 'Font Manager')'" icon-name="gtk-execute">
<vbox space-expand="true" space-fill="true">
<notebook tab-pos="2" page="'$PAGE_NR'" labels="'$(gettext 'Size')'|'$(gettext 'Appearance')'|'$(gettext 'Install fonts')'">
<frame '$(gettext 'Global font size')'>
'"`/usr/lib/gtkdialog/xml_info scale font_size.svg 60 "$(gettext 'Please choose dpi (dots per inch) for the screen. The larger the value, the bigger that antialiased fonts will render on the screen. Adjust up or down if fonts are rendering too small or too big on screen.')" " " "<b>$(gettext 'Note!')</b> $(gettext 'Some apps do not use antialiased rendering and will not be affected by this setting.')" "<b>$(gettext 'Note!')</b> $(gettext 'Restart X for changes to take effect')"`"'
<vbox space-expand="false" space-fill="false">
<text height-request="20"><label>""</label></text>
<hbox>
<text><label>""</label></text>
<text><label>'$(gettext 'Choose global fontsize')'</label></text>
<comboboxtext width-request="70">
<default>'$CURRDPI'</default>
<variable>NEWDPI</variable>
<item>54</item>
<item>60</item>
<item>66</item>
<item>72</item>
<item>78</item>
<item>84</item>
<item>90</item>
<item>96</item>
<item>102</item>
<item>108</item>
<item>114</item>
<item>120</item>
<item>126</item>
<item>132</item>
<item>138</item>
<item>144</item>
<item>150</item>
</comboboxtext>
</hbox>
<text height-request="5"><label>""</label></text>
</vbox>
</frame>
<frame '$(gettext 'Font appearance')'>
'"`/usr/lib/gtkdialog/xml_info scale font.svg 60 "$(gettext "You can change the way fonts appear on your screen: make them either sharper or smoother.")" "$(gettext "For LCD it is recommend to turn everything on. For CRT screens, do the opposite.")" " " "<b>$(gettext 'Note!')</b> $(gettext 'Restart application for changes to take affect.')"`"'
<vbox space-expand="false" space-fill="false">
<text height-request="20"><label>""</label></text>
<checkbox tooltip-text="'$(gettext "If checked, fonts will be smoothed with antialiasing.")'">
<label>'$(gettext 'Antialiasing')'</label>
<variable>antialiasing</variable>
<default>'$antialiasing'</default>
</checkbox>
<checkbox tooltip-text="'$(gettext "If checked, fonts will be smoothed with hinting.")'">
<label>'$(gettext 'Hinting')'</label>
<variable>hinting</variable>
<default>'$hinting'</default>
</checkbox>
<hbox space-expand="true" space-fill="true">
<checkbox>
<label>'$(gettext 'Automatic hinting')'</label>
<variable>autohint</variable>
<default>'$autohint'</default>
</checkbox>
<text space-expand="true" space-fill="true"><label>""</label></text>
<text space-expand="false" space-fill="false"><label>'$(gettext 'Hint style')'</label></text>
<spinbutton range-min="0" range-max="3" width="100" editable="false" space-expand="false" space-fill="false">
<variable>hintstyle</variable>
<default>'$hintstyle'</default>
<sensitive>true</sensitive>
</spinbutton>
</hbox>
<text height-request="5"><label>""</label></text>
</vbox>
</frame>
<frame '$(gettext 'Install font')'>
'"`/usr/lib/gtkdialog/xml_info scale font_add.svg 60 "$(gettext 'Define a *.TTF file by browsing, or just drag it to the field below. Then click install. Windows TTF-files are fine.')" "$(gettext 'To install several fonts at once, copy new *.TTF files to the font directory') (<i>/usr/share/fonts/default/TTF</i>), $(gettext 'and click install.')" " " "$(gettext 'You find a lot of free fonts on the web. - ie. at')" "<i>http://www.1001freefonts.com/</i>"`"'
<vbox space-expand="false" space-fill="false">
<text height-request="20"><label>""</label></text>
<hbox>
<entry accept="filename"><variable>FONT</variable></entry>
<button>
'"`/usr/lib/gtkdialog/xml_button-icon open`"'
<action type="fileselect">FONT</action>
<action>refresh:FONT</action>
</button>
</hbox>
<hbox>'
S=$S'<button space-expand="false" space-fill="false">
'"`/usr/lib/gtkdialog/xml_button-icon open`"'
<label>'$(gettext 'Open font directory')'</label>
<action>defaultfilemanager_x /usr/share/fonts/default/TTF</action>
</button>'
S=$S'<button>
'"`/usr/lib/gtkdialog/xml_button-icon font_add.svg`"'
<label>'$(gettext 'Install font(s)')'</label>
<action>install</action>
<action>clear:FONT</action>
</button>
</hbox>
<text height-request="5"><label>""</label></text>
</vbox>
</frame>
</notebook>
<hbox space-expand="false" space-fill="false">'
type gfontsel > /dev/null 2>&1 && S=$S' <button space-expand="false" space-fill="false">
'"`/usr/lib/gtkdialog/xml_button-icon select-font`"'
<label>'$(gettext 'View installed fonts')'</label>
<action>gfontsel &</action>
</button>'
S=$S'<text space-expand="true" space-fill="true"><label>""</label></text>
<button space-expand="false" space-fill="false">
<label>'$(gettext "Cancel")'</label>
'"`/usr/lib/gtkdialog/xml_button-icon cancel`"'
<action type="exit">EXIT_NOW</action>
</button>
<button space-expand="false" space-fill="false">
<label>'$(gettext "Ok")'</label>
'"`/usr/lib/gtkdialog/xml_button-icon ok`"'
<action type="exit">save</action>
</button>
</hbox>
</vbox>
</window>'
export Font_Manager="$S"
. /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
eval $(gtkdialog -p Font_Manager --styles=/tmp/gtkrc_xml_info.css)
case $EXIT in
save)
#set size
sed -i -e '/^Xft.dpi:/ d' $HOME/.Xresources
echo "Xft.dpi: $NEWDPI" >> $HOME/.Xresources
if [[ "$antialiasing" = "false" && "$hinting" = "false" && "$autohint" = "false" && "$hintstyle" = 0 ]];then
#don't write the file, delete if it's there.
[ -f $HOME/.fonts.conf ] && rm $HOME/.fonts.conf
echo "not writing file"
else
cat > $HOME/.fonts.conf << _EOF
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="font">
<test qual="all" name="rgba">
<const>unknown</const>
</test>
<edit name="rgba" mode="assign"><const>rgb</const></edit>
</match>
<match target="font">
<edit name="antialias" mode="assign">
<bool>$antialiasing</bool>
</edit>
<edit name="hinting" mode="assign">
<bool>$hinting</bool>
</edit>
<edit name="autohint" mode="assign">
<bool>$autohint</bool>
</edit>
<edit name="hintstyle" mode="assign">
<int>$hintstyle</int>
</edit>
</match>
<selectfont>
<rejectfont>
<pattern>
<patelt name="scalable"><bool>false</bool></patelt>
</pattern>
</rejectfont>
</selectfont>
</fontconfig>
_EOF
fi
;;
esac
exit 0