fontmanager 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #!/bin/bash
  2. #Combining fontwizard, pFont and set-xftdpi (Barry Kauler 2009)
  3. #Sigmund Berglund, Nov 2013
  4. export TEXTDOMAIN=fontmanager
  5. export OUTPUT_CHARSET=UTF-8
  6. #read current dpi setting...
  7. CURRDPI=`grep "^Xft\\.dpi:" /root/.Xresources | tr '\t' ' ' | tr -s ' ' | cut -f 2 -d ' '`
  8. [ ! $CURRDPI ] && CURRDPI=78
  9. CURRINDEX=$(( $CURRDPI / 6 - 9 ))
  10. #read appearance values
  11. if [ -f $HOME/.fonts.conf ];then
  12. export antialiasing=$(grep '<bool>' $HOME/.fonts.conf|head -1|cut -d '>' -f2|cut -d '<' -f1)
  13. export hinting=$(grep '<bool>' $HOME/.fonts.conf|head -2|tail -1|cut -d '>' -f2|cut -d '<' -f1)
  14. export autohint=$(grep '<bool>' $HOME/.fonts.conf|head -3|tail -1|cut -d '>' -f2|cut -d '<' -f1)
  15. export hintstyle=$(grep '<int>' $HOME/.fonts.conf|cut -d '>' -f2|cut -d '<' -f1)
  16. else
  17. export antialiasing=false hinting=false autohint=false hintstyle=0
  18. fi
  19. #what tab should be active
  20. [ "$1" = "install" ] && PAGE_NR=2 || PAGE_NR=0
  21. install (){
  22. case $FONT in
  23. *.ttf)
  24. cp "$FONT" /usr/share/fonts/default/TTF/
  25. rm /usr/share/fonts/default/TTF/fonts.dir
  26. rm /usr/share/fonts/default/TTF/fonts.scale
  27. mkfontscale /usr/share/fonts/default/TTF
  28. mkfontdir /usr/share/fonts/default/TTF
  29. ;;
  30. *)
  31. Xdialog --title "Font installer" --msgbox "'$(gettext 'No TTF-file to install')" 0 0
  32. ;;
  33. esac
  34. }
  35. export -f install
  36. S='
  37. <window title="'$(gettext 'Font Manager')'" icon-name="gtk-execute">
  38. <vbox space-expand="true" space-fill="true">
  39. <notebook tab-pos="2" page="'$PAGE_NR'" labels="'$(gettext 'Size')'|'$(gettext 'Appearance')'|'$(gettext 'Install fonts')'">
  40. <frame '$(gettext 'Global font size')'>
  41. '"`/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')"`"'
  42. <vbox space-expand="false" space-fill="false">
  43. <text height-request="20"><label>""</label></text>
  44. <hbox>
  45. <text><label>""</label></text>
  46. <text><label>'$(gettext 'Choose global fontsize')'</label></text>
  47. <comboboxtext width-request="70">
  48. <default>'$CURRDPI'</default>
  49. <variable>NEWDPI</variable>
  50. <item>54</item>
  51. <item>60</item>
  52. <item>66</item>
  53. <item>72</item>
  54. <item>78</item>
  55. <item>84</item>
  56. <item>90</item>
  57. <item>96</item>
  58. <item>102</item>
  59. <item>108</item>
  60. </comboboxtext>
  61. </hbox>
  62. <text height-request="5"><label>""</label></text>
  63. </vbox>
  64. </frame>
  65. <frame '$(gettext 'Font appearance')'>
  66. '"`/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.')"`"'
  67. <vbox space-expand="false" space-fill="false">
  68. <text height-request="20"><label>""</label></text>
  69. <checkbox tooltip-text="'$(gettext "If checked, fonts will be smoothed with antialiasing.")'">
  70. <label>'$(gettext 'Antialiasing')'</label>
  71. <variable>antialiasing</variable>
  72. <default>'$antialiasing'</default>
  73. </checkbox>
  74. <checkbox tooltip-text="'$(gettext "If checked, fonts will be smoothed with hinting.")'">
  75. <label>'$(gettext 'Hinting')'</label>
  76. <variable>hinting</variable>
  77. <default>'$hinting'</default>
  78. </checkbox>
  79. <hbox space-expand="true" space-fill="true">
  80. <checkbox>
  81. <label>'$(gettext 'Automatic hinting')'</label>
  82. <variable>autohint</variable>
  83. <default>'$autohint'</default>
  84. </checkbox>
  85. <text space-expand="true" space-fill="true"><label>""</label></text>
  86. <text space-expand="false" space-fill="false"><label>'$(gettext 'Hint style')'</label></text>
  87. <spinbutton range-min="0" range-max="3" width="100" editable="false" space-expand="false" space-fill="false">
  88. <variable>hintstyle</variable>
  89. <default>'$hintstyle'</default>
  90. <sensitive>true</sensitive>
  91. </spinbutton>
  92. </hbox>
  93. <text height-request="5"><label>""</label></text>
  94. </vbox>
  95. </frame>
  96. <frame '$(gettext 'Install font')'>
  97. '"`/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>"`"'
  98. <vbox space-expand="false" space-fill="false">
  99. <text height-request="20"><label>""</label></text>
  100. <hbox>
  101. <entry accept="filename"><variable>FONT</variable></entry>
  102. <button>
  103. '"`/usr/lib/gtkdialog/xml_button-icon open`"'
  104. <action type="fileselect">FONT</action>
  105. <action>refresh:FONT</action>
  106. </button>
  107. </hbox>
  108. <hbox>'
  109. type rox > /dev/null 2>&1 && S=$S'<button space-expand="false" space-fill="false">
  110. '"`/usr/lib/gtkdialog/xml_button-icon open`"'
  111. <label>'$(gettext 'Open font directory')'</label>
  112. <action>rox -d /usr/share/fonts/default/TTF</action>
  113. </button>'
  114. S=$S'<button>
  115. '"`/usr/lib/gtkdialog/xml_button-icon font_add.svg`"'
  116. <label>'$(gettext 'Install font(s)')'</label>
  117. <action>install</action>
  118. <action>clear:FONT</action>
  119. </button>
  120. </hbox>
  121. <text height-request="5"><label>""</label></text>
  122. </vbox>
  123. </frame>
  124. </notebook>
  125. <hbox space-expand="false" space-fill="false">'
  126. type gfontsel > /dev/null 2>&1 && S=$S' <button space-expand="false" space-fill="false">
  127. '"`/usr/lib/gtkdialog/xml_button-icon select-font`"'
  128. <label>'$(gettext 'View installed fonts')'</label>
  129. <action>gfontsel &</action>
  130. </button>'
  131. S=$S'<text space-expand="true" space-fill="true"><label>""</label></text>
  132. <button space-expand="false" space-fill="false">
  133. <label>'$(gettext "Cancel")'</label>
  134. '"`/usr/lib/gtkdialog/xml_button-icon cancel`"'
  135. <action type="exit">EXIT_NOW</action>
  136. </button>
  137. <button space-expand="false" space-fill="false">
  138. <label>'$(gettext "Ok")'</label>
  139. '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
  140. <action type="exit">save</action>
  141. </button>
  142. </hbox>
  143. </vbox>
  144. </window>'
  145. export Font_Manager="$S"
  146. . /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
  147. eval $(gtkdialog -p Font_Manager)
  148. case $EXIT in
  149. save)
  150. #set size
  151. TMP1="`cat /root/.Xresources | grep -v "Xft\\.dpi:"`"
  152. echo "$TMP1" > /root/.Xresources
  153. echo "Xft.dpi: $NEWDPI" >> /root/.Xresources
  154. sync
  155. if [[ "$antialiasing" = "false" && "$hinting" = "false" && "$autohint" = "false" && "$hintstyle" = 0 ]];then
  156. #don't write the file, delete if it's there.
  157. [ -f $HOME/.fonts.conf ] && rm $HOME/.fonts.conf
  158. echo "not writing file"
  159. else
  160. cat > $HOME/.fonts.conf << _EOF
  161. <?xml version="1.0"?>
  162. <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
  163. <fontconfig>
  164. <match target="font">
  165. <test qual="all" name="rgba">
  166. <const>unknown</const>
  167. </test>
  168. <edit name="rgba" mode="assign"><const>rgb</const></edit>
  169. </match>
  170. <match target="font">
  171. <edit name="antialias" mode="assign">
  172. <bool>$antialiasing</bool>
  173. </edit>
  174. <edit name="hinting" mode="assign">
  175. <bool>$hinting</bool>
  176. </edit>
  177. <edit name="autohint" mode="assign">
  178. <bool>$autohint</bool>
  179. </edit>
  180. <edit name="hintstyle" mode="assign">
  181. <int>$hintstyle</int>
  182. </edit>
  183. </match>
  184. <selectfont>
  185. <rejectfont>
  186. <pattern>
  187. <patelt name="scalable"><bool>false</bool></patelt>
  188. </pattern>
  189. </rejectfont>
  190. </selectfont>
  191. </fontconfig>
  192. _EOF
  193. fi
  194. ;;
  195. esac
  196. exit 0