Articles

Valid autohinting / hinting style options

In Ubuntu on 25/07/2010 by weirdfellow Tagged: , , , , , , ,

Everyone that ever tried to edit any of the FontConfig configuration files came across the dilemma which hinting to select for your fonts. There are dozens of sample files in the Internet, but noone tells what are the possible valid options and what actually they do.

Today I have been doing some experiments and have found a way to render the same font face with different hinting settings side by side in one window. The conclusion from that is: there are only five different results to be expected out of eight possible combinations of hintstyle and autohint properties.

  • hintstyle = hintnone – switches off the hinting
  • hinstyle = hintslight – switches on the slight hinting (usually results with only vertical hinting but unfortunately not always). Autohint property is ignored and autohinter is always used with this hinting style.
  • hintstyle = hintmedium, autohint = true.
  • hintstyle = hintfull, autohint = true.
  • hintstyle = hintmedium | hintfull, autohint = false – uses the BCI (patented) hinter. In majority it does not matter if hintstyle is set to medium or full – the results are the same.

As an example, the DejaVu Sans with different hinting options.

The difference might not be huge with this font, but with different fonts product more versatile results (Liberation Serif 14pt):

I used a trick with introducing an additional property to the fontconfig – family-old.
In the <match type="pattern"> elements I replace the all the weird font families with something a bit more sensible. But I also store the original family in the family-old property, so later the additional test in <match type="font"> can be performed and properties hintstyle and autohint modified according to the original font family.

This is the .font.config file I have used:

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-ah-none</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-ah-none</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-ah-slight</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-ah-slight</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-ah-medium</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-ah-medium</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-ah-full</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-ah-full</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-nah-none</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-nah-none</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-nah-slight</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-nah-slight</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-nah-medium</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-nah-medium</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-nah-full</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-nah-full</string></edit>
</match> 

<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-ah-none</string></test>

  <edit name="autohint" mode="assign"><bool>true</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintnone</const></edit> 
</match> 
<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-ah-slight</string></test>

  <edit name="autohint" mode="assign"><bool>true</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintslight</const></edit> 
</match> 
<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-ah-medium</string></test>

  <edit name="autohint" mode="assign"><bool>true</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintmedium</const></edit> 
</match> 
<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-ah-full</string></test>

  <edit name="autohint" mode="assign"><bool>true</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintfull</const></edit> 
</match> 

<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-nah-none</string></test>

  <edit name="autohint" mode="assign"><bool>false</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintnone</const></edit> 
</match> 
<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-nah-slight</string></test>

  <edit name="autohint" mode="assign"><bool>false</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintslight</const></edit> 
</match> 
<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-nah-medium</string></test>

  <edit name="autohint" mode="assign"><bool>false</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintmedium</const></edit> 
</match> 
<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-nah-full</string></test>

  <edit name="autohint" mode="assign"><bool>false</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintfull</const></edit> 
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont</string></test>
  <edit name="family" binding="same" mode="assign"><string>Liberation Serif</string></edit>
</match> 

</fontconfig>

Line 112 contains the name of the fontface to be actually used while rendering. The test images were generated in Firefox – following HTML/JavaScript document was used to display the content.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
		<script type="text/javascript">
function putText( fontFamily, weight, size ) {
	if (!size) size = 14;

	var $span = $("<div><span style='width: 180px; float: left; clear: left;'>" + fontFamily + " " + size + "pt.</span>aąbcćdeęfghijklłoónńsśzźż AĄBCĆDEĘFGHIJKLŁOÓNŃSŚZŻŹ</div>");
	$span.css("font-family", fontFamily).css("font-size", size).css("font-weight", weight);

	$("BODY").append($span);
}

function putSpace() {
	$("BODY").append($("<div>&nbsp;</div>"));
}

function generateHifferentHintingOptions( familyName, fontWeight ) {
	putText ( familyName + "-ah-none", fontWeight );
	putText ( familyName + "-nah-none", fontWeight );
	putSpace();

	putText ( familyName + "-ah-slight", fontWeight );
	putText ( familyName + "-nah-slight", fontWeight );
	putSpace();

	putText ( familyName + "-nah-medium", fontWeight );
	putText ( familyName + "-nah-full", fontWeight );
	putSpace();

	putText ( familyName + "-ah-medium", fontWeight );
	putSpace();

	putText ( familyName + "-ah-full", fontWeight);
	putSpace();
}

$(document).ready(function(){
	generateHifferentHintingOptions( "TestFont", "normal" );
});
		</script>
	</head>
	<body>
	</body>
</html>

I mentioned ealier that usually I prefer the autohint + hintslight combination. There are some rare exceptions I identified with this method. What are your preferences?

About these ads

One Response to “Valid autohinting / hinting style options”

  1. Thanks for sharing your clever solution for testing various fonts. I needed to test Courier New since I knew that it was too light for my eyes if it wasn’t set to no autohint, and medium hinting.

    I was also able to see FreeMono and Nimbus Mono are also too light for my eyes, so I got Courier New as a replacement for them.

    I always play around with my .fonts.conf file over the years, but I never really spent the time to figure the settings out.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: