Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # converts gconf /desktop/gnome/font_rendering to fonts.conf
- # usage setfonts.py > ~/.fonts.conf
- # http://www.cyberciti.biz/faq/gnome-linux-firefox-smooth-fonts/
- # https://wiki.archlinux.org/index.php/Font_Configuration
- # mappings (http://freedesktop.org/wiki/ScreenFontSettings)
- # gconf -> fontconfig
- # /desktop/gnome/font_rendering/antialiasing ->
- # none -> false
- # grayscale -> true, rgba -> none
- # rgba -> true, rgba -> (value in rgba_order)
- # /desktop/gnome/font_rendering/hinting -> hintstyle
- # none -> hintnone
- # slight -> hintslight
- # medium -> hintmedium
- # full -> hintfull
- # /desktop/gnome/font_rendering/rgba_order -> rgba
- # rgb -> rgb
- # bgr -> bgr
- # vrgb -> vrgb
- # vbgr -> vbgr
- # (if /antialising = grayscale) -> none
- import gconf
- # abbreviations in code:
- # g -> gconf
- # fc -> fontconfig
- g = gconf.client_get_default()
- def gen_header():
- return """<?xml version="1.0"?>
- <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
- <fontconfig>"""
- def gen_footer():
- return "</fontconfig>"
- def convert_hintstyle():
- try:
- g_hintstyle = g.get("/desktop/gnome/font_rendering/hinting").get_string()
- except AttributeError:
- return ""
- fc_hintstyle = "hint"+g_hintstyle
- return """<match target="font" >
- <edit mode="assign" name="hintstyle" >
- <const>"""+fc_hintstyle+"""</const>
- </edit>
- </match>"""
- def convert_rgbamode():
- try:
- g_antialias = g.get("/desktop/gnome/font_rendering/antialiasing").get_string()
- except AttributeError:
- return ""
- fc_rgbamode = None
- if (g_antialias == "grayscale"):
- fc_rgbamode = "none"
- if (g_antialias == "rgba"):
- try:
- g_rgbamode = g.get("/desktop/gnome/font_rendering/rgba_order").get_string()
- fc_rgbamode = g_rgbamode
- except AttributeError:
- fc_rgbamode = "rgb"
- if fc_rgbamode is not None:
- return """<match target="font" >
- <edit mode="assign" name="rgba" >
- <const>"""+fc_rgbamode+"""</const>
- </edit>
- </match>"""
- else:
- return ""
- def convert_hinting():
- try:
- g_hintstyle = g.get("/desktop/gnome/font_rendering/hinting").get_string()
- except AttributeError:
- return ""
- fc_hinting = "false"
- if (g_hintstyle != "none"):
- fc_hinting = "true"
- return """<match target="font" >
- <edit mode="assign" name="hinting" >
- <bool>"""+fc_hinting+"""</bool>
- </edit>
- </match>"""
- def convert_antialias():
- try:
- g_antialias = g.get("/desktop/gnome/font_rendering/antialiasing").get_string()
- except AttributeError:
- return ""
- fc_antialias = "false"
- if (g_antialias != "none"):
- fc_antialias = "true"
- return """<match target="font" >
- <edit mode="assign" name="antialias" >
- <bool>"""+fc_antialias+"""</bool>
- </edit>
- </match>"""
- # force disable autohinter if subpixel rendering is enabled (ie rgba != none)
- # leave unchanged otherwise
- def convert_autohint():
- g_antialias = g.get("/desktop/gnome/font_rendering/antialiasing").get_string()
- if (g_antialias == "rgba"):
- return """<match target="font" >
- <edit mode="assign" name="autohint" >
- <bool>false</bool>
- </edit>
- </match>"""
- else:
- return ""
- print gen_header()
- print convert_rgbamode()
- print convert_hinting()
- print convert_hintstyle()
- print convert_antialias()
- #print convert_autohint() # msttcorefonts might look better with autohint true, so dont touch
- print gen_footer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement