From Guest, 4 Years ago, written in Plain Text.
Embed
  1. #!/usr/bin/env python
  2. # converts gconf /desktop/gnome/font_rendering to fonts.conf
  3. # usage setfonts.py > ~/.fonts.conf
  4.  
  5. # http://www.cyberciti.biz/faq/gnome-linux-firefox-smooth-fonts/
  6. # https://wiki.archlinux.org/index.php/Font_Configuration
  7.  
  8. # mappings (http://freedesktop.org/wiki/ScreenFontSettings)
  9. # gconf -> fontconfig
  10. # /desktop/gnome/font_rendering/antialiasing ->
  11. #       none -> false
  12. #       grayscale -> true, rgba -> none
  13. #       rgba -> true, rgba -> (value in rgba_order)
  14. # /desktop/gnome/font_rendering/hinting -> hintstyle
  15. #       none -> hintnone
  16. #       slight -> hintslight
  17. #       medium -> hintmedium
  18. #       full -> hintfull
  19. # /desktop/gnome/font_rendering/rgba_order -> rgba
  20. #       rgb -> rgb
  21. #       bgr -> bgr
  22. #       vrgb -> vrgb
  23. #       vbgr -> vbgr
  24. #       (if /antialising = grayscale) -> none
  25.  
  26. import gconf
  27.  
  28. # abbreviations in code:
  29. # g -> gconf
  30. # fc -> fontconfig
  31. g = gconf.client_get_default()
  32. def gen_header():
  33.         return """<?xml version="1.0"?>
  34. <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
  35. <fontconfig>"""
  36.  
  37. def gen_footer():
  38.         return "</fontconfig>"
  39.  
  40. def convert_hintstyle():
  41.         try:
  42.                 g_hintstyle =  g.get("/desktop/gnome/font_rendering/hinting").get_string()
  43.         except AttributeError:
  44.                 return ""
  45.         fc_hintstyle = "hint"+g_hintstyle
  46.         return """<match target="font" >
  47.   <edit mode="assign" name="hintstyle" >
  48.     <const>"""+fc_hintstyle+"""</const>
  49.   </edit>
  50. </match>"""
  51.  
  52. def convert_rgbamode():
  53.         try:
  54.                 g_antialias = g.get("/desktop/gnome/font_rendering/antialiasing").get_string()
  55.         except AttributeError:
  56.                 return ""
  57.         fc_rgbamode = None
  58.         if (g_antialias == "grayscale"):
  59.                 fc_rgbamode = "none"
  60.         if (g_antialias == "rgba"):
  61.                 try:
  62.                         g_rgbamode = g.get("/desktop/gnome/font_rendering/rgba_order").get_string()
  63.                         fc_rgbamode = g_rgbamode
  64.                 except AttributeError:
  65.                         fc_rgbamode = "rgb"
  66.         if fc_rgbamode is not None:
  67.                 return """<match target="font" >
  68.   <edit mode="assign" name="rgba" >
  69.     <const>"""+fc_rgbamode+"""</const>
  70.   </edit>
  71. </match>"""
  72.         else:
  73.                 return ""
  74.  
  75. def convert_hinting():
  76.         try:
  77.                 g_hintstyle =  g.get("/desktop/gnome/font_rendering/hinting").get_string()
  78.         except AttributeError:
  79.                 return ""
  80.         fc_hinting = "false"
  81.         if (g_hintstyle != "none"):
  82.                 fc_hinting = "true"
  83.         return """<match target="font" >
  84.   <edit mode="assign" name="hinting" >
  85.     <bool>"""+fc_hinting+"""</bool>
  86.   </edit>
  87. </match>"""
  88.  
  89. def convert_antialias():
  90.         try:
  91.                 g_antialias = g.get("/desktop/gnome/font_rendering/antialiasing").get_string()
  92.         except AttributeError:
  93.                 return ""
  94.         fc_antialias = "false"
  95.         if (g_antialias != "none"):
  96.                 fc_antialias = "true"
  97.         return """<match target="font" >
  98.   <edit mode="assign" name="antialias" >
  99.     <bool>"""+fc_antialias+"""</bool>
  100.   </edit>
  101. </match>"""
  102.                
  103. # force disable autohinter if subpixel rendering is enabled (ie rgba != none)
  104. # leave unchanged otherwise
  105. def convert_autohint():
  106.         g_antialias = g.get("/desktop/gnome/font_rendering/antialiasing").get_string()
  107.         if (g_antialias == "rgba"):
  108.                 return """<match target="font" >
  109.   <edit mode="assign" name="autohint" >
  110.     <bool>false</bool>
  111.   </edit>
  112. </match>"""
  113.         else:
  114.                 return ""
  115.  
  116. print gen_header()
  117. print convert_rgbamode()
  118. print convert_hinting()
  119. print convert_hintstyle()
  120. print convert_antialias()
  121. #print convert_autohint()  # msttcorefonts might look better with autohint true, so dont touch
  122. print gen_footer()
  123.  
  124.