Skip to content

Instantly share code, notes, and snippets.

@piec
Created January 6, 2016 09:41
Show Gist options
  • Save piec/69ab603dd2f16aa57292 to your computer and use it in GitHub Desktop.
Save piec/69ab603dd2f16aa57292 to your computer and use it in GitHub Desktop.
lcdfilter test
#!/usr/bin/env python2
#
# This script will generate a fontconfig file that you should link from your ~/.fonts.conf, using:
#
# <include ignore_missing="yes">/path_to_this_directory/fonts.conf</include>
#
import os, os.path
PANGO_VIEW_PATH = "/usr/bin/"
IMG_WIDTH = 210
def gen_config(autohint, lcdfilter):
conf = open("fonts.conf.in").read()
conf = conf % {"autohint": autohint and "true" or "false", "lcdfilter": str(lcdfilter)}
open("fonts.conf", "w").write(conf)
def gen_image(autohinter, font, size, lcdfilter):
image_name = "-".join([autohinter and "autohinter" or "bytecode_int",
font.replace(" ", "_"), str(size), str(lcdfilter)]) + ".png"
print "Generating image:", image_name
gen_config(autohinter, lcdfilter)
if not os.path.exists("img"):
os.mkdir("img")
width = IMG_WIDTH
pv_path = PANGO_VIEW_PATH
os.system("%(pv_path)s/pango-view --header --width %(width)s --font '%(font)s %(size)s' " \
"--output img/%(image_name)s -q test-latin.txt" % locals())
return image_name
html = ""
# for autohinter in (False, True):
for autohinter in (False,):
html += "<tr><td colspan='4' class='title1'>%s</td></tr>\n" % \
(autohinter and "autohinter" or "bytecode interpreter")
for font in ("Cantarell", "Sans", "Courier New", "Verdana", "monospace"):
html += "<tr><td colspan='4' class='title2'>Font: %s</td></tr>\n" % font
for size in (6, 8, 10, 12, 16):
html += "<tr>\n"
for lcdfilter in range(4):
image_name = gen_image(autohinter, font, size, lcdfilter)
html += " <td><img src='img/%s'/></td>\n" % image_name
html += "</tr>\n"
open("index.html", "w").write(open("index.html.in").read().replace("@@CONTENT@@", html))
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="font">
<edit name="rgba" mode="assign"><const>rgb</const></edit>
</match>
<match target="pattern">
<edit name="autohint" mode="assign"><bool>%(autohint)s</bool></edit>
<edit mode="append" name="lcdfilter">
<int>%(lcdfilter)s</int>
</edit>
</match>
</fontconfig>
<!DOCTYPE html>
<html>
<head>
<title>Lcdfilter test</title>
<!--<link rel="stylesheet" type="text/css"
href="/style/base/template.css" media="screen" />-->
<!--<script src="/js/util.js" type="text/javascript"></script>-->
<script type="application/javascript">
</script>
<style type="text/css">
p {
padding-left: 1em;
font-family: sans;
}
.small {
font-size: small;
}
table {
border-collapse: collapse;
}
th {
border: 1px solid #aaa;
}
.title1, .title2 {
text-align: center;
}
.title1 {
font-size: 150%;
background-color: #aaa;
}
.title2 {
background-color: #ddd;
}
img {
outline: 1px solid #bbb;
}
</style>
</head>
<body>
<p>
This page shows text rendering with various types of lcd filtering parameters. The pango-view util from Pango was used to generate the images. Cairo is patched with the lcd filtering patch (https://bugs.freedesktop.org/show_bug.cgi?id=10301) and a modification to read lcd filtering parameters from fontconfig. <span class="small"><a href="build_testcase.py">Source for the hack script to generate this page</a></span>
</p>
<p>
You must have a LCD screen with RGB pixel order, otherwise the images won't make sense. First part of the page is done with the bytecode interpreter turned on and the second part with the autohinter.
</p>
<table>
<tr>
<th>FT_LCD_FILTER_NONE</th>
<th>FT_LCD_FILTER_DEFAULT</th>
<th>FT_LCD_FILTER_LIGHT</th>
<th>FT_LCD_FILTER_LEGACY</th>
</tr>
@@CONTENT@@
</table>
</body>
</html>
'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe;
All mimsy were the borogoves,
And the mome raths outgrabe.
'Beware the Jabberwock, my son!
The jaws that bite, the claws that catch!
Beware the Jubjub bird, and shun
The frumious Bandersnatch!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment